// Create PortOpDataEntry only if not present
portOpBuilder =
new PortOpDataEntryBuilder().setKey(new PortOpDataEntryKey(intfName)).setPortId(intfName);
- portOpBuilder.setSubnetId(subnetId);
+ List<Uuid> listSubnet = new ArrayList<>();
+ listSubnet.add(subnetId);
+ portOpBuilder.setSubnetIds(listSubnet);
} else {
+ List<Uuid> listSubnet = optionalPortOp.get().getSubnetIds();
portOpBuilder = new PortOpDataEntryBuilder(optionalPortOp.get());
- portOpBuilder.setSubnetId(subnetId);
+ if (listSubnet == null) {
+ listSubnet = new ArrayList<Uuid>();
+ }
+ if (!listSubnet.contains(subnetId)) {
+ listSubnet.add(subnetId);
+ }
+ portOpBuilder.setSubnetIds(listSubnet);
}
if (dpnId != null && !dpnId.equals(BigInteger.ZERO)) {
portOpBuilder.setDpnId(dpnId);
portOpEntry = portOpBuilder.build();
SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier,
portOpEntry);
- LOG.info("addPortOpDataEntry: Created PortOpData entry for port {} with DPNId {} intfName {}",
- intfName, dpnId, intfName);
+ LOG.info("addPortOpDataEntry: Created PortOpData entry for port {} with DPNId {} subnetId {}",
+ intfName, dpnId, subnetId.getValue());
} catch (TransactionCommitFailedException ex) {
LOG.error("addPortOpDataEntry: Addition of Interface {} for SubnetToDpn on subnet {} with DPN {} failed",
intfName, subnetId.getValue(), dpnId, ex);
return dpnRemoved;
}
- public PortOpDataEntry removePortOpDataEntry(String intfName) {
+ public PortOpDataEntry removePortOpDataEntry(String intfName, Uuid subnetId) {
// Remove PortOpData and return out
InstanceIdentifier<PortOpDataEntry> portOpIdentifier =
InstanceIdentifier.builder(PortOpData.class).child(PortOpDataEntry.class,
return null;
} else {
portOpEntry = optionalPortOp.get();
- MDSALUtil.syncDelete(broker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier);
- LOG.info("removePortOpDataEntry: Deleted portOpData entry for port {}", intfName);
+ List<Uuid> listSubnet = portOpEntry.getSubnetIds();
+ if (listSubnet == null) {
+ listSubnet = new ArrayList<Uuid>();
+ }
+ if (subnetId != null && listSubnet.contains(subnetId)) {
+ listSubnet.remove(subnetId);
+ }
+ if (listSubnet.isEmpty() || subnetId == null) {
+ MDSALUtil.syncDelete(broker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier);
+ LOG.info("removePortOpDataEntry: Deleted portOpData entry for port {}", intfName);
+ } else {
+ try {
+ PortOpDataEntryBuilder portOpBuilder = null;
+ portOpBuilder = new PortOpDataEntryBuilder(portOpEntry);
+ portOpBuilder.setSubnetIds(listSubnet);
+ SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier,
+ portOpEntry);
+ LOG.info("removePortOpDataEntry: Updated PortOpData entry for port {} with removing subnetId {}",
+ intfName, subnetId.getValue());
+ } catch (TransactionCommitFailedException ex) {
+ LOG.error("removePortOpDataEntry failed: Updated PortOpData entry for port {}"
+ + " with removing subnetId {}", intfName, subnetId.getValue());
+ }
+ return null;
+ }
}
return portOpEntry;
}
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
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.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntry;
+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.Port;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
@Override
protected void add(InstanceIdentifier<Interface> identifier, Interface intrf) {
LOG.trace("{} add: Received interface {} up event", LOGGING_PREFIX, intrf);
- final Uuid subnetId;
+ final List<Uuid> subnetIdList;
try {
if (L2vlan.class.equals(intrf.getType())) {
LOG.trace("SubnetRouteInterfaceListener add: Received interface {} up event", intrf);
if (intrf.getOperStatus().equals(Interface.OperStatus.Up)) {
- subnetId = getSubnetId(intrf);
- if (subnetId == null) {
+ subnetIdList = getSubnetId(intrf);
+ if (subnetIdList == null || subnetIdList.isEmpty()) {
LOG.trace("SubnetRouteInterfaceListener add: Port {} doesnt exist in configDS",
intrf.getName());
return;
}
- DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();
- dataStoreCoordinator.enqueueJob("SUBNETROUTE-" + subnetId,
- () -> {
- List<ListenableFuture<Void>> futures = new ArrayList<>();
- String interfaceName = intrf.getName();
- LOG.info("{} add: Received port UP event for interface {} subnetId {}",
- LOGGING_PREFIX, interfaceName, subnetId.getValue());
- try {
- BigInteger dpnId = InterfaceUtils.getDpIdFromInterface(intrf);
- vpnSubnetRouteHandler.onInterfaceUp(dpnId, intrf.getName(), subnetId);
- } catch (Exception e) {
- LOG.error("{} add: Unable to obtain dpnId for interface {} in subnet {},"
- + " subnetroute inclusion for this interface failed with exception {}",
- LOGGING_PREFIX, interfaceName, subnetId.getValue(), e);
- }
- return futures;
- });
+ for (Uuid subnetId : subnetIdList) {
+ DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();
+ dataStoreCoordinator.enqueueJob("SUBNETROUTE-" + subnetId,
+ () -> {
+ String interfaceName = intrf.getName();
+ LOG.info("{} add: Received port UP event for interface {} subnetId {}",
+ LOGGING_PREFIX, interfaceName, subnetId);
+ try {
+ BigInteger dpnId = InterfaceUtils.getDpIdFromInterface(intrf);
+ vpnSubnetRouteHandler.onInterfaceUp(dpnId, intrf.getName(), subnetId);
+ } catch (Exception e) {
+ LOG.error("{} add: Unable to obtain dpnId for interface {} in subnet {},"
+ + " subnetroute inclusion for this interface failed with exception {}",
+ LOGGING_PREFIX, interfaceName, subnetId, e);
+ }
+ List<ListenableFuture<Void>> futures = new ArrayList<>();
+ return futures;
+ });
+ }
}
}
LOG.info("{} add: Processed interface {} up event", LOGGING_PREFIX, intrf.getName());
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
protected void remove(InstanceIdentifier<Interface> identifier, Interface intrf) {
- final Uuid subnetId;
+ final List<Uuid> subnetIdList;
try {
if (L2vlan.class.equals(intrf.getType())) {
LOG.trace("SubnetRouteInterfaceListener remove: Received interface {} down event", intrf);
- subnetId = getSubnetId(intrf);
- if (subnetId == null) {
- LOG.trace("SubnetRouteInterfaceListener add: Port {} doesnt exist in configDS",
+ subnetIdList = getSubnetId(intrf);
+ if (subnetIdList == null || subnetIdList.isEmpty()) {
+ LOG.trace("SubnetRouteInterfaceListener remove: Port {} doesnt exist in configDS",
intrf.getName());
return;
}
- DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();
- dataStoreCoordinator.enqueueJob("SUBNETROUTE-" + subnetId,
- () -> {
- String interfaceName = intrf.getName();
- BigInteger dpnId = BigInteger.ZERO;
- LOG.info("{} remove: Received port DOWN event for interface {} in subnet {} ",
- LOGGING_PREFIX, interfaceName, subnetId.getValue());
- try {
- dpnId = InterfaceUtils.getDpIdFromInterface(intrf);
- } catch (Exception e) {
- LOG.error("{} remove: Unable to retrieve dpnId for interface {} in subnet {}. "
- + "Fetching from vpn interface itself due to exception {}",
- LOGGING_PREFIX, intrf.getName(), subnetId.getValue(), e);
- InstanceIdentifier<VpnInterface> id = VpnUtil
- .getVpnInterfaceIdentifier(interfaceName);
- Optional<VpnInterface> optVpnInterface = VpnUtil.read(dataBroker,
- LogicalDatastoreType.OPERATIONAL, id);
- if (optVpnInterface.isPresent()) {
- dpnId = optVpnInterface.get().getDpnId();
+ for (Uuid subnetId : subnetIdList) {
+ DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();
+ dataStoreCoordinator.enqueueJob("SUBNETROUTE-" + subnetId,
+ () -> {
+ String interfaceName = intrf.getName();
+ BigInteger dpnId = BigInteger.ZERO;
+ LOG.info("{} remove: Received port DOWN event for interface {} in subnet {} ",
+ LOGGING_PREFIX, interfaceName, subnetId);
+ try {
+ dpnId = InterfaceUtils.getDpIdFromInterface(intrf);
+ } catch (Exception e) {
+ LOG.error("{} remove: Unable to retrieve dpnId for interface {} in subnet {}. "
+ + "Fetching from vpn interface itself due to exception {}",
+ LOGGING_PREFIX, intrf.getName(), subnetId, e);
+ InstanceIdentifier<VpnInterface> id = VpnUtil
+ .getVpnInterfaceIdentifier(interfaceName);
+ Optional<VpnInterface> optVpnInterface = VpnUtil.read(dataBroker,
+ LogicalDatastoreType.OPERATIONAL, id);
+ if (optVpnInterface.isPresent()) {
+ dpnId = optVpnInterface.get().getDpnId();
+ }
+ }
+ if (!dpnId.equals(BigInteger.ZERO)) {
+ vpnSubnetRouteHandler.onInterfaceDown(dpnId, intrf.getName(), subnetId);
}
- }
- if (!dpnId.equals(BigInteger.ZERO)) {
- vpnSubnetRouteHandler.onInterfaceDown(dpnId, intrf.getName(), subnetId);
- }
- List<ListenableFuture<Void>> futures = new ArrayList<>();
- return futures;
- });
+ List<ListenableFuture<Void>> futures = new ArrayList<>();
+ return futures;
+ });
+ }
}
LOG.info("{} remove: Processed interface {} down event in ", LOGGING_PREFIX, intrf.getName());
} catch (Exception e) {
@Override
protected void update(InstanceIdentifier<Interface> identifier,
Interface original, Interface update) {
- final Uuid subnetId;
+ final List<Uuid> subnetIdList;
try {
String interfaceName = update.getName();
if (L2vlan.class.equals(update.getType())) {
LOG.trace("{} update: Operation Interface update event - Old: {}, New: {}", LOGGING_PREFIX,
original, update);
- subnetId = getSubnetId(update);
- if (subnetId == null) {
- LOG.trace("SubnetRouteInterfaceListener update: Port {} doesnt exist in configDS",
+ subnetIdList = getSubnetId(update);
+ if ((subnetIdList == null) || (subnetIdList.isEmpty())) {
+ LOG.error("SubnetRouteInterfaceListener update: Port {} doesnt exist in configDS",
update.getName());
return;
}
- DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();
- dataStoreCoordinator.enqueueJob("SUBNETROUTE-" + subnetId,
- () -> {
- List<ListenableFuture<Void>> futures = new ArrayList<>();
- BigInteger dpnId = BigInteger.ZERO;
- try {
- dpnId = InterfaceUtils.getDpIdFromInterface(update);
- } catch (Exception e) {
- LOG.error("{} remove: Unable to retrieve dpnId for interface {} in subnet {}. "
- + "Fetching from vpn interface itself due to exception {}", LOGGING_PREFIX,
- update.getName(), subnetId.getValue(), e);
- InstanceIdentifier<VpnInterface> id = VpnUtil
- .getVpnInterfaceIdentifier(interfaceName);
- Optional<VpnInterface> optVpnInterface = VpnUtil.read(dataBroker,
- LogicalDatastoreType.OPERATIONAL, id);
- if (optVpnInterface.isPresent()) {
- dpnId = optVpnInterface.get().getDpnId();
+ for (Uuid subnetId : subnetIdList) {
+ DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();
+ dataStoreCoordinator.enqueueJob("SUBNETROUTE-" + subnetId,
+ () -> {
+ List<ListenableFuture<Void>> futures = new ArrayList<>();
+ BigInteger dpnId = BigInteger.ZERO;
+ try {
+ dpnId = InterfaceUtils.getDpIdFromInterface(update);
+ } catch (Exception e) {
+ LOG.error("{} remove: Unable to retrieve dpnId for interface {} in subnet {}. "
+ + "Fetching from vpn interface itself due to exception {}", LOGGING_PREFIX,
+ update.getName(), subnetId, e);
+ InstanceIdentifier<VpnInterface> id = VpnUtil
+ .getVpnInterfaceIdentifier(interfaceName);
+ Optional<VpnInterface> optVpnInterface = VpnUtil.read(dataBroker,
+ LogicalDatastoreType.OPERATIONAL, id);
+ if (optVpnInterface.isPresent()) {
+ dpnId = optVpnInterface.get().getDpnId();
+ }
}
- }
- if (!dpnId.equals(BigInteger.ZERO)) {
- if (update.getOperStatus().equals(Interface.OperStatus.Up)) {
- LOG.info("{} update: Received port UP event for interface {} in subnet {}",
- LOGGING_PREFIX, update.getName(), subnetId.getValue());
- vpnSubnetRouteHandler.onInterfaceUp(dpnId, update.getName(), subnetId);
- } else if (update.getOperStatus().equals(Interface.OperStatus.Down)
- || update.getOperStatus().equals(Interface.OperStatus.Unknown)) {
- /*
- * If the interface went down voluntarily (or) if the interface is not
- * reachable from control-path involuntarily, trigger subnetRoute election
- */
- LOG.info("{} update: Received port {} event for interface {} in subnet {} ",
- LOGGING_PREFIX, update.getOperStatus().equals(Interface.OperStatus.Unknown)
- ? "UNKNOWN" : "DOWN", update.getName(), subnetId.getValue());
- vpnSubnetRouteHandler.onInterfaceDown(dpnId, update.getName(), subnetId);
+ if (!dpnId.equals(BigInteger.ZERO)) {
+ if (update.getOperStatus().equals(Interface.OperStatus.Up)) {
+ LOG.info("{} update: Received port UP event for interface {} in subnet {}",
+ LOGGING_PREFIX, update.getName(), subnetId);
+ vpnSubnetRouteHandler.onInterfaceUp(dpnId, update.getName(), subnetId);
+ } else if (update.getOperStatus().equals(Interface.OperStatus.Down)
+ || update.getOperStatus().equals(Interface.OperStatus.Unknown)) {
+ /*
+ * If the interface went down voluntarily (or) if the interface is not
+ * reachable from control-path involuntarily, trigger subnetRoute election
+ */
+ LOG.info("{} update: Received port {} event for interface {} in subnet {} ",
+ LOGGING_PREFIX, update.getOperStatus().equals(Interface.OperStatus.Unknown)
+ ? "UNKNOWN" : "DOWN", update.getName(), subnetId);
+ vpnSubnetRouteHandler.onInterfaceDown(dpnId, update.getName(), subnetId);
+ }
}
- }
- return futures;
- });
+ return futures;
+ });
+ }
}
LOG.info("{} update: Processed Interface {} update event", LOGGING_PREFIX, update.getName());
} catch (Exception e) {
}
}
- protected Uuid getSubnetId(Interface intrf) {
-
+ protected List<Uuid> getSubnetId(Interface intrf) {
+ List<Uuid> listSubnetIds = new ArrayList<Uuid>();
if (!NeutronUtils.isUuid(intrf.getName())) {
LOG.debug("SubnetRouteInterfaceListener: Interface {} doesnt have valid uuid pattern", intrf.getName());
- return null;
+ return listSubnetIds;
}
PortOpDataEntry portOpEntry = subOpDpnManager.getPortOpDataEntry(intrf.getName());
if (portOpEntry != null) {
- return portOpEntry.getSubnetId();
+ List<Uuid> subnet = portOpEntry.getSubnetIds();
+ if (subnet != null) {
+ return subnet;
+ }
+ return listSubnetIds;
}
LOG.trace("SubnetRouteInterfaceListener : Received Port {} event for {} that is not part of subnetRoute",
intrf.getOperStatus(), intrf.getName());
Port port = neutronVpnManager.getNeutronPort(intrf.getName());
- if (port != null && port.getFixedIps() != null && port.getFixedIps().size() > 0) {
- return port.getFixedIps().get(0).getSubnetId();
- } else {
- return null;
+ if (port == null) {
+ return listSubnetIds;
+ }
+ List<FixedIps> portIps = port.getFixedIps();
+ if (port.getFixedIps() != null) {
+ for (FixedIps portIp : portIps) {
+ listSubnetIds.add(portIp.getSubnetId());
+ }
}
+ return listSubnetIds;
}
}
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.netvirt.l3vpn.rev130911.Adjacencies;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency.AdjacencyType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance;
*/
// TODO(vivek) # It is not yet clear, where we are cleaning up the prefix-to-interface
// TODO(vivek) # for primary adjacencies and that has to be fixed.
- Adjacency adjacency = adjs.getAdjacency().get(0);
List<Prefixes> prefixToInterface = new ArrayList<>();
- Optional<Prefixes> prefix = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL,
- VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(),
- VpnUtil.getIpPrefix(adjacency.getIpAddress())));
- if (prefix.isPresent()) {
- prefixToInterface.add(prefix.get());
- }
- if (prefixToInterface.isEmpty()) {
- for (String nh : adjacency.getNextHopIpList()) {
- prefix = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL,
- VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(),
- VpnUtil.getIpPrefix(nh)));
- if (prefix.isPresent()) {
- prefixToInterface.add(prefix.get());
+ for (Adjacency adjacency : adjs.getAdjacency()) {
+ List<Prefixes> prefixToInterfaceLocal = new ArrayList<>();
+ if (adjacency.getAdjacencyType() != AdjacencyType.PrimaryAdjacency) {
+ continue;
+ }
+ Optional<Prefixes> prefix = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL,
+ VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(),
+ VpnUtil.getIpPrefix(adjacency.getIpAddress())));
+ if (prefix.isPresent()) {
+ prefixToInterfaceLocal.add(prefix.get());
+ }
+ if (prefixToInterfaceLocal.isEmpty()) {
+ for (String nh : adjacency.getNextHopIpList()) {
+ prefix = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL,
+ VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(),
+ VpnUtil.getIpPrefix(nh)));
+ if (prefix.isPresent()) {
+ prefixToInterfaceLocal.add(prefix.get());
+ }
}
}
+ if (!prefixToInterfaceLocal.isEmpty()) {
+ prefixToInterface.addAll(prefixToInterfaceLocal);
+ }
}
/*
* In VPN Migration scenarios, there is a race condition where we use the new DPNID
List<Adjacency> adjList = (adjs != null) ? adjs.getAdjacency() : null;
if (vpnInstOp != null && adjList != null && adjList.size() > 0) {
- Adjacency adjacency = adjs.getAdjacency().get(0);
List<Prefixes> prefixToInterfaceList = new ArrayList<>();
- Optional<Prefixes> prefixToInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL,
- VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(),
+ for (Adjacency adjacency : adjs.getAdjacency()) {
+ List<Prefixes> prefixToInterfaceListLocal = new ArrayList<>();
+ if (adjacency.getAdjacencyType() != AdjacencyType.PrimaryAdjacency) {
+ continue;
+ }
+ Optional<Prefixes> prefixToInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL,
+ VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(),
VpnUtil.getIpPrefix(adjacency.getIpAddress())));
- if (prefixToInterface.isPresent()) {
- prefixToInterfaceList.add(prefixToInterface.get());
- } else {
- for (String adj : adjacency.getNextHopIpList()) {
- prefixToInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL,
- VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(),
- VpnUtil.getIpPrefix(adj)));
- if (prefixToInterface.isPresent()) {
- prefixToInterfaceList.add(prefixToInterface.get());
+ if (prefixToInterface.isPresent()) {
+ prefixToInterfaceListLocal.add(prefixToInterface.get());
+ } else {
+ for (String adj : adjacency.getNextHopIpList()) {
+ prefixToInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL,
+ VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(),
+ VpnUtil.getIpPrefix(adj)));
+ if (prefixToInterface.isPresent()) {
+ prefixToInterfaceListLocal.add(prefixToInterface.get());
+ }
}
}
- }
- for (Prefixes prefix : prefixToInterfaceList) {
- vpnFootprintService.updateVpnToDpnMapping(prefix.getDpnId(), original.getVpnInstanceName(), rd,
- interfaceName, null /*ipAddressSourceValuePair*/, false /* delete */);
+ for (Prefixes prefix : prefixToInterfaceListLocal) {
+ vpnFootprintService.updateVpnToDpnMapping(prefix.getDpnId(),
+ original.getVpnInstanceName(), rd,
+ interfaceName, null /*ipAddressSourceValuePair*/, false /* delete */);
+ }
}
}
LOG.info("postProcessVpnInterfaceUpdate: Updated vpn operational data and vpn footprint"