Merge "Updated BgpManager for Be"
authorVivek Srivastava <vivek.v.srivastava@ericsson.com>
Thu, 14 Jan 2016 12:40:30 +0000 (12:40 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 14 Jan 2016 12:40:30 +0000 (12:40 +0000)
64 files changed:
alivenessmonitor/alivenessmonitor-impl/src/main/java/org/opendaylight/vpnservice/alivenessmonitor/internal/AlivenessProtocolHandlerARP.java
alivenessmonitor/alivenessmonitor-impl/src/main/java/org/opendaylight/vpnservice/alivenessmonitor/internal/AlivenessProtocolHandlerLLDP.java
dhcpservice/dhcpservice-api/src/main/java/org/opendaylight/vpnservice/dhcpservice/api/DHCPMConstants.java
dhcpservice/dhcpservice-impl/pom.xml
dhcpservice/dhcpservice-impl/src/main/config/default-config.xml
dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpConfigListener.java [new file with mode: 0644]
dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpManager.java
dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpProvider.java
dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/dhcpservice/impl/rev150710/DhcpServiceImplModule.java
dhcpservice/dhcpservice-impl/src/main/yang/dhcpservice-impl.yang
fibmanager/fibmanager-impl/src/main/java/org/opendaylight/vpnservice/fibmanager/FibManager.java
fibmanager/fibmanager-impl/src/main/java/org/opendaylight/vpnservice/fibmanager/NexthopManager.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/IfmConstants.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/commons/InterfaceManagerCommonUtils.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/rpcservice/InterfaceManagerRpcService.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/utilities/FlowBasedServicesUtils.java
interfacemgr/interfacemgr-impl/src/test/java/org/opendaylight/vpnservice/interfacemgr/test/FlowBasedServicesStateConfigurationTest.java
interfacemgr/interfacemgr-impl/src/test/java/org/opendaylight/vpnservice/interfacemgr/test/InterfaceManagerTestUtil.java
itm/itm-api/.gitignore [new file with mode: 0644]
itm/itm-api/src/main/java/org/opendaylight/vpnservice/itm/globals/ITMConstants.java
itm/itm-api/src/main/yang/itm-rpc.yang
itm/itm-api/src/main/yang/itm-state.yang
itm/itm-impl/pom.xml
itm/itm-impl/src/main/config/default-config.xml
itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmExternalTunnelAddWorker.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
itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/rpc/ItmManagerRpcService.java
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/vpnservice/datastoreutils/AsyncClusteredDataChangeListenerBase.java [new file with mode: 0644]
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/vpnservice/mdsalutil/ActionType.java
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/vpnservice/mdsalutil/MetaDataUtil.java
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/vpnservice/mdsalutil/NwConstants.java
neutronvpn/neutronvpn-api/pom.xml
neutronvpn/neutronvpn-api/src/main/java/org/opendaylight/vpnservice/neutronvpn/interfaces/INeutronVpnManager.java
neutronvpn/neutronvpn-api/src/main/yang/neutronvpn.yang
neutronvpn/neutronvpn-impl/pom.xml
neutronvpn/neutronvpn-impl/src/main/config/default-config.xml
neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronBgpvpnChangeListener.java
neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronNetworkChangeListener.java
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/NeutronvpnProvider.java
neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronvpnUtils.java
neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/neutronvpn/impl/rev150325/NeutronvpnImplModule.java
neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/neutronvpn/impl/rev150325/NeutronvpnImplModuleFactory.java
neutronvpn/neutronvpn-shell/pom.xml
neutronvpn/neutronvpn-shell/src/main/java/org/opendaylight/vpnservice/neutronvpn/shell/ConfigureL3VpnCommand.java
neutronvpn/neutronvpn-shell/src/main/java/org/opendaylight/vpnservice/neutronvpn/shell/ShowNeutronPortsCommand.java
neutronvpn/neutronvpn-shell/src/main/java/org/opendaylight/vpnservice/neutronvpn/shell/ShowVpnConfigCommand.java
neutronvpn/neutronvpn-shell/src/main/resources/OSGI-INF/blueprint/blueprint.xml
neutronvpn/pom.xml
vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/VpnConstants.java
vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/VpnInterfaceManager.java

index 33fb6ad90bd917a96285e0562fcc734dd6dd4630..d125ff066cd106e2c166ec5f51c1e94f8e378160 100644 (file)
@@ -14,6 +14,7 @@ import java.math.BigInteger;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 
 import org.opendaylight.controller.liblldp.Packet;
@@ -27,6 +28,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.endpoint.endpoint.type.Interface;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.endpoint.endpoint.type.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.monitor.configs.MonitoringInfo;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.GetInterfaceFromIfIndexInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.GetInterfaceFromIfIndexInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.GetInterfaceFromIfIndexOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.arputil.rev151126.OdlArputilService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.arputil.rev151126.SendArpRequestInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.arputil.rev151126.SendArpRequestInputBuilder;
@@ -79,12 +83,21 @@ public class AlivenessProtocolHandlerARP extends AbstractAlivenessProtocolHandle
                 BigInteger metadata = packetReceived.getMatch().getMetadata().getMetadata();
                 int portTag = MetaDataUtil.getLportFromMetadata(metadata).intValue();
                 String interfaceName = null;
-                NodeConnectorId connId = packetReceived.getMatch().getInPort();
-//                try {
-//                    interfaceName = serviceProvider.getInterfaceManager().getInterfaceNameForInterfaceTag(portTag);
-//                } catch(InterfaceNotFoundException e) {
-//                    LOG.warn("Error retrieving interface Name for tag {}", portTag, e);
-//                }
+
+                try {
+                    GetInterfaceFromIfIndexInput input = new GetInterfaceFromIfIndexInputBuilder().setIfIndex(portTag).build();
+                    Future<RpcResult<GetInterfaceFromIfIndexOutput>> output = serviceProvider.getInterfaceManager().getInterfaceFromIfIndex(input);
+                    RpcResult<GetInterfaceFromIfIndexOutput> result = output.get();
+                    if(result.isSuccessful()) {
+                        GetInterfaceFromIfIndexOutput ifIndexOutput = result.getResult();
+                        interfaceName = ifIndexOutput.getInterfaceName();
+                    } else {
+                        LOG.warn("RPC call to get interface name for if index {} failed with errors {}", portTag, result.getErrors());
+                        return null;
+                    }
+                } catch(InterruptedException | ExecutionException e) {
+                    LOG.warn("Error retrieving interface Name for tag {}", portTag, e);
+                }
                 if(!Strings.isNullOrEmpty(interfaceName)) {
                     String sourceIp = toStringIpAddress(packet.getSenderProtocolAddress());
                     String targetIp = toStringIpAddress(packet.getTargetProtocolAddress());
index d0391519fe41b6e13a87337f6370e1c27a04e1ba..d0d7511bb29e3f42be5f2d4cf127e64a3811fc7e 100644 (file)
@@ -36,11 +36,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.endpoint.endpoint.type.Interface;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.monitor.configs.MonitoringInfo;
 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.Interface;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfaceType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.GetDpidFromInterfaceInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.GetDpidFromInterfaceInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.GetDpidFromInterfaceOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.GetInterfaceFromIfIndexInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.GetInterfaceFromIfIndexInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.GetInterfaceFromIfIndexOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.GetPortFromInterfaceInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.GetPortFromInterfaceInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.GetPortFromInterfaceOutput;
@@ -122,12 +124,21 @@ public class AlivenessProtocolHandlerLLDP extends AbstractAlivenessProtocolHandl
         }
 
         String destInterfaceName = null;
-        //TODO: Use latest interface RPC
-//        try {
-//            destInterfaceName = serviceProvider.getInterfaceManager().getInterfaceNameForInterfaceTag(portTag);
-//        } catch(InterfaceNotFoundException e) {
-//            LOG.warn("Error retrieving interface Name for tag {}", portTag, e);
-//        }
+
+        try {
+            GetInterfaceFromIfIndexInput input = new GetInterfaceFromIfIndexInputBuilder().setIfIndex(portTag).build();
+            Future<RpcResult<GetInterfaceFromIfIndexOutput>> output = serviceProvider.getInterfaceManager().getInterfaceFromIfIndex(input);
+            RpcResult<GetInterfaceFromIfIndexOutput> result = output.get();
+            if(result.isSuccessful()) {
+                GetInterfaceFromIfIndexOutput ifIndexOutput = result.getResult();
+                destInterfaceName = ifIndexOutput.getInterfaceName();
+            } else {
+                LOG.warn("RPC call to get interface name for if index {} failed with errors {}", portTag, result.getErrors());
+                return null;
+            }
+        } catch(InterruptedException | ExecutionException e) {
+            LOG.warn("Error retrieving interface Name for tag {}", portTag, e);
+        }
 
         if(!Strings.isNullOrEmpty(interfaceName)) {
             String monitorKey = new StringBuilder().append(interfaceName).append(EtherTypes.LLDP).toString();
@@ -186,7 +197,7 @@ public class AlivenessProtocolHandlerLLDP extends AbstractAlivenessProtocolHandl
                 return;
             }
         }catch(InterruptedException | ExecutionException e) {
-            LOG.error("Failed to retrieve RPC Result ", e);
+            LOG.error("Failed to retrieve interface service RPC Result ", e);
             return;
         }
 
index 9da75e9d82580d568e15c93507151a388b45431c..bcf8612da273a357949bf0a066407a0027a541f0 100644 (file)
@@ -34,4 +34,5 @@ public final class DHCPMConstants {
     public static final short dhcpServerPort = 67;
 
     public static final int DEFAULT_LEASE_TIME = 86400;
+    public static final String DEFAULT_DOMAIN_NAME = "openstacklocal";
 }
index d6c1c00ebe1192839526919a0db19aad40a6a0fd..862601fd601300bbcf702a4a0ce592b90e811776 100644 (file)
@@ -40,6 +40,16 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       <artifactId>mdsalutil-api</artifactId>
       <version>${vpnservices.version}</version>
     </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>neutronvpn-api</artifactId>
