use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap in project netvirt by opendaylight.
the class NeutronvpnManager method associateRouter.
/**
* It handles the invocations to the neutronvpn:associateRouter RPC method.
*/
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public Future<RpcResult<Void>> associateRouter(AssociateRouterInput input) {
SettableFuture<RpcResult<Void>> result = SettableFuture.create();
LOG.debug("associateRouter {}", input);
StringBuilder returnMsg = new StringBuilder();
Uuid vpnId = input.getVpnId();
Uuid routerId = input.getRouterId();
try {
VpnMap vpnMap = neutronvpnUtils.getVpnMap(vpnId);
Router rtr = neutronvpnUtils.getNeutronRouter(routerId);
if (vpnMap != null) {
if (rtr != null) {
Uuid extVpnId = neutronvpnUtils.getVpnForRouter(routerId, true);
if (vpnMap.getRouterId() != null) {
returnMsg.append("vpn ").append(vpnId.getValue()).append(" already associated to router ").append(vpnMap.getRouterId().getValue());
} else if (extVpnId != null) {
returnMsg.append("router ").append(routerId.getValue()).append(" already associated to " + "another VPN ").append(extVpnId.getValue());
} else {
associateRouterToVpn(vpnId, routerId);
}
} else {
returnMsg.append("router not found : ").append(routerId.getValue());
}
} else {
returnMsg.append("VPN not found : ").append(vpnId.getValue());
}
if (returnMsg.length() != 0) {
result.set(RpcResultBuilder.<Void>failed().withWarning(ErrorType.PROTOCOL, "invalid-value", formatAndLog(LOG::error, "associate router to vpn {} failed due to {}", routerId.getValue(), returnMsg)).build());
} else {
result.set(RpcResultBuilder.<Void>success().build());
}
} catch (Exception ex) {
result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::error, "associate router {} to vpn {} failed due to {}", routerId.getValue(), vpnId.getValue(), ex.getMessage(), ex)).build());
}
LOG.debug("associateRouter returns..");
return result;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap in project netvirt by opendaylight.
the class NeutronvpnManager method removeSubnetFromVpn.
protected void removeSubnetFromVpn(final Uuid vpnId, Uuid subnet, Uuid internetVpnId) {
Preconditions.checkArgument(vpnId != null || internetVpnId != null, "removeSubnetFromVpn: at least one VPN must be not null");
LOG.debug("Removing subnet {} from vpn {}/{}", subnet.getValue(), vpnId, internetVpnId);
Subnetmap sn = neutronvpnUtils.getSubnetmap(subnet);
if (sn == null) {
LOG.error("removeSubnetFromVpn: Subnetmap for subnet {} not found", subnet.getValue());
return;
}
VpnMap vpnMap = null;
VpnInstance vpnInstance = null;
if (vpnId != null) {
vpnMap = neutronvpnUtils.getVpnMap(vpnId);
if (vpnMap == null) {
LOG.error("No vpnMap for vpnId {}, cannot remove subnet {} from VPN", vpnId.getValue(), subnet.getValue());
return;
}
vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpnId.getValue());
}
if (internetVpnId == null) {
internetVpnId = sn.getInternetVpnId();
}
if (internetVpnId != null) {
vpnMap = neutronvpnUtils.getVpnMap(internetVpnId);
if (vpnMap == null) {
LOG.error("No vpnMap for vpnId {}, cannot remove subnet {}" + " from Internet VPN", internetVpnId.getValue(), subnet.getValue());
return;
}
}
if (vpnInstance != null && isVpnOfTypeL2(vpnInstance)) {
neutronEvpnUtils.updateElanAndVpn(vpnInstance, sn.getNetworkId().getValue(), NeutronEvpnUtils.Operation.DELETE);
}
boolean subnetVpnAssociation = false;
if (vpnId != null && sn.getVpnId() != null && sn.getVpnId().getValue().equals(vpnId.getValue())) {
subnetVpnAssociation = true;
} else if (internetVpnId != null && sn.getInternetVpnId() != null && sn.getInternetVpnId().getValue().matches(internetVpnId.getValue())) {
subnetVpnAssociation = true;
}
if (subnetVpnAssociation == false) {
LOG.error("Removing subnet : Subnetmap is not in VPN {}/{}, owns {} and {}", vpnId, internetVpnId, sn.getVpnId(), sn.getInternetVpnId());
return;
}
// Check if there are ports on this subnet; remove corresponding vpn-interfaces
List<Uuid> portList = sn.getPortList();
final Uuid internetId = internetVpnId;
if (portList != null) {
for (final Uuid portId : portList) {
LOG.debug("withdrawing subnet IP {} from vpn-interface {}", sn.getSubnetIp(), portId.getValue());
final Port port = neutronvpnUtils.getNeutronPort(portId);
jobCoordinator.enqueueJob("PORT-" + portId.getValue(), () -> {
WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
List<ListenableFuture<Void>> futures = new ArrayList<>();
if (port != null) {
withdrawPortIpFromVpnIface(vpnId, internetId, port, sn, wrtConfigTxn);
} else {
LOG.warn("Cannot proceed with withdrawPortIpFromVpnIface for port {} in subnet {} since " + "port is absent in Neutron config DS", portId.getValue(), subnet.getValue());
}
futures.add(wrtConfigTxn.submit());
return futures;
});
}
}
// update subnet-vpn association
removeFromSubnetNode(subnet, null, null, vpnId, null);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap in project netvirt by opendaylight.
the class NeutronvpnUtils method getRouterforVpn.
protected Uuid getRouterforVpn(Uuid vpnId) {
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(vpnId)).build();
Optional<VpnMap> optionalVpnMap = read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
if (optionalVpnMap.isPresent()) {
VpnMap vpnMap = optionalVpnMap.get();
return vpnMap.getRouterId();
}
LOG.error("getRouterforVpn: Failed as VPNMaps DS is absent for VPN {}", vpnId.getValue());
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap in project netvirt by opendaylight.
the class NeutronvpnUtils method getRouterIdfromVpnInstance.
public String getRouterIdfromVpnInstance(String vpnName) {
// returns only router, attached to IPv4 networks
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(new Uuid(vpnName))).build();
Optional<VpnMap> optionalVpnMap = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
if (!optionalVpnMap.isPresent()) {
LOG.error("getRouterIdfromVpnInstance : Router not found for vpn : {}", vpnName);
return null;
}
Uuid routerId = optionalVpnMap.get().getRouterId();
if (routerId != null) {
return routerId.getValue();
}
LOG.info("getRouterIdfromVpnInstance : Router not found for vpn : {}", vpnName);
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap in project netvirt by opendaylight.
the class NeutronvpnUtils method getVpnForNetwork.
protected Uuid getVpnForNetwork(Uuid network) {
InstanceIdentifier<VpnMaps> vpnMapsIdentifier = InstanceIdentifier.builder(VpnMaps.class).build();
Optional<VpnMaps> optionalVpnMaps = read(LogicalDatastoreType.CONFIGURATION, vpnMapsIdentifier);
if (optionalVpnMaps.isPresent() && optionalVpnMaps.get().getVpnMap() != null) {
List<VpnMap> allMaps = optionalVpnMaps.get().getVpnMap();
for (VpnMap vpnMap : allMaps) {
List<Uuid> netIds = vpnMap.getNetworkIds();
if (netIds != null && netIds.contains(network)) {
return vpnMap.getVpnId();
}
}
}
LOG.debug("getVpnForNetwork: Failed for network {} as no VPN present in VPNMaps DS", network.getValue());
return null;
}
Aggregations