import java.util.HashSet;
import java.util.List;
import java.util.Set;
-
+import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
import org.opendaylight.genius.datastoreutils.DataStoreJobCoordinator;
+import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
import org.opendaylight.genius.mdsalutil.NwConstants;
import org.opendaylight.netvirt.elanmanager.api.IElanService;
return;
}
NeutronvpnUtils.addToPortCache(input);
-
String portStatus = NeutronUtils.PORT_STATUS_DOWN;
if (!Strings.isNullOrEmpty(input.getDeviceOwner()) && !Strings.isNullOrEmpty(input.getDeviceId())) {
if (input.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF)) {
if (input.getFixedIps() != null && !input.getFixedIps().isEmpty()) {
handleNeutronPortCreated(input);
}
-
NeutronUtils.createPortStatus(input.getUuid().getValue(), portStatus, dataBroker);
}
}
@Override
- // TODO Clean up the exception handling
- @SuppressWarnings("checkstyle:IllegalCatch")
protected void update(InstanceIdentifier<Port> identifier, Port original, Port update) {
final String portName = update.getUuid().getValue();
- LOG.trace("Updating Port : key: {}, original value={}, update value={}", identifier, original, update);
+ LOG.info("Update port {} from network {}", portName, update.getNetworkId().toString());
Network network = NeutronvpnUtils.getNeutronNetwork(dataBroker, update.getNetworkId());
+ LOG.info("Update port {} from network {}", portName, update.getNetworkId().toString());
if (network == null || !NeutronvpnUtils.isNetworkTypeSupported(network)) {
- LOG.warn("neutron vpn received a port update() for a network without a provider extension augmentation "
+ LOG.error("neutron vpn received a port update() for a network without a provider extension augmentation "
+ "or with an unsupported network type for the port {} which is part of network {}",
portName, network);
return;
portDataStoreCoordinator.enqueueJob("PORT- " + portName, () -> {
WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
try {
- Optional<Interface> optionalInf = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType
- .CONFIGURATION, interfaceIdentifier);
+ Optional<Interface> optionalInf =
+ SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ interfaceIdentifier);
if (optionalInf.isPresent()) {
InterfaceBuilder interfaceBuilder = new InterfaceBuilder(optionalInf.get());
- if (origSecurityEnabled || updatedSecurityEnabled) {
- InterfaceAcl infAcl = handlePortSecurityUpdated(original, update,
- origSecurityEnabled, updatedSecurityEnabled, interfaceBuilder).build();
- interfaceBuilder.addAugmentation(InterfaceAcl.class, infAcl);
- }
- LOG.info("Of-port-interface updation for port {}", portName);
+ InterfaceAcl infAcl = handlePortSecurityUpdated(dataBroker, original, update,
+ origSecurityEnabled, updatedSecurityEnabled, interfaceBuilder).build();
+ interfaceBuilder.addAugmentation(InterfaceAcl.class, infAcl);
+ LOG.info("update: Of-port-interface updation for port {}", portName);
// Update OFPort interface for this neutron port
wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier,
interfaceBuilder.build());
} else {
- LOG.error("Interface {} is not present", portName);
+ LOG.warn("update: Interface {} is not present", portName);
}
- } catch (Exception e) {
- LOG.error("Failed to update interface {}", portName, e);
+ } catch (ReadFailedException e) {
+ LOG.error("update: Failed to update interface {}", portName, e);
}
List<ListenableFuture<Void>> futures = new ArrayList<>();
futures.add(wrtConfigTxn.submit());
elanService.handleKnownL3DmacAddress(routerPort.getMacAddress().getValue(), infNetworkId.getValue(),
NwConstants.ADD_FLOW);
if (existingVpnId == null) {
+ Uuid vpnId = NeutronvpnUtils.getVpnForRouter(dataBroker, routerId, true);
+ List<Subnetmap> subnetMapList = new ArrayList<>();
+ if (vpnId == null) {
+ vpnId = routerId;
+ }
for (FixedIps portIP : routerPort.getFixedIps()) {
- Uuid vpnId = NeutronvpnUtils.getVpnForRouter(dataBroker, routerId, true);
- if (vpnId == null) {
- vpnId = routerId;
- }
// NOTE: Please donot change the order of calls to updateSubnetNodeWithFixedIP
// and addSubnetToVpn here
String ipValue = String.valueOf(portIP.getIpAddress().getValue());
- nvpnManager.updateSubnetNodeWithFixedIp(portIP.getSubnetId(), routerId,
+ Uuid subnetId = portIP.getSubnetId();
+ nvpnManager.updateSubnetNodeWithFixedIp(subnetId, routerId,
routerPort.getUuid(), ipValue, routerPort.getMacAddress().getValue());
- nvpnManager.createVpnInterface(vpnId, routerId, routerPort, null);
+ Subnetmap sn = NeutronvpnUtils.getSubnetmap(dataBroker, subnetId);
+ subnetMapList.add(sn);
+ }
+ if (! subnetMapList.isEmpty()) {
+ nvpnManager.createVpnInterface(vpnId, routerPort, null);
+ }
+ for (FixedIps portIP : routerPort.getFixedIps()) {
+ String ipValue = String.valueOf(portIP.getIpAddress().getValue());
nvpnManager.addSubnetToVpn(vpnId, portIP.getSubnetId());
- nvpnNatManager.handleSubnetsForExternalRouter(routerId, dataBroker);
- WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
- String portInterfaceName = createOfPortInterface(routerPort, wrtConfigTxn);
- createElanInterface(routerPort, portInterfaceName, wrtConfigTxn);
- wrtConfigTxn.submit();
- PhysAddress mac = new PhysAddress(routerPort.getMacAddress().getValue());
LOG.trace("NeutronPortChangeListener Add Subnet Gateway IP {} MAC {} Interface {} VPN {}",
ipValue, routerPort.getMacAddress(),
routerPort.getUuid().getValue(), vpnId.getValue());
-
}
+ nvpnNatManager.handleSubnetsForExternalRouter(routerId, dataBroker);
+ WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
+ String portInterfaceName = createOfPortInterface(routerPort, wrtConfigTxn);
+ createElanInterface(routerPort, portInterfaceName, wrtConfigTxn);
+ wrtConfigTxn.submit();
+ PhysAddress mac = new PhysAddress(routerPort.getMacAddress().getValue());
} else {
LOG.error("Neutron network {} corresponding to router interface port {} for neutron router {} already"
+ " associated to VPN {}", infNetworkId.getValue(), routerPort.getUuid().getValue(),
elanService.handleKnownL3DmacAddress(routerPort.getMacAddress().getValue(), infNetworkId.getValue(),
NwConstants.DEL_FLOW);
+ List<Subnetmap> subnetMapList = new ArrayList<>();
+ Uuid vpnId = NeutronvpnUtils.getVpnForRouter(dataBroker, routerId, true);
+ if (vpnId == null) {
+ vpnId = routerId;
+ }
+ for (FixedIps portIP : routerPort.getFixedIps()) {
+ Subnetmap sn = NeutronvpnUtils.getSubnetmap(dataBroker, portIP.getSubnetId());
+ subnetMapList.add(sn);
+ }
+ /* Remove ping responder for router interfaces
+ * A router interface reference in a VPN will have to be removed before the host interface references
+ * for that subnet in the VPN are removed. This is to ensure that the FIB Entry of the router interface
+ * is not the last entry to be removed for that subnet in the VPN.
+ * If router interface FIB entry is the last to be removed for a subnet in a VPN , then all the host
+ * interface references in the vpn will already have been cleared, which will cause failures in
+ * cleanup of router interface flows*/
+ nvpnManager.deleteVpnInterface(vpnId, routerPort, null);
for (FixedIps portIP : routerPort.getFixedIps()) {
- Uuid vpnId = NeutronvpnUtils.getVpnForRouter(dataBroker, routerId, true);
- if (vpnId == null) {
- vpnId = routerId;
- }
- /* Remove ping responder for router interfaces
- * A router interface reference in a VPN will have to be removed before the host interface references
- * for that subnet in the VPN are removed. This is to ensure that the FIB Entry of the router interface
- * is not the last entry to be removed for that subnet in the VPN.
- * If router interface FIB entry is the last to be removed for a subnet in a VPN , then all the host
- * interface references in the vpn will already have been cleared, which will cause failures in
- * cleanup of router interface flows*/
- nvpnManager.deleteVpnInterface(vpnId, routerId, routerPort, null);
// NOTE: Please donot change the order of calls to removeSubnetFromVpn and
// and updateSubnetNodeWithFixedIP
nvpnManager.removeSubnetFromVpn(vpnId, portIP.getSubnetId());
private void handleNeutronPortCreated(final Port port) {
final String portName = port.getUuid().getValue();
final Uuid portId = port.getUuid();
- final Uuid subnetId = port.getFixedIps().get(0).getSubnetId();
+ final List<FixedIps> portIpAddrsList = port.getFixedIps();
final DataStoreJobCoordinator portDataStoreCoordinator = DataStoreJobCoordinator.getInstance();
if (NeutronConstants.IS_ODL_DHCP_PORT.test(port)) {
return;
portDataStoreCoordinator.enqueueJob("PORT- " + portName, () -> {
WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
List<ListenableFuture<Void>> futures = new ArrayList<>();
-
// add direct port to subnetMaps config DS
if (!NeutronUtils.isPortVnicTypeNormal(port)) {
- nvpnManager.updateSubnetmapNodeWithPorts(subnetId, null, portId);
+ for (FixedIps ip: portIpAddrsList) {
+ nvpnManager.updateSubnetmapNodeWithPorts(ip.getSubnetId(), null, portId);
+ futures.add(wrtConfigTxn.submit());
+ }
LOG.info("Port {} is not a NORMAL VNIC Type port; OF Port interfaces are not created", portName);
- futures.add(wrtConfigTxn.submit());
return futures;
}
LOG.info("Of-port-interface creation for port {}", portName);
String portInterfaceName = createOfPortInterface(port, wrtConfigTxn);
LOG.debug("Creating ELAN Interface for port {}", portName);
createElanInterface(port, portInterfaceName, wrtConfigTxn);
-
- Subnetmap subnetMap = nvpnManager.updateSubnetmapNodeWithPorts(subnetId, portId, null);
- Uuid vpnId = (subnetMap != null) ? subnetMap.getVpnId() : null;
- Uuid routerId = (subnetMap != null) ? subnetMap.getRouterId() : null;
+ Uuid vpnId = null;
+ for (FixedIps ip: portIpAddrsList) {
+ Subnetmap subnetMap = nvpnManager.updateSubnetmapNodeWithPorts(ip.getSubnetId(), portId, null);
+ if (subnetMap != null && subnetMap.getVpnId() != null) {
+ // can't use NeutronvpnUtils.getVpnForNetwork to optimise here, because it gives BGPVPN id
+ // obtained subnetMaps belongs to one network => vpnId must be the same for each port Ip
+ vpnId = subnetMap.getVpnId();
+ }
+ }
if (vpnId != null) {
- // create vpn-interface on this neutron port
- LOG.debug("Adding VPN Interface for port {}", portName);
- nvpnManager.createVpnInterface(vpnId, routerId, port, wrtConfigTxn);
+ // create new vpn-interface for neutron port
+ LOG.debug("handleNeutronPortCreated: Adding VPN Interface for port {} from network {}", portName,
+ port.getNetworkId().toString());
+ nvpnManager.createVpnInterface(vpnId, port, wrtConfigTxn);
}
futures.add(wrtConfigTxn.submit());
return futures;
private void handleNeutronPortDeleted(final Port port) {
final String portName = port.getUuid().getValue();
final Uuid portId = port.getUuid();
- final Uuid subnetId = port.getFixedIps().get(0).getSubnetId();
- if (NeutronConstants.IS_ODL_DHCP_PORT.test(port)) {
- return;
- }
+ final List<FixedIps> portIpsList = port.getFixedIps();
final DataStoreJobCoordinator portDataStoreCoordinator = DataStoreJobCoordinator.getInstance();
portDataStoreCoordinator.enqueueJob("PORT- " + portName, () -> {
WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
List<ListenableFuture<Void>> futures = new ArrayList<>();
-
- // remove direct port from subnetMaps config DS
if (!NeutronUtils.isPortVnicTypeNormal(port)) {
- nvpnManager.removePortsFromSubnetmapNode(subnetId, null, portId);
+ for (FixedIps ip: portIpsList) {
+ // remove direct port from subnetMaps config DS
+ nvpnManager.removePortsFromSubnetmapNode(ip.getSubnetId(), null, portId);
+ futures.add(wrtConfigTxn.submit());
+ }
LOG.info("Port {} is not a NORMAL VNIC Type port; OF Port interfaces are not created", portName);
- futures.add(wrtConfigTxn.submit());
return futures;
}
- Subnetmap subnetMap = nvpnManager.removePortsFromSubnetmapNode(subnetId, portId, null);
- Uuid vpnId = (subnetMap != null) ? subnetMap.getVpnId() : null;
- Uuid routerId = (subnetMap != null) ? subnetMap.getRouterId() : null;
+ Uuid vpnId = null;
+ for (FixedIps ip: portIpsList) {
+ Subnetmap subnetMap = nvpnManager.removePortsFromSubnetmapNode(ip.getSubnetId(), portId, null);
+ if (subnetMap != null && subnetMap.getVpnId() != null) {
+ // can't use NeutronvpnUtils.getVpnForNetwork to optimise here, because it gives BGPVPN id
+ // obtained subnetMaps belongs to one network => vpnId must be the same for each port Ip
+ vpnId = subnetMap.getVpnId();
+ }
+ }
if (vpnId != null) {
// remove vpn-interface for this neutron port
LOG.debug("removing VPN Interface for port {}", portName);
- nvpnManager.deleteVpnInterface(vpnId, routerId, port, wrtConfigTxn);
+ nvpnManager.deleteVpnInterface(vpnId, port, wrtConfigTxn);
}
// Remove of-port interface for this neutron port
// ELAN interface is also implicitly deleted as part of this operation
});
}
+
private void handleNeutronPortUpdated(final Port portoriginal, final Port portupdate) {
- if (portoriginal.getFixedIps() == null || portoriginal.getFixedIps().isEmpty()) {
+ final List<FixedIps> portoriginalIps = portoriginal.getFixedIps();
+ final List<FixedIps> portupdateIps = portupdate.getFixedIps();
+ LOG.trace("PORT ORIGINAL: {} from network {} with fixed IPs: {}; "
+ + "PORT UPDATE: {} from network {} with fixed IPs: {}",
+ portoriginal.getName(), portoriginal.getNetworkId().toString(), portoriginalIps.toString(),
+ portupdate.getName(), portupdate.getNetworkId().toString(), portupdateIps.toString());
+ if (portoriginalIps == null || portoriginalIps.isEmpty()) {
handleNeutronPortCreated(portupdate);
return;
}
-
- if (portupdate.getFixedIps() == null || portupdate.getFixedIps().isEmpty()) {
- LOG.debug("Ignoring portUpdate (fixed_ip removal) for port {} as this case is handled "
+ if (portupdateIps == null || portupdateIps.isEmpty()) {
+ LOG.info("Ignoring portUpdate (fixed_ip removal) for port {} as this case is handled "
+ "during subnet deletion event.", portupdate.getUuid().getValue());
return;
}
final DataStoreJobCoordinator portDataStoreCoordinator = DataStoreJobCoordinator.getInstance();
portDataStoreCoordinator.enqueueJob("PORT- " + portupdate.getUuid().getValue(), () -> {
WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
- Uuid vpnIdOld = null;
- Uuid vpnIdNew = null;
- final Uuid oldSubnetId = portoriginal.getFixedIps().get(0).getSubnetId();
- final Uuid newSubnetId = portupdate.getFixedIps().get(0).getSubnetId();
- // check if subnet UUID has changed upon change in fixedIP
- final Boolean subnetUpdated = oldSubnetId.equals(newSubnetId) ? false : true;
- if (subnetUpdated) {
- Subnetmap subnetMapOld = nvpnManager.removePortsFromSubnetmapNode(oldSubnetId, portoriginal
- .getUuid(), null);
- vpnIdOld = (subnetMapOld != null) ? subnetMapOld.getVpnId() : null;
- Subnetmap subnetMapNew = nvpnManager.updateSubnetmapNodeWithPorts(newSubnetId, portupdate
- .getUuid(), null);
- vpnIdNew = (subnetMapNew != null) ? subnetMapNew.getVpnId() : null;
+ List<ListenableFuture<Void>> futures = new ArrayList<>();
+ final List<Uuid> originalSnMapsIds = portoriginalIps.stream().map(ip -> ip.getSubnetId())
+ .collect(Collectors.toList());
+ final List<Uuid> updateSnMapsIds = portupdateIps.stream().map(ip -> ip.getSubnetId())
+ .collect(Collectors.toList());
+ for (Uuid snId: originalSnMapsIds) {
+ if (!updateSnMapsIds.remove(snId)) {
+ // snId was present in originalSnMapsIds, but not in updateSnMapsIds
+ nvpnManager.removePortsFromSubnetmapNode(snId, portoriginal.getUuid(), null);
+ }
}
- if (!subnetUpdated) {
- Subnetmap subnetmap = NeutronvpnUtils.getSubnetmap(dataBroker, newSubnetId);
- vpnIdNew = subnetmap != null ? subnetmap.getVpnId() : null;
+ for (Uuid snId: updateSnMapsIds) {
+ nvpnManager.updateSubnetmapNodeWithPorts(snId, portupdate.getUuid(), null);
}
- if (vpnIdNew != null) {
- // remove vpn-interface for this neutron port
- LOG.debug("removing VPN Interface for port {}", portoriginal.getUuid().getValue());
- nvpnManager.deleteVpnInterface(vpnIdOld, null, portoriginal, wrtConfigTxn);
- // create vpn-interface on this neutron port
- LOG.debug("Adding VPN Interface for port {}", portupdate.getUuid().getValue());
- nvpnManager.createVpnInterface(vpnIdNew, null, portupdate, wrtConfigTxn);
+ final Uuid oldVpnId = NeutronvpnUtils.getVpnForNetwork(dataBroker, portoriginal.getNetworkId());
+ if (oldVpnId != null) {
+ LOG.info("removing VPN Interface for port {}", portoriginal.getUuid().getValue());
+ nvpnManager.deleteVpnInterface(oldVpnId, portoriginal, wrtConfigTxn);
+ futures.add(wrtConfigTxn.submit());
+ }
+ final Uuid newVpnId = NeutronvpnUtils.getVpnForNetwork(dataBroker, portupdate.getNetworkId());
+ if (newVpnId != null) {
+ LOG.info("Adding VPN Interface for port {}", portupdate.getUuid().getValue());
+ nvpnManager.createVpnInterface(newVpnId, portupdate, wrtConfigTxn);
+ futures.add(wrtConfigTxn.submit());
}
- List<ListenableFuture<Void>> futures = new ArrayList<>();
- futures.add(wrtConfigTxn.submit());
return futures;
});
}
- private static InterfaceAclBuilder handlePortSecurityUpdated(Port portOriginal, Port portUpdated, boolean
- origSecurityEnabled, boolean updatedSecurityEnabled, InterfaceBuilder interfaceBuilder) {
+ private static InterfaceAclBuilder handlePortSecurityUpdated(DataBroker dataBroker, Port portOriginal,
+ Port portUpdated, boolean origSecurityEnabled, boolean updatedSecurityEnabled,
+ InterfaceBuilder interfaceBuilder) {
String interfaceName = portUpdated.getUuid().getValue();
InterfaceAclBuilder interfaceAclBuilder = null;
if (origSecurityEnabled != updatedSecurityEnabled) {
return interfaceAclBuilder;
}
- // TODO Clean up the exception handling
- @SuppressWarnings("checkstyle:IllegalCatch")
private String createOfPortInterface(Port port, WriteTransaction wrtConfigTxn) {
Interface inf = createInterface(port);
String infName = inf.getName();
- LOG.debug("Creating OFPort Interface {}", infName);
InstanceIdentifier interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(infName);
try {
- Optional<Interface> optionalInf = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION,
- interfaceIdentifier);
+ Optional<Interface> optionalInf =
+ SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ interfaceIdentifier);
if (!optionalInf.isPresent()) {
wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier, inf);
} else {
LOG.warn("Interface {} is already present", infName);
}
- } catch (Exception e) {
+ } catch (ReadFailedException e) {
LOG.error("failed to create interface {}", infName, e);
}
return infName;
interfaceAclBuilder.setPortSecurityEnabled(true);
NeutronvpnUtils.populateInterfaceAclBuilder(interfaceAclBuilder, port);
interfaceBuilder.addAugmentation(InterfaceAcl.class, interfaceAclBuilder.build());
+ NeutronvpnUtils.populateSubnetIpPrefixes(dataBroker, port);
}
return interfaceBuilder.build();
}
- // TODO Clean up the exception handling
- @SuppressWarnings("checkstyle:IllegalCatch")
private void deleteOfPortInterface(Port port, WriteTransaction wrtConfigTxn) {
String name = port.getUuid().getValue();
LOG.debug("Removing OFPort Interface {}", name);
InstanceIdentifier interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(name);
try {
- Optional<Interface> optionalInf = NeutronvpnUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION,
- interfaceIdentifier);
+ Optional<Interface> optionalInf =
+ SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ interfaceIdentifier);
if (optionalInf.isPresent()) {
wrtConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier);
} else {
- LOG.error("Interface {} is not present", name);
+ LOG.warn("deleteOfPortInterface: Interface {} is not present", name);
}
- } catch (Exception e) {
- LOG.error("Failed to delete interface {}", name, e);
+ } catch (ReadFailedException e) {
+ LOG.error("deleteOfPortInterface: Failed to delete interface {}", name, e);
}
}