+      <version>${vpnservices.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.karaf.shell</groupId>
+      <artifactId>org.apache.karaf.shell.console</artifactId>
+      <version>${karaf.shell.console.version}</version>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.neutron</groupId>
       <artifactId>model</artifactId>
index 64b2bfaa29ce6d13318b79a3c8b871cb05a8037d..fe6008a4a2eb2258ca657388182d2e075625a286 100644 (file)
@@ -12,6 +12,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       <capability>urn:opendaylight:params:xml:ns:yang:dhcpservice:impl?module=dhcpservice-impl&amp;revision=2015-07-10</capability>
       <capability>urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding?module=opendaylight-md-sal-binding&amp;revision=2013-10-28</capability>
       <capability>urn:opendaylight:params:xml:ns:yang:mdsalutil:api?module=odl-mdsalutil&amp;revision=2015-04-10</capability>
+      <capability>urn:opendaylight:params:xml:ns:yang:neutronvpn:api?module=neutronvpn-api&amp;revision=2015-08-12</capability>
   </required-capabilities>
   <configuration>
 
@@ -36,6 +37,10 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
             <type xmlns:mdsalutil="urn:opendaylight:params:xml:ns:yang:mdsalutil:api">mdsalutil:odl-mdsalutil</type>
             <name>mdsalutil-service</name>
           </mdsalutil>
+          <neutronvpn>
+            <type xmlns:neutronvpn="urn:opendaylight:params:xml:ns:yang:neutronvpn:api">neutronvpn:neutronvpn-api</type>
+            <name>neutronvpn</name>
+          </neutronvpn>
         </module>
       </modules>
     </data>
diff --git a/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpConfigListener.java b/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpConfigListener.java
new file mode 100644 (file)
index 0000000..2d18705
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * 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.dhcpservice;
+
+import org.opendaylight.controller.md.sal.binding.api.ClusteredDataChangeListener;
+
+import org.opendaylight.vpnservice.datastoreutils.AsyncClusteredDataChangeListenerBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.dhcp.config.Configs;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
+import org.opendaylight.vpnservice.datastoreutils.AsyncDataChangeListenerBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.DhcpConfig;
+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.dhcpservice.api.DHCPMConstants;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DhcpConfigListener extends AsyncClusteredDataChangeListenerBase<DhcpConfig, DhcpConfigListener> implements AutoCloseable {
+
+    private static final Logger LOG = LoggerFactory.getLogger(DhcpConfigListener.class);
+
+    private ListenerRegistration<DataChangeListener> listenerRegistration;
+    private DhcpManager dhcpManager;
+
+    public DhcpConfigListener(final DataBroker db, final DhcpManager dhcpMgr) {
+        super(DhcpConfig.class, DhcpConfigListener.class);
+        dhcpManager = dhcpMgr;
+        registerListener(db);
+    }
+
+    private void registerListener(final DataBroker db) {
+        try {
+            listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
+                    getWildCardPath(), DhcpConfigListener.this, AsyncDataBroker.DataChangeScope.SUBTREE);
+        } catch (final Exception e) {
+            LOG.error("NodeListener: DataChange listener registration fail!", e);
+            throw new IllegalStateException("NodeListener: registration Listener failed.", e);
+        }
+    }
+
+    protected InstanceIdentifier<DhcpConfig> getWildCardPath() {
+        return InstanceIdentifier.create(DhcpConfig.class);
+    }
+
+    @Override
+    public void close() throws Exception {
+        if (listenerRegistration != null) {
+            try {
+                listenerRegistration.close();
+            } catch (final Exception e) {
+                LOG.error("Error when cleaning up DhcpConfigListener.", e);
+            }
+            listenerRegistration = null;
+        }
+        LOG.debug("DhcpConfig Listener Closed");
+    }
+
+    @Override
+    protected void remove(InstanceIdentifier<DhcpConfig> identifier, DhcpConfig del) {
+        LOG.trace("DhcpConfig removed: {}", del);
+        updateConfig(null);
+    }
+
+    @Override
+    protected void update(InstanceIdentifier<DhcpConfig> identifier, DhcpConfig original, DhcpConfig update) {
+        LOG.trace("DhcpConfig changed to {}", update);
+        updateConfig(update);
+    }
+
+    @Override
+    protected void add(InstanceIdentifier<DhcpConfig> identifier, DhcpConfig add) {
+        LOG.trace("DhcpConfig added {}", add);
+        updateConfig(add);
+    }
+
+    private void updateConfig(DhcpConfig update) {
+        //TODO: Update operational with actual values
+        if(update == null || update.getConfigs() == null || update.getConfigs().isEmpty()) {
+            dhcpManager.setLeaseDuration(DHCPMConstants.DEFAULT_LEASE_TIME);
+            dhcpManager.setDefaultDomain(DHCPMConstants.DEFAULT_DOMAIN_NAME);
+            return;
+        }
+        Configs config = update.getConfigs().get(0);
+        if(config.getLeaseDuration() != null) {
+            dhcpManager.setLeaseDuration(config.getLeaseDuration());
+        }
+        if(config.getDefaultDomain() != null) {
+            dhcpManager.setDefaultDomain(config.getDefaultDomain());
+            //TODO: What to do if string is ""
+        }
+    }
+
+    @Override
+    protected ClusteredDataChangeListener getDataChangeListener() {
+        return DhcpConfigListener.this;
+    }
+
+    @Override
+    protected DataChangeScope getDataChangeScope() {
+        return AsyncDataBroker.DataChangeScope.BASE;
+    }
+}
index 458ad968210da082b0d554468a3e3b7878dd983e..f195fa89535403a816bd697467a208c52c70997a 100644 (file)
@@ -7,8 +7,9 @@
  */
 package org.opendaylight.vpnservice.dhcpservice;
 
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.SubnetKey;
+import org.opendaylight.vpnservice.neutronvpn.interfaces.INeutronVpnManager;
 
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.SubnetKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets;
 import com.google.common.base.Optional;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -46,7 +47,8 @@ public class DhcpManager implements AutoCloseable {
     private int dhcpOptLeaseTime = 0;
     private int dhcpOptRenewalTime = 0;
     private int dhcpOptRebindingTime = 0;
-    private String dhcpOptDefDomainName = "openstacklocal";
+    private String dhcpOptDefDomainName;
+    private INeutronVpnManager neutronVpnService;
 
     private static final FutureCallback<Void> DEFAULT_CALLBACK =
         new FutureCallback<Void>() {
@@ -70,6 +72,11 @@ public class DhcpManager implements AutoCloseable {
         this.mdsalUtil = mdsalManager;
     }
 
+    public void setNeutronVpnService(INeutronVpnManager neutronVpnService) {
+        logger.debug("Setting NeutronVpn dependency");
+        this.neutronVpnService = neutronVpnService;
+    }
+
     @Override
     public void close() throws Exception {
         logger.info("DHCP Manager Closed");
@@ -150,7 +157,6 @@ public class DhcpManager implements AutoCloseable {
     }
 
     public Subnet getNeutronSubnet(Port nPort) {
-        /* TODO: Once NeutronVpn is merged, use it to get Subnet
         if (nPort != null) {
             try {
                 return neutronVpnService.getNeutronSubnet(nPort.getFixedIps().get(0).getSubnetId());
@@ -158,32 +164,11 @@ public class DhcpManager implements AutoCloseable {
                 logger.warn("Failed to get Neutron Subnet from Port: {}", e);
             }
         }
-        */
-        if (nPort.getFixedIps() != null && !nPort.getFixedIps().isEmpty()) {
-            InstanceIdentifier<Subnet> sIid =
-                            InstanceIdentifier.create(Neutron.class).child(Subnets.class)
-                                .child(Subnet.class, new SubnetKey(nPort.getFixedIps().get(0).getSubnetId()));
-            Optional<Subnet> optSubnet = MDSALUtil.read(LogicalDatastoreType.CONFIGURATION, sIid, broker);
-            if (optSubnet.isPresent()) {
-                return optSubnet.get();
-            }
-        }
         return null;
     }
 
     public Port getNeutronPort(String name) {
-        // TODO Once NeutronVpn is merged, use it to get port
-        //return neutronVpnService.getNeutronPort(name);
-        InstanceIdentifier<Ports> pIid = InstanceIdentifier.create(Neutron.class).child(Ports.class);
-        Optional<Ports> optPorts = MDSALUtil.read(LogicalDatastoreType.CONFIGURATION, pIid, broker);
-        if(optPorts.isPresent()) {
-            for(Port port: optPorts.get().getPort()) {
-                if(port.getUuid().getValue().startsWith(name.substring(3))) {
-                    return port;
-                }
-            }
-        }
-        return null;
+        return neutronVpnService.getNeutronPort(name);
     }
 
 }
index ce1a0a11c227c06c31555ab69aa5699841b2f8a0..5f15135fb3103bb5505ad1f2b48d3d165fe8bb0b 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.vpnservice.dhcpservice;
 
-import java.math.BigInteger;
+import org.opendaylight.vpnservice.neutronvpn.interfaces.INeutronVpnManager;
 
 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
@@ -28,6 +28,8 @@ public class DhcpProvider implements BindingAwareProvider, AutoCloseable {
     private NotificationProviderService notificationService;
     private DhcpManager dhcpManager;
     private NodeListener dhcpNodeListener;
+    private INeutronVpnManager neutronVpnManager;
+    private DhcpConfigListener dhcpConfigListener;
 
     @Override
     public void onSessionInitiated(ProviderContext session) {
@@ -37,10 +39,12 @@ public class DhcpProvider implements BindingAwareProvider, AutoCloseable {
             final PacketProcessingService pktProcessingService = session.getRpcService(PacketProcessingService.class);
             dhcpManager = new DhcpManager(dataBroker);
             dhcpManager.setMdsalManager(mdsalManager);
+            dhcpManager.setNeutronVpnService(neutronVpnManager);
             dhcpPktHandler = new DhcpPktHandler(dataBroker, dhcpManager);
             dhcpPktHandler.setPacketProcessingService(pktProcessingService);
             packetListener = notificationService.registerNotificationListener(dhcpPktHandler);
             dhcpNodeListener = new NodeListener(dataBroker, dhcpManager);
+            dhcpConfigListener = new DhcpConfigListener(dataBroker, dhcpManager);
         } catch (Exception e) {
             LOG.error("Error initializing services", e);
         }
@@ -51,6 +55,10 @@ public class DhcpProvider implements BindingAwareProvider, AutoCloseable {
         this.mdsalManager = mdsalManager;
     }
 
+    public void setNeutronVpnManager(INeutronVpnManager neutronVpnManager) {
+        this.neutronVpnManager = neutronVpnManager;
+    }
+
     @Override
     public void close() throws Exception {
         if(packetListener != null) {
index bf453d425700d35ddc1799eb78109c5443edc767..eac19a9934d7f5b397c8d6f23abb795b81040558 100644 (file)
@@ -21,6 +21,7 @@ public class DhcpServiceImplModule extends org.opendaylight.yang.gen.v1.urn.open
         DhcpProvider dhcpProvider = new DhcpProvider();
         dhcpProvider.setNotificationProviderService(getNotificationServiceDependency());
         dhcpProvider.setMdsalManager(getMdsalutilDependency());
+        dhcpProvider.setNeutronVpnManager(getNeutronvpnDependency());
         getBrokerDependency().registerProvider(dhcpProvider);
         return dhcpProvider;
     }
index dcbec022c08d041a7a3d61e388c32f4be7d10a4c..856b7716dc26a1244c8aa30f0618474184208ebc 100644 (file)
@@ -6,6 +6,7 @@ module dhcpservice-impl {
     import config { prefix config; revision-date 2013-04-05; }
     import opendaylight-md-sal-binding { prefix md-sal-binding; revision-date 2013-10-28;}
     import odl-mdsalutil { prefix odl-mdsal; revision-date 2015-04-10;}
+    import neutronvpn-api { prefix nvpn; revision-date 2015-08-12;}
 
     description
         "Service definition for dhcpservice project";
@@ -56,6 +57,15 @@ module dhcpservice-impl {
                     }
                 }
             }
+
+            container neutronvpn {
+                uses config:service-ref {
+                    refine type {
+                        mandatory true;
+                        config:required-identity nvpn:neutronvpn-api;
+                    }
+                }
+            }
         }
     }
 }
index d3d584201d7d97fb3026d06c495143fbd5b03883..7adde2c47d7fb3d6dae78c6b9ba79bd96f774747 100644 (file)
@@ -51,7 +51,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instanc
 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntryKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.TunnelTypeVxlan;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetTunnelInterfaceNameOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.ItmRpcService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.fibmanager.rev150330.FibEntries;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.fibmanager.rev150330.fibentries.VrfTables;
@@ -83,17 +82,12 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
   private NexthopManager nextHopManager;
   private ItmRpcService itmManager;
   private OdlInterfaceRpcService interfaceManager;
-
-  private static final short L3_FIB_TABLE = 21;
-  private static final short L3_LFIB_TABLE = 20;
-  private static final short L3_PROTOCOL_TABLE = 36;
-  private static final short L3_INTERFACE_TABLE = 80;
-  public static final short LPORT_DISPATCHER_TABLE = 30;
   private static final BigInteger COOKIE_VM_LFIB_TABLE = new BigInteger("8000002", 16);
   private static final BigInteger COOKIE_VM_FIB_TABLE =  new BigInteger("8000003", 16);
   private static final int DEFAULT_FIB_FLOW_PRIORITY = 10;
   private static final BigInteger METADATA_MASK_CLEAR = new BigInteger("000000FFFFFFFFFF", 16);
   private static final BigInteger CLEAR_METADATA = BigInteger.valueOf(0);
+  public static final BigInteger COOKIE_TUNNEL = new BigInteger("9000000", 16);
 
 
   private static final FutureCallback<Void> DEFAULT_CALLBACK =
@@ -212,9 +206,9 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
     Preconditions.checkNotNull(vpnInstance.getVpnId(), "Vpn Instance with rd " + vpnInstance.getVrfId() + "has null vpnId!");
 
     Collection<VpnToDpnList> vpnToDpnList = vpnInstance.getVpnToDpnList();
+    BigInteger localDpnId = createLocalFibEntry(vpnInstance.getVpnId(),
+              vrfTableKey.getRouteDistinguisher(), vrfEntry);
     if (vpnToDpnList != null) {
-      BigInteger localDpnId = createLocalFibEntry(vpnInstance.getVpnId(),
-                          vrfTableKey.getRouteDistinguisher(), vrfEntry);
       for (VpnToDpnList curDpn : vpnToDpnList) {
         if (!curDpn.getDpnId().equals(localDpnId)) {
           createRemoteFibEntry(localDpnId, curDpn.getDpnId(), vpnInstance.getVpnId(),
@@ -266,31 +260,39 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
   }
 
   public void createTerminatingServiceActions( BigInteger destDpId, int label, List<ActionInfo> actionsInfos) {
-    // FIXME
-/*      List<MatchInfo> mkMatches = new ArrayList<MatchInfo>();
+      List<MatchInfo> mkMatches = new ArrayList<MatchInfo>();
 
       LOG.info("create terminatingServiceAction on DpnId = {} and serviceId = {} and actions = {}", destDpId , label,actionsInfos);
 
       // Matching metadata
-      mkMatches.add(new MatchInfo(MatchFieldType.tunnel_id, new BigInteger[] {
-                                  MetaDataUtil.getTunnelIdWithValidVniBitAndVniSet(label),
-                                  MetaDataUtil.METADA_MASK_TUNNEL_ID }));
+      // FIXME vxlan vni bit set is not working properly with OVS.need to revisit
+      mkMatches.add(new MatchInfo(MatchFieldType.tunnel_id, new BigInteger[] {BigInteger.valueOf(label)}));
 
       List<InstructionInfo> mkInstructions = new ArrayList<InstructionInfo>();
       mkInstructions.add(new InstructionInfo(InstructionType.write_actions, actionsInfos));
 
-      FlowEntity terminatingServiceTableFlowEntity = MDSALUtil.buildFlowEntity(destDpId,ITMConstants.TERMINATING_SERVICE_TABLE,
-                      getFlowRef(destDpId, ITMConstants.TERMINATING_SERVICE_TABLE,label), 5, String.format("%s:%d","TST Flow Entry ",label),
-                      0, 0, ITMConstants.COOKIE_ITM.add(BigInteger.valueOf(label)),mkMatches, mkInstructions);
+      FlowEntity terminatingServiceTableFlowEntity = MDSALUtil.buildFlowEntity(destDpId, NwConstants.INTERNAL_TUNNEL_TABLE,
+                      getFlowRef(destDpId, NwConstants.INTERNAL_TUNNEL_TABLE,label), 5, String.format("%s:%d","TST Flow Entry ",label),
+                      0, 0, COOKIE_TUNNEL.add(BigInteger.valueOf(label)),mkMatches, mkInstructions);
 
-      mdsalManager.installFlow(terminatingServiceTableFlowEntity);*/
+      mdsalManager.installFlow(terminatingServiceTableFlowEntity);
  }
 
   private void removeTunnelTableEntry(BigInteger dpId, long label) {
-      // FIXME
-      // itmManager.removeTerminatingServiceAction(dpId, (int)label);
-
-      // LOG.debug("Terminating service Entry for dpID {} : label : {} removed successfully {}",dpId, label);
+    FlowEntity flowEntity;
+    LOG.info("remove terminatingServiceActions called with DpnId = {} and label = {}", dpId , label);
+    List<MatchInfo> mkMatches = new ArrayList<MatchInfo>();
+    // Matching metadata
+    mkMatches.add(new MatchInfo(MatchFieldType.tunnel_id, new BigInteger[] {
+        MetaDataUtil.getTunnelIdWithValidVniBitAndVniSet((int)label),
+        MetaDataUtil.METADA_MASK_TUNNEL_ID }));
+    flowEntity = MDSALUtil.buildFlowEntity(dpId,
+                                           NwConstants.INTERNAL_TUNNEL_TABLE,
+                                           getFlowRef(dpId, NwConstants.INTERNAL_TUNNEL_TABLE, (int)label),
+                                           5, String.format("%s:%d","TST Flow Entry ",label), 0, 0,
+                                           COOKIE_TUNNEL.add(BigInteger.valueOf(label)), mkMatches, null);
+    mdsalManager.removeFlow(flowEntity);
+    LOG.debug("Terminating service Entry for dpID {} : label : {} removed successfully {}",dpId, label);
   }
 
   public BigInteger deleteLocalFibEntry(Long vpnId, String rd, VrfEntry vrfEntry) {
@@ -362,7 +364,7 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
                              vrfEntry.getDestPrefix(), rd);
       return;
     }
-        List<ActionInfo> actionInfos = nextHopManager.getEgressActionsForInterface(tunnelInterface);
+      List<ActionInfo> actionInfos = new ArrayList<>();
        Class<? extends TunnelTypeBase> tunnel_type = getTunnelType(tunnelInterface);
     if (tunnel_type.equals(TunnelTypeMplsOverGre.class)) {
         LOG.debug("Push label action for prefix {}", vrfEntry.getDestPrefix());
@@ -371,15 +373,17 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
     } else {
         int label = vrfEntry.getLabel().intValue();
         BigInteger tunnelId;
+        // FIXME vxlan vni bit set is not working properly with OVS.need to revisit
         if(tunnel_type.equals(TunnelTypeVxlan.class)) {
-               tunnelId = MetaDataUtil.getTunnelIdWithValidVniBitAndVniSet(label);
+               tunnelId = BigInteger.valueOf(label);
         } else {
                tunnelId = BigInteger.valueOf(label);
         }
         LOG.debug("adding set tunnel id action for label {}", label);
-        actionInfos.add(new ActionInfo(ActionType.set_field_tunnel_id, new BigInteger[] {
-                       tunnelId, MetaDataUtil.METADA_MASK_VALID_TUNNEL_ID_BIT_AND_TUNNEL_ID }));
+        actionInfos.add(new ActionInfo(ActionType.set_field_tunnel_id, new BigInteger[]{
+                tunnelId}));
     }
+    actionInfos.addAll(nextHopManager.getEgressActionsForInterface(tunnelInterface));
 /*
     List<ActionInfo> actionInfos = resolveAdjacency(localDpnId, remoteDpnId, vpnId, vrfEntry);
     if(actionInfos == null) {
@@ -407,7 +411,7 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
                 MetaDataUtil.METADA_MASK_VALID_TUNNEL_ID_BIT_AND_TUNNEL_ID }));
     }
 **/
-    makeConnectedRoute(remoteDpnId, vpnId, vrfEntry, rd, actionInfos, NwConstants.ADD_FLOW);
+      makeConnectedRoute(remoteDpnId, vpnId, vrfEntry, rd, actionInfos, NwConstants.ADD_FLOW);
     LOG.debug(
         "Successfully added fib entry for " + vrfEntry.getDestPrefix() + " vpnId " + vpnId);
   }
@@ -421,9 +425,9 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
     VpnInstanceOpDataEntry vpnInstance = getVpnInstance(vrfTableKey.getRouteDistinguisher());
     Preconditions.checkNotNull(vpnInstance, "Vpn Instance not available!");
     Collection<VpnToDpnList> vpnToDpnList = vpnInstance.getVpnToDpnList();
+    BigInteger localDpnId = deleteLocalFibEntry(vpnInstance.getVpnId(),
+              vrfTableKey.getRouteDistinguisher(), vrfEntry);
     if (vpnToDpnList != null) {
-      BigInteger localDpnId = deleteLocalFibEntry(vpnInstance.getVpnId(),
-                          vrfTableKey.getRouteDistinguisher(), vrfEntry);
       for (VpnToDpnList curDpn : vpnToDpnList) {
         if (!curDpn.getDpnId().equals(localDpnId)) {
           deleteRemoteRoute(localDpnId, curDpn.getDpnId(), vpnInstance.getVpnId(), vrfTableKey, vrfEntry);
@@ -489,12 +493,12 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
       instructions.add(new InstructionInfo(InstructionType.write_actions, actionInfos));
     }
 
-    String flowRef = getFlowRef(dpId, L3_FIB_TABLE, rd, destPrefix);
+    String flowRef = getFlowRef(dpId, NwConstants.L3_FIB_TABLE, rd, destPrefix);
 
     FlowEntity flowEntity;
 
     int priority = DEFAULT_FIB_FLOW_PRIORITY + prefixLength;
-    flowEntity = MDSALUtil.buildFlowEntity(dpId, L3_FIB_TABLE, flowRef,
+    flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_FIB_TABLE, flowRef,
                                            priority, flowRef, 0, 0,
                                            COOKIE_VM_FIB_TABLE, matches, instructions);
 
@@ -528,10 +532,10 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
     instructions.add(new InstructionInfo(InstructionType.write_actions, actionsInfos));
 
     // Install the flow entry in L3_LFIB_TABLE
-    String flowRef = getFlowRef(dpId, L3_LFIB_TABLE, label, nextHop);
+    String flowRef = getFlowRef(dpId, NwConstants.L3_LFIB_TABLE, label, nextHop);
 
     FlowEntity flowEntity;
-    flowEntity = MDSALUtil.buildFlowEntity(dpId, L3_LFIB_TABLE, flowRef,
+    flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_LFIB_TABLE, flowRef,
                                            DEFAULT_FIB_FLOW_PRIORITY, flowRef, 0, 0,
                                            COOKIE_VM_LFIB_TABLE, matches, instructions);
 
@@ -645,13 +649,13 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
         final BigInteger COOKIE_TABLE_MISS = new BigInteger("1030000", 16);
         // Instruction to goto L3 InterfaceTable
         List<InstructionInfo> instructions = new ArrayList<InstructionInfo>();
-        instructions.add(new InstructionInfo(InstructionType.goto_table, new long[] { L3_INTERFACE_TABLE }));
+        instructions.add(new InstructionInfo(InstructionType.goto_table, new long[] { NwConstants.L3_INTERFACE_TABLE }));
         List<MatchInfo> matches = new ArrayList<MatchInfo>();
-        FlowEntity flowEntityLfib = MDSALUtil.buildFlowEntity(dpnId, L3_LFIB_TABLE,
-                getFlowRef(dpnId, L3_LFIB_TABLE, NwConstants.TABLE_MISS_FLOW),
+        FlowEntity flowEntityLfib = MDSALUtil.buildFlowEntity(dpnId, NwConstants.L3_LFIB_TABLE,
+                getFlowRef(dpnId, NwConstants.L3_LFIB_TABLE, NwConstants.TABLE_MISS_FLOW),
                 NwConstants.TABLE_MISS_PRIORITY, "Table Miss", 0, 0, COOKIE_TABLE_MISS, matches, instructions);
 
-        FlowEntity flowEntityFib = MDSALUtil.buildFlowEntity(dpnId,L3_FIB_TABLE, getFlowRef(dpnId, L3_FIB_TABLE, NwConstants.TABLE_MISS_FLOW),
+        FlowEntity flowEntityFib = MDSALUtil.buildFlowEntity(dpnId,NwConstants.L3_FIB_TABLE, getFlowRef(dpnId, NwConstants.L3_FIB_TABLE, NwConstants.TABLE_MISS_FLOW),
                 NwConstants.TABLE_MISS_PRIORITY, "FIB Table Miss Flow", 0, 0, COOKIE_VM_FIB_TABLE,
                 matches, instructions);
 
@@ -680,13 +684,13 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
     final BigInteger COOKIE_PROTOCOL_TABLE = new BigInteger("1070000", 16);
     // Instruction to goto L3 InterfaceTable
     List<InstructionInfo> instructions = new ArrayList<>();
-    instructions.add(new InstructionInfo(InstructionType.goto_table, new long[] {L3_LFIB_TABLE}));
+    instructions.add(new InstructionInfo(InstructionType.goto_table, new long[] {NwConstants.L3_LFIB_TABLE}));
     List<MatchInfo> matches = new ArrayList<MatchInfo>();
     matches.add(new MatchInfo(MatchFieldType.eth_type,
                               new long[] { 0x8847L }));
-    FlowEntity flowEntityToLfib = MDSALUtil.buildFlowEntity(dpnId, L3_PROTOCOL_TABLE,
-                                                          getFlowRef(dpnId, L3_PROTOCOL_TABLE,
-                                                                     L3_LFIB_TABLE),
+    FlowEntity flowEntityToLfib = MDSALUtil.buildFlowEntity(dpnId, NwConstants.L3_PROTOCOL_TABLE,
+                                                          getFlowRef(dpnId, NwConstants.L3_PROTOCOL_TABLE,
+                                                                  NwConstants.L3_LFIB_TABLE),
                                                           DEFAULT_FIB_FLOW_PRIORITY,
                                                           "Protocol Table For LFIB",
                                                           0, 0,
@@ -730,10 +734,10 @@ public class FibManager extends AbstractDataChangeListener<VrfEntry> implements
     instructions.add(new InstructionInfo(InstructionType.clear_actions));
     // Instruction to goto L3 InterfaceTable
 
-    instructions.add(new InstructionInfo(InstructionType.goto_table, new long[] { LPORT_DISPATCHER_TABLE }));
+    instructions.add(new InstructionInfo(InstructionType.goto_table, new long[] { NwConstants.LPORT_DISPATCHER_TABLE }));
 
-    FlowEntity flowEntityL3Intf = MDSALUtil.buildFlowEntity(dpnId, L3_INTERFACE_TABLE,
-            getFlowRef(dpnId, L3_INTERFACE_TABLE, NwConstants.TABLE_MISS_FLOW),
+    FlowEntity flowEntityL3Intf = MDSALUtil.buildFlowEntity(dpnId, NwConstants.L3_INTERFACE_TABLE,
+            getFlowRef(dpnId, NwConstants.L3_INTERFACE_TABLE, NwConstants.TABLE_MISS_FLOW),
             NwConstants.TABLE_MISS_PRIORITY, "L3 Interface Table Miss", 0, 0, COOKIE_TABLE_MISS, matches, instructions);
     if (addOrRemove == NwConstants.ADD_FLOW) {
       LOG.info("Invoking MDSAL to install L3 interface Table Miss Entries");
index b8a01d134027d9dee755887cf91243a97b13cfe8..7866cd2437ed20d4a9e20958065fb3463792fa4a 100644 (file)
@@ -218,8 +218,6 @@ public class NexthopManager implements AutoCloseable {
     }
 
     protected String getTunnelInterfaceName(BigInteger srcDpId, BigInteger dstDpId) {
-        // FIXME: Enable during itm integration
-        
         try {
             Future<RpcResult<GetTunnelInterfaceNameOutput>> result = itmManager.getTunnelInterfaceName(new GetTunnelInterfaceNameInputBuilder()
                                                                                  .setSourceDpid(srcDpId)
@@ -238,8 +236,6 @@ public class NexthopManager implements AutoCloseable {
     }
 
     protected String getExternalTunnelInterfaceName(BigInteger srcDpId, IpAddress dstIp) {
-        // FIXME: Enable during itm integration
-        
         try {
             Future<RpcResult<GetExternalTunnelInterfaceNameOutput>> result = itmManager.getExternalTunnelInterfaceName(new GetExternalTunnelInterfaceNameInputBuilder()
                                                                                  .setSourceDpid(srcDpId)
index ce95c4c309fafba6100a7394ed00c31c205def12..2e573bef4ce95aa8b6c43339ca1732c18c9fbec3 100644 (file)
@@ -20,10 +20,6 @@ public class IfmConstants {
     public static final int DEFAULT_IFINDEX = 65536;
     public static final int DEFAULT_FLOW_PRIORITY = 5;
     public static final String IFM_LPORT_TAG_IDPOOL_NAME = "vlaninterfaces.lporttag";
-    public static final short VLAN_INTERFACE_INGRESS_TABLE = 0;
-    public static final short INTERNAL_TUNNEL_TABLE = 22;
-    public static final short EXTERNAL_TUNNEL_TABLE = 23;
-    public static final short LFIB_TABLE = 20;
     public static final BigInteger COOKIE_VM_LFIB_TABLE = new BigInteger("8000002", 16);;
     public static final String TUNNEL_TABLE_FLOWID_PREFIX = "TUNNEL.";
     public static final BigInteger TUNNEL_TABLE_COOKIE = new BigInteger("9000000", 16);
index fe34b5a4a05b6415f8828ebfa6202742b6b96271..c3fafa07790a41890fa879ad4ffde6a524744432 100644 (file)
@@ -88,18 +88,18 @@ public class InterfaceManagerCommonUtils {
     }
     public static void makeTunnelIngressFlow(List<ListenableFuture<Void>> futures, IMdsalApiManager mdsalApiManager,
                                              IfTunnel tunnel, BigInteger dpnId, long portNo, Interface iface, int addOrRemoveFlow) {
-        String flowRef = InterfaceManagerCommonUtils.getTunnelInterfaceFlowRef(dpnId, VpnConstants.LPORT_INGRESS_TABLE, iface.getName());
+        String flowRef = InterfaceManagerCommonUtils.getTunnelInterfaceFlowRef(dpnId, NwConstants.VLAN_INTERFACE_INGRESS_TABLE, iface.getName());
         List<MatchInfo> matches = new ArrayList<MatchInfo>();
         List<InstructionInfo> mkInstructions = new ArrayList<InstructionInfo>();
         if (NwConstants.ADD_FLOW == addOrRemoveFlow) {
             matches.add(new MatchInfo(MatchFieldType.in_port, new BigInteger[] {
                     dpnId, BigInteger.valueOf(portNo) }));
-            short tableId = tunnel.getTunnelInterfaceType().isAssignableFrom(TunnelTypeMplsOverGre.class) ? IfmConstants.LFIB_TABLE :
-                    tunnel.isInternal() ? IfmConstants.INTERNAL_TUNNEL_TABLE : IfmConstants.EXTERNAL_TUNNEL_TABLE;
+            short tableId = tunnel.getTunnelInterfaceType().isAssignableFrom(TunnelTypeMplsOverGre.class) ? NwConstants.L3_LFIB_TABLE :
+                    tunnel.isInternal() ? NwConstants.INTERNAL_TUNNEL_TABLE : NwConstants.EXTERNAL_TUNNEL_TABLE;
             mkInstructions.add(new InstructionInfo(InstructionType.goto_table, new long[] {tableId}));}
 
         BigInteger COOKIE_VM_INGRESS_TABLE = new BigInteger("8000001", 16);
-        FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpnId, IfmConstants.VLAN_INTERFACE_INGRESS_TABLE, flowRef,
+        FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpnId, NwConstants.VLAN_INTERFACE_INGRESS_TABLE, flowRef,
                 IfmConstants.DEFAULT_FLOW_PRIORITY, iface.getName(), 0, 0, COOKIE_VM_INGRESS_TABLE, matches, mkInstructions);
         if (NwConstants.ADD_FLOW == addOrRemoveFlow) {
             futures.add(mdsalApiManager.installFlow(dpnId, flowEntity));
index 14070ed0c960d8e455fb574a33d24e9469322b35..b21cd15b1790164e64f790393378dfa080290efd 100644 (file)
@@ -397,8 +397,8 @@ public class InterfaceManagerRpcService implements OdlInterfaceRpcService {
     private ListenableFuture<Void> makeTerminatingServiceFlow(IfTunnel tunnelInfo, BigInteger dpnId, BigInteger tunnelKey, List<Instruction> instruction, int addOrRemove) {
         List<MatchInfo> mkMatches = new ArrayList<MatchInfo>();
         mkMatches.add(new MatchInfo(MatchFieldType.tunnel_id, new BigInteger[] {tunnelKey}));
-        short tableId = tunnelInfo.isInternal() ? IfmConstants.INTERNAL_TUNNEL_TABLE :
-                IfmConstants.EXTERNAL_TUNNEL_TABLE;
+        short tableId = tunnelInfo.isInternal() ? NwConstants.INTERNAL_TUNNEL_TABLE :
+                NwConstants.EXTERNAL_TUNNEL_TABLE;
         final String flowRef = getFlowRef(dpnId,tableId, tunnelKey);
         Flow terminatingSerFlow = MDSALUtil.buildFlowNew(tableId, flowRef,
                 5, "TST Flow Entry", 0, 0,
@@ -416,9 +416,9 @@ public class InterfaceManagerRpcService implements OdlInterfaceRpcService {
                 new long[]{0x8847L}));
         mkMatches.add(new MatchInfo(MatchFieldType.mpls_label, new String[]{Long.toString(tunnelKey.longValue())}));
         // Install the flow entry in L3_LFIB_TABLE
-        String flowRef = getFlowRef(dpnId, IfmConstants.LFIB_TABLE, tunnelKey);
+        String flowRef = getFlowRef(dpnId, NwConstants.L3_LFIB_TABLE, tunnelKey);
 
-        Flow lfibFlow = MDSALUtil.buildFlowNew(IfmConstants.LFIB_TABLE, flowRef,
+        Flow lfibFlow = MDSALUtil.buildFlowNew(NwConstants.L3_LFIB_TABLE, flowRef,
                 IfmConstants.DEFAULT_FLOW_PRIORITY, "LFIB Entry", 0, 0,
                 IfmConstants.COOKIE_VM_LFIB_TABLE, mkMatches, instruction);
         if (addOrRemove == NwConstants.ADD_FLOW) {
index e34e2b069a93d52a933e2a9a73b727994e090f5f..0e9be0533372d9cd9c9c052d230126e02fb6f4c4 100644 (file)
@@ -15,6 +15,7 @@ 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.vpnservice.mdsalutil.MatchInfo;
+import org.opendaylight.vpnservice.mdsalutil.NwConstants;
 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.Interface;
@@ -84,7 +85,7 @@ public class FlowBasedServicesConfigBindHelper {
 
             if (matches != null) {
                 FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface, boundServiceNew,
-                        transaction, matches, ifState.getIfIndex(), IfmConstants.VLAN_INTERFACE_INGRESS_TABLE);
+                        transaction, matches, ifState.getIfIndex(), NwConstants.VLAN_INTERFACE_INGRESS_TABLE);
             }
 
             if (transaction != null) {
@@ -131,7 +132,7 @@ public class FlowBasedServicesConfigBindHelper {
 
                 WriteTransaction installFlowTransaction = dataBroker.newWriteOnlyTransaction();
                 FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface, boundServiceNew, installFlowTransaction,
-                        matches, ifState.getIfIndex(), IfmConstants.VLAN_INTERFACE_INGRESS_TABLE);
+                        matches, ifState.getIfIndex(), NwConstants.VLAN_INTERFACE_INGRESS_TABLE);
                 futures.add(installFlowTransaction.submit());
             }
         }
index e18072c7164b70898f1da9482fac8c53bf677054..cd0c00d94d186675c0177b4de8b7f2c134eb18ee 100644 (file)
@@ -15,6 +15,7 @@ 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.vpnservice.mdsalutil.MatchInfo;
+import org.opendaylight.vpnservice.mdsalutil.NwConstants;
 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.Interface;
@@ -102,7 +103,7 @@ public class FlowBasedServicesConfigUnbindHelper {
         BoundServices toBeMoved = tmpServicesMap.get(highestPriority);
         FlowBasedServicesUtils.removeIngressFlow(iface, boundServiceOld, dpId, t);
         FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface, toBeMoved, t,
-                matches, ifState.getIfIndex(), IfmConstants.VLAN_INTERFACE_INGRESS_TABLE);
+                matches, ifState.getIfIndex(), NwConstants.VLAN_INTERFACE_INGRESS_TABLE);
         FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, toBeMoved, t);
 
         if (t != null) {
index b1c4d4898325500c6c2203f7dd74f75a9645ea20..25812cdf24236ae21885898364fbd9e42d79d832 100644 (file)
@@ -15,6 +15,7 @@ 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.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.iana._if.type.rev140508.L2vlan;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel;
@@ -73,7 +74,7 @@ public class FlowBasedServicesStateBindHelper {
 
         if (matches != null) {
             FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface, highestPriorityBoundService,
-                    t, matches, ifaceState.getIfIndex(), IfmConstants.VLAN_INTERFACE_INGRESS_TABLE);
+                    t, matches, ifaceState.getIfIndex(), NwConstants.VLAN_INTERFACE_INGRESS_TABLE);
         }
 
         for (BoundServices boundService : allServices) {
index bcaff79de63a9576a743178a472dd57bab00b6b1..1624b0b593caf40a1b93505cf55a401f14393d6f 100644 (file)
@@ -188,7 +188,7 @@ public class FlowBasedServicesUtils {
         Node nodeDpn = buildInventoryDpnNode(dpId);
         InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class)
                 .child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class)
-                .child(Table.class, new TableKey(IfmConstants.VLAN_INTERFACE_INGRESS_TABLE)).child(Flow.class, flowKey).build();
+                .child(Table.class, new TableKey(NwConstants.VLAN_INTERFACE_INGRESS_TABLE)).child(Flow.class, flowKey).build();
 
         t.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId);
     }
@@ -244,7 +244,7 @@ public class FlowBasedServicesUtils {
         Node nodeDpn = buildInventoryDpnNode(dpId);
         InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class)
                 .child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class)
-                .child(Table.class, new TableKey(IfmConstants.VLAN_INTERFACE_INGRESS_TABLE)).child(Flow.class, flowKey).build();
+                .child(Table.class, new TableKey(NwConstants.VLAN_INTERFACE_INGRESS_TABLE)).child(Flow.class, flowKey).build();
 
         t.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId);
     }
@@ -265,7 +265,7 @@ public class FlowBasedServicesUtils {
     }
 
     private static String getFlowRef(BigInteger dpnId, String iface, BoundServices service) {
-        return new StringBuffer().append(dpnId).append(IfmConstants.VLAN_INTERFACE_INGRESS_TABLE).append(NwConstants.FLOWID_SEPARATOR)
+        return new StringBuffer().append(dpnId).append( NwConstants.VLAN_INTERFACE_INGRESS_TABLE).append(NwConstants.FLOWID_SEPARATOR)
                 .append(iface).append(NwConstants.FLOWID_SEPARATOR).append(service.getServiceName()).append(NwConstants.FLOWID_SEPARATOR)
                 .append(service.getServicePriority()).toString();
     }
index 79ae74929df86d640787c0cc951345b9fad9ce46..ce7e9779f41d1c5300d96e2c8df6720156b3bf89 100644 (file)
@@ -17,10 +17,7 @@ import org.opendaylight.vpnservice.interfacemgr.IfmConstants;
 import org.opendaylight.vpnservice.interfacemgr.IfmUtil;
 import org.opendaylight.vpnservice.interfacemgr.servicebindings.flowbased.statehelpers.FlowBasedServicesStateBindHelper;
 import org.opendaylight.vpnservice.interfacemgr.servicebindings.flowbased.statehelpers.FlowBasedServicesStateUnbindHelper;
-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.*;
 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.ietf.interfaces.rev140508.interfaces.Interface;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus;
@@ -104,7 +101,7 @@ public class FlowBasedServicesStateConfigurationTest {
                 .setLowerLayerIf(lowerLayerIfList)
                 .setKey(IfmUtil.getStateInterfaceKeyFromName(InterfaceManagerTestUtil.interfaceName))
                 .setName(InterfaceManagerTestUtil.interfaceName);
-        stypeOpenflow = InterfaceManagerTestUtil.buildStypeOpenflow(dpId,flowpriority, IfmConstants.VLAN_INTERFACE_INGRESS_TABLE, instructions);
+        stypeOpenflow = InterfaceManagerTestUtil.buildStypeOpenflow(dpId,flowpriority, NwConstants.VLAN_INTERFACE_INGRESS_TABLE, instructions);
         instructionKey = new InstructionKey(instructionKeyval);
         BigInteger[] metadataValues = IfmUtil.mergeOpenflowMetadataWriteInstructions(instructions);
         boundService = InterfaceManagerTestUtil.buildBoundServices(serviceName,key,new BoundServicesKey(key),stypeOpenflow);
index 497d089b9e0a2a1b18e2fa7e74262c10ee39b6b9..89d7db18a4b3e0d8ab75f0dad761d2052778a22a 100644 (file)
@@ -217,7 +217,7 @@ public class InterfaceManagerTestUtil {
 
     public static String buildflowRef(BigInteger dpId,String servicaName,String boundServicename, short servicePriority)
     {
-        String flowRef = new StringBuffer().append(dpId).append(IfmConstants.VLAN_INTERFACE_INGRESS_TABLE).append(NwConstants.FLOWID_SEPARATOR).
+        String flowRef = new StringBuffer().append(dpId).append(NwConstants.VLAN_INTERFACE_INGRESS_TABLE).append(NwConstants.FLOWID_SEPARATOR).
                 append(servicaName).append(NwConstants.FLOWID_SEPARATOR).append(boundServicename).
                 append(NwConstants.FLOWID_SEPARATOR).append(servicePriority).toString();
         return flowRef;
diff --git a/itm/itm-api/.gitignore b/itm/itm-api/.gitignore
new file mode 100644 (file)
index 0000000..b49c563
--- /dev/null
@@ -0,0 +1,4 @@
+/target/
+/target/
+/target/
+/target/
index 11c6204173f0229fb5ab53343a74caa63ab85c8c..88cf81df95746e26542271b9e45661be9c0fc347 100644 (file)
@@ -11,6 +11,10 @@ import java.math.BigInteger;
 
 
 public class ITMConstants{
-    public static final short INTERNAL_TUNNEL_TABLE = 22;
-    public static final BigInteger COOKIE_ITM = new BigInteger("9000000", 16);
+  public static final BigInteger COOKIE_ITM = new BigInteger("9000000", 16);
+  public static final String ITM_IDPOOL_NAME = "Itmservices";
+  public static final long ITM_IDPOOL_START = 1L;
+  public static final String ITM_IDPOOL_SIZE = "100000";
+                
+
 }
index 69e1ea9bd8e8111ca46a19f7117f02ea7656b48d..2347e6eb055a472dedc967c4e85e9a7a82f73598 100644 (file)
@@ -47,6 +47,23 @@ module itm-rpc {
         }
     }
 
+    rpc get-internal-or-external-interface-name {
+        description "used to retrieve tunnel interface id with src Dpn and destination ip";
+            input {
+                leaf source-dpid {
+                type uint64;
+                }
+                leaf destination-ip {
+                type inet:ip-address;
+                }
+            }
+            output {
+                leaf interface-name {
+                    type string;
+                }
+        }
+    }
+
     rpc get-external-tunnel-interface-name {
         description "used to retrieve tunnel interface id between Dpns";
         input {
@@ -111,7 +128,7 @@ module itm-rpc {
         }
      }
 
-     rpc remove-external-tunnel-endpoint { 
+     rpc remove-external-tunnel-endpoint {
         description "used for building tunnels between teps on all Dpns and external node";
         input {
             leaf destination-ip {
@@ -129,7 +146,7 @@ module itm-rpc {
          description  "used for programming the terminating service actions";
          input {
              leaf dpn-id {
-               type uint64;  
+               type uint64;
              }
              leaf service-id {
                 type uint16;
@@ -142,7 +159,7 @@ module itm-rpc {
               description  "used for removing the terminating service actions";
               input {
                   leaf dpn-id {
-                    type uint64;  
+                    type uint64;
                   }
                   leaf service-id {
                      type uint16;
index ea54594c351f00b4658e850967002d6cd7b9f4f2..ca39c03eda5c66365aa14b392680a80a069cee92 100644 (file)
@@ -79,7 +79,7 @@ module itm-state {
 
 
       container tunnel-list {
-             list tunnel {
+             list internal-tunnel {
 
                key  "source-DPN destination-DPN";
 
@@ -98,7 +98,7 @@ module itm-state {
                }
              }
           }
-          
+
       container external-tunnel-list {
              list external-tunnel {
 
@@ -120,7 +120,7 @@ module itm-state {
 
              }
           }
-          
+
           notification itm-tunnel-build-complete{
           }
 
index 0e6fc4ff8d1291252b85e2a7ebf09667024efde8..ffbd3c990b0d502422029f6822a141c54d3a0422 100644 (file)
       <artifactId>itm-api</artifactId>
       <version>${vpnservices.version}</version>
     </dependency>
+    <dependency>
+       <groupId>org.opendaylight.vpnservice</groupId>
+       <artifactId>idmanager-api</artifactId>
+       <version>${vpnservices.version}</version>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.vpnservice</groupId>
       <artifactId>interfacemgr-api</artifactId>
       <groupId>commons-net</groupId>
       <artifactId>commons-net</artifactId>
     </dependency>
+        <dependency>
+            <groupId>org.opendaylight.vpnservice</groupId>
+            <artifactId>idmanager-api</artifactId>
+            <version>0.2.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.vpnservice</groupId>
+            <artifactId>idmanager-api</artifactId>
+            <version>0.2.0-SNAPSHOT</version>
+        </dependency>
     </dependencies>
   </project>
index cb0636057c2e256a34c9c015b2f9a89cec879c1c..302d1f6ef2d6b6435beadb3e4f4ca77017304c90 100644 (file)
@@ -9,8 +9,8 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
 -->
 <snapshot>
   <required-capabilities>
-      <capability>urn:opendaylight:params:xml:ns:yang:itm?module=itm&amp;revision=2015-07-01</capability>
-      <capability>urn:opendaylight:params:xml:ns:yang:itm:impl?module=itm-impl&amp;revision=2014-12-10</capability>
+      <capability>urn:opendaylight:vpnservice:itm?module=itm&amp;revision=2015-07-01</capability>
+      <capability>urn:opendaylight:vpnservice:itm:impl?module=itm-impl&amp;revision=2014-12-10</capability>
       <capability>urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding?module=opendaylight-md-sal-binding&amp;revision=2013-10-28</capability>
       <capability>urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding:impl?module=opendaylight-sal-binding-broker-impl&amp;revision=2013-10-28</capability>
       <capability>urn:opendaylight:params:xml:ns:yang:mdsalutil:api?module=odl-mdsalutil&amp;revision=2015-04-10</capability>
@@ -21,7 +21,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
     <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
       <modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
         <module>
-          <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:itm:impl">prefix:itm</type>
+          <type xmlns:prefix="urn:opendaylight:vpnservice:itm:impl">prefix:itm</type>
           <name>itm-default</name>
           <broker>
             <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-broker-osgi-registry</type>
@@ -51,7 +51,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       </modules>
       <services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
         <service>
-          <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:itm">prefix:itm</type>
+          <type xmlns:prefix="urn:opendaylight:vpnservice:itm">prefix:itm</type>
           <instance>
             <name>itm</name>
             <provider>/modules/module[type='itm'][name='itm-default']</provider>
index 2dcbfcc266d2783ff6cac497d2ee5c05e235d408..54277d4a6b5a8a7b7bea1a780d5a891b926fcf41 100644 (file)
@@ -17,6 +17,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.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.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;
@@ -48,7 +49,8 @@ public class ItmExternalTunnelAddWorker {
                 };
             };
 
-    public static List<ListenableFuture<Void>> buildTunnelsToExternalEndPoint(DataBroker dataBroker,List<DPNTEPsInfo> cfgDpnList, IpAddress extIp, Class<? extends TunnelTypeBase> tunType) {
+    public static List<ListenableFuture<Void>> buildTunnelsToExternalEndPoint(DataBroker dataBroker, IdManagerService idManagerService,
+                                                                              List<DPNTEPsInfo> cfgDpnList, IpAddress extIp, Class<? extends TunnelTypeBase> tunType) {
         List<ListenableFuture<Void>> futures = new ArrayList<>();
         WriteTransaction t = dataBroker.newWriteOnlyTransaction();
        if( null != cfgDpnList) {
@@ -56,7 +58,7 @@ public class ItmExternalTunnelAddWorker {
              // CHECK -- Assumption -- Only one End Point / Dpn for GRE/Vxlan Tunnels
               TunnelEndPoints firstEndPt = teps.getTunnelEndPoints().get(0) ;
               String interfaceName = firstEndPt.getInterfaceName() ;
-              String trunkInterfaceName = ItmUtils.getTrunkInterfaceName(interfaceName, firstEndPt.getIpAddress().getIpv4Address().getValue(), extIp.getIpv4Address().getValue()) ;
+              String trunkInterfaceName = ItmUtils.getTrunkInterfaceName(idManagerService, interfaceName, firstEndPt.getIpAddress().getIpv4Address().getValue(), extIp.getIpv4Address().getValue()) ;
               char[] subnetMaskArray = firstEndPt.getSubnetMask().getValue() ;
               String subnetMaskStr = String.valueOf(subnetMaskArray) ;
               SubnetUtils utils = new SubnetUtils(subnetMaskStr);
@@ -64,42 +66,29 @@ public class ItmExternalTunnelAddWorker {
               IpAddress gwyIpAddress = (utils.getInfo().isInRange(dcGwyIpStr) ) ? null : firstEndPt.getGwIpAddress() ;
               String ifDescription = tunType.getName();
               logger.debug(  " Creating Trunk Interface with parameters trunk I/f Name - {}, parent I/f name - {}, source IP - {}, DC Gateway IP - {} gateway IP - {}",trunkInterfaceName, interfaceName, firstEndPt.getIpAddress(), extIp, gwyIpAddress ) ;
-              Interface iface = ItmUtils.buildTunnelInterface(teps.getDPNID(), trunkInterfaceName, String.format( "%s %s",ifDescription, "Trunk Interface"), true, tunType, firstEndPt.getIpAddress(), extIp, gwyIpAddress) ;
+              Interface iface = ItmUtils.buildTunnelInterface(teps.getDPNID(), trunkInterfaceName, String.format( "%s %s",ifDescription, "Trunk Interface"), true, tunType, firstEndPt.getIpAddress(), extIp, gwyIpAddress, false) ;
               logger.debug(  " Trunk Interface builder - {} ", iface ) ;
               InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkInterfaceName);
               logger.debug(  " Trunk Interface Identifier - {} ", trunkIdentifier ) ;
               logger.trace(  " Writing Trunk Interface to Config DS {}, {} ", trunkIdentifier, iface ) ;
-              //ItmUtils.asyncUpdate(LogicalDatastoreType.CONFIGURATION,trunkIdentifier, iface , dataBroker, ItmUtils.DEFAULT_CALLBACK);
               t.merge(LogicalDatastoreType.CONFIGURATION, trunkIdentifier, iface, true);
-       //       update_external_tunnels_ds(teps.getDPNID(), extIp, trunkInterfaceName, tunType);
+              // update external_tunnel_list ds  
               InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(
                       ExternalTunnelList.class)
-                          .child(ExternalTunnel.class, new ExternalTunnelKey(extIp, teps.getDPNID()));   
-              ExternalTunnel tnl = new ExternalTunnelBuilder().setKey(new ExternalTunnelKey(extIp, teps.getDPNID()))
-                                             .setDestinationIP(extIp)
-                                             .setSourceDPN(teps.getDPNID())
-                                             .setTunnelInterfaceName(trunkInterfaceName).build();
-              ItmUtils.asyncUpdate(LogicalDatastoreType.CONFIGURATION, path, tnl, dataBroker, DEFAULT_CALLBACK);
+                          .child(ExternalTunnel.class, new ExternalTunnelKey(extIp, teps.getDPNID()));
+              ExternalTunnel tnl = ItmUtils.buildExternalTunnel(teps.getDPNID(), extIp, trunkInterfaceName);
+              t.merge(LogicalDatastoreType.CONFIGURATION,path, tnl, true) ;
           }
           futures.add( t.submit()) ;
        }
         return futures ;
     }
 
-    public static List<ListenableFuture<Void>> buildTunnelsFromDpnToExternalEndPoint(DataBroker dataBroker, List<BigInteger> dpnId, IpAddress extIp, Class<? extends TunnelTypeBase> tunType) {
+    public static List<ListenableFuture<Void>> buildTunnelsFromDpnToExternalEndPoint(DataBroker dataBroker, IdManagerService idManagerService,
+                                                                                     List<BigInteger> dpnId, IpAddress extIp, Class<? extends TunnelTypeBase> tunType) {
         List<ListenableFuture<Void>> futures = new ArrayList<>();
-        List<DPNTEPsInfo> cfgDpnList = new ArrayList<DPNTEPsInfo>() ;
-        List<DPNTEPsInfo> meshedDpnList = ItmUtils.getTunnelMeshInfo(dataBroker) ;
-        if( null != meshedDpnList) {
-          for (BigInteger dpn : dpnId){
-                 for( DPNTEPsInfo teps : meshedDpnList ) {
-                     if( teps.getDPNID().equals(dpn)) {
-                        cfgDpnList.add(teps) ;
-                     }
-                  }
-          }
-          futures = buildTunnelsToExternalEndPoint( dataBroker, cfgDpnList, extIp, tunType) ;
-       }
+        List<DPNTEPsInfo> cfgDpnList =( dpnId == null ) ? ItmUtils.getTunnelMeshInfo(dataBroker) :ItmUtils.getDPNTEPListFromDPNId(dataBroker, dpnId) ;
+          futures = buildTunnelsToExternalEndPoint( dataBroker, idManagerService, cfgDpnList, extIp, tunType) ;
         return futures ;
     }
 }
index 50a036c09357391435eed063c0095d9b27f27f89..81f6aaefbe0a6bbd8fd36c7b98bc715e26b1a961 100644 (file)
@@ -16,8 +16,13 @@ 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.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.interfacemgr.rev150331.TunnelTypeBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.ExternalTunnelList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.DPNTEPsInfo;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.dpn.teps.info.TunnelEndPoints;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnelKey;
+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;
@@ -27,7 +32,7 @@ import com.google.common.util.concurrent.ListenableFuture;
 public class ItmExternalTunnelDeleteWorker {
     private static final Logger logger = LoggerFactory.getLogger(ItmExternalTunnelDeleteWorker.class ) ;
 
-    public static List<ListenableFuture<Void>> deleteTunnels(DataBroker dataBroker, List<DPNTEPsInfo> dpnTepsList,IpAddress extIp ) {
+    public static List<ListenableFuture<Void>> deleteTunnels(DataBroker dataBroker, IdManagerService idManagerService, List<DPNTEPsInfo> dpnTepsList,IpAddress extIp, Class<? extends TunnelTypeBase> tunType ) {
         logger.trace( " Delete Tunnels towards DC Gateway with Ip  {}", extIp ) ;
         List<ListenableFuture<Void>> futures = new ArrayList<>();
         WriteTransaction t = dataBroker.newWriteOnlyTransaction();
@@ -38,10 +43,19 @@ public class ItmExternalTunnelDeleteWorker {
             }
             for( DPNTEPsInfo teps : dpnTepsList) {
                 TunnelEndPoints firstEndPt = teps.getTunnelEndPoints().get(0) ;
-                String interfaceName = firstEndPt.getInterfaceName() ;
-                String trunkInterfaceName = ItmUtils.getTrunkInterfaceName(interfaceName, firstEndPt.getIpAddress().getIpv4Address().getValue(), extIp.getIpv4Address().getValue()) ;
-                InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkInterfaceName);
-                t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
+                if( firstEndPt.getTunnelType().equals(tunType)) {
+                    String interfaceName = firstEndPt.getInterfaceName() ;
+                    String trunkInterfaceName = ItmUtils.getTrunkInterfaceName(idManagerService, interfaceName,firstEndPt.getIpAddress().getIpv4Address().getValue(), extIp.getIpv4Address().getValue()) ;
+                    InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkInterfaceName);
+                    t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
+
+                    InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(
+                            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);
+                }
             }
             futures.add(t.submit()) ;
         return futures ;
index 8e62b9c9e9b95a0816539bef9a04ae1577802a11..bde34d017104f5c85d67f14b71542f2bf87c5fb8 100644 (file)
@@ -20,6 +20,7 @@ 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.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;
@@ -32,9 +33,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnel;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnelBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnelKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.Tunnel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.TunnelBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.TunnelKey;
+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.InternalTunnelKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.slf4j.Logger;
@@ -54,7 +54,8 @@ public class ItmInternalTunnelAddWorker {
              };
 
 
-    public static List<ListenableFuture<Void>> build_all_tunnels(DataBroker dataBroker, List<DPNTEPsInfo> cfgdDpnList, List<DPNTEPsInfo> meshedDpnList) {
+    public static List<ListenableFuture<Void>> build_all_tunnels(DataBroker dataBroker, IdManagerService idManagerService,
+                                                                 List<DPNTEPsInfo> cfgdDpnList, List<DPNTEPsInfo> meshedDpnList) {
         logger.trace( "Building tunnels with DPN List {} " , cfgdDpnList );
         List<ListenableFuture<Void>> futures = new ArrayList<>();
         WriteTransaction t = dataBroker.newWriteOnlyTransaction();
@@ -65,7 +66,7 @@ public class ItmInternalTunnelAddWorker {
 
         for( DPNTEPsInfo dpn : cfgdDpnList) {
             //#####if dpn is not in meshedDpnList
-            build_tunnel_from(dpn, meshedDpnList, dataBroker, t, futures);
+            build_tunnel_from(dpn, meshedDpnList, dataBroker, idManagerService, t, futures);
             if(null == meshedDpnList) {
                 meshedDpnList = new ArrayList<DPNTEPsInfo>() ;
             }
@@ -86,7 +87,7 @@ public class ItmInternalTunnelAddWorker {
         t.merge(LogicalDatastoreType.CONFIGURATION, dep, tnlBuilder, true);
     }
 
-    private static void build_tunnel_from( DPNTEPsInfo srcDpn,List<DPNTEPsInfo> meshedDpnList, DataBroker dataBroker,  WriteTransaction t, List<ListenableFuture<Void>> futures) {
+    private static void build_tunnel_from( DPNTEPsInfo srcDpn,List<DPNTEPsInfo> meshedDpnList, DataBroker dataBroker,  IdManagerService idManagerService, WriteTransaction t, List<ListenableFuture<Void>> futures) {
         logger.trace( "Building tunnels from DPN {} " , srcDpn );
 
         if( null == meshedDpnList || 0 == meshedDpnList.size()) {
@@ -95,12 +96,13 @@ public class ItmInternalTunnelAddWorker {
         }
         for( DPNTEPsInfo dstDpn: meshedDpnList) {
             if ( ! srcDpn.equals(dstDpn) )
-                    wireUpWithinTransportZone(srcDpn, dstDpn, dataBroker, t, futures) ;
+                    wireUpWithinTransportZone(srcDpn, dstDpn, dataBroker, idManagerService, t, futures) ;
         }
 
    }
 
-    private static void wireUpWithinTransportZone( DPNTEPsInfo srcDpn, DPNTEPsInfo dstDpn, DataBroker dataBroker,  WriteTransaction t, List<ListenableFuture<Void>> futures) {
+    private static void wireUpWithinTransportZone( DPNTEPsInfo srcDpn, DPNTEPsInfo dstDpn, DataBroker dataBroker,
+                                                   IdManagerService idManagerService, 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();
@@ -111,7 +113,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, t, futures );
+                     wireUpBidirectionalTunnel( srcte, dstte, srcDpn.getDPNID(), dstDpn.getDPNID(), dataBroker, idManagerService, t, futures );
                      // CHECK THIS -- Assumption -- One end point per Dpn per transport zone
                      break ;
                 }
@@ -121,47 +123,45 @@ public class ItmInternalTunnelAddWorker {
     }
 
     private static void wireUpBidirectionalTunnel( TunnelEndPoints srcte, TunnelEndPoints dstte, BigInteger srcDpnId, BigInteger dstDpnId,
-        DataBroker dataBroker,  WriteTransaction t, List<ListenableFuture<Void>> futures) {
+        DataBroker dataBroker,  IdManagerService idManagerService, WriteTransaction t, List<ListenableFuture<Void>> futures) {
        // Setup the flow for LLDP monitoring -- PUNT TO CONTROLLER
        //  setUpOrRemoveTerminatingServiceTable(srcDpnId, true);
        //  setUpOrRemoveTerminatingServiceTable(dstDpnId, true);
 
         // Create the forward direction tunnel
-        if(!wireUp( srcte, dstte, srcDpnId, dstDpnId, dataBroker, t, futures ))
+        if(!wireUp( srcte, dstte, srcDpnId, dstDpnId, dataBroker, idManagerService, t, futures ))
            logger.error("Could not build tunnel between end points {}, {} " , srcte, dstte );
 
         // CHECK IF FORWARD IS NOT BUILT , REVERSE CAN BE BUILT
       // Create the tunnel for the reverse direction
-       if(! wireUp( dstte, srcte, dstDpnId, srcDpnId, dataBroker, t, futures ))
+       if(! wireUp( dstte, srcte, dstDpnId, srcDpnId, dataBroker, idManagerService, t, futures ))
           logger.error("Could not build tunnel between end points {}, {} " , dstte, srcte);
     }
 
-    private static boolean wireUp( TunnelEndPoints srcte, TunnelEndPoints dstte, BigInteger srcDpnId, BigInteger dstDpnId ,
-          DataBroker dataBroker,  WriteTransaction t, List<ListenableFuture<Void>> futures) {
+    private static boolean wireUp(TunnelEndPoints srcte, TunnelEndPoints dstte, BigInteger srcDpnId, BigInteger dstDpnId ,
+                                  DataBroker dataBroker, IdManagerService idManagerService, WriteTransaction t, List<ListenableFuture<Void>> futures) {
         // Wire Up logic
         logger.trace( "Wiring between source tunnel end points {}, destination tunnel end points {} " , srcte, dstte );
         String interfaceName = srcte.getInterfaceName() ;
         Class<? extends TunnelTypeBase> tunType = srcte.getTunnelType();
         String ifDescription = srcte.getTunnelType().getName();
         // Form the trunk Interface Name
-        String trunkInterfaceName = ItmUtils.getTrunkInterfaceName(interfaceName,srcte.getIpAddress().getIpv4Address().getValue(), dstte.getIpAddress().getIpv4Address().getValue()) ;
+        String trunkInterfaceName = ItmUtils.getTrunkInterfaceName(idManagerService, interfaceName,srcte.getIpAddress().getIpv4Address().getValue(), dstte.getIpAddress().getIpv4Address().getValue()) ;
         IpAddress gwyIpAddress = ( srcte.getSubnetMask().equals(dstte.getSubnetMask()) ) ? null : srcte.getGwIpAddress() ;
         logger.debug(  " Creating Trunk Interface with parameters trunk I/f Name - {}, parent I/f name - {}, source IP - {}, destination IP - {} gateway IP - {}",trunkInterfaceName, interfaceName, srcte.getIpAddress(), dstte.getIpAddress(), gwyIpAddress ) ;
-        Interface iface = ItmUtils.buildTunnelInterface(srcDpnId, trunkInterfaceName, String.format( "%s %s",ifDescription, "Trunk Interface"), true, tunType, srcte.getIpAddress(), dstte.getIpAddress(), gwyIpAddress) ;
+        Interface iface = ItmUtils.buildTunnelInterface(srcDpnId, trunkInterfaceName, String.format( "%s %s",ifDescription, "Trunk Interface"), true, tunType, srcte.getIpAddress(), dstte.getIpAddress(), gwyIpAddress, true) ;
         logger.debug(  " Trunk Interface builder - {} ", iface ) ;
         InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkInterfaceName);
         logger.debug(  " Trunk Interface Identifier - {} ", trunkIdentifier ) ;
         logger.trace(  " Writing Trunk Interface to Config DS {}, {} ", trunkIdentifier, iface ) ;
         t.merge(LogicalDatastoreType.CONFIGURATION, trunkIdentifier, iface, true);
         // also update itm-state ds?
-        InstanceIdentifier<Tunnel> path = InstanceIdentifier.create(
+        InstanceIdentifier<InternalTunnel> path = InstanceIdentifier.create(
                 TunnelList.class)
-                    .child(Tunnel.class, new TunnelKey(dstDpnId, srcDpnId));   
-        Tunnel tnl = new TunnelBuilder().setKey(new TunnelKey(dstDpnId, srcDpnId))
-                                       .setDestinationDPN(dstDpnId)
-                                       .setSourceDPN(srcDpnId)
-                                       .setTunnelInterfaceName(trunkInterfaceName).build();
-        ItmUtils.asyncUpdate(LogicalDatastoreType.CONFIGURATION, path, tnl, dataBroker, DEFAULT_CALLBACK);
+                    .child(InternalTunnel.class, new InternalTunnelKey( srcDpnId, dstDpnId));   
+        InternalTunnel tnl = ItmUtils.buildInternalTunnel(srcDpnId, dstDpnId, trunkInterfaceName);
+        //ItmUtils.asyncUpdate(LogicalDatastoreType.CONFIGURATION, path, tnl, dataBroker, DEFAULT_CALLBACK);
+        t.merge(LogicalDatastoreType.CONFIGURATION,path, tnl, true) ;
         return true;
     }
 
index a6d3d47f418ebed058747341e17da0fe5e402f04..096d81cffdec780ed96d74ee54cc12be3022ffa4 100644 (file)
@@ -17,9 +17,13 @@ import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 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.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;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.dpn.teps.info.TunnelEndPoints;
+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.InternalTunnelKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -30,7 +34,8 @@ 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, List<DPNTEPsInfo> dpnTepsList, List<DPNTEPsInfo> meshedDpnList)
+    public static List<ListenableFuture<Void>> deleteTunnels(DataBroker dataBroker, IdManagerService idManagerService,
+                                                             List<DPNTEPsInfo> dpnTepsList, List<DPNTEPsInfo> meshedDpnList)
     {
         List<ListenableFuture<Void>> futures = new ArrayList<>();
         WriteTransaction t = dataBroker.newWriteOnlyTransaction();
@@ -58,7 +63,7 @@ public class ItmInternalTunnelDeleteWorker {
                                 if (dstTep.getTransportZone().equals(srcTZone)) {
                                     // remove all trunk interfaces
                                     logger.trace("Invoking removeTrunkInterface between source TEP {} , Destination TEP {} " ,srcTep , dstTep);
-                                    removeTrunkInterface(dataBroker, srcTep, dstTep, srcDpn.getDPNID(), dstDpn.getDPNID(), t, futures);
+                                    removeTrunkInterface(dataBroker, idManagerService, srcTep, dstTep, srcDpn.getDPNID(), dstDpn.getDPNID(), t, futures);
                                 }
                             }
                         }
@@ -108,23 +113,42 @@ public class ItmInternalTunnelDeleteWorker {
         return futures ;
     }
 
-    private static void removeTrunkInterface(DataBroker dataBroker, TunnelEndPoints srcTep, TunnelEndPoints dstTep, BigInteger srcDpnId, BigInteger dstDpnId,
-        WriteTransaction t, List<ListenableFuture<Void>> futures) {
+    private static void removeTrunkInterface(DataBroker dataBroker, IdManagerService idManagerService,
+                                             TunnelEndPoints srcTep, TunnelEndPoints dstTep, BigInteger srcDpnId, BigInteger dstDpnId,
+                                             WriteTransaction t, List<ListenableFuture<Void>> futures) {
         String trunkfwdIfName =
-                        ItmUtils.getTrunkInterfaceName(srcTep.getInterfaceName(), srcTep.getIpAddress()
+                        ItmUtils.getTrunkInterfaceName(idManagerService, srcTep.getInterfaceName(), srcTep.getIpAddress()
                                         .getIpv4Address().getValue(), dstTep.getIpAddress().getIpv4Address()
                                         .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 ) ;
         t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
+
+        // also update itm-state ds -- Delete the forward tunnel-interface from the tunnel list
+        InstanceIdentifier<InternalTunnel> path = InstanceIdentifier.create(
+                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);
+
         String trunkRevIfName =
-                        ItmUtils.getTrunkInterfaceName(dstTep.getInterfaceName(), dstTep.getIpAddress()
+                        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 ) ;
         t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
+
+     // also update itm-state ds -- Delete the reverse tunnel-interface from the tunnel list
+        path = InstanceIdentifier.create(
+                TunnelList.class)
+                    .child(InternalTunnel.class, new InternalTunnelKey(dstDpnId, srcDpnId));   
+        t.delete(LogicalDatastoreType.CONFIGURATION,path) ;
+        
+        // Release the Id for the Reverse trunk
+        ItmUtils.releaseId(idManagerService, trunkRevIfName);
     }
 }
index e6dc9987cb280432e6aada9f121ed96d3dcc5e12..92c17e06e4d9f039cdc6397259fbbdcda0ed45bc 100644 (file)
@@ -15,6 +15,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.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.DPNTEPsInfo;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
@@ -22,12 +23,14 @@ import org.slf4j.Logger;
 public class ItmTepAddWorker implements Callable<List<ListenableFuture<Void>>> {
     private static final Logger logger = LoggerFactory.getLogger(ItmTepAddWorker.class ) ;
     private DataBroker dataBroker;
+    private IdManagerService idManagerService;
     private List<DPNTEPsInfo> meshedDpnList;
     private List<DPNTEPsInfo> cfgdDpnList ;
 
-    public ItmTepAddWorker( List<DPNTEPsInfo> cfgdDpnList,  DataBroker broker) {
+    public ItmTepAddWorker( List<DPNTEPsInfo> cfgdDpnList,  DataBroker broker, IdManagerService idManagerService) {
         this.cfgdDpnList = cfgdDpnList ;
         this.dataBroker = broker ;
+        this.idManagerService = idManagerService;
         logger.trace("ItmTepAddWorker initialized with  DpnList {}",cfgdDpnList );
     }
 
@@ -36,7 +39,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, cfgdDpnList, meshedDpnList) ) ;
+        futures.addAll( ItmInternalTunnelAddWorker.build_all_tunnels(dataBroker, idManagerService, 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 66ca75029a7188701a38c87c7cc53ca8fb53032b..6c4cb00810ca73fd6b74500778c43ddfead19b1b 100644 (file)
@@ -15,6 +15,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.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.DPNTEPsInfo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -24,10 +25,12 @@ public class ItmTepRemoveWorker implements Callable<List<ListenableFuture<Void>>
     private DataBroker dataBroker;
     private List<DPNTEPsInfo> delDpnList ;
     private List<DPNTEPsInfo> meshedDpnList ;
+    private IdManagerService idManagerService;
 
-    public ItmTepRemoveWorker( List<DPNTEPsInfo> delDpnList,  DataBroker broker) {
+    public ItmTepRemoveWorker( List<DPNTEPsInfo> delDpnList,  DataBroker broker, IdManagerService idManagerService) {
         this.delDpnList = delDpnList ;
         this.dataBroker = broker ;
+        this.idManagerService = idManagerService;
         logger.trace("ItmTepRemoveWorker initialized with  DpnList {}",delDpnList );
     }
 
@@ -35,7 +38,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, delDpnList, meshedDpnList));
+        futures.addAll( ItmInternalTunnelDeleteWorker.deleteTunnels(dataBroker, idManagerService, 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 b805a629c9bc6b3546a2c226225f26e16f957da9..1a4c02961f0f1ffc4df07d779646b3a8ea2825df 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.vpnservice.itm.impl;
 
 import java.math.BigInteger;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -21,9 +22,13 @@ import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
 import org.opendaylight.vpnservice.itm.api.IITMProvider;
+import org.opendaylight.vpnservice.itm.globals.ITMConstants;
 import org.opendaylight.vpnservice.itm.listeners.TransportZoneListener;
 import org.opendaylight.vpnservice.itm.rpc.ItmManagerRpcService;
 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
+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.OdlInterfaceRpcService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.ItmRpcService;
 
@@ -40,6 +45,7 @@ public class ItmProvider implements BindingAwareProvider, AutoCloseable, IITMPro
     private DataBroker dataBroker;
     private NotificationPublishService notificationPublishService;
     private ItmManagerRpcService itmRpcService ;
+    private IdManagerService idManager;
     private NotificationService notificationService;
     private TransportZoneListener tzChangeListener;
     private RpcProviderRegistry rpcProviderRegistry;
@@ -57,10 +63,11 @@ public class ItmProvider implements BindingAwareProvider, AutoCloseable, IITMPro
         LOG.info("ItmProvider Session Initiated");
         try {
             dataBroker = session.getSALService(DataBroker.class);
+            idManager = getRpcProviderRegistry().getRpcService(IdManagerService.class);
 
             itmManager = new ITMManager(dataBroker);
-            tzChangeListener = new TransportZoneListener(dataBroker) ;
-            itmRpcService = new ItmManagerRpcService(dataBroker);
+            tzChangeListener = new TransportZoneListener(dataBroker, idManager) ;
+            itmRpcService = new ItmManagerRpcService(dataBroker, idManager);
             final BindingAwareBroker.RpcRegistration<ItmRpcService> rpcRegistration = getRpcProviderRegistry().addRpcImplementation(ItmRpcService.class, itmRpcService);
             itmRpcService.setMdsalManager(mdsalManager);
             itmManager.setMdsalManager(mdsalManager);
@@ -68,6 +75,7 @@ public class ItmProvider implements BindingAwareProvider, AutoCloseable, IITMPro
             itmManager.setMdsalManager(mdsalManager);
             tzChangeListener.setItmManager(itmManager);
             tzChangeListener.registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
+            createIdPool();
         } catch (Exception e) {
             LOG.error("Error initializing services", e);
         }
@@ -100,5 +108,19 @@ public class ItmProvider implements BindingAwareProvider, AutoCloseable, IITMPro
         LOG.info("ItmProvider Closed");
     }
 
-
+    private void createIdPool() {
+        CreateIdPoolInput createPool = new CreateIdPoolInputBuilder()
+            .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
+            .setLow(ITMConstants.ITM_IDPOOL_START)
+            .setHigh(new BigInteger(ITMConstants.ITM_IDPOOL_SIZE).longValue())
+            .build();
+        try {
+            Future<RpcResult<Void>> result = idManager.createIdPool(createPool);
+            if ((result != null) && (result.get().isSuccessful())) {
+                LOG.debug("Created IdPool for ITM Service");
+            }
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("Failed to create idPool for ITM Service",e);
+        }
+    }
 }
index f156715ace514081dfb146bdf146b7cc7f82b9da..0750ea479213dc7f63648f453a25b4f7aa7fc320 100644 (file)
@@ -12,6 +12,8 @@ import java.net.InetAddress;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
 
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.net.util.SubnetUtils;
@@ -23,6 +25,12 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
 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.iana._if.type.rev140508.Tunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.AllocateIdInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.AllocateIdInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.AllocateIdOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.ReleaseIdInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.ReleaseIdInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.*;
 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.DpnEndpointsBuilder;
@@ -32,6 +40,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.dpn.teps.info.TunnelEndPoints;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.dpn.teps.info.TunnelEndPointsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.dpn.teps.info.TunnelEndPointsKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnelBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnelKey;
+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.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;
@@ -44,6 +58,7 @@ 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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
+import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -58,6 +73,7 @@ public class ItmUtils {
     public static final String DUMMY_IP_ADDRESS = "0.0.0.0";
     public static final String TUNNEL_TYPE_VXLAN = "VXLAN";
     public static final String TUNNEL_TYPE_GRE = "GRE";
+    public static final String TUNNEL = "TUNNEL";
 
     private static final Logger LOG = LoggerFactory.getLogger(ItmUtils.class);
 
@@ -117,8 +133,9 @@ public class ItmUtils {
         return dpnId;
     }
 
-    public static String getTrunkInterfaceName(String parentInterfaceName, String localHostName, String remoteHostName) {
+    public static String getTrunkInterfaceName(IdManagerService idManager, String parentInterfaceName, String localHostName, String remoteHostName) {
         String trunkInterfaceName = String.format("%s:%s:%s", parentInterfaceName, localHostName, remoteHostName);
+        trunkInterfaceName = String.format("%s:%s", TUNNEL, getUniqueId(idManager, trunkInterfaceName));
         return trunkInterfaceName;
     }
 
@@ -158,17 +175,30 @@ public class ItmUtils {
     }
 
     public static Interface buildTunnelInterface(BigInteger dpn, String ifName, String desc, boolean enabled, Class<? extends TunnelTypeBase> tunType,
-       IpAddress localIp, IpAddress remoteIp, IpAddress gatewayIp) {
+       IpAddress localIp, IpAddress remoteIp, IpAddress gatewayIp, boolean internal) {
        InterfaceBuilder builder = new InterfaceBuilder().setKey(new InterfaceKey(ifName)).setName(ifName)
        .setDescription(desc).setEnabled(enabled).setType(Tunnel.class);
        ParentRefs parentRefs = new ParentRefsBuilder().setDatapathNodeIdentifier(dpn).build();
        builder.addAugmentation(ParentRefs.class, parentRefs);
        IfTunnel tunnel = new IfTunnelBuilder().setTunnelDestination(remoteIp).setTunnelGateway(gatewayIp).setTunnelSource(localIp)
-       .setTunnelInterfaceType( tunType).build();
+       .setTunnelInterfaceType( tunType).setInternal(internal).build();
        builder.addAugmentation(IfTunnel.class, tunnel);
        return builder.build();
     }
 
+    public static InternalTunnel buildInternalTunnel( BigInteger srcDpnId, BigInteger dstDpnId, String trunkInterfaceName) {
+        InternalTunnel tnl = new InternalTunnelBuilder().setKey(new InternalTunnelKey(srcDpnId, dstDpnId))
+            .setDestinationDPN(dstDpnId)
+            .setSourceDPN(srcDpnId)
+            .setTunnelInterfaceName(trunkInterfaceName).build();
+        return tnl ;
+    }
+
+    public static ExternalTunnel buildExternalTunnel( BigInteger srcDpnId, IpAddress dstIp, String trunkInterfaceName) {
+        ExternalTunnel extTnl = new ExternalTunnelBuilder().setKey(new ExternalTunnelKey(dstIp, srcDpnId)).setSourceDPN(srcDpnId).setDestinationIP(dstIp).setTunnelInterfaceName(trunkInterfaceName).build();
+        return extTnl ;
+    }
+
     public static List<DPNTEPsInfo> getTunnelMeshInfo(DataBroker dataBroker) {
         List<DPNTEPsInfo> dpnTEPs= null ;
 
@@ -184,4 +214,50 @@ public class ItmUtils {
             LOG.debug( "No Dpn information in CONFIGURATION datastore "  );
          return dpnTEPs ;
     }
+
+    public static int getUniqueId(IdManagerService idManager, String idKey) {
+        AllocateIdInput getIdInput = new AllocateIdInputBuilder()
+            .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
+            .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 0;
+    }
+
+    public static void releaseId(IdManagerService idManager, String idKey) {
+        ReleaseIdInput idInput = new ReleaseIdInputBuilder().setPoolName(ITMConstants.ITM_IDPOOL_NAME).setIdKey(idKey).build();
+        try {
+            Future<RpcResult<Void>> result = idManager.releaseId(idInput);
+            RpcResult<Void> rpcResult = result.get();
+            if(!rpcResult.isSuccessful()) {
+                LOG.warn("RPC Call to Get Unique Id returned with Errors {}", rpcResult.getErrors());
+            }
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.warn("Exception when getting Unique Id for key {}", idKey, e);
+        }
+    }
+
+    public static List<DPNTEPsInfo> getDPNTEPListFromDPNId(DataBroker dataBroker, List<BigInteger> dpnIds) {
+        List<DPNTEPsInfo> meshedDpnList = getTunnelMeshInfo(dataBroker) ;
+        List<DPNTEPsInfo> cfgDpnList = new ArrayList<DPNTEPsInfo>();
+        if( null != meshedDpnList) {
+           for(BigInteger dpnId : dpnIds) {
+              for( DPNTEPsInfo teps : meshedDpnList ) {
+                 if( dpnId.equals(teps.getDPNID()))
+                 cfgDpnList.add( teps) ;
+              }
+            }
+        }
+        return cfgDpnList;
+    }
 }
index 3af1659aab01cbcb8d8dfb0f31f06c570f15b0f9..e60d3ee0fdde576b12fdb2fe64b6aa858f34b495 100644 (file)
@@ -24,6 +24,7 @@ import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 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.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.TunnelTypeBase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.DPNTEPsInfo;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.dpn.teps.info.TunnelEndPoints;
@@ -50,11 +51,13 @@ import org.slf4j.LoggerFactory;
 public class TransportZoneListener extends AsyncDataTreeChangeListenerBase<TransportZone, TransportZoneListener> implements AutoCloseable{
     private static final Logger LOG = LoggerFactory.getLogger(TransportZoneListener.class);
     private DataBroker dataBroker;
+    private IdManagerService idManagerService;
     private ITMManager itmManager;
 
-    public TransportZoneListener(final DataBroker dataBroker) {
+    public TransportZoneListener(final DataBroker dataBroker, final IdManagerService idManagerService) {
         super(TransportZone.class, TransportZoneListener.class);
         this.dataBroker = dataBroker;
+        this.idManagerService = idManagerService;
         initializeTZNode(dataBroker);
     }
 
@@ -103,7 +106,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);
+            ItmTepRemoveWorker removeWorker = new ItmTepRemoveWorker(opDpnList, dataBroker, idManagerService);
             coordinator.enqueueJob(tzOld.getZoneName(), removeWorker);
         }
     }
@@ -125,7 +128,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);
+          ItmTepAddWorker addWorker = new ItmTepAddWorker(opDpnList,dataBroker, idManagerService);
           coordinator.enqueueJob(tzNew.getZoneName(), addWorker);
       }
     }
index 70d8f82c45a789c7ffda0671eb23adcb01b19a6d..69aa9044e265da50b869d16d0b54579f019f52e7 100644 (file)
@@ -12,12 +12,15 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.Future;
 
+import org.opendaylight.vpnservice.mdsalutil.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
 import org.opendaylight.vpnservice.itm.confighelpers.ItmExternalTunnelAddWorker;
+import org.opendaylight.vpnservice.itm.confighelpers.ItmExternalTunnelDeleteWorker;
 import org.opendaylight.vpnservice.itm.globals.ITMConstants;
 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.vpnservice.itm.impl.ItmUtils;
@@ -26,16 +29,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.acti
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.ExternalTunnelList;
 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;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.dpn.teps.info.TunnelEndPoints;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnel;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnelKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.Tunnel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.TunnelKey;
+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.InternalTunnelKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.AddExternalTunnelEndpointInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.BuildExternalTunnelFromDpnsInput;
 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.GetExternalTunnelInterfaceNameInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetExternalTunnelInterfaceNameOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetExternalTunnelInterfaceNameOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetInternalOrExternalInterfaceNameInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetInternalOrExternalInterfaceNameOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetInternalOrExternalInterfaceNameOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetTunnelInterfaceNameInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetTunnelInterfaceNameOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetTunnelInterfaceNameOutputBuilder;
@@ -53,12 +60,6 @@ import com.google.common.util.concurrent.SettableFuture;
 
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-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.ActionInfo;
-import org.opendaylight.vpnservice.mdsalutil.ActionType;
 
 import com.google.common.base.Optional;
 
@@ -69,28 +70,33 @@ public class ItmManagerRpcService implements ItmRpcService {
    private static final Logger LOG = LoggerFactory.getLogger(ItmManagerRpcService.class);
         DataBroker dataBroker;
         private IMdsalApiManager mdsalManager;
-        public ItmManagerRpcService(DataBroker dataBroker) {
-        this.dataBroker = dataBroker;
-    }
+
 
     public void setMdsalManager(IMdsalApiManager mdsalManager) {
             this.mdsalManager = mdsalManager;
     }
 
+        IdManagerService idManagerService;
+
+        public ItmManagerRpcService(DataBroker dataBroker, IdManagerService idManagerService) {
+          this.dataBroker = dataBroker;
+          this.idManagerService = idManagerService;
+        }
+
      @Override
      public Future<RpcResult<GetTunnelInterfaceNameOutput>> getTunnelInterfaceName(GetTunnelInterfaceNameInput input) {
          RpcResultBuilder<GetTunnelInterfaceNameOutput> resultBld = null;
          BigInteger sourceDpn = input.getSourceDpid() ;
          BigInteger destinationDpn = input.getDestinationDpid() ;
-         InstanceIdentifier<Tunnel> path = InstanceIdentifier.create(
+         InstanceIdentifier<InternalTunnel> path = InstanceIdentifier.create(
                  TunnelList.class)
-                     .child(Tunnel.class, new TunnelKey(destinationDpn, sourceDpn));      
+                     .child(InternalTunnel.class, new InternalTunnelKey(destinationDpn, sourceDpn));      
          
-         Optional<Tunnel> tnl = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
+         Optional<InternalTunnel> tnl = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
 
          if( tnl != null && tnl.isPresent())
          {
-              Tunnel tunnel = tnl.get();
+              InternalTunnel tunnel = tnl.get();
               GetTunnelInterfaceNameOutputBuilder output = new GetTunnelInterfaceNameOutputBuilder() ;
               output.setInterfaceName(tunnel.getTunnelInterfaceName()) ;
               resultBld = RpcResultBuilder.success();
@@ -106,8 +112,12 @@ public class ItmManagerRpcService implements ItmRpcService {
     @Override
     public Future<RpcResult<Void>> removeExternalTunnelEndpoint(
             RemoveExternalTunnelEndpointInput input) {
-        // TODO Auto-generated method stub
-        return null;
+         //Ignore the Futures for now
+        final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
+        List<DPNTEPsInfo> meshedDpnList = ItmUtils.getTunnelMeshInfo(dataBroker) ;
+        ItmExternalTunnelDeleteWorker.deleteTunnels(dataBroker, idManagerService,meshedDpnList , input.getDestinationIp(), input.getTunnelType());
+        result.set(RpcResultBuilder.<Void>success().build());
+        return result;
     }
 
     @Override
@@ -115,7 +125,8 @@ public class ItmManagerRpcService implements ItmRpcService {
             RemoveExternalTunnelFromDpnsInput input) {
         //Ignore the Futures for now
         final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
-//        ItmExternalTunnelDeleteWorker.buildTunnelsFromDpnToExternalEndPoint(dataBroker, input.getDpnId(), null, input.getDestinationIp());
+        List<DPNTEPsInfo> cfgDpnList = ItmUtils.getDPNTEPListFromDPNId(dataBroker, input.getDpnId()) ;
+        ItmExternalTunnelDeleteWorker.deleteTunnels(dataBroker, idManagerService, cfgDpnList, input.getDestinationIp(), input.getTunnelType());
         result.set(RpcResultBuilder.<Void>success().build());
         return result;
     }
@@ -125,7 +136,7 @@ public class ItmManagerRpcService implements ItmRpcService {
             BuildExternalTunnelFromDpnsInput input) {
         //Ignore the Futures for now
         final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
-        List<ListenableFuture<Void>> extTunnelResultList = ItmExternalTunnelAddWorker.buildTunnelsFromDpnToExternalEndPoint(dataBroker, input.getDpnId(), input.getDestinationIp(), input.getTunnelType());
+        List<ListenableFuture<Void>> extTunnelResultList = ItmExternalTunnelAddWorker.buildTunnelsFromDpnToExternalEndPoint(dataBroker, idManagerService,input.getDpnId(), input.getDestinationIp(), input.getTunnelType());
         for (ListenableFuture<Void> extTunnelResult : extTunnelResultList) {
             Futures.addCallback(extTunnelResult, new FutureCallback<Void>(){
 
@@ -153,7 +164,8 @@ public class ItmManagerRpcService implements ItmRpcService {
 
         //Ignore the Futures for now
         final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
-    //    ItmExternalTunnelAddWorker.buildTunnelsToExternalEndPoint(dataBroker, null, input.getDestinationIp()) ;
+        List<DPNTEPsInfo> meshedDpnList = ItmUtils.getTunnelMeshInfo(dataBroker) ;
+        ItmExternalTunnelAddWorker.buildTunnelsToExternalEndPoint(dataBroker, idManagerService,meshedDpnList, input.getDestinationIp(), input.getTunnelType()) ;
         result.set(RpcResultBuilder.<Void>success().build());
         return result;
     }
@@ -206,8 +218,8 @@ public class ItmManagerRpcService implements ItmRpcService {
                                new BigInteger(1, vxLANHeader),
                                MetaDataUtil.METADA_MASK_VALID_TUNNEL_ID_BIT_AND_TUNNEL_ID }));
 
-       Flow terminatingServiceTableFlow = MDSALUtil.buildFlowNew(ITMConstants.INTERNAL_TUNNEL_TABLE,
-                       getFlowRef(ITMConstants.INTERNAL_TUNNEL_TABLE,serviceId), 5, String.format("%s:%d","ITM Flow Entry ",serviceId),
+       Flow terminatingServiceTableFlow = MDSALUtil.buildFlowNew(NwConstants.INTERNAL_TUNNEL_TABLE,
+                       getFlowRef(NwConstants.INTERNAL_TUNNEL_TABLE,serviceId), 5, String.format("%s:%d","ITM Flow Entry ",serviceId),
                        0, 0, ITMConstants.COOKIE_ITM.add(BigInteger.valueOf(serviceId)),mkMatches, input.getInstruction());
 
        ListenableFuture<Void> installFlowResult = mdsalManager.installFlow(input.getDpnId(), terminatingServiceTableFlow);
@@ -233,8 +245,8 @@ public class ItmManagerRpcService implements ItmRpcService {
     public Future<RpcResult<java.lang.Void>> removeTerminatingServiceActions(final RemoveTerminatingServiceActionsInput input) {
         LOG.info("remove terminatingServiceActions called with DpnId = {} and serviceId = {}", input.getDpnId(), input.getServiceId());
         final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
-        Flow terminatingServiceTableFlow = MDSALUtil.buildFlowNew(ITMConstants.INTERNAL_TUNNEL_TABLE,
-                getFlowRef(ITMConstants.INTERNAL_TUNNEL_TABLE,input.getServiceId()), 5, String.format("%s:%d","ITM Flow Entry ",input.getServiceId()),
+        Flow terminatingServiceTableFlow = MDSALUtil.buildFlowNew(NwConstants.INTERNAL_TUNNEL_TABLE,
+                getFlowRef(NwConstants.INTERNAL_TUNNEL_TABLE,input.getServiceId()), 5, String.format("%s:%d","ITM Flow Entry ",input.getServiceId()),
                 0, 0, ITMConstants.COOKIE_ITM.add(BigInteger.valueOf(input.getServiceId())),getTunnelMatchesForServiceId(input.getServiceId()), null );
 
         ListenableFuture<Void> installFlowResult = mdsalManager.installFlow(input.getDpnId(), terminatingServiceTableFlow);
@@ -282,4 +294,49 @@ public class ItmManagerRpcService implements ItmRpcService {
         return new StringBuffer().append(termSvcTable).append(svcId).toString();
     }
 
+    @Override
+    public Future<RpcResult<GetInternalOrExternalInterfaceNameOutput>> getInternalOrExternalInterfaceName(
+       GetInternalOrExternalInterfaceNameInput input) {
+       RpcResultBuilder<GetInternalOrExternalInterfaceNameOutput> resultBld = null;
+       BigInteger srcDpn = input.getSourceDpid() ;
+       IpAddress dstIp = input.getDestinationIp() ;
+       List<DPNTEPsInfo> meshedDpnList = ItmUtils.getTunnelMeshInfo(dataBroker) ;
+       // Look for external tunnels if not look for internal tunnel
+       for( DPNTEPsInfo teps : meshedDpnList) {
+           TunnelEndPoints firstEndPt = teps.getTunnelEndPoints().get(0) ;
+           if( dstIp.equals(firstEndPt.getIpAddress())) {
+              InstanceIdentifier<InternalTunnel> path = InstanceIdentifier.create(
+                       TunnelList.class)
+                           .child(InternalTunnel.class, new InternalTunnelKey(srcDpn, teps.getDPNID()));      
+               
+               Optional<InternalTunnel> tnl = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
+               if( tnl != null && tnl.isPresent())
+               {
+                    InternalTunnel tunnel = tnl.get();
+                    GetInternalOrExternalInterfaceNameOutputBuilder output = new GetInternalOrExternalInterfaceNameOutputBuilder().setInterfaceName(tunnel.getTunnelInterfaceName() );
+                    resultBld = RpcResultBuilder.success();
+                    resultBld.withResult(output.build()) ;
+               }else {
+                   //resultBld = RpcResultBuilder.failed();
+                   InstanceIdentifier<ExternalTunnel> path1 = InstanceIdentifier.create(
+                           ExternalTunnelList.class)
+                               .child(ExternalTunnel.class, new ExternalTunnelKey(dstIp, srcDpn));      
+                   
+                   Optional<ExternalTunnel> ext = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path1, dataBroker);
+
+                   if( ext != null && ext.isPresent())
+                   {
+                        ExternalTunnel extTunnel = ext.get();
+                        GetInternalOrExternalInterfaceNameOutputBuilder output = new GetInternalOrExternalInterfaceNameOutputBuilder().setInterfaceName(extTunnel.getTunnelInterfaceName() );
+                        resultBld = RpcResultBuilder.success();
+                        resultBld.withResult(output.build()) ;
+                   }else {
+                       resultBld = RpcResultBuilder.failed();
+                   }
+               }
+           }
+       }
+       return Futures.immediateFuture(resultBld.build());
+    }
+
 }
diff --git a/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/vpnservice/datastoreutils/AsyncClusteredDataChangeListenerBase.java b/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/vpnservice/datastoreutils/AsyncClusteredDataChangeListenerBase.java
new file mode 100644 (file)
index 0000000..612d72e
--- /dev/null
@@ -0,0 +1,184 @@
+/*
+ * Copyright (c) 2015 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.datastoreutils;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import org.opendaylight.controller.md.sal.binding.api.*;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+public abstract class AsyncClusteredDataChangeListenerBase<T extends DataObject, K extends ClusteredDataChangeListener> implements ClusteredDataChangeListener, AutoCloseable {
+    private static final Logger LOG = LoggerFactory.getLogger(AsyncClusteredDataChangeListenerBase.class);
+
+    private static final int DATATREE_CHANGE_HANDLER_THREAD_POOL_CORE_SIZE = 1;
+    private static final int DATATREE_CHANGE_HANDLER_THREAD_POOL_MAX_SIZE = 1;
+    private static final int DATATREE_CHANGE_HANDLER_THREAD_POOL_KEEP_ALIVE_TIME_SECS = 300;
+    private static final int STARTUP_LOOP_TICK = 500;
+    private static final int STARTUP_LOOP_MAX_RETRIES = 8;
+
+    private static ThreadPoolExecutor dataChangeHandlerExecutor = new ThreadPoolExecutor(
+            DATATREE_CHANGE_HANDLER_THREAD_POOL_CORE_SIZE,
+            DATATREE_CHANGE_HANDLER_THREAD_POOL_MAX_SIZE,
+            DATATREE_CHANGE_HANDLER_THREAD_POOL_KEEP_ALIVE_TIME_SECS,
+            TimeUnit.SECONDS,
+            new LinkedBlockingQueue<Runnable>());
+
+    private ListenerRegistration<K> listenerRegistration;
+    protected final Class<T> clazz;
+    private final Class<K> eventClazz;
+
+    /**
+     * @param clazz - for which the data change event is received
+     */
+    public AsyncClusteredDataChangeListenerBase(Class<T> clazz, Class<K> eventClazz) {
+        this.clazz = Preconditions.checkNotNull(clazz, "Class can not be null!");
+        this.eventClazz = Preconditions.checkNotNull(eventClazz, "eventClazz can not be null!");
+    }
+
+    public void registerListener(final LogicalDatastoreType dsType, final DataBroker db) {
+        try {
+            TaskRetryLooper looper = new TaskRetryLooper(STARTUP_LOOP_TICK, STARTUP_LOOP_MAX_RETRIES);
+            listenerRegistration = looper.loopUntilNoException(new Callable<ListenerRegistration<K>>() {
+                @Override
+                public ListenerRegistration call() throws Exception {
+                    return db.registerDataChangeListener(dsType, getWildCardPath(), getDataChangeListener(), getDataChangeScope());
+                }
+            });
+        } catch (final Exception e) {
+            LOG.warn("{}: Data Tree Change listener registration failed.", eventClazz.getName());
+            LOG.debug("{}: Data Tree Change listener registration failed: {}", eventClazz.getName(), e);
+            throw new IllegalStateException( eventClazz.getName() + "{}startup failed. System needs restart.", e);
+        }
+    }
+
+    @Override
+    public void onDataChanged(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changeEvent) {
+        if (changeEvent == null) {
+            return;
+        }
+
+        DataChangeHandler dataChangeHandler = new DataChangeHandler(changeEvent);
+        dataChangeHandlerExecutor.execute(dataChangeHandler);
+    }
+
+    @SuppressWarnings("unchecked")
+    private void createData(final Map<InstanceIdentifier<?>, DataObject> createdData) {
+        final Set<InstanceIdentifier<?>> keys = createdData.keySet() != null
+                ? createdData.keySet() : Collections.<InstanceIdentifier<?>>emptySet();
+        for (InstanceIdentifier<?> key : keys) {
+            if (clazz.equals(key.getTargetType())) {
+                InstanceIdentifier<T> createKeyIdent = key.firstIdentifierOf(clazz);
+                final Optional<DataObject> value = Optional.of(createdData.get(key));
+                if (value.isPresent()) {
+                    this.add(createKeyIdent, (T)value.get());
+                }
+            }
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private void updateData(final Map<InstanceIdentifier<?>, DataObject> updateData,
+                            final Map<InstanceIdentifier<?>, DataObject> originalData) {
+
+        final Set<InstanceIdentifier<?>> keys = updateData.keySet() != null
+                ? updateData.keySet() : Collections.<InstanceIdentifier<?>>emptySet();
+        for (InstanceIdentifier<?> key : keys) {
+            if (clazz.equals(key.getTargetType())) {
+                InstanceIdentifier<T> updateKeyIdent = key.firstIdentifierOf(clazz);
+                final Optional<DataObject> value = Optional.of(updateData.get(key));
+                final Optional<DataObject> original = Optional.of(originalData.get(key));
+                if (value.isPresent() && original.isPresent()) {
+                    this.update(updateKeyIdent, (T) original.get(), (T) value.get());
+                }
+            }
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private void removeData(final Set<InstanceIdentifier<?>> removeData,
+                            final Map<InstanceIdentifier<?>, DataObject> originalData) {
+
+        for (InstanceIdentifier<?> key : removeData) {
+            if (clazz.equals(key.getTargetType())) {
+                final InstanceIdentifier<T> ident = key.firstIdentifierOf(clazz);
+                final DataObject removeValue = originalData.get(key);
+                this.remove(ident, (T)removeValue);
+            }
+        }
+    }
+
+    @Override
+    public void close() throws Exception {
+        if (listenerRegistration != null) {
+            try {
+                listenerRegistration.close();
+            } catch (final Exception e) {
+                LOG.error("Error when cleaning up ClusteredDataChangeListener.", e);
+            }
+            listenerRegistration = null;
+        }
+        LOG.info("Interface Manager Closed");
+    }
+
+    protected abstract void remove(InstanceIdentifier<T> identifier, T del);
+
+    protected abstract void update(InstanceIdentifier<T> identifier, T original, T update);
+
+    protected abstract void add(InstanceIdentifier<T> identifier, T add);
+
+    protected abstract InstanceIdentifier<T> getWildCardPath();
+
+    protected abstract ClusteredDataChangeListener getDataChangeListener();
+
+    protected abstract AsyncDataBroker.DataChangeScope getDataChangeScope();
+
+    public class DataChangeHandler implements Runnable {
+        final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changeEvent;
+
+        public DataChangeHandler(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changeEvent) {
+            this.changeEvent = changeEvent;
+        }
+
+        @Override
+        public void run() {
+            Preconditions.checkNotNull(changeEvent,"Async ChangeEvent can not be null!");
+
+            /* All DataObjects for create */
+            final Map<InstanceIdentifier<?>, DataObject> createdData = changeEvent.getCreatedData() != null
+                    ? changeEvent.getCreatedData() : Collections.<InstanceIdentifier<?>, DataObject>emptyMap();
+            /* All DataObjects for remove */
+            final Set<InstanceIdentifier<?>> removeData = changeEvent.getRemovedPaths() != null
+                    ? changeEvent.getRemovedPaths() : Collections.<InstanceIdentifier<?>>emptySet();
+            /* All DataObjects for updates */
+            final Map<InstanceIdentifier<?>, DataObject> updateData = changeEvent.getUpdatedData() != null
+                    ? changeEvent.getUpdatedData() : Collections.<InstanceIdentifier<?>, DataObject>emptyMap();
+            /* All Original DataObjects */
+            final Map<InstanceIdentifier<?>, DataObject> originalData = changeEvent.getOriginalData() != null
+                    ? changeEvent.getOriginalData() : Collections.<InstanceIdentifier<?>, DataObject>emptyMap();
+
+            createData(createdData);
+            updateData(updateData, originalData);
+            removeData(removeData, originalData);
+        }
+    }
+}
index b5f1fc80845cfe825f4823cb9379043162a7d2cf..847284f52bd030aeb4f760d62d6a1e79e2be3a3c 100644 (file)
@@ -213,11 +213,23 @@ public enum ActionType {
         @Override
         public Action buildAction(ActionInfo actionInfo) {
             BigInteger [] actionValues = actionInfo.getBigActionValues();
-            return new ActionBuilder().setAction(
+            if (actionValues.length == 2) {
+                return new ActionBuilder().setAction(
+                    new SetFieldCaseBuilder().setSetField(
+                        new SetFieldBuilder()
+                            .setTunnel(new TunnelBuilder().setTunnelId(actionValues[0])
+                                           .setTunnelMask(actionValues[1]).build()).build())
+                        .build())
+                    .setKey(new ActionKey(actionInfo.getActionKey())).build();
+            } else {
+                return new ActionBuilder().setAction(
                     new SetFieldCaseBuilder().setSetField(
-                            new SetFieldBuilder().setTunnel(new TunnelBuilder().setTunnelId(actionValues[0])
-                                    .setTunnelMask(actionValues[1]).build()).build()).build())
-                                    .setKey(new ActionKey(actionInfo.getActionKey())).build();
+                        new SetFieldBuilder()
+                            .setTunnel(new TunnelBuilder().setTunnelId(actionValues[0])
+                                           .build()).build())
+                        .build())
+                    .setKey(new ActionKey(actionInfo.getActionKey())).build();
+            }
 
         }
 
index deb8c7573fd7b457b6f8177987179b839aff4774..568ad4f457483ccb5486ef2ba93fc1e0c756df32 100644 (file)
@@ -17,6 +17,7 @@ public class MetaDataUtil {
     public static final BigInteger METADATA_MASK_LPORT_WRITE = new BigInteger("00FFFF0000000000", 16);
     public static final BigInteger METADA_MASK_VALID_TUNNEL_ID_BIT_AND_TUNNEL_ID = new BigInteger("08000000FFFFFF00", 16);
     public static final BigInteger METADATA_MASK_LABEL_ITM = new BigInteger("40FFFFFF000000FF", 16);
+    public static final BigInteger METADA_MASK_TUNNEL_ID = new BigInteger("00000000FFFFFF00", 16);
 
     public static BigInteger getMetaDataForLPortDispatcher(int lportTag, short serviceIndex) {
         return getServiceIndexMetaData(serviceIndex).or(getLportTagMetaData(lportTag));
index da0b0f74abb9571264752702594d2dde04b4ec3f..56df83530ecc42c3391b3f9d444909d60a465686 100644 (file)
@@ -41,4 +41,15 @@ public class NwConstants {
 
     public static final int DEFAULT_ARP_FLOW_PRIORITY = 100;
 
+    //Table IDs
+    public static final short L3_FIB_TABLE = 21;
+    public static final short L3_LFIB_TABLE = 20;
+
+    public static final short L3_PROTOCOL_TABLE = 36;
+    public static final short L3_INTERFACE_TABLE = 80;
+    public static final short LPORT_DISPATCHER_TABLE = 30;
+    public static final short VLAN_INTERFACE_INGRESS_TABLE = 0;
+    public static final short INTERNAL_TUNNEL_TABLE = 36;
+    public static final short EXTERNAL_TUNNEL_TABLE = 38;
+
  }
\ No newline at end of file
index 16d28cb8683a4481f67e0d81a0d7c351ad3b219d..8624c6fc85210baa4e8174305457984ebb0cb900 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
-Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+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,
index 8da26707adc59ec95c917b4fe6f3d68b30cd613a..5aa42dcb97c487872de8e4f0d539a33edb6e4309 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * 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,
index c178534066d44407ceefa838123d8594aa6f7bbf..bc306bbfd8ba33c4e310c27afcc867b085ae5792 100644 (file)
@@ -151,6 +151,21 @@ module neutronvpn {
         }
     }
 
+    /* container for DHCP Configuration */
+    container dhcp-config {
+        list configs {
+            leaf lease-duration {
+                type    int32;
+                description "default lease duration for dhcp lease.
+                             -1 means infinite";
+            }
+            leaf default-domain {
+                type string;
+                description "default domain-name. used in dhcp reply";
+            }
+        }
+    }
+
     rpc createL3VPN{
         description "Create one or more L3 VPN";
         input {
index 8f9e42a95a6b044e03c0262b387e69098c400ea8..0ad31796383b415c8012ea320d6c362883de56ea 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: --><!--
-Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+<!--
+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,
index 898204245c5c50a2b4631f7f5c3f7189d2eba655..13b91f09ef6a7dd4632c4ca4fee75f33464bad41 100644 (file)
@@ -1,7 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: -->
 <!--
-Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+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,
index d413a32117290ec24c033456b7e2bf0c1ff4d552..7375c0585601b9cbad04cb80c1104a9a1a9163f1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * 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,
index e5bc67ef5e66747232e0d59ac7c0e4ae7dace2c0..1e0252b028b54c536fa006857aa2b77c9c3e602a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * 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,
index a615600aeeafd0df12718908319d5dafdeeb418c..3783a61ba6f3ae60c904a4e57b00fa271d63c64f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * 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,
@@ -8,15 +8,27 @@
 package org.opendaylight.vpnservice.neutronvpn;
 
 
+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.DataChangeScope;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 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.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
+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.ports.rev150712.port.attributes.FixedIps;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
+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
+        .PortNameToPortUuidBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.subnetmaps.Subnetmap;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
@@ -72,7 +84,7 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
         if (LOG.isTraceEnabled()) {
             LOG.trace("Adding Port : key: " + identifier + ", value=" + input);
         }
-        nvpnManager.handleNeutronPortCreated(input);
+        handleNeutronPortCreated(input);
 
     }
 
@@ -81,7 +93,7 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
         if (LOG.isTraceEnabled()) {
             LOG.trace("Removing Port : key: " + identifier + ", value=" + input);
         }
-        nvpnManager.handleNeutronPortDeleted(input);
+        handleNeutronPortDeleted(input);
 
     }
 
@@ -102,7 +114,158 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
                     iterator.remove();
                 }
             }
-            nvpnManager.handleNeutronPortUpdated(original, update);
+            handleNeutronPortUpdated(original, update);
+        }
+    }
+
+    private void handleNeutronPortCreated(Port port) {
+        LOG.info("Of-port-interface creation");
+        int portVlanId = NeutronvpnUtils.getVlanFromNeutronPort(port);
+        // Create of-port interface for this neutron port
+        createOfPortInterface(port, portVlanId);
+        LOG.debug("Add port to subnet");
+        // add port to local Subnets DS
+        Uuid vpnId = addPortToSubnets(port);
+
+        if (vpnId != null) {
+            // create vpn-interface on this neutron port
+            LOG.debug("Adding VPN Interface");
+            nvpnManager.createVpnInterface(vpnId, port);
+        }
+    }
+
+    private void handleNeutronPortDeleted(Port port) {
+        LOG.debug("Of-port-interface removal");
+        LOG.debug("Remove port from subnet");
+        // remove port from local Subnets DS
+        Uuid vpnId = removePortFromSubnets(port);
+
+        if (vpnId != null) {
+            // remove vpn-interface for this neutron port
+            LOG.debug("removing VPN Interface");
+            nvpnManager.deleteVpnInterface(port);
+        }
+        int portVlanId = NeutronvpnUtils.getVlanFromNeutronPort(port);
+        // Remove of-port interface for this neutron port
+        deleteOfPortInterface(port, portVlanId);
+
+    }
+
+    private void handleNeutronPortUpdated(Port portoriginal, Port portupdate) {
+        LOG.debug("Add port to subnet");
+        // add port FixedIPs to local Subnets DS
+        Uuid vpnIdup = addPortToSubnets(portupdate);
+
+        if (vpnIdup != null) {
+            nvpnManager.createVpnInterface(vpnIdup, portupdate);
+        }
+
+        // remove port FixedIPs from local Subnets DS
+        Uuid vpnIdor = removePortFromSubnets(portoriginal);
+
+        if (vpnIdor != null) {
+            nvpnManager.deleteVpnInterface(portoriginal);
+        }
+    }
+
+    private void createOfPortInterface(Port port, int portVlanId) {
+        String name = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
+        //String ifname = new StringBuilder(name).append(":").append(Integer.toString(portVlanId)).toString();
+        //Network network = NeutronvpnUtils.getNeutronNetwork(broker, port.getNetworkId());
+        //Boolean isVlanTransparent = network.isVlanTransparent();
+
+        LOG.debug("Creating OFPort Interface {}", name);
+        InstanceIdentifier interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(name);
+        try {
+            Optional<Interface> optionalInf = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+                    interfaceIdentifier);
+            if (!optionalInf.isPresent()) {
+                // handle these for trunkport extensions : portVlanId, isVlanTransparent
+                Interface inf = new InterfaceBuilder().setEnabled(true).setName(name).setType(L2vlan.class).build();
+                MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, interfaceIdentifier, inf);
+            } else {
+                LOG.error("Interface {} is already present", name);
+            }
+        } catch (Exception e) {
+            LOG.error("failed to create interface {} due to the exception {} ", name, e.getMessage());
+        }
+
+        InstanceIdentifier portIdentifier = NeutronvpnUtils.buildPortNameToPortUuidIdentifier(name);
+        PortNameToPortUuidBuilder builder = new PortNameToPortUuidBuilder().setPortName(name).setPortId(port.getUuid());
+        MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, portIdentifier, builder.build());
+        LOG.debug("name-uuid map for port with name: {}, uuid: {} added to NeutronPortData DS", name, port.getUuid
+                ());
+    }
+
+    private void deleteOfPortInterface(Port port, int portVlanId) {
+        String name = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
+        //String ifname = new StringBuilder(name).append(":").append(Integer.toString(portVlanId)).toString();
+        LOG.debug("Removing OFPort Interface {}", name);
+        InstanceIdentifier interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(name);
+        try {
+            Optional<Interface> optionalInf = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+                    interfaceIdentifier);
+            if (optionalInf.isPresent()) {
+                MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, interfaceIdentifier);
+            } else {
+                LOG.error("Interface {} is not present", name);
+            }
+        } catch (Exception e) {
+            LOG.error("Failed to delete interface {} due to the exception {}", name, e.getMessage());
+        }
+
+        InstanceIdentifier portIdentifier = NeutronvpnUtils.buildPortNameToPortUuidIdentifier(name);
+        MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, portIdentifier);
+        LOG.debug("name-uuid map for port with name: {}, uuid: {} deleted from NeutronPortData DS", name, port
+                .getUuid());
+    }
+
+    // adds port to subnet list and creates vpnInterface
+    private Uuid addPortToSubnets(Port port) {
+        Uuid subnetId = null;
+        Uuid vpnId = null;
+        String name = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
+
+        // find all subnets to which this port is associated
+        List<FixedIps> ips = port.getFixedIps();
+        for (FixedIps ip : ips) {
+            String ipValue = ip.getIpAddress().getIpv4Address().getValue();
+
+            InstanceIdentifier id = NeutronvpnUtils.buildFixedIpToPortNameIdentifier(ipValue);
+            PortFixedipToPortNameBuilder builder = new PortFixedipToPortNameBuilder().setPortFixedip(ipValue)
+                    .setPortName(name);
+            MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, id, builder.build());
+            LOG.debug("fixedIp-name map for neutron port with fixedIp: {}, name: {} added to NeutronPortData DS",
+                    ipValue, name);
+
+            subnetId = ip.getSubnetId();
+            Subnetmap subnetmap = nvpnManager.updateSubnetNode(subnetId, null, null, null, null, port.getUuid());
+            if (vpnId == null && subnetmap != null) {
+                vpnId = subnetmap.getVpnId();
+            }
+        }
+        return vpnId;
+    }
+
+    private Uuid removePortFromSubnets(Port port) {
+        Uuid subnetId = null;
+        Uuid vpnId = null;
+
+        // find all Subnets to which this port is associated
+        List<FixedIps> ips = port.getFixedIps();
+        for (FixedIps ip : ips) {
+            String ipValue = ip.getIpAddress().getIpv4Address().getValue();
+
+            InstanceIdentifier id = NeutronvpnUtils.buildFixedIpToPortNameIdentifier(ipValue);
+            MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, id);
+            LOG.debug("fixedIp-name map for neutron port with fixedIp: {} deleted from NeutronPortData DS", ipValue);
+
+            subnetId = ip.getSubnetId();
+            Subnetmap subnetmap = nvpnManager.removeFromSubnetNode(subnetId, null, null, null, port.getUuid());
+            if (vpnId == null && subnetmap != null) {
+                vpnId = subnetmap.getVpnId();
+            }
         }
+        return vpnId;
     }
 }
index 6d644851c663bf71af6f4f73b5f9710070ca47eb..826f9f839b52a35c0082c336f631031fe79ff456 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * 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,
index 6a1c05a4d45863485b78d950e5300cbfba0cd148..bea68b9a52fd3cfb7464056bc5d46b9bc0e20e2d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * 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,
@@ -7,20 +7,29 @@
  */
 package org.opendaylight.vpnservice.neutronvpn;
 
+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.DataChangeScope;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.vpnservice.mdsalutil.AbstractDataChangeListener;
+import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
+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.rev150712.Neutron;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.networkmaps.NetworkMap;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.networkmaps.NetworkMapBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.networkmaps.NetworkMapKey;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.ArrayList;
+import java.util.List;
+
 
 public class NeutronSubnetChangeListener extends AbstractDataChangeListener<Subnet> implements AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(NeutronSubnetChangeListener.class);
@@ -67,7 +76,7 @@ public class NeutronSubnetChangeListener extends AbstractDataChangeListener<Subn
         if (LOG.isTraceEnabled()) {
             LOG.trace("Adding Subnet : key: " + identifier + ", value=" + input);
         }
-        nvpnManager.handleNeutronSubnetCreated(input.getUuid(), input.getNetworkId(), input.getTenantId());
+        handleNeutronSubnetCreated(input.getUuid(), input.getNetworkId(), input.getTenantId());
     }
 
     @Override
@@ -75,7 +84,7 @@ public class NeutronSubnetChangeListener extends AbstractDataChangeListener<Subn
         if (LOG.isTraceEnabled()) {
             LOG.trace("Removing subnet : key: " + identifier + ", value=" + input);
         }
-        nvpnManager.handleNeutronSubnetDeleted(input.getUuid(), input.getNetworkId(), null);
+        handleNeutronSubnetDeleted(input.getUuid(), input.getNetworkId(), null);
     }
 
     @Override
@@ -84,6 +93,93 @@ public class NeutronSubnetChangeListener extends AbstractDataChangeListener<Subn
             LOG.trace("Updating Subnet : key: " + identifier + ", original value=" + original + ", update value=" +
                     update);
         }
-        nvpnManager.handleNeutronSubnetUpdated(update.getUuid(), update.getNetworkId(), update.getTenantId());
+        handleNeutronSubnetUpdated(update.getUuid(), update.getNetworkId(), update.getTenantId());
+    }
+
+    private void handleNeutronSubnetCreated(Uuid subnetId, Uuid networkId, Uuid tenantId) {
+        nvpnManager.updateSubnetNode(subnetId, tenantId, networkId, null, null, null);
+        if (networkId != null && NeutronvpnUtils.getNeutronNetwork(broker, networkId) != null) {
+            createSubnetToNetworkMapping(subnetId, networkId);
+        }
+    }
+
+    private void handleNeutronSubnetDeleted(Uuid subnetId, Uuid networkId, Uuid tenantId) {
+        Uuid vpnId = NeutronvpnUtils.getVpnForNetwork(broker, networkId);
+        if (vpnId != null) {
+            nvpnManager.removeSubnetFromVpn(vpnId, subnetId);
+        }
+        if (networkId != null)  {
+            deleteSubnetToNetworkMapping(subnetId, networkId);
+        }
+    }
+
+    private void handleNeutronSubnetUpdated(Uuid subnetId, Uuid networkId, Uuid tenantId) {
+        Uuid oldNetworkId = NeutronvpnUtils.getSubnetmap(broker, subnetId).getNetworkId();
+        if (oldNetworkId != null && !oldNetworkId.equals(networkId)) {
+            deleteSubnetToNetworkMapping(subnetId, oldNetworkId);
+        }
+        if (networkId != null && !networkId.equals(oldNetworkId)) {
+            createSubnetToNetworkMapping(subnetId, networkId);
+        }
+        nvpnManager.updateSubnetNode(subnetId, tenantId, networkId, null, null, null);
+    }
+
+    private void createSubnetToNetworkMapping(Uuid subnetId, Uuid networkId) {
+        try {
+            InstanceIdentifier networkMapIdentifier = NeutronvpnUtils.buildNetworkMapIdentifier(networkId);
+            Optional<NetworkMap> optionalNetworkMap = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+                    networkMapIdentifier);
+            NetworkMapBuilder nwMapBuilder = null;
+            if (optionalNetworkMap.isPresent()) {
+                nwMapBuilder = new NetworkMapBuilder(optionalNetworkMap.get());
+            } else {
+                nwMapBuilder = new NetworkMapBuilder().setKey(new NetworkMapKey(networkId)).setNetworkId(networkId);
+                LOG.debug("Adding a new network node in NetworkMaps DS for network {}", networkId.getValue());
+            }
+            List<Uuid> subnetIdList = nwMapBuilder.getSubnetIdList();
+            if (subnetIdList == null) {
+                subnetIdList = new ArrayList<>();
+            }
+            subnetIdList.add(subnetId);
+            nwMapBuilder.setSubnetIdList(subnetIdList);
+            MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier, nwMapBuilder.build());
+            LOG.debug("Created subnet-network mapping for subnet {} network {}", subnetId.getValue(),
+                    networkId.getValue());
+        } catch (Exception e) {
+            LOG.error("Create subnet-network mapping failed for subnet {} network {}", subnetId.getValue(),
+                    networkId.getValue());
+        }
+    }
+
+    private void deleteSubnetToNetworkMapping(Uuid subnetId, Uuid networkId) {
+        try {
+            InstanceIdentifier networkMapIdentifier = NeutronvpnUtils.buildNetworkMapIdentifier(networkId);
+            Optional<NetworkMap> optionalNetworkMap = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+                    networkMapIdentifier);
+            if (optionalNetworkMap.isPresent()) {
+                NetworkMapBuilder nwMapBuilder = new NetworkMapBuilder(optionalNetworkMap.get());
+                List<Uuid> subnetIdList = nwMapBuilder.getSubnetIdList();
+                if (subnetIdList.remove(subnetId)) {
+                    if (subnetIdList.size() == 0) {
+                        MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier);
+                        LOG.debug("Deleted network node in NetworkMaps DS for network {}", subnetId.getValue(),
+                                networkId.getValue());
+                    } else {
+                        nwMapBuilder.setSubnetIdList(subnetIdList);
+                        MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier,
+                                nwMapBuilder.build());
+                        LOG.debug("Deleted subnet-network mapping for subnet {} network {}", subnetId.getValue(),
+                                networkId.getValue());
+                    }
+                } else {
+                    LOG.error("Subnet {} is not mapped to network {}", subnetId.getValue(), networkId.getValue());
+                }
+            } else {
+                LOG.error("network {} not present for subnet {} ", networkId, subnetId);
+            }
+        } catch (Exception e) {
+            LOG.error("Delete subnet-network mapping failed for subnet {} network {}", subnetId.getValue(),
+                    networkId.getValue());
+        }
     }
 }
index 48959211d91b995ae237bc13684cf0b0031183e4..a94101d0fb0328d15fb59cb7794d6eb09319c486 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * 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,
@@ -11,7 +11,6 @@ import com.google.common.base.Optional;
 import com.google.common.util.concurrent.SettableFuture;
 
 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.vpnservice.mdsalutil.MDSALUtil;
 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
@@ -31,10 +30,7 @@ import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev14081
 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.VpnInterfaceBuilder;
 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.iana._if.type.rev140508.L2vlan;
 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.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
 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.l3vpn.rev130911.Adjacencies;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.AdjacenciesBuilder;
@@ -77,20 +73,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev15
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.getl3vpn.output.L3vpnInstances;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.getl3vpn.output
         .L3vpnInstancesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.networkmaps.NetworkMap;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.networkmaps.NetworkMapBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.networkmaps.NetworkMapKey;
-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
-        .PortNameToPortUuidBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.subnetmaps.Subnetmap;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.subnetmaps.SubnetmapBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.subnetmaps.SubnetmapKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.vpnmaps.VpnMap;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.vpnmaps.VpnMapBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.vpnmaps.VpnMapKey;
-import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
@@ -138,7 +126,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
 
             InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).
                     child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
-            Optional<Subnetmap> sn = read(LogicalDatastoreType.CONFIGURATION, id);
+            Optional<Subnetmap> sn = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, id);
             logger.debug("updating Subnet :read: ");
             if (sn.isPresent()) {
                 builder = new SubnetmapBuilder(sn.get());
@@ -189,7 +177,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         try {
             InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).
                     child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
-            Optional<Subnetmap> sn = read(LogicalDatastoreType.CONFIGURATION, id);
+            Optional<Subnetmap> sn = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, id);
 
             if (sn.isPresent()) {
                 SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
@@ -224,63 +212,6 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         return subnetmap;
     }
 
-    private void createSubnetToNetworkMapping(Uuid subnetId, Uuid networkId) {
-        try {
-            InstanceIdentifier networkMapIdentifier = NeutronvpnUtils.buildNetworkMapIdentifier(networkId);
-            Optional<NetworkMap> optionalNetworkMap = read(LogicalDatastoreType.CONFIGURATION, networkMapIdentifier);
-            NetworkMapBuilder nwMapBuilder = null;
-            if (optionalNetworkMap.isPresent()) {
-                nwMapBuilder = new NetworkMapBuilder(optionalNetworkMap.get());
-            } else {
-                nwMapBuilder = new NetworkMapBuilder().setKey(new NetworkMapKey(networkId)).setNetworkId(networkId);
-                logger.debug("Adding a new network node in NetworkMaps DS for network {}", networkId.getValue());
-            }
-            List<Uuid> subnetIdList = nwMapBuilder.getSubnetIdList();
-            if (subnetIdList == null) {
-                subnetIdList = new ArrayList<>();
-            }
-            subnetIdList.add(subnetId);
-            nwMapBuilder.setSubnetIdList(subnetIdList);
-            MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier, nwMapBuilder.build());
-            logger.debug("Created subnet-network mapping for subnet {} network {}", subnetId.getValue(),
-                    networkId.getValue());
-        } catch (Exception e) {
-            logger.error("Create subnet-network mapping failed for subnet {} network {}", subnetId.getValue(),
-                    networkId.getValue());
-        }
-    }
-
-    private void deleteSubnetToNetworkMapping(Uuid subnetId, Uuid networkId) {
-        try {
-            InstanceIdentifier networkMapIdentifier = NeutronvpnUtils.buildNetworkMapIdentifier(networkId);
-            Optional<NetworkMap> optionalNetworkMap = read(LogicalDatastoreType.CONFIGURATION, networkMapIdentifier);
-            if (optionalNetworkMap.isPresent()) {
-                NetworkMapBuilder nwMapBuilder = new NetworkMapBuilder(optionalNetworkMap.get());
-                List<Uuid> subnetIdList = nwMapBuilder.getSubnetIdList();
-                if (subnetIdList.remove(subnetId)) {
-                    if (subnetIdList.size() == 0) {
-                        MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier);
-                        logger.debug("Deleted network node in NetworkMaps DS for network {}", subnetId.getValue(),
-                                networkId.getValue());
-                    } else {
-                        nwMapBuilder.setSubnetIdList(subnetIdList);
-                        MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier,
-                                nwMapBuilder.build());
-                        logger.debug("Deleted subnet-network mapping for subnet {} network {}", subnetId.getValue(),
-                                networkId.getValue());
-                    }
-                } else {
-                    logger.error("Subnet {} is not mapped to network {}", subnetId.getValue(), networkId.getValue());
-                }
-            } else {
-                logger.error("network {} not present for subnet {} ", networkId, subnetId);
-            }
-        } catch (Exception e) {
-            logger.error("Delete subnet-network mapping failed for subnet {} network {}", subnetId.getValue(),
-                    networkId.getValue());
-        }
-    }
-
     private void updateVpnInstanceNode(String name, List<String> rd, List<String> irt, List<String> ert) {
 
         try {
@@ -288,7 +219,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
             List<VpnTarget> vpnTargetList = new ArrayList<VpnTarget>();
             InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class).
                     child(VpnInstance.class, new VpnInstanceKey(name)).build();
-            Optional<VpnInstance> optionalVpn = read(LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
+            Optional<VpnInstance> optionalVpn = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+                    vpnIdentifier);
             logger.debug("Creating/Updating a new vpn-instance node: {} ", name);
             if (optionalVpn.isPresent()) {
                 builder = new VpnInstanceBuilder(optionalVpn.get());
@@ -353,7 +285,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         VpnMapBuilder builder;
         InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class)
                 .child(VpnMap.class, new VpnMapKey(vpnId)).build();
-        Optional<VpnMap> optionalVpnMap = read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
+        Optional<VpnMap> optionalVpnMap = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+                vpnMapIdentifier);
         if (optionalVpnMap.isPresent()) {
             builder = new VpnMapBuilder(optionalVpnMap.get());
         } else {
@@ -386,7 +319,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
     private void clearFromVpnMaps(Uuid id, Uuid router, List<Uuid> networks) {
         InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class)
                 .child(VpnMap.class, new VpnMapKey(id)).build();
-        Optional<VpnMap> optionalVpnMap = read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
+        Optional<VpnMap> optionalVpnMap = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+                vpnMapIdentifier);
         if (optionalVpnMap.isPresent()) {
             VpnMap vpnMap = optionalVpnMap.get();
             VpnMapBuilder vpnMapBuilder = new VpnMapBuilder(vpnMap);
@@ -420,56 +354,6 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         logger.debug("VPNMaps DS clear success for VPN {} ", id.getValue());
     }
 
-    private void createOfPortInterface(Port port, int portVlanId) {
-        String name = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
-        //String ifname = new StringBuilder(name).append(":").append(Integer.toString(portVlanId)).toString();
-        //Network network = NeutronvpnUtils.getNeutronNetwork(broker, port.getNetworkId());
-        //Boolean isVlanTransparent = network.isVlanTransparent();
-
-        logger.debug("Creating OFPort Interface {}", name);
-        InstanceIdentifier interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(name);
-        try {
-            Optional<Interface> optionalInf = read(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier);
-            if (!optionalInf.isPresent()) {
-                // handle these for trunkport extensions : portVlanId, isVlanTransparent
-                Interface inf = new InterfaceBuilder().setEnabled(true).setName(name).setType(L2vlan.class).build();
-                MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, interfaceIdentifier, inf);
-            } else {
-                logger.error("Interface {} is already present", name);
-            }
-        } catch (Exception e) {
-            logger.error("failed to create interface {} due to the exception {} ", name, e.getMessage());
-        }
-
-        InstanceIdentifier portIdentifier = NeutronvpnUtils.buildPortNameToPortUuidIdentifier(name);
-        PortNameToPortUuidBuilder builder = new PortNameToPortUuidBuilder().setPortName(name).setPortId(port.getUuid());
-        MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, portIdentifier, builder.build());
-        logger.debug("name-uuid map for port with name: {}, uuid: {} added to NeutronPortData DS", name, port.getUuid
-                ());
-    }
-
-    private void deleteOfPortInterface(Port port, int portVlanId) {
-        String name = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
-        //String ifname = new StringBuilder(name).append(":").append(Integer.toString(portVlanId)).toString();
-        logger.debug("Removing OFPort Interface {}", name);
-        InstanceIdentifier interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(name);
-        try {
-            Optional<Interface> optionalInf = read(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier);
-            if (optionalInf.isPresent()) {
-                MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, interfaceIdentifier);
-            } else {
-                logger.error("Interface {} is not present", name);
-            }
-        } catch (Exception e) {
-            logger.error("Failed to delete interface {} due to the exception {}", name, e.getMessage());
-        }
-
-        InstanceIdentifier portIdentifier = NeutronvpnUtils.buildPortNameToPortUuidIdentifier(name);
-        MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, portIdentifier);
-        logger.debug("name-uuid map for port with name: {}, uuid: {} deleted from NeutronPortData DS", name, port
-                .getUuid());
-    }
-
     private void deleteVpnInstance(Uuid vpnId) {
 
         InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class).
@@ -479,7 +363,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
     }
 
 
-    private void createVpnInterface(Uuid vpnId, Port port) {
+    protected void createVpnInterface(Uuid vpnId, Port port) {
 
         if (vpnId == null || port == null) {
             return;
@@ -531,7 +415,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         }
     }
 
-    private void deleteVpnInterface(Port port) {
+    protected void deleteVpnInterface(Port port) {
 
         if (port != null) {
             String pname = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
@@ -551,134 +435,6 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         }
     }
 
-    // adds port to subnet list and creates vpnInterface
-    private Uuid addPortToSubnets(Port port) {
-        Uuid subnetId = null;
-        Uuid vpnId = null;
-        String name = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
-
-        // find all subnets to which this port is associated
-        List<FixedIps> ips = port.getFixedIps();
-        for (FixedIps ip : ips) {
-            String ipValue = ip.getIpAddress().getIpv4Address().getValue();
-
-            InstanceIdentifier id = NeutronvpnUtils.buildFixedIpToPortNameIdentifier(ipValue);
-            PortFixedipToPortNameBuilder builder = new PortFixedipToPortNameBuilder().setPortFixedip(ipValue)
-                    .setPortName(name);
-            MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, id, builder.build());
-            logger.debug("fixedIp-name map for neutron port with fixedIp: {}, name: {} added to NeutronPortData DS",
-                    ipValue, name);
-
-            subnetId = ip.getSubnetId();
-            Subnetmap subnetmap = updateSubnetNode(subnetId, null, null, null, null, port.getUuid());
-            if (vpnId == null && subnetmap != null) {
-                vpnId = subnetmap.getVpnId();
-            }
-        }
-        return vpnId;
-    }
-
-    private Uuid removePortFromSubnets(Port port) {
-        Uuid subnetId = null;
-        Uuid vpnId = null;
-
-        // find all Subnets to which this port is associated
-        List<FixedIps> ips = port.getFixedIps();
-        for (FixedIps ip : ips) {
-            String ipValue = ip.getIpAddress().getIpv4Address().getValue();
-
-            InstanceIdentifier id = NeutronvpnUtils.buildFixedIpToPortNameIdentifier(ipValue);
-            MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, id);
-            logger.debug("fixedIp-name map for neutron port with fixedIp: {} deleted from NeutronPortData DS",
-                    ipValue);
-
-            subnetId = ip.getSubnetId();
-            Subnetmap subnetmap = removeFromSubnetNode(subnetId, null, null, null, port.getUuid());
-            if (vpnId == null && subnetmap != null) {
-                vpnId = subnetmap.getVpnId();
-            }
-        }
-        return vpnId;
-    }
-
-    protected void handleNeutronSubnetCreated(Uuid subnetId, Uuid networkId, Uuid tenantId) {
-        updateSubnetNode(subnetId, tenantId, networkId, null, null, null);
-        if (networkId != null && NeutronvpnUtils.getNeutronNetwork(broker, networkId) != null) {
-            createSubnetToNetworkMapping(subnetId, networkId);
-        }
-    }
-
-    protected void handleNeutronSubnetDeleted(Uuid subnetId, Uuid networkId, Uuid tenantId) {
-        Uuid vpnId = NeutronvpnUtils.getVpnForNetwork(broker, networkId);
-        if (vpnId != null) {
-            removeSubnetFromVpn(vpnId, subnetId);
-        }
-        if (networkId != null)  {
-            deleteSubnetToNetworkMapping(subnetId, networkId);
-        }
-    }
-
-    protected void handleNeutronSubnetUpdated(Uuid subnetId, Uuid networkId, Uuid tenantId) {
-        Uuid oldNetworkId = NeutronvpnUtils.getSubnetmap(broker, subnetId).getNetworkId();
-        if (oldNetworkId != null && !oldNetworkId.equals(networkId)) {
-            deleteSubnetToNetworkMapping(subnetId, oldNetworkId);
-        }
-        if (networkId != null && !networkId.equals(oldNetworkId)) {
-            createSubnetToNetworkMapping(subnetId, networkId);
-        }
-        updateSubnetNode(subnetId, tenantId, networkId, null, null, null);
-    }
-
-    protected void handleNeutronPortCreated(Port port) {
-        logger.info("Of-port-interface creation");
-        int portVlanId = NeutronvpnUtils.getVlanFromNeutronPort(port);
-        // Create of-port interface for this neutron port
-        createOfPortInterface(port, portVlanId);
-        logger.debug("Add port to subnet");
-        // add port to local Subnets DS
-        Uuid vpnId = addPortToSubnets(port);
-
-        if (vpnId != null) {
-            // create vpn-interface on this neutron port
-            logger.debug("Adding VPN Interface");
-            createVpnInterface(vpnId, port);
-        }
-    }
-
-    protected void handleNeutronPortDeleted(Port port) {
-        logger.debug("Of-port-interface removal");
-        logger.debug("Remove port from subnet");
-        // remove port from local Subnets DS
-        Uuid vpnId = removePortFromSubnets(port);
-
-        if (vpnId != null) {
-            // remove vpn-interface for this neutron port
-            logger.debug("removing VPN Interface");
-            deleteVpnInterface(port);
-        }
-        int portVlanId = NeutronvpnUtils.getVlanFromNeutronPort(port);
-        // Remove of-port interface for this neutron port
-        deleteOfPortInterface(port, portVlanId);
-
-    }
-
-    protected void handleNeutronPortUpdated(Port portoriginal, Port portupdate) {
-        logger.debug("Add port to subnet");
-        // add port FixedIPs to local Subnets DS
-        Uuid vpnIdup = addPortToSubnets(portupdate);
-
-        if (vpnIdup != null) {
-            createVpnInterface(vpnIdup, portupdate);
-        }
-
-        // remove port FixedIPs from local Subnets DS
-        Uuid vpnIdor = removePortFromSubnets(portoriginal);
-
-        if (vpnIdor != null) {
-            deleteVpnInterface(portoriginal);
-        }
-    }
-
     public void createL3Vpn(Uuid vpn, String name, Uuid tenant, List<String> rd, List<String> irt, List<String> ert,
                             Uuid router, List<Uuid> networks) {
 
@@ -772,7 +528,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
                 // get all vpns
                 InstanceIdentifier<VpnInstances> vpnsIdentifier =
                         InstanceIdentifier.builder(VpnInstances.class).build();
-                Optional<VpnInstances> optionalVpns = read(LogicalDatastoreType.CONFIGURATION, vpnsIdentifier);
+                Optional<VpnInstances> optionalVpns = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+                        vpnsIdentifier);
                 if (optionalVpns.isPresent()) {
                     for (VpnInstance vpn : optionalVpns.get().getVpnInstance()) {
                         vpns.add(vpn);
@@ -789,7 +546,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
                         InstanceIdentifier.builder(VpnInstances.class)
                                 .child(VpnInstance.class, new VpnInstanceKey(name)).build();
                 // read VpnInstance Info
-                Optional<VpnInstance> optionalVpn = read(LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
+                Optional<VpnInstance> optionalVpn = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+                        vpnIdentifier);
                 if (optionalVpn.isPresent()) {
                     vpns.add(optionalVpn.get());
                 } else {
@@ -828,8 +586,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
                 }
 
                 l3vpn.setId(vpnId).setRouteDistinguisher(rd).setImportRT(irtList).setExportRT(ertList);
-                Optional<VpnMap> optionalVpnMap =
-                        read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
+                Optional<VpnMap> optionalVpnMap = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+                        vpnMapIdentifier);
                 if (optionalVpnMap.isPresent()) {
                     VpnMap vpnMap = optionalVpnMap.get();
                     l3vpn.setRouterId(vpnMap.getRouterId()).setNetworkIds(vpnMap.getNetworkIds())
@@ -867,7 +625,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
                 InstanceIdentifier<VpnInstance> vpnIdentifier =
                         InstanceIdentifier.builder(VpnInstances.class)
                                 .child(VpnInstance.class, new VpnInstanceKey(vpn.getValue())).build();
-                Optional<VpnInstance> optionalVpn = read(LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
+                Optional<VpnInstance> optionalVpn = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+                        vpnIdentifier);
                 if (optionalVpn.isPresent()) {
                     removeL3Vpn(vpn);
                 } else {
@@ -943,8 +702,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
                     }
                     InstanceIdentifier<VpnInterface> vpnIfIdentifier = InstanceIdentifier.builder(VpnInterfaces.class).
                             child(VpnInterface.class, new VpnInterfaceKey(ifname)).build();
-                    Optional<VpnInterface> optionalVpnInterface = read(LogicalDatastoreType.CONFIGURATION,
-                            vpnIfIdentifier);
+                    Optional<VpnInterface> optionalVpnInterface = NeutronvpnUtils.read(broker, LogicalDatastoreType
+                            .CONFIGURATION, vpnIfIdentifier);
                     if (optionalVpnInterface.isPresent()) {
                         Adjacencies erAdjs = new AdjacenciesBuilder().setAdjacency(Arrays.asList(erAdj)).build();
                         VpnInterface vpnIf = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(ifname))
@@ -1297,24 +1056,10 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         return result;
     }
 
-    private <T extends DataObject> Optional<T> read(LogicalDatastoreType datastoreType, InstanceIdentifier<T> path) {
-
-        ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
-
-        Optional<T> result = Optional.absent();
-        try {
-            result = tx.read(datastoreType, path).get();
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
-
-        return result;
-    }
-
     protected Subnet getNeutronSubnet(Uuid subnetId) {
         InstanceIdentifier<Subnet> inst = InstanceIdentifier.create(Neutron.class).
                 child(Subnets.class).child(Subnet.class, new SubnetKey(subnetId));
-        Optional<Subnet> sn = read(LogicalDatastoreType.CONFIGURATION, inst);
+        Optional<Subnet> sn = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, inst);
 
         if (sn.isPresent()) {
             return sn.get();
@@ -1335,7 +1080,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         if (portId != null) {
             InstanceIdentifier<Port> pid = InstanceIdentifier.create(Neutron.class).
                     child(Ports.class).child(Port.class, new PortKey(portId));
-            Optional<Port> optPort = read(LogicalDatastoreType.CONFIGURATION, pid);
+            Optional<Port> optPort = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, pid);
             if (optPort.isPresent()) {
                 return optPort.get();
             }
@@ -1348,7 +1093,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
     protected Port getNeutronPort(Uuid portId) {
         InstanceIdentifier<Port> pid = InstanceIdentifier.create(Neutron.class).
                 child(Ports.class).child(Port.class, new PortKey(portId));
-        Optional<Port> optPort = read(LogicalDatastoreType.CONFIGURATION, pid);
+        Optional<Port> optPort = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, pid);
         if (optPort.isPresent()) {
             return optPort.get();
         }
@@ -1359,7 +1104,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         List<Uuid> subnets = new ArrayList<Uuid>();
         //read subnetmaps
         InstanceIdentifier<Subnetmaps> subnetmapsid = InstanceIdentifier.builder(Subnetmaps.class).build();
-        Optional<Subnetmaps> subnetmaps = read(LogicalDatastoreType.CONFIGURATION, subnetmapsid);
+        Optional<Subnetmaps> subnetmaps = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+                subnetmapsid);
         if (subnetmaps.isPresent()) {
             Subnetmaps smaps = subnetmaps.get();
             List<Subnetmap> subnetMapList = smaps.getSubnetmap();
@@ -1379,13 +1125,13 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         result.add("---------------------------------------------------------------------------------------");
         InstanceIdentifier<Ports> portidentifier = InstanceIdentifier.create(Neutron.class).child(Ports.class);
         try {
-            Optional<Ports> ports = read(LogicalDatastoreType.CONFIGURATION, portidentifier);
+            Optional<Ports> ports = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, portidentifier);
             if (ports.isPresent()) {
                 List<Port> portList = ports.get().getPort();
                 for (Port port : portList) {
                     result.add(String.format(" %-22s  %-22s  %-22s  %-6s ", NeutronvpnUtils.uuidToTapPortName(port
                             .getUuid()), port.getMacAddress(), port.getFixedIps().get(0).getIpAddress().getIpv4Address()
-                            .getValue(), getIPPrefixFromPort(port)));
+                            .getValue(), NeutronvpnUtils.getIPPrefixFromPort(broker, port)));
                 }
             }
         } catch (Exception e) {
@@ -1395,44 +1141,6 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable {
         return result;
     }
 
-    private Short getIPPrefixFromPort(Port port) {
-        Short prefix = new Short((short) 0);
-        String cidr = "";
-        try {
-            Uuid subnetUUID = port.getFixedIps().get(0).getSubnetId();
-
-            org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets
-                    .SubnetKey subnetkey = new org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets
-                    .rev150712.subnets.attributes.subnets.SubnetKey(subnetUUID);
-            InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets
-                    .attributes.subnets.Subnet> subnetidentifier = InstanceIdentifier.create(Neutron.class).child(org
-                    .opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets
-                    .class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets
-                    .attributes.subnets.Subnet.class, subnetkey);
-            Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes
-                    .subnets.Subnet> subnet = read(LogicalDatastoreType.CONFIGURATION, subnetidentifier);
-
-            if (subnet.isPresent()) {
-                cidr = subnet.get().getCidr();
-                // Extract the prefix length from cidr
-                String[] parts = cidr.split("/");
-                if ((parts.length == 2)) {
-                    prefix = Short.valueOf(parts[1]);
-                    return prefix;
-                } else {
-                    logger.trace("Could not retrieve prefix from subnet CIDR");
-                    System.out.println("Could not retrieve prefix from subnet CIDR");
-                }
-            } else {
-                logger.trace("Unable to read on subnet datastore");
-            }
-        } catch (Exception e) {
-            logger.trace("Failed to retrieve IP prefix from port : ", e);
-            System.out.println("Failed to retrieve IP prefix from port : " + e.getMessage());
-        }
-        return null;
-    }
-
     public List<String> showVpnConfigCLI(Uuid vpnuuid) {
         List<String> result = new ArrayList<String>();
         if (vpnuuid == null) {
index ccfc14e80e64b0e24f5ac3f50bf71c8cdf78eaae..651ef836045f354f6dbf5f83d11a5a684085c5b9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * 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,
index 993a465337852a2a0ab1c53124b37ad4539f8c8c..042b0ea19f28dd22f0e400f892d715692b59c79b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * 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,
@@ -37,7 +37,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev15
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.VpnMaps;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.networkmaps.NetworkMap;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.networkmaps.NetworkMapKey;
-
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.neutron.port.data
         .PortFixedipToPortName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.neutron.port.data
@@ -80,10 +79,9 @@ public class NeutronvpnUtils {
     }
 
     protected static VpnMap getVpnMap(DataBroker broker, Uuid id) {
-        InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class)
-                .child(VpnMap.class, new VpnMapKey(id)).build();
-        Optional<VpnMap> optionalVpnMap = read(broker, LogicalDatastoreType.CONFIGURATION,
-                vpnMapIdentifier);
+        InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class,
+                new VpnMapKey(id)).build();
+        Optional<VpnMap> optionalVpnMap = read(broker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
         if (optionalVpnMap.isPresent()) {
             return optionalVpnMap.get();
         }
@@ -93,8 +91,7 @@ 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);
+        Optional<VpnMaps> optionalVpnMaps = read(broker, LogicalDatastoreType.CONFIGURATION, vpnMapsIdentifier);
         if (optionalVpnMaps.isPresent()) {
             VpnMaps vpnMaps = optionalVpnMaps.get();
             List<VpnMap> allMaps = vpnMaps.getVpnMap();
@@ -109,8 +106,7 @@ public class NeutronvpnUtils {
 
     protected static Uuid getVpnForRouter(DataBroker broker, Uuid router) {
         InstanceIdentifier<VpnMaps> vpnMapsIdentifier = InstanceIdentifier.builder(VpnMaps.class).build();
-        Optional<VpnMaps> optionalVpnMaps = read(broker, LogicalDatastoreType.CONFIGURATION,
-                vpnMapsIdentifier);
+        Optional<VpnMaps> optionalVpnMaps = read(broker, LogicalDatastoreType.CONFIGURATION, vpnMapsIdentifier);
         if (optionalVpnMaps.isPresent()) {
             VpnMaps vpnNets = optionalVpnMaps.get();
             List<VpnMap> allMaps = vpnNets.getVpnMap();
@@ -128,8 +124,7 @@ public class NeutronvpnUtils {
     protected static Uuid getRouterforVpn(DataBroker broker, Uuid vpnId) {
         InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class)
                 .child(VpnMap.class, new VpnMapKey(vpnId)).build();
-        Optional<VpnMap> optionalVpnMap = read(broker, LogicalDatastoreType.CONFIGURATION,
-                vpnMapIdentifier);
+        Optional<VpnMap> optionalVpnMap = read(broker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
         if (optionalVpnMap.isPresent()) {
             VpnMap vpnMap = optionalVpnMap.get();
             return vpnMap.getRouterId();
@@ -158,8 +153,7 @@ public class NeutronvpnUtils {
 
     protected static List<Uuid> getSubnetIdsFromNetworkId(DataBroker broker, Uuid networkId) {
         InstanceIdentifier id = buildNetworkMapIdentifier(networkId);
-        Optional<NetworkMap> optionalNetworkMap = read(broker, LogicalDatastoreType.CONFIGURATION,
-                id);
+        Optional<NetworkMap> optionalNetworkMap = read(broker, LogicalDatastoreType.CONFIGURATION, id);
         if (optionalNetworkMap.isPresent()) {
             return optionalNetworkMap.get().getSubnetIdList();
         }
@@ -184,9 +178,8 @@ public class NeutronvpnUtils {
 
     protected static Router getNeutronRouter(DataBroker broker, Uuid routerId) {
 
-        InstanceIdentifier<Router> inst = InstanceIdentifier.create(Neutron.class).
-                child(Routers.class).child(Router.class, new RouterKey(routerId));
-
+        InstanceIdentifier<Router> inst = InstanceIdentifier.create(Neutron.class).child(Routers.class).child(Router
+                .class, new RouterKey(routerId));
         Optional<Router> rtr = read(broker, LogicalDatastoreType.CONFIGURATION, inst);
         if (rtr.isPresent()) {
             return rtr.get();
@@ -196,9 +189,8 @@ public class NeutronvpnUtils {
 
     protected static Network getNeutronNetwork(DataBroker broker, Uuid networkId) {
         logger.debug("getNeutronNetwork for {}", networkId.getValue());
-        InstanceIdentifier<Network> inst = InstanceIdentifier.create(Neutron.class).
-                child(Networks.class).child(Network.class, new NetworkKey(networkId));
-
+        InstanceIdentifier<Network> inst = InstanceIdentifier.create(Neutron.class).child(Networks.class).child
+                (Network.class, new NetworkKey(networkId));
         Optional<Network> net = read(broker, LogicalDatastoreType.CONFIGURATION, inst);
         if (net.isPresent()) {
             return net.get();
@@ -263,6 +255,44 @@ public class NeutronvpnUtils {
         }
     }
 
+    protected static Short getIPPrefixFromPort(DataBroker broker, Port port) {
+        Short prefix = new Short((short) 0);
+        String cidr = "";
+        try {
+            Uuid subnetUUID = port.getFixedIps().get(0).getSubnetId();
+
+            org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets
+                    .SubnetKey subnetkey = new org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets
+                    .rev150712.subnets.attributes.subnets.SubnetKey(subnetUUID);
+            InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets
+                    .attributes.subnets.Subnet> subnetidentifier = InstanceIdentifier.create(Neutron.class).child(org
+                    .opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets
+                    .class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets
+                    .attributes.subnets.Subnet.class, subnetkey);
+            Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes
+                    .subnets.Subnet> subnet = read(broker, LogicalDatastoreType.CONFIGURATION, subnetidentifier);
+
+            if (subnet.isPresent()) {
+                cidr = subnet.get().getCidr();
+                // Extract the prefix length from cidr
+                String[] parts = cidr.split("/");
+                if ((parts.length == 2)) {
+                    prefix = Short.valueOf(parts[1]);
+                    return prefix;
+                } else {
+                    logger.trace("Could not retrieve prefix from subnet CIDR");
+                    System.out.println("Could not retrieve prefix from subnet CIDR");
+                }
+            } else {
+                logger.trace("Unable to read on subnet datastore");
+            }
+        } catch (Exception e) {
+            logger.trace("Failed to retrieve IP prefix from port : ", e);
+            System.out.println("Failed to retrieve IP prefix from port : " + e.getMessage());
+        }
+        return null;
+    }
+
     static InstanceIdentifier<PortNameToPortUuid> buildPortNameToPortUuidIdentifier(String portname) {
         InstanceIdentifier<PortNameToPortUuid> id = InstanceIdentifier.builder(NeutronPortData.class).child
                 (PortNameToPortUuid.class, new PortNameToPortUuidKey(portname)).build();
index c6b556df03ec661801c17720b4f837b6d9b9e456..9752c8b9d88e310769deae0d7c7bd880351edca7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * 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,
index d54bef15da9770c97996d8259561effc4bd9bb37..67886e585d742188b1a4d008e46a7364ee8d6ad9 100644 (file)
@@ -3,7 +3,7 @@
 *
 * Generated from: yang module name: neutronvpn-impl yang module local name: neutronvpn-impl
 * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
-* Generated at: Thu Jan 06 10:51:12 IST 2015
+* Generated at: Thu Jan 06 10:51:12 IST 2016
 *
 * Do not modify this file unless it is present under src/main directory
 */
index 4be86556be0a675c2d41d2e5a99aa28c826f5177..2bf2a630d9e8375a64baac03924ea276004f4a0a 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: --><!--
-Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+<!--
+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,
index 01bfeb1160133a4b15ea7041f7377d74ad3b7129..8139079b46bf4d9cc7c53e3ff2e15b129a2b3d85 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * 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,
index cf4736e485c0c68ea25f67b4290e2903e60a8a46..b10521bf9c3118a51b718dc9f0a48fb3d4251929 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * 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,
index 8801af350abc841bf8d630e90038578837c7ba79..6e8acdc1ebfdafed65505104db7864b3a3fe177f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * 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,
index 80cff0495feb94a9e47208667848f30e7c55f3ec..40f4e90a471773cf2c0f30cc38e6c16a51a410e0 100644 (file)
@@ -1,8 +1,10 @@
-<!--    * Copyright (c) 2015 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
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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
 -->
 
 <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
index 18814e09ade4b8bacf7f8f00f75c038176fc4988..0479e185a59648fdeef8edd6522b95fcef763d1e 100644 (file)
@@ -1,9 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
-Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+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 INTERNAL
+and is available at http://www.eclipse.org/legal/epl-v10.html
 -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
index 8bcde64dcc9884659d7f077cf8253818711fc222..75b076395e4895c9ecd99419cd61879bfd62f727 100644 (file)
@@ -14,10 +14,6 @@ public class VpnConstants {
     public static final String VPN_IDPOOL_NAME = "vpnservices";
     public static final long VPN_IDPOOL_START = 100L;
     public static final String VPN_IDPOOL_SIZE = "100000";
-    public static final short LPORT_INGRESS_TABLE = 0;
-    public static final short LFIB_TABLE = 20;
-    public static final short FIB_TABLE = 21;
-    public static final short L3_INTERFACE_TABLE = 80;
     public static final short DEFAULT_FLOW_PRIORITY = 10;
     public static final short L3VPN_SERVICE_IDENTIFIER = 2;
     public static final long INVALID_ID = -1;
index 45a21744d21cc205ecb875b304cca06009c75628..c37666a919aa10b4dfd458ba030bda4fd4b28229 100644 (file)
@@ -212,7 +212,7 @@ public class VpnInterfaceManager extends AbstractDataChangeListener<VpnInterface
         List<Instruction> instructions = new ArrayList<Instruction>();
 
         instructions.add(MDSALUtil.buildAndGetWriteMetadaInstruction(BigInteger.valueOf(vpnId), MetaDataUtil.METADATA_MASK_VRFID, ++instructionKey));
-        instructions.add(MDSALUtil.buildAndGetGotoTableInstruction(VpnConstants.FIB_TABLE, ++instructionKey));
+        instructions.add(MDSALUtil.buildAndGetGotoTableInstruction(NwConstants.L3_FIB_TABLE, ++instructionKey));
 
         BoundServices
             serviceInfo =
@@ -305,10 +305,10 @@ public class VpnInterfaceManager extends AbstractDataChangeListener<VpnInterface
 
         // Install the flow entry in L3_INTERFACE_TABLE
         BigInteger dpId = InterfaceUtils.getDpnForInterface(interfaceManager, vpnInterfaceName);
-        String flowRef = VpnUtil.getFlowRef(dpId, VpnConstants.L3_INTERFACE_TABLE,
+        String flowRef = VpnUtil.getFlowRef(dpId, NwConstants.L3_INTERFACE_TABLE,
                     NwConstants.ETHTYPE_ARP, lPortTag, replyOrRequest.getArpOperation());
         FlowEntity flowEntity;
-        flowEntity = MDSALUtil.buildFlowEntity(dpId, VpnConstants.L3_INTERFACE_TABLE, flowRef,
+        flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_INTERFACE_TABLE, flowRef,
                 NwConstants.DEFAULT_ARP_FLOW_PRIORITY, replyOrRequest.getName(), 0, 0,
                 VpnUtil.getCookieArpFlow(lPortTag), matches, instructions);