Merge "Bug 5267 - Setting vlan id for termination end point not working"
authorVishal Thapar <vishal.thapar@ericsson.com>
Fri, 19 Feb 2016 08:34:56 +0000 (08:34 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 19 Feb 2016 08:34:56 +0000 (08:34 +0000)
36 files changed:
alivenessmonitor/alivenessmonitor-impl/src/main/java/org/opendaylight/vpnservice/alivenessmonitor/internal/AlivenessProtocolHandlerLLDP.java
dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpPktHandler.java
elanmanager/elanmanager-impl/pom.xml
elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanInterfaceManager.java
elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanInterfaceStateChangeListener.java [new file with mode: 0644]
elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanServiceProvider.java
elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/utils/ElanUtils.java
fibmanager/fibmanager-impl/src/main/java/org/opendaylight/vpnservice/fibmanager/FibManager.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/IfmUtil.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/commons/AlivenessMonitorUtils.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/commons/InterfaceManagerCommonUtils.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/confighelpers/OvsInterfaceConfigAddHelper.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/confighelpers/OvsInterfaceConfigRemoveHelper.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/confighelpers/OvsVlanMemberConfigAddHelper.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/statehelpers/OvsInterfaceStateAddHelper.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/confighelpers/FlowBasedServicesConfigBindHelper.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/confighelpers/FlowBasedServicesConfigUnbindHelper.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/statehelpers/FlowBasedServicesStateBindHelper.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/statehelpers/FlowBasedServicesStateUnbindHelper.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/utilities/FlowBasedServicesUtils.java
itm/itm-api/src/main/java/org/opendaylight/vpnservice/itm/globals/ITMConstants.java
itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmExternalTunnelDeleteWorker.java
itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmInternalTunnelAddWorker.java
itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmInternalTunnelDeleteWorker.java
itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmTepAddWorker.java
itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmTepRemoveWorker.java
itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/impl/ItmProvider.java
itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/impl/ItmUtils.java
itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/listeners/TransportZoneListener.java
neutronvpn/neutronvpn-api/src/main/yang/neutronvpn.yang
neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronPortChangeListener.java
neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronRouterChangeListener.java
neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronSubnetChangeListener.java
neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronvpnManager.java
neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronvpnUtils.java
vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/VpnInterfaceManager.java

index 9ff6a5a18f9bcfd4402283981a784e3865326727..c1c045a474e65c94728dc7d48e57c6e7452316b7 100644 (file)
@@ -194,10 +194,10 @@ public class AlivenessProtocolHandlerLLDP extends AbstractAlivenessProtocolHandl
         }
 
         List<ActionInfo> actionInfos  = new ArrayList<ActionInfo>();
-
+        // Set the LLDP service Id which is 0
         if(Tunnel.class.equals(intfType)) {
             actionInfos.add(new ActionInfo(ActionType.set_field_tunnel_id, new BigInteger[] {
-                    BigInteger.valueOf(0x08000000)}));
+                    BigInteger.valueOf(0)}));
         }
         actionInfos.add(new ActionInfo(ActionType.output, new String[] { Long.toString(portNum) }));
         return actionInfos;
