use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports in project netvirt by opendaylight.
the class IfMgr method removePort.
public void removePort(Uuid portId) {
VirtualPort intf = portId != null ? vintfs.remove(portId) : null;
if (intf != null) {
intf.removeSelf();
Uuid networkID = intf.getNetworkID();
if (intf.getDeviceOwner().equalsIgnoreCase(Ipv6ServiceConstants.NETWORK_ROUTER_INTERFACE)) {
LOG.info("In removePort for router interface, portId {}", portId);
if (networkID != null) {
vrouterv6IntfMap.remove(networkID, intf);
}
/* Router port is deleted. Remove the corresponding icmpv6 punt flows on all
the dpnIds which were hosting the VMs on the network.
*/
programIcmpv6RSPuntFlows(intf.getNetworkID(), Ipv6ServiceConstants.DEL_FLOW);
programIcmpv6NaPuntFlow(networkID, intf.getSubnets(), Ipv6ServiceConstants.DEL_FLOW);
if (Objects.equals(ipV6NAConfigHelper.getNaResponderMode(), Ipv6serviceConfig.NaResponderMode.Switch)) {
checkIcmpv6NsMatchAndResponderFlow(Uint64.ZERO, 0, intf, Ipv6ServiceConstants.DEL_FLOW);
} else {
for (Ipv6Address ipv6Address : intf.getIpv6Addresses()) {
programIcmpv6NSPuntFlowForAddress(intf.getNetworkID(), ipv6Address, Ipv6ServiceConstants.DEL_FLOW);
}
}
for (VirtualSubnet subnet : intf.getSubnets()) {
programIcmpv6NaForwardFlows(networkID, subnet, Ipv6ServiceConstants.DEL_FLOW);
}
} else {
LOG.info("In removePort for host interface, portId {}", portId);
String jobKey = Ipv6ServiceUtils.buildIpv6MonitorJobKey(portId.getValue());
coordinator.enqueueJob(jobKey, () -> {
// Remove the serviceBinding entry for the port.
ipv6ServiceUtils.unbindIpv6Service(portId.getValue());
// Remove the portId from the (network <--> List[dpnIds, List <ports>]) cache.
VirtualNetwork vnet = getNetwork(networkID);
if (null != vnet) {
Uint64 dpId = intf.getDpId();
vnet.updateDpnPortInfo(dpId, intf.getOfPort(), portId, Ipv6ServiceConstants.DEL_ENTRY);
}
if (Objects.equals(ipV6NAConfigHelper.getNaResponderMode(), Ipv6serviceConfig.NaResponderMode.Switch)) {
if (intf.getDpId() != null) {
checkIcmpv6NsMatchAndResponderFlow(intf.getDpId(), 0, intf, Ipv6ServiceConstants.DEL_FLOW);
} else {
checkIcmpv6NsMatchAndResponderFlow(Uint64.ZERO, 0, intf, Ipv6ServiceConstants.DEL_FLOW);
}
}
return Collections.emptyList();
});
}
transmitRouterAdvertisement(intf, Ipv6RouterAdvertisementType.CEASE_ADVERTISEMENT);
timer.cancelPeriodicTransmissionTimeout(intf.getPeriodicTimeout());
intf.resetPeriodicTimeout();
LOG.debug("Reset the periodic RA Timer for intf {}", intf.getIntfUUID());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports in project netvirt by opendaylight.
the class VpnSubnetRouteHandler method onSubnetDeletedFromVpn.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void onSubnetDeletedFromVpn(Subnetmap subnetmap, boolean isBgpVpn) {
Uuid subnetId = subnetmap.getId();
LOG.info("{} onSubnetDeletedFromVpn: Subnet {} with ip {} being removed from vpnId {}", LOGGING_PREFIX, subnetId, subnetmap.getSubnetIp(), subnetmap.getVpnId());
// TODO(vivek): Change this to use more granularized lock at subnetId level
try {
vpnUtil.lockSubnet(subnetId.getValue());
InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
Optional<SubnetOpDataEntry> optionalSubs = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
if (!optionalSubs.isPresent()) {
LOG.error("{} onSubnetDeletedFromVpn: SubnetOpDataEntry for subnet {} subnetIp {} vpn {}" + " not available in datastore", LOGGING_PREFIX, subnetId.getValue(), subnetId.getValue(), subnetmap.getVpnId());
return;
}
LOG.trace("{} onSubnetDeletedFromVpn: Removing the SubnetOpDataEntry node for subnet {} subnetIp {}" + " vpnName {} rd {} TaskState {}", LOGGING_PREFIX, subnetId.getValue(), optionalSubs.get().getSubnetCidr(), optionalSubs.get().getVpnName(), optionalSubs.get().getVrfId(), optionalSubs.get().getRouteAdvState());
/* If subnet is deleted (or if its removed from VPN), the ports that are DOWN on that subnet
* will continue to be stale in portOpData DS, as subDpnList used for portOpData removal will
* contain only ports that are UP. So here we explicitly cleanup the ports of the subnet by
* going through the list of ports on the subnet
*/
List<Uuid> portList = subnetmap.getPortList();
if (portList != null) {
for (Uuid port : portList) {
InstanceIdentifier<PortOpDataEntry> portOpIdentifier = InstanceIdentifier.builder(PortOpData.class).child(PortOpDataEntry.class, new PortOpDataEntryKey(port.getValue())).build();
LOG.trace("{} onSubnetDeletedFromVpn: Deleting portOpData entry for port {}" + " from subnet {} subnetIp {} vpnName {} TaskState {}", LOGGING_PREFIX, port.getValue(), subnetId.getValue(), optionalSubs.get().getSubnetCidr(), optionalSubs.get().getVpnName(), optionalSubs.get().getRouteAdvState());
SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier, VpnUtil.SINGLE_TRANSACTION_BROKER_NO_RETRY);
}
}
SubnetOpDataEntryBuilder subOpBuilder = new SubnetOpDataEntryBuilder(optionalSubs.get());
String rd = subOpBuilder.getVrfId();
String subnetIp = subOpBuilder.getSubnetCidr();
String vpnName = subOpBuilder.getVpnName();
// Withdraw the routes for all the interfaces on this subnet
// Remove subnet route entry from FIB
deleteSubnetRouteFromFib(rd, subnetIp, vpnName, isBgpVpn);
SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier, VpnUtil.SINGLE_TRANSACTION_BROKER_NO_RETRY);
int releasedLabel = vpnUtil.releaseId(VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(rd, subnetIp));
if (releasedLabel == VpnConstants.INVALID_LABEL) {
LOG.error("onSubnetDeletedFromVpn: Unable to release label for key {}", VpnUtil.getNextHopLabelKey(rd, subnetIp));
}
LOG.info("{} onSubnetDeletedFromVpn: Removed subnetopdataentry successfully from Datastore" + " for subnet {} subnetIp {} vpnName {} rd {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, rd);
} catch (RuntimeException e) {
// TODO: Avoid this
LOG.error("{} onSubnetDeletedFromVpn: Unable to handle subnet {} with Ip {} removed from vpn {}", LOGGING_PREFIX, subnetId.getValue(), subnetmap.getSubnetIp(), subnetmap.getVpnId(), e);
} catch (TransactionCommitFailedException ex) {
LOG.error("{} onSubnetDeletedFromVpn: Removal of SubnetOpDataEntry for subnet {} subnetIp {}" + " vpnId {} failed", LOGGING_PREFIX, subnetId.getValue(), subnetmap.getSubnetIp(), subnetmap.getVpnId(), ex);
} catch (InterruptedException | ExecutionException e) {
LOG.error("{} onSubnetDeletedFromVpn: Failed to read data store for subnet {} ip {} vpn {}", LOGGING_PREFIX, subnetId, subnetmap.getSubnetIp(), subnetmap.getVpnId());
} finally {
vpnUtil.unlockSubnet(subnetId.getValue());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnForSubnet.
@Nullable
private Subnetmap updateVpnForSubnet(Uuid oldVpnId, Uuid newVpnId, Uuid subnet, boolean isBeingAssociated) {
LOG.debug("Moving subnet {} from oldVpn {} to newVpn {} ", subnet.getValue(), oldVpnId.getValue(), newVpnId.getValue());
Uuid networkUuid = neutronvpnUtils.getSubnetmap(subnet).getNetworkId();
Network network = neutronvpnUtils.getNeutronNetwork(networkUuid);
boolean netIsExternal = NeutronvpnUtils.getIsExternal(network);
Uuid vpnExtUuid = netIsExternal ? neutronvpnUtils.getInternetvpnUuidBoundToSubnetRouter(subnet) : null;
Subnetmap sn = updateSubnetNode(subnet, null, newVpnId, vpnExtUuid);
if (sn == null) {
LOG.error("Updating subnet {} with newVpn {} failed", subnet.getValue(), newVpnId.getValue());
return sn;
}
/* vpnExtUuid will contain the value only on if the subnet is V6 and it is already been
* associated with internet BGP-VPN.
*/
if (vpnExtUuid != null) {
/* Update V6 Internet default route match with new VPN metadata.
* isBeingAssociated = true means oldVpnId is same as routerId
* isBeingAssociated = false means newVpnId is same as routerId
*/
if (isBeingAssociated) {
neutronvpnUtils.updateVpnInstanceWithFallback(oldVpnId, vpnExtUuid, true);
} else {
neutronvpnUtils.updateVpnInstanceWithFallback(newVpnId, vpnExtUuid, true);
}
}
// Update Router Interface first synchronously.
// CAUTION: Please DONOT make the router interface VPN Movement as an asynchronous commit again !
ListenableFuture<?> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> updateVpnInterface(newVpnId, oldVpnId, neutronvpnUtils.getNeutronPort(sn.getRouterInterfacePortId()), isBeingAssociated, true, tx, false));
Futures.addCallback(future, new FutureCallback<Object>() {
@Override
public void onSuccess(Object result) {
// Check for ports on this subnet and update association of
// corresponding vpn-interfaces to external vpn
List<Uuid> portList = sn.getPortList();
if (portList != null) {
for (Uuid port : portList) {
LOG.debug("Updating vpn-interface for port {} isBeingAssociated {}", port.getValue(), isBeingAssociated);
jobCoordinator.enqueueJob("PORT-" + port.getValue(), () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> updateVpnInterface(newVpnId, oldVpnId, neutronvpnUtils.getNeutronPort(port), isBeingAssociated, false, tx, false))));
}
}
}
@Override
public void onFailure(Throwable throwable) {
LOG.error("Failed to update router interface {} in subnet {} from oldVpnId {} to newVpnId {}, " + "returning", sn.getRouterInterfacePortId().getValue(), subnet.getValue(), oldVpnId, newVpnId, throwable);
}
}, MoreExecutors.directExecutor());
return sn;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports in project netvirt by opendaylight.
the class NeutronvpnManager method addSubnetToVpn.
protected void addSubnetToVpn(@Nullable final Uuid vpnId, Uuid subnet, @Nullable final Uuid internetVpnId) {
LOG.debug("addSubnetToVpn: Adding subnet {} to vpn {}", subnet.getValue(), vpnId != null ? vpnId.getValue() : internetVpnId.getValue());
Subnetmap sn = updateSubnetNode(subnet, null, vpnId, internetVpnId);
if (sn == null) {
LOG.error("addSubnetToVpn: subnetmap is null, cannot add subnet {} to VPN {}", subnet.getValue(), vpnId != null ? vpnId.getValue() : internetVpnId.getValue());
return;
}
if (vpnId != null) {
VpnMap vpnMap = neutronvpnUtils.getVpnMap(vpnId);
if (vpnMap == null) {
LOG.error("addSubnetToVpn: No vpnMap for vpnId {}," + " cannot add subnet {} to VPN", vpnId.getValue(), subnet.getValue());
return;
}
final VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpnId.getValue());
LOG.debug("addSubnetToVpn: VpnInstance {}", vpnInstance);
if (isVpnOfTypeL2(vpnInstance)) {
neutronEvpnUtils.updateElanAndVpn(vpnInstance, sn.getNetworkId().getValue(), NeutronEvpnUtils.Operation.ADD);
}
}
if (internetVpnId != null) {
VpnMap vpnMap = neutronvpnUtils.getVpnMap(internetVpnId);
if (vpnMap == null) {
LOG.error("addSubnetToVpn: No vpnMap for InternetVpnId {}, cannot add " + "subnet {} to VPN", internetVpnId.getValue(), subnet.getValue());
return;
}
}
final Uuid internetId = internetVpnId;
// Check if there are ports on this subnet and add corresponding vpn-interfaces
List<Uuid> portList = sn.getPortList();
if (portList != null) {
for (final Uuid portId : portList) {
String vpnInfName = portId.getValue();
VpnInterface vpnIface = VpnHelper.getVpnInterface(dataBroker, vpnInfName);
Port port = neutronvpnUtils.getNeutronPort(portId);
if (port == null) {
LOG.error("addSubnetToVpn: Cannot proceed with addSubnetToVpn for port {} in subnet {} " + "since port is absent in Neutron config DS", portId.getValue(), subnet.getValue());
continue;
}
final Boolean isRouterInterface = port.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF) ? true : false;
jobCoordinator.enqueueJob("PORT-" + portId.getValue(), () -> {
ListenableFuture<?> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, wrtConfigTxn -> {
Adjacencies portAdj = createPortIpAdjacencies(port, isRouterInterface, wrtConfigTxn, vpnIface);
if (vpnIface == null) {
LOG.trace("addSubnetToVpn: create new VpnInterface for Port {}", vpnInfName);
Set<Uuid> listVpn = new HashSet<>();
if (vpnId != null) {
listVpn.add(vpnId);
}
if (internetId != null) {
listVpn.add(internetId);
}
writeVpnInterfaceToDs(listVpn, vpnInfName, portAdj, port.getNetworkId(), isRouterInterface, wrtConfigTxn);
if (sn.getRouterId() != null) {
addToNeutronRouterInterfacesMap(sn.getRouterId(), portId.getValue());
}
} else {
LOG.trace("update VpnInterface for Port {} with adj {}", vpnInfName, portAdj);
if (vpnId != null) {
updateVpnInterfaceWithAdjacencies(vpnId, vpnInfName, portAdj, wrtConfigTxn);
}
if (internetId != null) {
updateVpnInterfaceWithAdjacencies(internetId, vpnInfName, portAdj, wrtConfigTxn);
}
}
});
LoggingFutures.addErrorLogging(future, LOG, "addSubnetToVpn: Failed while creating VPN interface for vpnId {}, portId {}" + "{}, subnetId {}", vpnId.getValue(), portId, subnet.getValue());
return Collections.singletonList(future);
});
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports in project netvirt by opendaylight.
the class NeutronvpnManager method createPortIpAdjacencies.
protected Adjacencies createPortIpAdjacencies(Port port, Boolean isRouterInterface, TypedWriteTransaction<Configuration> wrtConfigTxn, @Nullable VpnInterface vpnIface) {
List<Adjacency> adjList = new ArrayList<>();
if (vpnIface != null) {
adjList = new ArrayList<>(vpnIface.augmentation(Adjacencies.class).getAdjacency().values());
}
String infName = port.getUuid().getValue();
LOG.trace("neutronVpnManager: create config adjacencies for Port: {}", infName);
for (FixedIps ip : port.nonnullFixedIps().values()) {
String ipValue = ip.getIpAddress().stringValue();
String ipPrefix = ip.getIpAddress().getIpv4Address() != null ? ipValue + "/32" : ipValue + "/128";
Subnetmap snTemp = neutronvpnUtils.getSubnetmap(ip.getSubnetId());
if (snTemp != null && !FibHelper.doesPrefixBelongToSubnet(ipPrefix, snTemp.getSubnetIp(), false)) {
continue;
}
Uuid vpnId = snTemp != null ? snTemp.getVpnId() : null;
if (vpnId != null) {
neutronvpnUtils.createVpnPortFixedIpToPort(vpnId.getValue(), ipValue, infName, port.getMacAddress().getValue(), isRouterInterface, wrtConfigTxn);
// Create Neutron port adjacency if VPN presence is existing for subnet
Adjacency vmAdj = new AdjacencyBuilder().withKey(new AdjacencyKey(ipPrefix)).setIpAddress(ipPrefix).setMacAddress(port.getMacAddress().getValue()).setAdjacencyType(AdjacencyType.PrimaryAdjacency).setSubnetId(ip.getSubnetId()).build();
if (!adjList.contains(vmAdj)) {
adjList.add(vmAdj);
}
}
Uuid routerId = snTemp != null ? snTemp.getRouterId() : null;
if (snTemp != null && snTemp.getInternetVpnId() != null) {
neutronvpnUtils.createVpnPortFixedIpToPort(snTemp.getInternetVpnId().getValue(), ipValue, infName, port.getMacAddress().getValue(), isRouterInterface, wrtConfigTxn);
}
if (routerId != null) {
Router rtr = neutronvpnUtils.getNeutronRouter(routerId);
if (rtr != null && rtr.getRoutes() != null) {
List<Routes> routeList = new ArrayList<>(rtr.getRoutes().values());
// create extraroute Adjacence for each ipValue,
// because router can have IPv4 and IPv6 subnet ports, or can have
// more that one IPv4 subnet port or more than one IPv6 subnet port
List<Adjacency> erAdjList = getAdjacencyforExtraRoute(routeList, ipValue);
if (!erAdjList.isEmpty()) {
adjList.addAll(erAdjList);
}
}
}
}
return new AdjacenciesBuilder().setAdjacency(getAdjacencyMap(adjList)).build();
}
Aggregations