use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.getevpn.output.EvpnInstances in project netvirt by opendaylight.
the class NeutronEvpnManager method getEVPN.
public Future<RpcResult<GetEVPNOutput>> getEVPN(GetEVPNInput input) {
GetEVPNOutputBuilder opBuilder = new GetEVPNOutputBuilder();
SettableFuture<RpcResult<GetEVPNOutput>> result = SettableFuture.create();
Uuid inputVpnId = input.getId();
List<VpnInstance> vpns = new ArrayList<>();
if (inputVpnId == null) {
vpns = VpnHelper.getAllVpnInstances(dataBroker);
if (!vpns.isEmpty()) {
for (VpnInstance vpn : vpns) {
if (vpn.getIpv4Family().getRouteDistinguisher() != null && vpn.getType() == VpnInstance.Type.L2) {
vpns.add(vpn);
}
}
} else {
// No VPN present
result.set(RpcResultBuilder.<GetEVPNOutput>success().withResult(opBuilder.build()).build());
return result;
}
} else {
String name = inputVpnId.getValue();
VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, name);
if (vpnInstance != null && vpnInstance.getIpv4Family().getRouteDistinguisher() != null && vpnInstance.getType() == VpnInstance.Type.L2) {
vpns.add(vpnInstance);
} else {
result.set(RpcResultBuilder.<GetEVPNOutput>failed().withWarning(RpcError.ErrorType.PROTOCOL, "invalid-value", formatAndLog(LOG::error, "GetEVPN failed because VPN {} is not present", name)).build());
}
}
List<EvpnInstances> evpnList = new ArrayList<>();
for (VpnInstance vpnInstance : vpns) {
Uuid vpnId = new Uuid(vpnInstance.getVpnInstanceName());
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(vpnId)).build();
EvpnInstancesBuilder evpn = new EvpnInstancesBuilder();
List<String> rd = vpnInstance.getIpv4Family().getRouteDistinguisher();
List<VpnTarget> vpnTargetList = vpnInstance.getIpv4Family().getVpnTargets().getVpnTarget();
List<String> ertList = new ArrayList<>();
List<String> irtList = new ArrayList<>();
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());
}
}
evpn.setId(vpnId).setRouteDistinguisher(rd).setImportRT(irtList).setExportRT(ertList);
try {
Optional<VpnMap> optionalVpnMap = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
if (optionalVpnMap.isPresent()) {
VpnMap vpnMap = optionalVpnMap.get();
evpn.setTenantId(vpnMap.getTenantId()).setName(vpnMap.getName());
}
} catch (ReadFailedException e) {
LOG.error("Error reading the VPN map for {}", vpnMapIdentifier, e);
result.set(RpcResultBuilder.<GetEVPNOutput>failed().withError(RpcError.ErrorType.APPLICATION, "Error reading the VPN map for " + vpnMapIdentifier, e).build());
return result;
}
evpnList.add(evpn.build());
}
opBuilder.setEvpnInstances(evpnList);
result.set(RpcResultBuilder.<GetEVPNOutput>success().withResult(opBuilder.build()).build());
return result;
}
Aggregations