use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIds in project netvirt by opendaylight.
the class NeutronvpnManager method dissociateRouter.
/**
* It handles the invocations to the neutronvpn:dissociateRouter RPC method.
*/
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public ListenableFuture<RpcResult<DissociateRouterOutput>> dissociateRouter(DissociateRouterInput input) {
SettableFuture<RpcResult<DissociateRouterOutput>> result = SettableFuture.create();
LOG.debug("dissociateRouter {}", input);
StringBuilder returnMsg = new StringBuilder();
Uuid vpnId = input.getVpnId();
Map<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.dissociaterouter.input.RouterIdsKey, org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.dissociaterouter.input.RouterIds> keyRouterIdsMap = input.nonnullRouterIds();
String routerIdsString = "";
Preconditions.checkArgument(!keyRouterIdsMap.isEmpty(), "dissociateRouter: RouterIds list is empty!");
Preconditions.checkNotNull(vpnId, "dissociateRouter: vpnId not found!");
Preconditions.checkNotNull(keyRouterIdsMap, "dissociateRouter: keyRouterIdsMap not found!");
if (neutronvpnUtils.getVpnMap(vpnId) != null) {
for (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.dissociaterouter.input.RouterIds routerId : keyRouterIdsMap.values()) {
try {
if (routerId != null) {
routerIdsString += routerId.getRouterId() + ", ";
Router rtr = neutronvpnUtils.getNeutronRouter(routerId.getRouterId());
if (rtr != null) {
Uuid routerVpnId = neutronvpnUtils.getVpnForRouter(routerId.getRouterId(), true);
if (routerVpnId == null) {
returnMsg.append("input router ").append(routerId.getRouterId()).append(" not associated to any vpn yet");
} else if (vpnId.equals(routerVpnId)) {
dissociateRouterFromVpn(vpnId, routerId.getRouterId());
} else {
returnMsg.append("input router ").append(routerId.getRouterId()).append(" associated to vpn ").append(routerVpnId.getValue()).append("instead of the vpn given as input");
}
} else {
returnMsg.append("router not found : ").append(routerId.getRouterId());
}
}
if (returnMsg.length() != 0) {
result.set(RpcResultBuilder.<DissociateRouterOutput>failed().withWarning(ErrorType.PROTOCOL, "invalid-value", formatAndLog(LOG::error, "dissociate router {} to " + "vpn {} failed due to {}", routerId.getRouterId(), vpnId.getValue(), returnMsg)).build());
} else {
result.set(RpcResultBuilder.success(new DissociateRouterOutputBuilder().build()).build());
}
} catch (Exception ex) {
result.set(RpcResultBuilder.<DissociateRouterOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::error, "disssociate router {} to vpn {} failed due to {}", routerId.getRouterId(), vpnId.getValue(), ex.getMessage(), ex)).build());
}
}
} else {
returnMsg.append("VPN not found : ").append(vpnId.getValue());
}
LOG.debug("dissociateRouter returns..");
return result;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIds in project netvirt by opendaylight.
the class NeutronvpnManager method clearFromVpnMaps.
private void clearFromVpnMaps(Uuid vpnId, @Nullable Uuid routerId, @Nullable List<Uuid> networkIds) {
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 (ExecutionException | InterruptedException e) {
LOG.error("Error reading the VPN map for {}", vpnMapIdentifier, e);
return;
}
if (optionalVpnMap.isPresent()) {
VpnMap vpnMap = optionalVpnMap.get();
VpnMapBuilder vpnMapBuilder = new VpnMapBuilder(vpnMap);
List<RouterIds> rtrIds = new ArrayList<>(vpnMap.nonnullRouterIds().values());
if (rtrIds == null) {
rtrIds = new ArrayList<>();
}
if (routerId != null) {
if (vpnMap.getNetworkIds() == null && routerId.equals(vpnMap.getVpnId())) {
rtrIds.add(new RouterIdsBuilder().setRouterId(routerId).build());
vpnMapBuilder.setRouterIds(rtrIds);
try (AcquireResult lock = tryVpnLock(vpnId)) {
if (!lock.wasAcquired()) {
// FIXME: why do we even bother with locking if we do not honor it?!
logTryLockFailure(vpnId);
}
LOG.debug("removing vpnMaps node: {} ", vpnId);
try {
SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
} catch (TransactionCommitFailedException e) {
LOG.error("Deletion of vpnMaps node failed for vpn {}", vpnId.getValue());
}
}
return;
} else if (vpnMap.getNetworkIds() == null && !routerId.equals(vpnMap.getVpnId())) {
rtrIds.remove(new RouterIdsBuilder().setRouterId(routerId).build());
vpnMapBuilder.setRouterIds(rtrIds);
LOG.debug("Removing routerId {} in vpnMaps for the vpn {}", routerId, vpnId.getValue());
}
}
if (networkIds != null) {
List<Uuid> vpnNw = vpnMap.getNetworkIds() != null ? new ArrayList<>(vpnMap.getNetworkIds()) : new ArrayList<>();
vpnNw.removeAll(networkIds);
if (vpnNw.isEmpty()) {
LOG.debug("setting networks null in vpnMaps node: {} ", vpnId.getValue());
vpnMapBuilder.setNetworkIds(null);
} else {
vpnMapBuilder.setNetworkIds(vpnNw);
}
}
try (AcquireResult lock = tryVpnLock(vpnId)) {
if (!lock.wasAcquired()) {
// FIXME: why do we even bother with locking if we do not honor it?!
logTryLockFailure(vpnId);
}
LOG.debug("clearing from vpnMaps node: {} ", vpnId.getValue());
try {
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier, vpnMapBuilder.build());
} catch (TransactionCommitFailedException e) {
LOG.error("Clearing from vpnMaps node failed for vpn {}", vpnId.getValue());
}
}
} 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.RouterIds in project netvirt by opendaylight.
the class NeutronvpnUtils method getVpnForRouter.
// @param external vpn - true if external vpn being fetched, false for internal vpn
@Nullable
protected Uuid getVpnForRouter(@Nullable Uuid routerId, boolean externalVpn) {
if (routerId == null) {
return null;
}
Optional<VpnMaps> optionalVpnMaps = read(LogicalDatastoreType.CONFIGURATION, VPN_MAPS_IID);
if (optionalVpnMaps.isPresent() && optionalVpnMaps.get().nonnullVpnMap() != null) {
for (VpnMap vpnMap : new ArrayList<>(optionalVpnMaps.get().nonnullVpnMap().values())) {
Map<RouterIdsKey, org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIds> keyRouterIdsMap = vpnMap.nonnullRouterIds();
if (keyRouterIdsMap == null || keyRouterIdsMap.isEmpty()) {
continue;
}
// Skip router vpnId fetching from internet BGP-VPN
if (hasExternalNetwork(vpnMap.getNetworkIds())) {
continue;
}
// FIXME: NETVIRT-1503: this check can be replaced by a ReadOnlyTransaction.exists()
if (keyRouterIdsMap.values().stream().anyMatch(routerIds -> routerId.equals(routerIds.getRouterId()))) {
if (externalVpn) {
if (!routerId.equals(vpnMap.getVpnId())) {
return vpnMap.getVpnId();
}
} else {
if (routerId.equals(vpnMap.getVpnId())) {
return vpnMap.getVpnId();
}
}
}
}
}
LOG.debug("getVpnForRouter: Failed for router {} as no VPN present in VPNMaps DS", routerId.getValue());
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIds in project netvirt by opendaylight.
the class NeutronvpnUtils method updateVpnInstanceWithFallback.
public void updateVpnInstanceWithFallback(Uuid routerId, Uuid vpnName, boolean add) {
VpnInstanceOpDataEntry vpnInstanceOpDataEntry = getVpnInstanceOpDataEntryFromVpnId(vpnName.getValue());
if (vpnInstanceOpDataEntry == null) {
LOG.error("updateVpnInstanceWithFallback: vpnInstanceOpDataEntry not found for vpn {}", vpnName);
return;
}
Long internetBgpVpnId = vpnInstanceOpDataEntry.getVpnId().toJava();
List<Uuid> routerIds = new ArrayList<>();
// Handle router specific V6 internet fallback flow else handle all V6 external routers
if (routerId != null) {
routerIds.add(routerId);
} else {
// This block will execute for ext-nw to Internet VPN association/disassociation event.
routerIds = getRouterIdListforVpn(vpnName);
}
if (routerIds == null || routerIds.isEmpty()) {
LOG.error("updateVpnInstanceWithFallback: router not found for vpn {}", vpnName);
return;
}
for (Uuid rtrId : routerIds) {
if (rtrId == null) {
continue;
}
List<Uint64> dpnIds = getDpnsForRouter(rtrId.getValue());
if (dpnIds.isEmpty()) {
continue;
}
VpnInstanceOpDataEntry vpnOpDataEntry = getVpnInstanceOpDataEntryFromVpnId(rtrId.getValue());
Long routerIdAsLong = vpnOpDataEntry.getVpnId().toJava();
long vpnId;
Uuid rtrVpnId = getVpnForRouter(rtrId, true);
if (rtrVpnId == null) {
// If external BGP-VPN is not associated with router then routerId is same as routerVpnId
vpnId = routerIdAsLong;
} else {
vpnId = getVpnId(rtrVpnId.getValue());
}
for (Uint64 dpnId : dpnIds) {
if (add) {
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION, tx -> ipV6InternetDefRt.installDefaultRoute(tx, dpnId, rtrId.getValue(), internetBgpVpnId, vpnId)), LOG, "Error adding default route");
} else {
LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(Datastore.CONFIGURATION, tx -> ipV6InternetDefRt.removeDefaultRoute(tx, dpnId, rtrId.getValue(), internetBgpVpnId, vpnId)), LOG, "Error removing default route");
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIds 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;
}
Aggregations