Bug 3248 84/20484/5
authorDeepthi V V <deepthi.v.v@ericsson.com>
Fri, 15 May 2015 08:39:09 +0000 (14:09 +0530)
committerDeepthi V V <deepthi.v.v@ericsson.com>
Mon, 18 May 2015 09:53:00 +0000 (09:53 +0000)
1. Fix remove flow entry for tunnel nexthop
2. Fib entry should be read from operational datastore.

Signed-off-by: Deepthi V V <deepthi.v.v@ericsson.com>
Change-Id: Ic113ef775ea0053a6db7929f3dc7c68c8409dd43

fibmanager/fibmanager-impl/src/main/java/org/opendaylight/vpnservice/fibmanager/FibManager.java
fibmanager/fibmanager-impl/src/main/java/org/opendaylight/vpnservice/fibmanager/FibManagerProvider.java
nexthopmgr/nexthopmgr-impl/src/main/java/org/opendaylight/vpnservice/nexthopmgr/NexthopManager.java
nexthopmgr/nexthopmgr-impl/src/main/java/org/opendaylight/vpnservice/nexthopmgr/OdlInterfaceChangeListener.java

index 48e545595a80eaf3666ed0a9faa86f6546d57764..2ff2bd8233d5ab8b43a46edfdd8e6dcd573186e5 100644 (file)
@@ -368,7 +368,7 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
   public void populateFibOnNewDpn(long dpnId, long vpnId, String rd) {
     LOG.trace("New dpn {} for vpn {} : populateFibOnNewDpn", dpnId, rd);
     InstanceIdentifier<VrfTables> id = buildVrfId(rd);
-    Optional<VrfTables> vrfTable = read(LogicalDatastoreType.OPERATIONAL, id);
+    Optional<VrfTables> vrfTable = read(LogicalDatastoreType.CONFIGURATION, id);
     if(vrfTable.isPresent()) {
       for(VrfEntry vrfEntry : vrfTable.get().getVrfEntry()) {
         addRouteInternal(dpnId, vpnId, vrfTable.get().getKey(), vrfEntry);
@@ -379,7 +379,7 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
   public void cleanUpDpnForVpn(long dpnId, long vpnId, String rd) {
     LOG.trace("Remove dpn {} for vpn {} : cleanUpDpnForVpn", dpnId, rd);
     InstanceIdentifier<VrfTables> id = buildVrfId(rd);
-    Optional<VrfTables> vrfTable = read(LogicalDatastoreType.OPERATIONAL, id);
+    Optional<VrfTables> vrfTable = read(LogicalDatastoreType.CONFIGURATION, id);
     if(vrfTable.isPresent()) {
       for(VrfEntry vrfEntry : vrfTable.get().getVrfEntry()) {
         deleteRoute(dpnId, vpnId, vrfTable.get().getKey(), vrfEntry);
index 15ea7db36dcb5e707c72db09b49e21cc9d3755d6..aef8ce5d67c84ee3ed6d875af31aeb5b8c9edef1 100644 (file)
@@ -65,6 +65,6 @@ public class FibManagerProvider implements BindingAwareProvider, IFibManager, Au
 
   @Override
   public void cleanUpDpnForVpn(long dpnId, long vpnId, String rd) {
-    fibManager.populateFibOnNewDpn(dpnId, vpnId, rd);
+    fibManager.cleanUpDpnForVpn(dpnId, vpnId, rd);
   }
 }
index e5aa70c1bee556d12a45af64318c792cc939e9e6..5c0184eba734fc3ab6e19738b04c5f0629e3cb1b 100644 (file)
@@ -12,9 +12,8 @@ import org.opendaylight.vpnservice.mdsalutil.InstructionInfo;
 import org.opendaylight.vpnservice.mdsalutil.InstructionType;
 import org.opendaylight.vpnservice.mdsalutil.MatchFieldType;
 import org.opendaylight.vpnservice.mdsalutil.MatchInfo;
-import org.opendaylight.vpnservice.mdsalutil.MetaDataUtil;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.L3tunnel;
+import org.opendaylight.vpnservice.mdsalutil.NwConstants;
+
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
@@ -211,7 +210,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
             GroupEntity groupEntity = MDSALUtil.buildGroupEntity(
                 dpnId, groupId, ipAddress, GroupTypes.GroupIndirect, listBucketInfo);
             mdsalManager.installGroup(groupEntity);
-            addRemoteFlow(dpnId, ifName);
+            makeRemoteFlow(dpnId, ifName, NwConstants.ADD_FLOW);
 
             //update MD-SAL DS
             addTunnelNexthopToDS(dpnId, ipAddress, groupId);
@@ -220,37 +219,38 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
         }
     }
 
-    private void addRemoteFlow(long dpId, String ifName) {
-
-            long portNo = interfaceManager.getPortForInterface(ifName);
-            String flowRef = getTunnelInterfaceFlowRef(dpId, LPORT_INGRESS_TABLE, portNo);
-
-            String flowName = ifName;
-            BigInteger COOKIE_VM_INGRESS_TABLE = new BigInteger("8000001", 16);
-
-            int priority = DEFAULT_FLOW_PRIORITY;
-            short gotoTableId = LFIB_TABLE;
-
-            List<InstructionInfo> mkInstructions = new ArrayList<InstructionInfo>();
-            mkInstructions.add(new InstructionInfo(InstructionType.goto_table, new long[] { gotoTableId }));
-
-            List<MatchInfo> matches = new ArrayList<MatchInfo>();
+    private void makeRemoteFlow(long dpId, String ifName, int addOrRemoveFlow) {
+        long portNo = 0;
+        String flowName = ifName;
+        String flowRef = getTunnelInterfaceFlowRef(dpId, LPORT_INGRESS_TABLE, ifName);
+        List<MatchInfo> matches = new ArrayList<MatchInfo>();
+        List<InstructionInfo> mkInstructions = new ArrayList<InstructionInfo>();
+        if (NwConstants.ADD_FLOW == addOrRemoveFlow) {
+            interfaceManager.getPortForInterface(ifName);
             matches.add(new MatchInfo(MatchFieldType.in_port, new long[] {
-                    dpId, portNo }));
+                dpId, portNo }));
+            mkInstructions.add(new InstructionInfo(InstructionType.goto_table, new long[] {LFIB_TABLE}));
+        }
 
-            FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, LPORT_INGRESS_TABLE, flowRef,
-                              priority, flowName, 0, 0, COOKIE_VM_INGRESS_TABLE, matches, mkInstructions);
+        BigInteger COOKIE_VM_INGRESS_TABLE = new BigInteger("8000001", 16);
+        FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, LPORT_INGRESS_TABLE, flowRef,
+                                                          DEFAULT_FLOW_PRIORITY, flowName, 0, 0, COOKIE_VM_INGRESS_TABLE, matches, mkInstructions);
 
