Merge "Modified the aclservice-api.yang."
authorSam Hague <shague@redhat.com>
Mon, 20 Jun 2016 14:47:20 +0000 (14:47 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 20 Jun 2016 14:47:20 +0000 (14:47 +0000)
14 files changed:
.gitignore
vpnservice/fibmanager/fibmanager-shell/pom.xml
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronFloatingToFixedIpMappingChangeListener.java [new file with mode: 0644]
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronNetworkChangeListener.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronPortChangeListener.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronRouterChangeListener.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronSubnetChangeListener.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnManager.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnNatManager.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnProvider.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnUtils.java
vpnservice/neutronvpn/neutronvpn-shell/src/main/java/org/opendaylight/netvirt/neutronvpn/shell/DhcpConfigureCommand.java [new file with mode: 0644]
vpnservice/neutronvpn/neutronvpn-shell/src/main/java/org/opendaylight/netvirt/neutronvpn/shell/DhcpShowCommand.java [new file with mode: 0644]
vpnservice/neutronvpn/neutronvpn-shell/src/main/resources/OSGI-INF/blueprint/blueprint.xml

index 6576f6243cb3b4a5a016470b063553fa9dbe32de..a8dcb6d0a202e05d16c16fd35ac895954509536e 100755 (executable)
@@ -27,6 +27,7 @@ target-ide/
 .vagrant
 .DS_Store
 .checkstyle
+.factorypath
 yang-gen-config
 yang-gen-sal
 maven-metadata-local.xml
index 2634c9e97c15fba1b001dfff1e3422c75e70775a..69668a10659b46e83b30b8e483b6cee721d6afda 100644 (file)
@@ -30,7 +30,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       <groupId>org.apache.karaf.shell</groupId>
       <artifactId>org.apache.karaf.shell.console</artifactId>
       <version>${karaf.shell.console.version}</version>
-   </dependency>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.netvirt</groupId>
       <artifactId>fibmanager-impl</artifactId>
diff --git a/vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronFloatingToFixedIpMappingChangeListener.java b/vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronFloatingToFixedIpMappingChangeListener.java
new file mode 100644 (file)
index 0000000..d0ce8be
--- /dev/null
@@ -0,0 +1,267 @@
+/*
+ * 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.netvirt.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.genius.mdsalutil.AbstractDataChangeListener;
+import org.opendaylight.genius.mdsalutil.MDSALUtil;
+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.yang.types.rev130715.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.floatingips.attributes.Floatingips;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.floatingips.attributes.floatingips.Floatingip;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockManagerService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.FloatingIpInfo;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports
+        .PortsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports
+        .PortsKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports
+        .ports.IpMapping;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports
+        .ports.IpMappingBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports
+        .ports.IpMappingKey;
+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 NeutronFloatingToFixedIpMappingChangeListener extends AbstractDataChangeListener<Floatingip> implements
+        AutoCloseable {
+    private static final Logger LOG = LoggerFactory.getLogger(NeutronFloatingToFixedIpMappingChangeListener.class);
+
+    private ListenerRegistration<DataChangeListener> listenerRegistration;
+    private final DataBroker broker;
+    private LockManagerService lockManager;
+
+
+    public NeutronFloatingToFixedIpMappingChangeListener(final DataBroker db) {
+        super(Floatingip.class);
+        broker = db;
+        registerListener(db);
+    }
+
+    public void setLockManager(LockManagerService lockManager) {
+        this.lockManager = lockManager;
+    }
+
+    @Override
+    public void close() throws Exception {
+        if (listenerRegistration != null) {
+            try {
+                listenerRegistration.close();
+            } catch (final Exception e) {
+                LOG.error("Error when cleaning up DataChangeListener.", e);
+            }
+            listenerRegistration = null;
+        }
+        LOG.info("N_FloatingIp listener Closed");
+    }
+
+
+    private void registerListener(final DataBroker db) {
+        try {
+            listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
+                    InstanceIdentifier.create(Neutron.class).child(Floatingips.class).child(Floatingip.class),
+                    NeutronFloatingToFixedIpMappingChangeListener.this, DataChangeScope.SUBTREE);
+        } catch (final Exception e) {
+            LOG.error("NeutronVpnManager FloatingIp DataChange listener registration fail!", e);
+            throw new IllegalStateException("NeutronVpnManager FloatingIp DataChange listener registration failed.", e);
+        }
+    }
+
+    @Override
+    protected void add(InstanceIdentifier<Floatingip> identifier, Floatingip input) {
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Neutron Floating IP created: key: " + identifier + ", value=" + input);
+        }
+    }
+
+    @Override
+    protected void remove(InstanceIdentifier<Floatingip> identifier, Floatingip input) {
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Neutron Floating IP deleted : key: " + identifier + ", value=" + input);
+        }
+    }
+
+    // populate the floating to fixed ip map upon association/dissociation from fixed ip
+    @Override
+    protected void update(InstanceIdentifier<Floatingip> identifier, Floatingip original, Floatingip update) {
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Handling FloatingIptoFixedIp mapping : key: " + identifier + ", original value=" + original +
+                    ", update value=" + update);
+        }
+        IpAddress oldFixedIp = original.getFixedIpAddress();
+        IpAddress newFixedIp = update.getFixedIpAddress();
+
+        if (oldFixedIp != null && !oldFixedIp.equals(newFixedIp)) {
+            clearFromFloatingIpInfo(original.getRouterId().getValue(), original.getPortId().getValue(), oldFixedIp
+                    .getIpv4Address().getValue());
+        }
+        if (newFixedIp != null && !newFixedIp.equals(oldFixedIp)) {
+            addToFloatingIpInfo(update.getRouterId().getValue(), update.getFloatingNetworkId(), update.getPortId()
+                    .getValue(), newFixedIp.getIpv4Address().getValue(), update.getFloatingIpAddress
+                    ().getIpv4Address().getValue());
+        }
+    }
+
+    private void addToFloatingIpInfo(String routerName, Uuid extNetworkId, String fixedNeutronPortName, String
+            fixedIpAddress, String floatingIpAddress) {
+        RouterPortsBuilder routerPortsBuilder;
+        boolean isLockAcquired = false;
+        InstanceIdentifier<RouterPorts> routerPortsIdentifier = InstanceIdentifier.builder(FloatingIpInfo.class)
+                .child(RouterPorts.class, new RouterPortsKey(routerName)).build();
+        try {
+            Optional<RouterPorts> optionalRouterPorts = NeutronvpnUtils.read(broker, LogicalDatastoreType
+                    .CONFIGURATION, routerPortsIdentifier);
+            if (optionalRouterPorts.isPresent()) {
+                LOG.debug("Updating routerPorts node {} in floatingIpInfo DS for floating IP () on fixed " +
+                        "neutron port {} : ", routerName, floatingIpAddress, fixedNeutronPortName);
+                routerPortsBuilder = new RouterPortsBuilder(optionalRouterPorts.get());
+            } else {
+                LOG.debug("Creating new routerPorts node {} in floatingIpInfo DS for floating IP () on fixed " +
+                        "neutron port {} : ", routerName, floatingIpAddress, fixedNeutronPortName);
+                routerPortsBuilder = new RouterPortsBuilder().setKey(new RouterPortsKey(routerName)).setRouterId
+                        (routerName);
+            }
+            if (extNetworkId != null) {
+                routerPortsBuilder.setExternalNetworkId(extNetworkId);
+            }
+            if (fixedNeutronPortName != null) {
+                List<Ports> portsList = routerPortsBuilder.getPorts();
+                if (portsList == null) {
+                    portsList = new ArrayList<>();
+                }
+                PortsBuilder fixedNeutronPortBuilder = null;
+                for (Ports neutronPort : portsList) {
+                    if (neutronPort.getPortName().equals(fixedNeutronPortName)) {
+                        fixedNeutronPortBuilder = new PortsBuilder(neutronPort);
+                        break;
+                    }
+                }
+                if (fixedNeutronPortBuilder == null) {
+                    fixedNeutronPortBuilder = new PortsBuilder().setKey(new PortsKey(fixedNeutronPortName))
+                            .setPortName(fixedNeutronPortName);
+                }
+                if (fixedIpAddress != null) {
+                    List<IpMapping> ipMappingList = fixedNeutronPortBuilder.getIpMapping();
+                    if (ipMappingList == null) {
+                        ipMappingList = new ArrayList<>();
+                    }
+                    IpMapping ipMapping = new IpMappingBuilder().setKey(new IpMappingKey(fixedIpAddress))
+                            .setInternalIp(fixedIpAddress).setExternalIp(floatingIpAddress).setLabel(null).build();
+                    ipMappingList.add(ipMapping);
+                    fixedNeutronPortBuilder.setIpMapping(ipMappingList);
+                }
+                portsList.add(fixedNeutronPortBuilder.build());
+                routerPortsBuilder.setPorts(portsList);
+            }
+            isLockAcquired = NeutronvpnUtils.lock(lockManager, routerName);
+            LOG.debug("Creating/Updating routerPorts node {} in floatingIpInfo DS for floating IP () on fixed " +
+                    "neutron port {} : ", routerName, floatingIpAddress, fixedNeutronPortName);
+            MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifier, routerPortsBuilder
+                    .build());
+            LOG.debug("FloatingIpInfo DS updated for floating IP {} ", floatingIpAddress);
+        } catch (Exception e) {
+            LOG.error("addToFloatingIpInfo failed for floating IP: {} ", floatingIpAddress);
+        } finally {
+            if (isLockAcquired) {
+                NeutronvpnUtils.unlock(lockManager, routerName);
+            }
+        }
+    }
+
+    private void clearFromFloatingIpInfo(String routerName, String fixedNeutronPortName, String fixedIpAddress) {
+        boolean isLockAcquired = false;
+        InstanceIdentifier.InstanceIdentifierBuilder<RouterPorts> routerPortsIdentifierBuilder = InstanceIdentifier
+                .builder(FloatingIpInfo.class).child(RouterPorts.class, new RouterPortsKey(routerName));
+        try {
+            Optional<RouterPorts> optionalRouterPorts = NeutronvpnUtils.read(broker, LogicalDatastoreType
+                    .CONFIGURATION, routerPortsIdentifierBuilder.build());
+            if (optionalRouterPorts.isPresent()) {
+                RouterPorts routerPorts = optionalRouterPorts.get();
+                List<Ports> portsList = routerPorts.getPorts();
+                List<IpMapping> ipMapping = new ArrayList<>();
+                for (Ports ports : portsList) {
+                    if (ports.getPortName().equals(fixedNeutronPortName)) {
+                        ipMapping = ports.getIpMapping();
+                    }
+                }
+                InstanceIdentifier.InstanceIdentifierBuilder<Ports> portsIdentifierBuilder = null;
+                if (ipMapping.size() == 1) {
+                    if (portsList.size() == 1) {
+                        try {
+                            // remove entire routerPorts node
+                            isLockAcquired = NeutronvpnUtils.lock(lockManager, routerName);
+                            LOG.debug("removing routerPorts node: {} ", routerName);
+                            MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION,
+                                    routerPortsIdentifierBuilder.build());
+                        } catch (Exception e) {
+                            LOG.error("Failure in deletion of routerPorts node {}", routerName);
+                        } finally {
+                            if (isLockAcquired) {
+                                NeutronvpnUtils.unlock(lockManager, routerName);
+                            }
+                        }
+                    } else {
+                        portsIdentifierBuilder = routerPortsIdentifierBuilder.child(Ports.class, new PortsKey
+                                (fixedNeutronPortName));
+                        try {
+                            // remove entire ports node under this routerPorts node
+                            isLockAcquired = NeutronvpnUtils.lock(lockManager, fixedNeutronPortName);
+                            LOG.debug("removing ports node {} under routerPorts node {}", fixedNeutronPortName,
+                                    routerName);
+                            MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, portsIdentifierBuilder
+                                    .build());
+                        } catch (Exception e) {
+                            LOG.error("Failure in deletion of routerPorts node {}", routerName);
+                        } finally {
+                            if (isLockAcquired) {
+                                NeutronvpnUtils.unlock(lockManager, routerName);
+                            }
+                        }
+                    }
+                } else {
+                    InstanceIdentifier<IpMapping> ipMappingIdentifier =
+                            portsIdentifierBuilder.child(IpMapping.class, new IpMappingKey(fixedIpAddress)).build();
+                    try {
+                        // remove particular ipMapping
+                        isLockAcquired = NeutronvpnUtils.lock(lockManager, fixedIpAddress);
+                        LOG.debug("removing particular ipMapping {}", ipMapping);
+                        MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, ipMappingIdentifier);
+                    } catch (Exception e) {
+                        LOG.error("Failure in deletion of ipMapping {}", ipMapping);
+                    } finally {
+                        if (isLockAcquired) {
+                            NeutronvpnUtils.unlock(lockManager, fixedIpAddress);
+                        }
+                    }
+                }
+                LOG.debug("Deletion from FloatingIpInfo DS successful for fixedIp {} ", fixedIpAddress);
+            } else {
+                LOG.error("routerPorts for router {} not found", routerName);
+            }
+        } catch (Exception e) {
+            LOG.error("Failed to delete ipMapping from FloatingIpInfo DS for fixed Ip {}", fixedIpAddress);
+        }
+    }
+}
index 27faa88d4972ea35f0fe82bdae4ecd3d80935a3f..8413eea274f97e9c8ead5fd30b82330619ccb4b3 100644 (file)
@@ -37,13 +37,16 @@ public class NeutronNetworkChangeListener extends AbstractDataChangeListener<Net
     private final DataBroker broker;
     private NeutronvpnManager nvpnManager;
     private NeutronvpnNatManager nvpnNatManager;
+    private NeutronvpnUtils neutronvpnUtils;
 
 
-    public NeutronNetworkChangeListener(final DataBroker db, NeutronvpnManager nVpnMgr, NeutronvpnNatManager nVpnNatMgr) {
+    public NeutronNetworkChangeListener(final DataBroker db, NeutronvpnManager nVpnMgr, NeutronvpnNatManager
+            nVpnNatMgr, NeutronvpnUtils nVpnUtils) {
         super(Network.class);
         broker = db;
         nvpnManager = nVpnMgr;
         nvpnNatManager = nVpnNatMgr;
+        neutronvpnUtils = nVpnUtils;
         registerListener(db);
     }
 
@@ -79,10 +82,16 @@ public class NeutronNetworkChangeListener extends AbstractDataChangeListener<Net
         if (LOG.isTraceEnabled()) {
             LOG.trace("Adding Network : key: " + identifier + ", value=" + input);
         }
+        if (NeutronvpnUtils.isNetworkTypeVlanOrGre(input)) {
+            //FIXME: This should be removed when support for VLAN and GRE network types is added
+            LOG.error("Neutronvpn doesn't support vlan/gre network provider type for this network {}.", input);
+            return;
+        }
         //Create ELAN instance for this network
         createElanInstance(input);
         if (input.getAugmentation(NetworkL3Extension.class).isExternal()) {
             nvpnNatManager.addExternalNetwork(input);
+            neutronvpnUtils.addToNetworkCache(input);
         }
     }
 
@@ -91,10 +100,16 @@ public class NeutronNetworkChangeListener extends AbstractDataChangeListener<Net
         if (LOG.isTraceEnabled()) {
             LOG.trace("Removing Network : key: " + identifier + ", value=" + input);
         }
+        if (NeutronvpnUtils.isNetworkTypeVlanOrGre(input)) {
+            //FIXME: This should be removed when support for VLAN and GRE network types is added
+            LOG.error("Neutronvpn doesn't support vlan/gre network provider type for this network {}.", input);
+            return;
+        }
         //Delete ELAN instance for this network
         deleteElanInstance(input.getUuid().getValue());
         if (input.getAugmentation(NetworkL3Extension.class).isExternal()) {
             nvpnNatManager.removeExternalNetwork(input);
+            neutronvpnUtils.removeFromNetworkCache(input);
         }
     }
 
index d8c0c5963dd58d76e1ce5dace4b38980c2f4856f..f7135564093dd5f94287d815919eed7c9bc09045 100644 (file)
@@ -24,6 +24,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network;
 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;
@@ -62,15 +63,19 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
     private LockManagerService lockManager;
     private NotificationPublishService notificationPublishService;
     private NotificationService notificationService;
+    private NeutronvpnUtils neutronvpnUtils;
 
 
-    public NeutronPortChangeListener(final DataBroker db, NeutronvpnManager nVpnMgr,NeutronvpnNatManager nVpnNatMgr, NotificationPublishService notiPublishService, NotificationService notiService) {
+    public NeutronPortChangeListener(final DataBroker db, NeutronvpnManager nVpnMgr,NeutronvpnNatManager nVpnNatMgr,
+                                     NotificationPublishService notiPublishService, NotificationService notiService,
+                                     NeutronvpnUtils nVpnUtils) {
         super(Port.class);
         broker = db;
         nvpnManager = nVpnMgr;
         nvpnNatManager = nVpnNatMgr;
         notificationPublishService = notiPublishService;
         notificationService = notiService;
+        neutronvpnUtils = nVpnUtils;
         registerListener(db);
     }
 
@@ -108,7 +113,13 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
         if (LOG.isTraceEnabled()) {
             LOG.trace("Adding Port : key: " + identifier + ", value=" + input);
         }
-
+        Network network = NeutronvpnUtils.getNeutronNetwork(broker, input.getNetworkId());
+        if (network == null || NeutronvpnUtils.isNetworkTypeVlanOrGre(network)) {
+            //FIXME: This should be removed when support for VLAN and GRE network types is added
+            LOG.error("neutron vpn doesn't support vlan/gre network provider type for the port {} which is part of network {}.",
+                    input.getName(), network);
+            return;
+        }
         /* check if router interface has been created */
         if ((input.getDeviceOwner() != null) && (input.getDeviceId() != null)) {
             if (input.getDeviceOwner().equals(NeutronvpnUtils.DEVICE_OWNER_ROUTER_INF)) {
@@ -118,6 +129,7 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
             }
         }
         handleNeutronPortCreated(input);
+        neutronvpnUtils.addToPortCache(input);
 
     }
 
