use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap 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.subnetmaps.Subnetmap in project netvirt by opendaylight.
the class NeutronvpnManager method createSubnetmapNode.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void createSubnetmapNode(Uuid subnetId, String subnetIp, Uuid tenantId, Uuid networkId, NetworkAttributes.NetworkType networkType, long segmentationId) {
try {
InstanceIdentifier<Subnetmap> subnetMapIdentifier = NeutronvpnUtils.buildSubnetMapIdentifier(subnetId);
synchronized (subnetId.getValue().intern()) {
LOG.info("createSubnetmapNode: subnet ID {}", subnetId.toString());
Optional<Subnetmap> sn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetMapIdentifier);
if (sn.isPresent()) {
LOG.error("createSubnetmapNode: Subnetmap node for subnet ID {} already exists, returning", subnetId.getValue());
return;
}
SubnetmapBuilder subnetmapBuilder = new SubnetmapBuilder().setKey(new SubnetmapKey(subnetId)).setId(subnetId).setSubnetIp(subnetIp).setTenantId(tenantId).setNetworkId(networkId).setNetworkType(networkType).setSegmentationId(segmentationId);
LOG.debug("createSubnetmapNode: Adding a new subnet node in Subnetmaps DS for subnet {}", subnetId.getValue());
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetMapIdentifier, subnetmapBuilder.build());
}
} catch (TransactionCommitFailedException | ReadFailedException e) {
LOG.error("createSubnetmapNode: Creating subnetmap node failed for subnet {}", subnetId.getValue());
}
// check if there are ports to update for already created Subnetmap node
LOG.debug("createSubnetmapNode: Update created Subnetmap for subnet {} with ports", subnetId.getValue());
for (Map.Entry<Uuid, Uuid> entry : unprocessedPortsMap.entrySet()) {
if (entry.getValue().getValue().equals(subnetId.getValue())) {
updateSubnetmapNodeWithPorts(subnetId, entry.getKey(), null);
unprocessedPortsMap.remove(entry.getKey());
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.
the class NeutronvpnNatManager method removeExternalNetworkFromRouter.
public void removeExternalNetworkFromRouter(Uuid origExtNetId, Router update, List<ExternalFixedIps> origExtFixedIps) {
Uuid routerId = update.getUuid();
// Remove the router to the ExtRouters list
removeExternalRouter(update);
// Remove router entry from floating-ip-info list
removeRouterFromFloatingIpInfo(update, dataBroker);
// Remove the router from External Subnets
removeRouterFromExternalSubnets(routerId, origExtNetId, origExtFixedIps);
// Remove the router from the ExternalNetworks list
InstanceIdentifier<Networks> netsIdentifier = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(origExtNetId)).build();
Optional<Networks> optionalNets = null;
try {
optionalNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
} catch (ReadFailedException ex) {
LOG.error("removeExternalNetworkFromRouter: Failed to remove provider network {} from router {}", origExtNetId.getValue(), routerId.getValue(), ex);
return;
}
if (!optionalNets.isPresent()) {
LOG.error("removeExternalNetworkFromRouter: Provider Network {} not present in the NVPN datamodel", origExtNetId.getValue());
return;
}
Networks nets = optionalNets.get();
try {
NetworksBuilder builder = new NetworksBuilder(nets);
List<Uuid> rtrList = builder.getRouterIds();
if (rtrList != null) {
rtrList.remove(routerId);
builder.setRouterIds(rtrList);
Networks networkss = builder.build();
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier, networkss);
LOG.trace("removeExternalNetworkFromRouter: Remove router {} from External Networks node {}", routerId, origExtNetId.getValue());
}
} catch (TransactionCommitFailedException ex) {
LOG.error("removeExternalNetworkFromRouter: Failed to remove provider network {} from router {}", origExtNetId.getValue(), routerId.getValue(), ex);
}
// Remove the vpnInternetId fromSubnetmap
Network net = neutronvpnUtils.getNeutronNetwork(nets.getId());
List<Uuid> submapIds = neutronvpnUtils.getPrivateSubnetsToExport(net);
for (Uuid snId : submapIds) {
Subnetmap subnetMap = neutronvpnUtils.getSubnetmap(snId);
if ((subnetMap == null) || (subnetMap.getInternetVpnId() == null)) {
LOG.error("removeExternalNetworkFromRouter: Can not find Subnetmap for SubnetId {} in ConfigDS", snId.getValue());
continue;
}
LOG.trace("removeExternalNetworkFromRouter: Remove Internet VPN Id {} from SubnetMap {}", subnetMap.getInternetVpnId(), subnetMap.getId());
IpVersionChoice ipVers = NeutronvpnUtils.getIpVersionFromString(subnetMap.getSubnetIp());
if (ipVers == IpVersionChoice.IPV6) {
nvpnManager.updateVpnInternetForSubnet(subnetMap, subnetMap.getInternetVpnId(), false);
LOG.debug("removeExternalNetworkFromRouter: Withdraw IPv6 routes from VPN {}", subnetMap.getInternetVpnId());
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.
the class NeutronvpnUtils method getPrivateSubnetsToExport.
/**
* Get a list of Private Subnetmap Ids from router to export then its prefixes in Internet VPN.
* @param extNet Provider Network, which has a port attached as external network gateway to router
* @return a list of Private Subnetmap Ids of the router with external network gateway
*/
@Nonnull
public List<Uuid> getPrivateSubnetsToExport(@Nonnull Network extNet) {
List<Uuid> subList = new ArrayList<>();
Uuid extNetVpnId = getVpnForNetwork(extNet.getUuid());
if (extNetVpnId == null) {
return subList;
}
Router router = getNeutronRouter(getRouterforVpn(extNetVpnId));
ExternalGatewayInfo info = router.getExternalGatewayInfo();
if (info == null) {
LOG.error("getPrivateSubnetsToExport: can not get info about external gateway for router {}", router.getUuid().getValue());
return subList;
}
// check that router really has given provider network as its external gateway port
if (!extNet.getUuid().equals(info.getExternalNetworkId())) {
LOG.error("getPrivateSubnetsToExport: router {} is not attached to given provider network {}", router.getUuid().getValue(), extNet.getUuid().getValue());
return subList;
}
return getSubnetsforVpn(router.getUuid());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.
the class NeutronvpnUtils method getNeutronRouterSubnetIds.
@Nonnull
protected List<Uuid> getNeutronRouterSubnetIds(Uuid routerId) {
LOG.debug("getNeutronRouterSubnetIds for {}", routerId.getValue());
List<Uuid> subnetIdList = new ArrayList<>();
Optional<Subnetmaps> subnetMaps = read(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(Subnetmaps.class).build());
if (subnetMaps.isPresent() && subnetMaps.get().getSubnetmap() != null) {
for (Subnetmap subnetmap : subnetMaps.get().getSubnetmap()) {
if (routerId.equals(subnetmap.getRouterId())) {
subnetIdList.add(subnetmap.getId());
}
}
}
LOG.debug("getNeutronRouterSubnetIds returns {}", subnetIdList);
return subnetIdList;
}
Aggregations