Moving TableIds into a single constants file
[vpnservice.git] / fibmanager / fibmanager-impl / src / main / java / org / opendaylight / vpnservice / fibmanager / FibManager.java
index 1db29e16814cc0856e6ab73a862db83b3a0361b0..7adde2c47d7fb3d6dae78c6b9ba79bd96f774747 100644 (file)
@@ -82,13 +82,6 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
   private NexthopManager nextHopManager;
   private ItmRpcService itmManager;
   private OdlInterfaceRpcService interfaceManager;
-
-  private static final short L3_FIB_TABLE = 21;
-  private static final short L3_LFIB_TABLE = 20;
-  public static final short INTERNAL_TUNNEL_TABLE = 23;
-  private static final short L3_PROTOCOL_TABLE = 36;
-  private static final short L3_INTERFACE_TABLE = 80;
-  public static final short LPORT_DISPATCHER_TABLE = 30;
   private static final BigInteger COOKIE_VM_LFIB_TABLE = new BigInteger("8000002", 16);
   private static final BigInteger COOKIE_VM_FIB_TABLE =  new BigInteger("8000003", 16);
   private static final int DEFAULT_FIB_FLOW_PRIORITY = 10;
@@ -213,9 +206,9 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
     Preconditions.checkNotNull(vpnInstance.getVpnId(), "Vpn Instance with rd " + vpnInstance.getVrfId() + "has null vpnId!");
 
     Collection<VpnToDpnList> vpnToDpnList = vpnInstance.getVpnToDpnList();
+    BigInteger localDpnId = createLocalFibEntry(vpnInstance.getVpnId(),
+              vrfTableKey.getRouteDistinguisher(), vrfEntry);
     if (vpnToDpnList != null) {
-      BigInteger localDpnId = createLocalFibEntry(vpnInstance.getVpnId(),
-                          vrfTableKey.getRouteDistinguisher(), vrfEntry);
       for (VpnToDpnList curDpn : vpnToDpnList) {
         if (!curDpn.getDpnId().equals(localDpnId)) {
           createRemoteFibEntry(localDpnId, curDpn.getDpnId(), vpnInstance.getVpnId(),
@@ -272,15 +265,14 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
       LOG.info("create terminatingServiceAction on DpnId = {} and serviceId = {} and actions = {}", destDpId , label,actionsInfos);
 
       // Matching metadata
-      mkMatches.add(new MatchInfo(MatchFieldType.tunnel_id, new BigInteger[] {
-                                  MetaDataUtil.getTunnelIdWithValidVniBitAndVniSet(label),
-                                  MetaDataUtil.METADA_MASK_TUNNEL_ID }));
+      // FIXME vxlan vni bit set is not working properly with OVS.need to revisit
+      mkMatches.add(new MatchInfo(MatchFieldType.tunnel_id, new BigInteger[] {BigInteger.valueOf(label)}));
 
       List<InstructionInfo> mkInstructions = new ArrayList<InstructionInfo>();
       mkInstructions.add(new InstructionInfo(InstructionType.write_actions, actionsInfos));
 
-      FlowEntity terminatingServiceTableFlowEntity = MDSALUtil.buildFlowEntity(destDpId, INTERNAL_TUNNEL_TABLE,
-                      getFlowRef(destDpId, INTERNAL_TUNNEL_TABLE,label), 5, String.format("%s:%d","TST Flow Entry ",label),
+      FlowEntity terminatingServiceTableFlowEntity = MDSALUtil.buildFlowEntity(destDpId, NwConstants.INTERNAL_TUNNEL_TABLE,
+                      getFlowRef(destDpId, NwConstants.INTERNAL_TUNNEL_TABLE,label), 5, String.format("%s:%d","TST Flow Entry ",label),
                       0, 0, COOKIE_TUNNEL.add(BigInteger.valueOf(label)),mkMatches, mkInstructions);
 
       mdsalManager.installFlow(terminatingServiceTableFlowEntity);
@@ -295,8 +287,8 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
         MetaDataUtil.getTunnelIdWithValidVniBitAndVniSet((int)label),
         MetaDataUtil.METADA_MASK_TUNNEL_ID }));
     flowEntity = MDSALUtil.buildFlowEntity(dpId,
-                                           INTERNAL_TUNNEL_TABLE,
-                                           getFlowRef(dpId, INTERNAL_TUNNEL_TABLE, (int)label),
+                                           NwConstants.INTERNAL_TUNNEL_TABLE,
+                                           getFlowRef(dpId, NwConstants.INTERNAL_TUNNEL_TABLE, (int)label),
                                            5, String.format("%s:%d","TST Flow Entry ",label), 0, 0,
                                            COOKIE_TUNNEL.add(BigInteger.valueOf(label)), mkMatches, null);
     mdsalManager.removeFlow(flowEntity);
@@ -372,7 +364,7 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
                              vrfEntry.getDestPrefix(), rd);
       return;
     }
