use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance in project netvirt by opendaylight.
the class CloudScVpnInterfaceListener method add.
@Override
protected void add(InstanceIdentifier<VpnInterface> key, VpnInterface vpnIfaceAdded) {
for (VpnInstanceNames vpnInstance : vpnIfaceAdded.getVpnInstanceNames()) {
String vpnName = vpnInstance.getVpnName();
if (!vpnInstance.getAssociatedSubnetType().equals(AssociatedSubnetType.V4AndV6Subnets) && !vpnInstance.getAssociatedSubnetType().equals(AssociatedSubnetType.V4Subnet)) {
continue;
}
try {
Optional<VpnToPseudoPortData> optScfInfoForVpn = vpnScHandler.getScfInfoForVpn(vpnName);
if (!optScfInfoForVpn.isPresent()) {
LOG.trace("Vpn {} is not related to ServiceChaining. No further action", vpnName);
return;
}
vpnScHandler.bindScfOnVpnInterface(vpnIfaceAdded.getKey().getName(), optScfInfoForVpn.get().getScfTag());
} catch (ReadFailedException e) {
LOG.error("Error reading the SFC information for VPN {}", vpnName, e);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance 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.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance in project netvirt by opendaylight.
the class NeutronEvpnManager method deleteEVPN.
public Future<RpcResult<DeleteEVPNOutput>> deleteEVPN(DeleteEVPNInput input) {
DeleteEVPNOutputBuilder opBuilder = new DeleteEVPNOutputBuilder();
SettableFuture<RpcResult<DeleteEVPNOutput>> 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;
VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpn.getValue());
if (vpnInstance != null) {
neutronvpnManager.removeVpn(vpn);
} else {
errorList.add(RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-value", formatAndLog(LOG::warn, "EVPN with vpnid: {} does not exist", vpn.getValue())));
warningcount++;
}
}
if (failurecount != 0) {
result.set(RpcResultBuilder.<DeleteEVPNOutput>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("Deletion of EVPN operation successful");
}
opBuilder.setResponse(errorResponseList);
result.set(RpcResultBuilder.<DeleteEVPNOutput>success().withResult(opBuilder.build()).build());
}
return result;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance 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.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance in project netvirt by opendaylight.
the class NeutronvpnManager method addSubnetToVpn.
protected void addSubnetToVpn(@Nullable final Uuid vpnId, Uuid subnet, @Nullable final Uuid internetVpnId) {
LOG.debug("addSubnetToVpn: Adding subnet {} to vpn {}", subnet.getValue(), vpnId != null ? vpnId.getValue() : internetVpnId.getValue());
Subnetmap sn = updateSubnetNode(subnet, null, vpnId, internetVpnId);
if (sn == null) {
LOG.error("addSubnetToVpn: subnetmap is null, cannot add subnet {} to VPN {}", subnet.getValue(), vpnId != null ? vpnId.getValue() : internetVpnId.getValue());
return;
}
if (vpnId != null) {
VpnMap vpnMap = neutronvpnUtils.getVpnMap(vpnId);
if (vpnMap == null) {
LOG.error("addSubnetToVpn: No vpnMap for vpnId {}," + " cannot add subnet {} to VPN", vpnId.getValue(), subnet.getValue());
return;
}
final VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpnId.getValue());
LOG.debug("addSubnetToVpn: VpnInstance {}", vpnInstance.toString());
if (isVpnOfTypeL2(vpnInstance)) {
neutronEvpnUtils.updateElanAndVpn(vpnInstance, sn.getNetworkId().getValue(), NeutronEvpnUtils.Operation.ADD);
}
}
if (internetVpnId != null) {
VpnMap vpnMap = neutronvpnUtils.getVpnMap(internetVpnId);
if (vpnMap == null) {
LOG.error("addSubnetToVpn: No vpnMap for InternetVpnId {}, cannot add " + "subnet {} to VPN", internetVpnId.getValue(), subnet.getValue());
return;
}
}
final Uuid internetId = internetVpnId;
// Check if there are ports on this subnet and add corresponding vpn-interfaces
List<Uuid> portList = sn.getPortList();
if (portList != null) {
for (final Uuid portId : portList) {
String vpnInfName = portId.getValue();
VpnInterface vpnIface = VpnHelper.getVpnInterface(dataBroker, vpnInfName);
Port port = neutronvpnUtils.getNeutronPort(portId);
if (port == null) {
LOG.error("addSubnetToVpn: Cannot proceed with addSubnetToVpn for port {} in subnet {} " + "since port is absent in Neutron config DS", portId.getValue(), subnet.getValue());
continue;
}
final Boolean isRouterInterface = port.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF) ? true : false;
jobCoordinator.enqueueJob("PORT-" + portId.getValue(), () -> singletonList(managedNewTransactionRunner.callWithNewWriteOnlyTransactionAndSubmit(wrtConfigTxn -> {
Adjacencies portAdj = createPortIpAdjacencies(port, isRouterInterface, wrtConfigTxn, sn, vpnIface);
if (vpnIface == null) {
LOG.trace("addSubnetToVpn: create new VpnInterface for Port {}", vpnInfName);
Set<Uuid> listVpn = new HashSet<Uuid>();
if (vpnId != null) {
listVpn.add(vpnId);
}
if (internetId != null) {
listVpn.add(internetId);
}
writeVpnInterfaceToDs(listVpn, vpnInfName, portAdj, isRouterInterface, wrtConfigTxn);
if (sn.getRouterId() != null) {
addToNeutronRouterInterfacesMap(sn.getRouterId(), portId.getValue());
}
} else {
LOG.trace("update VpnInterface for Port {} with adj {}", vpnInfName, portAdj);
if (vpnId != null) {
updateVpnInterfaceWithAdjacencies(vpnId, vpnInfName, portAdj, wrtConfigTxn);
}
if (internetId != null) {
updateVpnInterfaceWithAdjacencies(internetId, vpnInfName, portAdj, wrtConfigTxn);
}
}
})));
}
}
}
Aggregations