neutron: unbreak of neutron northbound yang model revise 58/40258/1
authorIsaku Yamahata <isaku.yamahata@intel.com>
Mon, 13 Jun 2016 22:02:59 +0000 (15:02 -0700)
committerIsaku Yamahata <isaku.yamahata@intel.com>
Mon, 13 Jun 2016 22:06:41 +0000 (15:06 -0700)
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 <isaku.yamahata@intel.com>
dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpExternalTunnelManager.java
dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpInterfaceEventListener.java
dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpNeutronPortListener.java
dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpPktHandler.java
dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/vpnservice/dhcpservice/DhcpServiceUtils.java
neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronPortChangeListener.java
neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronRouterChangeListener.java
neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronSubnetChangeListener.java
neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronvpnManager.java
neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/vpnservice/neutronvpn/NeutronvpnUtils.java

index 79e34826d7af148c54a93a3e82635c3524dff3ad..ababb711019cb80a63aa79709b593f50405a25dd 100644 (file)
@@ -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) {
index 3550156fcca16bff3b527f6b81ceb3e7af86e2fa..4f66a9099d0e4473d2b9c5387b62ea4c849ff48f 100644 (file)
@@ -195,7 +195,7 @@ public class DhcpInterfaceEventListener extends AbstractDataChangeListener<Inter
         Port port = dhcpManager.getNeutronPort(interfaceName);
         if (port!=null) {
             logger.trace("Port found in neutron. Interface Name {}, port {}", interfaceName, port);
-            return port.getMacAddress();
+            return port.getMacAddress().getValue();
         }
         return null;
     }
index 385d9192d945dd203f983bcfdf39792da01b714c..2f287f084d01c7a20dacd5fb8b9f2223cb771543 100644 (file)
@@ -64,7 +64,7 @@ public class DhcpNeutronPortListener extends AsyncClusteredDataChangeListenerBas
         if(NeutronUtils.isPortVnicTypeNormal(del)) {
             return;
         }
-        String macAddress = del.getMacAddress();
+        String macAddress = del.getMacAddress().getValue();
         Uuid networkId = del.getNetworkId();
         String segmentationId = DhcpServiceUtils.getSegmentationId(networkId, broker);
         if (segmentationId == null) {
@@ -87,7 +87,7 @@ public class DhcpNeutronPortListener extends AsyncClusteredDataChangeListenerBas
             LOG.trace("Port is normal {}", add);
             return;
         }
-        String macAddress = add.getMacAddress();
+        String macAddress = add.getMacAddress().getValue();
         Uuid networkId = add.getNetworkId();
         String segmentationId = DhcpServiceUtils.getSegmentationId(networkId, broker);
         if (segmentationId == null) {
index c74171a30ffe28c33b91a2e2fbd7dc9d3d6b6289..4d1c51b67a1d58cc0bf6c19d4ebd58bd84c6c0ae 100644 (file)
@@ -165,7 +165,8 @@ public class DhcpPktHandler implements AutoCloseable, PacketProcessingListener {
             List<IpAddress> 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;
index b925646fcdbb5e0fd4a953f1ad86ad93a723f7e1..f336564930ef44c3ca1a8a9a4e3c26d86e06e420 100644 (file)
@@ -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
+}
index 2feca2cd75ff4d4d97454d3f198c835bb36ff283..a684d9118ee5b2f4c077b89e03109b8810d615cc 100644 (file)
@@ -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<Port> implements AutoCloseable {
@@ -190,26 +192,47 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
 
     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<Uuid> 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<Uuid> 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<Port>
     private void createElanInterface(Port port, String name) {
         String elanInstanceName = port.getNetworkId().getValue();
         List<PhysAddress> physAddresses = new ArrayList<>();
-        physAddresses.add(new PhysAddress(port.getMacAddress()));
+        physAddresses.add(new PhysAddress(String.valueOf(port.getMacAddress().getValue())));
 
         InstanceIdentifier<ElanInterface> id = InstanceIdentifier.builder(ElanInterfaces.class).child(ElanInterface
                 .class, new ElanInterfaceKey(name)).build();
@@ -311,6 +334,15 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
                     NeutronvpnUtils.unlock(lockManager, lockName);
                 }
             }
+            if (port.getDeviceOwner().equals("network:router_interface")) {
+                Set<Uuid> 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<Port>
                     NeutronvpnUtils.unlock(lockManager, lockName);
                 }
             }
+            if (port.getDeviceOwner().equals("network:router_interface")) {
+                Set<Uuid> subnetUuids = new HashSet<>();
+                for (FixedIps fixedIps : port.getFixedIps()) {
+                    subnetUuids.add(fixedIps.getSubnetId());
+                }
+                for (Uuid subnetUuid : subnetUuids) {
+                    nvpnManager.removeSubnetFromVpn(vpnId, subnetUuid);
+                }
+            }
         }
         return vpnId;
     }
index b2b46a94a956ccce4f02616c9394cb18bb7fb460..86ea66384463db536af67821fa0ef60a98b0432f 100644 (file)
@@ -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<Router> implements AutoCloseable {
@@ -67,6 +75,27 @@ public class NeutronRouterChangeListener extends AbstractDataChangeListener<Rout
         }
     }
 
