SfcProviderServiceFunctionAPI { public static ServiceFunction readServiceFunction(SfName serviceFunctionName) { printTraceStart(LOG); ServiceFunction sf; InstanceIdentifier<ServiceFunction> sfIID; ServiceFunctionKey serviceFunctionKey = new ServiceFunctionKey(serviceFunctionName); sfIID = InstanceIdentifier.builder(ServiceFunctions.class) .child(ServiceFunction.class, serviceFunctionKey) .build(); sf = SfcDataStoreAPI.readTransactionAPI(sfIID, LogicalDatastoreType.CONFIGURATION); printTraceStop(LOG); return sf; }  static List<SfServicePath> readServiceFunctionState(SfName serviceFunctionName); static List<RspName> getRspsBySfName(SfName serviceFunctionName); static SfcSfDescMon readServiceFunctionDescriptionMonitor(SfName serviceFunctionName); static boolean deleteServiceFunctionState(SfName serviceFunctionName); static boolean addPathToServiceFunctionState(RenderedServicePath renderedServicePath); static boolean putServiceFunction(ServiceFunction sf); static boolean putServiceFunctionState(ServiceFunctionState sfState); static boolean mergeServiceFunctionState(ServiceFunctionState sfState); static ServiceFunction readServiceFunction(SfName serviceFunctionName); static boolean deleteServicePathFromServiceFunctionState(SfpName sfpName); static boolean deleteServicePathFromServiceFunctionState(List<RspName> rspNames); static boolean deleteRspFromServiceFunctionState(RspName rspName);  }
@Test public void testCreateReadServiceFunctions() throws ExecutionException, InterruptedException { final List<SfName> sfName = new ArrayList<SfName>() { private static final long serialVersionUID = 1L; { add(new SfName("unittest-fw-1")); add(new SfName("unittest-fw-2")); add(new SfName("unittest-fw-3")); } }; final SftTypeName sfType = new SftTypeName("firewall"); final IpAddress[] ipMgmtAddress = {new IpAddress(new Ipv4Address(IP_MGMT_ADDRESS.get(0))), new IpAddress(new Ipv4Address(IP_MGMT_ADDRESS.get(1))), new IpAddress(new Ipv4Address(IP_MGMT_ADDRESS.get(2)))}; SfDataPlaneLocator[] sfDataPlaneLocator = new SfDataPlaneLocator[3]; ServiceFunctionKey[] key = new ServiceFunctionKey[3]; for (int i = 0; i < 3; i++) { key[i] = new ServiceFunctionKey(new SfName(sfName.get(i))); } final IpAddress[] locatorIpAddress = {new IpAddress(new Ipv4Address(LOCATOR_IP_ADDRESS.get(0))), new IpAddress(new Ipv4Address(LOCATOR_IP_ADDRESS.get(1))), new IpAddress(new Ipv4Address(LOCATOR_IP_ADDRESS.get(2)))}; PortNumber portNumber = new PortNumber(PORT); List<ServiceFunction> list = new ArrayList<>(); for (int i = 0; i < 3; i++) { IpBuilder ipBuilder = new IpBuilder(); ipBuilder.setIp(locatorIpAddress[i]).setPort(portNumber); SfDataPlaneLocatorBuilder locatorBuilder = new SfDataPlaneLocatorBuilder(); locatorBuilder.setName(new SfDataPlaneLocatorName(LOCATOR_IP_ADDRESS.get(i))) .setLocatorType(ipBuilder.build()) .setTransport(SlTransportType.class); sfDataPlaneLocator[i] = locatorBuilder.build(); ServiceFunctionBuilder sfBuilder = new ServiceFunctionBuilder(); List<SfDataPlaneLocator> dataPlaneLocatorList = new ArrayList<>(); dataPlaneLocatorList.add(sfDataPlaneLocator[i]); sfBuilder.setName(new SfName(sfName.get(i))) .setKey(key[i]) .setType(sfType) .setIpMgmtAddress(ipMgmtAddress[i]) .setSfDataPlaneLocator(dataPlaneLocatorList); list.add(sfBuilder.build()); } ServiceFunctionsBuilder sfsBuilder = new ServiceFunctionsBuilder(); sfsBuilder.setServiceFunction(list); SfcDataStoreAPI.writePutTransactionAPI(SfcInstanceIdentifiers.SF_IID, sfsBuilder.build(), LogicalDatastoreType.CONFIGURATION); ServiceFunction sf2 = SfcProviderServiceFunctionAPI.readServiceFunction(new SfName(sfName.get(1))); assertNotNull("Must be not null", sf2); assertEquals("Must be equal", sf2.getIpMgmtAddress(), ipMgmtAddress[1]); assertEquals("Must be equal", sf2.getType(), sfType); List<SfDataPlaneLocator> dataPlaneLocatorList2 = new ArrayList<>(); dataPlaneLocatorList2.add(sfDataPlaneLocator[1]); assertEquals("Must be equal", sf2.getSfDataPlaneLocator(), dataPlaneLocatorList2); }
@Test public void testCreateReadDeleteServiceFunction() throws Exception { boolean transactionSuccessful = writeRemoveServiceFunction(IP_MGMT_ADDRESS.get(1), true); assertTrue("Must be true", transactionSuccessful); ServiceFunction serviceFunction = SfcProviderServiceFunctionAPI.readServiceFunction(SF_NAME); assertNotNull("Must be not null", serviceFunction); assertEquals("Must be equal", serviceFunction.getIpMgmtAddress().getIpv4Address().getValue(), IP_MGMT_ADDRESS.get(1)); transactionSuccessful = writeRemoveServiceFunction(IP_MGMT_ADDRESS.get(1), false); assertTrue("Must be true", transactionSuccessful); }