-        List<ActionInfo> actionInfos = nextHopManager.getEgressActionsForInterface(tunnelInterface);
+      List<ActionInfo> actionInfos = new ArrayList<>();
        Class<? extends TunnelTypeBase> tunnel_type = getTunnelType(tunnelInterface);
     if (tunnel_type.equals(TunnelTypeMplsOverGre.class)) {
         LOG.debug("Push label action for prefix {}", vrfEntry.getDestPrefix());
@@ -381,15 +373,17 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
     } else {
         int label = vrfEntry.getLabel().intValue();
         BigInteger tunnelId;
+        // FIXME vxlan vni bit set is not working properly with OVS.need to revisit
         if(tunnel_type.equals(TunnelTypeVxlan.class)) {
-               tunnelId = MetaDataUtil.getTunnelIdWithValidVniBitAndVniSet(label);
+               tunnelId = BigInteger.valueOf(label);
         } else {
                tunnelId = BigInteger.valueOf(label);
         }
         LOG.debug("adding set tunnel id action for label {}", label);
-        actionInfos.add(new ActionInfo(ActionType.set_field_tunnel_id, new BigInteger[] {
-                       tunnelId}));
+        actionInfos.add(new ActionInfo(ActionType.set_field_tunnel_id, new BigInteger[]{
+                tunnelId}));
     }
+    actionInfos.addAll(nextHopManager.getEgressActionsForInterface(tunnelInterface));
 /*
     List<ActionInfo> actionInfos = resolveAdjacency(localDpnId, remoteDpnId, vpnId, vrfEntry);
     if(actionInfos == null) {
@@ -417,7 +411,7 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
                 MetaDataUtil.METADA_MASK_VALID_TUNNEL_ID_BIT_AND_TUNNEL_ID }));
     }
 **/
-    makeConnectedRoute(remoteDpnId, vpnId, vrfEntry, rd, actionInfos, NwConstants.ADD_FLOW);
+      makeConnectedRoute(remoteDpnId, vpnId, vrfEntry, rd, actionInfos, NwConstants.ADD_FLOW);
     LOG.debug(
         "Successfully added fib entry for " + vrfEntry.getDestPrefix() + " vpnId " + vpnId);
   }
@@ -431,9 +425,9 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
     VpnInstanceOpDataEntry vpnInstance = getVpnInstance(vrfTableKey.getRouteDistinguisher());
     Preconditions.checkNotNull(vpnInstance, "Vpn Instance not available!");
     Collection<VpnToDpnList> vpnToDpnList = vpnInstance.getVpnToDpnList();
