use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.vpn.instance.Ipv6FamilyBuilder 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.instances.vpn.instance.Ipv6FamilyBuilder in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnInstanceNode.
private void updateVpnInstanceNode(Uuid vpnId, List<String> rd, List<String> irt, List<String> ert, VpnInstance.Type type, long l3vni, IpVersionChoice ipVersion) {
String vpnName = vpnId.getValue();
VpnInstanceBuilder builder = null;
List<VpnTarget> vpnTargetList = new ArrayList<>();
boolean isLockAcquired = false;
InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class).child(VpnInstance.class, new VpnInstanceKey(vpnName)).build();
try {
Optional<VpnInstance> optionalVpn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
LOG.debug("Creating/Updating a new vpn-instance node: {} ", vpnName);
if (optionalVpn.isPresent()) {
builder = new VpnInstanceBuilder(optionalVpn.get());
LOG.debug("updating existing vpninstance node");
} else {
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();
isLockAcquired = vpnLock.tryLock(vpnId, LOCK_WAIT_TIME, TimeUnit.SECONDS);
LOG.debug("Creating/Updating vpn-instance for {} ", vpnName);
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier, newVpn);
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Update VPN Instance node failed for node: {} {} {} {}", vpnName, rd, irt, ert);
} finally {
if (isLockAcquired) {
vpnLock.unlock(vpnId);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.vpn.instance.Ipv6FamilyBuilder in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnInstanceWithRDs.
public void updateVpnInstanceWithRDs(String vpnInstanceId, final List<String> rds) {
InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class).child(VpnInstance.class, new VpnInstanceKey(vpnInstanceId)).build();
try {
Optional<VpnInstance> vpnInstanceConfig = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
if (!vpnInstanceConfig.isPresent()) {
LOG.debug("No VpnInstance present under config vpnInstance:{}", vpnInstanceId);
return;
}
VpnInstance vpnInstance = vpnInstanceConfig.get();
VpnInstanceBuilder updateVpnInstanceBuilder = new VpnInstanceBuilder(vpnInstance);
if (vpnInstance.getIpv4Family() != null) {
Ipv4FamilyBuilder ipv4FamilyBuilder = new Ipv4FamilyBuilder(vpnInstance.getIpv4Family());
updateVpnInstanceBuilder.setIpv4Family(ipv4FamilyBuilder.setRouteDistinguisher(rds).build());
}
if (vpnInstance.getIpv6Family() != null) {
Ipv6FamilyBuilder ipv6FamilyBuilder = new Ipv6FamilyBuilder(vpnInstance.getIpv6Family());
updateVpnInstanceBuilder.setIpv6Family(ipv6FamilyBuilder.setRouteDistinguisher(rds).build());
}
LOG.debug("Updating Config vpn-instance: {} with the list of RDs: {}", vpnInstanceId, rds);
SingleTransactionDataBroker.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier, updateVpnInstanceBuilder.build());
} catch (ReadFailedException | TransactionCommitFailedException ex) {
LOG.warn("Error configuring feature ", ex);
}
}
Aggregations