use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.VpnInstanceOpData in project netvirt by opendaylight.
the class VpnInterfaceManager method addNewAdjToVpnInterface.
protected void addNewAdjToVpnInterface(InstanceIdentifier<VpnInterfaceOpDataEntry> identifier, String primaryRd, Adjacency adj, BigInteger dpnId, WriteTransaction writeOperTxn, WriteTransaction writeConfigTxn) {
Optional<VpnInterfaceOpDataEntry> optVpnInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier);
if (optVpnInterface.isPresent()) {
VpnInterfaceOpDataEntry currVpnIntf = optVpnInterface.get();
String prefix = VpnUtil.getIpPrefix(adj.getIpAddress());
String vpnName = currVpnIntf.getVpnInstanceName();
VpnInstanceOpDataEntry vpnInstanceOpData = VpnUtil.getVpnInstanceOpData(dataBroker, primaryRd);
InstanceIdentifier<AdjacenciesOp> adjPath = identifier.augmentation(AdjacenciesOp.class);
Optional<AdjacenciesOp> optAdjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, adjPath);
boolean isL3VpnOverVxLan = VpnUtil.isL3VpnOverVxLan(vpnInstanceOpData.getL3vni());
VrfEntry.EncapType encapType = VpnUtil.getEncapType(isL3VpnOverVxLan);
long l3vni = vpnInstanceOpData.getL3vni() == null ? 0L : vpnInstanceOpData.getL3vni();
VpnPopulator populator = L3vpnRegistry.getRegisteredPopulator(encapType);
List<Adjacency> adjacencies;
if (optAdjacencies.isPresent()) {
adjacencies = optAdjacencies.get().getAdjacency();
} else {
// This code will be hit in case of first PNF adjacency
adjacencies = new ArrayList<>();
}
long vpnId = VpnUtil.getVpnId(dataBroker, vpnName);
L3vpnInput input = new L3vpnInput().setNextHop(adj).setVpnName(vpnName).setInterfaceName(currVpnIntf.getName()).setPrimaryRd(primaryRd).setRd(primaryRd);
Adjacency operationalAdjacency = null;
if (adj.getNextHopIpList() != null && !adj.getNextHopIpList().isEmpty()) {
RouteOrigin origin = adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency ? RouteOrigin.LOCAL : RouteOrigin.STATIC;
String nh = adj.getNextHopIpList().get(0);
String vpnPrefixKey = VpnUtil.getVpnNamePrefixKey(vpnName, prefix);
synchronized (vpnPrefixKey.intern()) {
java.util.Optional<String> rdToAllocate = VpnUtil.allocateRdForExtraRouteAndUpdateUsedRdsMap(dataBroker, vpnId, null, prefix, vpnName, nh, dpnId);
if (rdToAllocate.isPresent()) {
input.setRd(rdToAllocate.get());
operationalAdjacency = populator.createOperationalAdjacency(input);
int label = operationalAdjacency.getLabel().intValue();
vpnManager.addExtraRoute(vpnName, adj.getIpAddress(), nh, rdToAllocate.get(), currVpnIntf.getVpnInstanceName(), l3vni, origin, currVpnIntf.getName(), operationalAdjacency, encapType, writeConfigTxn);
LOG.info("addNewAdjToVpnInterface: Added extra route ip {} nh {} rd {} vpnname {} label {}" + " Interface {} on dpn {}", adj.getIpAddress(), nh, rdToAllocate.get(), vpnName, label, currVpnIntf.getName(), dpnId);
} else {
LOG.error("addNewAdjToVpnInterface: No rds to allocate extraroute vpn {} prefix {}", vpnName, prefix);
return;
}
// Keeping the MPLS check for now.
if (encapType.equals(VrfEntryBase.EncapType.Mplsgre)) {
final Adjacency opAdjacency = new AdjacencyBuilder(operationalAdjacency).build();
List<VpnInstanceOpDataEntry> vpnsToImportRoute = VpnUtil.getVpnsImportingMyRoute(dataBroker, vpnName);
vpnsToImportRoute.forEach(vpn -> {
if (vpn.getVrfId() != null) {
VpnUtil.allocateRdForExtraRouteAndUpdateUsedRdsMap(dataBroker, vpn.getVpnId(), vpnId, prefix, VpnUtil.getVpnName(dataBroker, vpn.getVpnId()), nh, dpnId).ifPresent(rds -> vpnManager.addExtraRoute(VpnUtil.getVpnName(dataBroker, vpn.getVpnId()), adj.getIpAddress(), nh, rds, currVpnIntf.getVpnInstanceName(), l3vni, RouteOrigin.SELF_IMPORTED, currVpnIntf.getName(), opAdjacency, encapType, writeConfigTxn));
}
});
}
}
} else if (adj.isPhysNetworkFunc()) {
// PNF adjacency.
LOG.trace("addNewAdjToVpnInterface: Adding prefix {} to interface {} for vpn {}", prefix, currVpnIntf.getName(), vpnName);
String parentVpnRd = getParentVpnRdForExternalSubnet(adj);
writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(VpnUtil.getVpnId(dataBroker, adj.getSubnetId().getValue()), prefix), VpnUtil.getPrefixToInterface(BigInteger.ZERO, currVpnIntf.getName(), prefix, adj.getSubnetId(), Prefixes.PrefixCue.PhysNetFunc), true);
fibManager.addOrUpdateFibEntry(adj.getSubnetId().getValue(), adj.getMacAddress(), adj.getIpAddress(), Collections.emptyList(), null, /* EncapType */
0, /* label */
0, /*l3vni*/
null, /* gw-mac */
parentVpnRd, RouteOrigin.LOCAL, writeConfigTxn);
input.setRd(adj.getVrfId());
}
if (operationalAdjacency == null) {
operationalAdjacency = populator.createOperationalAdjacency(input);
}
adjacencies.add(operationalAdjacency);
AdjacenciesOp aug = VpnUtil.getVpnInterfaceOpDataEntryAugmentation(adjacencies);
VpnInterfaceOpDataEntry newVpnIntf = VpnUtil.getVpnInterfaceOpDataEntry(currVpnIntf.getName(), currVpnIntf.getVpnInstanceName(), aug, dpnId, currVpnIntf.isScheduledForRemove(), currVpnIntf.getLportTag(), currVpnIntf.getGatewayMacAddress());
writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, identifier, newVpnIntf, true);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.VpnInstanceOpData in project netvirt by opendaylight.
the class FibEntriesListener method removeLabelFromVpnInstance.
private void removeLabelFromVpnInstance(String rd, List<RoutePaths> routePaths) {
List<Long> labels = routePaths.stream().map(RoutePaths::getLabel).distinct().collect(Collectors.toList());
VpnInstanceOpDataEntry vpnInstanceOpData = vpnInstanceListener.getVpnInstanceOpData(rd);
if (vpnInstanceOpData != null) {
List<Long> routeIds = vpnInstanceOpData.getRouteEntryId();
if (routeIds == null) {
LOG.debug("Fib Route entry is empty.");
} else {
LOG.debug("Removing label from vpn info - {}", labels);
routeIds.removeAll(labels);
TransactionUtil.asyncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getVpnInstanceOpDataIdentifier(rd), new VpnInstanceOpDataEntryBuilder(vpnInstanceOpData).setRouteEntryId(routeIds).build(), TransactionUtil.DEFAULT_CALLBACK);
}
} else {
LOG.warn("No VPN Instance found for RD: {}", rd);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.VpnInstanceOpData in project netvirt by opendaylight.
the class TunnelInterfaceStateListener method update.
@Override
protected void update(InstanceIdentifier<StateTunnelList> identifier, StateTunnelList original, StateTunnelList update) {
LOG.trace("update: Tunnel updation---- {}", update);
LOG.info("update: ITM Tunnel {} of type {} state event changed from :{} to :{}", update.getTunnelInterfaceName(), fibManager.getTransportTypeStr(update.getTransportType().toString()), original.getOperState(), update.getOperState());
TunnelOperStatus tunOpStatus = update.getOperState();
if (tunOpStatus != TunnelOperStatus.Down && tunOpStatus != TunnelOperStatus.Up) {
LOG.info("update: Returning from unsupported tunnelOperStatus {} for tunnel interface {}", tunOpStatus, update.getTunnelInterfaceName());
return;
}
if (isGreTunnel(update)) {
programDcGwLoadBalancingGroup(update, NwConstants.MOD_FLOW);
}
// Remove the corresponding nexthop from the routepath under extraroute in fibentries.
BigInteger srcDpnId = new BigInteger(update.getSrcInfo().getTepDeviceId());
String srcTepIp = String.valueOf(update.getSrcInfo().getTepIp().getValue());
List<VpnInstanceOpDataEntry> vpnInstanceOpData = VpnUtil.getAllVpnInstanceOpData(dataBroker);
if (vpnInstanceOpData == null) {
LOG.trace("update: No vpnInstanceOpdata present");
return;
}
WriteTransaction writeConfigTxn = dataBroker.newWriteOnlyTransaction();
if (tunOpStatus == TunnelOperStatus.Up) {
handleTunnelEventForDPN(update, TunnelAction.TUNNEL_EP_ADD);
} else {
vpnInstanceOpData.stream().filter(opData -> {
if (opData.getVpnToDpnList() == null) {
return false;
}
return opData.getVpnToDpnList().stream().anyMatch(vpnToDpn -> vpnToDpn.getDpnId().equals(srcDpnId));
}).forEach(opData -> {
List<DestPrefixes> prefixes = VpnExtraRouteHelper.getExtraRouteDestPrefixes(dataBroker, opData.getVpnId());
prefixes.forEach(destPrefix -> {
VrfEntry vrfEntry = VpnUtil.getVrfEntry(dataBroker, opData.getVrfId(), destPrefix.getDestPrefix());
if (vrfEntry == null || vrfEntry.getRoutePaths() == null) {
return;
}
List<RoutePaths> routePaths = vrfEntry.getRoutePaths();
routePaths.forEach(routePath -> {
if (routePath.getNexthopAddress().equals(srcTepIp)) {
fibManager.updateRoutePathForFibEntry(opData.getVrfId(), destPrefix.getDestPrefix(), srcTepIp, routePath.getLabel(), false, writeConfigTxn);
}
});
});
});
}
writeConfigTxn.submit();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.VpnInstanceOpData in project netvirt by opendaylight.
the class VrfEntryListener method deleteFibEntries.
private void deleteFibEntries(final InstanceIdentifier<VrfEntry> identifier, final VrfEntry vrfEntry) {
final VrfTablesKey vrfTableKey = identifier.firstKeyOf(VrfTables.class);
final String rd = vrfTableKey.getRouteDistinguisher();
final VpnInstanceOpDataEntry vpnInstance = fibUtil.getVpnInstance(vrfTableKey.getRouteDistinguisher());
if (vpnInstance == null) {
LOG.error("VPN Instance for rd {} is not available from VPN Op Instance Datastore", rd);
return;
}
final Collection<VpnToDpnList> vpnToDpnList;
if (vrfEntry.getParentVpnRd() != null && FibHelper.isControllerManagedNonSelfImportedRoute(RouteOrigin.value(vrfEntry.getOrigin()))) {
// This block MUST BE HIT only for PNF (Physical Network Function) FIB Entries.
VpnInstanceOpDataEntry parentVpnInstance = fibUtil.getVpnInstance(vrfEntry.getParentVpnRd());
vpnToDpnList = parentVpnInstance != null ? parentVpnInstance.getVpnToDpnList() : vpnInstance.getVpnToDpnList();
LOG.info("deleteFibEntries: Processing deletion of PNF FIB entry with rd {} prefix {}", vrfEntry.getParentVpnRd(), vrfEntry.getDestPrefix());
} else {
vpnToDpnList = vpnInstance.getVpnToDpnList();
}
SubnetRoute subnetRoute = vrfEntry.getAugmentation(SubnetRoute.class);
final java.util.Optional<Long> optionalLabel = FibUtil.getLabelFromRoutePaths(vrfEntry);
List<String> nextHopAddressList = FibHelper.getNextHopListFromRoutePaths(vrfEntry);
String vpnName = fibUtil.getVpnNameFromId(vpnInstance.getVpnId());
if (subnetRoute != null) {
long elanTag = subnetRoute.getElantag();
LOG.trace("SUBNETROUTE: deleteFibEntries: SubnetRoute augmented vrfentry found for rd {} prefix {}" + " with elantag {}", rd, vrfEntry.getDestPrefix(), elanTag);
if (vpnToDpnList != null) {
jobCoordinator.enqueueJob(FibUtil.getJobKeyForRdPrefix(rd, vrfEntry.getDestPrefix()), () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
for (final VpnToDpnList curDpn : vpnToDpnList) {
baseVrfEntryHandler.makeConnectedRoute(curDpn.getDpnId(), vpnInstance.getVpnId(), vrfEntry, vrfTableKey.getRouteDistinguisher(), null, NwConstants.DEL_FLOW, tx, null);
if (RouteOrigin.value(vrfEntry.getOrigin()) != RouteOrigin.SELF_IMPORTED) {
optionalLabel.ifPresent(label -> makeLFibTableEntry(curDpn.getDpnId(), label, null, DEFAULT_FIB_FLOW_PRIORITY, NwConstants.DEL_FLOW, tx));
}
installSubnetBroadcastAddrDropRule(curDpn.getDpnId(), rd, vpnInstance.getVpnId(), vrfEntry, NwConstants.DEL_FLOW, tx);
}
})));
}
optionalLabel.ifPresent(label -> {
synchronized (label.toString().intern()) {
LabelRouteInfo lri = getLabelRouteInfo(label);
if (isPrefixAndNextHopPresentInLri(vrfEntry.getDestPrefix(), nextHopAddressList, lri)) {
Optional<VpnInstanceOpDataEntry> vpnInstanceOpDataEntryOptional = fibUtil.getVpnInstanceOpData(rd);
String vpnInstanceName = "";
if (vpnInstanceOpDataEntryOptional.isPresent()) {
vpnInstanceName = vpnInstanceOpDataEntryOptional.get().getVpnInstanceName();
}
boolean lriRemoved = this.deleteLabelRouteInfo(lri, vpnInstanceName, null);
if (lriRemoved) {
String parentRd = lri.getParentVpnRd();
fibUtil.releaseId(FibConstants.VPN_IDPOOL_NAME, FibUtil.getNextHopLabelKey(parentRd, vrfEntry.getDestPrefix()));
LOG.trace("SUBNETROUTE: deleteFibEntries: Released subnetroute label {} for rd {} prefix {}" + " as labelRouteInfo cleared", label, rd, vrfEntry.getDestPrefix());
}
} else {
fibUtil.releaseId(FibConstants.VPN_IDPOOL_NAME, FibUtil.getNextHopLabelKey(rd, vrfEntry.getDestPrefix()));
LOG.trace("SUBNETROUTE: deleteFibEntries: Released subnetroute label {} for rd {} prefix {}", label, rd, vrfEntry.getDestPrefix());
}
}
});
return;
}
final List<BigInteger> localDpnIdList = deleteLocalFibEntry(vpnInstance.getVpnId(), vrfTableKey.getRouteDistinguisher(), vrfEntry);
if (vpnToDpnList != null) {
List<String> usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, vpnInstance.getVpnId(), vrfEntry.getDestPrefix());
String jobKey;
Optional<Routes> extraRouteOptional;
// Is this fib route an extra route? If yes, get the nexthop which would be an adjacency in the vpn
if (usedRds != null && !usedRds.isEmpty()) {
jobKey = FibUtil.getJobKeyForRdPrefix(usedRds.get(0), vrfEntry.getDestPrefix());
if (usedRds.size() > 1) {
LOG.error("The extra route prefix is still present in some DPNs");
return;
} else {
// The first rd is retrieved from usedrds as Only 1 rd would be present as extra route prefix
// is not present in any other DPN
extraRouteOptional = VpnExtraRouteHelper.getVpnExtraroutes(dataBroker, vpnName, usedRds.get(0), vrfEntry.getDestPrefix());
}
} else {
jobKey = FibUtil.getJobKeyForRdPrefix(rd, vrfEntry.getDestPrefix());
extraRouteOptional = Optional.absent();
}
jobCoordinator.enqueueJob(jobKey, () -> {
WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
if (localDpnIdList.size() <= 0) {
for (VpnToDpnList curDpn : vpnToDpnList) {
baseVrfEntryHandler.deleteRemoteRoute(BigInteger.ZERO, curDpn.getDpnId(), vpnInstance.getVpnId(), vrfTableKey, vrfEntry, extraRouteOptional, tx);
}
} else {
for (BigInteger localDpnId : localDpnIdList) {
for (VpnToDpnList curDpn : vpnToDpnList) {
if (!curDpn.getDpnId().equals(localDpnId)) {
baseVrfEntryHandler.deleteRemoteRoute(localDpnId, curDpn.getDpnId(), vpnInstance.getVpnId(), vrfTableKey, vrfEntry, extraRouteOptional, tx);
}
}
}
}
List<ListenableFuture<Void>> futures = new ArrayList<>();
futures.add(tx.submit());
return futures;
}, MAX_RETRIES);
}
// The flow/group entry has been deleted from config DS; need to clean up associated operational
// DS entries in VPN Op DS, VpnInstanceOpData and PrefixToInterface to complete deletion
cleanUpOpDataForFib(vpnInstance.getVpnId(), vrfTableKey.getRouteDistinguisher(), vrfEntry);
// Remove all fib entries configured due to interVpnLink, when nexthop is the opposite endPoint
// of the interVpnLink.
Optional<String> optVpnUuid = fibUtil.getVpnNameFromRd(rd);
if (optVpnUuid.isPresent()) {
String vpnUuid = optVpnUuid.get();
FibUtil.getFirstNextHopAddress(vrfEntry).ifPresent(routeNexthop -> {
Optional<InterVpnLinkDataComposite> optInterVpnLink = interVpnLinkCache.getInterVpnLinkByVpnId(vpnUuid);
if (optInterVpnLink.isPresent()) {
InterVpnLinkDataComposite interVpnLink = optInterVpnLink.get();
if (interVpnLink.isIpAddrTheOtherVpnEndpoint(routeNexthop, vpnUuid)) {
// This is route that points to the other endpoint of an InterVpnLink
// In that case, we should look for the FIB table pointing to
// LPortDispatcher table and remove it.
removeInterVPNLinkRouteFlows(interVpnLink, vpnUuid, vrfEntry);
}
}
});
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.VpnInstanceOpData in project netvirt by opendaylight.
the class VpnUtil method isVpnPendingDelete.
public static boolean isVpnPendingDelete(DataBroker broker, String rd) {
VpnInstanceOpDataEntry vpnInstanceOpData = getVpnInstanceOpData(broker, rd);
boolean isVpnPendingDelete = false;
if (vpnInstanceOpData == null || vpnInstanceOpData.getVpnState() == VpnInstanceOpDataEntry.VpnState.PendingDelete) {
isVpnPendingDelete = true;
}
return isVpnPendingDelete;
}
Aggregations