use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstanceKey in project netvirt by opendaylight.
the class NeutronvpnManager method getL3VPN.
/**
* It handles the invocations to the neutronvpn:getL3VPN RPC method.
*/
@Override
public ListenableFuture<RpcResult<GetL3VPNOutput>> getL3VPN(GetL3VPNInput input) {
GetL3VPNOutputBuilder opBuilder = new GetL3VPNOutputBuilder();
SettableFuture<RpcResult<GetL3VPNOutput>> result = SettableFuture.create();
Uuid inputVpnId = input.getId();
List<VpnInstance> vpns = new ArrayList<>();
List<L3vpnInstances> l3vpnList = new ArrayList<>();
try {
if (inputVpnId == null) {
// get all vpns
InstanceIdentifier<VpnInstances> vpnsIdentifier = InstanceIdentifier.builder(VpnInstances.class).build();
Optional<VpnInstances> optionalVpns = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnsIdentifier);
if (optionalVpns.isPresent() && !optionalVpns.get().getVpnInstance().isEmpty()) {
for (VpnInstance vpn : optionalVpns.get().nonnullVpnInstance().values()) {
// from getL3VPN output
if (vpn.getRouteDistinguisher() != null) {
vpns.add(vpn);
}
}
} else {
// No VPN present
opBuilder.setL3vpnInstances(l3vpnList);
result.set(RpcResultBuilder.<GetL3VPNOutput>success().withResult(opBuilder.build()).build());
return result;
}
} else {
String name = inputVpnId.getValue();
InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class).child(VpnInstance.class, new VpnInstanceKey(name)).build();
// read VpnInstance Info
Optional<VpnInstance> optionalVpn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
// getL3VPN output
if (optionalVpn.isPresent() && optionalVpn.get().getRouteDistinguisher() != null) {
vpns.add(optionalVpn.get());
} else {
result.set(RpcResultBuilder.<GetL3VPNOutput>failed().withWarning(ErrorType.PROTOCOL, "invalid-value", formatAndLog(LOG::error, "GetL3VPN failed because VPN {} is not present", name)).build());
}
}
for (VpnInstance vpnInstance : vpns) {
Uuid vpnId = new Uuid(vpnInstance.getVpnInstanceName());
// create VpnMaps id
L3vpnInstancesBuilder l3vpn = new L3vpnInstancesBuilder();
List<String> rd = Collections.emptyList();
if (vpnInstance.getRouteDistinguisher() != null) {
rd = vpnInstance.getRouteDistinguisher();
}
List<String> ertList = new ArrayList<>();
List<String> irtList = new ArrayList<>();
if (vpnInstance.getVpnTargets() != null) {
Map<VpnTargetKey, VpnTarget> keyVpnTargetMap = Collections.emptyMap();
if (!vpnInstance.getVpnTargets().getVpnTarget().isEmpty()) {
keyVpnTargetMap = vpnInstance.getVpnTargets().getVpnTarget();
}
if (!keyVpnTargetMap.isEmpty()) {
for (VpnTarget vpnTarget : keyVpnTargetMap.values()) {
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());
}
}
}
}
l3vpn.setId(vpnId).setRouteDistinguisher(rd).setImportRT(irtList).setExportRT(ertList);
if (vpnInstance.getL3vni() != null) {
l3vpn.setL3vni(vpnInstance.getL3vni());
}
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(vpnId)).build();
Optional<VpnMap> optionalVpnMap = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
if (optionalVpnMap.isPresent()) {
VpnMap vpnMap = optionalVpnMap.get();
List<Uuid> rtrIds = new ArrayList<>();
if (vpnMap.getRouterIds() != null && !vpnMap.getRouterIds().isEmpty()) {
for (RouterIds rtrId : vpnMap.getRouterIds().values()) {
rtrIds.add(rtrId.getRouterId());
}
}
l3vpn.setRouterIds(NeutronvpnUtils.getVpnInstanceRouterIdsList(rtrIds)).setNetworkIds(vpnMap.getNetworkIds()).setTenantId(vpnMap.getTenantId()).setName(vpnMap.getName());
}
l3vpnList.add(l3vpn.build());
}
opBuilder.setL3vpnInstances(l3vpnList);
result.set(RpcResultBuilder.<GetL3VPNOutput>success().withResult(opBuilder.build()).build());
} catch (ExecutionException | InterruptedException ex) {
result.set(RpcResultBuilder.<GetL3VPNOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::error, "GetVPN failed due to {}", ex.getMessage())).build());
}
return result;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstanceKey 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("updateVpnInstanceWithRDs: " + "No VpnInstance present under config vpnInstance:{}", vpnInstanceId);
return;
}
VpnInstance vpnInstance = vpnInstanceConfig.get();
VpnInstanceBuilder updateVpnInstanceBuilder = new VpnInstanceBuilder(vpnInstance);
updateVpnInstanceBuilder.setRouteDistinguisher(rds);
LOG.debug("updateVpnInstanceWithRDs: " + "Updating Config vpn-instance: {} with the list of RDs: {}", vpnInstanceId, rds);
SingleTransactionDataBroker.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier, updateVpnInstanceBuilder.build());
} catch (TransactionCommitFailedException | ExecutionException | InterruptedException ex) {
LOG.warn("updateVpnInstanceWithRDs: Error configuring vpn-instance: {} with " + "the list of RDs: {}", vpnInstanceId, rds, ex);
}
}
Aggregations