From 55492c9a3aa14b644c8360bbf472a07bf469d571 Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Mon, 13 Jun 2016 15:02:59 -0700 Subject: [PATCH] neutron: unbreak of neutron northbound yang model revise The patch series[1] for ODL neutron northbound changes its yang model. Which breaks neutron service. This patch unbreaks it. [1] https://git.opendaylight.org/gerrit/#/q/status:open+project:neutron+branch:master+topic:yang-model-revise Change-Id: I11b7694e24d2c6ff212503673d0bf19ece4a3f03 Signed-off-by: Isaku Yamahata --- .../DhcpExternalTunnelManager.java | 2 +- .../DhcpInterfaceEventListener.java | 2 +- .../dhcpservice/DhcpNeutronPortListener.java | 4 +- .../dhcpservice/DhcpPktHandler.java | 3 +- .../dhcpservice/DhcpServiceUtils.java | 4 +- .../neutronvpn/NeutronPortChangeListener.java | 49 +++++++++++++-- .../NeutronRouterChangeListener.java | 62 ++++++++++++------- .../NeutronSubnetChangeListener.java | 2 +- .../neutronvpn/NeutronvpnManager.java | 2 +- .../neutronvpn/NeutronvpnUtils.java | 30 ++++++--- 10 files changed, 115 insertions(+), 45 deletions(-) diff --git a/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpExternalTunnelManager.java b/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpExternalTunnelManager.java index 79e34826..ababb711 100644 --- a/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpExternalTunnelManager.java +++ b/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpExternalTunnelManager.java @@ -133,7 +133,7 @@ public class DhcpExternalTunnelManager { if(NeutronUtils.isPortVnicTypeNormal(port)) { continue; } - String macAddress = port.getMacAddress(); + String macAddress = port.getMacAddress().getValue(); Uuid networkId = port.getNetworkId(); String segmentationId = DhcpServiceUtils.getSegmentationId(networkId, broker); if (segmentationId == null) { diff --git a/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpInterfaceEventListener.java b/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpInterfaceEventListener.java index 3550156f..4f66a909 100644 --- a/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpInterfaceEventListener.java +++ b/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpInterfaceEventListener.java @@ -195,7 +195,7 @@ public class DhcpInterfaceEventListener extends AbstractDataChangeListener dnsServers = nSubnet.getDnsNameservers(); dhcpInfo = new DhcpInfo(); dhcpInfo.setClientIp(clientIp).setServerIp(serverIp) - .setCidr(nSubnet.getCidr()).setHostRoutes(nSubnet.getHostRoutes()) + .setCidr(String.valueOf(nSubnet.getCidr().getValue())) + .setHostRoutes(nSubnet.getHostRoutes()) .setDnsServersIpAddrs(dnsServers).setGatewayIp(serverIp); } return dhcpInfo; diff --git a/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpServiceUtils.java b/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpServiceUtils.java index b925646f..f3365649 100644 --- a/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpServiceUtils.java +++ b/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpServiceUtils.java @@ -220,6 +220,6 @@ public class DhcpServiceUtils { logger.warn("Trunk port {} not available for sub-port", parentRefName); return null; } - return trunkPort.get().getMacAddress(); + return trunkPort.get().getMacAddress().getValue(); } -} \ No newline at end of file +} diff --git a/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronPortChangeListener.java b/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronPortChangeListener.java index 2feca2cd..a684d911 100644 --- a/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronPortChangeListener.java +++ b/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronPortChangeListener.java @@ -48,8 +48,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.ArrayList; +import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; public class NeutronPortChangeListener extends AbstractDataChangeListener implements AutoCloseable { @@ -190,26 +192,47 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener private void handleNeutronPortUpdated(Port portoriginal, Port portupdate) { LOG.debug("Add port to subnet"); - // add port FixedIP to local Subnets DS Uuid vpnIdup = addPortToSubnets(portupdate); + Uuid vpnIdor = removePortFromSubnets(portoriginal); + // add port FixedIP to local Subnets DS if (vpnIdup != null) { nvpnManager.createVpnInterface(vpnIdup, portupdate); Uuid routerId = NeutronvpnUtils.getVpnMap(broker, vpnIdup).getRouterId(); if(routerId != null) { nvpnManager.addToNeutronRouterInterfacesMap(routerId, portupdate.getUuid().getValue()); } + if ((vpnIdor != vpnIdup || + !portoriginal.getDeviceOwner().equals("network:router_interface")) && + portupdate.getDeviceOwner().equals("network:router_interface")) { + Set subnetUuids = new HashSet<>(); + for (FixedIps fixedIps : portupdate.getFixedIps()) { + subnetUuids.add(fixedIps.getSubnetId()); + } + for (Uuid subnetUuid : subnetUuids) { + nvpnManager.addSubnetToVpn(vpnIdup, subnetUuid); + } + } } // remove port FixedIP from local Subnets DS - Uuid vpnIdor = removePortFromSubnets(portoriginal); - if (vpnIdor != null) { nvpnManager.deleteVpnInterface(portoriginal); Uuid routerId = NeutronvpnUtils.getVpnMap(broker, vpnIdor).getRouterId(); if(routerId != null) { nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, portoriginal.getUuid().getValue()); } + if ((vpnIdor != vpnIdup || + !portupdate.getDeviceOwner().equals("network:router_interface")) && + portoriginal.getDeviceOwner().equals("network:router_interface")) { + Set subnetUuids = new HashSet<>(); + for (FixedIps fixedIps : portoriginal.getFixedIps()) { + subnetUuids.add(fixedIps.getSubnetId()); + } + for (Uuid subnetUuid : subnetUuids) { + nvpnManager.removeSubnetFromVpn(vpnIdor, subnetUuid); + } + } } } @@ -266,7 +289,7 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener private void createElanInterface(Port port, String name) { String elanInstanceName = port.getNetworkId().getValue(); List physAddresses = new ArrayList<>(); - physAddresses.add(new PhysAddress(port.getMacAddress())); + physAddresses.add(new PhysAddress(String.valueOf(port.getMacAddress().getValue()))); InstanceIdentifier id = InstanceIdentifier.builder(ElanInterfaces.class).child(ElanInterface .class, new ElanInterfaceKey(name)).build(); @@ -311,6 +334,15 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener NeutronvpnUtils.unlock(lockManager, lockName); } } + if (port.getDeviceOwner().equals("network:router_interface")) { + Set subnetUuids = new HashSet<>(); + for (FixedIps fixedIps : port.getFixedIps()) { + subnetUuids.add(fixedIps.getSubnetId()); + } + for (Uuid subnetUuid : subnetUuids) { + nvpnManager.addSubnetToVpn(vpnId, subnetUuid); + } + } } return vpnId; } @@ -345,6 +377,15 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener NeutronvpnUtils.unlock(lockManager, lockName); } } + if (port.getDeviceOwner().equals("network:router_interface")) { + Set subnetUuids = new HashSet<>(); + for (FixedIps fixedIps : port.getFixedIps()) { + subnetUuids.add(fixedIps.getSubnetId()); + } + for (Uuid subnetUuid : subnetUuids) { + nvpnManager.removeSubnetFromVpn(vpnId, subnetUuid); + } + } } return vpnId; } diff --git a/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronRouterChangeListener.java b/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronRouterChangeListener.java index b2b46a94..86ea6638 100644 --- a/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronRouterChangeListener.java +++ b/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronRouterChangeListener.java @@ -7,24 +7,32 @@ */ package org.opendaylight.vpnservice.neutronvpn; +import com.google.common.base.Optional; +import com.google.common.util.concurrent.CheckedFuture; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; +import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.vpnservice.mdsalutil.AbstractDataChangeListener; 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.l3.attributes.Routes; 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.router.Interfaces; +import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps; +import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports; +import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron; import org.opendaylight.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.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; public class NeutronRouterChangeListener extends AbstractDataChangeListener implements AutoCloseable { @@ -67,6 +75,27 @@ public class NeutronRouterChangeListener extends AbstractDataChangeListener getInterfaces(final Uuid deviceId) { + final Set interfaces = new HashSet<>(); + InstanceIdentifier path = InstanceIdentifier.create(Neutron.class).child(Ports.class); + + try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) { + final CheckedFuture, ReadFailedException> future = tx.read(LogicalDatastoreType.CONFIGURATION, path); + Optional optional = future.checkedGet(); + if (optional.isPresent()) { + for (final Port port : optional.get().getPort()) { + if (port.getDeviceOwner().equals("network:router_interface") && port.getDeviceId().equals(deviceId.getValue())) { + interfaces.add(port); + } + } + } + } catch (final ReadFailedException e) { + LOG.warn("Failed to read {}", path, e); + } + + return interfaces; + } + @Override protected void add(InstanceIdentifier identifier, Router input) { if (LOG.isTraceEnabled()) { @@ -82,13 +111,16 @@ public class NeutronRouterChangeListener extends AbstractDataChangeListener subnetIdList = new ArrayList(); - Router router = getNeutronRouter(broker, routerId); - if (router != null) { - List interfacesList = router.getInterfaces(); - if (interfacesList != null) { - for (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers - .router.Interfaces interfaces : interfacesList) { - subnetIdList.add(interfaces.getSubnetId()); + InstanceIdentifier path = InstanceIdentifier.create(Neutron.class).child(Ports.class); + final Set subnetUuids = new HashSet<>(); + try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) { + final CheckedFuture, ReadFailedException> future = tx.read(LogicalDatastoreType.CONFIGURATION, path); + Optional optional = future.checkedGet(); + if (optional.isPresent()) { + for (final Port port : optional.get().getPort()) { + if (port.getDeviceOwner().equals("network:router_interface") && port.getDeviceId().equals(routerId.getValue())) { + for (FixedIps fixedIps : port.getFixedIps()) { + subnetUuids.add(fixedIps.getSubnetId()); + } + } } } + } catch (final ReadFailedException e) { + logger.error("Failed to read {}", path, e); } + subnetIdList.addAll(subnetUuids); logger.info("returning from getNeutronRouterSubnetIds for {}", routerId.getValue()); return subnetIdList; } @@ -271,7 +283,7 @@ public class NeutronvpnUtils { .class).child(Subnet.class, subnetkey); Optional subnet = read(broker, LogicalDatastoreType.CONFIGURATION,subnetidentifier); if (subnet.isPresent()) { - cidr = subnet.get().getCidr(); + cidr = String.valueOf(subnet.get().getCidr().getValue()); // Extract the prefix length from cidr String[] parts = cidr.split("/"); if ((parts.length == 2)) { -- 2.36.6