use of org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice in project netvirt by opendaylight.
the class VpnUtil method getIpVersionFromString.
/**
*Get IpVersionChoice from String IP like x.x.x.x or an representation IPv6.
* @param ipAddress String of an representation IP address V4 or V6
* @return the IpVersionChoice of the version or IpVersionChoice.UNDEFINED otherwise
*/
public static IpVersionChoice getIpVersionFromString(String ipAddress) {
IpVersionChoice ipchoice = IpVersionChoice.UNDEFINED;
int indexIpAddress = ipAddress.indexOf('/');
if (indexIpAddress >= 0) {
ipAddress = ipAddress.substring(0, indexIpAddress);
}
try {
InetAddress address = InetAddress.getByName(ipAddress);
if (address instanceof Inet4Address) {
return IpVersionChoice.IPV4;
} else if (address instanceof Inet6Address) {
return IpVersionChoice.IPV6;
}
} catch (UnknownHostException | SecurityException e) {
ipchoice = IpVersionChoice.UNDEFINED;
}
return ipchoice;
}
use of org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice in project netvirt by opendaylight.
the class NeutronvpnNatManager method addExternalNetworkToRouter.
private void addExternalNetworkToRouter(Router update) {
Uuid routerId = update.getUuid();
Uuid extNetId = update.getExternalGatewayInfo().getExternalNetworkId();
List<ExternalFixedIps> externalFixedIps = update.getExternalGatewayInfo().getExternalFixedIps();
try {
Network input = neutronvpnUtils.getNeutronNetwork(extNetId);
ProviderTypes providerNwType = NeutronvpnUtils.getProviderNetworkType(input);
if (providerNwType == null) {
LOG.error("Unable to get Network Provider Type for network {}", input.getUuid().getValue());
return;
}
// Add this router to the ExtRouters list
addExternalRouter(update);
// Update External Subnets for this router
updateExternalSubnetsForRouter(routerId, extNetId, externalFixedIps);
// Create and add Networks object for this External Network to the ExternalNetworks list
InstanceIdentifier<Networks> netsIdentifier = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNetId)).build();
Optional<Networks> optionalNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
if (!optionalNets.isPresent()) {
LOG.error("External Network {} not present in the NVPN datamodel", extNetId.getValue());
return;
}
NetworksBuilder builder = new NetworksBuilder(optionalNets.get());
List<Uuid> rtrList = builder.getRouterIds();
if (rtrList == null) {
rtrList = new ArrayList<>();
}
rtrList.add(routerId);
builder.setRouterIds(rtrList);
if (NeutronvpnUtils.isFlatOrVlanNetwork(input)) {
builder.setVpnid(extNetId);
}
Networks networkss = builder.build();
// Add Networks object to the ExternalNetworks list
LOG.trace("Updating externalnetworks {}", networkss);
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier, networkss);
LOG.trace("Updated externalnetworks successfully to CONFIG Datastore");
// get vpn external form this network external to setup vpnInternet for ipv6
Uuid vpnExternal = neutronvpnUtils.getVpnForNetwork(extNetId);
if (vpnExternal == null) {
LOG.debug("addExternalNetworkToRouter : no vpnExternal for Network {}", extNetId);
}
LOG.debug("addExternalNetworkToRouter : the vpnExternal {}", vpnExternal);
// get subnetmap associate to the router, any subnetmap "external" could be existing
List<Subnetmap> snList = neutronvpnUtils.getNeutronRouterSubnetMaps(routerId);
LOG.debug("addExternalNetworkToRouter : the vpnExternal {} subnetmap to be set with vpnInternet {}", vpnExternal, snList);
for (Subnetmap sn : snList) {
if (sn.getInternetVpnId() == null) {
continue;
}
IpVersionChoice ipVers = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
if (ipVers == IpVersionChoice.IPV6) {
LOG.debug("addExternalNetworkToRouter : setup vpnInternet IPv6 for vpnExternal {} subnetmap {}", vpnExternal, sn);
nvpnManager.updateVpnInternetForSubnet(sn, vpnExternal, true);
}
}
} catch (TransactionCommitFailedException | ReadFailedException ex) {
LOG.error("Creation of externalnetworks failed for {}", extNetId.getValue(), ex);
}
}
use of org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice in project netvirt by opendaylight.
the class NeutronvpnUtils method getIpVersionChoicesFromRouterUuid.
/**
* Method to get an ipVersionChosen as IPV4 and/or IPV6 or undefined from the subnetmaps of the router.
* @param routerUuid the Uuid for which find out the IP version associated
* @return an IpVersionChoice used by the router from its attached subnetmaps. IpVersionChoice.UNDEFINED if any
*/
public IpVersionChoice getIpVersionChoicesFromRouterUuid(Uuid routerUuid) {
IpVersionChoice rep = IpVersionChoice.UNDEFINED;
if (routerUuid == null) {
return rep;
}
List<Subnetmap> subnetmapList = getNeutronRouterSubnetMaps(routerUuid);
if (subnetmapList.isEmpty()) {
return rep;
}
for (Subnetmap sn : subnetmapList) {
if (sn.getSubnetIp() != null) {
IpVersionChoice ipVers = getIpVersionFromString(sn.getSubnetIp());
if (rep.choice != ipVers.choice) {
rep = rep.addVersion(ipVers);
}
if (rep.choice == IpVersionChoice.IPV4AND6.choice) {
return rep;
}
}
}
return rep;
}
use of org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice in project netvirt by opendaylight.
the class NeutronvpnManager method createVpn.
/**
* Performs the creation of a Neutron L3VPN, associating the new VPN to the
* specified Neutron Networks and Routers.
*
* @param vpn Uuid of the VPN tp be created
* @param name Representative name of the new VPN
* @param tenant Uuid of the Tenant under which the VPN is going to be created
* @param rd Route-distinguisher for the VPN
* @param irt A list of Import Route Targets
* @param ert A list of Export Route Targets
* @param router neutron router Id to associate with created VPN
* @param networks UUID of the neutron network the VPN may be associated to
* @param type Type of the VPN Instance
* @param l3vni L3VNI for the VPN Instance using VxLAN as the underlay
* @throws Exception if association of L3VPN failed
*/
public void createVpn(Uuid vpn, String name, Uuid tenant, List<String> rd, List<String> irt, List<String> ert, Uuid router, List<Uuid> networks, VpnInstance.Type type, long l3vni) throws Exception {
IpVersionChoice ipVersChoices = IpVersionChoice.UNDEFINED;
if (router != null) {
IpVersionChoice vers = neutronvpnUtils.getIpVersionChoicesFromRouterUuid(router);
ipVersChoices = ipVersChoices.addVersion(vers);
}
updateVpnInstanceNode(vpn, rd, irt, ert, type, l3vni, ipVersChoices);
// Please note that router and networks will be filled into VPNMaps
// by subsequent calls here to associateRouterToVpn and
// associateNetworksToVpn
updateVpnMaps(vpn, name, null, tenant, null);
if (router != null) {
associateRouterToVpn(vpn, router);
}
if (networks != null) {
List<String> failStrings = associateNetworksToVpn(vpn, networks);
if (!failStrings.isEmpty()) {
LOG.error("VPN {} association to networks failed for networks: {}. ", vpn.getValue(), failStrings.toString());
throw new Exception(failStrings.toString());
}
}
}
use of org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice in project netvirt by opendaylight.
the class NeutronvpnManager method dissociateNetworksFromVpn.
/**
* Parses and disassociates networks list from given VPN.
*
* @param vpnId Uuid of given VPN.
* @param networks List list of network Ids (Uuid), which will be disassociated.
* @return list of formatted strings with detailed error messages.
*/
@Nonnull
protected List<String> dissociateNetworksFromVpn(@Nonnull Uuid vpnId, @Nonnull List<Uuid> networks) {
List<String> failedNwList = new ArrayList<>();
HashSet<Uuid> passedNwList = new HashSet<>();
if (networks.isEmpty()) {
LOG.error("dissociateNetworksFromVpn: Failed as networks list is empty");
failedNwList.add(String.format("Failed to disassociate networks from VPN %s as networks list is empty", vpnId.getValue()));
return failedNwList;
}
for (Uuid nw : networks) {
Network network = neutronvpnUtils.getNeutronNetwork(nw);
if (network == null) {
LOG.error("dissociateNetworksFromVpn: Network {} not found in ConfigDS");
failedNwList.add(String.format("Failed to disassociate network %s as is not found in ConfigDS", nw.getValue()));
continue;
}
Uuid networkVpnId = neutronvpnUtils.getVpnForNetwork(nw);
if (networkVpnId == null) {
LOG.error("dissociateNetworksFromVpn: Network {} is not associated to any VPN", nw.getValue());
failedNwList.add(String.format("Failed to disassociate network %s as is not associated to any VPN", nw.getValue()));
continue;
}
if (!vpnId.equals(networkVpnId)) {
LOG.error("dissociateNetworksFromVpn: Network {} is associated to another VPN {} instead of given {}", nw.getValue(), networkVpnId.getValue(), vpnId.getValue());
failedNwList.add(String.format("Failed to disassociate network %s as it is associated to another " + "vpn %s instead of given %s", nw.getValue(), networkVpnId.getValue(), vpnId.getValue()));
continue;
}
if (neutronvpnUtils.getIsExternal(network)) {
if (disassociateExtNetworkFromVpn(vpnId, network)) {
passedNwList.add(nw);
continue;
} else {
LOG.error("dissociateNetworksFromVpn: Failed to withdraw Provider Network {} from VPN {}", nw.getValue(), vpnId.getValue());
failedNwList.add(String.format("Failed to withdraw Provider Network %s from VPN %s", nw.getValue(), vpnId.getValue()));
continue;
}
}
List<Uuid> networkSubnets = neutronvpnUtils.getSubnetIdsFromNetworkId(nw);
if (networkSubnets == null) {
passedNwList.add(nw);
continue;
}
for (Uuid subnet : networkSubnets) {
Subnetmap sm = neutronvpnUtils.getSubnetmap(subnet);
if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sm, vpnId)) {
IpVersionChoice ipVersionsToRemove = IpVersionChoice.UNDEFINED;
IpVersionChoice ipVersion = neutronvpnUtils.getIpVersionFromString(sm.getSubnetIp());
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersionsToRemove.addVersion(ipVersion), false);
}
LOG.debug("dissociateNetworksFromVpn: Withdraw subnet {} from VPN {}", subnet.getValue(), vpnId.getValue());
removeSubnetFromVpn(vpnId, subnet, null);
passedNwList.add(nw);
}
}
LOG.info("dissociateNetworksFromVpn: Withdraw networks list {} from VPN {}", networks.toString(), vpnId.getValue());
clearFromVpnMaps(vpnId, null, new ArrayList<Uuid>(passedNwList));
return failedNwList;
}
Aggregations