@Test public void testResolveRemoteSfcComponents_noForwarderLocator() { final PolicyConfigurationContext context = new PolicyConfigurationContext(); context.setPolicyMapLocation(getLocation()); final ServiceFunctionForwarderBuilder forwarderBuilder = new ServiceFunctionForwarderBuilder(); forwarderBuilder.setName(new SffName(SERVICE_FUNCTION_FORWARDER)); final RenderedServicePathHopBuilder hopBuilder = new RenderedServicePathHopBuilder(); hopBuilder.setServiceFunctionForwarder(new SffName(SERVICE_FUNCTION_FORWARDER)); final RenderedServicePathBuilder rspBuilder = new RenderedServicePathBuilder(); rspBuilder.setRenderedServicePathHop(Collections.singletonList(hopBuilder.build())); stub(method(SfcProviderServiceForwarderAPI.class, "readServiceFunctionForwarder")).toReturn(forwarderBuilder.build()); boolean result = ServiceChainingUtil.resolveRemoteSfcComponents(rspBuilder.build(), context); assertFalse(result); }
public static boolean resolveRemoteSfcComponents(final RenderedServicePath renderedServicePath, final PolicyConfigurationContext context) { final PolicyManagerImpl.PolicyMapLocation location = context.getPolicyMapLocation(); final ServiceFunctionForwarder forwarder = getFirstHopSff(renderedServicePath); if (forwarder == null) { return false; } final SffName sffName = forwarder.getName(); if (forwarder.getSffDataPlaneLocator() == null || forwarder.getSffDataPlaneLocator().isEmpty()) { LOG.warn("Service function forwarder {} does not contain data plane locator", sffName.getValue()); return false; } final SffDataPlaneLocator sffDataPlaneLocator = forwarder.getSffDataPlaneLocator().get(0); final DataPlaneLocator dataPlaneLocator = sffDataPlaneLocator.getDataPlaneLocator(); final LocatorType locatorType = dataPlaneLocator.getLocatorType(); if (locatorType != null && locatorType instanceof Ip) { final IpAddress remoteForwarderIpAddress = (((Ip) locatorType).getIp()); if (remoteForwarderIpAddress == null || remoteForwarderIpAddress.getIpv4Address() == null) { LOG.warn("Service function forwarder {} data plane locator does not contain ip address", sffName.getValue()); return false; } final String remoteForwarderStringIp = remoteForwarderIpAddress.getIpv4Address().getValue(); final java.util.Optional<IpAddress> optionalIpMgmtAddress = java.util.Optional.ofNullable(forwarder.getIpMgmtAddress()); return optionalIpMgmtAddress.map(IpAddress::getIpv4Address) .map(Ipv4Address::getValue) .map(addressValue -> { final ServiceTypeChoice serviceTypeChoice; if (!addressValue.equals(location.getManagementIpAddress())) { final ServiceFfNameBuilder remoteSffBuilder = new ServiceFfNameBuilder(); remoteSffBuilder.setName(sffName.getValue()) .setKey(new ServiceFfNameKey(sffName.getValue())) .setIp(new IpBuilder().setAddress(new Ipv4Address(remoteForwarderStringIp)).build()); boolean rsResult = PolicyWriterUtil.writeRemote(remoteSffBuilder.build(), location); context.setFutureResult(Futures.immediateCheckedFuture(rsResult)); serviceTypeChoice = createForwarderTypeChoice(sffName.getValue()); final List<Services> services = new ArrayList<>(); final ServicesBuilder servicesBuilder = new ServicesBuilder(); servicesBuilder.setServiceIndexId(renderedServicePath.getStartingIndex()) .setServiceTypeChoice(serviceTypeChoice); services.add(servicesBuilder.build()); final List<ServicePath> servicePaths = new ArrayList<>(); final ServicePathBuilder servicePathBuilder = new ServicePathBuilder(); servicePathBuilder.setKey(new ServicePathKey(renderedServicePath.getPathId())) .setServicePathId(renderedServicePath.getPathId()) .setConfigServiceChainPathMode(new ConfigServiceChainPathModeBuilder() .setServiceIndex(new ServiceIndexBuilder() .setServices(services).build()).build()); servicePaths.add(servicePathBuilder.build()); final ServiceChainBuilder chainBuilder = new ServiceChainBuilder(); chainBuilder.setServicePath(servicePaths); final ServiceChain serviceChain = chainBuilder.build(); boolean scResult = PolicyWriterUtil.writeServicePath(serviceChain, location); context.setFutureResult(Futures.immediateCheckedFuture(scResult)); } return true; }).orElseGet(createNegativePathWithLogSupplier(sffName.getValue(), (value) -> LOG.error("Cannot create remote forwarder, SFF {} does not contain management ip address", value)) ); } return false; }
ServiceChainingUtil { public static boolean resolveRemoteSfcComponents(final RenderedServicePath renderedServicePath, final PolicyConfigurationContext context) { final PolicyManagerImpl.PolicyMapLocation location = context.getPolicyMapLocation(); final ServiceFunctionForwarder forwarder = getFirstHopSff(renderedServicePath); if (forwarder == null) { return false; } final SffName sffName = forwarder.getName(); if (forwarder.getSffDataPlaneLocator() == null || forwarder.getSffDataPlaneLocator().isEmpty()) { LOG.warn("Service function forwarder {} does not contain data plane locator", sffName.getValue()); return false; } final SffDataPlaneLocator sffDataPlaneLocator = forwarder.getSffDataPlaneLocator().get(0); final DataPlaneLocator dataPlaneLocator = sffDataPlaneLocator.getDataPlaneLocator(); final LocatorType locatorType = dataPlaneLocator.getLocatorType(); if (locatorType != null && locatorType instanceof Ip) { final IpAddress remoteForwarderIpAddress = (((Ip) locatorType).getIp()); if (remoteForwarderIpAddress == null || remoteForwarderIpAddress.getIpv4Address() == null) { LOG.warn("Service function forwarder {} data plane locator does not contain ip address", sffName.getValue()); return false; } final String remoteForwarderStringIp = remoteForwarderIpAddress.getIpv4Address().getValue(); final java.util.Optional<IpAddress> optionalIpMgmtAddress = java.util.Optional.ofNullable(forwarder.getIpMgmtAddress()); return optionalIpMgmtAddress.map(IpAddress::getIpv4Address) .map(Ipv4Address::getValue) .map(addressValue -> { final ServiceTypeChoice serviceTypeChoice; if (!addressValue.equals(location.getManagementIpAddress())) { final ServiceFfNameBuilder remoteSffBuilder = new ServiceFfNameBuilder(); remoteSffBuilder.setName(sffName.getValue()) .setKey(new ServiceFfNameKey(sffName.getValue())) .setIp(new IpBuilder().setAddress(new Ipv4Address(remoteForwarderStringIp)).build()); boolean rsResult = PolicyWriterUtil.writeRemote(remoteSffBuilder.build(), location); context.setFutureResult(Futures.immediateCheckedFuture(rsResult)); serviceTypeChoice = createForwarderTypeChoice(sffName.getValue()); final List<Services> services = new ArrayList<>(); final ServicesBuilder servicesBuilder = new ServicesBuilder(); servicesBuilder.setServiceIndexId(renderedServicePath.getStartingIndex()) .setServiceTypeChoice(serviceTypeChoice); services.add(servicesBuilder.build()); final List<ServicePath> servicePaths = new ArrayList<>(); final ServicePathBuilder servicePathBuilder = new ServicePathBuilder(); servicePathBuilder.setKey(new ServicePathKey(renderedServicePath.getPathId())) .setServicePathId(renderedServicePath.getPathId()) .setConfigServiceChainPathMode(new ConfigServiceChainPathModeBuilder() .setServiceIndex(new ServiceIndexBuilder() .setServices(services).build()).build()); servicePaths.add(servicePathBuilder.build()); final ServiceChainBuilder chainBuilder = new ServiceChainBuilder(); chainBuilder.setServicePath(servicePaths); final ServiceChain serviceChain = chainBuilder.build(); boolean scResult = PolicyWriterUtil.writeServicePath(serviceChain, location); context.setFutureResult(Futures.immediateCheckedFuture(scResult)); } return true; }).orElseGet(createNegativePathWithLogSupplier(sffName.getValue(), (value) -> LOG.error("Cannot create remote forwarder, SFF {} does not contain management ip address", value)) ); } return false; } }
ServiceChainingUtil { public static boolean resolveRemoteSfcComponents(final RenderedServicePath renderedServicePath, final PolicyConfigurationContext context) { final PolicyManagerImpl.PolicyMapLocation location = context.getPolicyMapLocation(); final ServiceFunctionForwarder forwarder = getFirstHopSff(renderedServicePath); if (forwarder == null) { return false; } final SffName sffName = forwarder.getName(); if (forwarder.getSffDataPlaneLocator() == null || forwarder.getSffDataPlaneLocator().isEmpty()) { LOG.warn("Service function forwarder {} does not contain data plane locator", sffName.getValue()); return false; } final SffDataPlaneLocator sffDataPlaneLocator = forwarder.getSffDataPlaneLocator().get(0); final DataPlaneLocator dataPlaneLocator = sffDataPlaneLocator.getDataPlaneLocator(); final LocatorType locatorType = dataPlaneLocator.getLocatorType(); if (locatorType != null && locatorType instanceof Ip) { final IpAddress remoteForwarderIpAddress = (((Ip) locatorType).getIp()); if (remoteForwarderIpAddress == null || remoteForwarderIpAddress.getIpv4Address() == null) { LOG.warn("Service function forwarder {} data plane locator does not contain ip address", sffName.getValue()); return false; } final String remoteForwarderStringIp = remoteForwarderIpAddress.getIpv4Address().getValue(); final java.util.Optional<IpAddress> optionalIpMgmtAddress = java.util.Optional.ofNullable(forwarder.getIpMgmtAddress()); return optionalIpMgmtAddress.map(IpAddress::getIpv4Address) .map(Ipv4Address::getValue) .map(addressValue -> { final ServiceTypeChoice serviceTypeChoice; if (!addressValue.equals(location.getManagementIpAddress())) { final ServiceFfNameBuilder remoteSffBuilder = new ServiceFfNameBuilder(); remoteSffBuilder.setName(sffName.getValue()) .setKey(new ServiceFfNameKey(sffName.getValue())) .setIp(new IpBuilder().setAddress(new Ipv4Address(remoteForwarderStringIp)).build()); boolean rsResult = PolicyWriterUtil.writeRemote(remoteSffBuilder.build(), location); context.setFutureResult(Futures.immediateCheckedFuture(rsResult)); serviceTypeChoice = createForwarderTypeChoice(sffName.getValue()); final List<Services> services = new ArrayList<>(); final ServicesBuilder servicesBuilder = new ServicesBuilder(); servicesBuilder.setServiceIndexId(renderedServicePath.getStartingIndex()) .setServiceTypeChoice(serviceTypeChoice); services.add(servicesBuilder.build()); final List<ServicePath> servicePaths = new ArrayList<>(); final ServicePathBuilder servicePathBuilder = new ServicePathBuilder(); servicePathBuilder.setKey(new ServicePathKey(renderedServicePath.getPathId())) .setServicePathId(renderedServicePath.getPathId()) .setConfigServiceChainPathMode(new ConfigServiceChainPathModeBuilder() .setServiceIndex(new ServiceIndexBuilder() .setServices(services).build()).build()); servicePaths.add(servicePathBuilder.build()); final ServiceChainBuilder chainBuilder = new ServiceChainBuilder(); chainBuilder.setServicePath(servicePaths); final ServiceChain serviceChain = chainBuilder.build(); boolean scResult = PolicyWriterUtil.writeServicePath(serviceChain, location); context.setFutureResult(Futures.immediateCheckedFuture(scResult)); } return true; }).orElseGet(createNegativePathWithLogSupplier(sffName.getValue(), (value) -> LOG.error("Cannot create remote forwarder, SFF {} does not contain management ip address", value)) ); } return false; } private  ServiceChainingUtil(); }
ServiceChainingUtil { public static boolean resolveRemoteSfcComponents(final RenderedServicePath renderedServicePath, final PolicyConfigurationContext context) { final PolicyManagerImpl.PolicyMapLocation location = context.getPolicyMapLocation(); final ServiceFunctionForwarder forwarder = getFirstHopSff(renderedServicePath); if (forwarder == null) { return false; } final SffName sffName = forwarder.getName(); if (forwarder.getSffDataPlaneLocator() == null || forwarder.getSffDataPlaneLocator().isEmpty()) { LOG.warn("Service function forwarder {} does not contain data plane locator", sffName.getValue()); return false; } final SffDataPlaneLocator sffDataPlaneLocator = forwarder.getSffDataPlaneLocator().get(0); final DataPlaneLocator dataPlaneLocator = sffDataPlaneLocator.getDataPlaneLocator(); final LocatorType locatorType = dataPlaneLocator.getLocatorType(); if (locatorType != null && locatorType instanceof Ip) { final IpAddress remoteForwarderIpAddress = (((Ip) locatorType).getIp()); if (remoteForwarderIpAddress == null || remoteForwarderIpAddress.getIpv4Address() == null) { LOG.warn("Service function forwarder {} data plane locator does not contain ip address", sffName.getValue()); return false; } final String remoteForwarderStringIp = remoteForwarderIpAddress.getIpv4Address().getValue(); final java.util.Optional<IpAddress> optionalIpMgmtAddress = java.util.Optional.ofNullable(forwarder.getIpMgmtAddress()); return optionalIpMgmtAddress.map(IpAddress::getIpv4Address) .map(Ipv4Address::getValue) .map(addressValue -> { final ServiceTypeChoice serviceTypeChoice; if (!addressValue.equals(location.getManagementIpAddress())) { final ServiceFfNameBuilder remoteSffBuilder = new ServiceFfNameBuilder(); remoteSffBuilder.setName(sffName.getValue()) .setKey(new ServiceFfNameKey(sffName.getValue())) .setIp(new IpBuilder().setAddress(new Ipv4Address(remoteForwarderStringIp)).build()); boolean rsResult = PolicyWriterUtil.writeRemote(remoteSffBuilder.build(), location); context.setFutureResult(Futures.immediateCheckedFuture(rsResult)); serviceTypeChoice = createForwarderTypeChoice(sffName.getValue()); final List<Services> services = new ArrayList<>(); final ServicesBuilder servicesBuilder = new ServicesBuilder(); servicesBuilder.setServiceIndexId(renderedServicePath.getStartingIndex()) .setServiceTypeChoice(serviceTypeChoice); services.add(servicesBuilder.build()); final List<ServicePath> servicePaths = new ArrayList<>(); final ServicePathBuilder servicePathBuilder = new ServicePathBuilder(); servicePathBuilder.setKey(new ServicePathKey(renderedServicePath.getPathId())) .setServicePathId(renderedServicePath.getPathId()) .setConfigServiceChainPathMode(new ConfigServiceChainPathModeBuilder() .setServiceIndex(new ServiceIndexBuilder() .setServices(services).build()).build()); servicePaths.add(servicePathBuilder.build()); final ServiceChainBuilder chainBuilder = new ServiceChainBuilder(); chainBuilder.setServicePath(servicePaths); final ServiceChain serviceChain = chainBuilder.build(); boolean scResult = PolicyWriterUtil.writeServicePath(serviceChain, location); context.setFutureResult(Futures.immediateCheckedFuture(scResult)); } return true; }).orElseGet(createNegativePathWithLogSupplier(sffName.getValue(), (value) -> LOG.error("Cannot create remote forwarder, SFF {} does not contain management ip address", value)) ); } return false; } private  ServiceChainingUtil(); static boolean resolveRemoteSfcComponents(final RenderedServicePath renderedServicePath,
                                                      final PolicyConfigurationContext context); static RenderedServicePath resolveReversedRenderedServicePath(final ServiceFunctionPath sfp, final TenantId tenantId,
                                                                          final DataBroker dataBroker, final Sgt sourceSgt,
                                                                          final Sgt destinationSgt, final PolicyConfigurationContext context); @VisibleForTesting static void setTimeout(long value); }
