use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.
the class VpnSubnetRouteHandler method onSubnetAddedToVpn.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void onSubnetAddedToVpn(Subnetmap subnetmap, boolean isBgpVpn, Long elanTag) {
Uuid subnetId = subnetmap.getId();
String subnetIp = subnetmap.getSubnetIp();
SubnetOpDataEntry subOpEntry = null;
SubnetOpDataEntryBuilder subOpBuilder = null;
InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = null;
Optional<SubnetOpDataEntry> optionalSubs = null;
Uint32 label;
requireNonNull(subnetId, LOGGING_PREFIX + " onSubnetAddedToVpn: SubnetId cannot be null or empty!");
requireNonNull(subnetIp, LOGGING_PREFIX + " onSubnetAddedToVpn: SubnetPrefix cannot be null or empty!");
requireNonNull(elanTag, LOGGING_PREFIX + " onSubnetAddedToVpn: ElanTag cannot be null or empty!");
if (subnetmap.getVpnId() == null) {
LOG.error("onSubnetAddedToVpn: VpnId {} for subnet {} not found, bailing out", subnetmap.getVpnId(), subnetId);
return;
}
String vpnName = subnetmap.getVpnId().getValue();
Uint32 vpnId = waitAndGetVpnIdIfInvalid(vpnName);
if (VpnConstants.INVALID_ID.equals(vpnId)) {
LOG.error("{} onSubnetAddedToVpn: VpnInstance to VPNId mapping not yet available for VpnName {} " + "processing subnet {} with IP {}, bailing out now.", LOGGING_PREFIX, vpnName, subnetId, subnetIp);
return;
}
String primaryRd = vpnUtil.getPrimaryRd(vpnName);
VpnInstanceOpDataEntry vpnInstanceOpData = waitAndGetVpnInstanceOpDataIfNull(vpnName, primaryRd);
if (vpnInstanceOpData == null) {
LOG.error("{} onSubnetAddedToVpn: VpnInstanceOpData not yet available for VpnName {} " + "processing subnet {} with IP {}, bailing out now.", LOGGING_PREFIX, vpnName, subnetId, subnetIp);
return;
}
LOG.info("{} onSubnetAddedToVpn: Subnet {} with IP {} being added to vpn {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName);
// TODO(vivek): Change this to use more granularized lock at subnetId level
try {
vpnUtil.lockSubnet(subnetId.getValue());
if (isBgpVpn) {
InstanceIdentifier<Networks> netsIdentifier = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(subnetmap.getNetworkId())).build();
Optional<Networks> optionalNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
if (optionalNets.isPresent()) {
LOG.info("{} onSubnetAddedToVpn: subnet {} with IP {} is an external subnet on external " + "network {}, so ignoring this for SubnetRoute on vpn {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, subnetmap.getNetworkId().getValue(), vpnName);
return;
}
}
// Create and add SubnetOpDataEntry object for this subnet to the SubnetOpData container
subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
optionalSubs = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
if (optionalSubs.isPresent()) {
LOG.error("{} onSubnetAddedToVpn: SubnetOpDataEntry for subnet {} with ip {} and vpn {} already" + " detected to be present", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName);
return;
}
LOG.debug("{} onSubnetAddedToVpn: Creating new SubnetOpDataEntry node for subnet {} subnetIp {} " + "vpn {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName);
subOpBuilder = new SubnetOpDataEntryBuilder().withKey(new SubnetOpDataEntryKey(subnetId));
subOpBuilder.setSubnetId(subnetId);
subOpBuilder.setSubnetCidr(subnetIp);
if (isBgpVpn && !VpnUtil.isBgpVpn(vpnName, primaryRd)) {
LOG.error("{} onSubnetAddedToVpn: The VPN Instance name {} does not have RD. Bailing out for" + " subnet {} subnetIp {} ", LOGGING_PREFIX, vpnName, subnetId.getValue(), subnetIp);
return;
}
// Allocate MPLS label for subnet-route at the time SubnetOpDataEntry creation
label = vpnUtil.getUniqueId(VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(primaryRd, subnetIp));
if (label == VpnConstants.INVALID_ID) {
LOG.error("onSubnetAddedToVpn: Unable to retrieve label for rd {}, subnetIp {}", primaryRd, subnetIp);
return;
}
subOpBuilder.setVrfId(primaryRd);
subOpBuilder.setVpnName(vpnName);
subOpBuilder.setSubnetToDpn(new ArrayList<>());
subOpBuilder.setRouteAdvState(TaskState.Idle);
subOpBuilder.setElanTag(elanTag);
subOpBuilder.setLabel(label);
Long l3Vni = vpnInstanceOpData.getL3vni() != null ? vpnInstanceOpData.getL3vni().toJava() : 0L;
subOpBuilder.setL3vni(l3Vni);
subOpEntry = subOpBuilder.build();
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier, subOpEntry, VpnUtil.SINGLE_TRANSACTION_BROKER_NO_RETRY);
LOG.info("{} onSubnetAddedToVpn: Added subnetopdataentry to OP Datastore for subnet {}", LOGGING_PREFIX, subnetId.getValue());
} catch (TransactionCommitFailedException e) {
LOG.error("{} Creation of SubnetOpDataEntry for subnet {} failed ", LOGGING_PREFIX, subnetId.getValue(), e);
// The second part of this method depends on subnetmap being non-null so fail fast here.
return;
} catch (RuntimeException e) {
// TODO: Avoid this
LOG.error("{} onSubnetAddedToVpn: Unable to handle subnet {} with ip {} added to vpn {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, e);
return;
} catch (InterruptedException | ExecutionException e) {
LOG.error("{} onSubnetAddedToVpn: Failed to read data store for subnet {} ip {} vpn {}", LOGGING_PREFIX, subnetId, subnetIp, vpnName);
return;
} finally {
vpnUtil.unlockSubnet(subnetId.getValue());
}
try {
// In second critical section , Port-Op-Data will be updated.
vpnUtil.lockSubnet(subnetId.getValue());
Uint64 dpnId = null;
SubnetToDpn subDpn = null;
Map<Uint64, SubnetToDpn> subDpnMap = new HashMap<>();
optionalSubs = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
subOpBuilder = new SubnetOpDataEntryBuilder(optionalSubs.get()).withKey(new SubnetOpDataEntryKey(subnetId));
List<Uuid> portList = subnetmap.getPortList();
if (portList != null) {
for (Uuid port : portList) {
Interface intfState = InterfaceUtils.getInterfaceStateFromOperDS(dataBroker, port.getValue());
if (intfState != null) {
try {
dpnId = InterfaceUtils.getDpIdFromInterface(intfState);
} catch (Exception e) {
LOG.error("{} onSubnetAddedToVpn: Unable to obtain dpnId for interface {}," + " subnetroute inclusion for this interface for subnet {} subnetIp {} " + "vpn {} failed with exception", LOGGING_PREFIX, port.getValue(), subnetId.getValue(), subnetIp, vpnName, e);
continue;
}
if (dpnId.equals(Uint64.ZERO)) {
LOG.error("{} onSubnetAddedToVpn: Port {} is not assigned DPN yet," + " ignoring subnet {} subnetIP {} vpn {}", LOGGING_PREFIX, port.getValue(), subnetId.getValue(), subnetIp, vpnName);
continue;
}
subOpDpnManager.addPortOpDataEntry(port.getValue(), subnetId, dpnId);
if (intfState.getOperStatus() != OperStatus.Up) {
LOG.error("{} onSubnetAddedToVpn: Port {} is not UP yet, ignoring subnet {}" + " subnetIp {} vpn {}", LOGGING_PREFIX, port.getValue(), subnetId.getValue(), subnetIp, vpnName);
continue;
}
subDpn = subOpDpnManager.addInterfaceToDpn(subnetId, dpnId, port.getValue());
if (intfState.getOperStatus() == OperStatus.Up) {
// port is UP
subDpnMap.put(dpnId, subDpn);
}
} else {
subOpDpnManager.addPortOpDataEntry(port.getValue(), subnetId, null);
}
}
if (subDpnMap.size() > 0) {
subOpBuilder.setSubnetToDpn(new ArrayList<>(subDpnMap.values()));
}
}
electNewDpnForSubnetRoute(subOpBuilder, null, /* oldDpnId */
subnetId, subnetmap.getNetworkId(), isBgpVpn, label);
subOpEntry = subOpBuilder.build();
SingleTransactionDataBroker.syncUpdate(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier, subOpEntry, VpnUtil.SINGLE_TRANSACTION_BROKER_NO_RETRY);
LOG.info("{} onSubnetAddedToVpn: Added PortOpDataEntry and VpnInterfaces to SubnetOpData" + " for subnet {} subnetIp {} vpn {} TaskState {} lastTaskState {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, subOpEntry.getRouteAdvState(), subOpEntry.getLastAdvState());
} catch (RuntimeException e) {
LOG.error("{} onSubnetAddedToVpn: Unable to handle subnet {} with ip {} added to vpn {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, e);
} catch (InterruptedException | ExecutionException e) {
LOG.error("{} onSubnetAddedToVpn: Failed to read data store for subnet {} ip {} vpn {}", LOGGING_PREFIX, subnetId, subnetIp, vpnName);
} catch (TransactionCommitFailedException ex) {
LOG.error("{} onSubnetAddedToVpn: Creation of SubnetOpDataEntry for subnet {} subnetIp {} vpn {} failed", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, ex);
} finally {
vpnUtil.unlockSubnet(subnetId.getValue());
}
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks 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 vpnId Uuid of the VPN tp be created
* @param name Representative name of the new VPN
* @param tenantId Uuid of the Tenant under which the VPN is going to be created
* @param rdList Route-distinguisher for the VPN
* @param irtList A list of Import Route Targets
* @param ertList A list of Export Route Targets
* @param routerIdsList ist of neutron router Id to associate with created VPN
* @param networkList UUID of the neutron network the VPN may be associated to
* @param isL2Vpn True if VPN Instance is of type L2, false if L3
* @param l3vni L3VNI for the VPN Instance using VxLAN as the underlay
* @throws Exception if association of L3VPN failed
*/
public void createVpn(Uuid vpnId, String name, Uuid tenantId, List<String> rdList, List<String> irtList, List<String> ertList, @Nullable List<Uuid> routerIdsList, @Nullable List<Uuid> networkList, boolean isL2Vpn, long l3vni) throws Exception {
IpVersionChoice ipVersChoices = IpVersionChoice.UNDEFINED;
if (routerIdsList != null && !routerIdsList.isEmpty()) {
for (Uuid routerId : routerIdsList) {
IpVersionChoice vers = neutronvpnUtils.getIpVersionChoicesFromRouterUuid(routerId);
ipVersChoices = ipVersChoices.addVersion(vers);
}
}
updateVpnInstanceNode(vpnId, rdList, irtList, ertList, isL2Vpn, l3vni, ipVersChoices);
// Please note that router and networks will be filled into VPNMaps
// by subsequent calls here to associateRouterToVpn and
// associateNetworksToVpn
updateVpnMaps(vpnId, name, null, tenantId, null);
LOG.debug("Created L3VPN with ID {}, name {}, tenantID {}, RDList {}, iRTList {}, eRTList{}, routerIdsList {}, " + "networkList {}", vpnId.getValue(), name, tenantId, rdList, irtList, ertList, routerIdsList, networkList);
if (routerIdsList != null && !routerIdsList.isEmpty()) {
for (Uuid routerId : routerIdsList) {
associateRouterToVpn(vpnId, routerId);
}
}
if (networkList != null) {
List<String> failStrings = associateNetworksToVpn(vpnId, networkList);
if (!failStrings.isEmpty()) {
LOG.error("VPN {} association to networks failed for networks: {}. ", vpnId.getValue(), failStrings);
throw new Exception(failStrings.toString());
}
}
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.
the class NeutronvpnManager method removeExternalNetworkFromVpn.
private boolean removeExternalNetworkFromVpn(Network extNet) {
Uuid extNetId = extNet.getUuid();
InstanceIdentifier<Networks> extNetsId = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNetId)).build();
try {
Optional<Networks> optionalNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, extNetsId);
NetworksBuilder builder = null;
if (optionalNets.isPresent()) {
builder = new NetworksBuilder(optionalNets.get());
} else {
LOG.error("removeExternalNetworkFromVpn: Provider Network {} is not present in the ConfigDS", extNetId.getValue());
return false;
}
builder.setVpnid(null);
Networks networks = builder.build();
LOG.info("removeExternalNetworkFromVpn: Withdraw VPN Id from Provider Network {} node", extNetId.getValue());
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, extNetsId, networks);
return true;
} catch (TransactionCommitFailedException | ExecutionException | InterruptedException ex) {
LOG.error("removeExternalNetworkFromVpn: Failed to withdraw VPN Id from Provider Network node {}: ", extNetId.getValue(), ex);
}
return false;
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.
the class NeutronvpnNatManager method addExternalNetworkToRouter.
private void addExternalNetworkToRouter(Router update) {
Uuid routerId = update.getUuid();
Uuid extNetId = update.getExternalGatewayInfo().getExternalNetworkId();
Map<ExternalFixedIpsKey, ExternalFixedIps> keyExternalFixedIpsMap = update.getExternalGatewayInfo().nonnullExternalFixedIps();
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, new ArrayList<ExternalFixedIps>(keyExternalFixedIpsMap.values()));
// 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() != null && !builder.getRouterIds().isEmpty()) ? new ArrayList<>(builder.getRouterIds()) : 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");
} catch (TransactionCommitFailedException | ExecutionException | InterruptedException ex) {
LOG.error("Creation of externalnetworks failed for {}", extNetId.getValue(), ex);
}
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks 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 networkList 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> networkList) {
List<String> failedNwList = new ArrayList<>();
HashSet<Uuid> passedNwList = new HashSet<>();
ConcurrentMap<Uuid, Network> extNwMap = new ConcurrentHashMap<>();
IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
if (networkList.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 : networkList) {
List<Uuid> networkSubnets = neutronvpnUtils.getSubnetIdsFromNetworkId(nw);
if (networkSubnets == null) {
passedNwList.add(nw);
continue;
}
Network network = neutronvpnUtils.getNeutronNetwork(nw);
if (network == null) {
LOG.error("dissociateNetworksFromVpn: Network {} not found in ConfigDS", nw.getValue());
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;
}
/* Handle disassociation of external network(s) from Internet BGP-VPN use case outside of the
* networkList iteration
*/
if (neutronvpnUtils.getIsExternal(network)) {
extNwMap.put(nw, network);
// Handle external-Nw to BGPVPN Disassociation and still ext-router is being set with external-Nw
List<Uuid> routerList = neutronvpnUtils.getRouterIdsForExtNetwork(nw);
if (!routerList.isEmpty()) {
for (Uuid routerId : routerList) {
// If v6 subnet was already added to router means it requires IPv6 AddrFamily in VpnInstance
if (neutronvpnUtils.isV6SubnetPartOfRouter(routerId)) {
ipVersion = ipVersion.addVersion(IpVersionChoice.IPV6);
LOG.debug("dissociateNetworksFromVpn: External network {} is still associated with " + "router(router-gw) {} and V6 subnet is part of that router. Hence Set IPv6 " + "address family type in Internet VPN Instance {}", network, routerId, vpnId);
break;
}
}
}
}
for (Uuid subnet : networkSubnets) {
Subnetmap subnetmap = neutronvpnUtils.getSubnetmap(subnet);
if (subnetmap == null) {
failedNwList.add(String.format("subnetmap %s not found for network %s", subnet.getValue(), nw.getValue()));
LOG.error("dissociateNetworksFromVpn: Subnetmap for subnet {} not found when " + "dissociating network {} from VPN {}", subnet.getValue(), nw.getValue(), vpnId.getValue());
continue;
}
IpVersionChoice ipVers = NeutronvpnUtils.getIpVersionFromString(subnetmap.getSubnetIp());
if (!ipVersion.isIpVersionChosen(ipVers)) {
ipVersion = ipVersion.addVersion(ipVers);
}
if (!NeutronvpnUtils.getIsExternal(network)) {
LOG.debug("dissociateNetworksFromVpn: Withdraw subnet {} from VPN {}", subnet.getValue(), vpnId.getValue());
removeSubnetFromVpn(vpnId, subnetmap, null);
Set<VpnTarget> routeTargets = vpnManager.getRtListForVpn(vpnId.getValue());
vpnManager.removeRouteTargetsToSubnetAssociation(routeTargets, subnetmap.getSubnetIp(), vpnId.getValue());
passedNwList.add(nw);
}
}
if (ipVersion != IpVersionChoice.UNDEFINED) {
LOG.debug("dissociateNetworksFromVpn: Updating vpnInstance with ip address family {}" + " for VPN {}", ipVersion, vpnId);
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, false);
}
}
// Handle disassociation of external network(s) from Internet BGP-VPN Instance use case
if (!extNwMap.isEmpty() || extNwMap != null) {
for (Network extNw : extNwMap.values()) {
if (disassociateExtNetworkFromVpn(vpnId, extNw)) {
passedNwList.add(extNw.getUuid());
} else {
LOG.error("dissociateNetworksFromVpn: Failed to withdraw External Provider Network {} from VPN {}", extNw, vpnId.getValue());
failedNwList.add(String.format("Failed to withdraw External Provider Network %s from VPN %s", extNw, vpnId.getValue()));
continue;
}
}
}
clearFromVpnMaps(vpnId, null, new ArrayList<>(passedNwList));
LOG.info("dissociateNetworksFromVpn: Network(s) {} disassociated from L3VPN {} successfully", passedNwList, vpnId.getValue());
return failedNwList;
}
Aggregations