+        if (NwConstants.ADD_FLOW == addOrRemoveFlow) {
             mdsalManager.installFlow(flowEntity);
+        } else {
+            mdsalManager.removeFlow(flowEntity);
+        }
     }
 
-    private String getTunnelInterfaceFlowRef(long dpId, short tableId, long portNo) {
-                return new StringBuilder().append(dpId).append(tableId).append(portNo).toString();
+    private String getTunnelInterfaceFlowRef(long dpId, short tableId, String ifName) {
+                return new StringBuilder().append(dpId).append(tableId).append(ifName).toString();
             }
 
     protected void addVpnNexthopToDS(long vpnId, String ipPrefix, long egressPointer) {
 
-        InstanceIdentifierBuilder<VpnNexthops> idBuilder = InstanceIdentifier.builder(L3nexthop.class)
+        InstanceIdentifierBuilder<VpnNexthops> idBuilder = InstanceIdentifier.builder(
+            L3nexthop.class)
                 .child(VpnNexthops.class, new VpnNexthopsKey(vpnId));
 
         // Add nexthop to vpn node
@@ -387,7 +387,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
 
     }
 
-    public void removeRemoteNextHop(long dpnId, String ipAddress) {
+    public void removeRemoteNextHop(long dpnId, String ifName, String ipAddress) {
 
         TunnelNexthop nh = getTunnelNexthop(dpnId, ipAddress);
         if (nh != null) {
@@ -399,6 +399,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
                     dpnId, nh.getEgressPointer(), ipAddress, GroupTypes.GroupIndirect, null);
             // remove Group ...
             mdsalManager.removeGroup(groupEntity);
+            makeRemoteFlow(dpnId, ifName, NwConstants.DEL_FLOW);
             //update MD-SAL DS
             removeTunnelNexthopFromDS(dpnId, ipAddress);
         } else {
@@ -451,14 +452,14 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
     private <T extends DataObject> void asyncWrite(LogicalDatastoreType datastoreType,
             InstanceIdentifier<T> path, T data, FutureCallback<Void> callback) {
         WriteTransaction tx = broker.newWriteOnlyTransaction();
-        tx.put(datastoreType, path, data, true);
+        tx.merge(datastoreType, path, data, true);
         Futures.addCallback(tx.submit(), callback);
     }
 
     private <T extends DataObject> void syncWrite(LogicalDatastoreType datastoreType,
             InstanceIdentifier<T> path, T data, FutureCallback<Void> callback) {
         WriteTransaction tx = broker.newWriteOnlyTransaction();
-        tx.put(datastoreType, path, data, true);
+        tx.merge(datastoreType, path, data, true);
         tx.submit();
     }
 
index 43a5fc509fea72e2628d3b2a7cabd65bde616216..ccb7ea4dd61dae87876e2f9946704b6b6bf5d2a5 100644 (file)
@@ -76,16 +76,9 @@ public class OdlInterfaceChangeListener extends AbstractDataChangeListener<Inter
         if (intrf.getType().equals(L3tunnel.class)) {
             IfL3tunnel intfData = intrf.getAugmentation(IfL3tunnel.class);
             IpAddress gatewayIp = intfData.getGatewayIp();
-            String gwIp = (gatewayIp == null) ? null : gatewayIp.toString();
-            String remoteIp = null;
-            if (gwIp != null) {
-                remoteIp = gwIp;
-            } else {
-                IpAddress remIp = intfData.getRemoteIp();
-                remoteIp = (remIp == null) ? null : remIp.toString();
-            }
+            IpAddress remoteIp = (gatewayIp == null) ? intfData.getRemoteIp() : gatewayIp;
             NodeConnectorId ofPort = intrf.getAugmentation(BaseIds.class).getOfPortId();
-            nexthopManager.createRemoteNextHop(intrf.getName(), ofPort.toString(), remoteIp);
+            nexthopManager.createRemoteNextHop(intrf.getName(), ofPort.toString(), remoteIp.getIpv4Address().getValue());
         }
     }
 
@@ -101,12 +94,9 @@ public class OdlInterfaceChangeListener extends AbstractDataChangeListener<Inter
         if (intrf.getType().equals(L3tunnel.class)) {
             long dpnId = interfaceManager.getDpnForInterface(intrf.getName());
             IfL3tunnel intfData = intrf.getAugmentation(IfL3tunnel.class);
-            String gwIp = intfData.getGatewayIp().toString();
-            String remoteIp = intfData.getRemoteIp().toString();
-            if (gwIp != null) {
-                remoteIp = gwIp;
-            }
-            nexthopManager.removeRemoteNextHop(dpnId, remoteIp);
+            IpAddress gatewayIp = intfData.getGatewayIp();
+            IpAddress remoteIp = (gatewayIp == null) ? intfData.getRemoteIp() : gatewayIp;
+            nexthopManager.removeRemoteNextHop(dpnId, intrf.getName(), remoteIp.getIpv4Address().getValue());
         }
     }