ServiceChainingUtil { public static boolean resolveRemoteSfcComponents(final RenderedServicePath renderedServicePath, final PolicyConfigurationContext context) { final PolicyManagerImpl.PolicyMapLocation location = context.getPolicyMapLocation(); final ServiceFunctionForwarder forwarder = getFirstHopSff(renderedServicePath); if (forwarder == null) { return false; } final SffName sffName = forwarder.getName(); if (forwarder.getSffDataPlaneLocator() == null || forwarder.getSffDataPlaneLocator().isEmpty()) { LOG.warn("Service function forwarder {} does not contain data plane locator", sffName.getValue()); return false; } final SffDataPlaneLocator sffDataPlaneLocator = forwarder.getSffDataPlaneLocator().get(0); final DataPlaneLocator dataPlaneLocator = sffDataPlaneLocator.getDataPlaneLocator(); final LocatorType locatorType = dataPlaneLocator.getLocatorType(); if (locatorType != null && locatorType instanceof Ip) { final IpAddress remoteForwarderIpAddress = (((Ip) locatorType).getIp()); if (remoteForwarderIpAddress == null || remoteForwarderIpAddress.getIpv4Address() == null) { LOG.warn("Service function forwarder {} data plane locator does not contain ip address", sffName.getValue()); return false; } final String remoteForwarderStringIp = remoteForwarderIpAddress.getIpv4Address().getValue(); final java.util.Optional<IpAddress> optionalIpMgmtAddress = java.util.Optional.ofNullable(forwarder.getIpMgmtAddress()); return optionalIpMgmtAddress.map(IpAddress::getIpv4Address) .map(Ipv4Address::getValue) .map(addressValue -> { final ServiceTypeChoice serviceTypeChoice; if (!addressValue.equals(location.getManagementIpAddress())) { final ServiceFfNameBuilder remoteSffBuilder = new ServiceFfNameBuilder(); remoteSffBuilder.setName(sffName.getValue()) .setKey(new ServiceFfNameKey(sffName.getValue())) .setIp(new IpBuilder().setAddress(new Ipv4Address(remoteForwarderStringIp)).build()); boolean rsResult = PolicyWriterUtil.writeRemote(remoteSffBuilder.build(), location); context.setFutureResult(Futures.immediateCheckedFuture(rsResult)); serviceTypeChoice = createForwarderTypeChoice(sffName.getValue()); final List<Services> services = new ArrayList<>(); final ServicesBuilder servicesBuilder = new ServicesBuilder(); servicesBuilder.setServiceIndexId(renderedServicePath.getStartingIndex()) .setServiceTypeChoice(serviceTypeChoice); services.add(servicesBuilder.build()); final List<ServicePath> servicePaths = new ArrayList<>(); final ServicePathBuilder servicePathBuilder = new ServicePathBuilder(); servicePathBuilder.setKey(new ServicePathKey(renderedServicePath.getPathId())) .setServicePathId(renderedServicePath.getPathId()) .setConfigServiceChainPathMode(new ConfigServiceChainPathModeBuilder() .setServiceIndex(new ServiceIndexBuilder() .setServices(services).build()).build()); servicePaths.add(servicePathBuilder.build()); final ServiceChainBuilder chainBuilder = new ServiceChainBuilder(); chainBuilder.setServicePath(servicePaths); final ServiceChain serviceChain = chainBuilder.build(); boolean scResult = PolicyWriterUtil.writeServicePath(serviceChain, location); context.setFutureResult(Futures.immediateCheckedFuture(scResult)); } return true; }).orElseGet(createNegativePathWithLogSupplier(sffName.getValue(), (value) -> LOG.error("Cannot create remote forwarder, SFF {} does not contain management ip address", value)) ); } return false; } private  ServiceChainingUtil(); static boolean resolveRemoteSfcComponents(final RenderedServicePath renderedServicePath,
                                                      final PolicyConfigurationContext context); static RenderedServicePath resolveReversedRenderedServicePath(final ServiceFunctionPath sfp, final TenantId tenantId,
                                                                          final DataBroker dataBroker, final Sgt sourceSgt,
                                                                          final Sgt destinationSgt, final PolicyConfigurationContext context); @VisibleForTesting static void setTimeout(long value);  }