Fix for incorrect RspName from SfpName 12/29412/4
authorKeith Burns (alagalah) <alagalah@gmail.com>
Sat, 7 Nov 2015 19:50:19 +0000 (11:50 -0800)
committerMartin Sunal <msunal@cisco.com>
Thu, 26 Nov 2015 19:35:27 +0000 (19:35 +0000)
- added Tenant ID for unique RSP

Change-Id: I882c43e5d6856eaa51f8e408a7353ee8878fe826
Signed-off-by: Keith Burns (alagalah) <alagalah@gmail.com>
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/sf/ChainAction.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/sf/ChainActionTest.java

index d043f263982facfa561c43d8bd9b862520ff51c2..8e423638e29fb4a45a712f5c65c8ebe3474ddbe0 100755 (executable)
@@ -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<RenderedServicePath> optRsp = DataStoreHelper.readFromDs(LogicalDatastoreType.OPERATIONAL,
-                SfcIidFactory.rspIid(rspName), rTx);
+        Optional<RenderedServicePath> optRsp =
+                DataStoreHelper.readFromDs(LogicalDatastoreType.OPERATIONAL, SfcIidFactory.rspIid(rspName), rTx);
         if (optRsp.isPresent()) {
             return optRsp.get();
         }
index 42f39392bbad1ad8d0b4f9384e44a1784d77cac4..7d316647e57fa427a8e9bf7d612ce5a7083c1764 100755 (executable)
@@ -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<ActionBuilder> result = chainAction.updateAction(actions, params, order, netElements, policyPair,
-                ofWriter,
-                ctx, Direction.Out);
+        List<ActionBuilder> 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<ActionBuilder> result = chainAction.updateAction(actions, null, order, netElements, policyPair,
-                ofWriter,
-                ctx, Direction.In);
+        List<ActionBuilder> 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<ActionBuilder> result = chainAction.updateAction(actions, params, order, netElements, policyPair,
-                ofWriter,
-                ctx, Direction.Out);
+        List<ActionBuilder> 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));
     }
 }