+    BigInteger localDpnId = deleteLocalFibEntry(vpnInstance.getVpnId(),
+              vrfTableKey.getRouteDistinguisher(), vrfEntry);
     if (vpnToDpnList != null) {
-      BigInteger localDpnId = deleteLocalFibEntry(vpnInstance.getVpnId(),
-                          vrfTableKey.getRouteDistinguisher(), vrfEntry);
       for (VpnToDpnList curDpn : vpnToDpnList) {
         if (!curDpn.getDpnId().equals(localDpnId)) {
           deleteRemoteRoute(localDpnId, curDpn.getDpnId(), vpnInstance.getVpnId(), vrfTableKey, vrfEntry);
@@ -499,12 +493,12 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
       instructions.add(new InstructionInfo(InstructionType.write_actions, actionInfos));
     }
 
-    String flowRef = getFlowRef(dpId, L3_FIB_TABLE, rd, destPrefix);
+    String flowRef = getFlowRef(dpId, NwConstants.L3_FIB_TABLE, rd, destPrefix);
 
     FlowEntity flowEntity;
 
     int priority = DEFAULT_FIB_FLOW_PRIORITY + prefixLength;
-    flowEntity = MDSALUtil.buildFlowEntity(dpId, L3_FIB_TABLE, flowRef,
+    flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_FIB_TABLE, flowRef,
                                            priority, flowRef, 0, 0,
                                            COOKIE_VM_FIB_TABLE, matches, instructions);
 
@@ -538,10 +532,10 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
     instructions.add(new InstructionInfo(InstructionType.write_actions, actionsInfos));
 
     // Install the flow entry in L3_LFIB_TABLE
-    String flowRef = getFlowRef(dpId, L3_LFIB_TABLE, label, nextHop);
+    String flowRef = getFlowRef(dpId, NwConstants.L3_LFIB_TABLE, label, nextHop);
 
     FlowEntity flowEntity;
-    flowEntity = MDSALUtil.buildFlowEntity(dpId, L3_LFIB_TABLE, flowRef,
+    flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_LFIB_TABLE, flowRef,
                                            DEFAULT_FIB_FLOW_PRIORITY, flowRef, 0, 0,
                                            COOKIE_VM_LFIB_TABLE, matches, instructions);
 
@@ -655,13 +649,13 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
         final BigInteger COOKIE_TABLE_MISS = new BigInteger("1030000", 16);
         // Instruction to goto L3 InterfaceTable
         List<InstructionInfo> instructions = new ArrayList<InstructionInfo>();
-        instructions.add(new InstructionInfo(InstructionType.goto_table, new long[] { L3_INTERFACE_TABLE }));
+        instructions.add(new InstructionInfo(InstructionType.goto_table, new long[] { NwConstants.L3_INTERFACE_TABLE }));
         List<MatchInfo> matches = new ArrayList<MatchInfo>();
-        FlowEntity flowEntityLfib = MDSALUtil.buildFlowEntity(dpnId, L3_LFIB_TABLE,
-                getFlowRef(dpnId, L3_LFIB_TABLE, NwConstants.TABLE_MISS_FLOW),
+        FlowEntity flowEntityLfib = MDSALUtil.buildFlowEntity(dpnId, NwConstants.L3_LFIB_TABLE,
+                getFlowRef(dpnId, NwConstants.L3_LFIB_TABLE, NwConstants.TABLE_MISS_FLOW),
                 NwConstants.TABLE_MISS_PRIORITY, "Table Miss", 0, 0, COOKIE_TABLE_MISS, matches, instructions);
 
-        FlowEntity flowEntityFib = MDSALUtil.buildFlowEntity(dpnId,L3_FIB_TABLE, getFlowRef(dpnId, L3_FIB_TABLE, NwConstants.TABLE_MISS_FLOW),
+        FlowEntity flowEntityFib = MDSALUtil.buildFlowEntity(dpnId,NwConstants.L3_FIB_TABLE, getFlowRef(dpnId, NwConstants.L3_FIB_TABLE, NwConstants.TABLE_MISS_FLOW),
                 NwConstants.TABLE_MISS_PRIORITY, "FIB Table Miss Flow", 0, 0, COOKIE_VM_FIB_TABLE,
                 matches, instructions);
 
@@ -690,13 +684,13 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
     final BigInteger COOKIE_PROTOCOL_TABLE = new BigInteger("1070000", 16);
     // Instruction to goto L3 InterfaceTable
     List<InstructionInfo> instructions = new ArrayList<>();
-    instructions.add(new InstructionInfo(InstructionType.goto_table, new long[] {L3_LFIB_TABLE}));
+    instructions.add(new InstructionInfo(InstructionType.goto_table, new long[] {NwConstants.L3_LFIB_TABLE}));
     List<MatchInfo> matches = new ArrayList<MatchInfo>();
     matches.add(new MatchInfo(MatchFieldType.eth_type,
                               new long[] { 0x8847L }));
-    FlowEntity flowEntityToLfib = MDSALUtil.buildFlowEntity(dpnId, L3_PROTOCOL_TABLE,
-                                                          getFlowRef(dpnId, L3_PROTOCOL_TABLE,
-                                                                     L3_LFIB_TABLE),
+    FlowEntity flowEntityToLfib = MDSALUtil.buildFlowEntity(dpnId, NwConstants.L3_PROTOCOL_TABLE,
+                                                          getFlowRef(dpnId, NwConstants.L3_PROTOCOL_TABLE,
+                                                                  NwConstants.L3_LFIB_TABLE),
                                                           DEFAULT_FIB_FLOW_PRIORITY,
                                                           "Protocol Table For LFIB",
                                                           0, 0,
@@ -740,10 +734,10 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
     instructions.add(new InstructionInfo(InstructionType.clear_actions));
     // Instruction to goto L3 InterfaceTable
 
-    instructions.add(new InstructionInfo(InstructionType.goto_table, new long[] { LPORT_DISPATCHER_TABLE }));
+    instructions.add(new InstructionInfo(InstructionType.goto_table, new long[] { NwConstants.LPORT_DISPATCHER_TABLE }));
 
-    FlowEntity flowEntityL3Intf = MDSALUtil.buildFlowEntity(dpnId, L3_INTERFACE_TABLE,
-            getFlowRef(dpnId, L3_INTERFACE_TABLE, NwConstants.TABLE_MISS_FLOW),
+    FlowEntity flowEntityL3Intf = MDSALUtil.buildFlowEntity(dpnId, NwConstants.L3_INTERFACE_TABLE,
+            getFlowRef(dpnId, NwConstants.L3_INTERFACE_TABLE, NwConstants.TABLE_MISS_FLOW),
             NwConstants.TABLE_MISS_PRIORITY, "L3 Interface Table Miss", 0, 0, COOKIE_TABLE_MISS, matches, instructions);
     if (addOrRemove == NwConstants.ADD_FLOW) {
       LOG.info("Invoking MDSAL to install L3 interface Table Miss Entries");