use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.Result in project netvirt by opendaylight.
the class NeutronEvpnManager method createEVPN.
@SuppressWarnings("checkstyle:IllegalCatch")
public Future<RpcResult<CreateEVPNOutput>> createEVPN(CreateEVPNInput input) {
CreateEVPNOutputBuilder opBuilder = new CreateEVPNOutputBuilder();
SettableFuture<RpcResult<CreateEVPNOutput>> result = SettableFuture.create();
List<RpcError> errorList = new ArrayList<>();
int failurecount = 0;
int warningcount = 0;
List<String> existingRDs = neutronvpnUtils.getExistingRDs();
List<Evpn> vpns = input.getEvpn();
for (Evpn vpn : vpns) {
if (vpn.getRouteDistinguisher() == null || vpn.getImportRT() == null || vpn.getExportRT() == null) {
errorList.add(RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input", formatAndLog(LOG::warn, "Creation of EVPN failed for VPN {} due to absence of RD/iRT/eRT input", vpn.getId().getValue())));
warningcount++;
continue;
}
VpnInstance.Type vpnInstanceType = VpnInstance.Type.L2;
if (vpn.getRouteDistinguisher().size() > 1) {
errorList.add(RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input", formatAndLog(LOG::warn, "Creation of EVPN failed for VPN {} due to multiple RD input {}", vpn.getId().getValue(), vpn.getRouteDistinguisher())));
warningcount++;
continue;
}
if (existingRDs.contains(vpn.getRouteDistinguisher().get(0))) {
errorList.add(RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input", formatAndLog(LOG::warn, "Creation of EVPN failed for VPN {} as another VPN with the same RD {} is already " + "configured", vpn.getId().getValue(), vpn.getRouteDistinguisher().get(0))));
warningcount++;
continue;
}
try {
neutronvpnManager.createVpn(vpn.getId(), vpn.getName(), vpn.getTenantId(), vpn.getRouteDistinguisher(), vpn.getImportRT(), vpn.getExportRT(), null, /*router-id*/
null, /*network-id*/
vpnInstanceType, 0);
} catch (Exception ex) {
errorList.add(RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, formatAndLog(LOG::error, "Creation of EVPN failed for VPN {}", vpn.getId().getValue(), ex), ex.getMessage()));
failurecount++;
}
}
if (failurecount != 0) {
result.set(RpcResultBuilder.<CreateEVPNOutput>failed().withRpcErrors(errorList).build());
} else {
List<String> errorResponseList = new ArrayList<>();
if (!errorList.isEmpty()) {
for (RpcError rpcError : errorList) {
errorResponseList.add("ErrorType: " + rpcError.getErrorType() + ", ErrorTag: " + rpcError.getTag() + ", ErrorMessage: " + rpcError.getMessage());
}
} else {
errorResponseList.add("EVPN creation successful with no errors");
}
opBuilder.setResponse(errorResponseList);
result.set(RpcResultBuilder.<CreateEVPNOutput>success().withResult(opBuilder.build()).build());
}
return result;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.Result 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;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.Result in project netvirt by opendaylight.
the class NeutronvpnManager method deleteL3VPN.
/**
* It handles the invocations to the neutronvpn:deleteL3VPN RPC method.
*/
@Override
public Future<RpcResult<DeleteL3VPNOutput>> deleteL3VPN(DeleteL3VPNInput input) {
DeleteL3VPNOutputBuilder opBuilder = new DeleteL3VPNOutputBuilder();
SettableFuture<RpcResult<DeleteL3VPNOutput>> result = SettableFuture.create();
List<RpcError> errorList = new ArrayList<>();
int failurecount = 0;
int warningcount = 0;
List<Uuid> vpns = input.getId();
for (Uuid vpn : vpns) {
RpcError error;
String msg;
try {
InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class).child(VpnInstance.class, new VpnInstanceKey(vpn.getValue())).build();
Optional<VpnInstance> optionalVpn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
if (optionalVpn.isPresent()) {
removeVpn(vpn);
} else {
errorList.add(RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-value", formatAndLog(LOG::warn, "VPN with vpnid: {} does not exist", vpn.getValue())));
warningcount++;
}
} catch (ReadFailedException ex) {
errorList.add(RpcResultBuilder.newError(ErrorType.APPLICATION, formatAndLog(LOG::error, "Deletion of L3VPN failed when deleting for uuid {}", vpn.getValue()), ex.getMessage()));
failurecount++;
}
}
// if none succeeds; result is failure
if (failurecount + warningcount == vpns.size()) {
result.set(RpcResultBuilder.<DeleteL3VPNOutput>failed().withRpcErrors(errorList).build());
} else {
List<String> errorResponseList = new ArrayList<>();
if (!errorList.isEmpty()) {
for (RpcError rpcError : errorList) {
errorResponseList.add("ErrorType: " + rpcError.getErrorType() + ", ErrorTag: " + rpcError.getTag() + ", ErrorMessage: " + rpcError.getMessage());
}
} else {
errorResponseList.add("Operation successful with no errors");
}
opBuilder.setResponse(errorResponseList);
result.set(RpcResultBuilder.<DeleteL3VPNOutput>success().withResult(opBuilder.build()).build());
}
return result;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.Result in project netvirt by opendaylight.
the class NeutronvpnManager method associateNetworks.
/**
* It handles the invocations to the neutronvpn:associateNetworks RPC method.
*/
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public Future<RpcResult<AssociateNetworksOutput>> associateNetworks(AssociateNetworksInput input) {
AssociateNetworksOutputBuilder opBuilder = new AssociateNetworksOutputBuilder();
SettableFuture<RpcResult<AssociateNetworksOutput>> result = SettableFuture.create();
LOG.debug("associateNetworks {}", input);
StringBuilder returnMsg = new StringBuilder();
Uuid vpnId = input.getVpnId();
try {
if (neutronvpnUtils.getVpnMap(vpnId) != null) {
List<Uuid> netIds = input.getNetworkId();
if (netIds != null && !netIds.isEmpty()) {
List<String> failed = associateNetworksToVpn(vpnId, netIds);
if (!failed.isEmpty()) {
returnMsg.append(failed);
}
}
} else {
returnMsg.append("VPN not found : ").append(vpnId.getValue());
}
if (returnMsg.length() != 0) {
opBuilder.setResponse("ErrorType: PROTOCOL, ErrorTag: invalid-value, ErrorMessage: " + formatAndLog(LOG::error, "associate Networks to vpn {} failed due to {}", vpnId.getValue(), returnMsg));
result.set(RpcResultBuilder.<AssociateNetworksOutput>success().withResult(opBuilder.build()).build());
} else {
result.set(RpcResultBuilder.<AssociateNetworksOutput>success().build());
}
} catch (Exception ex) {
result.set(RpcResultBuilder.<AssociateNetworksOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::error, "associate Networks to vpn {} failed due to {}", input.getVpnId().getValue(), ex.getMessage(), ex)).build());
}
LOG.debug("associateNetworks returns..");
return result;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.Result in project netvirt by opendaylight.
the class L2GatewayUtils method createItmTunnels.
protected static void createItmTunnels(ItmRpcService itmRpcService, String hwvtepId, String psName, IpAddress tunnelIp) {
AddL2GwDeviceInputBuilder builder = new AddL2GwDeviceInputBuilder();
builder.setTopologyId(HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID.getValue());
builder.setNodeId(HwvtepSouthboundUtils.createManagedNodeId(new NodeId(hwvtepId), psName).getValue());
builder.setIpAddress(tunnelIp);
try {
Future<RpcResult<Void>> result = itmRpcService.addL2GwDevice(builder.build());
RpcResult<Void> rpcResult = result.get();
if (rpcResult.isSuccessful()) {
LOG.info("Created ITM tunnels for {}", hwvtepId);
} else {
LOG.error("Failed to create ITM Tunnels: {}", rpcResult.getErrors());
}
} catch (InterruptedException | ExecutionException e) {
LOG.error("RPC to create ITM tunnels failed", e);
}
}
Aggregations