From: Vishal Thapar Date: Tue, 12 Jan 2016 18:57:34 +0000 (+0100) Subject: Misc changes to use neutronvpn for dhcpservice X-Git-Tag: release/beryllium~60^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=vpnservice.git;a=commitdiff_plain;h=refs%2Fchanges%2F39%2F32439%2F3 Misc changes to use neutronvpn for dhcpservice Adds code to use neutronvpn APIs to get Port and Subnet info Adds dhcp-config parameters to neutronvpn yang file to persist dhcp configuration Fix namespace issue in ITM causing bundle failure TODO: Clustering support Change-Id: Ica57dc4d742333996804295e4b4ec80916c7a9ee Signed-off-by: Vishal Thapar --- diff --git a/dhcpservice/dhcpservice-api/src/main/java/org/opendaylight/vpnservice/dhcpservice/api/DHCPMConstants.java b/dhcpservice/dhcpservice-api/src/main/java/org/opendaylight/vpnservice/dhcpservice/api/DHCPMConstants.java index 9da75e9d..bcf8612d 100644 --- a/dhcpservice/dhcpservice-api/src/main/java/org/opendaylight/vpnservice/dhcpservice/api/DHCPMConstants.java +++ b/dhcpservice/dhcpservice-api/src/main/java/org/opendaylight/vpnservice/dhcpservice/api/DHCPMConstants.java @@ -34,4 +34,5 @@ public final class DHCPMConstants { public static final short dhcpServerPort = 67; public static final int DEFAULT_LEASE_TIME = 86400; + public static final String DEFAULT_DOMAIN_NAME = "openstacklocal"; } diff --git a/dhcpservice/dhcpservice-impl/pom.xml b/dhcpservice/dhcpservice-impl/pom.xml index d6c1c00e..862601fd 100644 --- a/dhcpservice/dhcpservice-impl/pom.xml +++ b/dhcpservice/dhcpservice-impl/pom.xml @@ -40,6 +40,16 @@ and is available at http://www.eclipse.org/legal/epl-v10.html mdsalutil-api ${vpnservices.version} + + ${project.groupId} + neutronvpn-api + ${vpnservices.version} + + + org.apache.karaf.shell + org.apache.karaf.shell.console + ${karaf.shell.console.version} + org.opendaylight.neutron model diff --git a/dhcpservice/dhcpservice-impl/src/main/config/default-config.xml b/dhcpservice/dhcpservice-impl/src/main/config/default-config.xml index 64b2bfaa..fe6008a4 100644 --- a/dhcpservice/dhcpservice-impl/src/main/config/default-config.xml +++ b/dhcpservice/dhcpservice-impl/src/main/config/default-config.xml @@ -12,6 +12,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html urn:opendaylight:params:xml:ns:yang:dhcpservice:impl?module=dhcpservice-impl&revision=2015-07-10 urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding?module=opendaylight-md-sal-binding&revision=2013-10-28 urn:opendaylight:params:xml:ns:yang:mdsalutil:api?module=odl-mdsalutil&revision=2015-04-10 + urn:opendaylight:params:xml:ns:yang:neutronvpn:api?module=neutronvpn-api&revision=2015-08-12 @@ -36,6 +37,10 @@ and is available at http://www.eclipse.org/legal/epl-v10.html mdsalutil:odl-mdsalutil mdsalutil-service + + neutronvpn:neutronvpn-api + neutronvpn + diff --git a/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpConfigListener.java b/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpConfigListener.java new file mode 100644 index 00000000..57512b4c --- /dev/null +++ b/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpConfigListener.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.vpnservice.dhcpservice; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.dhcp.config.Configs; + +import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope; +import org.opendaylight.vpnservice.datastoreutils.AsyncDataChangeListenerBase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.DhcpConfig; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; +import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.vpnservice.dhcpservice.api.DHCPMConstants; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DhcpConfigListener extends AsyncDataChangeListenerBase implements AutoCloseable { + + private static final Logger LOG = LoggerFactory.getLogger(DhcpConfigListener.class); + + private ListenerRegistration listenerRegistration; + private DhcpManager dhcpManager; + + public DhcpConfigListener(final DataBroker db, final DhcpManager dhcpMgr) { + super(DhcpConfig.class, DhcpConfigListener.class); + dhcpManager = dhcpMgr; + registerListener(db); + } + + private void registerListener(final DataBroker db) { + try { + listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION, + getWildCardPath(), DhcpConfigListener.this, AsyncDataBroker.DataChangeScope.SUBTREE); + } catch (final Exception e) { + LOG.error("NodeListener: DataChange listener registration fail!", e); + throw new IllegalStateException("NodeListener: registration Listener failed.", e); + } + } + + protected InstanceIdentifier getWildCardPath() { + return InstanceIdentifier.create(DhcpConfig.class); + } + + @Override + public void close() throws Exception { + if (listenerRegistration != null) { + try { + listenerRegistration.close(); + } catch (final Exception e) { + LOG.error("Error when cleaning up DhcpConfigListener.", e); + } + listenerRegistration = null; + } + LOG.debug("DhcpConfig Listener Closed"); + } + + @Override + protected void remove(InstanceIdentifier identifier, DhcpConfig del) { + LOG.trace("DhcpConfig removed: {}", del); + updateConfig(null); + } + + @Override + protected void update(InstanceIdentifier identifier, DhcpConfig original, DhcpConfig update) { + LOG.trace("DhcpConfig changed to {}", update); + updateConfig(update); + } + + @Override + protected void add(InstanceIdentifier identifier, DhcpConfig add) { + LOG.trace("DhcpConfig added {}", add); + updateConfig(add); + } + + private void updateConfig(DhcpConfig update) { + //TODO: Update operational with actual values + if(update == null || update.getConfigs() == null || update.getConfigs().isEmpty()) { + dhcpManager.setLeaseDuration(DHCPMConstants.DEFAULT_LEASE_TIME); + dhcpManager.setDefaultDomain(DHCPMConstants.DEFAULT_DOMAIN_NAME); + return; + } + Configs config = update.getConfigs().get(0); + if(config.getLeaseDuration() != null) { + dhcpManager.setLeaseDuration(config.getLeaseDuration()); + } + if(config.getDefaultDomain() != null) { + dhcpManager.setDefaultDomain(config.getDefaultDomain()); + //TODO: What to do if string is "" + } + } + + @Override + protected DataChangeListener getDataChangeListener() { + return DhcpConfigListener.this; + } + + @Override + protected DataChangeScope getDataChangeScope() { + return AsyncDataBroker.DataChangeScope.BASE; + } +} diff --git a/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpManager.java b/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpManager.java index 458ad968..f195fa89 100644 --- a/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpManager.java +++ b/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpManager.java @@ -7,8 +7,9 @@ */ package org.opendaylight.vpnservice.dhcpservice; -import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.SubnetKey; +import org.opendaylight.vpnservice.neutronvpn.interfaces.INeutronVpnManager; +import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.SubnetKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets; import com.google.common.base.Optional; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; @@ -46,7 +47,8 @@ public class DhcpManager implements AutoCloseable { private int dhcpOptLeaseTime = 0; private int dhcpOptRenewalTime = 0; private int dhcpOptRebindingTime = 0; - private String dhcpOptDefDomainName = "openstacklocal"; + private String dhcpOptDefDomainName; + private INeutronVpnManager neutronVpnService; private static final FutureCallback DEFAULT_CALLBACK = new FutureCallback() { @@ -70,6 +72,11 @@ public class DhcpManager implements AutoCloseable { this.mdsalUtil = mdsalManager; } + public void setNeutronVpnService(INeutronVpnManager neutronVpnService) { + logger.debug("Setting NeutronVpn dependency"); + this.neutronVpnService = neutronVpnService; + } + @Override public void close() throws Exception { logger.info("DHCP Manager Closed"); @@ -150,7 +157,6 @@ public class DhcpManager implements AutoCloseable { } public Subnet getNeutronSubnet(Port nPort) { - /* TODO: Once NeutronVpn is merged, use it to get Subnet if (nPort != null) { try { return neutronVpnService.getNeutronSubnet(nPort.getFixedIps().get(0).getSubnetId()); @@ -158,32 +164,11 @@ public class DhcpManager implements AutoCloseable { logger.warn("Failed to get Neutron Subnet from Port: {}", e); } } - */ - if (nPort.getFixedIps() != null && !nPort.getFixedIps().isEmpty()) { - InstanceIdentifier sIid = - InstanceIdentifier.create(Neutron.class).child(Subnets.class) - .child(Subnet.class, new SubnetKey(nPort.getFixedIps().get(0).getSubnetId())); - Optional optSubnet = MDSALUtil.read(LogicalDatastoreType.CONFIGURATION, sIid, broker); - if (optSubnet.isPresent()) { - return optSubnet.get(); - } - } return null; } public Port getNeutronPort(String name) { - // TODO Once NeutronVpn is merged, use it to get port - //return neutronVpnService.getNeutronPort(name); - InstanceIdentifier pIid = InstanceIdentifier.create(Neutron.class).child(Ports.class); - Optional optPorts = MDSALUtil.read(LogicalDatastoreType.CONFIGURATION, pIid, broker); - if(optPorts.isPresent()) { - for(Port port: optPorts.get().getPort()) { - if(port.getUuid().getValue().startsWith(name.substring(3))) { - return port; - } - } - } - return null; + return neutronVpnService.getNeutronPort(name); } } diff --git a/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpProvider.java b/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpProvider.java index ce1a0a11..5f15135f 100644 --- a/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpProvider.java +++ b/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpProvider.java @@ -7,7 +7,7 @@ */ package org.opendaylight.vpnservice.dhcpservice; -import java.math.BigInteger; +import org.opendaylight.vpnservice.neutronvpn.interfaces.INeutronVpnManager; import org.opendaylight.controller.sal.binding.api.NotificationProviderService; import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService; @@ -28,6 +28,8 @@ public class DhcpProvider implements BindingAwareProvider, AutoCloseable { private NotificationProviderService notificationService; private DhcpManager dhcpManager; private NodeListener dhcpNodeListener; + private INeutronVpnManager neutronVpnManager; + private DhcpConfigListener dhcpConfigListener; @Override public void onSessionInitiated(ProviderContext session) { @@ -37,10 +39,12 @@ public class DhcpProvider implements BindingAwareProvider, AutoCloseable { final PacketProcessingService pktProcessingService = session.getRpcService(PacketProcessingService.class); dhcpManager = new DhcpManager(dataBroker); dhcpManager.setMdsalManager(mdsalManager); + dhcpManager.setNeutronVpnService(neutronVpnManager); dhcpPktHandler = new DhcpPktHandler(dataBroker, dhcpManager); dhcpPktHandler.setPacketProcessingService(pktProcessingService); packetListener = notificationService.registerNotificationListener(dhcpPktHandler); dhcpNodeListener = new NodeListener(dataBroker, dhcpManager); + dhcpConfigListener = new DhcpConfigListener(dataBroker, dhcpManager); } catch (Exception e) { LOG.error("Error initializing services", e); } @@ -51,6 +55,10 @@ public class DhcpProvider implements BindingAwareProvider, AutoCloseable { this.mdsalManager = mdsalManager; } + public void setNeutronVpnManager(INeutronVpnManager neutronVpnManager) { + this.neutronVpnManager = neutronVpnManager; + } + @Override public void close() throws Exception { if(packetListener != null) { diff --git a/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/dhcpservice/impl/rev150710/DhcpServiceImplModule.java b/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/dhcpservice/impl/rev150710/DhcpServiceImplModule.java index bf453d42..eac19a99 100644 --- a/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/dhcpservice/impl/rev150710/DhcpServiceImplModule.java +++ b/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/dhcpservice/impl/rev150710/DhcpServiceImplModule.java @@ -21,6 +21,7 @@ public class DhcpServiceImplModule extends org.opendaylight.yang.gen.v1.urn.open DhcpProvider dhcpProvider = new DhcpProvider(); dhcpProvider.setNotificationProviderService(getNotificationServiceDependency()); dhcpProvider.setMdsalManager(getMdsalutilDependency()); + dhcpProvider.setNeutronVpnManager(getNeutronvpnDependency()); getBrokerDependency().registerProvider(dhcpProvider); return dhcpProvider; } diff --git a/dhcpservice/dhcpservice-impl/src/main/yang/dhcpservice-impl.yang b/dhcpservice/dhcpservice-impl/src/main/yang/dhcpservice-impl.yang index dcbec022..856b7716 100644 --- a/dhcpservice/dhcpservice-impl/src/main/yang/dhcpservice-impl.yang +++ b/dhcpservice/dhcpservice-impl/src/main/yang/dhcpservice-impl.yang @@ -6,6 +6,7 @@ module dhcpservice-impl { import config { prefix config; revision-date 2013-04-05; } import opendaylight-md-sal-binding { prefix md-sal-binding; revision-date 2013-10-28;} import odl-mdsalutil { prefix odl-mdsal; revision-date 2015-04-10;} + import neutronvpn-api { prefix nvpn; revision-date 2015-08-12;} description "Service definition for dhcpservice project"; @@ -56,6 +57,15 @@ module dhcpservice-impl { } } } + + container neutronvpn { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity nvpn:neutronvpn-api; + } + } + } } } } diff --git a/itm/itm-impl/src/main/config/default-config.xml b/itm/itm-impl/src/main/config/default-config.xml index cb063605..302d1f6e 100644 --- a/itm/itm-impl/src/main/config/default-config.xml +++ b/itm/itm-impl/src/main/config/default-config.xml @@ -9,8 +9,8 @@ and is available at http://www.eclipse.org/legal/epl-v10.html --> - urn:opendaylight:params:xml:ns:yang:itm?module=itm&revision=2015-07-01 - urn:opendaylight:params:xml:ns:yang:itm:impl?module=itm-impl&revision=2014-12-10 + urn:opendaylight:vpnservice:itm?module=itm&revision=2015-07-01 + urn:opendaylight:vpnservice:itm:impl?module=itm-impl&revision=2014-12-10 urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding?module=opendaylight-md-sal-binding&revision=2013-10-28 urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding:impl?module=opendaylight-sal-binding-broker-impl&revision=2013-10-28 urn:opendaylight:params:xml:ns:yang:mdsalutil:api?module=odl-mdsalutil&revision=2015-04-10 @@ -21,7 +21,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html - prefix:itm + prefix:itm itm-default binding:binding-broker-osgi-registry @@ -51,7 +51,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html - prefix:itm + prefix:itm itm /modules/module[type='itm'][name='itm-default'] diff --git a/neutronvpn/neutronvpn-api/src/main/yang/neutronvpn.yang b/neutronvpn/neutronvpn-api/src/main/yang/neutronvpn.yang index c1785340..bc306bbf 100644 --- a/neutronvpn/neutronvpn-api/src/main/yang/neutronvpn.yang +++ b/neutronvpn/neutronvpn-api/src/main/yang/neutronvpn.yang @@ -151,6 +151,21 @@ module neutronvpn { } } + /* container for DHCP Configuration */ + container dhcp-config { + list configs { + leaf lease-duration { + type int32; + description "default lease duration for dhcp lease. + -1 means infinite"; + } + leaf default-domain { + type string; + description "default domain-name. used in dhcp reply"; + } + } + } + rpc createL3VPN{ description "Create one or more L3 VPN"; input {