use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.VpnInstanceToVpnId in project netvirt by opendaylight.
the class VpnInstanceListener method addVpnInstance.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void addVpnInstance(VpnInstance value, WriteTransaction writeConfigTxn, WriteTransaction writeOperTxn) {
VpnAfConfig config = value.getIpv4Family();
String vpnInstanceName = value.getVpnInstanceName();
long vpnId = VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME, vpnInstanceName);
if (vpnId == 0) {
LOG.error("{} addVpnInstance: Unable to fetch label from Id Manager. Bailing out of adding operational" + " data for Vpn Instance {}", LOGGING_PREFIX_ADD, value.getVpnInstanceName());
return;
}
LOG.info("{} addVpnInstance: VPN Id {} generated for VpnInstanceName {}", LOGGING_PREFIX_ADD, vpnId, vpnInstanceName);
String primaryRd = VpnUtil.getPrimaryRd(value);
org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance vpnInstanceToVpnId = VpnUtil.getVpnInstanceToVpnId(vpnInstanceName, vpnId, primaryRd);
if (writeConfigTxn != null) {
writeConfigTxn.put(LogicalDatastoreType.CONFIGURATION, VpnOperDsUtils.getVpnInstanceToVpnIdIdentifier(vpnInstanceName), vpnInstanceToVpnId, WriteTransaction.CREATE_MISSING_PARENTS);
} else {
TransactionUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, VpnOperDsUtils.getVpnInstanceToVpnIdIdentifier(vpnInstanceName), vpnInstanceToVpnId);
}
VpnIds vpnIdToVpnInstance = VpnUtil.getVpnIdToVpnInstance(vpnId, value.getVpnInstanceName(), primaryRd, VpnUtil.isBgpVpn(vpnInstanceName, primaryRd));
if (writeConfigTxn != null) {
writeConfigTxn.put(LogicalDatastoreType.CONFIGURATION, VpnUtil.getVpnIdToVpnInstanceIdentifier(vpnId), vpnIdToVpnInstance, WriteTransaction.CREATE_MISSING_PARENTS);
} else {
TransactionUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, VpnUtil.getVpnIdToVpnInstanceIdentifier(vpnId), vpnIdToVpnInstance);
}
try {
String cachedTransType = fibManager.getConfTransType();
if (cachedTransType.equals("Invalid")) {
try {
fibManager.setConfTransType("L3VPN", "VXLAN");
} catch (Exception e) {
LOG.error("{} addVpnInstance: Exception caught setting the L3VPN tunnel transportType for vpn {}", LOGGING_PREFIX_ADD, vpnInstanceName, e);
}
} else {
LOG.debug("{} addVpnInstance: Configured tunnel transport type for L3VPN {} as {}", LOGGING_PREFIX_ADD, vpnInstanceName, cachedTransType);
}
} catch (Exception e) {
LOG.error("{} addVpnInstance: Error when trying to retrieve tunnel transport type for L3VPN {}", LOGGING_PREFIX_ADD, vpnInstanceName, e);
}
VpnInstanceOpDataEntryBuilder builder = new VpnInstanceOpDataEntryBuilder().setVrfId(primaryRd).setVpnId(vpnId).setVpnInstanceName(vpnInstanceName).setVpnState(VpnInstanceOpDataEntry.VpnState.Created).setIpv4Configured(false).setIpv6Configured(false);
if (VpnUtil.isBgpVpn(vpnInstanceName, primaryRd)) {
List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpntargets.VpnTarget> opVpnTargetList = new ArrayList<>();
builder.setBgpvpnType(VpnInstanceOpDataEntry.BgpvpnType.BGPVPNExternal);
if (value.getL3vni() != null) {
builder.setL3vni(value.getL3vni());
}
if (value.getType() == VpnInstance.Type.L2) {
builder.setType(VpnInstanceOpDataEntry.Type.L2);
}
VpnTargets vpnTargets = config.getVpnTargets();
if (vpnTargets != null) {
List<VpnTarget> vpnTargetList = vpnTargets.getVpnTarget();
if (vpnTargetList != null) {
for (VpnTarget vpnTarget : vpnTargetList) {
VpnTargetBuilder vpnTargetBuilder = new VpnTargetBuilder().setKey(new VpnTargetKey(vpnTarget.getKey().getVrfRTValue())).setVrfRTType(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpntargets.VpnTarget.VrfRTType.forValue(vpnTarget.getVrfRTType().getIntValue())).setVrfRTValue(vpnTarget.getVrfRTValue());
opVpnTargetList.add(vpnTargetBuilder.build());
}
}
}
VpnTargetsBuilder vpnTargetsBuilder = new VpnTargetsBuilder().setVpnTarget(opVpnTargetList);
builder.setVpnTargets(vpnTargetsBuilder.build());
List<String> rds = config.getRouteDistinguisher();
builder.setRd(rds);
} else {
builder.setBgpvpnType(VpnInstanceOpDataEntry.BgpvpnType.VPN);
}
if (writeOperTxn != null) {
writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, VpnUtil.getVpnInstanceOpDataIdentifier(primaryRd), builder.build(), true);
} else {
TransactionUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getVpnInstanceOpDataIdentifier(primaryRd), builder.build());
}
LOG.info("{} addVpnInstance: VpnInstanceOpData populated successfully for vpn {} rd {}", LOGGING_PREFIX_ADD, vpnInstanceName, primaryRd);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.VpnInstanceToVpnId in project netvirt by opendaylight.
the class VpnInterfaceOpListener method postProcessVpnInterfaceRemoval.
private void postProcessVpnInterfaceRemoval(InstanceIdentifier<VpnInterfaceOpDataEntry> identifier, VpnInterfaceOpDataEntry del, WriteTransaction writeOperTxn) {
final VpnInterfaceOpDataEntryKey key = identifier.firstKeyOf(VpnInterfaceOpDataEntry.class, VpnInterfaceOpDataEntryKey.class);
String interfaceName = key.getName();
String vpnName = del.getVpnInstanceName();
LOG.info("postProcessVpnInterfaceRemoval: interface name {} vpnName {} dpn {}", interfaceName, vpnName, del.getDpnId());
// decrement the vpn interface count in Vpn Instance Op Data
Optional<VpnInstance> vpnInstance = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, VpnOperDsUtils.getVpnInstanceToVpnIdIdentifier(vpnName));
if (vpnInstance.isPresent()) {
String rd = null;
rd = vpnInstance.get().getVrfId();
VpnInstanceOpDataEntry vpnInstOp = VpnUtil.getVpnInstanceOpData(dataBroker, rd);
AdjacenciesOp adjs = del.getAugmentation(AdjacenciesOp.class);
List<Adjacency> adjList = adjs != null ? adjs.getAdjacency() : null;
if (vpnInstOp != null && adjList != null && adjList.size() > 0) {
/*
* When a VPN Interface is removed by FibManager (aka VrfEntryListener and its cohorts),
* one adjacency for that VPN Interface will be hanging around along with that
* VPN Interface. That adjacency could be primary (or) non-primary.
* If its a primary adjacency, then a prefix-to-interface entry will be available for the
* same. If its a non-primary adjacency, then a prefix-to-interface entry will not be
* available for the same, instead we will have vpn-to-extraroutes filled in for them.
*
* Here we try to remove prefix-to-interface entry for pending adjacency in the deleted
* vpnInterface. More importantly, we also update the vpnInstanceOpData by removing this
* vpnInterface from it.
*/
List<Prefixes> prefixToInterface = new ArrayList<>();
for (Adjacency adjacency : adjs.getAdjacency()) {
List<Prefixes> prefixToInterfaceLocal = new ArrayList<>();
Optional<Prefixes> prefix = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(), VpnUtil.getIpPrefix(adjacency.getIpAddress())));
if (prefix.isPresent()) {
prefixToInterfaceLocal.add(prefix.get());
}
if (prefixToInterfaceLocal.isEmpty()) {
for (String nh : adjacency.getNextHopIpList()) {
prefix = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(), VpnUtil.getIpPrefix(nh)));
if (prefix.isPresent()) {
prefixToInterfaceLocal.add(prefix.get());
}
}
}
if (!prefixToInterfaceLocal.isEmpty()) {
prefixToInterface.addAll(prefixToInterfaceLocal);
}
}
/*
* In VPN Migration scenarios, there is a race condition where we use the new DPNID
* for the migrated VM instead of old DPNID because when we read prefix-to-interface to cleanup
* old DPNID, we actually get the new DPNID.
*
* More dangerously, we tend to alter the new prefix-to-interface which should be retained intac
* for the migration to succeed in L3VPN. As a workaround, here we are going to use the dpnId in
* the deleted vpnInterface itself instead of tinkering with the prefix-to-interface. Further we
* will tinker prefix-to-interface only when are damn sure if its value matches our
* deleted vpnInterface.
*
*/
for (Prefixes pref : prefixToInterface) {
if (isMatchedPrefixToInterface(pref, del)) {
if (writeOperTxn != null) {
writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(), pref.getIpAddress()));
} else {
VpnUtil.delete(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(), pref.getIpAddress()), VpnUtil.DEFAULT_CALLBACK);
}
}
}
}
if (del.getDpnId() != null) {
vpnFootprintService.updateVpnToDpnMapping(del.getDpnId(), del.getVpnInstanceName(), rd, interfaceName, null, /*ipAddressSourceValuePair*/
false);
}
LOG.info("postProcessVpnInterfaceRemoval: Removed vpn operational data and updated vpn footprint" + " for interface {} on dpn {} vpn {}", interfaceName, del.getDpnId(), vpnName);
} else {
LOG.error("postProcessVpnInterfaceRemoval: rd not retrievable as vpninstancetovpnid for vpn {} is absent," + " trying rd as {}. interface {} dpn {}", vpnName, vpnName, interfaceName, del.getDpnId());
}
notifyTaskIfRequired(interfaceName);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.VpnInstanceToVpnId in project netvirt by opendaylight.
the class VpnOpStatusListener method update.
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
protected void update(InstanceIdentifier<VpnInstanceOpDataEntry> identifier, VpnInstanceOpDataEntry original, VpnInstanceOpDataEntry update) {
LOG.info("update: Processing update for vpn {} with rd {}", update.getVpnInstanceName(), update.getVrfId());
if (update.getVpnState() == VpnInstanceOpDataEntry.VpnState.PendingDelete && vpnFootprintService.isVpnFootPrintCleared(update)) {
// Cleanup VPN data
final String vpnName = update.getVpnInstanceName();
final List<String> rds = update.getRd();
String primaryRd = update.getVrfId();
final long vpnId = VpnUtil.getVpnId(dataBroker, vpnName);
jobCoordinator.enqueueJob("VPN-" + update.getVpnInstanceName(), () -> {
WriteTransaction writeTxn = dataBroker.newWriteOnlyTransaction();
// Clean up VpnInstanceToVpnId from Config DS
VpnUtil.removeVpnIdToVpnInstance(dataBroker, vpnId, writeTxn);
VpnUtil.removeVpnInstanceToVpnId(dataBroker, vpnName, writeTxn);
LOG.trace("Removed vpnIdentifier for rd{} vpnname {}", primaryRd, vpnName);
// Clean up FIB Entries Config DS
fibManager.removeVrfTable(primaryRd, null);
// Clean up VPNExtraRoutes Operational DS
if (VpnUtil.isBgpVpn(vpnName, primaryRd)) {
if (update.getType() == VpnInstanceOpDataEntry.Type.L2) {
rds.parallelStream().forEach(rd -> bgpManager.deleteVrf(rd, false, AddressFamily.L2VPN));
}
if (update.isIpv4Configured()) {
rds.parallelStream().forEach(rd -> bgpManager.deleteVrf(rd, false, AddressFamily.IPV4));
}
if (update.isIpv6Configured()) {
rds.parallelStream().forEach(rd -> bgpManager.deleteVrf(rd, false, AddressFamily.IPV6));
}
}
InstanceIdentifier<Vpn> vpnToExtraroute = VpnExtraRouteHelper.getVpnToExtrarouteVpnIdentifier(vpnName);
Optional<Vpn> optVpnToExtraroute = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, vpnToExtraroute);
if (optVpnToExtraroute.isPresent()) {
VpnUtil.removeVpnExtraRouteForVpn(dataBroker, vpnName, writeTxn);
}
if (VpnUtil.isL3VpnOverVxLan(update.getL3vni())) {
VpnUtil.removeExternalTunnelDemuxFlows(vpnName, dataBroker, mdsalManager);
}
// Clean up VPNInstanceOpDataEntry
VpnUtil.removeVpnOpInstance(dataBroker, primaryRd, writeTxn);
// Clean up PrefixToInterface Operational DS
VpnUtil.removePrefixToInterfaceForVpnId(dataBroker, vpnId, writeTxn);
// Clean up L3NextHop Operational DS
VpnUtil.removeL3nexthopForVpnId(dataBroker, vpnId, writeTxn);
// Release the ID used for this VPN back to IdManager
VpnUtil.releaseId(idManager, VpnConstants.VPN_IDPOOL_NAME, vpnName);
List<ListenableFuture<Void>> futures = new ArrayList<>();
futures.add(writeTxn.submit());
return futures;
}, SystemPropertyReader.getDataStoreJobCoordinatorMaxRetries());
} else if (update.getVpnState() == VpnInstanceOpDataEntry.VpnState.Created) {
final String vpnName = update.getVpnInstanceName();
final List<String> rds = update.getRd();
String primaryRd = update.getVrfId();
if (!VpnUtil.isBgpVpn(vpnName, primaryRd)) {
return;
}
if (original == null) {
LOG.error("VpnOpStatusListener.update: vpn {} with RD {}. add() handler already called", vpnName, primaryRd);
return;
}
if (update.getVpnTargets() == null) {
LOG.error("VpnOpStatusListener.update: vpn {} with RD {} vpnTargets not ready", vpnName, primaryRd);
return;
}
List<VpnTarget> vpnTargetList = update.getVpnTargets().getVpnTarget();
List<String> ertList = new ArrayList<>();
List<String> irtList = new ArrayList<>();
if (vpnTargetList != null) {
for (VpnTarget vpnTarget : vpnTargetList) {
if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.ExportExtcommunity) {
ertList.add(vpnTarget.getVrfRTValue());
}
if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.ImportExtcommunity) {
irtList.add(vpnTarget.getVrfRTValue());
}
if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.Both) {
ertList.add(vpnTarget.getVrfRTValue());
irtList.add(vpnTarget.getVrfRTValue());
}
}
} else {
LOG.error("VpnOpStatusListener.update: vpn target list is empty, cannot add BGP" + " VPN {} RD {}", vpnName, primaryRd);
return;
}
jobCoordinator.enqueueJob("VPN-" + update.getVpnInstanceName(), () -> {
WriteTransaction writeTxn = dataBroker.newWriteOnlyTransaction();
long primaryRdAddFailed = rds.parallelStream().filter(rd -> {
try {
LOG.info("VpnOpStatusListener.update: updating BGPVPN for vpn {} with RD {}" + " Type is {}, IPv4 is {}, IPv6 is {}", vpnName, primaryRd, update.getType(), update.isIpv4Configured(), update.isIpv6Configured());
if (update.getType() == VpnInstanceOpDataEntry.Type.L2) {
bgpManager.addVrf(rd, irtList, ertList, AddressFamily.L2VPN);
} else {
bgpManager.deleteVrf(rd, false, AddressFamily.L2VPN);
}
if (!original.isIpv4Configured() && update.isIpv4Configured()) {
bgpManager.addVrf(rd, irtList, ertList, AddressFamily.IPV4);
} else if (original.isIpv4Configured() && !update.isIpv4Configured()) {
bgpManager.deleteVrf(rd, false, AddressFamily.IPV4);
}
if (!original.isIpv6Configured() && update.isIpv6Configured()) {
bgpManager.addVrf(rd, irtList, ertList, AddressFamily.IPV6);
} else if (original.isIpv6Configured() && !update.isIpv6Configured()) {
bgpManager.deleteVrf(rd, false, AddressFamily.IPV6);
}
} catch (Exception e) {
LOG.error("VpnOpStatusListener.update: Exception when updating VRF to BGP" + " for vpn {} rd {}", vpnName, rd);
return false;
}
return false;
}).count();
return Collections.emptyList();
});
}
}
Aggregations