use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes in project netvirt by opendaylight.
the class InterVpnLinkListener method add.
@Override
public void add(InstanceIdentifier<InterVpnLink> identifier, InterVpnLink add) {
String ivpnLinkName = add.getName();
LOG.debug("Reacting to IVpnLink {} creation. Vpn1=[name={} EndpointIp={}] Vpn2=[name={} endpointIP={}]", ivpnLinkName, add.getFirstEndpoint().getVpnUuid(), add.getFirstEndpoint().getIpAddress(), add.getSecondEndpoint().getVpnUuid(), add.getSecondEndpoint().getIpAddress());
// Create VpnLink state
InstanceIdentifier<InterVpnLinkState> vpnLinkStateIid = InterVpnLinkUtil.getInterVpnLinkStateIid(ivpnLinkName);
InterVpnLinkState vpnLinkState = new InterVpnLinkStateBuilder().setInterVpnLinkName(ivpnLinkName).build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnLinkStateIid, vpnLinkState);
InterVpnLinkKey key = add.key();
Uuid vpn1Uuid = add.getFirstEndpoint().getVpnUuid();
String vpn1Name = vpn1Uuid.getValue();
Uuid vpn2Uuid = add.getSecondEndpoint().getVpnUuid();
String vpn2Name = vpn2Uuid.getValue();
String vpn1PrimaryRd = vpnUtil.getPrimaryRd(vpn1Name);
String vpn2PrimaryRd = vpnUtil.getPrimaryRd(vpn1Name);
if (!vpnUtil.isVpnPendingDelete(vpn1PrimaryRd) && !vpnUtil.isVpnPendingDelete(vpn2PrimaryRd)) {
if (vpnUtil.getVpnInstance(vpn1Name) == null) {
String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: could not find 1st endpoint Vpn " + vpn1Name;
setInError(vpnLinkStateIid, vpnLinkState, errMsg);
return;
}
if (!checkVpnAvailability(key, vpn1Name)) {
String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: Vpn " + vpn1Name + " is already associated to an inter-vpn-link ";
setInError(vpnLinkStateIid, vpnLinkState, errMsg);
return;
}
// Second VPN
if (vpnUtil.getVpnInstance(vpn2Name) == null) {
String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: could not find 2nd endpoint Vpn " + vpn2Name;
setInError(vpnLinkStateIid, vpnLinkState, errMsg);
return;
}
if (!checkVpnAvailability(key, vpn2Name)) {
String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: Vpn " + vpn2Name + " is already associated with an inter-vpn-link";
setInError(vpnLinkStateIid, vpnLinkState, errMsg);
return;
}
interVpnLinkCache.addInterVpnLinkToCaches(add);
// Wait for VPN Operational data ready
Uint32 vpn1Id = vpnUtil.getVpnId(vpn1Name);
if (VpnConstants.INVALID_ID.equals(vpn1Id)) {
boolean vpn1Ready = vpnOpDataSyncer.waitForVpnDataReady(VpnOpDataSyncer.VpnOpDataType.vpnInstanceToId, vpn1Name, VpnConstants.PER_VPN_INSTANCE_MAX_WAIT_TIME_IN_MILLISECONDS);
if (!vpn1Ready) {
String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: Operational Data for VPN " + vpn1Name + " not ready after " + VpnConstants.PER_INTERFACE_MAX_WAIT_TIME_IN_MILLISECONDS + " milliseconds";
setInError(vpnLinkStateIid, vpnLinkState, errMsg);
return;
}
}
Uint32 vpn2Id = vpnUtil.getVpnId(vpn2Name);
if (VpnConstants.INVALID_ID.equals(vpn2Id)) {
boolean vpn1Ready = vpnOpDataSyncer.waitForVpnDataReady(VpnOpDataSyncer.VpnOpDataType.vpnInstanceToId, vpn2Name, VpnConstants.PER_VPN_INSTANCE_MAX_WAIT_TIME_IN_MILLISECONDS);
if (!vpn1Ready) {
String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: Operational Data for VPN " + vpn2Name + " not ready after " + VpnConstants.PER_INTERFACE_MAX_WAIT_TIME_IN_MILLISECONDS + " milliseconds";
setInError(vpnLinkStateIid, vpnLinkState, errMsg);
return;
}
}
List<Uint64> firstDpnList = ivpnLinkLocator.selectSuitableDpns(add);
if (firstDpnList != null && !firstDpnList.isEmpty()) {
List<Uint64> secondDpnList = firstDpnList;
Long firstVpnLportTag = allocateVpnLinkLportTag(key.getName() + vpn1Name);
Long secondVpnLportTag = allocateVpnLinkLportTag(key.getName() + vpn2Name);
FirstEndpointState firstEndPointState = new FirstEndpointStateBuilder().setVpnUuid(vpn1Uuid).setDpId(firstDpnList).setLportTag(firstVpnLportTag).build();
SecondEndpointState secondEndPointState = new SecondEndpointStateBuilder().setVpnUuid(vpn2Uuid).setDpId(secondDpnList).setLportTag(secondVpnLportTag).build();
interVpnLinkUtil.updateInterVpnLinkState(ivpnLinkName, InterVpnLinkState.State.Active, firstEndPointState, secondEndPointState, interVpnLinkCache);
// Note that in the DPN of the firstEndpoint we install the lportTag of the secondEndpoint and viceversa
interVpnLinkUtil.installLPortDispatcherTableFlow(ivpnLinkName, firstDpnList, vpn2Name, secondVpnLportTag);
interVpnLinkUtil.installLPortDispatcherTableFlow(ivpnLinkName, secondDpnList, vpn1Name, firstVpnLportTag);
// Update the VPN -> DPNs Map.
// Note: when a set of DPNs is calculated for Vpn1, these DPNs are added to the VpnToDpn map of Vpn2.
// Why? because we do the handover from Vpn1 to Vpn2 in those DPNs, so in those DPNs we must know how
// to reach to Vpn2 targets. If new Vpn2 targets are added later, the Fib will be maintained in these
// DPNs even if Vpn2 is not physically present there.
interVpnLinkUtil.updateVpnFootprint(vpn2Name, vpn2PrimaryRd, firstDpnList);
interVpnLinkUtil.updateVpnFootprint(vpn1Name, vpn1PrimaryRd, secondDpnList);
// Program static routes if needed
Optional<InterVpnLinkDataComposite> interVpnLink = interVpnLinkCache.getInterVpnLinkByName(ivpnLinkName);
ivpnLinkService.handleStaticRoutes(interVpnLink.get());
// Now, if the corresponding flags are activated, there will be some routes exchange
ivpnLinkService.exchangeRoutes(interVpnLink.get());
} else {
// If there is no connection to DPNs, the InterVpnLink is created and the InterVpnLinkState is also
// created with the corresponding LPortTags but no DPN is assigned since there is no DPN operative.
Long firstVpnLportTag = allocateVpnLinkLportTag(key.getName() + vpn1Name);
Long secondVpnLportTag = allocateVpnLinkLportTag(key.getName() + vpn2Name);
FirstEndpointState firstEndPointState = new FirstEndpointStateBuilder().setVpnUuid(vpn1Uuid).setLportTag(firstVpnLportTag).setDpId(Collections.emptyList()).build();
SecondEndpointState secondEndPointState = new SecondEndpointStateBuilder().setVpnUuid(vpn2Uuid).setLportTag(secondVpnLportTag).setDpId(Collections.emptyList()).build();
interVpnLinkUtil.updateInterVpnLinkState(ivpnLinkName, InterVpnLinkState.State.Error, firstEndPointState, secondEndPointState, interVpnLinkCache);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes 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.rib.rev180329.rib.tables.Routes in project netvirt by opendaylight.
the class NeutronvpnManager method addInterVpnRoutes.
/**
* Creates the corresponding static routes in the specified VPN. These static routes must be point to an
* InterVpnLink endpoint and the specified VPN must be the other end of the InterVpnLink. Otherwise the
* route will be ignored.
*
* @param vpnName the VPN identifier
* @param interVpnLinkRoutes The list of static routes
* @param nexthopsXinterVpnLinks A Map with the correspondence nextHop-InterVpnLink
*/
public void addInterVpnRoutes(Uuid vpnName, List<Routes> interVpnLinkRoutes, HashMap<String, InterVpnLink> nexthopsXinterVpnLinks) {
for (Routes route : interVpnLinkRoutes) {
String nexthop = route.getNexthop().stringValue();
String destination = route.getDestination().stringValue();
InterVpnLink interVpnLink = nexthopsXinterVpnLinks.get(nexthop);
if (isNexthopTheOtherVpnLinkEndpoint(nexthop, vpnName.getValue(), interVpnLink)) {
AddStaticRouteInput rpcInput = new AddStaticRouteInputBuilder().setDestination(destination).setNexthop(nexthop).setVpnInstanceName(vpnName.getValue()).build();
Future<RpcResult<AddStaticRouteOutput>> labelOuputFtr = vpnRpcService.addStaticRoute(rpcInput);
RpcResult<AddStaticRouteOutput> rpcResult;
try {
rpcResult = labelOuputFtr.get();
if (rpcResult.isSuccessful()) {
LOG.debug("Label generated for destination {} is: {}", destination, rpcResult.getResult().getLabel());
} else {
LOG.error("RPC call to add a static Route to {} with nexthop {} returned with errors {}", destination, nexthop, rpcResult.getErrors());
}
} catch (InterruptedException | ExecutionException e) {
LOG.error("Error happened while invoking addStaticRoute RPC for nexthop {} with destination {} " + "for VPN {}", nexthop, destination, vpnName.getValue(), e);
}
} else {
// Any other case is a fault.
LOG.warn("route with destination {} and nexthop {} does not apply to any InterVpnLink", route.getDestination().stringValue(), nexthop);
continue;
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes 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();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes in project netvirt by opendaylight.
the class NeutronRouterChangeListener method update.
@Override
public void update(InstanceIdentifier<Router> identifier, Router original, Router update) {
LOG.trace("Updating Router : key: {}, original value={}, update value={}", identifier, original, update);
if (Objects.equals(original, update)) {
return;
}
neutronvpnUtils.addToRouterCache(update);
Uuid routerId = update.getUuid();
neutronvpnUtils.addToRouterCache(update);
Uuid vpnId = neutronvpnUtils.getVpnForRouter(routerId, true);
// internal vpn always present in case external vpn not found
if (vpnId == null) {
vpnId = routerId;
}
List<Routes> oldRoutes = new ArrayList<>(original.nonnullRoutes().values());
List<Routes> newRoutes = new ArrayList<>(update.nonnullRoutes().values());
if (!oldRoutes.equals(newRoutes)) {
Iterator<Routes> iterator = newRoutes.iterator();
while (iterator.hasNext()) {
Routes route = iterator.next();
if (oldRoutes.remove(route)) {
iterator.remove();
}
}
LOG.debug("Updating Router : AddRoutes {}, DeleteRoutes {}", newRoutes, oldRoutes);
if (!oldRoutes.isEmpty()) {
handleChangedRoutes(vpnId, oldRoutes, NwConstants.DEL_FLOW);
}
// A better fix/design need to be thought to avoid race condition
try {
// sleep for 2sec
Thread.sleep(2000);
} catch (java.lang.InterruptedException e) {
LOG.error("Exception while sleeping", e);
}
if (!newRoutes.isEmpty()) {
handleChangedRoutes(vpnId, newRoutes, NwConstants.ADD_FLOW);
}
}
jobCoordinator.enqueueJob(update.getUuid().toString(), () -> {
nvpnNatManager.handleExternalNetworkForRouter(original, update);
return Collections.emptyList();
});
gwMacResolver.sendArpRequestsToExtGateways(update);
}
Aggregations