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>
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) {
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;
}
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) {
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) {
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;
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
+}
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 {
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);
+ }
+ }
}
}
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();
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;
}
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;
}
*/
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 {
}
}
+ 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()) {
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);
}
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()) {
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
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) {
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;
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;
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;
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;
}
.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)) {