use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet in project netvirt by opendaylight.
the class NeutronvpnManager method addSubnetToVpn.
protected void addSubnetToVpn(@Nullable final Uuid vpnId, Uuid subnet, @Nullable final Uuid internetVpnId) {
LOG.debug("addSubnetToVpn: Adding subnet {} to vpn {}", subnet.getValue(), vpnId != null ? vpnId.getValue() : internetVpnId.getValue());
Subnetmap sn = updateSubnetNode(subnet, null, vpnId, internetVpnId);
if (sn == null) {
LOG.error("addSubnetToVpn: subnetmap is null, cannot add subnet {} to VPN {}", subnet.getValue(), vpnId != null ? vpnId.getValue() : internetVpnId.getValue());
return;
}
if (vpnId != null) {
VpnMap vpnMap = neutronvpnUtils.getVpnMap(vpnId);
if (vpnMap == null) {
LOG.error("addSubnetToVpn: No vpnMap for vpnId {}," + " cannot add subnet {} to VPN", vpnId.getValue(), subnet.getValue());
return;
}
final VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpnId.getValue());
LOG.debug("addSubnetToVpn: VpnInstance {}", vpnInstance.toString());
if (isVpnOfTypeL2(vpnInstance)) {
neutronEvpnUtils.updateElanAndVpn(vpnInstance, sn.getNetworkId().getValue(), NeutronEvpnUtils.Operation.ADD);
}
}
if (internetVpnId != null) {
VpnMap vpnMap = neutronvpnUtils.getVpnMap(internetVpnId);
if (vpnMap == null) {
LOG.error("addSubnetToVpn: No vpnMap for InternetVpnId {}, cannot add " + "subnet {} to VPN", internetVpnId.getValue(), subnet.getValue());
return;
}
}
final Uuid internetId = internetVpnId;
// Check if there are ports on this subnet and add corresponding vpn-interfaces
List<Uuid> portList = sn.getPortList();
if (portList != null) {
for (final Uuid portId : portList) {
String vpnInfName = portId.getValue();
VpnInterface vpnIface = VpnHelper.getVpnInterface(dataBroker, vpnInfName);
Port port = neutronvpnUtils.getNeutronPort(portId);
if (port == null) {
LOG.error("addSubnetToVpn: Cannot proceed with addSubnetToVpn for port {} in subnet {} " + "since port is absent in Neutron config DS", portId.getValue(), subnet.getValue());
continue;
}
final Boolean isRouterInterface = port.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF) ? true : false;
jobCoordinator.enqueueJob("PORT-" + portId.getValue(), () -> singletonList(managedNewTransactionRunner.callWithNewWriteOnlyTransactionAndSubmit(wrtConfigTxn -> {
Adjacencies portAdj = createPortIpAdjacencies(port, isRouterInterface, wrtConfigTxn, sn, vpnIface);
if (vpnIface == null) {
LOG.trace("addSubnetToVpn: create new VpnInterface for Port {}", vpnInfName);
Set<Uuid> listVpn = new HashSet<Uuid>();
if (vpnId != null) {
listVpn.add(vpnId);
}
if (internetId != null) {
listVpn.add(internetId);
}
writeVpnInterfaceToDs(listVpn, vpnInfName, portAdj, isRouterInterface, wrtConfigTxn);
if (sn.getRouterId() != null) {
addToNeutronRouterInterfacesMap(sn.getRouterId(), portId.getValue());
}
} else {
LOG.trace("update VpnInterface for Port {} with adj {}", vpnInfName, portAdj);
if (vpnId != null) {
updateVpnInterfaceWithAdjacencies(vpnId, vpnInfName, portAdj, wrtConfigTxn);
}
if (internetId != null) {
updateVpnInterfaceWithAdjacencies(internetId, vpnInfName, portAdj, wrtConfigTxn);
}
}
})));
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet in project netvirt by opendaylight.
the class NeutronvpnManager method associateNetworksToVpn.
/**
* Parses and associates networks list with given VPN.
*
* @param vpnId Uuid of given VPN.
* @param networks List list of network Ids (Uuid), which will be associated.
* @return list of formatted strings with detailed error messages.
*/
@Nonnull
protected List<String> associateNetworksToVpn(@Nonnull Uuid vpnId, @Nonnull List<Uuid> networks) {
List<String> failedNwList = new ArrayList<>();
HashSet<Uuid> passedNwList = new HashSet<>();
if (networks.isEmpty()) {
LOG.error("associateNetworksToVpn: Failed as given networks list is empty, VPN Id: {}", vpnId.getValue());
failedNwList.add(String.format("Failed to associate networks with VPN %s as given networks list is empty", vpnId.getValue()));
return failedNwList;
}
VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpnId.getValue());
if (vpnInstance == null) {
LOG.error("associateNetworksToVpn: Can not find vpnInstance for VPN {} in ConfigDS", vpnId.getValue());
failedNwList.add(String.format("Failed to associate network: can not found vpnInstance for VPN %s " + "in ConfigDS", vpnId.getValue()));
return failedNwList;
}
try {
if (isVpnOfTypeL2(vpnInstance) && neutronEvpnUtils.isVpnAssociatedWithNetwork(vpnInstance)) {
LOG.error("associateNetworksToVpn: EVPN {} supports only one network to be associated with", vpnId.getValue());
failedNwList.add(String.format("Failed to associate network: EVPN %s supports only one network to be " + "associated with", vpnId.getValue()));
return failedNwList;
}
for (Uuid nw : networks) {
Network network = neutronvpnUtils.getNeutronNetwork(nw);
if (network == null) {
LOG.error("associateNetworksToVpn: Network {} not found in ConfigDS", nw.getValue());
failedNwList.add(String.format("Failed to associate network: network %s not found in ConfigDS", nw.getValue()));
continue;
}
NetworkProviderExtension providerExtension = network.getAugmentation(NetworkProviderExtension.class);
if (providerExtension.getSegments() != null && providerExtension.getSegments().size() > 1) {
LOG.error("associateNetworksToVpn: MultiSegmented network {} not supported in BGPVPN {}", nw.getValue(), vpnId.getValue());
failedNwList.add(String.format("Failed to associate multisegmented network %s with BGPVPN %s", nw.getValue(), vpnId.getValue()));
continue;
}
Uuid networkVpnId = neutronvpnUtils.getVpnForNetwork(nw);
if (networkVpnId != null) {
LOG.error("associateNetworksToVpn: Network {} already associated with another VPN {}", nw.getValue(), networkVpnId.getValue());
failedNwList.add(String.format("Failed to associate network %s as it is already associated to " + "another VPN %s", nw.getValue(), networkVpnId.getValue()));
continue;
}
if (neutronvpnUtils.getIsExternal(network)) {
if (associateExtNetworkToVpn(vpnId, network)) {
passedNwList.add(nw);
continue;
} else {
LOG.error("associateNetworksToVpn: Failed to associate Provider Network {} with VPN {}", nw.getValue(), vpnId.getValue());
failedNwList.add(String.format("Failed to associate Provider Network %s with VPN %s", nw.getValue(), vpnId.getValue()));
continue;
}
}
List<Uuid> networkSubnets = neutronvpnUtils.getSubnetIdsFromNetworkId(nw);
if (networkSubnets == null) {
passedNwList.add(nw);
continue;
}
for (Uuid subnet : networkSubnets) {
Uuid subnetVpnId = neutronvpnUtils.getVpnForSubnet(subnet);
if (subnetVpnId != null) {
LOG.error("associateNetworksToVpn: Failed to associate subnet {} with VPN {} as it is already " + "associated", subnet.getValue(), subnetVpnId.getValue());
failedNwList.add(String.format("Failed to associate subnet %s with VPN %s as it is already " + "associated", subnet.getValue(), vpnId.getValue()));
continue;
}
Subnetmap sm = neutronvpnUtils.getSubnetmap(subnet);
if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToAdd(sm, vpnId)) {
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), NeutronvpnUtils.getIpVersionFromString(sm.getSubnetIp()), true);
}
LOG.debug("associateNetworksToVpn: Add subnet {} to VPN {}", subnet.getValue(), vpnId.getValue());
addSubnetToVpn(vpnId, subnet, null);
passedNwList.add(nw);
}
}
} catch (ReadFailedException e) {
LOG.error("associateNetworksToVpn: Failed to associate VPN {} with networks {}: ", vpnId.getValue(), networks, e);
failedNwList.add(String.format("Failed to associate VPN %s with networks %s: %s", vpnId.getValue(), networks, e));
}
LOG.info("associateNetworksToVpn: update VPN {} with networks list: {}", vpnId.getValue(), passedNwList.toString());
updateVpnMaps(vpnId, null, null, null, new ArrayList<Uuid>(passedNwList));
return failedNwList;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnForSubnet.
private Subnetmap updateVpnForSubnet(Uuid oldVpnId, Uuid newVpnId, Uuid subnet, boolean isBeingAssociated) {
LOG.debug("Moving subnet {} from oldVpn {} to newVpn {} ", subnet.getValue(), oldVpnId.getValue(), newVpnId.getValue());
Uuid networkUuid = neutronvpnUtils.getSubnetmap(subnet).getNetworkId();
Network network = neutronvpnUtils.getNeutronNetwork(networkUuid);
boolean netIsExternal = NeutronvpnUtils.getIsExternal(network);
Uuid vpnExtUuid = netIsExternal ? null : neutronvpnUtils.getInternetvpnUuidBoundToSubnetRouter(subnet);
Subnetmap sn = updateSubnetNode(subnet, null, newVpnId, vpnExtUuid);
if (sn == null) {
LOG.error("Updating subnet {} with newVpn {} failed", subnet.getValue(), newVpnId.getValue());
return sn;
}
// CAUTION: Please DONOT make the router interface VPN Movement as an asynchronous commit again !
try {
WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
updateVpnInterface(newVpnId, oldVpnId, neutronvpnUtils.getNeutronPort(sn.getRouterInterfacePortId()), isBeingAssociated, true, wrtConfigTxn);
wrtConfigTxn.submit().checkedGet();
} catch (TransactionCommitFailedException e) {
LOG.error("Failed to update router interface {} in subnet {} from oldVpnId {} to newVpnId {}, returning", sn.getRouterInterfacePortId().getValue(), subnet.getValue(), oldVpnId, newVpnId);
return sn;
}
// Check for ports on this subnet and update association of
// corresponding vpn-interfaces to external vpn
List<Uuid> portList = sn.getPortList();
if (portList != null) {
for (Uuid port : portList) {
LOG.debug("Updating vpn-interface for port {} isBeingAssociated {}", port.getValue(), isBeingAssociated);
jobCoordinator.enqueueJob("PORT-" + port.getValue(), () -> {
WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
List<ListenableFuture<Void>> futures = new ArrayList<>();
updateVpnInterface(newVpnId, oldVpnId, neutronvpnUtils.getNeutronPort(port), isBeingAssociated, false, wrtConfigTxn);
futures.add(wrtConfigTxn.submit());
return futures;
});
}
}
return sn;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet 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.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet 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();
}
Aggregations