use of org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6 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.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6 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.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6 in project netvirt by opendaylight.
the class NeutronvpnManager method associateExtNetworkToVpn.
private boolean associateExtNetworkToVpn(@Nonnull Uuid vpnId, @Nonnull Network extNet) {
VpnInstanceOpDataEntry vpnOpDataEntry = neutronvpnUtils.getVpnInstanceOpDataEntryFromVpnId(vpnId.getValue());
if (vpnOpDataEntry == null) {
LOG.error("associateExtNetworkToVpn: can not find VpnOpDataEntry for VPN {}", vpnId.getValue());
return false;
}
if (!addExternalNetworkToVpn(extNet, vpnId)) {
return false;
}
if (!vpnOpDataEntry.getBgpvpnType().equals(BgpvpnType.BGPVPNInternet)) {
LOG.info("associateExtNetworkToVpn: set type {} for VPN {}", BgpvpnType.BGPVPNInternet, vpnId.getValue());
neutronvpnUtils.updateVpnInstanceOpWithType(BgpvpnType.BGPVPNInternet, vpnId);
}
for (Uuid snId : neutronvpnUtils.getPrivateSubnetsToExport(extNet)) {
Subnetmap sm = neutronvpnUtils.getSubnetmap(snId);
if (sm == null) {
LOG.error("associateExtNetworkToVpn: can not find subnet with Id {} in ConfigDS", snId.getValue());
continue;
}
updateVpnInternetForSubnet(sm, vpnId, true);
if (!(vpnOpDataEntry.isIpv6Configured()) && (NeutronvpnUtils.getIpVersionFromString(sm.getSubnetIp()) == IpVersionChoice.IPV6)) {
LOG.info("associateExtNetworkToVpn: add IPv6 Internet default route in VPN {}", vpnId.getValue());
neutronvpnUtils.updateVpnInstanceWithFallback(vpnId.getValue(), true);
}
}
return true;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6 in project netvirt by opendaylight.
the class NeutronvpnManager method createPortIpAdjacencies.
protected Adjacencies createPortIpAdjacencies(Port port, Boolean isRouterInterface, WriteTransaction wrtConfigTxn, Subnetmap sn, VpnInterface vpnIface) {
List<Adjacency> adjList = new ArrayList<>();
if (vpnIface != null) {
adjList = vpnIface.getAugmentation(Adjacencies.class).getAdjacency();
}
String infName = port.getUuid().getValue();
LOG.trace("neutronVpnManager: create config adjacencies for Port: {}", infName);
for (FixedIps ip : port.getFixedIps()) {
String ipValue = String.valueOf(ip.getIpAddress().getValue());
String ipPrefix = ip.getIpAddress().getIpv4Address() != null ? ipValue + "/32" : ipValue + "/128";
if (sn != null && !FibHelper.doesPrefixBelongToSubnet(ipPrefix, sn.getSubnetIp(), false)) {
continue;
}
Adjacency vmAdj = new AdjacencyBuilder().setKey(new AdjacencyKey(ipPrefix)).setIpAddress(ipPrefix).setMacAddress(port.getMacAddress().getValue()).setAdjacencyType(AdjacencyType.PrimaryAdjacency).setSubnetId(ip.getSubnetId()).build();
if (!adjList.contains(vmAdj)) {
adjList.add(vmAdj);
}
Subnetmap snTemp = sn != null ? sn : neutronvpnUtils.getSubnetmap(ip.getSubnetId());
Uuid routerId = snTemp != null ? snTemp.getRouterId() : null;
Uuid vpnId = snTemp != null ? snTemp.getVpnId() : null;
if (vpnId != null) {
neutronvpnUtils.createVpnPortFixedIpToPort(vpnId.getValue(), ipValue, infName, port.getMacAddress().getValue(), isRouterInterface, wrtConfigTxn);
}
if (snTemp != null && snTemp.getInternetVpnId() != null) {
neutronvpnUtils.createVpnPortFixedIpToPort(sn.getInternetVpnId().getValue(), ipValue, infName, port.getMacAddress().getValue(), isRouterInterface, wrtConfigTxn);
}
if (routerId != null) {
Router rtr = neutronvpnUtils.getNeutronRouter(routerId);
if (rtr != null && rtr.getRoutes() != null) {
List<Routes> routeList = rtr.getRoutes();
// create extraroute Adjacence for each ipValue,
// because router can have IPv4 and IPv6 subnet ports, or can have
// more that one IPv4 subnet port or more than one IPv6 subnet port
List<Adjacency> erAdjList = getAdjacencyforExtraRoute(routeList, ipValue);
if (!erAdjList.isEmpty()) {
adjList.addAll(erAdjList);
}
}
}
}
return new AdjacenciesBuilder().setAdjacency(adjList).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6 in project netvirt by opendaylight.
the class NeutronPortChangeListener method handleRouterInterfaceRemoved.
private void handleRouterInterfaceRemoved(Port routerPort) {
if (routerPort.getDeviceId() != null) {
Uuid routerId = new Uuid(routerPort.getDeviceId());
Uuid infNetworkId = routerPort.getNetworkId();
elanService.removeKnownL3DmacAddress(routerPort.getMacAddress().getValue(), infNetworkId.getValue());
Uuid vpnId = neutronvpnUtils.getVpnForRouter(routerId, true);
if (vpnId == null) {
vpnId = routerId;
}
List<FixedIps> portIps = routerPort.getFixedIps();
boolean vpnInstanceInternetIpVersionRemoved = false;
Uuid vpnInstanceInternetUuid = null;
for (FixedIps portIP : portIps) {
// Internet VPN : flush InternetVPN first
Uuid subnetId = portIP.getSubnetId();
Subnetmap sn = neutronvpnUtils.getSubnetmap(subnetId);
if (sn != null && sn.getInternetVpnId() != null) {
if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, sn.getInternetVpnId())) {
vpnInstanceInternetIpVersionRemoved = true;
vpnInstanceInternetUuid = sn.getInternetVpnId();
}
nvpnManager.updateVpnInternetForSubnet(sn, sn.getInternetVpnId(), false);
}
}
/* Remove ping responder for router interfaces
* A router interface reference in a VPN will have to be removed before the host interface references
* for that subnet in the VPN are removed. This is to ensure that the FIB Entry of the router interface
* is not the last entry to be removed for that subnet in the VPN.
* If router interface FIB entry is the last to be removed for a subnet in a VPN , then all the host
* interface references in the vpn will already have been cleared, which will cause failures in
* cleanup of router interface flows*/
nvpnManager.deleteVpnInterface(routerPort.getUuid().getValue(), null, /* vpn-id */
null);
// update RouterInterfaces map
WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
boolean vpnInstanceIpVersionRemoved = false;
IpVersionChoice vpnInstanceIpVersionToRemove = IpVersionChoice.UNDEFINED;
for (FixedIps portIP : portIps) {
Subnetmap sn = neutronvpnUtils.getSubnetmap(portIP.getSubnetId());
// router Port have either IPv4 or IPv6, never both
if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, vpnId)) {
vpnInstanceIpVersionRemoved = true;
vpnInstanceIpVersionToRemove = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
}
String ipValue = String.valueOf(portIP.getIpAddress().getValue());
neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipValue, wrtConfigTxn);
// NOTE: Please donot change the order of calls to removeSubnetFromVpn and
// and updateSubnetNodeWithFixedIP
nvpnManager.removeSubnetFromVpn(vpnId, portIP.getSubnetId(), sn != null ? sn.getInternetVpnId() : null);
nvpnManager.updateSubnetNodeWithFixedIp(portIP.getSubnetId(), null, null, null, null, null);
}
nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, routerPort.getUuid().getValue());
deleteElanInterface(routerPort.getUuid().getValue(), wrtConfigTxn);
deleteOfPortInterface(routerPort, wrtConfigTxn);
wrtConfigTxn.submit();
nvpnNatManager.handleSubnetsForExternalRouter(routerId);
if (vpnInstanceIpVersionRemoved) {
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), vpnInstanceIpVersionToRemove, false);
}
if (vpnInstanceInternetIpVersionRemoved) {
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnInstanceInternetUuid.getValue(), IpVersionChoice.IPV6, false);
neutronvpnUtils.updateVpnInstanceWithFallback(vpnInstanceInternetUuid.getValue(), false);
}
}
}
Aggregations