.vagrant
.DS_Store
.checkstyle
+.factorypath
yang-gen-config
yang-gen-sal
maven-metadata-local.xml
<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>
--- /dev/null
+/*
+ * 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);
+ }
+ }
+}
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);
}
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);
}
}
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);
}
}
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;
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);
}
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)) {
}
}
handleNeutronPortCreated(input);
+ neutronvpnUtils.addToPortCache(input);
}
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);
}
}
handleNeutronPortDeleted(input);
+ neutronvpnUtils.removeFromPortCache(input);
}
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)) {
}
}
handleNeutronPortUpdated(original, update);
+ neutronvpnUtils.addToPortCache(update);
}
}
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);
}
}
// Create internal VPN
nvpnManager.createL3Vpn(input.getUuid(), null, null, null, null, null, input.getUuid(), null);
+ neutronvpnUtils.addToRouterCache(input);
}
@Override
//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();
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;
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);
}
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
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
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);
}
}
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;
IMdsalApiManager mdsalUtil;
private NotificationPublishService notificationPublishService;
private NotificationService notificationService;
+ private NeutronvpnUtils neutronvpnUtils;
Boolean isExternalVpn;
/**
* @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) {
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();
}
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)) {
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);
}
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);
}
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;
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) {
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");
subnetListener.close();
routerListener.close();
networkListener.close();
+ floatingIpMapListener.close();
bgpvpnListener.close();
nvManager.close();
l2GatewayProvider.close();
@Override
public Subnet getNeutronSubnet(Uuid subnetId) {
- return nvManager.getNeutronSubnet(subnetId);
+ return nVpnUtils.getNeutronSubnet(broker, subnetId);
}
@Override
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;
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;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
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);
}
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) {
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) &&
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) {
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();
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;
+ }
}
--- /dev/null
+/*
+ * 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();
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
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>
</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>