@@ -126,7 +138,13 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
         if (LOG.isTraceEnabled()) {
             LOG.trace("Removing Port : key: " + identifier + ", value=" + input);
         }
-
+        Network network = NeutronvpnUtils.getNeutronNetwork(broker, input.getNetworkId());
+        if (network == null || NeutronvpnUtils.isNetworkTypeVlanOrGre(network)) {
+            //FIXME: This should be removed when support for VLAN and GRE network types is added
+            LOG.error("neutron vpn doesn't support vlan/gre network provider type for the port {} which is part of network {}.",
+                    input.getName(), network);
+            return;
+        }
         if ((input.getDeviceOwner() != null) && (input.getDeviceId() != null)) {
             if (input.getDeviceOwner().equals(NeutronvpnUtils.DEVICE_OWNER_ROUTER_INF)) {
                 handleRouterInterfaceRemoved(input);
@@ -135,6 +153,7 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
             }
         }
         handleNeutronPortDeleted(input);
+        neutronvpnUtils.removeFromPortCache(input);
 
     }
 
@@ -145,8 +164,14 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
                     update);
         }
 
-        List<FixedIps> oldIPs = (original.getFixedIps() != null) ? original.getFixedIps() : new ArrayList<>();
-        List<FixedIps> newIPs = (update.getFixedIps() != null) ? update.getFixedIps() : new ArrayList<>();
+        Network network = NeutronvpnUtils.getNeutronNetwork(broker, update.getNetworkId());
+        if (network == null || NeutronvpnUtils.isNetworkTypeVlanOrGre(network)) {
+            LOG.error("neutron vpn doesn't support vlan/gre network provider type for the port {} which is part of network {}."
+                    + " Skipping the processing of Port update DCN", update.getName(), network);
+            return;
+        }
+        List<FixedIps> oldIPs = (original.getFixedIps() != null) ? original.getFixedIps() : new ArrayList<FixedIps>();
+        List<FixedIps> newIPs = (update.getFixedIps() != null) ? update.getFixedIps() : new ArrayList<FixedIps>();
 
         /* check if router interface has been updated */
         if ((update.getDeviceOwner() != null) && (update.getDeviceId() != null)) {
@@ -166,6 +191,7 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
                 }
             }
             handleNeutronPortUpdated(original, update);
