Fixing issues with idmanager 21/30921/2
authorFaseela K <faseela.k@ericsson.com>
Mon, 7 Dec 2015 17:49:07 +0000 (23:19 +0530)
committerFaseela K <faseela.k@ericsson.com>
Tue, 8 Dec 2015 08:58:57 +0000 (14:28 +0530)
Adding if-index support for interfacemanager

Change-Id: If607bb91f14d729478065b7c5af29f26ffbd8e28
Signed-off-by: Faseela K <faseela.k@ericsson.com>
23 files changed:
idmanager/idmanager-impl/src/main/java/org/opendaylight/idmanager/IdUtils.java
idmanager/idmanager-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/idmanager/impl/rev150325/IdmanagerImplModule.java
idmanager/idmanager-impl/src/test/java/org/opendaylight/idmanager/test/IdManagerTest.java
interfacemgr/interfacemgr-api/src/main/yang/odl-interface-meta.yang
interfacemgr/interfacemgr-api/src/main/yang/odl-interface-rpc.yang
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/IfmUtil.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/InterfacemgrProvider.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/commons/InterfaceMetaUtils.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/listeners/InterfaceConfigListener.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/listeners/InterfaceInventoryStateListener.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/listeners/VlanMemberConfigListener.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/OvsInterfaceConfigUpdateHelper.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/confighelpers/OvsVlanMemberConfigRemoveHelper.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/confighelpers/OvsVlanMemberConfigUpdateHelper.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/renderer/ovs/statehelpers/OvsInterfaceStateRemoveHelper.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/rpcservice/InterfaceManagerRpcService.java
interfacemgr/interfacemgr-impl/src/test/java/org/opendaylight/vpnservice/interfacemgr/test/TunnelInterfaceConfigurationTest.java
nexthopmgr/nexthopmgr-impl/src/main/java/org/opendaylight/vpnservice/nexthopmgr/NexthopManager.java
nexthopmgr/nexthopmgr-impl/src/main/java/org/opendaylight/vpnservice/nexthopmgr/NexthopmgrProvider.java

index 507dad2b4b6ed6d11b21a9303fc7dfbae13be391..ebf4cd7361ac232c1cec2a8dec943982e7e23f3d 100644 (file)
@@ -52,15 +52,8 @@ class IdUtils {
 
     private static int BLADE_ID;
     static {
-        String hostName;
         try {
-            hostName = InetAddress.getLocalHost().getHostName();
             BLADE_ID = InetAddresses.coerceToInteger(InetAddress.getLocalHost());
-            if (hostName.indexOf("-") > 0) {
-                BLADE_ID = new Integer(hostName.split("-")[1].toString()).intValue();
-            } else {
-                LOGGER.error("Host name {} is not matching with the condition!! PL-X is expected", hostName);
-            }
         } catch (Exception e) {
             LOGGER.error("IdManager - Exception - {}", e.getMessage());
         }
index d141e3eef2271c0f3ae41dbd76a5a409c55f2e01..17f99bef5c0311e61ee737facba554ef645ab7ed 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.idmanag
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
 import org.opendaylight.idmanager.IdManagerServiceProvider;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.lockmanager.rev150819.LockManagerService;
 
 public class IdmanagerImplModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.idmanager.impl.rev150325.AbstractIdmanagerImplModule {
     public IdmanagerImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
@@ -23,7 +24,9 @@ public class IdmanagerImplModule extends org.opendaylight.yang.gen.v1.urn.openda
 
     @Override
     public java.lang.AutoCloseable createInstance() {
+        LockManagerService lockManagerService = getRpcRegistryDependency().getRpcService(LockManagerService.class);
         IdManagerServiceProvider provider = new IdManagerServiceProvider(getRpcRegistryDependency());
+        provider.setLockManager(lockManagerService);
         getBrokerDependency().registerProvider(provider);
         return provider;
     }
index 181cc499da154e57ecd99204266f8720239c559d..9833d04c5849b1948aae1b8061bf94b97e275b7c 100644 (file)
@@ -69,15 +69,8 @@ public class IdManagerTest {
     private static final Logger LOG = LoggerFactory.getLogger(IdManagerTest.class);
     private static int BLADE_ID;
     static {
-        String hostName;
         try {
-            hostName = InetAddress.getLocalHost().getHostName();
             BLADE_ID = InetAddresses.coerceToInteger(InetAddress.getLocalHost());
-            if (hostName.indexOf("-") > 0) {
-                BLADE_ID = new Integer(hostName.split("-")[1].toString()).intValue();
-            } else {
-                LOG.error("Host name {} is not matching with the condition!! PL-X is expected", hostName);
-            }
         } catch (Exception e) {
             LOG.error("IdManager - Exception - {}", e.getMessage());
         }
index 66b4a850b2baad239d92e96f7c11eb603bd26853..ef6aa20aeef774d4325f6e6dfc5078a47bb4e9c1 100644 (file)
@@ -61,4 +61,17 @@ module odl-interface-meta {
             }
         }
     }
+
+   container if-indexes-interface-map {
+           config false;
+           list if-index-interface {
+               key if-index;
+               leaf if-index {
+                   type int32;
+               }
+               leaf interface-name {
+                   type string;
+               }
+           }
+       }
 }
\ No newline at end of file
index 88ce5ac664d0590aea4bac7c43a959ee6dd99c13..ef1cad591a0b54e739a31d6a8330dde28bd247eb 100644 (file)
@@ -128,4 +128,18 @@ module odl-interface-rpc {
             }
         }
     }
