use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.Interfaces in project netvirt by opendaylight.
the class NeutronvpnManager method handleNeutronRouterDeleted.
protected void handleNeutronRouterDeleted(Uuid routerId, List<Uuid> routerSubnetIds) {
// check if the router is associated to some VPN
Uuid vpnId = neutronvpnUtils.getVpnForRouter(routerId, true);
Uuid internetVpnId = neutronvpnUtils.getInternetvpnUuidBoundToRouterId(routerId);
if (vpnId != null) {
// remove existing external vpn interfaces
for (Uuid subnetId : routerSubnetIds) {
removeSubnetFromVpn(vpnId, subnetId, internetVpnId);
}
clearFromVpnMaps(vpnId, routerId, null);
} else {
// remove existing internal vpn interfaces
for (Uuid subnetId : routerSubnetIds) {
removeSubnetFromVpn(routerId, subnetId, internetVpnId);
}
}
// delete entire vpnMaps node for internal VPN
deleteVpnMapsNode(routerId);
// delete vpn-instance for internal VPN
deleteVpnInstance(routerId);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.Interfaces in project netvirt by opendaylight.
the class NeutronvpnManager method removeFromNeutronRouterInterfacesMap.
protected void removeFromNeutronRouterInterfacesMap(Uuid routerId, String interfaceName) {
synchronized (routerId.getValue().intern()) {
InstanceIdentifier<RouterInterfaces> routerInterfacesId = getRouterInterfacesId(routerId);
try {
Optional<RouterInterfaces> optRouterInterfaces = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId);
Interfaces routerInterface = new InterfacesBuilder().setKey(new InterfacesKey(interfaceName)).setInterfaceId(interfaceName).build();
if (optRouterInterfaces.isPresent()) {
RouterInterfaces routerInterfaces = optRouterInterfaces.get();
List<Interfaces> interfaces = routerInterfaces.getInterfaces();
if (interfaces != null && interfaces.remove(routerInterface)) {
if (interfaces.isEmpty()) {
SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId);
} else {
SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)));
}
}
}
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Error reading the router interfaces for {}", routerInterfacesId, e);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.Interfaces in project netvirt by opendaylight.
the class NeutronvpnManager method addToNeutronRouterInterfacesMap.
protected void addToNeutronRouterInterfacesMap(Uuid routerId, String interfaceName) {
synchronized (routerId.getValue().intern()) {
InstanceIdentifier<RouterInterfaces> routerInterfacesId = getRouterInterfacesId(routerId);
try {
Optional<RouterInterfaces> optRouterInterfaces = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId);
Interfaces routerInterface = new InterfacesBuilder().setKey(new InterfacesKey(interfaceName)).setInterfaceId(interfaceName).build();
if (optRouterInterfaces.isPresent()) {
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)), routerInterface);
} else {
// TODO Shouldn't we be doing something with builder and interfaces?
// RouterInterfacesBuilder builder = new RouterInterfacesBuilder().setRouterId(routerId);
// List<Interfaces> interfaces = new ArrayList<>();
// interfaces.add(routerInterface);
SingleTransactionDataBroker.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)), routerInterface);
}
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Error reading router interfaces for {}", routerInterfacesId, e);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.Interfaces in project netvirt by opendaylight.
the class NeutronPortChangeListener method handleNeutronPortCreated.
private void handleNeutronPortCreated(final Port port) {
final String portName = port.getUuid().getValue();
final Uuid portId = port.getUuid();
final List<FixedIps> portIpAddrsList = port.getFixedIps();
if (NeutronConstants.IS_ODL_DHCP_PORT.test(port)) {
return;
}
jobCoordinator.enqueueJob("PORT- " + portName, () -> {
// add direct port to subnetMaps config DS
if (!(NeutronUtils.isPortVnicTypeNormal(port) || (isPortTypeSwitchdev(port) && isSupportedVnicTypeByHost(port, NeutronConstants.VNIC_TYPE_DIRECT)))) {
for (FixedIps ip : portIpAddrsList) {
nvpnManager.updateSubnetmapNodeWithPorts(ip.getSubnetId(), null, portId);
}
LOG.info("Port {} is not a normal and not a direct with switchdev VNIC type ;" + "OF Port interfaces are not created", portName);
return Collections.emptyList();
}
return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
LOG.info("Of-port-interface creation for port {}", portName);
// Create of-port interface for this neutron port
String portInterfaceName = createOfPortInterface(port, tx);
LOG.debug("Creating ELAN Interface for port {}", portName);
createElanInterface(port, portInterfaceName, tx);
Set<Uuid> vpnIdList = new HashSet<>();
Set<Uuid> routerIds = new HashSet<>();
for (FixedIps ip : portIpAddrsList) {
Subnetmap subnetMap = nvpnManager.updateSubnetmapNodeWithPorts(ip.getSubnetId(), portId, null);
if (subnetMap != null && subnetMap.getInternetVpnId() != null) {
if (!vpnIdList.contains(subnetMap.getInternetVpnId())) {
vpnIdList.add(subnetMap.getInternetVpnId());
}
}
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
Uuid vpnId = subnetMap.getVpnId();
if (vpnId != null) {
vpnIdList.add(vpnId);
}
}
if (subnetMap != null && subnetMap.getRouterId() != null) {
routerIds.add(subnetMap.getRouterId());
}
}
if (!vpnIdList.isEmpty()) {
// create new vpn-interface for neutron port
LOG.debug("handleNeutronPortCreated: Adding VPN Interface for port {} from network {}", portName, port.getNetworkId().toString());
nvpnManager.createVpnInterface(vpnIdList, port, tx);
if (!routerIds.isEmpty()) {
for (Uuid routerId : routerIds) {
nvpnManager.addToNeutronRouterInterfacesMap(routerId, port.getUuid().getValue());
}
}
}
}));
});
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.Interfaces in project netvirt by opendaylight.
the class NeutronPortChangeListener method handleRouterInterfaceRemoved.
private void handleRouterInterfaceRemoved(Port routerPort) {
if (routerPort.getDeviceId() != null) {
Uuid routerId = new Uuid(routerPort.getDeviceId());
Uuid infNetworkId = routerPort.getNetworkId();
elanService.removeKnownL3DmacAddress(routerPort.getMacAddress().getValue(), infNetworkId.getValue());
Uuid vpnId = neutronvpnUtils.getVpnForRouter(routerId, true);
if (vpnId == null) {
vpnId = routerId;
}
List<FixedIps> portIps = routerPort.getFixedIps();
boolean vpnInstanceInternetIpVersionRemoved = false;
Uuid vpnInstanceInternetUuid = null;
for (FixedIps portIP : portIps) {
// Internet VPN : flush InternetVPN first
Uuid subnetId = portIP.getSubnetId();
Subnetmap sn = neutronvpnUtils.getSubnetmap(subnetId);
if (sn != null && sn.getInternetVpnId() != null) {
if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, sn.getInternetVpnId())) {
vpnInstanceInternetIpVersionRemoved = true;
vpnInstanceInternetUuid = sn.getInternetVpnId();
}
nvpnManager.updateVpnInternetForSubnet(sn, sn.getInternetVpnId(), false);
}
}
/* 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(routerPort.getUuid().getValue(), null, /* vpn-id */
null);
// update RouterInterfaces map
WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
boolean vpnInstanceIpVersionRemoved = false;
IpVersionChoice vpnInstanceIpVersionToRemove = IpVersionChoice.UNDEFINED;
for (FixedIps portIP : portIps) {
Subnetmap sn = neutronvpnUtils.getSubnetmap(portIP.getSubnetId());
// router Port have either IPv4 or IPv6, never both
if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, vpnId)) {
vpnInstanceIpVersionRemoved = true;
vpnInstanceIpVersionToRemove = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
}
String ipValue = String.valueOf(portIP.getIpAddress().getValue());
neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipValue, wrtConfigTxn);
// NOTE: Please donot change the order of calls to removeSubnetFromVpn and
// and updateSubnetNodeWithFixedIP
nvpnManager.removeSubnetFromVpn(vpnId, portIP.getSubnetId(), sn != null ? sn.getInternetVpnId() : null);
nvpnManager.updateSubnetNodeWithFixedIp(portIP.getSubnetId(), null, null, null, null, null);
}
nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, routerPort.getUuid().getValue());
deleteElanInterface(routerPort.getUuid().getValue(), wrtConfigTxn);
deleteOfPortInterface(routerPort, wrtConfigTxn);
wrtConfigTxn.submit();
nvpnNatManager.handleSubnetsForExternalRouter(routerId);
if (vpnInstanceIpVersionRemoved) {
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), vpnInstanceIpVersionToRemove, false);
}
if (vpnInstanceInternetIpVersionRemoved) {
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnInstanceInternetUuid.getValue(), IpVersionChoice.IPV6, false);
neutronvpnUtils.updateVpnInstanceWithFallback(vpnInstanceInternetUuid.getValue(), false);
}
}
}
Aggregations