@Test public void testResolveNewChainAction_noTenantId() { 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)); final ServiceFunctionPathsBuilder pathsBuilder = new ServiceFunctionPathsBuilder(); pathsBuilder.setServiceFunctionPath(Collections.singletonList(pathBuilder.build())); final PeerEndpoint peerEndpoint = peerEndpointBuilder(); final Action action = actionBuilder(Collections.singletonList(parameterValue)); final PolicyConfigurationContext context = policyConfigurationContextBuilder(); stub(method(SfcProviderServicePathAPI.class, "readAllServiceFunctionPaths")).toReturn(pathsBuilder.build()); stub(method(PolicyManagerUtil.class, "getTenantId")).toReturn(null); ServiceChainingUtil.newChainAction(peerEndpoint, sgtBuilder(10), sgtBuilder(20), resolvedActionBuilder(RULE_NAME, CHAIN, action, In), context, dataBroker); verifyNoMoreInteractions(policyWriterUtil); verifyNoMoreInteractions(dataBroker); }
static void newChainAction(final PeerEndpoint peerEndpoint, final Sgt sourceSgt, final Sgt destinationSgt, final Map<PolicyManagerImpl.ActionCase, ActionInDirection> actionMap, final PolicyConfigurationContext context, final DataBroker dataBroker) { final ActionInDirection actionInDirection = actionMap.get(ActionCase.CHAIN); if (actionInDirection == null) { return; } context.setCurrentUnconfiguredRule(new UnconfiguredResolvedRuleBuilder() .setRuleName(new RuleName(actionInDirection.getRuleName())).build()); 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) { final String info = String.format("service-path not found (sourceSgt=%s, destinationSgt=%s)", sourceSgt, destinationSgt); context.appendUnconfiguredRendererEP(StatusUtil.assembleNotConfigurableRendererEPForPeer(context, peerEndpoint, info)); return; } final TenantId tenantId = PolicyManagerUtil.getTenantId(peerEndpoint); if (tenantId == null) { final String info = String.format("tenant-id not found (sourceSgt=%s, destinationSgt=%s)", sourceSgt, destinationSgt); context.appendUnconfiguredRendererEP(StatusUtil.assembleNotConfigurableRendererEPForPeer(context, peerEndpoint, info)); return; } boolean sfcPartSuccessful = true; if ((participation.equals(PROVIDER) && direction.equals(Out)) || (participation.equals(CONSUMER) && direction.equals(In))) { final RenderedServicePath renderedServicePath = ServiceChainingUtil.resolveRenderedServicePath(servicePath, tenantId, dataBroker, sourceSgt, destinationSgt, context); sfcPartSuccessful = resolveRemoteSfcComponents(renderedServicePath, context); } else if (servicePath.isSymmetric()) { final RenderedServicePath renderedServicePath = ServiceChainingUtil.resolveReversedRenderedServicePath(servicePath, tenantId, dataBroker, sourceSgt, destinationSgt, context); sfcPartSuccessful = resolveRemoteSfcComponents(renderedServicePath, context); } if (!sfcPartSuccessful) { final String info = String.format("failed during sfc-part execution (sourceSgt=%s, destinationSgt=%s)", sourceSgt, destinationSgt); context.appendUnconfiguredRendererEP(StatusUtil.assembleNotConfigurableRendererEPForPeer(context, peerEndpoint, info)); } }
ServiceChainingUtil { static void newChainAction(final PeerEndpoint peerEndpoint, final Sgt sourceSgt, final Sgt destinationSgt, final Map<PolicyManagerImpl.ActionCase, ActionInDirection> actionMap, final PolicyConfigurationContext context, final DataBroker dataBroker) { final ActionInDirection actionInDirection = actionMap.get(ActionCase.CHAIN); if (actionInDirection == null) { return; } context.setCurrentUnconfiguredRule(new UnconfiguredResolvedRuleBuilder() .setRuleName(new RuleName(actionInDirection.getRuleName())).build()); 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) { final String info = String.format("service-path not found (sourceSgt=%s, destinationSgt=%s)", sourceSgt, destinationSgt); context.appendUnconfiguredRendererEP(StatusUtil.assembleNotConfigurableRendererEPForPeer(context, peerEndpoint, info)); return; } final TenantId tenantId = PolicyManagerUtil.getTenantId(peerEndpoint); if (tenantId == null) { final String info = String.format("tenant-id not found (sourceSgt=%s, destinationSgt=%s)", sourceSgt, destinationSgt); context.appendUnconfiguredRendererEP(StatusUtil.assembleNotConfigurableRendererEPForPeer(context, peerEndpoint, info)); return; } boolean sfcPartSuccessful = true; if ((participation.equals(PROVIDER) && direction.equals(Out)) || (participation.equals(CONSUMER) && direction.equals(In))) { final RenderedServicePath renderedServicePath = ServiceChainingUtil.resolveRenderedServicePath(servicePath, tenantId, dataBroker, sourceSgt, destinationSgt, context); sfcPartSuccessful = resolveRemoteSfcComponents(renderedServicePath, context); } else if (servicePath.isSymmetric()) { final RenderedServicePath renderedServicePath = ServiceChainingUtil.resolveReversedRenderedServicePath(servicePath, tenantId, dataBroker, sourceSgt, destinationSgt, context); sfcPartSuccessful = resolveRemoteSfcComponents(renderedServicePath, context); } if (!sfcPartSuccessful) { final String info = String.format("failed during sfc-part execution (sourceSgt=%s, destinationSgt=%s)", sourceSgt, destinationSgt); context.appendUnconfiguredRendererEP(StatusUtil.assembleNotConfigurableRendererEPForPeer(context, peerEndpoint, info)); } } }
ServiceChainingUtil { static void newChainAction(final PeerEndpoint peerEndpoint, final Sgt sourceSgt, final Sgt destinationSgt, final Map<PolicyManagerImpl.ActionCase, ActionInDirection> actionMap, final PolicyConfigurationContext context, final DataBroker dataBroker) { final ActionInDirection actionInDirection = actionMap.get(ActionCase.CHAIN); if (actionInDirection == null) { return; } context.setCurrentUnconfiguredRule(new UnconfiguredResolvedRuleBuilder() .setRuleName(new RuleName(actionInDirection.getRuleName())).build()); 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) { final String info = String.format("service-path not found (sourceSgt=%s, destinationSgt=%s)", sourceSgt, destinationSgt); context.appendUnconfiguredRendererEP(StatusUtil.assembleNotConfigurableRendererEPForPeer(context, peerEndpoint, info)); return; } final TenantId tenantId = PolicyManagerUtil.getTenantId(peerEndpoint); if (tenantId == null) { final String info = String.format("tenant-id not found (sourceSgt=%s, destinationSgt=%s)", sourceSgt, destinationSgt); context.appendUnconfiguredRendererEP(StatusUtil.assembleNotConfigurableRendererEPForPeer(context, peerEndpoint, info)); return; } boolean sfcPartSuccessful = true; if ((participation.equals(PROVIDER) && direction.equals(Out)) || (participation.equals(CONSUMER) && direction.equals(In))) { final RenderedServicePath renderedServicePath = ServiceChainingUtil.resolveRenderedServicePath(servicePath, tenantId, dataBroker, sourceSgt, destinationSgt, context); sfcPartSuccessful = resolveRemoteSfcComponents(renderedServicePath, context); } else if (servicePath.isSymmetric()) { final RenderedServicePath renderedServicePath = ServiceChainingUtil.resolveReversedRenderedServicePath(servicePath, tenantId, dataBroker, sourceSgt, destinationSgt, context); sfcPartSuccessful = resolveRemoteSfcComponents(renderedServicePath, context); } if (!sfcPartSuccessful) { final String info = String.format("failed during sfc-part execution (sourceSgt=%s, destinationSgt=%s)", sourceSgt, destinationSgt); context.appendUnconfiguredRendererEP(StatusUtil.assembleNotConfigurableRendererEPForPeer(context, peerEndpoint, info)); } } private  ServiceChainingUtil(); }
ServiceChainingUtil { static void newChainAction(final PeerEndpoint peerEndpoint, final Sgt sourceSgt, final Sgt destinationSgt, final Map<PolicyManagerImpl.ActionCase, ActionInDirection> actionMap, final PolicyConfigurationContext context, final DataBroker dataBroker) { final ActionInDirection actionInDirection = actionMap.get(ActionCase.CHAIN); if (actionInDirection == null) { return; } context.setCurrentUnconfiguredRule(new UnconfiguredResolvedRuleBuilder() .setRuleName(new RuleName(actionInDirection.getRuleName())).build()); 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) { final String info = String.format("service-path not found (sourceSgt=%s, destinationSgt=%s)", sourceSgt, destinationSgt); context.appendUnconfiguredRendererEP(StatusUtil.assembleNotConfigurableRendererEPForPeer(context, peerEndpoint, info)); return; } final TenantId tenantId = PolicyManagerUtil.getTenantId(peerEndpoint); if (tenantId == null) { final String info = String.format("tenant-id not found (sourceSgt=%s, destinationSgt=%s)", sourceSgt, destinationSgt); context.appendUnconfiguredRendererEP(StatusUtil.assembleNotConfigurableRendererEPForPeer(context, peerEndpoint, info)); return; } boolean sfcPartSuccessful = true; if ((participation.equals(PROVIDER) && direction.equals(Out)) || (participation.equals(CONSUMER) && direction.equals(In))) { final RenderedServicePath renderedServicePath = ServiceChainingUtil.resolveRenderedServicePath(servicePath, tenantId, dataBroker, sourceSgt, destinationSgt, context); sfcPartSuccessful = resolveRemoteSfcComponents(renderedServicePath, context); } else if (servicePath.isSymmetric()) { final RenderedServicePath renderedServicePath = ServiceChainingUtil.resolveReversedRenderedServicePath(servicePath, tenantId, dataBroker, sourceSgt, destinationSgt, context); sfcPartSuccessful = resolveRemoteSfcComponents(renderedServicePath, context); } if (!sfcPartSuccessful) { final String info = String.format("failed during sfc-part execution (sourceSgt=%s, destinationSgt=%s)", sourceSgt, destinationSgt); context.appendUnconfiguredRendererEP(StatusUtil.assembleNotConfigurableRendererEPForPeer(context, peerEndpoint, info)); } } 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 newChainAction(final PeerEndpoint peerEndpoint, final Sgt sourceSgt, final Sgt destinationSgt, final Map<PolicyManagerImpl.ActionCase, ActionInDirection> actionMap, final PolicyConfigurationContext context, final DataBroker dataBroker) { final ActionInDirection actionInDirection = actionMap.get(ActionCase.CHAIN); if (actionInDirection == null) { return; } context.setCurrentUnconfiguredRule(new UnconfiguredResolvedRuleBuilder() .setRuleName(new RuleName(actionInDirection.getRuleName())).build()); 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) { final String info = String.format("service-path not found (sourceSgt=%s, destinationSgt=%s)", sourceSgt, destinationSgt); context.appendUnconfiguredRendererEP(StatusUtil.assembleNotConfigurableRendererEPForPeer(context, peerEndpoint, info)); return; } final TenantId tenantId = PolicyManagerUtil.getTenantId(peerEndpoint); if (tenantId == null) { final String info = String.format("tenant-id not found (sourceSgt=%s, destinationSgt=%s)", sourceSgt, destinationSgt); context.appendUnconfiguredRendererEP(StatusUtil.assembleNotConfigurableRendererEPForPeer(context, peerEndpoint, info)); return; } boolean sfcPartSuccessful = true; if ((participation.equals(PROVIDER) && direction.equals(Out)) || (participation.equals(CONSUMER) && direction.equals(In))) { final RenderedServicePath renderedServicePath = ServiceChainingUtil.resolveRenderedServicePath(servicePath, tenantId, dataBroker, sourceSgt, destinationSgt, context); sfcPartSuccessful = resolveRemoteSfcComponents(renderedServicePath, context); } else if (servicePath.isSymmetric()) { final RenderedServicePath renderedServicePath = ServiceChainingUtil.resolveReversedRenderedServicePath(servicePath, tenantId, dataBroker, sourceSgt, destinationSgt, context); sfcPartSuccessful = resolveRemoteSfcComponents(renderedServicePath, context); } if (!sfcPartSuccessful) { final String info = String.format("failed during sfc-part execution (sourceSgt=%s, destinationSgt=%s)", sourceSgt, destinationSgt); context.appendUnconfiguredRendererEP(StatusUtil.assembleNotConfigurableRendererEPForPeer(context, peerEndpoint, info)); } } 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);  }