+            neutronvpnUtils.addToPortCache(update);
         }
     }
 
index b2a7a3ce79f5cbf7a2b84878ccaeb8812a9c513d..fa2b6f87af72f104af04f1427465857ef3b7fcae 100644 (file)
@@ -33,13 +33,16 @@ public class NeutronRouterChangeListener extends AbstractDataChangeListener<Rout
     private final DataBroker broker;
     private NeutronvpnManager nvpnManager;
     private NeutronvpnNatManager nvpnNatManager;
+    private NeutronvpnUtils neutronvpnUtils;
 
 
-    public NeutronRouterChangeListener(final DataBroker db, NeutronvpnManager nVpnMgr, NeutronvpnNatManager nVpnNatMgr) {
+    public NeutronRouterChangeListener(final DataBroker db, NeutronvpnManager nVpnMgr, NeutronvpnNatManager
+            nVpnNatMgr, NeutronvpnUtils nVpnUtils) {
         super(Router.class);
         broker = db;
         nvpnManager = nVpnMgr;
         nvpnNatManager = nVpnNatMgr;
+        neutronvpnUtils = nVpnUtils;
         registerListener(db);
     }
 
@@ -75,6 +78,7 @@ public class NeutronRouterChangeListener extends AbstractDataChangeListener<Rout
         }
         // Create internal VPN
         nvpnManager.createL3Vpn(input.getUuid(), null, null, null, null, null, input.getUuid(), null);
