From: Keith Burns (alagalah) Date: Sat, 7 Nov 2015 19:50:19 +0000 (-0800) Subject: Fix for incorrect RspName from SfpName X-Git-Tag: release/beryllium~64 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=253aa83df8d1fc44de9418bed7404752f10a02c8;p=groupbasedpolicy.git Fix for incorrect RspName from SfpName - added Tenant ID for unique RSP Change-Id: I882c43e5d6856eaa51f8e408a7353ee8878fe826 Signed-off-by: Keith Burns (alagalah) --- diff --git a/renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/sf/ChainAction.java b/renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/sf/ChainAction.java index d043f2639..8e423638e 100755 --- a/renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/sf/ChainAction.java +++ b/renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/sf/ChainAction.java @@ -17,14 +17,14 @@ import java.util.Map; import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.groupbasedpolicy.sf.actions.ChainActionDefinition; -import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter; import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext; +import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter; import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.PolicyEnforcer.NetworkElements; import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.PolicyEnforcer.PolicyPair; import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils.SfcIidFactory; import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils.SfcNshHeader; import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils.SfcNshHeader.SfcNshHeaderBuilder; +import org.opendaylight.groupbasedpolicy.sf.actions.ChainActionDefinition; import org.opendaylight.groupbasedpolicy.util.DataStoreHelper; import org.opendaylight.sfc.provider.api.SfcProviderRenderedPathAPI; import org.opendaylight.sfc.provider.api.SfcProviderServiceChainAPI; @@ -117,8 +117,12 @@ public class ChainAction extends Action { LOG.error("updateAction: SFC Path was invalid. Either null or name was null.", sfcPath); return null; } + // TODO Need helper function to get getTenantName() that returns Name or UUID if Name is + // null + + String tenantName = netElements.getSrcEp().getTenant().getValue(); // Find existing RSP based on following naming convention, else create it. - RspName rspName = new RspName(sfcPath.getName() + "-gbp-rsp"); + RspName rspName = new RspName(sfcPath.getName().getValue() + tenantName + "-gbp-rsp"); ReadOnlyTransaction rTx = ctx.getDataBroker().newReadOnlyTransaction(); RenderedServicePath renderedServicePath; RenderedServicePath rsp = getRspByName(rspName, rTx); @@ -135,7 +139,7 @@ public class ChainAction extends Action { } try { - if (sfcPath.isSymmetric() && direction.equals(Direction.Out)){ + if (sfcPath.isSymmetric() && direction.equals(Direction.Out)) { rspName = new RspName(rspName.getValue() + "-Reverse"); rsp = getRspByName(rspName, rTx); if (rsp == null) { @@ -150,7 +154,8 @@ public class ChainAction extends Action { } } } catch (Exception e) { - LOG.error("updateAction: Attemping to determine if srcEp {} was consumer.", netElements.getSrcEp().getKey(), e); + LOG.error("updateAction: Attemping to determine if srcEp {} was consumer.", netElements.getSrcEp().getKey(), + e); return null; } @@ -160,7 +165,7 @@ public class ChainAction extends Action { return null; } - NodeId tunnelDestNodeId=netElements.getDstNodeId(); + NodeId tunnelDestNodeId = netElements.getDstNodeId(); Long returnVnid = (long) netElements.getSrcEpOrds().getTunnelId(); @@ -193,12 +198,12 @@ public class ChainAction extends Action { } private RenderedServicePath createRsp(ServiceFunctionPath sfcPath, RspName rspName) { - CreateRenderedPathInput rspInput = new CreateRenderedPathInputBuilder().setParentServiceFunctionPath( - sfcPath.getName().getValue()) - .setName(rspName.getValue()) - .setSymmetric(sfcPath.isSymmetric()) - .build(); - return SfcProviderRenderedPathAPI.createRenderedServicePathAndState(sfcPath, rspInput); + CreateRenderedPathInput rspInput = + new CreateRenderedPathInputBuilder().setParentServiceFunctionPath(sfcPath.getName().getValue()) + .setName(rspName.getValue()) + .setSymmetric(sfcPath.isSymmetric()) + .build(); + return SfcProviderRenderedPathAPI.createRenderedServicePathAndState(sfcPath, rspInput); } private RenderedServicePath createSymmetricRsp(RenderedServicePath rsp) { @@ -235,8 +240,8 @@ public class ChainAction extends Action { } private RenderedServicePath getRspByName(RspName rspName, ReadOnlyTransaction rTx) { - Optional optRsp = DataStoreHelper.readFromDs(LogicalDatastoreType.OPERATIONAL, - SfcIidFactory.rspIid(rspName), rTx); + Optional optRsp = + DataStoreHelper.readFromDs(LogicalDatastoreType.OPERATIONAL, SfcIidFactory.rspIid(rspName), rTx); if (optRsp.isPresent()) { return optRsp.get(); } diff --git a/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/sf/ChainActionTest.java b/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/sf/ChainActionTest.java index 42f39392b..7d316647e 100755 --- a/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/sf/ChainActionTest.java +++ b/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/sf/ChainActionTest.java @@ -41,6 +41,7 @@ import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.common.rev1 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.paths.RenderedServicePath; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.service.function.paths.ServiceFunctionPath; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.HasDirection.Direction; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.subject.feature.instances.ActionInstance; @@ -68,6 +69,7 @@ public class ChainActionTest { private PolicyPair policyPair; private EndpointManager endpointManager; private EgKey egKey; + private TenantId tenant = new TenantId("e09a2308-6ffa-40af-92a2-69f54b2cf3e4"); @SuppressWarnings("unchecked") @Before @@ -98,6 +100,7 @@ public class ChainActionTest { when(netElements.getSrcEpOrds()).thenReturn(endpointFwdCtxOrdinals); endpoint = mock(Endpoint.class); when(netElements.getSrcEp()).thenReturn(endpoint); + when(netElements.getSrcEp().getTenant()).thenReturn(tenant); policyPair = mock(PolicyPair.class); when(policyPair.getConsumerEpgId()).thenReturn(Integer.valueOf(5)); @@ -127,9 +130,8 @@ public class ChainActionTest { doReturn(sfcPath).when(chainAction).getSfcPath(new SfcName(chainName)); - List result = chainAction.updateAction(actions, params, order, netElements, policyPair, - ofWriter, - ctx, Direction.Out); + List result = + chainAction.updateAction(actions, params, order, netElements, policyPair, ofWriter, ctx, Direction.Out); Assert.assertNull(result); } @@ -140,9 +142,8 @@ public class ChainActionTest { Integer order = Integer.valueOf(0); OfWriter ofWriter = mock(OfWriter.class); - List result = chainAction.updateAction(actions, null, order, netElements, policyPair, - ofWriter, - ctx, Direction.In); + List result = + chainAction.updateAction(actions, null, order, netElements, policyPair, ofWriter, ctx, Direction.In); Assert.assertNull(result); } @@ -173,15 +174,14 @@ public class ChainActionTest { doReturn(sfcPath).when(chainAction).getSfcPath(new SfcName(chainName)); when(sfcPath.getName()).thenReturn(null); - List result = chainAction.updateAction(actions, params, order, netElements, policyPair, - ofWriter, - ctx, Direction.Out); + List result = + chainAction.updateAction(actions, params, order, netElements, policyPair, ofWriter, ctx, Direction.Out); Assert.assertNull(result); } - @Test + @Test public void isValidTestParameterValueNull() { - ActionInstance actionInstance = mock(ActionInstance.class); - Assert.assertFalse(chainAction.isValid(actionInstance)); + ActionInstance actionInstance = mock(ActionInstance.class); + Assert.assertFalse(chainAction.isValid(actionInstance)); } }