index 5c26610c157044fa4a8247dde4d4600b1475ab0a..60d8bd729ec465a125968e3826dff8c2c37a0131 100644 (file)
@@ -87,7 +87,7 @@ public class DhcpPktHandler implements AutoCloseable, PacketProcessingListener {
         LOG.trace("Pkt received: {}", packet);
         Class<? extends PacketInReason> pktInReason = packet.getPacketInReason();
         short tableId = packet.getTableId().getValue();
-        if (isPktInReasonSendtoCtrl(pktInReason) && ((NwConstants.DHCP_TABLE == tableId))) {
+        if (isPktInReasonSendtoCtrl(pktInReason)) {
             byte[] inPayload = packet.getPayload();
             Ethernet ethPkt = new Ethernet();
             try {
index 313c6ee5f5c7127c4e4235a51bd8f638ad8b387a..195226510442f9ff20cbf819664e7f2d8b2fa9ae 100644 (file)
@@ -55,6 +55,11 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       <artifactId>org.apache.karaf.shell.console</artifactId>
       <version>3.0.3</version>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.vpnservice</groupId>
+      <artifactId>interfacemgr-impl</artifactId>
+      <version>${vpnservices.version}</version>
+    </dependency>
   </dependencies>
 
 </project>
index 4413a3bba5fd074b103e56af5efaec4fee7ba429..5bffcfc4f6e3c1bd414c8285c2bce8636e6903f7 100644 (file)
@@ -147,12 +147,11 @@ public class ElanInterfaceManager extends AbstractDataChangeListener<ElanInterfa
         removeElanInterface(elanInfo, interfaceName);
     }
 
-    public void removeElanService(ElanInterface del, int vlanId) {
+    public void removeElanService(ElanInterface del, InterfaceInfo interfaceInfo) {
         ElanInstance elanInstance = ElanUtils.getElanInstanceByName(del.getElanInstanceName());
         String interfaceName = del.getName();
-        InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfoFromOperationalDataStore(interfaceName, InterfaceType.VLAN_INTERFACE);
         removeElanInterface(elanInstance, interfaceInfo);
-        unbindService(elanInstance, interfaceName, vlanId);
+        unbindService(elanInstance, interfaceName);
     }
 
     public void removeElanInterface(ElanInstance elanInfo, String interfaceName) {
@@ -562,12 +561,24 @@ public class ElanInterfaceManager extends AbstractDataChangeListener<ElanInterfa
                                                InterfaceInfo interfaceInfo, BigInteger dstDpId) {
         int elanTag = elanInfo.getElanTag().intValue();
         long groupId = ElanUtils.getElanRemoteBCGID(elanTag);
+        DpnInterfaces dpnInterfaces = ElanUtils.getElanInterfaceInfoByElanDpn(elanInfo.getElanInstanceName(), interfaceInfo.getDpId());
         List<DpnInterfaces> elanDpns = ElanUtils.getInvolvedDpnsInElan(elanInfo.getElanInstanceName());
         if(elanDpns != null) {
             for(DpnInterfaces dpnInterface : elanDpns) {
                 int bucketId = 0;
                 List<Bucket> remoteListBucket = new ArrayList<Bucket>();
                 if(ElanUtils.isDpnPresent(dstDpId) && dpnInterface.getDpId().equals(dstDpId) && dpnInterface.getInterfaces() != null && !dpnInterface.getInterfaces().isEmpty()) {
+                    for(String ifName : dpnInterfaces.getInterfaces()) {
+                        // In case if there is a InterfacePort in the cache which is not in
+                        // operational state, skip processing it
+                        InterfaceInfo ifInfo = interfaceManager.getInterfaceInfoFromOperationalDataStore(ifName, interfaceInfo.getInterfaceType());
+                        if (!isOperational(ifInfo)) {
+                            continue;
+                        }
+
+                        remoteListBucket.add(MDSALUtil.buildBucket(getInterfacePortActions(ifInfo), MDSALUtil.GROUP_WEIGHT, bucketId, MDSALUtil.WATCH_PORT, MDSALUtil.WATCH_GROUP));
+                        bucketId++;
+                    }
                     try {
                         List<Action> remoteListActionInfo = ElanUtils.getItmEgressAction(interfaceInfo.getDpId(), dstDpId, (int) elanTag);
                         remoteListBucket.add(MDSALUtil.buildBucket(remoteListActionInfo, MDSALUtil.GROUP_WEIGHT, bucketId, MDSALUtil.WATCH_PORT, MDSALUtil.WATCH_GROUP));
@@ -576,9 +587,6 @@ public class ElanInterfaceManager extends AbstractDataChangeListener<ElanInterfa
                         logger.error( "Logical Group Interface not found between source Dpn - {}, destination Dpn - {} " ,dpnInterface.getDpId(), dstDpId);
                         return;
                     }
-                    List<Action> remoteListActionInfo = new ArrayList<Action>();
-                    remoteListActionInfo.add(new ActionInfo(ActionType.group, new String[] {String.valueOf(ElanUtils.getElanLocalBCGID(elanTag))}).buildAction());
-                    remoteListBucket.add(MDSALUtil.buildBucket(remoteListActionInfo, MDSALUtil.GROUP_WEIGHT, bucketId, MDSALUtil.WATCH_PORT, MDSALUtil.WATCH_GROUP));
                     Group group = MDSALUtil.buildGroup(groupId, elanInfo.getElanInstanceName(), GroupTypes.GroupAll, MDSALUtil.buildBucketLists(remoteListBucket));
                     mdsalManager.syncInstallGroup(interfaceInfo.getDpId(), group, ElanConstants.DELAY_TIME_IN_MILLISECOND);
                     break;
@@ -688,7 +696,7 @@ public class ElanInterfaceManager extends AbstractDataChangeListener<ElanInterfa
             // In case if there is a InterfacePort in the cache which is not in
             // operational state, skip processing it
             InterfaceInfo ifInfo = interfaceManager.getInterfaceInfoFromOperationalDataStore(ifName, interfaceInfo.getInterfaceType());
-            if (!isOperational(ifInfo)) {
+            if (ifInfo == null || !isOperational(ifInfo)) {
                 continue;
             }
 
@@ -700,7 +708,13 @@ public class ElanInterfaceManager extends AbstractDataChangeListener<ElanInterfa
 
         Group group = MDSALUtil.buildGroup(groupId, elanInfo.getElanInstanceName(), GroupTypes.GroupAll, MDSALUtil.buildBucketLists(listBucket));
         logger.trace("installing the localBroadCast Group:{}", group);
-        mdsalManager.syncInstallGroup(dpnId, group, ElanConstants.DELAY_TIME_IN_MILLISECOND);
+        // In the case of OVS disconnected we receive null object when we query Interface Operation datastore
+        // so the size of the bucket will be zero
+        if(listBucket.size() == 0) {
+            mdsalManager.syncRemoveGroup(dpnId, group);
+        } else {
+            mdsalManager.syncInstallGroup(dpnId, group, ElanConstants.DELAY_TIME_IN_MILLISECOND);
+        }
     }
 
     public void setupLocalBroadcastGroups(ElanInstance elanInfo, InterfaceInfo interfaceInfo) {
@@ -714,7 +728,7 @@ public class ElanInterfaceManager extends AbstractDataChangeListener<ElanInterfa
             // In case if there is a InterfacePort in the cache which is not in
             // operational state, skip processing it
             InterfaceInfo ifInfo = interfaceManager.getInterfaceInfoFromOperationalDataStore(ifName, interfaceInfo.getInterfaceType());
-            if (!isOperational(ifInfo)) {
+            if (ifInfo == null || !isOperational(ifInfo)) {
                 continue;
             }
 
@@ -722,9 +736,16 @@ public class ElanInterfaceManager extends AbstractDataChangeListener<ElanInterfa
             bucketId++;
         }
 
+
         Group group = MDSALUtil.buildGroup(groupId, elanInfo.getElanInstanceName(), GroupTypes.GroupAll, MDSALUtil.buildBucketLists(listBucket));
         logger.trace("installing the localBroadCast Group:{}", group);
-        mdsalManager.syncInstallGroup(dpnId, group, ElanConstants.DELAY_TIME_IN_MILLISECOND);
+        // In the case of OVS disconnected we receive null object for the Interface Operation datastore
+        // so the size of the bucket will be zero
+        if(listBucket.size() == 0) {
+            mdsalManager.syncRemoveGroup(dpnId, group);
+        } else {
+            mdsalManager.syncInstallGroup(dpnId, group, ElanConstants.DELAY_TIME_IN_MILLISECOND);
+        }
     }
 
     public void removeLocalBroadcastGroup(ElanInstance elanInfo, InterfaceInfo interfaceInfo) {
@@ -792,6 +813,7 @@ public class ElanInterfaceManager extends AbstractDataChangeListener<ElanInterfa
             removeFilterEqualsTable(elanInfo, interfaceInfo);
         } else {
             setupElanBroadcastGroups(elanInfo, interfaceInfo);
+            setupLocalBroadcastGroups(elanInfo, interfaceInfo);
             removeFilterEqualsTable(elanInfo, interfaceInfo);
         }
     }
diff --git a/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanInterfaceStateChangeListener.java b/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanInterfaceStateChangeListener.java
new file mode 100644 (file)
index 0000000..58f0aea
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.vpnservice.elan.internal;
+
+
+import com.google.common.base.Optional;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.vpnservice.elan.utils.ElanUtils;
+import org.opendaylight.vpnservice.interfacemgr.globals.InterfaceInfo;
+import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
+import org.opendaylight.vpnservice.mdsalutil.AbstractDataChangeListener;
+import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.elan.instances.ElanInstance;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.elan.interfaces.ElanInterface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnel;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.math.BigInteger;
+import java.util.List;
+
+public class ElanInterfaceStateChangeListener extends AbstractDataChangeListener<Interface> implements AutoCloseable {
+    private DataBroker broker;
+    private IInterfaceManager interfaceManager;
+    private ElanInterfaceManager elanInterfaceManager;
+    private ListenerRegistration<DataChangeListener> listenerRegistration;
+    private static final Logger logger = LoggerFactory.getLogger(ElanInterfaceStateChangeListener.class);
+
+    public ElanInterfaceStateChangeListener(final DataBroker db, final ElanInterfaceManager ifManager) {
+        super(Interface.class);
+        broker = db;
+        elanInterfaceManager = ifManager;
+        registerListener(db);
+    }
+
+    private void registerListener(final DataBroker db) {
+        try {
+            listenerRegistration = broker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
+                    getWildCardPath(), ElanInterfaceStateChangeListener.this, AsyncDataBroker.DataChangeScope.SUBTREE);
+        } catch (final Exception e) {
+            logger.error("Elan Interfaces DataChange listener registration fail!", e);
+            throw new IllegalStateException("ElanInterface registration Listener failed.", e);
+        }
+    }
+
+    private InstanceIdentifier<Interface> getWildCardPath() {
+        return InstanceIdentifier.create(InterfacesState.class).child(Interface.class);
+    }
+
+    public void setInterfaceManager(IInterfaceManager interfaceManager) {
+        this.interfaceManager = interfaceManager;
+    }
+
+    private void handleVlanInterfaceOperationalStateChange(String interfaceName, boolean isStateUp) {
+        //fetching the elanInstanceName from elan-interface config data-store
+        ElanInterface elanInterface = ElanUtils.getElanInterfaceByElanInterfaceName(interfaceName);
+        if (elanInterface == null) {
+            return;
+        }
+        ElanInstance elanInfo = ElanUtils.getElanInstanceByName(elanInterface.getElanInstanceName());
+        InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
+
+        logger.trace("ElanService Interface Operational state has changes for Interface:{}", interfaceName);
+        elanInterfaceManager.handleInterfaceUpated(interfaceInfo, elanInfo , isStateUp);
+    }
+
+    @Override
+    protected void remove(InstanceIdentifier<Interface> identifier, Interface delIf) {
+        logger.trace("Received interface {} Down event", delIf);
+        String interfaceName =  delIf.getName();
+        ElanInterface elanInterface = ElanUtils.getElanInterfaceByElanInterfaceName(interfaceName);
+        if(elanInterface == null) {
+            logger.debug("No Elan Interface is created for the interface:{} ", interfaceName);
+            return;
+        }
+        NodeConnectorId nodeConnectorId = new NodeConnectorId(delIf.getLowerLayerIf().get(0));
+        BigInteger dpId = MDSALUtil.getDpnIdFromNodeName(nodeConnectorId.getValue());
+        InterfaceInfo interfaceInfo = new InterfaceInfo(dpId, nodeConnectorId.getValue());
+        interfaceInfo.setInterfaceName(interfaceName);
+        interfaceInfo.setInterfaceType(InterfaceInfo.InterfaceType.VLAN_INTERFACE);
+        interfaceInfo.setInterfaceTag(delIf.getIfIndex());
+        elanInterfaceManager.removeElanService(elanInterface, interfaceInfo);
+    }
+
+    @Override
+    protected void update(InstanceIdentifier<Interface> identifier, Interface original, Interface update) {
+        logger.trace("Operation Interface update event - Old: {}, New: {}", original, update);
+        String interfaceName = update.getName();
+        if(update.getType().equals(Tunnel.class)) {
+            if (update.getOperStatus().equals(Interface.OperStatus.Up)) {
+                InternalTunnel internalTunnel = getTunnelState(interfaceName);
+                if (internalTunnel != null) {
+                    elanInterfaceManager.handleTunnelStateEvent(internalTunnel.getSourceDPN(), internalTunnel.getDestinationDPN());
+                }
+            }
+        } else if(update.getType().equals(L2vlan.class)) {
+            ElanInterface elanInterface = ElanUtils.getElanInterfaceByElanInterfaceName(interfaceName);
+            if(elanInterface == null) {
+                logger.debug("No Elan Interface is created for the interface:{} ", interfaceName);
+                return;
+            }
+            if (update.getOperStatus().equals(Interface.OperStatus.Up) && update.getAdminStatus() == Interface.AdminStatus.Up) {
+                logger.trace("Operation Status for Interface:{}  event state UP ", interfaceName);
+                handleVlanInterfaceOperationalStateChange(interfaceName, true);
+            } else if (update.getOperStatus().equals(Interface.OperStatus.Down)) {
+                logger.trace("Operation Status for Interface:{}  event state DOWN ", interfaceName);
+                handleVlanInterfaceOperationalStateChange(interfaceName, false);
+            }
+
+        }
+    }
+
+    @Override
+    protected void add(InstanceIdentifier<Interface> identifier, Interface intrf) {
+        logger.trace("Received interface {} up event", intrf);
+        String interfaceName =  intrf.getName();
+        ElanInterface elanInterface = ElanUtils.getElanInterfaceByElanInterfaceName(interfaceName);
+        if(elanInterface == null) {
+            if (intrf.getType() != null && intrf.getType().equals(Tunnel.class)) {
+                if(intrf.getOperStatus().equals(Interface.OperStatus.Up)) {
+                    InternalTunnel internalTunnel = getTunnelState(interfaceName);
+                    if (internalTunnel != null) {
+                        elanInterfaceManager.handleTunnelStateEvent(internalTunnel.getSourceDPN(), internalTunnel.getDestinationDPN());
+                    }
+                }
+            }
+            return;
+        }
+        InstanceIdentifier<ElanInterface> elanInterfaceId = ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName);
+        elanInterfaceManager.add(elanInterfaceId, elanInterface);
+    }
+
+    @Override
+    public void close() throws Exception {
+
+    }
+
+    public  InternalTunnel getTunnelState(String interfaceName) {
+        InternalTunnel internalTunnel = null;
+        TunnelList tunnelList = ElanUtils.buildInternalTunnel(broker);
+        if (tunnelList.getInternalTunnel() != null) {
+            List<InternalTunnel> internalTunnels = tunnelList.getInternalTunnel();
+            for (InternalTunnel tunnel : internalTunnels) {
+                if (internalTunnel.getTunnelInterfaceName().equalsIgnoreCase(interfaceName)) {
+                    internalTunnel = tunnel;
+                    break;
+                }
+            }
+        }
+        return internalTunnel;
+    }
+}
index 200e645d984af2172fe368c34cdf0af368367f1e..7f901756ee3c6d21b67f8818a954c2cc0331ab17 100644 (file)
@@ -63,6 +63,7 @@ public class ElanServiceProvider implements BindingAwareProvider, IElanService,
     private ElanInterfaceManager elanInterfaceManager;
     private ElanPacketInHandler elanPacketInHandler;
     private ElanSmacFlowEventListener elanSmacFlowEventListener;
+    private ElanInterfaceStateChangeListener elanInterfaceStateChangeListener;
     private ElanNodeListener elanNodeListener;
     private NotificationService notificationService;
     private RpcProviderRegistry rpcProviderRegistry;
@@ -71,7 +72,7 @@ public class ElanServiceProvider implements BindingAwareProvider, IElanService,
         rpcProviderRegistry = rpcRegistry;
     }
 
-    //private ElanInterfaceEventListener elanInterfaceEventListener;
+    //private ElanInterfaceStateChangeListener elanInterfaceEventListener;
     private ElanItmEventListener elanItmEventListener;
 
     public void setItmRpcService(ItmRpcService itmRpcService) {
@@ -125,6 +126,8 @@ public class ElanServiceProvider implements BindingAwareProvider, IElanService,
         ElanStatisticsService interfaceStatsService = new ElanStatisticsImpl(broker, interfaceManager, mdsalManager);
         rpcProviderRegistry.addRpcImplementation(ElanStatisticsService.class, interfaceStatsService);
 
+        elanInterfaceStateChangeListener = new ElanInterfaceStateChangeListener(broker, elanInterfaceManager);
+        elanInterfaceStateChangeListener.setInterfaceManager(interfaceManager);
         ElanUtils.setElanServiceProvider(this);
     }
 
index 96ad2c80e231bf92d6217467591d58e299ef98b2..10d4df2b79fae955f1ccb44910ffb284464149d2 100644 (file)
@@ -76,6 +76,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpc
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.GetEgressActionsInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.GetEgressActionsOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.OdlInterfaceRpcService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.CreateTerminatingServiceActionsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.CreateTerminatingServiceActionsInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetTunnelInterfaceNameInput;
@@ -835,4 +836,13 @@ public class ElanUtils {
 
         itmRpcService.createTerminatingServiceActions(input);
     }
+
+    public static TunnelList buildInternalTunnel(DataBroker dataBroker) {
+        InstanceIdentifier<TunnelList> tunnelListInstanceIdentifier = InstanceIdentifier.builder(TunnelList.class).build();
+        Optional<TunnelList> tunnelList = read(dataBroker, LogicalDatastoreType.CONFIGURATION, tunnelListInstanceIdentifier);
+        if(tunnelList.isPresent()) {
+            return tunnelList.get();
+        }
+        return null;
+    }
 }
index 62b60ca8c1783aa7516ba633b5ee2e06591fbc9a..493076af544cae7f6561f4de08980348302e584e 100644 (file)
@@ -460,25 +460,34 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
       if (prefixInfo == null)
           return; //Don't have any info for this prefix (shouldn't happen); need to return
       String ifName = prefixInfo.getVpnInterfaceName();
-      Optional<Adjacencies> optAdjacencies = FibUtil.read(broker, LogicalDatastoreType.OPERATIONAL, FibUtil.getAdjListPath(ifName));
-      int numAdj = 0;
-      if (optAdjacencies.isPresent()) {
+      Optional<OpState> opStateData = FibUtil.read(broker, LogicalDatastoreType.OPERATIONAL,
+                                                   FibUtil.getVpnInterfaceOpStateIdentifier(ifName));
+      if(opStateData.isPresent() && !opStateData.get().isStateUp()) {
+        Optional<Adjacencies>
+            optAdjacencies =
+            FibUtil.read(broker, LogicalDatastoreType.OPERATIONAL, FibUtil.getAdjListPath(ifName));
+        int numAdj = 0;
+        if (optAdjacencies.isPresent()) {
           numAdj = optAdjacencies.get().getAdjacency().size();
-      }
-      LOG.trace("cleanUpOpDataForFib: remove adjacency for prefix: {} {}", vpnId, vrfEntry.getDestPrefix());
-      //remove adjacency corr to prefix
-      FibUtil.delete(broker, LogicalDatastoreType.OPERATIONAL, FibUtil.getAdjacencyIdentifier(ifName, vrfEntry.getDestPrefix()));
-
-      if((numAdj - 1) == 0) { //there are no adjacencies left for this vpn interface, clean up
-        //clean up the vpn interface from DpnToVpn list
+        }
+        LOG.trace("cleanUpOpDataForFib: remove adjacency for prefix: {} {}", vpnId,
+                  vrfEntry.getDestPrefix());
+        //remove adjacency corr to prefix
+        FibUtil.delete(broker, LogicalDatastoreType.OPERATIONAL,
+                       FibUtil.getAdjacencyIdentifier(ifName, vrfEntry.getDestPrefix()));
+
+        if ((numAdj - 1) == 0) { //there are no adjacencies left for this vpn interface, clean up
+          //clean up the vpn interface from DpnToVpn list
           delIntfFromDpnToVpnList(vpnId, prefixInfo.getDpnId(), ifName, rd);
-        LOG.trace("cleanUpOpDataForFib: Delete prefix to interface and vpnInterface ");
+          LOG.trace("cleanUpOpDataForFib: Delete prefix to interface and vpnInterface ");
           FibUtil.delete(broker, LogicalDatastoreType.OPERATIONAL,
-                  FibUtil.getPrefixToInterfaceIdentifier(
-                          vpnId,
-                          (extra_route) ? vrfEntry.getNextHopAddress() + "/32" : vrfEntry.getDestPrefix()));
+                         FibUtil.getPrefixToInterfaceIdentifier(
+                             vpnId,
+                             (extra_route) ? vrfEntry.getNextHopAddress() + "/32"
+                                           : vrfEntry.getDestPrefix()));
           FibUtil.delete(broker, LogicalDatastoreType.OPERATIONAL,
-                  FibUtil.getVpnInterfaceIdentifier(ifName));
+                         FibUtil.getVpnInterfaceIdentifier(ifName));
+        }
       }
   }
 
@@ -510,17 +519,25 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
                                 final VrfEntry vrfEntry) {
     LOG.debug("deleting route "+ vrfEntry.getDestPrefix() + " "+vpnId);
     String rd = vrfTableKey.getRouteDistinguisher();
-    String egressInterface = resolveAdjacency(localDpnId, remoteDpnId, vpnId, vrfEntry, rd);
-    if(egressInterface == null) {
-      LOG.error("Could not get nexthop group id for nexthop: {} in vpn {}",
-                vrfEntry.getNextHopAddress(), rd);
-      LOG.warn("Failed to delete Route: {} in vpn: {}",
-               vrfEntry.getDestPrefix(), rd);
-      return;
+    boolean isRemoteRoute = true;
+    if (localDpnId == null) {
+      // localDpnId is not known when clean up happens for last vm for a vpn on a dpn
+      VpnNexthop localNextHopInfo = nextHopManager.getVpnNexthop(vpnId, vrfEntry.getDestPrefix());
+      if(localNextHopInfo == null) {
+        //Is this fib route an extra route? If yes, get the nexthop which would be an adjacency in the vpn
+        Extraroute extra_route = getVpnToExtraroute(rd, vrfEntry.getDestPrefix());
+        if (extra_route != null) {
+          localNextHopInfo = nextHopManager.getVpnNexthop(vpnId, extra_route.getNexthopIp());
+        }
+      }
+      isRemoteRoute = ((localNextHopInfo != null) && (!remoteDpnId.equals(localNextHopInfo.getDpnId())));
+    }
+    if (isRemoteRoute) {
+      makeConnectedRoute(remoteDpnId, vpnId, vrfEntry, rd, null, NwConstants.DEL_FLOW);
+      LOG.debug("Successfully delete fib entry for "+ vrfEntry.getDestPrefix() + " vpnId "+vpnId);
+    } else{
+      LOG.debug("Did not delete fib entry rd: {} =, prefix: {} as it is local to dpn {}", rd, vrfEntry.getDestPrefix(), remoteDpnId);
     }
-
-    makeConnectedRoute(remoteDpnId, vpnId, vrfEntry, rd, null, NwConstants.DEL_FLOW);
-    LOG.debug("Successfully delete fib entry for "+ vrfEntry.getDestPrefix() + " vpnId "+vpnId);
   }
 
   private long getIpAddress(byte[] rawIpAddress) {
index 531f25b151549b51a9f5163bce9c16b60d6c8aba..76f78b2a5954fafe79e1b647185e426838958048 100644 (file)
@@ -198,7 +198,8 @@ public class IfmUtil {
         if(L2vlan.class.equals(ifType)){
             IfL2vlan vlanIface = interfaceInfo.getAugmentation(IfL2vlan.class);
             LOG.trace("L2Vlan: {}",vlanIface);
-            long vlanVid = (vlanIface == null) ? 0 : vlanIface.getVlanId().getValue();
+            long vlanVid = (vlanIface == null) ? 0 :
+                    vlanIface.getVlanId() == null ? 0 : vlanIface.getVlanId().getValue();
             if (vlanVid != 0) {
                 listActionInfo.add(new ActionInfo(ActionType.push_vlan, new String[] {}, actionKeyStart));
                 actionKeyStart++;
index 27795c2c38e57b0eb98e80c0c9d08158ecae966c..abc3b2c837690ff1034739c7902b3cfb7844f692 100644 (file)
@@ -66,7 +66,7 @@ public class AlivenessMonitorUtils {
     public static void startLLDPMonitoring(AlivenessMonitorService alivenessMonitorService, DataBroker dataBroker,
                                             Interface trunkInterface) {
         //LLDP monitoring for the trunk interface
-        /*String trunkInterfaceName = trunkInterface.getName();
+        String trunkInterfaceName = trunkInterface.getName();
         IfTunnel ifTunnel = trunkInterface.getAugmentation(IfTunnel.class);
         if(ifTunnel.getTunnelInterfaceType().isAssignableFrom(TunnelTypeVxlan.class)) {
             MonitorStartInput lldpMonitorInput = new MonitorStartInputBuilder().setConfig(new ConfigBuilder()
@@ -90,12 +90,12 @@ public class AlivenessMonitorUtils {
             } catch (InterruptedException | ExecutionException e) {
                 LOG.warn("Exception when starting monitoring", e);
             }
-        }*/
+        }
     }
 
     public static void stopLLDPMonitoring(AlivenessMonitorService alivenessMonitorService, DataBroker dataBroker,
                                           Interface trunkInterface) {
-        /*IfTunnel ifTunnel = trunkInterface.getAugmentation(IfTunnel.class);
+        IfTunnel ifTunnel = trunkInterface.getAugmentation(IfTunnel.class);
         if(!ifTunnel.getTunnelInterfaceType().isAssignableFrom(TunnelTypeVxlan.class)){
             return;
         }
@@ -113,7 +113,7 @@ public class AlivenessMonitorUtils {
                 removeMonitorIdFromInterfaceMonitorIdMap(dataBroker, interfaceName, monitorId);
                 return;
             }
-        }*/
+        }
     }
 
     public static String getInterfaceFromMonitorId(DataBroker broker, Long monitorId) {
index 6339f5f3c6db8d09062fa61838a3f709c0138dd6..aa350d6ccb9df70795186eb18165e555d976d945 100644 (file)
@@ -8,16 +8,24 @@
 
 package org.opendaylight.vpnservice.interfacemgr.commons;
 
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.ListenableFuture;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.idmanager.IdManager;
 import org.opendaylight.vpnservice.interfacemgr.IfmConstants;
 import org.opendaylight.vpnservice.interfacemgr.IfmUtil;
 import org.opendaylight.vpnservice.interfacemgr.servicebindings.flowbased.utilities.FlowBasedServicesUtils;
-import org.opendaylight.vpnservice.mdsalutil.*;
+import org.opendaylight.vpnservice.mdsalutil.FlowEntity;
+import org.opendaylight.vpnservice.mdsalutil.InstructionInfo;
+import org.opendaylight.vpnservice.mdsalutil.InstructionType;
+import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
+import org.opendaylight.vpnservice.mdsalutil.MatchFieldType;
+import org.opendaylight.vpnservice.mdsalutil.MatchInfo;
+import org.opendaylight.vpnservice.mdsalutil.MetaDataUtil;
+import org.opendaylight.vpnservice.mdsalutil.NwConstants;
 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
@@ -46,9 +54,8 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.List;
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.ListenableFuture;
 
 public class InterfaceManagerCommonUtils {
     private static final Logger LOG = LoggerFactory.getLogger(InterfaceManagerCommonUtils.class);
@@ -145,24 +152,6 @@ public class InterfaceManagerCommonUtils {
         MDSALUtil.syncUpdate(broker, LogicalDatastoreType.OPERATIONAL, id, ifaceBuilder.build());
     }
 
-    public static void createInterfaceParentEntryIfNotPresent(DataBroker dataBroker, WriteTransaction t,
-                                                               String parentInterface){
-        InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentInterface);
-        InstanceIdentifier<InterfaceParentEntry> interfaceParentEntryIdentifier =
-                InterfaceMetaUtils.getInterfaceParentEntryIdentifier(interfaceParentEntryKey);
-        InterfaceParentEntry interfaceParentEntry =
-                InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(interfaceParentEntryIdentifier, dataBroker);
-
-        if(interfaceParentEntry != null){
-            LOG.info("Not Found entry for Parent Interface: {} in Vlan Trunk-Member Interface Renderer ConfigDS. " +
-                    "Creating...", parentInterface);
-            InterfaceParentEntryBuilder interfaceParentEntryBuilder = new InterfaceParentEntryBuilder()
-                    .setKey(interfaceParentEntryKey).setParentInterface(parentInterface);
-            t.put(LogicalDatastoreType.CONFIGURATION, interfaceParentEntryIdentifier,
-                    interfaceParentEntryBuilder.build(), true);
-        }
-    }
-
     public static void createInterfaceChildEntry( WriteTransaction t,
                                                   String parentInterface, String childInterface){
         InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentInterface);
@@ -292,4 +281,37 @@ public class InterfaceManagerCommonUtils {
                 IfmUtil.buildStateInterfaceId(interfaceName);
         transaction.delete(LogicalDatastoreType.OPERATIONAL, ifChildStateId);
     }
+
+    // For trunk interfaces, binding to a parent interface which is already bound to another trunk interface should not
+    // be allowed
+    public static boolean createInterfaceChildEntryIfNotPresent( DataBroker dataBroker, WriteTransaction t,
+                                               String parentInterface, String childInterface){
+        InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentInterface);
+        InstanceIdentifier<InterfaceParentEntry> interfaceParentEntryIdentifier =
+                InterfaceMetaUtils.getInterfaceParentEntryIdentifier(interfaceParentEntryKey);
+        InterfaceParentEntry interfaceParentEntry =
+                InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(interfaceParentEntryIdentifier, dataBroker);
+
+        if(interfaceParentEntry != null){
+            LOG.error("Trying to bind the same parent interface {} to multiple trunk interfaces. ", parentInterface);
+            return false;
+        }
+
+        LOG.info("First vlan trunk {} bound on parent-interface {}", childInterface, parentInterface);
+        InterfaceChildEntryKey interfaceChildEntryKey = new InterfaceChildEntryKey(childInterface);
+        InstanceIdentifier<InterfaceChildEntry> intfId =
+                InterfaceMetaUtils.getInterfaceChildEntryIdentifier(interfaceParentEntryKey, interfaceChildEntryKey);
+        InterfaceChildEntryBuilder entryBuilder = new InterfaceChildEntryBuilder().setKey(interfaceChildEntryKey)
+                .setChildInterface(childInterface);
+        t.put(LogicalDatastoreType.CONFIGURATION, intfId, entryBuilder.build(),true);
+        return true;
+    }
+
+    public static boolean deleteParentInterfaceEntry( WriteTransaction t, String parentInterface){
+        InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentInterface);
+        InstanceIdentifier<InterfaceParentEntry> interfaceParentEntryIdentifier = InterfaceMetaUtils.getInterfaceParentEntryIdentifier(interfaceParentEntryKey);
+        t.delete(LogicalDatastoreType.CONFIGURATION, interfaceParentEntryIdentifier);
+        return true;
+    }
+
 }
\ No newline at end of file
index e98e6d6aec0c69e1085085881ed48763df172ec8..fecf3cf78f93034d826413ad32dc5820d6b894d1 100644 (file)
@@ -7,12 +7,13 @@
  */
 package org.opendaylight.vpnservice.interfacemgr.renderer.ovs.confighelpers;
 
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.ListenableFuture;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.idmanager.IdManager;
 import org.opendaylight.vpnservice.interfacemgr.IfmUtil;
 import org.opendaylight.vpnservice.interfacemgr.commons.AlivenessMonitorUtils;
 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils;
@@ -39,9 +40,8 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.List;
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.ListenableFuture;
 
 public class OvsInterfaceConfigAddHelper {
     private static final Logger LOG = LoggerFactory.getLogger(OvsInterfaceConfigAddHelper.class);
@@ -69,10 +69,12 @@ public class OvsInterfaceConfigAddHelper {
         if (ifL2vlan == null || IfL2vlan.L2vlanMode.Trunk != ifL2vlan.getL2vlanMode()) {
             return;
         }
-        LOG.debug("adding vlan configuration for {}",interfaceNew.getName());
         WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
-        InterfaceManagerCommonUtils.createInterfaceChildEntry(transaction,
-                parentRefs.getParentInterface(), interfaceNew.getName());
+        if(!InterfaceManagerCommonUtils.createInterfaceChildEntryIfNotPresent(dataBroker, transaction,
+                parentRefs.getParentInterface(), interfaceNew.getName())){
+            return;
+        }
+        LOG.debug("adding vlan configuration for {}",interfaceNew.getName());
 
         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState =
                 InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(parentRefs.getParentInterface(), dataBroker);
index 64e7957139d3001f3e1a5932f3408623b3bf5ec0..fe92920478682621050574990b936134d2af373e 100644 (file)
@@ -92,6 +92,7 @@ public class OvsInterfaceConfigRemoveHelper {
         NodeConnectorId ncId = new NodeConnectorId(ifState.getLowerLayerIf().get(0));
         BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(ncId));
         FlowBasedServicesUtils.removeIngressFlow(interfaceOld.getName(), dpId, transaction);
+        InterfaceManagerCommonUtils.deleteParentInterfaceEntry(transaction, parentRefs.getParentInterface());
         // For Vlan-Trunk Interface, remove the trunk-member operstates as well...
 
         InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(interfaceOld.getName());
index c4e7a9dbd632709f7649f330bdbef27ee6f2f746..e0086804dd3d0c53aecef61361e849cf64cb4417 100644 (file)
@@ -7,34 +7,21 @@
  */
 package org.opendaylight.vpnservice.interfacemgr.renderer.ovs.confighelpers;
 
-import com.google.common.util.concurrent.ListenableFuture;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.vpnservice.interfacemgr.IfmConstants;
-import org.opendaylight.vpnservice.interfacemgr.IfmUtil;
 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils;
-import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils;
-import org.opendaylight.vpnservice.interfacemgr.servicebindings.flowbased.utilities.FlowBasedServicesUtils;
-import org.opendaylight.vpnservice.mdsalutil.MatchInfo;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.AdminStatus;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfL2vlan;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.ParentRefs;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.List;
+import com.google.common.util.concurrent.ListenableFuture;
 
 public class OvsVlanMemberConfigAddHelper {
     private static final Logger LOG = LoggerFactory.getLogger(OvsVlanMemberConfigAddHelper.class);
@@ -45,7 +32,6 @@ public class OvsVlanMemberConfigAddHelper {
         List<ListenableFuture<Void>> futures = new ArrayList<>();
         WriteTransaction t = dataBroker.newWriteOnlyTransaction();
 
-        InterfaceManagerCommonUtils.createInterfaceParentEntryIfNotPresent(dataBroker, t, parentRefs.getParentInterface());
         InterfaceManagerCommonUtils.createInterfaceChildEntry(t, parentRefs.getParentInterface(), interfaceNew.getName());
 
         InterfaceKey interfaceKey = new InterfaceKey(parentRefs.getParentInterface());
@@ -68,35 +54,8 @@ public class OvsVlanMemberConfigAddHelper {
                 InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(parentRefs.getParentInterface(), dataBroker);
         if (ifState != null) {
             LOG.debug("add interface state info for vlan member {}",interfaceNew.getName());
-            OperStatus operStatus = ifState.getOperStatus();
-            AdminStatus adminStatus = ifState.getAdminStatus();
-            PhysAddress physAddress = ifState.getPhysAddress();
-
-            if (!interfaceNew.isEnabled()) {
-                operStatus = OperStatus.Down;
-            }
+            InterfaceManagerCommonUtils.addStateEntry(interfaceNew.getName(), t, dataBroker, idManager, ifState);
 
-            InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
-                    IfmUtil.buildStateInterfaceId(interfaceNew.getName());
-            List<String> lowerLayerIfList = new ArrayList<>();
-            lowerLayerIfList.add(ifState.getLowerLayerIf().get(0));
-            //lowerLayerIfList.add(parentRefs.getParentInterface());
-            Integer ifIndex = IfmUtil.allocateId(idManager, IfmConstants.IFM_IDPOOL_NAME, interfaceNew.getName());
-            InterfaceBuilder ifaceBuilder = new InterfaceBuilder().setAdminStatus(adminStatus).setOperStatus(operStatus)
-                    .setPhysAddress(physAddress).setLowerLayerIf(lowerLayerIfList).setIfIndex(ifIndex);
-            ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(interfaceNew.getName()));
-            t.put(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build(), true);
-
-            // create lportTag Interface Map
-            InterfaceMetaUtils.createLportTagInterfaceMap(t, interfaceNew.getName(), ifIndex);
-            //Installing vlan flow for vlan member
-            NodeConnectorId nodeConnectorId = new NodeConnectorId(ifState.getLowerLayerIf().get(0));
-            BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
-            long portNo = Long.valueOf(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId));
-            if (operStatus == OperStatus.Up) {
-                List<MatchInfo> matches = FlowBasedServicesUtils.getMatchInfoForVlanPortAtIngressTable(dpId, portNo, interfaceNew);
-                FlowBasedServicesUtils.installVlanFlow(dpId, portNo, interfaceNew, t, matches, ifIndex);
-            }
 
             // FIXME: Maybe, add the new interface to the higher-layer if of the parent interface-state.
             // That may not serve any purpose though for interface manager.... Unless some external parties are interested in it.
index 7d90a44adb7fc1e3abb8d60ecccf411f883c576a..24832638ad560c16a40d37161188cc313a1807f8 100644 (file)
@@ -7,16 +7,16 @@
  */
 package org.opendaylight.vpnservice.interfacemgr.renderer.ovs.statehelpers;
 
-import com.google.common.util.concurrent.ListenableFuture;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.vpnservice.interfacemgr.IfmConstants;
 import org.opendaylight.vpnservice.interfacemgr.IfmUtil;
 import org.opendaylight.vpnservice.interfacemgr.commons.AlivenessMonitorUtils;
 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils;
 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils;
-import org.opendaylight.vpnservice.interfacemgr.servicebindings.flowbased.utilities.FlowBasedServicesUtils;
-import org.opendaylight.vpnservice.mdsalutil.MatchInfo;
 import org.opendaylight.vpnservice.mdsalutil.NwConstants;
 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
@@ -33,9 +33,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.List;
+import com.google.common.util.concurrent.ListenableFuture;
 
 /**
  * This worker is responsible for adding the openflow-interfaces/of-port-info container
@@ -73,12 +71,12 @@ public class OvsInterfaceStateAddHelper {
 
         Interface ifState = InterfaceManagerCommonUtils.addStateEntry(iface, portName, transaction, idManager,
                 physAddress, operStatus, adminStatus, nodeConnectorId);
-        BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
-        long portNo = Long.valueOf(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId));
         // If this interface is a tunnel interface, create the tunnel ingress flow
         if(iface != null) {
             IfTunnel tunnel = iface.getAugmentation(IfTunnel.class);
             if (tunnel != null) {
+                BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
+                long portNo = Long.valueOf(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId));
                 InterfaceManagerCommonUtils.makeTunnelIngressFlow(futures, mdsalApiManager, tunnel, dpId, portNo, iface,
                         ifState.getIfIndex(), NwConstants.ADD_FLOW);
                 futures.add(transaction.submit());
index 5bc4219e9fb833ff2bcdeb4e1d95c5def688f7b4..1308221d1e8ce14d9237990947507677801b0e96 100644 (file)
@@ -125,7 +125,7 @@ public class FlowBasedServicesConfigBindHelper {
             if (matches != null) {
 
                 WriteTransaction removeFlowTransaction = dataBroker.newWriteOnlyTransaction();
-                FlowBasedServicesUtils.removeIngressFlow(iface, serviceToReplace, dpId, removeFlowTransaction);
+                FlowBasedServicesUtils.removeIngressFlow(iface.getName(), serviceToReplace, dpId, removeFlowTransaction);
                 futures.add(removeFlowTransaction.submit());
 
                 WriteTransaction installFlowTransaction = dataBroker.newWriteOnlyTransaction();
index 6984e784d3b7a61988df7ac55f0edbef99211eb4..25b93c24f5b3228871983f665d0b4c2ce993e5c0 100644 (file)
@@ -82,7 +82,7 @@ public class FlowBasedServicesConfigUnbindHelper {
         BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
         if (boundServices.isEmpty()) {
             // Remove default entry from Lport Dispatcher Table.
-            FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, boundServiceOld, t, IfmConstants.DEFAULT_SERVICE_INDEX);
+            FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface.getName(), boundServiceOld, t, IfmConstants.DEFAULT_SERVICE_INDEX);
             if (t != null) {
                 futures.add(t.submit());
             }
@@ -94,11 +94,11 @@ public class FlowBasedServicesConfigUnbindHelper {
         // This means the one removed was the highest priority service
         if (high == null) {
             LOG.trace("Deleting table entry for service {}, match service index {}", boundServiceOld, IfmConstants.DEFAULT_SERVICE_INDEX);
-            FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, boundServiceOld, t, IfmConstants.DEFAULT_SERVICE_INDEX);
+            FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface.getName(), boundServiceOld, t, IfmConstants.DEFAULT_SERVICE_INDEX);
             if (low != null) {
                 //delete the lower services flow entry.
                 LOG.trace("Deleting table entry for lower service {}, match service index {}", low, low.getServicePriority());
-                FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, low, t, low.getServicePriority());
+                FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface.getName(), low, t, low.getServicePriority());
                 BoundServices lower = FlowBasedServicesUtils.getHighAndLowPriorityService(boundServices, low)[0];
                 short lowerServiceIndex = (short) ((lower!=null) ? lower.getServicePriority() : low.getServicePriority() + 1);
                 LOG.trace("Installing new entry for lower service {}, match service index {}, update service index {}", low, IfmConstants.DEFAULT_SERVICE_INDEX, lowerServiceIndex);
@@ -106,7 +106,7 @@ public class FlowBasedServicesConfigUnbindHelper {
             }
         } else {
             LOG.trace("Deleting table entry for service {}, match service index {}", boundServiceOld, boundServiceOld.getServicePriority());
-            FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, boundServiceOld, t, boundServiceOld.getServicePriority());
+            FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface.getName(), boundServiceOld, t, boundServiceOld.getServicePriority());
             short lowerServiceIndex = (short) ((low!=null) ? low.getServicePriority() : boundServiceOld.getServicePriority() + 1);
             BoundServices highest = FlowBasedServicesUtils.getHighestPriorityService(boundServices);
             if (high.equals(highest)) {
@@ -134,7 +134,7 @@ public class FlowBasedServicesConfigUnbindHelper {
 
         if (boundServices.isEmpty()) {
             // Remove entry from Ingress Table.
-            FlowBasedServicesUtils.removeIngressFlow(iface, boundServiceOld, dpId, t);
+            FlowBasedServicesUtils.removeIngressFlow(iface.getName(), boundServiceOld, dpId, t);
             if (t != null) {
                 futures.add(t.submit());
             }
@@ -151,7 +151,7 @@ public class FlowBasedServicesConfigUnbindHelper {
         }
 
         if (highestPriority < boundServiceOld.getServicePriority()) {
-            FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, boundServiceOld, t, boundServiceOld.getServicePriority());
+            FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface.getName(), boundServiceOld, t, boundServiceOld.getServicePriority());
             if (t != null) {
                 futures.add(t.submit());
             }
@@ -162,10 +162,10 @@ public class FlowBasedServicesConfigUnbindHelper {
         matches = FlowBasedServicesUtils.getMatchInfoForTunnelPortAtIngressTable (dpId, portNo, iface);
 
         BoundServices toBeMoved = tmpServicesMap.get(highestPriority);
-        FlowBasedServicesUtils.removeIngressFlow(iface, boundServiceOld, dpId, t);
+        FlowBasedServicesUtils.removeIngressFlow(iface.getName(), boundServiceOld, dpId, t);
         FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface, toBeMoved, t,
                 matches, ifIndex, NwConstants.VLAN_INTERFACE_INGRESS_TABLE);
-        FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, toBeMoved, t, toBeMoved.getServicePriority());
+        FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface.getName(), toBeMoved, t, toBeMoved.getServicePriority());
 
         if (t != null) {
             futures.add(t.submit());
index 6186802fcc37e780c0c1a4a068a62e2a253f986a..3f6cac015d07afed60f5222a3676ba7511afc224 100644 (file)
@@ -101,7 +101,7 @@ public class FlowBasedServicesStateBindHelper {
         Collections.sort(allServices, new Comparator<BoundServices>() {
             @Override
             public int compare(BoundServices serviceInfo1, BoundServices serviceInfo2) {
-                return serviceInfo2.getServicePriority().compareTo(serviceInfo1.getServicePriority());
+                return serviceInfo1.getServicePriority().compareTo(serviceInfo2.getServicePriority());
             }
         });
         BoundServices highestPriority = allServices.remove(0);
index ede481e1e88eee26fc6f127d475b73e8bf8b3ea3..619c6bf595fef0ca109212c17b17af643f1d7218 100644 (file)
@@ -17,11 +17,9 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.vpnservice.interfacemgr.IfmConstants;
 import org.opendaylight.vpnservice.interfacemgr.IfmUtil;
-import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils;
 import org.opendaylight.vpnservice.interfacemgr.servicebindings.flowbased.utilities.FlowBasedServicesUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.servicebinding.rev151015.service.bindings.ServicesInfo;
@@ -48,37 +46,34 @@ public class FlowBasedServicesStateUnbindHelper {
             return futures;
         }
 
-        InterfaceKey interfaceKey = new InterfaceKey(ifaceState.getName());
-        org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface =
-                    InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
-
         if (ifaceState.getType().isAssignableFrom(L2vlan.class)) {
-            return unbindServiceOnVlan(allServices, iface, ifaceState.getIfIndex(), dataBroker);
+            return unbindServiceOnVlan(allServices, ifaceState, ifaceState.getIfIndex(), dataBroker);
         } else if (ifaceState.getType().isAssignableFrom(Tunnel.class)){
-             return unbindServiceOnTunnel(allServices, iface, ifaceState.getIfIndex(), dataBroker);
+             return unbindServiceOnTunnel(allServices, ifaceState, ifaceState.getIfIndex(), dataBroker);
         }
         return futures;
     }
 
     private static List<ListenableFuture<Void>> unbindServiceOnTunnel(
             List<BoundServices> allServices,
-            org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface,
+            Interface iface,
             Integer ifIndex, DataBroker dataBroker) {
         List<ListenableFuture<Void>> futures = new ArrayList<>();
         WriteTransaction t = dataBroker.newWriteOnlyTransaction();
 
-        NodeConnectorId nodeConnectorId = FlowBasedServicesUtils.getNodeConnectorIdFromInterface(iface, dataBroker);
+        List<String> ofportIds = iface.getLowerLayerIf();
+        NodeConnectorId nodeConnectorId = new NodeConnectorId(ofportIds.get(0));
         if(nodeConnectorId == null){
             return futures;
         }
         BoundServices highestPriorityBoundService = FlowBasedServicesUtils.getHighestPriorityService(allServices);
 
         BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
-        FlowBasedServicesUtils.removeIngressFlow(iface, highestPriorityBoundService, dpId, t);
+        FlowBasedServicesUtils.removeIngressFlow(iface.getName(), highestPriorityBoundService, dpId, t);
 
         for (BoundServices boundService : allServices) {
             if (!boundService.equals(highestPriorityBoundService)) {
-                FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, boundService, t, boundService.getServicePriority());
+                FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface.getName(), boundService, t, boundService.getServicePriority());
             }
         }
 
@@ -87,26 +82,26 @@ public class FlowBasedServicesStateUnbindHelper {
     }
 
     private static List<ListenableFuture<Void>> unbindServiceOnVlan(
-            List<BoundServices> allServices,
-            org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface,
+            List<BoundServices> allServices, Interface ifaceState,
             Integer ifIndex, DataBroker dataBroker) {
         List<ListenableFuture<Void>> futures = new ArrayList<>();
         WriteTransaction t = dataBroker.newWriteOnlyTransaction();
-        NodeConnectorId nodeConnectorId = FlowBasedServicesUtils.getNodeConnectorIdFromInterface(iface, dataBroker);
-        if (nodeConnectorId == null) {
+        List<String> ofportIds = ifaceState.getLowerLayerIf();
+        NodeConnectorId nodeConnectorId = new NodeConnectorId(ofportIds.get(0));
+        if(nodeConnectorId == null){
             return futures;
         }
         BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
         Collections.sort(allServices, new Comparator<BoundServices>() {
             @Override
             public int compare(BoundServices serviceInfo1, BoundServices serviceInfo2) {
-                return serviceInfo2.getServicePriority().compareTo(serviceInfo1.getServicePriority());
+                return serviceInfo1.getServicePriority().compareTo(serviceInfo2.getServicePriority());
             }
         });
         BoundServices highestPriority = allServices.remove(0);
-        FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, highestPriority, t, IfmConstants.DEFAULT_SERVICE_INDEX);
+        FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, ifaceState.getName(), highestPriority, t, IfmConstants.DEFAULT_SERVICE_INDEX);
         for (BoundServices boundService : allServices) {
-                FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, boundService, t, boundService.getServicePriority());
+                FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, ifaceState.getName(), boundService, t, boundService.getServicePriority());
         }
         futures.add(t.submit());
         return futures;
index 36730e4c2eb75085138a6aa445eac2130e53a4c3..787ad51c330968ca2555e7daa000884648e29a62 100644 (file)
@@ -39,7 +39,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.servicebinding.rev151015.ServiceBindings;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.servicebinding.rev151015.StypeOpenflow;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.servicebinding.rev151015.service.bindings.ServicesInfo;
@@ -243,9 +242,9 @@ public class FlowBasedServicesUtils {
         installFlow(dpId, ingressFlow, t);
     }
 
-    public static void removeIngressFlow(Interface iface, BoundServices serviceOld, BigInteger dpId, WriteTransaction t) {
+    public static void removeIngressFlow(String name, BoundServices serviceOld, BigInteger dpId, WriteTransaction t) {
         LOG.debug("Removing Ingress Flows");
-        String flowKeyStr = getFlowRef(dpId, iface.getName(), serviceOld, serviceOld.getServicePriority());
+        String flowKeyStr = getFlowRef(dpId, name, serviceOld, serviceOld.getServicePriority());
         FlowKey flowKey = new FlowKey(new FlowId(flowKeyStr));
         Node nodeDpn = buildInventoryDpnNode(dpId);
         InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class)
@@ -255,17 +254,17 @@ public class FlowBasedServicesUtils {
         t.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId);
     }
 
-    public static void removeLPortDispatcherFlow(BigInteger dpId, Interface iface, BoundServices boundServicesOld, WriteTransaction t, short currentServiceIndex) {
+    public static void removeLPortDispatcherFlow(BigInteger dpId, String iface, BoundServices boundServicesOld, WriteTransaction t, short currentServiceIndex) {
         LOG.debug("Removing LPort Dispatcher Flows {}, {}", dpId, iface);
 
         StypeOpenflow stypeOpenFlow = boundServicesOld.getAugmentation(StypeOpenflow.class);
         // build the flow and install it
-        String flowRef = getFlowRef(dpId, iface.getName(), boundServicesOld, currentServiceIndex);
+        String flowRef = getFlowRef(dpId, iface, boundServicesOld, currentServiceIndex);
         FlowKey flowKey = new FlowKey(new FlowId(flowRef));
         Node nodeDpn = buildInventoryDpnNode(dpId);
         InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class)
                 .child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class)
-                .child(Table.class, new TableKey(stypeOpenFlow.getDispatcherTableId())).child(Flow.class, flowKey).build();
+                .child(Table.class, new TableKey(NwConstants.LPORT_DISPATCHER_TABLE)).child(Flow.class, flowKey).build();
 
         t.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId);
     }
@@ -295,11 +294,11 @@ public class FlowBasedServicesUtils {
         Collections.sort(availableServiceInfos, new Comparator<BoundServices>() {
             @Override
             public int compare(BoundServices serviceInfo1, BoundServices serviceInfo2) {
-                return serviceInfo2.getServicePriority().compareTo(serviceInfo1.getServicePriority());
+                return serviceInfo1.getServicePriority().compareTo(serviceInfo2.getServicePriority());
             }
         });
         for (BoundServices availableServiceInfo: availableServiceInfos) {
-            if (currentServiceInfo.getServicePriority() > availableServiceInfo.getServicePriority()) {
+            if (currentServiceInfo.getServicePriority() < availableServiceInfo.getServicePriority()) {
                 lower = availableServiceInfo;
                 break;
             } else {
@@ -317,7 +316,7 @@ public class FlowBasedServicesUtils {
         BoundServices highPriorityService = availableServiceInfos.get(0);
         availableServiceInfos.remove(0);
         for (BoundServices availableServiceInfo: availableServiceInfos) {
-            if (availableServiceInfo.getServicePriority() > highPriorityService.getServicePriority()) {
+            if (availableServiceInfo.getServicePriority() < highPriorityService.getServicePriority()) {
                 highPriorityService = availableServiceInfo;
             }
         }
index eddaeb4fed7e2f74cd9dd5ab915c3c8664c05612..1cb20a09e931a260315944ada7094655b2f669f7 100644 (file)
@@ -16,10 +16,5 @@ public class ITMConstants{
   public static final String ITM_IDPOOL_NAME = "Itmservices";
   public static final long ITM_IDPOOL_START = 1L;
   public static final String ITM_IDPOOL_SIZE = "100000";
-                
-    public static final short INTERNAL_TUNNEL_TABLE = 22;
-
-
-
-    public static final short TERMINATING_SERVICE_TABLE = 36;
+  public static int LLDP_SERVICE_ID = 0;
 }
index 81f6aaefbe0a6bbd8fd36c7b98bc715e26b1a961..5cef68f26bf98a59928ed2c348a6198be3d451a9 100644 (file)
@@ -53,8 +53,8 @@ public class ItmExternalTunnelDeleteWorker {
                             ExternalTunnelList.class)
                                 .child(ExternalTunnel.class, new ExternalTunnelKey(extIp, teps.getDPNID()));
                     t.delete(LogicalDatastoreType.CONFIGURATION, path);
-                    // Release the Ids for the trunk interface
-                    ItmUtils.releaseId(idManagerService, trunkInterfaceName);
+                    // Release the Ids for the trunk interface Name
+                    ItmUtils.releaseIdForTrunkInterfaceName(idManagerService,interfaceName,firstEndPt.getIpAddress().getIpv4Address().getValue(), extIp.getIpv4Address().getValue() );
                 }
             }
             futures.add(t.submit()) ;
index bde34d017104f5c85d67f14b71542f2bf87c5fb8..c7c5ae726bc7b3c9e6eefe17c3935605593ab4e8 100644 (file)
@@ -15,12 +15,15 @@ import java.util.concurrent.Callable;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.ListenableFuture;
 
+import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
+import org.opendaylight.vpnservice.itm.globals.ITMConstants;
 import org.opendaylight.vpnservice.itm.impl.ItmUtils;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 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.idmanager.rev150403.IdManagerService;
+import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.TunnelTypeBase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.TunnelTypeGre;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.TunnelTypeVxlan;
@@ -54,7 +57,7 @@ public class ItmInternalTunnelAddWorker {
              };
 
 
-    public static List<ListenableFuture<Void>> build_all_tunnels(DataBroker dataBroker, IdManagerService idManagerService,
+    public static List<ListenableFuture<Void>> build_all_tunnels(DataBroker dataBroker, IdManagerService idManagerService,IMdsalApiManager mdsalManager,
                                                                  List<DPNTEPsInfo> cfgdDpnList, List<DPNTEPsInfo> meshedDpnList) {
         logger.trace( "Building tunnels with DPN List {} " , cfgdDpnList );
         List<ListenableFuture<Void>> futures = new ArrayList<>();
@@ -66,7 +69,7 @@ public class ItmInternalTunnelAddWorker {
 
         for( DPNTEPsInfo dpn : cfgdDpnList) {
             //#####if dpn is not in meshedDpnList
-            build_tunnel_from(dpn, meshedDpnList, dataBroker, idManagerService, t, futures);
+            build_tunnel_from(dpn, meshedDpnList, dataBroker, idManagerService, mdsalManager, t, futures);
             if(null == meshedDpnList) {
                 meshedDpnList = new ArrayList<DPNTEPsInfo>() ;
             }
@@ -87,7 +90,7 @@ public class ItmInternalTunnelAddWorker {
         t.merge(LogicalDatastoreType.CONFIGURATION, dep, tnlBuilder, true);
     }
 
-    private static void build_tunnel_from( DPNTEPsInfo srcDpn,List<DPNTEPsInfo> meshedDpnList, DataBroker dataBroker,  IdManagerService idManagerService, WriteTransaction t, List<ListenableFuture<Void>> futures) {
+    private static void build_tunnel_from( DPNTEPsInfo srcDpn,List<DPNTEPsInfo> meshedDpnList, DataBroker dataBroker,  IdManagerService idManagerService, IMdsalApiManager mdsalManager, WriteTransaction t, List<ListenableFuture<Void>> futures) {
         logger.trace( "Building tunnels from DPN {} " , srcDpn );
 
         if( null == meshedDpnList || 0 == meshedDpnList.size()) {
@@ -96,13 +99,13 @@ public class ItmInternalTunnelAddWorker {
         }
         for( DPNTEPsInfo dstDpn: meshedDpnList) {
             if ( ! srcDpn.equals(dstDpn) )
-                    wireUpWithinTransportZone(srcDpn, dstDpn, dataBroker, idManagerService, t, futures) ;
+                    wireUpWithinTransportZone(srcDpn, dstDpn, dataBroker, idManagerService, mdsalManager, t, futures) ;
         }
 
    }
 
     private static void wireUpWithinTransportZone( DPNTEPsInfo srcDpn, DPNTEPsInfo dstDpn, DataBroker dataBroker,
-                                                   IdManagerService idManagerService, WriteTransaction t, List<ListenableFuture<Void>> futures) {
+                                                   IdManagerService idManagerService, IMdsalApiManager mdsalManager,WriteTransaction t, List<ListenableFuture<Void>> futures) {
         logger.trace( "Wiring up within Transport Zone for Dpns {}, {} " , srcDpn, dstDpn );
         List<TunnelEndPoints> srcEndPts = srcDpn.getTunnelEndPoints();
         List<TunnelEndPoints> dstEndPts = dstDpn.getTunnelEndPoints();
@@ -113,7 +116,7 @@ public class ItmInternalTunnelAddWorker {
               if (!srcDpn.getDPNID().equals(dstDpn.getDPNID())) {
                 if( (srcte.getTransportZone().equals(dstte.getTransportZone()))) {
                      // wire them up
-                     wireUpBidirectionalTunnel( srcte, dstte, srcDpn.getDPNID(), dstDpn.getDPNID(), dataBroker, idManagerService, t, futures );
+                     wireUpBidirectionalTunnel( srcte, dstte, srcDpn.getDPNID(), dstDpn.getDPNID(), dataBroker, idManagerService,  mdsalManager, t, futures );
                      // CHECK THIS -- Assumption -- One end point per Dpn per transport zone
                      break ;
                 }
@@ -123,10 +126,10 @@ public class ItmInternalTunnelAddWorker {
     }
 
     private static void wireUpBidirectionalTunnel( TunnelEndPoints srcte, TunnelEndPoints dstte, BigInteger srcDpnId, BigInteger dstDpnId,
-        DataBroker dataBroker,  IdManagerService idManagerService, WriteTransaction t, List<ListenableFuture<Void>> futures) {
+        DataBroker dataBroker,  IdManagerService idManagerService, IMdsalApiManager mdsalManager, WriteTransaction t, List<ListenableFuture<Void>> futures) {
        // Setup the flow for LLDP monitoring -- PUNT TO CONTROLLER
-       //  setUpOrRemoveTerminatingServiceTable(srcDpnId, true);
-       //  setUpOrRemoveTerminatingServiceTable(dstDpnId, true);
+         ItmUtils.setUpOrRemoveTerminatingServiceTable(srcDpnId, mdsalManager, true);
+         ItmUtils.setUpOrRemoveTerminatingServiceTable(dstDpnId, mdsalManager, true);
 
         // Create the forward direction tunnel
         if(!wireUp( srcte, dstte, srcDpnId, dstDpnId, dataBroker, idManagerService, t, futures ))
@@ -164,5 +167,4 @@ public class ItmInternalTunnelAddWorker {
         t.merge(LogicalDatastoreType.CONFIGURATION,path, tnl, true) ;
         return true;
     }
-
 }
index 096d81cffdec780ed96d74ee54cc12be3022ffa4..9e113f25b04887fddeb07d938ac43c7afd66dc19 100644 (file)
@@ -18,6 +18,7 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.vpnservice.itm.impl.ItmUtils;
 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.idmanager.rev150403.IdManagerService;
+import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.DpnEndpoints;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.DPNTEPsInfo;
@@ -34,7 +35,7 @@ import com.google.common.util.concurrent.ListenableFuture;
 public class ItmInternalTunnelDeleteWorker {
    private static final Logger logger = LoggerFactory.getLogger(ItmInternalTunnelDeleteWorker.class) ;
 
-    public static List<ListenableFuture<Void>> deleteTunnels(DataBroker dataBroker, IdManagerService idManagerService,
+    public static List<ListenableFuture<Void>> deleteTunnels(DataBroker dataBroker, IdManagerService idManagerService,IMdsalApiManager mdsalManager,
                                                              List<DPNTEPsInfo> dpnTepsList, List<DPNTEPsInfo> meshedDpnList)
     {
         List<ListenableFuture<Void>> futures = new ArrayList<>();
@@ -61,9 +62,11 @@ public class ItmInternalTunnelDeleteWorker {
                             for (TunnelEndPoints dstTep : dstDpn.getTunnelEndPoints()) {
                                 logger.trace("Processing dstTep " + dstTep);
                                 if (dstTep.getTransportZone().equals(srcTZone)) {
+                                    if( checkIfTrunkExists(dstDpn.getDPNID(), srcDpn.getDPNID(), dataBroker)) {
                                     // remove all trunk interfaces
                                     logger.trace("Invoking removeTrunkInterface between source TEP {} , Destination TEP {} " ,srcTep , dstTep);
                                     removeTrunkInterface(dataBroker, idManagerService, srcTep, dstTep, srcDpn.getDPNID(), dstDpn.getDPNID(), t, futures);
+                                    }
                                 }
                             }
                         }
@@ -86,7 +89,7 @@ public class ItmInternalTunnelDeleteWorker {
                         // remove dpn if no vteps exist on dpn
                         if (dpnRead.getTunnelEndPoints() == null || dpnRead.getTunnelEndPoints().size() == 0) {
                             logger.debug( "Removing Terminating Service Table Flow ") ;
-                           // setUpOrRemoveTerminatingServiceTable(dpnRead.getDPNID(), false);
+                           ItmUtils.setUpOrRemoveTerminatingServiceTable(dpnRead.getDPNID(), mdsalManager,false);
                             logger.trace("DPN Removal from DPNTEPSINFO CONFIG DS " + dpnRead);
                             t.delete(LogicalDatastoreType.CONFIGURATION, dpnPath);
                             InstanceIdentifier<DpnEndpoints> tnlContainerPath =
@@ -96,7 +99,7 @@ public class ItmInternalTunnelDeleteWorker {
                                                             tnlContainerPath, dataBroker);
                             // remove container if no DPNs are present
                             if (containerOptional.isPresent()) {
-                               DpnEndpoints deps = containerOptional.get();
+                               DpnEndpoints deps = containerOptional.get();
                                 if (deps.getDPNTEPsInfo() == null || deps.getDPNTEPsInfo().isEmpty()) {
                                     logger.trace("Container Removal from DPNTEPSINFO CONFIG DS");
                                     t.delete(LogicalDatastoreType.CONFIGURATION, tnlContainerPath);
@@ -122,7 +125,7 @@ public class ItmInternalTunnelDeleteWorker {
                                         .getValue());
         logger.trace("Removing forward Trunk Interface " + trunkfwdIfName);
         InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkfwdIfName);
-        logger.debug(  " Removing Trunk Interface Name - {} , Id - {} from Config DS {}, {} ", trunkfwdIfName, trunkIdentifier ) ;
+        logger.debug(  " Removing Trunk Interface Name - {} , Id - {} from Config DS ", trunkfwdIfName, trunkIdentifier ) ;
         t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
 
         // also update itm-state ds -- Delete the forward tunnel-interface from the tunnel list
@@ -130,16 +133,18 @@ public class ItmInternalTunnelDeleteWorker {
                 TunnelList.class)
                     .child(InternalTunnel.class, new InternalTunnelKey( srcDpnId, dstDpnId));   
         t.delete(LogicalDatastoreType.CONFIGURATION,path) ;
-        // Release the Id for the forward trunk
-        ItmUtils.releaseId(idManagerService, trunkfwdIfName);
+        // Release the Ids for the forward trunk interface Name
+        ItmUtils.releaseIdForTrunkInterfaceName(idManagerService,srcTep.getInterfaceName(), srcTep.getIpAddress()
+                .getIpv4Address().getValue(), dstTep.getIpAddress().getIpv4Address()
+                .getValue() );
 
         String trunkRevIfName =
                         ItmUtils.getTrunkInterfaceName(idManagerService, dstTep.getInterfaceName(), dstTep.getIpAddress()
                                         .getIpv4Address().getValue(), srcTep.getIpAddress().getIpv4Address()
                                         .getValue());
         logger.trace("Removing Reverse Trunk Interface " + trunkRevIfName);
-        trunkIdentifier = ItmUtils.buildId(trunkfwdIfName);
-        logger.debug(  " Removing Trunk Interface Name - {} , Id - {} from Config DS {}, {} ", trunkfwdIfName, trunkIdentifier ) ;
+        trunkIdentifier = ItmUtils.buildId(trunkRevIfName);
+        logger.debug(  " Removing Trunk Interface Name - {} , Id - {} from Config DS ", trunkRevIfName, trunkIdentifier ) ;
         t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
 
      // also update itm-state ds -- Delete the reverse tunnel-interface from the tunnel list
@@ -148,7 +153,19 @@ public class ItmInternalTunnelDeleteWorker {
                     .child(InternalTunnel.class, new InternalTunnelKey(dstDpnId, srcDpnId));   
         t.delete(LogicalDatastoreType.CONFIGURATION,path) ;
         
-        // Release the Id for the Reverse trunk
-        ItmUtils.releaseId(idManagerService, trunkRevIfName);
+     // Release the Ids for the reverse trunk interface Name
+        ItmUtils.releaseIdForTrunkInterfaceName(idManagerService, dstTep.getInterfaceName(), dstTep.getIpAddress()
+                .getIpv4Address().getValue(), srcTep.getIpAddress().getIpv4Address()
+                .getValue());
+    }
+    private static boolean checkIfTrunkExists( BigInteger srcDpnId, BigInteger dstDpnId, DataBroker dataBroker) {
+        boolean existsFlag = false ;
+        InstanceIdentifier<InternalTunnel> path = InstanceIdentifier.create(
+                TunnelList.class)
+                    .child(InternalTunnel.class, new InternalTunnelKey( srcDpnId, dstDpnId));   
+        Optional<InternalTunnel> internalTunnels = ItmUtils.read(LogicalDatastoreType.CONFIGURATION,path, dataBroker) ;
+        if( internalTunnels.isPresent())
+            existsFlag = true ;
+           return existsFlag ;
     }
 }
index 92c17e06e4d9f039cdc6397259fbbdcda0ed45bc..40a5314ec1eb9b718e7ecc9fac6f32436fd2b921 100644 (file)
@@ -16,6 +16,7 @@ import com.google.common.util.concurrent.ListenableFuture;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.vpnservice.itm.impl.ItmUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
+import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.DPNTEPsInfo;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
@@ -26,11 +27,13 @@ public class ItmTepAddWorker implements Callable<List<ListenableFuture<Void>>> {
     private IdManagerService idManagerService;
     private List<DPNTEPsInfo> meshedDpnList;
     private List<DPNTEPsInfo> cfgdDpnList ;
+    private IMdsalApiManager mdsalManager;
 
-    public ItmTepAddWorker( List<DPNTEPsInfo> cfgdDpnList,  DataBroker broker, IdManagerService idManagerService) {
+    public ItmTepAddWorker( List<DPNTEPsInfo> cfgdDpnList,  DataBroker broker, IdManagerService idManagerService, IMdsalApiManager mdsalManager) {
         this.cfgdDpnList = cfgdDpnList ;
         this.dataBroker = broker ;
         this.idManagerService = idManagerService;
+        this.mdsalManager = mdsalManager;
         logger.trace("ItmTepAddWorker initialized with  DpnList {}",cfgdDpnList );
     }
 
@@ -39,7 +42,7 @@ public class ItmTepAddWorker implements Callable<List<ListenableFuture<Void>>> {
         List<ListenableFuture<Void>> futures = new ArrayList<>() ;
         this.meshedDpnList = ItmUtils.getTunnelMeshInfo(dataBroker) ;
         logger.debug("Invoking Internal Tunnel build method with Configured DpnList {} ; Meshed DpnList {} ",cfgdDpnList, meshedDpnList );
-        futures.addAll( ItmInternalTunnelAddWorker.build_all_tunnels(dataBroker, idManagerService, cfgdDpnList, meshedDpnList) ) ;
+        futures.addAll( ItmInternalTunnelAddWorker.build_all_tunnels(dataBroker, idManagerService,mdsalManager, cfgdDpnList, meshedDpnList) ) ;
         // IF EXTERNAL TUNNELS NEEDS TO BE BUILT, DO IT HERE. IT COULD BE TO DC GATEWAY OR TOR SWITCH
         //futures.addAll(ItmExternalTunnelAddWorker.buildTunnelsToExternalEndPoint(dataBroker,meshedDpnList, extIp) ;
         return futures ;
index 6c4cb00810ca73fd6b74500778c43ddfead19b1b..dfc6afdfac3d67f2e60d8c6d3419838f895a4ef8 100644 (file)
@@ -16,6 +16,7 @@ import com.google.common.util.concurrent.ListenableFuture;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.vpnservice.itm.impl.ItmUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
+import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.DPNTEPsInfo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -26,11 +27,13 @@ public class ItmTepRemoveWorker implements Callable<List<ListenableFuture<Void>>
     private List<DPNTEPsInfo> delDpnList ;
     private List<DPNTEPsInfo> meshedDpnList ;
     private IdManagerService idManagerService;
+    private IMdsalApiManager mdsalManager;
 
-    public ItmTepRemoveWorker( List<DPNTEPsInfo> delDpnList,  DataBroker broker, IdManagerService idManagerService) {
+    public ItmTepRemoveWorker( List<DPNTEPsInfo> delDpnList,  DataBroker broker, IdManagerService idManagerService, IMdsalApiManager mdsalManager) {
         this.delDpnList = delDpnList ;
         this.dataBroker = broker ;
         this.idManagerService = idManagerService;
+        this.mdsalManager = mdsalManager;
         logger.trace("ItmTepRemoveWorker initialized with  DpnList {}",delDpnList );
     }
 
@@ -38,7 +41,7 @@ public class ItmTepRemoveWorker implements Callable<List<ListenableFuture<Void>>
     public List<ListenableFuture<Void>> call() throws Exception {
         List<ListenableFuture<Void>> futures = new ArrayList<>() ;
         this.meshedDpnList = ItmUtils.getTunnelMeshInfo(dataBroker) ;
-        futures.addAll( ItmInternalTunnelDeleteWorker.deleteTunnels(dataBroker, idManagerService, delDpnList, meshedDpnList));
+        futures.addAll( ItmInternalTunnelDeleteWorker.deleteTunnels(dataBroker, idManagerService, mdsalManager, delDpnList, meshedDpnList));
         logger.debug("Invoking Internal Tunnel delete method with DpnList to be deleted {} ; Meshed DpnList {} ",delDpnList, meshedDpnList );
         // IF EXTERNAL TUNNELS NEEDS TO BE DELETED, DO IT HERE, IT COULD BE TO DC GATEWAY OR TOR SWITCH
         return futures ;
index 1a4c02961f0f1ffc4df07d779646b3a8ea2825df..2c2126e95cc6f428f9e1117d07cdc387cb32882f 100644 (file)
@@ -73,6 +73,7 @@ public class ItmProvider implements BindingAwareProvider, AutoCloseable, IITMPro
             itmManager.setMdsalManager(mdsalManager);
             itmManager.setNotificationPublishService(notificationPublishService);
             itmManager.setMdsalManager(mdsalManager);
+            tzChangeListener.setMdsalManager(mdsalManager);
             tzChangeListener.setItmManager(itmManager);
             tzChangeListener.registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
             createIdPool();
index 0750ea479213dc7f63648f453a25b4f7aa7fc320..f597e9f32dd48650db6490540fa0e9454de78752 100644 (file)
@@ -46,6 +46,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnel;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnelBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnelKey;
+import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.vpnservice.itm.globals.ITMConstants;
 import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
@@ -62,6 +63,15 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import org.opendaylight.vpnservice.mdsalutil.ActionInfo;
+import org.opendaylight.vpnservice.mdsalutil.ActionType;
+import org.opendaylight.vpnservice.mdsalutil.FlowEntity;
+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.vpnservice.mdsalutil.NwConstants;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.net.InetAddresses;
@@ -139,6 +149,12 @@ public class ItmUtils {
         return trunkInterfaceName;
     }
 
+    public static void releaseIdForTrunkInterfaceName(IdManagerService idManager, String parentInterfaceName, String localHostName, String remoteHostName) {
+        String trunkInterfaceName = String.format("%s:%s:%s", parentInterfaceName, localHostName, remoteHostName);
+        LOG.trace("Releasing Id for trunkInterface - {}", trunkInterfaceName );
+        releaseId(idManager, trunkInterfaceName) ;
+    }
+
     public static InetAddress getInetAddressFromIpAddress(IpAddress ip) {
         return InetAddresses.forString(ip.getIpv4Address().getValue());
     }
@@ -260,4 +276,44 @@ public class ItmUtils {
         }
         return cfgDpnList;
     }
+
+    public static void setUpOrRemoveTerminatingServiceTable(BigInteger dpnId, IMdsalApiManager mdsalManager, boolean addFlag) {
+        String logmsg = ( addFlag == true) ? "Installing" : "Removing";
+        LOG.trace( logmsg + " PUNT to Controller flow in DPN {} ", dpnId );
+        long dpId;
+        List<ActionInfo> listActionInfo = new ArrayList<ActionInfo>();
+        listActionInfo.add(new ActionInfo(ActionType.punt_to_controller,
+                new String[] {}));
+
+        try {
+            List<MatchInfo> mkMatches = new ArrayList<MatchInfo>();
+
+            mkMatches.add(new MatchInfo(MatchFieldType.tunnel_id, new BigInteger[] {
+                    BigInteger.valueOf(ITMConstants.LLDP_SERVICE_ID) }));
+
+            List<InstructionInfo> mkInstructions = new ArrayList<InstructionInfo>();
+            mkInstructions.add(new InstructionInfo(InstructionType.apply_actions,
+                   listActionInfo));
+
+            FlowEntity terminatingServiceTableFlowEntity = MDSALUtil
+                    .buildFlowEntity(
+                             dpnId,
+                             NwConstants.INTERNAL_TUNNEL_TABLE,
+                            getFlowRef(NwConstants.INTERNAL_TUNNEL_TABLE,
+                                   ITMConstants.LLDP_SERVICE_ID), 5, String.format("%s:%d","ITM Flow Entry ",ITMConstants.LLDP_SERVICE_ID),
+                            0, 0, ITMConstants.COOKIE_ITM
+                                    .add(BigInteger.valueOf(ITMConstants.LLDP_SERVICE_ID)),
+                                    mkMatches, mkInstructions);
+            if(addFlag)
+                mdsalManager.installFlow(terminatingServiceTableFlowEntity);
+            else
+                mdsalManager.removeFlow(terminatingServiceTableFlowEntity);
+        } catch (Exception e) {
+            LOG.error("Error while setting up Table 36 for {}", dpnId, e);
+        }
+    }
+
+    private static String getFlowRef(long termSvcTable, int svcId) {
+        return new StringBuffer().append(termSvcTable).append(svcId).toString();
+    }
 }
index e60d3ee0fdde576b12fdb2fe64b6aa858f34b495..f15bd19b0fa0e3126a362635407a68f909aefd2a 100644 (file)
@@ -35,6 +35,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.tr
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.transport.zones.transport.zone.subnets.Vteps;
 import org.opendaylight.vpnservice.datastoreutils.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.vpnservice.datastoreutils.DataStoreJobCoordinator;
+import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.vpnservice.itm.impl.ITMManager;
 import org.opendaylight.vpnservice.itm.impl.ItmUtils;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -52,6 +53,7 @@ public class TransportZoneListener extends AsyncDataTreeChangeListenerBase<Trans
     private static final Logger LOG = LoggerFactory.getLogger(TransportZoneListener.class);
     private DataBroker dataBroker;
     private IdManagerService idManagerService;
+    private IMdsalApiManager mdsalManager;
     private ITMManager itmManager;
 
     public TransportZoneListener(final DataBroker dataBroker, final IdManagerService idManagerService) {
@@ -65,6 +67,10 @@ public class TransportZoneListener extends AsyncDataTreeChangeListenerBase<Trans
         this.itmManager = itmManager;
     }
 
+    public void setMdsalManager(IMdsalApiManager mdsalManager) {
+        this.mdsalManager = mdsalManager;
+    }
+
     private void initializeTZNode(DataBroker db) {
         ReadWriteTransaction transaction = db.newReadWriteTransaction();
         InstanceIdentifier<TransportZones> path = InstanceIdentifier.create(TransportZones.class);
@@ -106,7 +112,7 @@ public class TransportZoneListener extends AsyncDataTreeChangeListenerBase<Trans
             LOG.trace("Delete: Invoking ItmManager");
            // itmManager.deleteTunnels(opDpnList);
             DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
-            ItmTepRemoveWorker removeWorker = new ItmTepRemoveWorker(opDpnList, dataBroker, idManagerService);
+            ItmTepRemoveWorker removeWorker = new ItmTepRemoveWorker(opDpnList, dataBroker, idManagerService, mdsalManager);
             coordinator.enqueueJob(tzOld.getZoneName(), removeWorker);
         }
     }
@@ -128,7 +134,7 @@ public class TransportZoneListener extends AsyncDataTreeChangeListenerBase<Trans
           LOG.trace("Add: Invoking ItmManager with DPN List {} " , opDpnList);
           //itmManager.build_all_tunnels(opDpnList);
           DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
-          ItmTepAddWorker addWorker = new ItmTepAddWorker(opDpnList,dataBroker, idManagerService);
+          ItmTepAddWorker addWorker = new ItmTepAddWorker(opDpnList,dataBroker, idManagerService, mdsalManager);
           coordinator.enqueueJob(tzNew.getZoneName(), addWorker);
       }
     }
index bc306bbfd8ba33c4e310c27afcc867b085ae5792..470e9f0a36e0423a0048ad0da1ac12400827e791 100644 (file)
@@ -18,6 +18,11 @@ module neutronvpn {
               description "UUID representing the subnet ";
             }
 
+            leaf subnet-ip {
+                type    string;
+                description "Specifies the subnet IP in CIDR format";
+            }
+
             leaf tenant-id {
                 type    yang:uuid;
                 description "The UUID of the tenant that will own the subnet.";
index 50dc8ad6f099e2847e85cefe252f37362fe949a0..9a14c570bf505181b97c7c29dff8633dddf8ad07 100644 (file)
@@ -29,6 +29,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.E
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.elan.interfaces.ElanInterface;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.elan.interfaces.ElanInterfaceBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.elan.interfaces.ElanInterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfL2vlan;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfL2vlanBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.ParentRefs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.ParentRefsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.neutron.port.data
         .PortFixedipToPortNameBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.neutron.port.data
@@ -129,7 +133,7 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
         // Create of-port interface for this neutron port
         createOfPortInterface(port, portVlanId);
         LOG.debug("Creating ELAN Interface");
-        createElanInterface(port, portVlanId);
+        createElanInterface(port);
         LOG.debug("Add port to subnet");
         // add port to local Subnets DS
         Uuid vpnId = addPortToSubnets(port);
@@ -189,7 +193,10 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
                     interfaceIdentifier);
             if (!optionalInf.isPresent()) {
                 // handle these for trunkport extensions : portVlanId, isVlanTransparent
-                Interface inf = new InterfaceBuilder().setEnabled(true).setName(name).setType(L2vlan.class).build();
+                IfL2vlan l2vlan = new IfL2vlanBuilder().setL2vlanMode(IfL2vlan.L2vlanMode.Trunk).build();
+                ParentRefs parentRefs = new ParentRefsBuilder().setParentInterface(name).build();
+                Interface inf = new InterfaceBuilder().setEnabled(true).setName(name).setType(L2vlan.class)
+                        .addAugmentation(IfL2vlan.class, l2vlan).addAugmentation(ParentRefs.class, parentRefs).build();
                 MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, interfaceIdentifier, inf);
             } else {
                 LOG.error("Interface {} is already present", name);
@@ -227,18 +234,16 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
                 .getUuid());
     }
 
-    private void createElanInterface(Port port, int portVlanId) {
+    private void createElanInterface(Port port) {
         String name = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
-        String interfaceName = new StringBuilder(name).append(":").append(Integer.toString(portVlanId)).toString();
         String elanInstanceName = port.getNetworkId().getValue();
         List<PhysAddress> physAddresses = new ArrayList<>();
         physAddresses.add(new PhysAddress(port.getMacAddress()));
 
         InstanceIdentifier<ElanInterface> id = InstanceIdentifier.builder(ElanInterfaces.class).child(ElanInterface
-                .class, new ElanInterfaceKey(interfaceName)).build();
+                .class, new ElanInterfaceKey(name)).build();
         ElanInterface elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName)
-                .setName(interfaceName).setStaticMacEntries(physAddresses).
-                        setKey(new ElanInterfaceKey(interfaceName)).build();
+                .setName(name).setStaticMacEntries(physAddresses).setKey(new ElanInterfaceKey(name)).build();
         MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, id, elanInterface);
         LOG.debug("Creating new ELan Interface {}", elanInterface);
     }
@@ -262,8 +267,8 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
                     ipValue, name);
 
             subnetId = ip.getSubnetId();
-            Subnetmap subnetmap = nvpnManager.updateSubnetNode(subnetId, null, null, null, null, port.getUuid());
-            if (vpnId == null && subnetmap != null) {
+            Subnetmap subnetmap = nvpnManager.updateSubnetNode(subnetId, null, null, null, null, null, port.getUuid());
+            if (subnetmap != null) {
                 vpnId = subnetmap.getVpnId();
             }
         }
index 9da9f7d45b05ef7398eaded76f1a7f64ba2f1237..b2b46a94a956ccce4f02616c9394cb18bb7fb460 100644 (file)
@@ -7,15 +7,13 @@
  */
 package org.opendaylight.vpnservice.neutronvpn;
 
-
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes;
-
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.vpnservice.mdsalutil.AbstractDataChangeListener;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.Interfaces;
index bea68b9a52fd3cfb7464056bc5d46b9bc0e20e2d..9a6fa4e1e6e404f9349e5249cd254d093550a7e8 100644 (file)
@@ -76,7 +76,7 @@ public class NeutronSubnetChangeListener extends AbstractDataChangeListener<Subn
         if (LOG.isTraceEnabled()) {
             LOG.trace("Adding Subnet : key: " + identifier + ", value=" + input);
         }
-        handleNeutronSubnetCreated(input.getUuid(), input.getNetworkId(), input.getTenantId());
+        handleNeutronSubnetCreated(input.getUuid(), input.getCidr(), input.getNetworkId(), input.getTenantId());
     }
 
     @Override
@@ -96,8 +96,8 @@ public class NeutronSubnetChangeListener extends AbstractDataChangeListener<Subn
         handleNeutronSubnetUpdated(update.getUuid(), update.getNetworkId(), update.getTenantId());
     }
 
-    private void handleNeutronSubnetCreated(Uuid subnetId, Uuid networkId, Uuid tenantId) {
-        nvpnManager.updateSubnetNode(subnetId, tenantId, networkId, null, null, null);
+    private void handleNeutronSubnetCreated(Uuid subnetId, String subnetIp, Uuid networkId, Uuid tenantId) {
+        nvpnManager.updateSubnetNode(subnetId, subnetIp, tenantId, networkId, null, null, null);
         if (networkId != null && NeutronvpnUtils.getNeutronNetwork(broker, networkId) != null) {
             createSubnetToNetworkMapping(subnetId, networkId);
         }
@@ -111,6 +111,7 @@ public class NeutronSubnetChangeListener extends AbstractDataChangeListener<Subn
         if (networkId != null)  {
             deleteSubnetToNetworkMapping(subnetId, networkId);
         }
+        nvpnManager.deleteSubnetMapNode(subnetId);
     }
 
     private void handleNeutronSubnetUpdated(Uuid subnetId, Uuid networkId, Uuid tenantId) {
@@ -121,7 +122,7 @@ public class NeutronSubnetChangeListener extends AbstractDataChangeListener<Subn
         if (networkId != null && !networkId.equals(oldNetworkId)) {
             createSubnetToNetworkMapping(subnetId, networkId);
         }
-        nvpnManager.updateSubnetNode(subnetId, tenantId, networkId, null, null, null);
+        nvpnManager.updateSubnetNode(subnetId, null, tenantId, networkId, null, null, null);
     }
 
     private void createSubnetToNetworkMapping(Uuid subnetId, Uuid networkId) {
index a04c7ec6040460b08523e2c2631f8f1cbc4da0b7..87803b969519ae33c561bd8cce443538e2194788 100644 (file)
@@ -7,8 +7,6 @@
  */
 package org.opendaylight.vpnservice.neutronvpn;
 
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes;
-
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.SettableFuture;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -38,6 +36,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.Adjacencies
 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.adjacency.list.Adjacency;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.adjacency.list.AdjacencyBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.adjacency.list.AdjacencyKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports;
@@ -118,8 +117,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         logger.info("Neutron VPN Manager Closed");
     }
 
-    protected Subnetmap updateSubnetNode(Uuid subnetId, Uuid tenantId, Uuid networkId, Uuid routerId, Uuid vpnId,
-                                         Uuid portId) {
+    protected Subnetmap updateSubnetNode(Uuid subnetId, String subnetIp, Uuid tenantId, Uuid networkId, Uuid routerId,
+                                         Uuid vpnId, Uuid portId) {
         Subnetmap subnetmap = null;
         SubnetmapBuilder builder = null;
         boolean isLockAcquired = false;
@@ -136,6 +135,9 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
                 logger.debug("updating Subnet :new: ");
             }
 
+            if (subnetIp != null) {
+                builder.setSubnetIp(subnetIp);
+            }
             if (routerId != null) {
                 builder.setRouterId(routerId);
             }
@@ -213,6 +215,23 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         return subnetmap;
     }
 
+    protected void deleteSubnetMapNode(Uuid subnetId) {
+        boolean isLockAcquired = false;
+        InstanceIdentifier<Subnetmap> subnetMapIdentifier = InstanceIdentifier.builder(Subnetmaps.class)
+                .child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
+        logger.debug("removing subnetMap node: {} ", subnetId.getValue());
+        try {
+            isLockAcquired = NeutronvpnUtils.lock(lockManager, subnetId.getValue());
+            MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, subnetMapIdentifier);
+        } catch (Exception e) {
+            logger.error("Delete subnetMap node failed for subnet : {} ", subnetId.getValue());
+        } finally {
+            if (isLockAcquired) {
+                NeutronvpnUtils.unlock(lockManager, subnetId.getValue());
+            }
+        }
+    }
+
     private void updateVpnInstanceNode(String vpnName, List<String> rd, List<String> irt, List<String> ert) {
 
         VpnInstanceBuilder builder = null;
@@ -423,8 +442,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         }
         String portname = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
         List<Adjacency> adjList = new ArrayList<Adjacency>();
-        InstanceIdentifier<VpnInterface> vpnIfIdentifier = InstanceIdentifier.builder(VpnInterfaces.class).
-                child(VpnInterface.class, new VpnInterfaceKey(portname)).build();
+        InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(portname);
+
         // find router associated to vpn
         Uuid routerId = NeutronvpnUtils.getRouterforVpn(broker, vpnId);
         Router rtr = null;
@@ -474,8 +493,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         if (port != null) {
             boolean isLockAcquired = false;
             String pname = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
-            InstanceIdentifier<VpnInterface> vpnIfIdentifier = InstanceIdentifier.builder(VpnInterfaces.class).
-                    child(VpnInterface.class, new VpnInterfaceKey(pname)).build();
+            InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(pname);
+
             try {
                 isLockAcquired = NeutronvpnUtils.lock(lockManager, pname);
                 logger.debug("Deleting vpn interface {}", pname);
@@ -490,6 +509,35 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         }
     }
 
+    protected void updateVpnInterface(Uuid vpnId, Port port) {
+        if (vpnId == null || port == null) {
+            return;
+        }
+        boolean isLockAcquired = false;
+        String portname = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
+        String ifname = new StringBuilder(portname).append(":0").toString();
+        InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(ifname);
+        try {
+            Optional<VpnInterface> optionalVpnInterface = NeutronvpnUtils.read(broker, LogicalDatastoreType
+                    .CONFIGURATION, vpnIfIdentifier);
+            if (optionalVpnInterface.isPresent()) {
+                VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get());
+                VpnInterface vpnIf = vpnIfBuilder.setVpnInstanceName(vpnId.getValue()).build();
+                isLockAcquired = NeutronvpnUtils.lock(lockManager, ifname);
+                logger.debug("Updating vpn interface {}", vpnIf);
+                MDSALUtil.syncUpdate(broker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
+            } else {
+                logger.error("VPN Interface {} not found", ifname);
+            }
+        } catch (Exception ex) {
+            logger.error("Updation of vpninterface {} failed due to {}", ifname, ex);
+        } finally {
+            if (isLockAcquired) {
+                NeutronvpnUtils.unlock(lockManager, ifname);
+            }
+        }
+    }
+
     public void createL3Vpn(Uuid vpn, String name, Uuid tenant, List<String> rd, List<String> irt, List<String> ert,
                             Uuid router, List<Uuid> networks) {
 
@@ -543,7 +591,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
                         vpn.getImportRT(), vpn.getExportRT(), vpn.getRouterId(), vpn.getNetworkIds());
             } catch (Exception ex) {
                 msg = String.format("Creation of L3VPN failed for VPN %s", vpn.getId().getValue());
-                logger.error(msg, ex.getMessage());
+                logger.error(msg, ex);
                 error = RpcResultBuilder.newError(ErrorType.APPLICATION, msg, ex.getMessage());
                 errorList.add(error);
                 failurecount++;
@@ -585,7 +633,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
                         InstanceIdentifier.builder(VpnInstances.class).build();
                 Optional<VpnInstances> optionalVpns = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
                         vpnsIdentifier);
-                if (optionalVpns.isPresent()) {
+                if (optionalVpns.isPresent() && optionalVpns.get().getVpnInstance() != null) {
                     for (VpnInstance vpn : optionalVpns.get().getVpnInstance()) {
                         vpns.add(vpn);
                     }
@@ -616,9 +664,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
             for (VpnInstance vpnInstance : vpns) {
                 Uuid vpnId = new Uuid(vpnInstance.getVpnInstanceName());
                 // create VpnMaps id
-                InstanceIdentifier<VpnMap> vpnMapIdentifier =
-                        InstanceIdentifier.builder(VpnMaps.class)
-                                .child(VpnMap.class, new VpnMapKey(vpnId)).build();
+                InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap
+                        .class, new VpnMapKey(vpnId)).build();
                 L3vpnInstancesBuilder l3vpn = new L3vpnInstancesBuilder();
 
                 List<String> rd = Arrays.asList(vpnInstance.getIpv4Family().getRouteDistinguisher().split(","));
@@ -656,10 +703,9 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
 
         } catch (Exception ex) {
             String message = String.format("GetL3VPN failed due to %s", ex.getMessage());
-            logger.error(message);
+            logger.error(message, ex);
             result.set(RpcResultBuilder.<GetL3VPNOutput>failed().withError(ErrorType.APPLICATION, message).build());
         }
-
         return result;
     }
 
@@ -693,7 +739,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
                 }
             } catch (Exception ex) {
                 msg = String.format("Deletion of L3VPN failed when deleting for uuid %s", vpn.getValue());
-                logger.error(msg, ex.getMessage());
+                logger.error(msg, ex);
                 error = RpcResultBuilder.newError(ErrorType.APPLICATION, msg, ex.getMessage());
                 errorList.add(error);
                 failurecount++;
@@ -722,7 +768,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
 
     protected void addSubnetToVpn(Uuid vpnId, Uuid subnet) {
         logger.debug("Adding subnet {} to vpn {}", subnet.getValue(), vpnId.getValue());
-        Subnetmap sn = updateSubnetNode(subnet, null, null, null, vpnId, null);
+        Subnetmap sn = updateSubnetNode(subnet, null, null, null, null, vpnId, null);
         // Check if there are ports on this subnet and add corresponding vpn-interfaces
         List<Uuid> portList = sn.getPortList();
         if (portList != null) {
@@ -733,6 +779,19 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         }
     }
 
+    protected void updateVpnForSubnet(Uuid vpnId, Uuid subnet) {
+        logger.debug("Updating VPN {} for subnet {}", vpnId.getValue(), subnet.getValue());
+        Subnetmap sn = updateSubnetNode(subnet, null, null, null, null, vpnId, null);
+        // Check for ports on this subnet and update association of corresponding vpn-interfaces to external vpn
+        List<Uuid> portList = sn.getPortList();
+        if (portList != null) {
+            for (Uuid port : sn.getPortList()) {
+                logger.debug("Updating vpn-interface for port {}", port.getValue());
+                updateVpnInterface(vpnId, getNeutronPort(port));
+            }
+        }
+    }
+
     protected List<Adjacency> addAdjacencyforExtraRoute(List<Routes> routeList, boolean rtrUp, String vpnifname) {
         List<Adjacency> adjList = new ArrayList<Adjacency>();
         for (Routes route : routeList) {
@@ -861,36 +920,30 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
     }
 
     protected void associateRouterToVpn(Uuid vpnId, Uuid routerId) {
-
+        updateVpnMaps(vpnId, null, routerId, null, null);
         List<Uuid> routerSubnets = NeutronvpnUtils.getNeutronRouterSubnetIds(broker, routerId);
-
         if (!vpnId.equals(routerId)) {
-            logger.debug("Removing subnets from internal vpn {}", routerId.getValue());
+            logger.debug("Updating association of subnets to external vpn {}", vpnId.getValue());
             if (routerSubnets != null) {
-                for (Uuid subnet : routerSubnets) {
-                    removeSubnetFromVpn(routerId, subnet);
+                for (Uuid subnetId : routerSubnets) {
+                    updateVpnForSubnet(vpnId, subnetId);
                 }
             }
+        } else {
+            logger.debug("Adding subnets to internal vpn {}", vpnId.getValue());
+            for (Uuid subnet : routerSubnets) {
+                addSubnetToVpn(vpnId, subnet);
+            }
         }
-        logger.debug("Adding subnets to vpn {}", vpnId.getValue());
-        for (Uuid subnet : routerSubnets) {
-            addSubnetToVpn(vpnId, subnet);
-        }
-
-        updateVpnMaps(vpnId, null, routerId, null, null);
     }
 
     protected void dissociateRouterFromVpn(Uuid vpnId, Uuid routerId) {
 
-        // remove existing external vpn interfaces
         List<Uuid> routerSubnets = NeutronvpnUtils.getNeutronRouterSubnetIds(broker, routerId);
-
         if (routerSubnets != null) {
-            for (Uuid subnet : routerSubnets) {
-                logger.debug("Removing subnets from external vpn {}", vpnId.getValue());
-                removeSubnetFromVpn(vpnId, subnet);
-                logger.debug("Adding subnets to internal vpn {}", routerId.getValue());
-                addSubnetToVpn(routerId, subnet);
+            for (Uuid subnetId : routerSubnets) {
+                logger.debug("Updating association of subnets to internal vpn {}", routerId.getValue());
+                updateVpnForSubnet(routerId, subnetId);
             }
         }
         clearFromVpnMaps(vpnId, routerId, null);
@@ -977,7 +1030,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         } catch (Exception ex) {
             String message = String.format("associate Networks to vpn %s failed due to %s", input.getVpnId().getValue(),
                     ex.getMessage());
-            logger.error(message);
+            logger.error(message, ex);
             result.set(RpcResultBuilder.<AssociateNetworksOutput>failed().withError(ErrorType.APPLICATION, message)
                     .build());
         }
@@ -1022,7 +1075,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         } catch (Exception ex) {
             String message = String.format("associate router %s to vpn %s failed due to %s", routerId.getValue(),
                     vpnId.getValue(), ex.getMessage());
-            logger.error(message);
+            logger.error(message, ex);
             result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, message).build());
         }
         logger.debug("associateRouter returns..");
@@ -1052,7 +1105,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
                 returnMsg.append("VPN not found : ").append(vpnId.getValue());
             }
             if (returnMsg.length() != 0) {
-                String message = String.format("disssociate Networks to vpn %s failed due to %s", vpnId.getValue(),
+                String message = String.format("dissociate Networks to vpn %s failed due to %s", vpnId.getValue(),
                         returnMsg);
                 logger.error(message);
                 String errorResponse = String.format("ErrorType: PROTOCOL, ErrorTag: invalid-value, ErrorMessage: " +
@@ -1065,7 +1118,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         } catch (Exception ex) {
             String message = String.format("dissociate Networks to vpn %s failed due to %s", input.getVpnId().
                     getValue(), ex.getMessage());
-            logger.error(message);
+            logger.error(message, ex);
             result.set(RpcResultBuilder.<DissociateNetworksOutput>failed().withError(ErrorType.APPLICATION, message)
                     .build());
         }
@@ -1096,7 +1149,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
                 returnMsg.append("VPN not found : ").append(vpnId.getValue());
             }
             if (returnMsg.length() != 0) {
-                String message = String.format("disssociate router %s to vpn %s failed due to %s", routerId.getValue(),
+                String message = String.format("dissociate router %s to vpn %s failed due to %s", routerId.getValue(),
                         vpnId.getValue(), returnMsg);
                 logger.error(message);
                 String errorResponse = String.format("ErrorType: PROTOCOL, ErrorTag: invalid-value, ErrorMessage: " +
@@ -1109,7 +1162,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         } catch (Exception ex) {
             String message = String.format("disssociate router %s to vpn %s failed due to %s", routerId.getValue(),
                     vpnId.getValue(), ex.getMessage());
-            logger.error(message);
+            logger.error(message, ex);
             result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, message).build());
         }
         logger.debug("dissociateRouter returns..");
@@ -1189,9 +1242,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         InstanceIdentifier<Subnetmaps> subnetmapsid = InstanceIdentifier.builder(Subnetmaps.class).build();
         Optional<Subnetmaps> subnetmaps = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
                 subnetmapsid);
-        if (subnetmaps.isPresent()) {
-            Subnetmaps smaps = subnetmaps.get();
-            List<Subnetmap> subnetMapList = smaps.getSubnetmap();
+        if (subnetmaps.isPresent() && subnetmaps.get().getSubnetmap() != null) {
+            List<Subnetmap> subnetMapList = subnetmaps.get().getSubnetmap();
             for (Subnetmap subnetMap : subnetMapList) {
                 if (subnetMap.getVpnId() != null && subnetMap.getVpnId().equals(vpnid)) {
                     subnets.add(subnetMap.getId());
@@ -1209,7 +1261,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         InstanceIdentifier<Ports> portidentifier = InstanceIdentifier.create(Neutron.class).child(Ports.class);
         try {
             Optional<Ports> ports = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, portidentifier);
-            if (ports.isPresent()) {
+            if (ports.isPresent() && ports.get().getPort()!= null) {
                 List<Port> portList = ports.get().getPort();
                 for (Port port : portList) {
                     result.add(String.format(" %-22s  %-22s  %-22s  %-6s ", NeutronvpnUtils.uuidToTapPortName(port
index 71d11541a41a2a365677812be30b170535992a0f..b23120e4508aa645fb2e1b5994f5cec75b1cce0d 100644 (file)
@@ -13,6 +13,9 @@ import com.google.common.base.Optional;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInterfaces;
+import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface;
+import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
@@ -95,9 +98,8 @@ public class NeutronvpnUtils {
     protected static Uuid getVpnForNetwork(DataBroker broker, Uuid network) {
         InstanceIdentifier<VpnMaps> vpnMapsIdentifier = InstanceIdentifier.builder(VpnMaps.class).build();
         Optional<VpnMaps> optionalVpnMaps = read(broker, LogicalDatastoreType.CONFIGURATION, vpnMapsIdentifier);
-        if (optionalVpnMaps.isPresent()) {
-            VpnMaps vpnMaps = optionalVpnMaps.get();
-            List<VpnMap> allMaps = vpnMaps.getVpnMap();
+        if (optionalVpnMaps.isPresent() && optionalVpnMaps.get().getVpnMap() != null) {
+            List<VpnMap> allMaps = optionalVpnMaps.get().getVpnMap();
             for (VpnMap vpnMap : allMaps) {
                 if (vpnMap.getNetworkIds().contains(network)) {
                     return vpnMap.getVpnId();
@@ -112,9 +114,8 @@ public class NeutronvpnUtils {
         InstanceIdentifier<VpnMaps> vpnMapsIdentifier = InstanceIdentifier.builder(VpnMaps.class).build();
         Optional<VpnMaps> optionalVpnMaps = read(broker, LogicalDatastoreType.CONFIGURATION,
                 vpnMapsIdentifier);
-        if (optionalVpnMaps.isPresent()) {
-            VpnMaps vpnNets = optionalVpnMaps.get();
-            List<VpnMap> allMaps = vpnNets.getVpnMap();
+        if (optionalVpnMaps.isPresent() && optionalVpnMaps.get().getVpnMap() != null) {
+            List<VpnMap> allMaps = optionalVpnMaps.get().getVpnMap();
             if (routerId != null) {
                 for (VpnMap vpnMap : allMaps) {
                     if (routerId.equals(vpnMap.getRouterId())) {
@@ -219,7 +220,7 @@ public class NeutronvpnUtils {
         if (router != null) {
             List<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router
                     .Interfaces> interfacesList = router.getInterfaces();
-            if (!interfacesList.isEmpty()) {
+            if (interfacesList != null) {
                 for (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers
                         .router.Interfaces interfaces : interfacesList) {
                     subnetIdList.add(interfaces.getSubnetId());
@@ -238,37 +239,38 @@ public class NeutronvpnUtils {
     protected static boolean lock(LockManagerService lockManager, String lockName) {
         TryLockInput input = new TryLockInputBuilder().setLockName(lockName).setTime(5L).setTimeUnit
                 (TimeUnits.Milliseconds).build();
-        boolean islockAquired = false;
+        boolean islockAcquired = false;
         try {
             Future<RpcResult<Void>> result = lockManager.tryLock(input);
             if ((result != null) && (result.get().isSuccessful())) {
                 logger.debug("Acquired lock for {}", lockName);
-                islockAquired = true;
+                islockAcquired = true;
             } else {
-                throw new RuntimeException(String.format("Unable to acquire lock for  %s", lockName));
+                logger.error("Unable to acquire lock for  {}", lockName);
             }
         } catch (InterruptedException | ExecutionException e) {
             logger.error("Unable to acquire lock for  {}", lockName);
-            throw new RuntimeException(String.format("Unable to acquire lock for %s", lockName), e
-                    .getCause());
+            throw new RuntimeException(String.format("Unable to acquire lock for %s", lockName), e.getCause());
         }
-        return islockAquired;
+        return islockAcquired;
     }
 
-    protected static void unlock(LockManagerService lockManager, String lockName) {
+    protected static boolean unlock(LockManagerService lockManager, String lockName) {
         UnlockInput input = new UnlockInputBuilder().setLockName(lockName).build();
+        boolean islockAcquired = false;
         try {
             Future<RpcResult<Void>> result = lockManager.unlock(input);
             if ((result != null) && (result.get().isSuccessful())) {
                 logger.debug("Unlocked {}", lockName);
+                islockAcquired = true;
             } else {
-                logger.debug("Unable to unlock {}", lockName);
+                logger.error("Unable to unlock {}", lockName);
             }
         } catch (InterruptedException | ExecutionException e) {
             logger.error("Unable to unlock {}", lockName);
-            throw new RuntimeException(String.format("Unable to unlock %s", lockName), e
-                    .getCause());
+            throw new RuntimeException(String.format("Unable to unlock %s", lockName), e.getCause());
         }
+        return islockAcquired;
     }
 
     protected static Short getIPPrefixFromPort(DataBroker broker, Port port) {
@@ -296,7 +298,7 @@ public class NeutronvpnUtils {
                 logger.trace("Unable to read on subnet datastore");
             }
         } catch (Exception e) {
-            logger.trace("Failed to retrieve IP prefix from port : ", e);
+            logger.error("Failed to retrieve IP prefix from port : ", e);
             System.out.println("Failed to retrieve IP prefix from port : " + e.getMessage());
         }
         return null;
@@ -320,6 +322,12 @@ public class NeutronvpnUtils {
         return id;
     }
 
+    static InstanceIdentifier<VpnInterface> buildVpnInterfaceIdentifier(String ifName) {
+        InstanceIdentifier<VpnInterface> id = InstanceIdentifier.builder(VpnInterfaces.class).
+                child(VpnInterface.class, new VpnInterfaceKey(ifName)).build();
+        return id;
+    }
+
     static InstanceIdentifier<Subnetmap> buildSubnetMapIdentifier(Uuid subnetId) {
         InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new
                 SubnetmapKey(subnetId)).build();
index 66e24e132b8f94b01d231c7fcd268e734f8a904c..e7e471747f1092c558a265aacc163a2318c294ad 100644 (file)
@@ -209,7 +209,6 @@ public class VpnInterfaceManager extends AbstractDataChangeListener<VpnInterface
                 LOG.trace("VPN Interface already provisioned , bailing out from here.");
                 return;
             }
-
             bindService(dpId, vpnName, interfaceName, lPortTag);
             updateDpnDbs(vpnName, interfaceName, true);
             processVpnInterfaceAdjacencies(VpnUtil.getVpnInterfaceIdentifier(vpnInterface.getName()), vpnInterface, true);
@@ -543,56 +542,29 @@ public class VpnInterfaceManager extends AbstractDataChangeListener<VpnInterface
     }
 
     @Override
-    protected void update(InstanceIdentifier<VpnInterface> identifier,
-                                   VpnInterface original, VpnInterface update) {
-        LOG.trace("Update VPN Interface {} , original {}, update {}",
-                                                  identifier, original, update);
-        String vpnName = original.getVpnInstanceName();
-
-        boolean vpnNameChanged = false;
-        String rd = getRouteDistinguisher(vpnName);
-        String newRd = rd;
-        String newVpnName = update.getVpnInstanceName();
-        if(!vpnName.equals(newVpnName)) {
-            //VPN for this interface got changed.
-            //Remove the interface from old VPN and add it to new VPN
-            newRd = getRouteDistinguisher(newVpnName);
-            if(newRd.equals("")) {
-                LOG.warn("VPN Instance {} not found. Update operation aborted", newVpnName);
-                return;
-            }
-            vpnNameChanged = true;
-            LOG.debug("New VPN Name for the interface {} is {}", newVpnName, original.getName());
+    protected void update(InstanceIdentifier<VpnInterface> identifier, VpnInterface original, VpnInterface update) {
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Updating VPN Interface : key " + identifier + ",  original value=" + original + ", update " +
+                    "value=" + update);
         }
-
+        String oldVpnName = original.getVpnInstanceName();
+        String newVpnName = update.getVpnInstanceName();
         List<Adjacency> oldAdjs = original.getAugmentation(Adjacencies.class).getAdjacency();
         List<Adjacency> newAdjs = update.getAugmentation(Adjacencies.class).getAdjacency();
-        if(vpnNameChanged && newAdjs != null && !newAdjs.isEmpty()) {
-            long label = VpnConstants.INVALID_ID;
-            InstanceIdentifier<Adjacencies> path = identifier.augmentation(Adjacencies.class);
-            Optional<Adjacencies> adjacencies = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, path);
-            if (adjacencies.isPresent()) {
-                List<Adjacency> nextHops = adjacencies.get().getAdjacency();
-                for(Adjacency nextHop : nextHops) {
-                    label = nextHop.getLabel();
-                    if(label == VpnConstants.INVALID_ID) {
-                        //Generate label using ID Manager
-                        label = VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME,
-                                                    VpnUtil.getNextHopLabelKey(newRd, nextHop.getIpAddress()));
-                    }
-                    if (rd != null) {
-                        removePrefixFromBGP(rd, nextHop.getIpAddress());
-                    } else {
-                        removeFibEntryFromDS(vpnName, nextHop.getIpAddress());
-                    }
-                    //updatePrefixToBGP(newRd, nextHop, nextHopIp, label);
-                }
-                processVpnInterfaceAdjacencies(identifier, update, true);
-                VpnUtil.syncUpdate(broker, LogicalDatastoreType.OPERATIONAL, identifier, update);
-            }
-        } else if (oldAdjs != newAdjs) {
-            //handle both addition and removal of adjacencies
-            //currently, new adjacency may be an extra route
+        if (oldAdjs == null) {
+            oldAdjs = new ArrayList<>();
+        }
+        if (newAdjs == null) {
+            newAdjs = new ArrayList<>();
+        }
+        //handles switching between <internal VPN - external VPN>
+        if (!oldVpnName.equals(newVpnName)) {
+            remove(identifier, original);
+            add(identifier, update);
+        }
+        //handle both addition and removal of adjacencies
+        //currently, new adjacency may be an extra route
+        if (!oldAdjs.equals(newAdjs)) {
             for (Adjacency adj : newAdjs) {
                 if (oldAdjs.contains(adj)) {
                     oldAdjs.remove(adj);
@@ -601,15 +573,10 @@ public class VpnInterfaceManager extends AbstractDataChangeListener<VpnInterface
                     addNewAdjToVpnInterface(identifier, adj);
                 }
             }
-
             for (Adjacency adj : oldAdjs) {
                 delAdjFromVpnInterface(identifier, adj);
             }
         }
-        else {
-            LOG.debug("No Update information is available for VPN Interface to proceed");
-        }
-
     }
 
     public void processArpRequest(IpAddress srcIP, PhysAddress srcMac, IpAddress targetIP, String srcInterface){