+        neutronvpnUtils.addToRouterCache(input);
     }
 
     @Override
@@ -87,6 +91,7 @@ public class NeutronRouterChangeListener extends AbstractDataChangeListener<Rout
         //will be removed from VPN by invocations from NeutronPortChangeListener
         List<Uuid> routerSubnetIds = new ArrayList<>();
         nvpnManager.handleNeutronRouterDeleted(routerId, routerSubnetIds);
+        neutronvpnUtils.removeFromRouterCache(input);
         // Handle router deletion for the NAT service
         if (input.getExternalGatewayInfo() != null) {
             Uuid extNetId = input.getExternalGatewayInfo().getExternalNetworkId();
index a469161ecd132177ed68902b0db32927362f513c..5040c523461f92e30dfeca7d4c73305c3cb22792 100644 (file)
@@ -16,6 +16,7 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.mdsalutil.AbstractDataChangeListener;
 import org.opendaylight.genius.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.networks.rev150712.networks.attributes.networks.Network;
 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;
@@ -37,12 +38,14 @@ public class NeutronSubnetChangeListener extends AbstractDataChangeListener<Subn
     private ListenerRegistration<DataChangeListener> listenerRegistration;
     private final DataBroker broker;
     private NeutronvpnManager nvpnManager;
+    private NeutronvpnUtils neutronvpnUtils;
 
 
-    public NeutronSubnetChangeListener(final DataBroker db, NeutronvpnManager nVpnMgr) {
+    public NeutronSubnetChangeListener(final DataBroker db, NeutronvpnManager nVpnMgr, NeutronvpnUtils nVpnUtils) {
         super(Subnet.class);
         broker = db;
         nvpnManager = nVpnMgr;
+        neutronvpnUtils = nVpnUtils;
         registerListener(db);
     }
 
@@ -76,7 +79,16 @@ public class NeutronSubnetChangeListener extends AbstractDataChangeListener<Subn
         if (LOG.isTraceEnabled()) {
             LOG.trace("Adding Subnet : key: " + identifier + ", value=" + input);
         }
-        handleNeutronSubnetCreated(input.getUuid(), input.getCidr(), input.getNetworkId(), input.getTenantId());
+        Uuid networkId = input.getNetworkId();
+        Network network = NeutronvpnUtils.getNeutronNetwork(broker, networkId);
+        if (network == null || NeutronvpnUtils.isNetworkTypeVlanOrGre(network)) {
+            //FIXME: This should be removed when support for VLAN and GRE network types is added
+            LOG.error("neutron vpn doesn't support vlan/gre network provider type for the port {} which is part of network {}.",
+                    input.getName(), network);
+            return;
+        }
+        handleNeutronSubnetCreated(input.getUuid(), input.getCidr(), networkId, input.getTenantId());
+        neutronvpnUtils.addToSubnetCache(input);
     }
 
     @Override
@@ -84,7 +96,16 @@ public class NeutronSubnetChangeListener extends AbstractDataChangeListener<Subn
         if (LOG.isTraceEnabled()) {
             LOG.trace("Removing subnet : key: " + identifier + ", value=" + input);
         }
-        handleNeutronSubnetDeleted(input.getUuid(), input.getNetworkId(), null);
+        Uuid networkId = input.getNetworkId();
+        Network network = NeutronvpnUtils.getNeutronNetwork(broker, networkId);
+        if (network == null || NeutronvpnUtils.isNetworkTypeVlanOrGre(network)) {
+            //FIXME: This should be removed when support for VLAN and GRE network types is added
+            LOG.error("neutron vpn doesn't support vlan/gre network provider type for the port {} which is part of network {}.",
+                    input.getName(), network);
+            return;
+        }
+        handleNeutronSubnetDeleted(input.getUuid(), networkId, null);
+        neutronvpnUtils.removeFromSubnetCache(input);
     }
 
     @Override
