SfcIosXeUtils { public static ServiceFfName createRemoteForwarder(SffName sffName) { ServiceFunctionForwarder sfcForwarder = SfcProviderServiceForwarderAPI.readServiceFunctionForwarder(sffName); if (sfcForwarder == null) { return null; } Ipv4Address sffIp = null; for (SffDataPlaneLocator sffDpl : sfcForwarder.getSffDataPlaneLocator()) { DataPlaneLocator dataPlaneLocator = sffDpl.getDataPlaneLocator(); LocatorType sffLocatorType = dataPlaneLocator.getLocatorType(); if (sffLocatorType instanceof Ip && ((Ip) sffLocatorType).getIp() != null) { sffIp = ((Ip) sffLocatorType).getIp().getIpv4Address(); } } if (sffIp == null) { return null; } IpBuilder ipBuilder = new IpBuilder(); ipBuilder.setAddress(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address(sffIp.getValue())); ServiceFfNameBuilder ffNameBuilder = new ServiceFfNameBuilder(); ffNameBuilder.setKey(new ServiceFfNameKey(sffName.getValue())) .setName(sffName.getValue()) .setIp(ipBuilder.build()) .setDescription(REMOTE + sffName.getValue()); return ffNameBuilder.build(); }  static org.opendaylight.yang.gen.v1.urn.ios.rev160308._native.service.chain.ServiceFunctionForwarder createLocalForwarder(
            IpAddress ipAddress); static ServiceFfName createRemoteForwarder(SffName sffName); static SfDataPlaneLocator getDplWithIpLocatorType(List<SfDataPlaneLocator> dataPlaneLocators);  }
@Test public void createRemoteForwarder_noForwarderFound() { SffName forwarderSff = new SffName(forwarderName); PowerMockito.stub(PowerMockito.method(SfcProviderServiceForwarderAPI.class, "readServiceFunctionForwarder")) .toReturn(null); ServiceFfName result = SfcIosXeUtils.createRemoteForwarder(forwarderSff); assertNull(result); }
@Test public void createRemoteForwarder_noIpLocatorType() { ServiceFunctionForwarderBuilder serviceFunctionForwarderBuilder = new ServiceFunctionForwarderBuilder(); List<SffDataPlaneLocator> sffDataPlaneLocators = new ArrayList<>(); SffDataPlaneLocatorBuilder sffDataPlaneLocatorBuilder = new SffDataPlaneLocatorBuilder(); DataPlaneLocatorBuilder dataPlaneLocatorBuilder = new DataPlaneLocatorBuilder(); MacBuilder macBuilder = new MacBuilder(); dataPlaneLocatorBuilder.setLocatorType(macBuilder.build()); sffDataPlaneLocatorBuilder.setDataPlaneLocator(dataPlaneLocatorBuilder.build()); sffDataPlaneLocators.add(sffDataPlaneLocatorBuilder.build()); serviceFunctionForwarderBuilder.setSffDataPlaneLocator(sffDataPlaneLocators); SffName forwarderSff = new SffName(forwarderName); PowerMockito.stub(PowerMockito.method(SfcProviderServiceForwarderAPI.class, "readServiceFunctionForwarder")) .toReturn(serviceFunctionForwarderBuilder.build()); ServiceFfName result = SfcIosXeUtils.createRemoteForwarder(forwarderSff); assertNull(result); }
@Test public void createRemoteForwarder() { ServiceFunctionForwarderBuilder serviceFunctionForwarderBuilder = new ServiceFunctionForwarderBuilder(); List<SffDataPlaneLocator> sffDataPlaneLocators = new ArrayList<>(); SffDataPlaneLocatorBuilder sffDataPlaneLocatorBuilder = new SffDataPlaneLocatorBuilder(); DataPlaneLocatorBuilder dataPlaneLocatorBuilder = new DataPlaneLocatorBuilder(); IpBuilder ipBuilder = new IpBuilder(); ipBuilder.setIp(new IpAddress(new Ipv4Address(ipv4Address))) .setPort(new PortNumber(100)); dataPlaneLocatorBuilder.setLocatorType(ipBuilder.build()); sffDataPlaneLocatorBuilder.setDataPlaneLocator(dataPlaneLocatorBuilder.build()); sffDataPlaneLocators.add(sffDataPlaneLocatorBuilder.build()); serviceFunctionForwarderBuilder.setSffDataPlaneLocator(sffDataPlaneLocators); SffName forwarderSff = new SffName(forwarderName); PowerMockito.stub(PowerMockito.method(SfcProviderServiceForwarderAPI.class, "readServiceFunctionForwarder")) .toReturn(serviceFunctionForwarderBuilder.build()); ServiceFfName result = SfcIosXeUtils.createRemoteForwarder(forwarderSff); assertNotNull(result); assertEquals(result.getIp().getAddress().getValue(), ipv4Address); }