use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap in project netvirt by opendaylight.
the class NeutronvpnManager method removeVpn.
public void removeVpn(Uuid id) {
// read VPNMaps
VpnMap vpnMap = neutronvpnUtils.getVpnMap(id);
Uuid router = vpnMap != null ? vpnMap.getRouterId() : null;
// dissociate router
if (router != null) {
dissociateRouterFromVpn(id, router);
}
// dissociate networks
if (!id.equals(router) && vpnMap.getNetworkIds() != null) {
dissociateNetworksFromVpn(id, vpnMap.getNetworkIds());
}
// remove entire vpnMaps node
deleteVpnMapsNode(id);
// remove vpn-instance
deleteVpnInstance(id);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap in project netvirt by opendaylight.
the class NatUtil method getVpnForRouter.
static Uuid getVpnForRouter(DataBroker broker, String routerId) {
InstanceIdentifier<VpnMaps> vpnMapsIdentifier = InstanceIdentifier.builder(VpnMaps.class).build();
Optional<VpnMaps> optionalVpnMaps = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.CONFIGURATION, vpnMapsIdentifier);
if (optionalVpnMaps.isPresent() && optionalVpnMaps.get().getVpnMap() != null) {
List<VpnMap> allMaps = optionalVpnMaps.get().getVpnMap();
if (routerId != null) {
for (VpnMap vpnMap : allMaps) {
if (vpnMap.getRouterId() != null && routerId.equals(vpnMap.getRouterId().getValue()) && !routerId.equals(vpnMap.getVpnId().getValue())) {
return vpnMap.getVpnId();
}
}
}
}
LOG.debug("getVpnForRouter : VPN not found for routerID:{}", routerId);
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnMaps.
private void updateVpnMaps(Uuid vpnId, String name, Uuid router, Uuid tenantId, List<Uuid> networks) {
VpnMapBuilder builder;
boolean isLockAcquired = false;
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(vpnId)).build();
try {
Optional<VpnMap> optionalVpnMap = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
if (optionalVpnMap.isPresent()) {
builder = new VpnMapBuilder(optionalVpnMap.get());
} else {
builder = new VpnMapBuilder().setKey(new VpnMapKey(vpnId)).setVpnId(vpnId);
}
if (name != null) {
builder.setName(name);
}
if (tenantId != null) {
builder.setTenantId(tenantId);
}
if (router != null) {
builder.setRouterId(router);
}
if (networks != null) {
List<Uuid> nwList = builder.getNetworkIds();
if (nwList == null) {
nwList = new ArrayList<>();
}
nwList.addAll(networks);
builder.setNetworkIds(nwList);
}
isLockAcquired = vpnLock.tryLock(vpnId, LOCK_WAIT_TIME, TimeUnit.SECONDS);
LOG.debug("Creating/Updating vpnMaps node: {} ", vpnId.getValue());
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier, builder.build());
LOG.debug("VPNMaps DS updated for VPN {} ", vpnId.getValue());
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("UpdateVpnMaps failed for node: {} ", vpnId.getValue());
} finally {
if (isLockAcquired) {
vpnLock.unlock(vpnId);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap in project netvirt by opendaylight.
the class NeutronvpnManager method clearFromVpnMaps.
private void clearFromVpnMaps(Uuid vpnId, Uuid routerId, List<Uuid> networkIds) {
boolean isLockAcquired = false;
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(vpnId)).build();
Optional<VpnMap> optionalVpnMap;
try {
optionalVpnMap = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
} catch (ReadFailedException e) {
LOG.error("Error reading the VPN map for {}", vpnMapIdentifier, e);
return;
}
if (optionalVpnMap.isPresent()) {
VpnMap vpnMap = optionalVpnMap.get();
VpnMapBuilder vpnMapBuilder = new VpnMapBuilder(vpnMap);
if (routerId != null) {
if (vpnMap.getNetworkIds() == null && routerId.equals(vpnMap.getVpnId())) {
try {
// remove entire node in case of internal VPN
isLockAcquired = vpnLock.tryLock(vpnId, LOCK_WAIT_TIME, TimeUnit.SECONDS);
LOG.debug("removing vpnMaps node: {} ", vpnId);
SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
} catch (TransactionCommitFailedException e) {
LOG.error("Deletion of vpnMaps node failed for vpn {}", vpnId.getValue());
} finally {
if (isLockAcquired) {
vpnLock.unlock(vpnId);
}
}
return;
}
vpnMapBuilder.setRouterId(null);
}
if (networkIds != null) {
List<Uuid> vpnNw = vpnMap.getNetworkIds();
vpnNw.removeAll(networkIds);
if (vpnNw.isEmpty()) {
LOG.debug("setting networks null in vpnMaps node: {} ", vpnId.getValue());
vpnMapBuilder.setNetworkIds(null);
} else {
vpnMapBuilder.setNetworkIds(vpnNw);
}
}
try {
isLockAcquired = vpnLock.tryLock(vpnId, LOCK_WAIT_TIME, TimeUnit.SECONDS);
LOG.debug("clearing from vpnMaps node: {} ", vpnId.getValue());
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier, vpnMapBuilder.build());
} catch (TransactionCommitFailedException e) {
LOG.error("Clearing from vpnMaps node failed for vpn {}", vpnId.getValue());
} finally {
if (isLockAcquired) {
vpnLock.unlock(vpnId);
}
}
} else {
LOG.error("VPN : {} not found", vpnId.getValue());
}
LOG.debug("Clear from VPNMaps DS successful for VPN {} ", vpnId.getValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap in project netvirt by opendaylight.
the class NeutronvpnManager method getL3VPN.
/**
* It handles the invocations to the neutronvpn:getL3VPN RPC method.
*/
@Override
public Future<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().getVpnInstance()) {
// from getL3VPN output
if (vpn.getIpv4Family().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().getIpv4Family().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 = vpnInstance.getIpv4Family().getRouteDistinguisher();
List<String> ertList = new ArrayList<>();
List<String> irtList = new ArrayList<>();
if (vpnInstance.getIpv4Family().getVpnTargets() != null) {
List<VpnTarget> vpnTargetList = vpnInstance.getIpv4Family().getVpnTargets().getVpnTarget();
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());
}
}
}
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();
l3vpn.setRouterId(vpnMap.getRouterId()).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 (ReadFailedException ex) {
result.set(RpcResultBuilder.<GetL3VPNOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::error, "GetVPN failed due to {}", ex.getMessage())).build());
}
return result;
}
Aggregations