@@ -93,12 +114,20 @@ public class NeutronSubnetChangeListener extends AbstractDataChangeListener<Subn
             LOG.trace("Updating Subnet : key: " + identifier + ", original value=" + original + ", update value=" +
                     update);
         }
-        handleNeutronSubnetUpdated(update.getUuid(), update.getNetworkId(), update.getTenantId());
+        Uuid networkId = update.getNetworkId();
+        Network network = NeutronvpnUtils.getNeutronNetwork(broker, networkId);
+        if (network == null || NeutronvpnUtils.isNetworkTypeVlanOrGre(network)) {
+            LOG.error("neutron vpn doesn't support vlan/gre network provider type for the port {} which is part of network {}."
+                    + " Skipping the processing of Subnet update DCN", update.getName(), network);
+            return;
+        }
+        handleNeutronSubnetUpdated(update.getUuid(), networkId, update.getTenantId());
+        neutronvpnUtils.addToSubnetCache(update);
     }
 
     private void handleNeutronSubnetCreated(Uuid subnetId, String subnetIp, Uuid networkId, Uuid tenantId) {
         nvpnManager.updateSubnetNode(subnetId, subnetIp, tenantId, networkId, null, null, null);
-        if (networkId != null && NeutronvpnUtils.getNeutronNetwork(broker, networkId) != null) {
+        if (networkId != null) {
             createSubnetToNetworkMapping(subnetId, networkId);
         }
     }
index 8fbfbcb622f69c4c4ff7b68b215a6ee59c66db99..0561d7fa5913490e37f9a45d79dd7bbf929919d3 100644 (file)
@@ -86,6 +86,7 @@ import org.slf4j.LoggerFactory;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 
@@ -98,6 +99,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable , Eve
     IMdsalApiManager mdsalUtil;
     private NotificationPublishService notificationPublishService;
     private NotificationService notificationService;
+    private NeutronvpnUtils neutronvpnUtils;
     Boolean isExternalVpn;
 
     /**
@@ -105,12 +107,14 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable , Eve
      * @param mdsalManager - MDSAL Util API access
      */
     public NeutronvpnManager(final DataBroker db, IMdsalApiManager mdsalManager,NotificationPublishService notiPublishService,
-                             NotificationService notiService, NeutronvpnNatManager vpnNatMgr) {
+                             NotificationService notiService, NeutronvpnNatManager vpnNatMgr, NeutronvpnUtils
+                                     nVpnUtils) {
         broker = db;
         mdsalUtil = mdsalManager;
         nvpnNatManager = vpnNatMgr;
         notificationPublishService = notiPublishService;
         notificationService = notiService;
+        neutronvpnUtils = nVpnUtils;
     }
 
     public void setLockManager(LockManagerService lockManager) {
@@ -1394,19 +1398,12 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable , Eve
         deleteVpnInstance(routerId);
     }
 
-    protected Subnet getNeutronSubnet(Uuid subnetId) {
-        InstanceIdentifier<Subnet> inst = InstanceIdentifier.create(Neutron.class).
-                child(Subnets.class).child(Subnet.class, new SubnetKey(subnetId));
-        Optional<Subnet> sn = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, inst);
-
-        if (sn.isPresent()) {
-            return sn.get();
-        }
-        return null;
+    protected Subnet getNeutronSubnet(Uuid subnetId){
+        return NeutronvpnUtils.getNeutronSubnet(broker, subnetId);
     }
 
     protected IpAddress getNeutronSubnetGateway(Uuid subnetId) {
-        Subnet sn = getNeutronSubnet(subnetId);
+        Subnet sn = NeutronvpnUtils.getNeutronSubnet(broker, subnetId);
         if (null != sn) {
             return sn.getGatewayIp();
         }
index e0f44083a344a23e30995ddec4022f6ffe81a9ae..41f78d2e374b077ddab735cbd4a0838ea221bdc0 100644 (file)
@@ -167,12 +167,12 @@ public class NeutronvpnNatManager implements AutoCloseable {
             List<ExternalFixedIps> orig_ext_fixed_ips = orig_ext_gw.getExternalFixedIps();
             HashSet<String> orig_fixed_ip_set = new HashSet<String>();
             for (ExternalFixedIps fixed_ip: orig_ext_fixed_ips) {
-                orig_fixed_ip_set.add(fixed_ip.getIpAddress().toString());
+                orig_fixed_ip_set.add(fixed_ip.getIpAddress().getIpv4Address().getValue());
             }
             HashSet<String> upd_fixed_ip_set = new HashSet<String>();
             List<ExternalFixedIps> new_ext_fixed_ips = new_ext_gw.getExternalFixedIps();
             for (ExternalFixedIps fixed_ip: new_ext_fixed_ips) {
-                upd_fixed_ip_set.add(fixed_ip.getIpAddress().toString());
+                upd_fixed_ip_set.add(fixed_ip.getIpAddress().getIpv4Address().getValue());
             }
 
             if (!orig_fixed_ip_set.equals(upd_fixed_ip_set)) {
@@ -442,7 +442,7 @@ public class NeutronvpnNatManager implements AutoCloseable {
             if (builder != null) {
                 ArrayList<String> ext_fixed_ips = new ArrayList<String>();
                 for (ExternalFixedIps fixed_ips : update.getExternalGatewayInfo().getExternalFixedIps()) {
-                    ext_fixed_ips.add(fixed_ips.getIpAddress().toString());
+                    ext_fixed_ips.add(fixed_ips.getIpAddress().getIpv4Address().getValue());
                 }
                 builder.setExternalIps(ext_fixed_ips);
             }
@@ -507,7 +507,7 @@ public class NeutronvpnNatManager implements AutoCloseable {
                 if (builder != null) {
                     ArrayList<String> ext_fixed_ips = new ArrayList<String>();
                     for (ExternalFixedIps fixed_ips : update.getExternalGatewayInfo().getExternalFixedIps()) {
-                        ext_fixed_ips.add(fixed_ips.getIpAddress().toString());
+                        ext_fixed_ips.add(fixed_ips.getIpAddress().getIpv4Address().getValue());
                     }
                     builder.setExternalIps(ext_fixed_ips);
                 }
index 3d731ae5d26a81e0f90d857601c1494082149091..d5bebb3b7e4dbcbf53cb71a7418740ef5b8b8ac8 100644 (file)
@@ -34,6 +34,7 @@ public class NeutronvpnProvider implements BindingAwareProvider, INeutronVpnMana
     private static final Logger LOG = LoggerFactory.getLogger(NeutronvpnProvider.class);
     private NeutronvpnManager nvManager;
     private NeutronvpnNatManager nvNatManager;
+    private NeutronvpnUtils nVpnUtils;
     private IMdsalApiManager mdsalManager;
     private LockManagerService lockManager;
     private NeutronBgpvpnChangeListener bgpvpnListener;
@@ -41,11 +42,13 @@ public class NeutronvpnProvider implements BindingAwareProvider, INeutronVpnMana
     private NeutronSubnetChangeListener subnetListener;
     private NeutronRouterChangeListener routerListener;
     private NeutronPortChangeListener portListener;
+    private NeutronFloatingToFixedIpMappingChangeListener floatingIpMapListener;
     private RpcProviderRegistry rpcProviderRegistry;
     private L2GatewayProvider l2GatewayProvider;
     private NotificationPublishService notificationPublishService;
     private NotificationService notificationService;
     private EntityOwnershipService entityOwnershipService;
+    private DataBroker broker;
 
     public NeutronvpnProvider(RpcProviderRegistry rpcRegistry,NotificationPublishService notificationPublishService,
                               NotificationService notificationService) {
@@ -79,18 +82,22 @@ public class NeutronvpnProvider implements BindingAwareProvider, INeutronVpnMana
         try {
             final DataBroker dbx = session.getSALService(DataBroker.class);
             nvNatManager = new NeutronvpnNatManager(dbx, mdsalManager);
-            nvManager = new NeutronvpnManager(dbx, mdsalManager,notificationPublishService,notificationService, nvNatManager);
+            nvManager = new NeutronvpnManager(dbx, mdsalManager,notificationPublishService,notificationService,
+                    nvNatManager, nVpnUtils);
             final BindingAwareBroker.RpcRegistration<NeutronvpnService> rpcRegistration =
                     getRpcProviderRegistry().addRpcImplementation(NeutronvpnService.class, nvManager);
             bgpvpnListener = new NeutronBgpvpnChangeListener(dbx, nvManager);
-            networkListener = new NeutronNetworkChangeListener(dbx, nvManager, nvNatManager);
-            subnetListener = new NeutronSubnetChangeListener(dbx, nvManager);
-            routerListener = new NeutronRouterChangeListener(dbx, nvManager, nvNatManager);
+            networkListener = new NeutronNetworkChangeListener(dbx, nvManager, nvNatManager, nVpnUtils);
+            subnetListener = new NeutronSubnetChangeListener(dbx, nvManager, nVpnUtils);
+            routerListener = new NeutronRouterChangeListener(dbx, nvManager, nvNatManager, nVpnUtils);
             portListener = new NeutronPortChangeListener(dbx, nvManager, nvNatManager,
-                    notificationPublishService,notificationService);
+                    notificationPublishService,notificationService, nVpnUtils);
             portListener.setLockManager(lockManager);
             portListener.setLockManager(lockManager);
+            floatingIpMapListener = new NeutronFloatingToFixedIpMappingChangeListener(dbx);
             nvManager.setLockManager(lockManager);
+            portListener.setLockManager(lockManager);
+            floatingIpMapListener.setLockManager(lockManager);
             l2GatewayProvider = new L2GatewayProvider(dbx, rpcProviderRegistry, entityOwnershipService);
 
             LOG.info("NeutronvpnProvider Session Initiated");
@@ -105,6 +112,7 @@ public class NeutronvpnProvider implements BindingAwareProvider, INeutronVpnMana
         subnetListener.close();
         routerListener.close();
         networkListener.close();
+        floatingIpMapListener.close();
         bgpvpnListener.close();
         nvManager.close();
         l2GatewayProvider.close();
@@ -148,7 +156,7 @@ public class NeutronvpnProvider implements BindingAwareProvider, INeutronVpnMana
 
     @Override
     public Subnet getNeutronSubnet(Uuid subnetId) {
-        return nvManager.getNeutronSubnet(subnetId);
+        return nVpnUtils.getNeutronSubnet(broker, subnetId);
     }
 
     @Override
index 33d691f7180191341a6442507d2480678e72ecf6..5a298c8196d7e5fe49ff1671a60cd76498fd6fcd 100644 (file)
@@ -23,6 +23,9 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.RouterKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.NetworkTypeBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.NetworkTypeGre;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.NetworkTypeVlan;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.Networks;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.NetworkKey;
@@ -30,6 +33,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.por
 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.ports.rev150712.ports.attributes.ports.PortKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.NetworkProviderExtension;
 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;
@@ -62,6 +66,7 @@ import org.slf4j.LoggerFactory;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 
@@ -70,6 +75,10 @@ public class NeutronvpnUtils {
     private static final Logger logger = LoggerFactory.getLogger(NeutronvpnUtils.class);
     public static final String DEVICE_OWNER_ROUTER_INF = "network:router_interface";
     public static final String VNIC_TYPE_NORMAL = "normal";
+    public static ConcurrentHashMap<Uuid, Network> networkMap = new ConcurrentHashMap<Uuid, Network>();
+    public static ConcurrentHashMap<Uuid, Router> routerMap = new ConcurrentHashMap<Uuid, Router>();
+    public static ConcurrentHashMap<Uuid, Port> portMap = new ConcurrentHashMap<Uuid, Port>();
+    public static ConcurrentHashMap<Uuid, Subnet> subnetMap = new ConcurrentHashMap<Uuid, Subnet>();
 
     protected static Subnetmap getSubnetmap(DataBroker broker, Uuid subnetId) {
         InstanceIdentifier id = buildSubnetMapIdentifier(subnetId);
@@ -164,25 +173,34 @@ public class NeutronvpnUtils {
     }
 
     protected static Router getNeutronRouter(DataBroker broker, Uuid routerId) {
-
+        Router router = null;
+        router = routerMap.get(routerId);
+        if (router != null) {
+            return router;
+        }
         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();
+            router = rtr.get();
         }
-        return null;
+        return router;
     }
 
     protected static Network getNeutronNetwork(DataBroker broker, Uuid networkId) {
+        Network network = null;
+        network = networkMap.get(networkId);
+        if (network != null) {
+            return network;
+        }
         logger.debug("getNeutronNetwork for {}", networkId.getValue());
         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();
+            network = net.get();
         }
-        return null;
+        return network;
     }
 
     protected static List<Uuid> getNeutronRouterSubnetIds(DataBroker broker, Uuid routerId) {
@@ -190,7 +208,7 @@ public class NeutronvpnUtils {
 
         List<Uuid> subnetIdList = new ArrayList<>();
         Ports ports = getNeutrounPorts(broker);
-        if(ports != null && ports.getPort() != null) {
+        if (ports != null && ports.getPort() != null) {
             for (Port port: ports.getPort()) {
                 if ((port.getDeviceOwner() != null) && (port.getDeviceId() != null)) {
                     if (port.getDeviceOwner().equals(DEVICE_OWNER_ROUTER_INF) &&
@@ -220,21 +238,42 @@ public class NeutronvpnUtils {
     protected static Ports getNeutrounPorts(DataBroker broker) {
         InstanceIdentifier<Ports> inst = InstanceIdentifier.create(Neutron.class).child(Ports.class);
         Optional<Ports> ports = read(broker, LogicalDatastoreType.CONFIGURATION, inst);
-        if(ports.isPresent()) {
+        if (ports.isPresent()) {
             return ports.get();
         }
         return null;
     }
 
     protected static Port getNeutronPort(DataBroker broker, Uuid portId) {
+        Port prt = null;
+        prt = portMap.get(portId);
+        if (prt != null) {
+            return prt;
+        }
         logger.debug("getNeutronPort for {}", portId.getValue());
         InstanceIdentifier<Port> inst = InstanceIdentifier.create(Neutron.class).child(Ports.class).child(Port.class,
                 new PortKey(portId));
         Optional<Port> port = read(broker, LogicalDatastoreType.CONFIGURATION, inst);
         if (port.isPresent()) {
-            return port.get();
+            prt = port.get();
         }
-        return null;
+        return prt;
+    }
+
+    protected static Subnet getNeutronSubnet(DataBroker broker, Uuid subnetId) {
+        Subnet subnet = null;
+        subnet = subnetMap.get(subnetId);
+        if (subnet != null) {
+            return subnet;
+        }
+        InstanceIdentifier<Subnet> inst = InstanceIdentifier.create(Neutron.class).
+                child(Subnets.class).child(Subnet.class, new SubnetKey(subnetId));
+        Optional<Subnet> sn = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, inst);
+
+        if (sn.isPresent()) {
+            subnet = sn.get();
+        }
+        return subnet;
     }
 
     protected static String uuidToTapPortName(Uuid id) {
@@ -310,6 +349,38 @@ public class NeutronvpnUtils {
         return null;
     }
 
+    public static void addToNetworkCache(Network network) {
+        networkMap.put(network.getUuid(),network);
+    }
+
+    public static void removeFromNetworkCache(Network network) {
+        networkMap.remove(network.getUuid());
+    }
+
+    public static void addToRouterCache(Router router) {
+        routerMap.put(router.getUuid(),router);
+    }
+
+    public static void removeFromRouterCache(Router router) {
+        routerMap.remove(router.getUuid());
+    }
+
+    public static void addToPortCache(Port port) {
+        portMap.put(port.getUuid(),port);
+    }
+
+    public static void removeFromPortCache(Port port) {
+        portMap.remove(port.getUuid());
+    }
+
+    public static void addToSubnetCache(Subnet subnet) {
+        subnetMap.put(subnet.getUuid(),subnet);
+    }
+
+    public static void removeFromSubnetCache(Subnet subnet) {
+        subnetMap.remove(subnet.getUuid());
+    }
+
     static InstanceIdentifier<PortFixedipToPortName> buildFixedIpToPortNameIdentifier(String fixedIp) {
         InstanceIdentifier<PortFixedipToPortName> id = InstanceIdentifier.builder(NeutronPortData.class).child
                 (PortFixedipToPortName.class, new PortFixedipToPortNameKey(fixedIp)).build();
@@ -354,4 +425,16 @@ public class NeutronvpnUtils {
 
         return result;
     }
+
+    static boolean isNetworkTypeVlanOrGre(Network network) {
+        NetworkProviderExtension npe = network.getAugmentation(NetworkProviderExtension.class);
+        if (npe != null) {
+            Class<? extends NetworkTypeBase> networkTypeBase = npe.getNetworkType();
+            if (networkTypeBase.isAssignableFrom(NetworkTypeVlan.class) || networkTypeBase.isAssignableFrom(NetworkTypeGre.class)) {
+                logger.trace("Network is of type {}", networkTypeBase);
+                return true;
+            }
+        }
+        return false;
+    }
 }
diff --git a/vpnservice/neutronvpn/neutronvpn-shell/src/main/java/org/opendaylight/netvirt/neutronvpn/shell/DhcpConfigureCommand.java b/vpnservice/neutronvpn/neutronvpn-shell/src/main/java/org/opendaylight/netvirt/neutronvpn/shell/DhcpConfigureCommand.java
new file mode 100644 (file)
index 0000000..c3e2d08
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ * 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.netvirt.neutronvpn.shell;
+
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DhcpConfig;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DhcpConfigBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.dhcp.config.Configs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.dhcp.config.ConfigsBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+
+@Command(scope = "vpnservice", name = "dhcp-configure", description = "configuring parameters for DHCP Service")
+public class DhcpConfigureCommand extends OsgiCommandSupport {
+
+    final Logger Logger = LoggerFactory.getLogger(DhcpConfigureCommand.class);
+
+    @Option(name = "-ld", aliases = {"--leaseDuration"}, description = "Lease Duration", required = false, multiValued = false)
+    Integer leaseDuration;
+
+    @Option(name = "-dd", aliases = {"--defaultDomain"}, description = "Default Domain", required = false, multiValued = false)
+    String defaultDomain;
+
+    private DataBroker dataBroker;
+    private final String defDomain = "openstacklocal";
+    private final Integer defLeaseDuration = 86400;
+
+    public void setDataBroker(DataBroker broker) {
+        this.dataBroker = broker;
+    }
+
+    @Override
+    protected Object doExecute() throws Exception {
+        try {
+            if ((defaultDomain == null) && (leaseDuration == null)) {
+                System.out.println(getHelp());
+                return null;
+            }
+            Integer currLeaseDuration = defLeaseDuration;
+            String currDefDomain = defDomain;
+            DhcpConfigBuilder dcBuilder = new DhcpConfigBuilder();
+            ConfigsBuilder dccBuilder = new ConfigsBuilder();
+            InstanceIdentifier<DhcpConfig> iid = InstanceIdentifier.create(DhcpConfig.class);
+            DhcpConfig currentConfig = read(iid);
+            if (currentConfig != null && currentConfig.getConfigs() != null &&
+                    !currentConfig.getConfigs().isEmpty()) {
+                Configs dhcpConfig = currentConfig.getConfigs().get(0);
+                if (dhcpConfig.getLeaseDuration() != null) {
+                    currLeaseDuration = dhcpConfig.getLeaseDuration();
+                }
+                if (dhcpConfig.getDefaultDomain() != null) {
+                    currDefDomain = dhcpConfig.getDefaultDomain();
+                }
+            }
+
+            dccBuilder.setLeaseDuration((leaseDuration == null) ? currLeaseDuration : leaseDuration);
+            dccBuilder.setDefaultDomain((defaultDomain == null) ? currDefDomain : defaultDomain);
+
+            List<Configs> configList = Arrays.asList(dccBuilder.build());
+            dcBuilder.setConfigs(configList);
+            write(iid, dcBuilder.build());
+        } catch (Exception e) {
+            System.out.println("Failed to configure. Try again");
+            Logger.error ("Failed to configure DHCP parameters",e);
+        }
+        return null;
+    }
+
+    private void write(InstanceIdentifier<DhcpConfig> iid, DhcpConfig dhcpConfig) {
+        WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
+        tx.put(LogicalDatastoreType.CONFIGURATION, iid, dhcpConfig);
+        CheckedFuture<Void, TransactionCommitFailedException> futures = tx.submit();
+        try {
+            futures.get();
+        } catch (InterruptedException | ExecutionException e) {
+            Logger.error("Error writing to datastore (path, data) : ({}, {})", iid, dhcpConfig);
+            throw new RuntimeException(e.getMessage());
+        }
+    }
+
+    private DhcpConfig read(InstanceIdentifier<DhcpConfig> iid) {
+
+        ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();
+        Optional<DhcpConfig> result = Optional.absent();
+        try {
+            result = tx.read(LogicalDatastoreType.CONFIGURATION, iid).get();
+        } catch (Exception e) {
+            Logger.debug("DhcpConfig not present");
+            return null;
+        }
+        if (result.isPresent()) {
+            return result.get();
+        }
+        return null;
+    }
+
+    private String getHelp() {
+        StringBuilder help = new StringBuilder("Usage: ");
+
+        help.append("exec dhcp-configure ");
+        help.append("[-ld/--leaseDuration leaseTime] [-dd/--defaultDomain defaultDomain]");
+        return help.toString();
+    }
+
+}
diff --git a/vpnservice/neutronvpn/neutronvpn-shell/src/main/java/org/opendaylight/netvirt/neutronvpn/shell/DhcpShowCommand.java b/vpnservice/neutronvpn/neutronvpn-shell/src/main/java/org/opendaylight/netvirt/neutronvpn/shell/DhcpShowCommand.java
new file mode 100644 (file)
index 0000000..e6ebc76
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * 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.netvirt.neutronvpn.shell;
+
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DhcpConfig;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Optional;
+
+@Command(scope = "vpnservice", name = "dhcp-show", description = "showing parameters for DHCP Service")
+public class DhcpShowCommand extends OsgiCommandSupport {
+
+    final Logger Logger = LoggerFactory.getLogger(DhcpShowCommand.class);
+
+
+    private DataBroker dataBroker;
+    Integer leaseDuration = null;
+    String defDomain = null;
+
+    public void setDataBroker(DataBroker broker) {
+        this.dataBroker = broker;
+    }
+
+    @Override
+    protected Object doExecute() throws Exception {
+        try {
+            InstanceIdentifier<DhcpConfig> iid = InstanceIdentifier.create(DhcpConfig.class);
+            DhcpConfig dhcpConfig = read(iid);
+            if (dhcpConfig == null || dhcpConfig.getConfigs() == null) {
+                //TODO: Should we print the defaults?
+                System.out.println("Failed to get DHCP Configuration. Try again");
+                return null;
+            }
+            if (!dhcpConfig.getConfigs().isEmpty()) {
+                leaseDuration = dhcpConfig.getConfigs().get(0).getLeaseDuration();
+                defDomain = dhcpConfig.getConfigs().get(0).getDefaultDomain();
+            }
+            System.out.println("Lease Duration: " + ((leaseDuration != null) ? leaseDuration:86400));
+            System.out.println("Default Domain: " + ((defDomain != null) ? defDomain:"openstacklocal"));
+        } catch (Exception e) {
+            System.out.println("Failed to fetch configuration parameters. Try again");
+            Logger.error("Failed to fetch DHCP parameters",e);
+        }
+        return null;
+    }
+
+    private DhcpConfig read(InstanceIdentifier<DhcpConfig> iid) {
+
+        ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();
+        Optional<DhcpConfig> result = Optional.absent();
+        try {
+            result = tx.read(LogicalDatastoreType.CONFIGURATION, iid).get();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        if (result.isPresent()) {
+            return result.get();
+        }
+        return null;
+    }
+
+}
index 68f3270ef0e1ce2e2a1330400cc8ddd30a117d8f..ce47c5525ab82d8fbcc8842fa9a4e8a4d30ce940 100644 (file)
@@ -14,6 +14,8 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
                availability="optional"/>
     <reference id="rpcRegistryRef" interface="org.opendaylight.controller.sal.binding.api.RpcProviderRegistry"
                availability="optional"/>
+    <reference id="dataBrokerRef" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"
+               availability="optional"/>
     <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
 
         <command>
@@ -35,6 +37,18 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
             </action>
         </command>
 
+        <command>
+            <action class="org.opendaylight.vpnservice.neutronvpn.shell.DhcpConfigureCommand">
+                <property name="dataBroker" ref="dataBrokerRef"/>
+            </action>
+        </command>
+
+        <command>
+            <action class="org.opendaylight.vpnservice.neutronvpn.shell.DhcpShowCommand">
+                <property name="dataBroker" ref="dataBrokerRef"/>
+            </action>
+        </command>
+
     </command-bundle>
 
 </blueprint>