Move utility function to common place. 49/17149/2
authorThomas Bachman <tbachman@yahoo.com>
Thu, 26 Mar 2015 11:56:58 +0000 (07:56 -0400)
committerThomas Bachman <tbachman@yahoo.com>
Thu, 26 Mar 2015 12:06:15 +0000 (08:06 -0400)
The utility function is helpful byeond just the flow
table use cases.

Change-Id: If1578fe6dd680b956d1be5bb6609987cdbaff2ad
Signed-off-by: Thomas Bachman <tbachman@yahoo.com>
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/FlowUtils.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/OfTable.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/DestinationMapperTest.java

index 4e6ab1d45dc5446e3b2e071d734a92437de2429a..9c749e3bbd139e0b5973e681117b8b950e1243ab 100644 (file)
@@ -651,5 +651,18 @@ public final class FlowUtils {
                 .build());
         return emb.build();
     }
+
+    /**
+     * Parse an OF port number from a node connector ID
+     * @param id the ID
+     * @return the port number
+     */
+    public static long getOfPortNum(NodeConnectorId id) {
+        String cnid = id.getValue();
+        int ci = cnid.lastIndexOf(':');
+        if (ci < 0 || (ci+1 >= cnid.length()))
+            throw new NumberFormatException("Invalid node connector ID " + cnid);
+        return Long.parseLong(cnid.substring(ci+1));
+    }
 }
 
index 3e89608ec44158361832ad8f73b5b75b104e7c5a..e9d5255979abd403fbf5a0a0cc2b6515ac6cd08d 100644 (file)
@@ -18,7 +18,6 @@ import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager.Dirty;
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.SwitchManager;
 import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
 import org.opendaylight.groupbasedpolicy.resolver.PolicyResolver;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -87,21 +86,4 @@ public abstract class OfTable {
     public abstract void update(NodeId nodeId, 
                                 PolicyInfo policyInfo,
                                 Dirty dirty) throws Exception;
-    
-    // ***************
-    // Utility methods
-    // ***************
-
-    /**
-     * Parse an OF port number from a node connector ID
-     * @param id the ID
-     * @return the port number
-     */
-    protected static long getOfPortNum(NodeConnectorId id) {
-        String cnid = id.getValue();
-        int ci = cnid.lastIndexOf(':');
-        if (ci < 0 || (ci+1 >= cnid.length()))
-            throw new NumberFormatException("Invalid node connector ID " + cnid);
-        return Long.parseLong(cnid.substring(ci+1));
-    }
 }
index 5ef124521415e644ed6fa6e82020ff8bcf9b6715..9adcd9c3140a1711f77efcf2337fd9a6317993ef 100644 (file)
@@ -131,7 +131,7 @@ public class DestinationMapperTest extends FlowTableTest {
                 int icount = 0;
                 for (Instruction ins : f.getInstructions().getInstruction()) {
                     if (ins.getInstruction() instanceof ApplyActionsCase) {
-                        long p = OfTable.getOfPortNum(nodeConnectorId);
+                        long p = getOfPortNum(nodeConnectorId);
                         List<Action> actions = ((ApplyActionsCase)ins.getInstruction()).getApplyActions().getAction();
                         assertEquals(nxLoadRegAction(NxmNxReg7.class,
                                                      BigInteger.valueOf(p)),
@@ -152,7 +152,7 @@ public class DestinationMapperTest extends FlowTableTest {
                 int icount = 0;
                 for (Instruction ins : f.getInstructions().getInstruction()) {
                     if (ins.getInstruction() instanceof ApplyActionsCase) {
-                        long p = OfTable.getOfPortNum(tunnelId);
+                        long p = getOfPortNum(tunnelId);
                         List<Action> actions = ((ApplyActionsCase)ins.getInstruction()).getApplyActions().getAction();
                         assertEquals(nxLoadRegAction(NxmNxReg7.class,
                                                      BigInteger.valueOf(p)),
@@ -177,7 +177,7 @@ public class DestinationMapperTest extends FlowTableTest {
                     Instruction ins = f.getInstructions().getInstruction().get(0);
                     assertTrue(ins.getInstruction() instanceof ApplyActionsCase);
                     List<Action> actions = ((ApplyActionsCase)ins.getInstruction()).getApplyActions().getAction();
-                    long p = OfTable.getOfPortNum(nodeConnectorId);
+                    long p = getOfPortNum(nodeConnectorId);
                     assertEquals(nxLoadRegAction(NxmNxReg7.class,
                                                  BigInteger.valueOf(p)),
                                  actions.get(2).getAction());
@@ -198,7 +198,7 @@ public class DestinationMapperTest extends FlowTableTest {
                     Instruction ins = f.getInstructions().getInstruction().get(0);
                     assertTrue(ins.getInstruction() instanceof ApplyActionsCase);
                     List<Action> actions = ((ApplyActionsCase)ins.getInstruction()).getApplyActions().getAction();
-                    long p = OfTable.getOfPortNum(tunnelId);
+                    long p = getOfPortNum(tunnelId);
                     assertEquals(nxLoadRegAction(NxmNxReg7.class,
                                                  BigInteger.valueOf(p)),
                                  actions.get(4).getAction());