@Test public void testResolveRemovedChainAction_symmetricChainDirect() { final PolicyConfigurationContext context = new PolicyConfigurationContext(); context.setPolicyMapLocation(getLocation()); final ParameterValueBuilder parameterValueBuilder = new ParameterValueBuilder(); parameterValueBuilder.setName(new ParameterName(SFC_CHAIN_NAME)).setStringValue(SFC_CHAIN_NAME); final ParameterValue parameterValue = parameterValueBuilder.build(); final ServiceFunctionPathBuilder pathBuilder = new ServiceFunctionPathBuilder(); pathBuilder.setName(new SfpName(SFC_PATH_NAME)).setServiceChainName(new SfcName(SFC_CHAIN_NAME)) .setSymmetric(true); final ServiceFunctionPathsBuilder pathsBuilder = new ServiceFunctionPathsBuilder(); pathsBuilder.setServiceFunctionPath(Collections.singletonList(pathBuilder.build())); final PeerEndpoint peerEndpoint = peerEndpointBuilder(); final Action action = actionBuilder(Collections.singletonList(parameterValue)); final RenderedServicePathHopBuilder hopBuilder = new RenderedServicePathHopBuilder(); hopBuilder.setServiceFunctionForwarder(new SffName(SERVICE_FUNCTION_FORWARDER)); final ServiceFunctionForwarderBuilder forwarder = new ServiceFunctionForwarderBuilder(); forwarder.setName(new SffName(SERVICE_FUNCTION_FORWARDER)) .setIpMgmtAddress(new IpAddress(new Ipv4Address(IP_ADDRESS))); stub(method(SfcProviderServicePathAPI.class, "readAllServiceFunctionPaths")).toReturn(pathsBuilder.build()); stub(method(PolicyWriterUtil.class, "removeClassMap")).toReturn(true); stub(method(PolicyWriterUtil.class, "removePolicyMapEntry")).toReturn(true); stub(method(PolicyWriterUtil.class, "removeServicePath")).toReturn(true); stub(method(PolicyWriterUtil.class, "removeRemote")).toReturn(true); ServiceChainingUtil.resolveRemovedChainAction(peerEndpoint, sgtBuilder(10), sgtBuilder(20), resolvedActionBuilder(new RuleName("rule-name"), CHAIN, action, Out), context); verifyStatic(times(1)); PolicyWriterUtil.removeClassMap(any(ClassMap.class), any(PolicyManagerImpl.PolicyMapLocation.class)); PolicyWriterUtil.removePolicyMapEntry(any(Class.class), any(PolicyManagerImpl.PolicyMapLocation.class)); PolicyWriterUtil.removeServicePath(any(ServiceChain.class), any(PolicyManagerImpl.PolicyMapLocation.class)); PolicyWriterUtil.removeRemote(any(ServiceFfName.class), any(PolicyManagerImpl.PolicyMapLocation.class)); }
static void resolveRemovedChainAction(final PeerEndpoint peerEndpoint, final Sgt sourceSgt, final Sgt destinationSgt, final Map<ActionCase, ActionInDirection> actionMap, final PolicyConfigurationContext context) { final ActionInDirection actionInDirection = actionMap.get(ActionCase.CHAIN); final Action action = actionInDirection.getAction(); final EndpointPolicyParticipation participation = actionInDirection.getParticipation(); final Direction direction = actionInDirection.getDirection(); final ServiceFunctionPath servicePath = ServiceChainingUtil.findServicePathFromParameterValues(action.getParameterValue()); if (servicePath == null || servicePath.getName() == null) { return; } final TenantId tenantId = getTenantId(peerEndpoint); if (tenantId == null) { return; } if ((participation.equals(PROVIDER) && direction.equals(Out)) || (participation.equals(CONSUMER) && direction.equals(In))) { final RspName rspName = generateRspName(servicePath, tenantId); resolveRemovedRenderedServicePath(rspName, sourceSgt, destinationSgt, context); } else if (servicePath.isSymmetric()) { final RspName rspName = generateReversedRspName(servicePath, tenantId); resolveRemovedRenderedServicePath(rspName, sourceSgt, destinationSgt, context); } }
ServiceChainingUtil { static void resolveRemovedChainAction(final PeerEndpoint peerEndpoint, final Sgt sourceSgt, final Sgt destinationSgt, final Map<ActionCase, ActionInDirection> actionMap, final PolicyConfigurationContext context) { final ActionInDirection actionInDirection = actionMap.get(ActionCase.CHAIN); final Action action = actionInDirection.getAction(); final EndpointPolicyParticipation participation = actionInDirection.getParticipation(); final Direction direction = actionInDirection.getDirection(); final ServiceFunctionPath servicePath = ServiceChainingUtil.findServicePathFromParameterValues(action.getParameterValue()); if (servicePath == null || servicePath.getName() == null) { return; } final TenantId tenantId = getTenantId(peerEndpoint); if (tenantId == null) { return; } if ((participation.equals(PROVIDER) && direction.equals(Out)) || (participation.equals(CONSUMER) && direction.equals(In))) { final RspName rspName = generateRspName(servicePath, tenantId); resolveRemovedRenderedServicePath(rspName, sourceSgt, destinationSgt, context); } else if (servicePath.isSymmetric()) { final RspName rspName = generateReversedRspName(servicePath, tenantId); resolveRemovedRenderedServicePath(rspName, sourceSgt, destinationSgt, context); } } }
ServiceChainingUtil { static void resolveRemovedChainAction(final PeerEndpoint peerEndpoint, final Sgt sourceSgt, final Sgt destinationSgt, final Map<ActionCase, ActionInDirection> actionMap, final PolicyConfigurationContext context) { final ActionInDirection actionInDirection = actionMap.get(ActionCase.CHAIN); final Action action = actionInDirection.getAction(); final EndpointPolicyParticipation participation = actionInDirection.getParticipation(); final Direction direction = actionInDirection.getDirection(); final ServiceFunctionPath servicePath = ServiceChainingUtil.findServicePathFromParameterValues(action.getParameterValue()); if (servicePath == null || servicePath.getName() == null) { return; } final TenantId tenantId = getTenantId(peerEndpoint); if (tenantId == null) { return; } if ((participation.equals(PROVIDER) && direction.equals(Out)) || (participation.equals(CONSUMER) && direction.equals(In))) { final RspName rspName = generateRspName(servicePath, tenantId); resolveRemovedRenderedServicePath(rspName, sourceSgt, destinationSgt, context); } else if (servicePath.isSymmetric()) { final RspName rspName = generateReversedRspName(servicePath, tenantId); resolveRemovedRenderedServicePath(rspName, sourceSgt, destinationSgt, context); } } private  ServiceChainingUtil(); }
ServiceChainingUtil { static void resolveRemovedChainAction(final PeerEndpoint peerEndpoint, final Sgt sourceSgt, final Sgt destinationSgt, final Map<ActionCase, ActionInDirection> actionMap, final PolicyConfigurationContext context) { final ActionInDirection actionInDirection = actionMap.get(ActionCase.CHAIN); final Action action = actionInDirection.getAction(); final EndpointPolicyParticipation participation = actionInDirection.getParticipation(); final Direction direction = actionInDirection.getDirection(); final ServiceFunctionPath servicePath = ServiceChainingUtil.findServicePathFromParameterValues(action.getParameterValue()); if (servicePath == null || servicePath.getName() == null) { return; } final TenantId tenantId = getTenantId(peerEndpoint); if (tenantId == null) { return; } if ((participation.equals(PROVIDER) && direction.equals(Out)) || (participation.equals(CONSUMER) && direction.equals(In))) { final RspName rspName = generateRspName(servicePath, tenantId); resolveRemovedRenderedServicePath(rspName, sourceSgt, destinationSgt, context); } else if (servicePath.isSymmetric()) { final RspName rspName = generateReversedRspName(servicePath, tenantId); resolveRemovedRenderedServicePath(rspName, sourceSgt, destinationSgt, context); } } 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 { static void resolveRemovedChainAction(final PeerEndpoint peerEndpoint, final Sgt sourceSgt, final Sgt destinationSgt, final Map<ActionCase, ActionInDirection> actionMap, final PolicyConfigurationContext context) { final ActionInDirection actionInDirection = actionMap.get(ActionCase.CHAIN); final Action action = actionInDirection.getAction(); final EndpointPolicyParticipation participation = actionInDirection.getParticipation(); final Direction direction = actionInDirection.getDirection(); final ServiceFunctionPath servicePath = ServiceChainingUtil.findServicePathFromParameterValues(action.getParameterValue()); if (servicePath == null || servicePath.getName() == null) { return; } final TenantId tenantId = getTenantId(peerEndpoint); if (tenantId == null) { return; } if ((participation.equals(PROVIDER) && direction.equals(Out)) || (participation.equals(CONSUMER) && direction.equals(In))) { final RspName rspName = generateRspName(servicePath, tenantId); resolveRemovedRenderedServicePath(rspName, sourceSgt, destinationSgt, context); } else if (servicePath.isSymmetric()) { final RspName rspName = generateReversedRspName(servicePath, tenantId); resolveRemovedRenderedServicePath(rspName, sourceSgt, destinationSgt, context); } } 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);  }