use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.VpnTargets in project netvirt by opendaylight.
the class VpnUtil method getRts.
public static List<String> getRts(VpnInstanceOpDataEntry vpnInstance, VpnTarget.VrfRTType rtType) {
String name = vpnInstance.getVpnInstanceName();
List<String> rts = new ArrayList<>();
VpnTargets targets = vpnInstance.getVpnTargets();
if (targets == null) {
LOG.info("getRts: vpn targets not available for {}", name);
return rts;
}
List<VpnTarget> vpnTargets = targets.getVpnTarget();
if (vpnTargets == null) {
LOG.info("getRts: vpnTarget values not available for {}", name);
return rts;
}
for (VpnTarget target : vpnTargets) {
// TODO: Check for RT type is Both
if (target.getVrfRTType().equals(rtType) || target.getVrfRTType().equals(VpnTarget.VrfRTType.Both)) {
String rtValue = target.getVrfRTValue();
rts.add(rtValue);
}
}
return rts;
}
use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.VpnTargets in project netvirt by opendaylight.
the class InterVpnLinkLocator method getRts.
private List<String> getRts(VpnInstanceOpDataEntry vpnInstance, VpnTarget.VrfRTType rtType) {
String name = vpnInstance.getVpnInstanceName();
VpnTargets targets = vpnInstance.getVpnTargets();
if (targets == null) {
LOG.trace("vpn targets not available for {}", name);
return new ArrayList<>();
}
List<VpnTarget> vpnTargets = targets.getVpnTarget();
if (vpnTargets == null) {
LOG.trace("vpnTarget values not available for {}", name);
return new ArrayList<>();
}
return vpnTargets.stream().filter(target -> target.getVrfRTType().equals(rtType) || target.getVrfRTType().equals(VpnTarget.VrfRTType.Both)).map(VpnTarget::getVrfRTValue).collect(Collectors.toList());
}
use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.VpnTargets in project netvirt by opendaylight.
the class CoeUtils method createVpnInstance.
public static void createVpnInstance(String vpnName, List<String> rd, List<String> irt, List<String> ert, VpnInstance.Type type, long l3vni, IpVersionChoice ipVersion, ReadWriteTransaction tx) throws ReadFailedException {
List<VpnTarget> vpnTargetList = new ArrayList<>();
LOG.debug("Creating/Updating a new vpn-instance node: {} ", vpnName);
VpnInstanceBuilder builder = new VpnInstanceBuilder().setKey(new VpnInstanceKey(vpnName)).setVpnInstanceName(vpnName).setType(type).setL3vni(l3vni);
if (irt != null && !irt.isEmpty()) {
if (ert != null && !ert.isEmpty()) {
List<String> commonRT = new ArrayList<>(irt);
commonRT.retainAll(ert);
for (String common : commonRT) {
irt.remove(common);
ert.remove(common);
VpnTarget vpnTarget = new VpnTargetBuilder().setKey(new VpnTargetKey(common)).setVrfRTValue(common).setVrfRTType(VpnTarget.VrfRTType.Both).build();
vpnTargetList.add(vpnTarget);
}
}
for (String importRT : irt) {
VpnTarget vpnTarget = new VpnTargetBuilder().setKey(new VpnTargetKey(importRT)).setVrfRTValue(importRT).setVrfRTType(VpnTarget.VrfRTType.ImportExtcommunity).build();
vpnTargetList.add(vpnTarget);
}
}
if (ert != null && !ert.isEmpty()) {
for (String exportRT : ert) {
VpnTarget vpnTarget = new VpnTargetBuilder().setKey(new VpnTargetKey(exportRT)).setVrfRTValue(exportRT).setVrfRTType(VpnTarget.VrfRTType.ExportExtcommunity).build();
vpnTargetList.add(vpnTarget);
}
}
VpnTargets vpnTargets = new VpnTargetsBuilder().setVpnTarget(vpnTargetList).build();
Ipv4FamilyBuilder ipv4vpnBuilder = new Ipv4FamilyBuilder().setVpnTargets(vpnTargets);
Ipv6FamilyBuilder ipv6vpnBuilder = new Ipv6FamilyBuilder().setVpnTargets(vpnTargets);
if (rd != null && !rd.isEmpty()) {
ipv4vpnBuilder.setRouteDistinguisher(rd);
ipv6vpnBuilder.setRouteDistinguisher(rd);
}
if (ipVersion != null && ipVersion.isIpVersionChosen(IpVersionChoice.IPV4)) {
builder.setIpv4Family(ipv4vpnBuilder.build());
}
if (ipVersion != null && ipVersion.isIpVersionChosen(IpVersionChoice.IPV6)) {
builder.setIpv6Family(ipv6vpnBuilder.build());
}
if (ipVersion != null && ipVersion.isIpVersionChosen(IpVersionChoice.UNDEFINED)) {
builder.setIpv4Family(ipv4vpnBuilder.build());
}
VpnInstance newVpn = builder.build();
LOG.debug("Creating/Updating vpn-instance for {} ", vpnName);
InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class).child(VpnInstance.class, new VpnInstanceKey(vpnName)).build();
tx.put(LogicalDatastoreType.CONFIGURATION, vpnIdentifier, newVpn);
}
use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.VpnTargets 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.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.VpnTargets 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