+
+    rpc get-interface-from-if-index {
+        description "to get interface associated with an if-index";
+            input {
+                leaf if-index {
+                    type int32;
+                }
+            }
+            output {
+                leaf interface-name {
+                    type string;
+                }
+            }
+        }
 }
\ No newline at end of file
index ebfed475b5687d644c4aa8ff51acbe2f41870c11..26366286c9ed9581b7105fdb705ad52d98664a81 100644 (file)
@@ -38,9 +38,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class IfmUtil {
-
+    private static final Logger LOG = LoggerFactory.getLogger(IfmUtil.class);
+    private static final int INVALID_ID = 0;
     public static String getDpnFromNodeConnectorId(NodeConnectorId portId) {
         /*
          * NodeConnectorId is of form 'openflow:dpnid:portnum'
@@ -154,6 +158,37 @@ public class IfmUtil {
         return new BigInteger[] { metadata, metadataMask };
     }
 
+    public static Integer allocateId(IdManagerService idManager, String poolName, String idKey) {
+        AllocateIdInput getIdInput = new AllocateIdInputBuilder()
+                .setPoolName(poolName)
+                .setIdKey(idKey).build();
+        try {
+            Future<RpcResult<AllocateIdOutput>> result = idManager.allocateId(getIdInput);
+            RpcResult<AllocateIdOutput> rpcResult = result.get();
+            if(rpcResult.isSuccessful()) {
+                return rpcResult.getResult().getIdValue().intValue();
+            } else {
+                LOG.warn("RPC Call to Get Unique Id returned with Errors {}", rpcResult.getErrors());
+            }
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.warn("Exception when getting Unique Id",e);
+        }
+        return INVALID_ID;
+    }
 
-
+    public static void releaseId(IdManagerService idManager, String poolName, String idKey) {
+        ReleaseIdInput idInput = new ReleaseIdInputBuilder()
+                .setPoolName(poolName)
+                .setIdKey(idKey).build();
+        try {
+            Future<RpcResult<Void>> result = idManager.releaseId(idInput);
+            RpcResult<Void> rpcResult = result.get();
+            if(!rpcResult.isSuccessful()) {
+                LOG.warn("RPC Call to release Id {} with Key {} returned with Errors {}",
+                        idKey, rpcResult.getErrors());
+            }
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.warn("Exception when releasing Id for key {}", idKey, e);
+        }
+    }
 }
index e886115f33768695ae2ea6758ec8c2c343eccb3f..f519acf320f38e81b899cd17d6cb6ea7cf7cbd3d 100644 (file)
@@ -13,7 +13,6 @@ import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
-import org.opendaylight.idmanager.IdManager;
 import org.opendaylight.vpnservice.interfacemgr.listeners.InterfaceConfigListener;
 import org.opendaylight.vpnservice.interfacemgr.listeners.InterfaceInventoryStateListener;
 import org.opendaylight.vpnservice.interfacemgr.listeners.InterfaceTopologyStateListener;
@@ -28,6 +27,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 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.CreateIdPoolInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.CreateIdPoolInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.*;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
@@ -43,7 +43,7 @@ public class InterfacemgrProvider implements BindingAwareProvider, AutoCloseable
     private static final Logger LOG = LoggerFactory.getLogger(InterfacemgrProvider.class);
 
     private RpcProviderRegistry rpcProviderRegistry;
-    private IdManager idManager;
+    private IdManagerService idManager;
 
     private InterfaceConfigListener interfaceConfigListener;
     private InterfaceTopologyStateListener topologyStateListener;
@@ -64,7 +64,7 @@ public class InterfacemgrProvider implements BindingAwareProvider, AutoCloseable
         LOG.info("InterfacemgrProvider Session Initiated");
         try {
             final  DataBroker dataBroker = session.getSALService(DataBroker.class);
-            idManager = new IdManager(dataBroker);
+            idManager = rpcProviderRegistry.getRpcService(IdManagerService.class);
             createIdPool();
 
             interfaceManagerRpcService = new InterfaceManagerRpcService(dataBroker);
@@ -74,7 +74,7 @@ public class InterfacemgrProvider implements BindingAwareProvider, AutoCloseable
             interfaceConfigListener = new InterfaceConfigListener(dataBroker, idManager);
             interfaceConfigListener.registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
 
-            interfaceInventoryStateListener = new InterfaceInventoryStateListener(dataBroker);
+            interfaceInventoryStateListener = new InterfaceInventoryStateListener(dataBroker, idManager);
             interfaceInventoryStateListener.registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
 
             topologyStateListener = new InterfaceTopologyStateListener(dataBroker);
index f8aaaf6b956a7f25bf1123dab667584247018fdc..a123fccc1e846bcfaa41de4bfe24705231e291cb 100644 (file)
@@ -11,10 +11,17 @@ import com.google.common.base.Optional;
 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.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.BridgeInterfaceInfo;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.BridgeRefInfo;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.IfIndexesInterfaceMap;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.InterfaceChildInfo;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._if.indexes._interface.map.IfIndexInterface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._if.indexes._interface.map.IfIndexInterfaceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._if.indexes._interface.map.IfIndexInterfaceKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntryKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info._interface.parent.entry.InterfaceChildEntry;
@@ -146,4 +153,19 @@ public class InterfaceMetaUtils {
         }
         return interfaceChildEntryOptional.get();
     }
+
+    public static void createLportTagInterfaceMap(WriteTransaction t, String infName, Integer ifIndex) {
+        InstanceIdentifier<IfIndexInterface> id = InstanceIdentifier.builder(IfIndexesInterfaceMap.class).child(IfIndexInterface.class, new IfIndexInterfaceKey(ifIndex)).build();
+        IfIndexInterface ifIndexInterface = new IfIndexInterfaceBuilder().setIfIndex(ifIndex).setKey(new IfIndexInterfaceKey(ifIndex)).setInterfaceName(infName).build();
+        t.put(LogicalDatastoreType.OPERATIONAL, id, ifIndexInterface, true);
+    }
+
+    public static void removeLportTagInterfaceMap(WriteTransaction t, IdManagerService idManager, DataBroker broker, String infName, Integer ifIndex) {
+        InstanceIdentifier<IfIndexInterface> id = InstanceIdentifier.builder(IfIndexesInterfaceMap.class).child(IfIndexInterface.class, new IfIndexInterfaceKey(ifIndex)).build();
+        Optional<IfIndexInterface> ifIndexesInterface = IfmUtil.read(LogicalDatastoreType.OPERATIONAL, id, broker);
+        if(ifIndexesInterface.isPresent()) {
+           t.delete(LogicalDatastoreType.OPERATIONAL, id);
+        }
+        IfmUtil.releaseId(idManager, IfmConstants.IFM_IDPOOL_NAME, infName);
+    }
 }
\ No newline at end of file
index a8457c551e7206fab8356f7f6df2eb0177b8e980..6e911667b56576ba0c7027419cfd9bcd4d2e0898 100644 (file)
@@ -18,6 +18,7 @@ import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.confighelpers.OvsIn
 import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.confighelpers.OvsInterfaceConfigUpdateHelper;
 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.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.ParentRefs;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
@@ -33,9 +34,9 @@ import java.util.concurrent.Callable;
 public class InterfaceConfigListener extends AsyncDataTreeChangeListenerBase<Interface, InterfaceConfigListener> {
     private static final Logger LOG = LoggerFactory.getLogger(InterfaceConfigListener.class);
     private DataBroker dataBroker;
-    private IdManager idManager;
+    private IdManagerService idManager;
 
-    public InterfaceConfigListener(final DataBroker dataBroker, final IdManager idManager) {
+    public InterfaceConfigListener(final DataBroker dataBroker, final IdManagerService idManager) {
         super(Interface.class, InterfaceConfigListener.class);
         this.dataBroker = dataBroker;
         this.idManager = idManager;
index 8629a75c560ae7ddd3a98bbedad108960ac54821..f496bbc0b8484e7a9ff52ed159d4d8cf9a873fd4 100644 (file)
@@ -10,16 +10,19 @@ package org.opendaylight.vpnservice.interfacemgr.listeners;
 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.idmanager.IdManager;
 import org.opendaylight.vpnservice.datastoreutils.AsyncDataChangeListenerBase;
 import org.opendaylight.vpnservice.datastoreutils.DataStoreJobCoordinator;
 import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.statehelpers.OvsInterfaceStateAddHelper;
 import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.statehelpers.OvsInterfaceStateRemoveHelper;
+import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.statehelpers.OvsInterfaceStateRemoveHelper;
 import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.statehelpers.OvsInterfaceStateUpdateHelper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -38,10 +41,12 @@ import java.util.concurrent.Callable;
 public class InterfaceInventoryStateListener extends AsyncDataChangeListenerBase<FlowCapableNodeConnector, InterfaceInventoryStateListener> implements AutoCloseable{
     private static final Logger LOG = LoggerFactory.getLogger(InterfaceInventoryStateListener.class);
     private DataBroker dataBroker;
+    private IdManagerService idManager;
 
-    public InterfaceInventoryStateListener(final DataBroker dataBroker) {
+    public InterfaceInventoryStateListener(final DataBroker dataBroker, final IdManagerService idManager) {
         super(FlowCapableNodeConnector.class, InterfaceInventoryStateListener.class);
         this.dataBroker = dataBroker;
+        this.idManager = idManager;
     }
 
     @Override
@@ -68,7 +73,7 @@ public class InterfaceInventoryStateListener extends AsyncDataChangeListenerBase
         NodeConnectorId nodeConnectorId = InstanceIdentifier.keyOf(key.firstIdentifierOf(NodeConnector.class)).getId();
         DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
 
-        InterfaceStateRemoveWorker interfaceStateRemoveWorker = new InterfaceStateRemoveWorker(key,
+        InterfaceStateRemoveWorker interfaceStateRemoveWorker = new InterfaceStateRemoveWorker(idManager, key,
                 flowCapableNodeConnectorOld, portName);
         coordinator.enqueueJob(portName, interfaceStateRemoveWorker);
     }
@@ -92,7 +97,7 @@ public class InterfaceInventoryStateListener extends AsyncDataChangeListenerBase
         NodeConnectorId nodeConnectorId = InstanceIdentifier.keyOf(key.firstIdentifierOf(NodeConnector.class)).getId();
 
         DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
-        InterfaceStateAddWorker ifStateAddWorker = new InterfaceStateAddWorker(nodeConnectorId,
+        InterfaceStateAddWorker ifStateAddWorker = new InterfaceStateAddWorker(idManager, nodeConnectorId,
                 fcNodeConnectorNew, portName);
         coordinator.enqueueJob(portName, ifStateAddWorker);
     }
@@ -101,20 +106,22 @@ public class InterfaceInventoryStateListener extends AsyncDataChangeListenerBase
         private final NodeConnectorId nodeConnectorId;
         private final FlowCapableNodeConnector fcNodeConnectorNew;
         private final String portName;
+        private final IdManagerService idManager;
 
-        public InterfaceStateAddWorker(NodeConnectorId nodeConnectorId,
+        public InterfaceStateAddWorker(IdManagerService idManager, NodeConnectorId nodeConnectorId,
                                        FlowCapableNodeConnector fcNodeConnectorNew,
                                        String portName) {
             this.nodeConnectorId = nodeConnectorId;
             this.fcNodeConnectorNew = fcNodeConnectorNew;
             this.portName = portName;
+            this.idManager = idManager;
         }
 
         @Override
         public Object call() throws Exception {
             // If another renderer(for eg : CSS) needs to be supported, check can be performed here
             // to call the respective helpers.
-             return OvsInterfaceStateAddHelper.addState(dataBroker, nodeConnectorId,
+             return OvsInterfaceStateAddHelper.addState(dataBroker, idManager, nodeConnectorId,
                      portName, fcNodeConnectorNew);
         }
 
@@ -168,20 +175,23 @@ public class InterfaceInventoryStateListener extends AsyncDataChangeListenerBase
         InstanceIdentifier<FlowCapableNodeConnector> key;
         FlowCapableNodeConnector fcNodeConnectorOld;
         private final String portName;
+        private final IdManagerService idManager;
 
-        public InterfaceStateRemoveWorker(InstanceIdentifier<FlowCapableNodeConnector> key,
+        public InterfaceStateRemoveWorker(IdManagerService idManager,
+                                          InstanceIdentifier<FlowCapableNodeConnector> key,
                                           FlowCapableNodeConnector fcNodeConnectorOld,
                                           String portName) {
             this.key = key;
             this.fcNodeConnectorOld = fcNodeConnectorOld;
             this.portName = portName;
+            this.idManager = idManager;
         }
 
         @Override
         public Object call() throws Exception {
             // If another renderer(for eg : CSS) needs to be supported, check can be performed here
             // to call the respective helpers.
-            return OvsInterfaceStateRemoveHelper.removeState(key, dataBroker, portName, fcNodeConnectorOld);
+            return OvsInterfaceStateRemoveHelper.removeState(idManager, key, dataBroker, portName, fcNodeConnectorOld);
         }
 
         @Override
index 2d94716225928945aa8e56efd9d044c71de59088..eb43d689abe927007580d8263a530d92686d44dc 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.confighelpers.OvsVl
 import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.confighelpers.OvsVlanMemberConfigUpdateHelper;
 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.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;
@@ -29,9 +30,9 @@ import java.util.concurrent.Callable;
 public class VlanMemberConfigListener extends AsyncDataTreeChangeListenerBase<Interface, VlanMemberConfigListener> {
     private static final Logger LOG = LoggerFactory.getLogger(VlanMemberConfigListener.class);
     private DataBroker dataBroker;
-    private IdManager idManager;
+    private IdManagerService idManager;
 
-    public VlanMemberConfigListener(final DataBroker dataBroker, final IdManager idManager) {
+    public VlanMemberConfigListener(final DataBroker dataBroker, final IdManagerService idManager) {
         super(Interface.class, VlanMemberConfigListener.class);
         this.dataBroker = dataBroker;
         this.idManager = idManager;
index 323ac88052362a0612fb5f7ccb8ef9eae3682147..17d4cf6b090bd0130b2e8a4641bec0a112b7c2a5 100644 (file)
@@ -13,6 +13,7 @@ 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.commons.InterfaceManagerCommonUtils;
 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils;
@@ -25,6 +26,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.
 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.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntryKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info._interface.parent.entry.InterfaceChildEntry;
@@ -51,7 +53,7 @@ public class OvsInterfaceConfigAddHelper {
     private static final Logger LOG = LoggerFactory.getLogger(OvsInterfaceConfigAddHelper.class);
 
     public static List<ListenableFuture<Void>> addConfiguration(DataBroker dataBroker, ParentRefs parentRefs,
-                                                                Interface interfaceNew, IdManager idManager) {
+                                                                Interface interfaceNew, IdManagerService idManager) {
         List<ListenableFuture<Void>> futures = new ArrayList<>();
 
         IfTunnel ifTunnel = interfaceNew.getAugmentation(IfTunnel.class);
@@ -60,19 +62,20 @@ public class OvsInterfaceConfigAddHelper {
             return futures;
         }
 
-        addVlanConfiguration(interfaceNew, dataBroker, futures);
+        addVlanConfiguration(interfaceNew, dataBroker, idManager, futures);
         return futures;
     }
 
-    private static void addVlanConfiguration(Interface interfaceNew, DataBroker dataBroker,
+    private static void addVlanConfiguration(Interface interfaceNew, DataBroker dataBroker, IdManagerService idManager,
                                              List<ListenableFuture<Void>> futures) {
         WriteTransaction t = dataBroker.newWriteOnlyTransaction();
         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState =
                 InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(interfaceNew.getName(), dataBroker);
+
         if (ifState == null) {
             return;
         }
-        updateStateEntry(interfaceNew, t, ifState);
+        updateStateEntry(interfaceNew, ifState.getIfIndex(), t, ifState);
 
         IfL2vlan ifL2vlan = interfaceNew.getAugmentation(IfL2vlan.class);
         if (ifL2vlan == null || ifL2vlan.getL2vlanMode() != IfL2vlan.L2vlanMode.Trunk) {
@@ -120,7 +123,7 @@ public class OvsInterfaceConfigAddHelper {
     }
 
     private static void addTunnelConfiguration(DataBroker dataBroker, ParentRefs parentRefs,
-                                              Interface interfaceNew, IdManager idManager,
+                                              Interface interfaceNew, IdManagerService idManager,
                                               List<ListenableFuture<Void>> futures) {
         LOG.debug("adding tunnel configuration for {}", interfaceNew.getName());
         WriteTransaction t = dataBroker.newWriteOnlyTransaction();
@@ -168,17 +171,16 @@ public class OvsInterfaceConfigAddHelper {
         }
     }
 
-    private static void updateStateEntry(Interface interfaceNew, WriteTransaction t,
+    private static void updateStateEntry(Interface interfaceNew, Integer ifIndex, WriteTransaction t,
                                          org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState) {
-        OperStatus operStatus;
+        InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
+                IfmUtil.buildStateInterfaceId(interfaceNew.getName());
+        InterfaceBuilder ifaceBuilder = new InterfaceBuilder();
         if (!interfaceNew.isEnabled() && ifState.getOperStatus() != OperStatus.Down) {
-            operStatus = OperStatus.Down;
-            InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
-                    IfmUtil.buildStateInterfaceId(interfaceNew.getName());
-            InterfaceBuilder ifaceBuilder = new InterfaceBuilder();
-            ifaceBuilder.setOperStatus(operStatus);
-            ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(interfaceNew.getName()));
-            t.merge(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build());
+            ifaceBuilder.setOperStatus(OperStatus.Down);
         }
+        ifaceBuilder.setIfIndex(ifIndex);
+        ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(interfaceNew.getName()));
+        t.merge(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build());
     }
 }
index bb55c4f7261ef361ef5583b84f39f3fe4fb6f903..03f9c0600c40783e0b728da5a6b1c9d4df1b03f5 100644 (file)
@@ -23,6 +23,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntryKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info._interface.parent.entry.InterfaceChildEntry;
@@ -49,21 +50,16 @@ public class OvsInterfaceConfigRemoveHelper {
     private static final Logger LOG = LoggerFactory.getLogger(OvsInterfaceConfigRemoveHelper.class);
 
     public static List<ListenableFuture<Void>> removeConfiguration(DataBroker dataBroker, Interface interfaceOld,
-                                                                   IdManager idManager, ParentRefs parentRefs) {
+                                                                   IdManagerService idManager, ParentRefs parentRefs) {
         List<ListenableFuture<Void>> futures = new ArrayList<>();
         WriteTransaction t = dataBroker.newWriteOnlyTransaction();
 
         IfTunnel ifTunnel = interfaceOld.getAugmentation(IfTunnel.class);
         if (ifTunnel != null) {
             removeTunnelConfiguration(parentRefs, dataBroker, interfaceOld, idManager, t);
-            futures.add(t.submit());
-            return futures;
+        }else {
+            removeVlanConfiguration(dataBroker, interfaceOld, t);
         }
-
-        removeVlanConfiguration(dataBroker, interfaceOld, t);
-
-        /* FIXME: Deallocate ID from Idmanager. */
-
         futures.add(t.submit());
         return futures;
     }
@@ -128,7 +124,7 @@ public class OvsInterfaceConfigRemoveHelper {
     }
 
     private static void removeTunnelConfiguration(ParentRefs parentRefs, DataBroker dataBroker, Interface interfaceOld,
-                                                  IdManager idManager, WriteTransaction t) {
+                                                  IdManagerService idManager, WriteTransaction t) {
 
         BigInteger dpId = null;
         if (parentRefs != null) {
index b7c2bb09a2293660fec45729749cc663c397f621..0770bd5b1648f49fb88b9a3ac3aeb5b720dcbfe0 100644 (file)
@@ -22,6 +22,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntryKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info._interface.parent.entry.InterfaceChildEntry;
@@ -38,7 +39,7 @@ import java.util.List;
 public class OvsInterfaceConfigUpdateHelper {
     private static final Logger LOG = LoggerFactory.getLogger(OvsInterfaceConfigUpdateHelper.class);
 
-    public static List<ListenableFuture<Void>> updateConfiguration(DataBroker dataBroker,  IdManager idManager,
+    public static List<ListenableFuture<Void>> updateConfiguration(DataBroker dataBroker,  IdManagerService idManager,
                                                                    Interface interfaceNew, Interface interfaceOld) {
         List<ListenableFuture<Void>> futures = new ArrayList<>();
 
index 78f87f34e5e8227814dcd7398c44d45069bd4da8..d9dd3762b8db2188049b5a435ab9ef957ada3bd6 100644 (file)
@@ -23,6 +23,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.
 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.vpnservice.idmanager.rev150403.IdManagerService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntryBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntryKey;
@@ -42,7 +43,7 @@ public class OvsVlanMemberConfigAddHelper {
     private static final Logger LOG = LoggerFactory.getLogger(OvsVlanMemberConfigAddHelper.class);
     public static List<ListenableFuture<Void>> addConfiguration(DataBroker dataBroker, ParentRefs parentRefs,
                                                                 Interface interfaceNew, IfL2vlan ifL2vlan,
-                                                                IdManager idManager) {
+                                                                IdManagerService idManager) {
         List<ListenableFuture<Void>> futures = new ArrayList<>();
         WriteTransaction t = dataBroker.newWriteOnlyTransaction();
 
@@ -137,18 +138,16 @@ public class OvsVlanMemberConfigAddHelper {
         }
     }
 
-    private static long createInterfaceChildEntry(DataBroker dataBroker, IdManager idManager, WriteTransaction t,
+    private static long createInterfaceChildEntry(DataBroker dataBroker, IdManagerService idManager, WriteTransaction t,
                                                 InterfaceParentEntryKey interfaceParentEntryKey, String childInterface){
 
-            //TODO FIXME
-//        long lportTag = InterfaceManagerCommonUtils.getUniqueId(idManager, childInterface);
-//        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 lportTag;
-        return 0L;
+        long lportTag = IfmUtil.allocateId(idManager, IfmConstants.IFM_IDPOOL_NAME, childInterface);
+        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 lportTag;
     }
 }
index a0b404f34bb1a2f621bc635ed3d248592de23905..cb0397968898e3c17d18afd128f6e3f1812ba71c 100644 (file)
@@ -16,6 +16,7 @@ import org.opendaylight.vpnservice.interfacemgr.IfmUtil;
 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils;
 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils;
 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.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntryKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info._interface.parent.entry.InterfaceChildEntry;
@@ -33,7 +34,7 @@ public class OvsVlanMemberConfigRemoveHelper {
     private static final Logger LOG = LoggerFactory.getLogger(OvsVlanMemberConfigRemoveHelper.class);
     public static List<ListenableFuture<Void>> removeConfiguration(DataBroker dataBroker, ParentRefs parentRefs,
                                                                 Interface interfaceOld, IfL2vlan ifL2vlan,
-                                                                IdManager idManager) {
+                                                                IdManagerService idManager) {
         List<ListenableFuture<Void>> futures = new ArrayList<>();
         WriteTransaction t = dataBroker.newWriteOnlyTransaction();
 
index 73edde0206cd98e0a37ada21b98c0b3f2f256102..703322653f8ce402513d3579819d7b23bc40cd90 100644 (file)
@@ -18,6 +18,7 @@ import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils;
 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.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.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntryKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info._interface.parent.entry.InterfaceChildEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info._interface.parent.entry.InterfaceChildEntryKey;
@@ -34,7 +35,7 @@ public class OvsVlanMemberConfigUpdateHelper {
     private static final Logger LOG = LoggerFactory.getLogger(OvsVlanMemberConfigUpdateHelper.class);
     public static List<ListenableFuture<Void>> updateConfiguration(DataBroker dataBroker, ParentRefs parentRefsNew,
                                                                    Interface interfaceOld, IfL2vlan ifL2vlanNew,
-                                                                   Interface interfaceNew, IdManager idManager) {
+                                                                   Interface interfaceNew, IdManagerService idManager) {
         List<ListenableFuture<Void>> futures = new ArrayList<>();
         ParentRefs parentRefsOld = interfaceOld.getAugmentation(ParentRefs.class);
 
index 95df19873d5942dbfb8c5050fed4e3e37ba56168..9891226da07dfeeff59ad0a1bd9deaace3a9e3d6 100644 (file)
@@ -11,6 +11,8 @@ import com.google.common.util.concurrent.ListenableFuture;
 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.commons.InterfaceManagerCommonUtils;
 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils;
@@ -20,6 +22,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.
 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.flow.inventory.rev130819.FlowCapableNodeConnector;
 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.meta.rev151007._interface.child.info.InterfaceParentEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntryKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info._interface.parent.entry.InterfaceChildEntry;
@@ -42,7 +45,7 @@ import java.util.List;
 public class OvsInterfaceStateAddHelper {
     private static final Logger LOG = LoggerFactory.getLogger(OvsInterfaceStateAddHelper.class);
 
-    public static List<ListenableFuture<Void>> addState(DataBroker dataBroker, NodeConnectorId nodeConnectorId,
+    public static List<ListenableFuture<Void>> addState(DataBroker dataBroker, IdManagerService idManager, NodeConnectorId nodeConnectorId,
                                                         String portName, FlowCapableNodeConnector fcNodeConnectorNew) {
         LOG.debug("Adding Interface State to Oper DS for port: {}", portName);
         List<ListenableFuture<Void>> futures = new ArrayList<>();
@@ -69,12 +72,15 @@ public class OvsInterfaceStateAddHelper {
         List<String> lowerLayerIfList = new ArrayList<>();
         lowerLayerIfList.add(nodeConnectorId.getValue());
 
+        Integer ifIndex = IfmUtil.allocateId(idManager, IfmConstants.IFM_IDPOOL_NAME, portName);
         InstanceIdentifier<Interface> ifStateId = IfmUtil.buildStateInterfaceId(portName);
         InterfaceBuilder ifaceBuilder = new InterfaceBuilder().setOperStatus(operStatus)
-                .setAdminStatus(adminStatus).setPhysAddress(physAddress).setLowerLayerIf(lowerLayerIfList)
+                .setAdminStatus(adminStatus).setPhysAddress(physAddress).setIfIndex(ifIndex).setLowerLayerIf(lowerLayerIfList)
                 .setKey(IfmUtil.getStateInterfaceKeyFromName(portName));
         t.put(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build(), true);
 
+        // allocate lport tag and set in if-index
+        InterfaceMetaUtils.createLportTagInterfaceMap(t, portName, ifIndex);
         if (iface == null) {
             futures.add(t.submit());
             return futures;
index 26734cac448c3ec6375265498e1027af32520435..9d9c668ea649d4249bff40092cb25245ecc3eb89 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils;
 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.flow.inventory.rev130819.FlowCapableNodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntryKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info._interface.parent.entry.InterfaceChildEntry;
@@ -30,13 +31,19 @@ import java.util.List;
 public class OvsInterfaceStateRemoveHelper {
     private static final Logger LOG = LoggerFactory.getLogger(OvsInterfaceStateRemoveHelper.class);
 
-    public static List<ListenableFuture<Void>> removeState(InstanceIdentifier<FlowCapableNodeConnector> key,
+    public static List<ListenableFuture<Void>> removeState(IdManagerService idManager,
+                                                           InstanceIdentifier<FlowCapableNodeConnector> key,
                                                            DataBroker dataBroker, String portName, FlowCapableNodeConnector fcNodeConnectorOld) {
         LOG.debug("Removing interface-state for port: {}", portName);
         List<ListenableFuture<Void>> futures = new ArrayList<>();
         WriteTransaction t = dataBroker.newWriteOnlyTransaction();
 
         InstanceIdentifier<Interface> ifStateId = IfmUtil.buildStateInterfaceId(portName);
+        /* Remove entry from if-index-interface-name map and deallocate Id from Idmanager. */
+        org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState =
+                InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(portName, dataBroker);
+        InterfaceMetaUtils.removeLportTagInterfaceMap(t, idManager, dataBroker, interfaceState.getName(), interfaceState.getIfIndex());
+
         t.delete(LogicalDatastoreType.OPERATIONAL, ifStateId);
 
         // For Vlan-Trunk Interface, remove the trunk-member operstates as well...
index a2d26912b2ef4268f6f2415216f22c8587466593..ef70eb84f414701a31ea4f4296e56dd5cbcb32c3 100644 (file)
@@ -31,7 +31,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 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.NodeKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.IfIndexesInterfaceMap;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.InterfaceChildInfo;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._if.indexes._interface.map.IfIndexInterface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._if.indexes._interface.map.IfIndexInterfaceKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntryKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info._interface.parent.entry.InterfaceChildEntry;
@@ -214,6 +217,26 @@ public class InterfaceManagerRpcService implements OdlInterfaceRpcService {
         return Futures.immediateFuture(rpcResultBuilder.build());
     }
 
+    @Override
+    public Future<RpcResult<GetInterfaceFromIfIndexOutput>> getInterfaceFromIfIndex(GetInterfaceFromIfIndexInput input) {
+        Integer ifIndex = input.getIfIndex();
+        RpcResultBuilder<GetInterfaceFromIfIndexOutput> rpcResultBuilder = null;
+        try {
+            InstanceIdentifier<IfIndexInterface> id = InstanceIdentifier.builder(IfIndexesInterfaceMap.class).child(IfIndexInterface.class, new IfIndexInterfaceKey(ifIndex)).build();
+            Optional<IfIndexInterface> ifIndexesInterface = IfmUtil.read(LogicalDatastoreType.OPERATIONAL, id, dataBroker);
+            if(ifIndexesInterface.isPresent()) {
+                String interfaceName = ifIndexesInterface.get().getInterfaceName();
+                GetInterfaceFromIfIndexOutputBuilder output = new GetInterfaceFromIfIndexOutputBuilder().setInterfaceName(interfaceName);
+                rpcResultBuilder = RpcResultBuilder.success();
+                rpcResultBuilder.withResult(output.build());
+            }
+        } catch (Exception e) {
+            LOG.error("Retrieval of interfaceName for the key {} failed due to {}", ifIndex, e);
+            rpcResultBuilder = RpcResultBuilder.failed();
+        }
+        return Futures.immediateFuture(rpcResultBuilder.build());
+    }
+
     public List<ActionInfo> getEgressActionInfosForInterface(String interfaceName) {
         Interface interfaceInfo = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(new InterfaceKey(interfaceName),
                 dataBroker);
index 92c0b743d9a8094fb9260e3b564425ac35857fc5..24fa511b148224ad6523b29f9621bdef20e16523 100644 (file)
@@ -33,6 +33,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.No
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.InterfaceTypeGre;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge._interface.info.BridgeEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge._interface.info.BridgeEntryKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge._interface.info.bridge.entry.BridgeInterfaceEntry;
@@ -82,7 +83,7 @@ public class TunnelInterfaceConfigurationTest {
     TerminationPoint terminationPoint;
 
     @Mock DataBroker dataBroker;
-    @Mock IdManager idManager;
+    @Mock IdManagerService idManager;
     @Mock ListenerRegistration<DataChangeListener> dataChangeListenerRegistration;
     @Mock ReadOnlyTransaction mockReadTx;
     @Mock WriteTransaction mockWriteTx;
index f44e84197cefcc0e44f93613a41be0cb850fab7a..4f384474a782e8f0e72d870a9b2385ce100e24d0 100644 (file)
@@ -64,7 +64,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
     private final DataBroker broker;
     private IMdsalApiManager mdsalManager;
     private IInterfaceManager interfaceManager;
-    private IdManager idManager;
+    private IdManagerService idManager;
     private static final short LPORT_INGRESS_TABLE = 0;
     private static final short LFIB_TABLE = 20;
     private static final short FIB_TABLE = 21;
@@ -103,7 +103,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
         this.mdsalManager = mdsalManager;
     }
 
-    public void setIdManager(IdManager idManager) {
+    public void setIdManager(IdManagerService idManager) {
         this.idManager = idManager;
     }
 
index de61812fe958519ecc17da8c6822308b1f2c7027..5855c759e41839a2e3ef0b685a3dbe6c36f5ffe8 100644 (file)
@@ -14,6 +14,7 @@ import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
 import org.opendaylight.vpnservice.nexthopmgr.NexthopManager;
 import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.l3nexthop.rev150409.L3nexthopService;
 import org.opendaylight.idmanager.IdManager;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
@@ -28,7 +29,7 @@ public class NexthopmgrProvider implements BindingAwareProvider, AutoCloseable {
     private NexthopManager nhManager;
     private IMdsalApiManager mdsalManager;
     private IInterfaceManager interfaceManager;
-    private IdManager idManager;
+    private IdManagerService idManager;
     private RpcProviderRegistry rpcProviderRegistry;
 
     public RpcProviderRegistry getRpcProviderRegistry() {
@@ -46,7 +47,7 @@ public class NexthopmgrProvider implements BindingAwareProvider, AutoCloseable {
         nhManager = new NexthopManager(dbx);
         vpnIfListener = new VpnInterfaceChangeListener(dbx, nhManager);
         odlIfListener = new OdlInterfaceChangeListener(dbx, nhManager, interfaceManager);
-        idManager = new IdManager(dbx);
+        idManager = rpcProviderRegistry.getRpcService(IdManagerService.class);
         final BindingAwareBroker.RpcRegistration<L3nexthopService> rpcRegistration = getRpcProviderRegistry().addRpcImplementation(L3nexthopService.class, nhManager);
         nhManager.setMdsalManager(mdsalManager);
         nhManager.setInterfaceManager(interfaceManager);