+    private Set<Port> getInterfaces(final Uuid deviceId) {
+        final Set<Port> interfaces = new HashSet<>();
+        InstanceIdentifier<Ports> path = InstanceIdentifier.create(Neutron.class).child(Ports.class);
+
+        try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
+            final CheckedFuture<Optional<Ports>, ReadFailedException> future = tx.read(LogicalDatastoreType.CONFIGURATION, path);
+            Optional<Ports> 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<Router> identifier, Router input) {
         if (LOG.isTraceEnabled()) {
@@ -82,13 +111,16 @@ public class NeutronRouterChangeListener extends AbstractDataChangeListener<Rout
             LOG.trace("Removing router : key: " + identifier + ", value=" + input);
         }
         Uuid routerId = input.getUuid();
-        // fetch subnets associated to router
-        List<Interfaces> routerInterfaces = input.getInterfaces();
-        List<Uuid> routerSubnetIds = new ArrayList<Uuid>();
-        if (routerInterfaces != null) {
-            for (Interfaces rtrIf : routerInterfaces) {
-                routerSubnetIds.add(rtrIf.getSubnetId());
+        Set<Port> routerInterfaces = this.getInterfaces(input.getUuid());
+        List<Uuid> routerSubnetIds = new ArrayList<>();
+        if (!routerInterfaces.isEmpty()) {
+            Set<Uuid> uuids = new HashSet<>();
+            for (Port port : routerInterfaces) {
+                for (FixedIps fixedIps : port.getFixedIps()) {
+                    uuids.add(fixedIps.getSubnetId());
+                }
             }
+            routerSubnetIds.addAll(uuids);
         }
         nvpnManager.handleNeutronRouterDeleted(routerId, routerSubnetIds);
     }
@@ -105,24 +137,8 @@ public class NeutronRouterChangeListener extends AbstractDataChangeListener<Rout
         if (vpnId == null) {
             vpnId = routerId;
         }
-        List<Interfaces> oldInterfaces = (original.getInterfaces() != null) ? original.getInterfaces() : new
-                ArrayList<Interfaces>();
-        List<Interfaces> newInterfaces = (update.getInterfaces() != null) ? update.getInterfaces() : new
-                ArrayList<Interfaces>();
         List<Routes> oldRoutes = (original.getRoutes() != null) ? original.getRoutes() : new ArrayList<Routes>();
         List<Routes> newRoutes = (update.getRoutes() != null) ? update.getRoutes() : new ArrayList<Routes>();
-        if (!oldInterfaces.equals(newInterfaces)) {
-            for (Interfaces intrf : newInterfaces) {
-                if (!oldInterfaces.remove(intrf)) {
-                    // add new subnet
-                    nvpnManager.addSubnetToVpn(vpnId, intrf.getSubnetId());
-                }
-            }
-            //clear remaining old subnets
-            for (Interfaces intrf : oldInterfaces) {
-                nvpnManager.removeSubnetFromVpn(vpnId, intrf.getSubnetId());
-            }
-        }
         if (!oldRoutes.equals(newRoutes)) {
             Iterator<Routes> iterator = newRoutes.iterator();
             while (iterator.hasNext()) {
index 9a6fa4e1e6e404f9349e5249cd254d093550a7e8..278214a47b01ce9e9b25a60f46c617921acc387b 100644 (file)
@@ -76,7 +76,7 @@ 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());
+        handleNeutronSubnetCreated(input.getUuid(), String.valueOf(input.getCidr().getValue()), input.getNetworkId(), input.getTenantId());
     }
 
     @Override
index bd66c26f7735d13a06fad04ed3342db44f22f346..1490b0bb36fdc8b47153d8eb0267d71f2b46f8bd 100644 (file)
@@ -458,7 +458,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable , Eve
             StringBuilder IpPrefixBuild = new StringBuilder(ip.getIpAddress().getIpv4Address().getValue());
             String IpPrefix = IpPrefixBuild.append("/32").toString();
             Adjacency vmAdj = new AdjacencyBuilder().setKey(new AdjacencyKey(IpPrefix)).setIpAddress(IpPrefix)
-                    .setMacAddress(port.getMacAddress()).build();
+                    .setMacAddress(port.getMacAddress().getValue()).build();
             adjList.add(vmAdj);
             // create extra route adjacency
             if (rtr != null && rtr.getRoutes() != null) {
index d161f97dfdde3441ca4dd97e18128a7c795ee77c..7e8483f73a58cc84bcd7e2f4815db5c3507cd858 100644 (file)
@@ -9,10 +9,12 @@
 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.ReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInterfaces;
 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface;
 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey;
@@ -31,6 +33,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.NetworkKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.NetworkProviderExtension;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.neutron.networks.network.Segments;
+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.ports.rev150712.ports.attributes.ports.PortKey;
@@ -65,7 +68,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 
@@ -192,17 +197,24 @@ public class NeutronvpnUtils {
         logger.info("getNeutronRouterSubnetIds for {}", routerId.getValue());
 
         List<Uuid> subnetIdList = new ArrayList<Uuid>();
-        Router router = getNeutronRouter(broker, routerId);
-        if (router != null) {
-            List<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router
-                    .Interfaces> 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<Ports> path = InstanceIdentifier.create(Neutron.class).child(Ports.class);
+        final Set<Uuid> subnetUuids = new HashSet<>();
+        try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
+            final CheckedFuture<Optional<Ports>, ReadFailedException> future = tx.read(LogicalDatastoreType.CONFIGURATION, path);
+            Optional<Ports> 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> 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)) {