use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class ShowVpnInstanceOpData method getVpnInstanceOpData.
private void getVpnInstanceOpData() {
List<VpnInstanceOpDataEntry> vpnInstanceOpDataEntryList = new ArrayList<>();
InstanceIdentifier<VpnInstances> vpnsIdentifier = InstanceIdentifier.builder(VpnInstances.class).build();
InstanceIdentifier<VpnInstanceOpData> vpnInstanceOpDataEntryIdentifier = InstanceIdentifier.builder(VpnInstanceOpData.class).build();
Optional<VpnInstances> optionalVpnInstances = read(LogicalDatastoreType.CONFIGURATION, vpnsIdentifier);
if (!optionalVpnInstances.isPresent() || optionalVpnInstances.get().getVpnInstance() == null || optionalVpnInstances.get().getVpnInstance().isEmpty()) {
LOG.trace("No VPNInstances configured.");
session.getConsole().println("No VPNInstances configured.");
} else {
vpnInstanceList = new ArrayList<VpnInstance>(optionalVpnInstances.get().getVpnInstance().values());
}
Optional<VpnInstanceOpData> optionalOpData = read(LogicalDatastoreType.OPERATIONAL, vpnInstanceOpDataEntryIdentifier);
if (!optionalOpData.isPresent()) {
LOG.trace("No VPNInstanceOpDataEntry present.");
session.getConsole().println("No VPNInstanceOpDataEntry present.");
} else {
vpnInstanceOpDataEntryList = new ArrayList<VpnInstanceOpDataEntry>(optionalOpData.get().nonnullVpnInstanceOpDataEntry().values());
}
for (VpnInstanceOpDataEntry vpnInstanceOpDataEntry : vpnInstanceOpDataEntryList) {
vpnInstanceOpDataEntryMap.put(vpnInstanceOpDataEntry.getVpnInstanceName(), vpnInstanceOpDataEntry);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class L3VpnTestCatalog method build.
static L3VpnComposite build(String vpnName, String vpnRd, long vpnTag, List<String> irts, List<String> erts) {
Objects.nonNull(irts);
Objects.nonNull(erts);
VpnInstance vpnInst = new VpnInstanceBuilder().setVpnInstanceName(vpnName).setVpnTargets(makeVpnTargets(irts, erts)).build();
VpnInstanceOpDataEntry vpnOpData = new VpnInstanceOpDataEntryBuilder().setVpnId(vpnTag).setVpnInstanceName(vpnName).setVrfId(vpnRd).setVpnTargets(VpnOperDsUtils.makeVpnTargets(irts, erts)).build();
return new L3VpnComposite(vpnInst, vpnOpData);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class ShowVpn method doExecute.
@Override
@Nullable
protected Object doExecute() {
Map<String, Integer> vpnNameToConfigInterfaceMap = new HashMap<>();
Map<String, Integer> vpnNameToOperInterfaceMap = new HashMap<>();
if (detail == null) {
showVpn();
Set<String> vpnInstances = new HashSet<>();
for (VpnInterface vpnInterface : vpnInterfaceConfigList) {
if (vpnInterface.getVpnInstanceNames() != null) {
for (VpnInstanceNames vpnInterfaceVpnInstance : vpnInterface.getVpnInstanceNames().values()) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
if (vpnName != null) {
vpnInstances.add(vpnName);
}
}
}
}
for (String routerId : vpnInstances) {
ifPresent = vpnNameToConfigInterfaceMap.get(routerId);
if (ifPresent == null) {
vpnNameToConfigInterfaceMap.put(routerId, 1);
} else {
vpnNameToConfigInterfaceMap.put(routerId, vpnNameToConfigInterfaceMap.get(routerId) + 1);
}
}
for (VpnInterfaceOpDataEntry vpnInterfaceOp : vpnInterfaceOpList) {
ifPresent = vpnNameToOperInterfaceMap.get(vpnInterfaceOp.getVpnInstanceName());
if (ifPresent == null) {
vpnNameToOperInterfaceMap.put(vpnInterfaceOp.getVpnInstanceName(), 1);
} else {
vpnNameToOperInterfaceMap.put(vpnInterfaceOp.getVpnInstanceName(), vpnNameToOperInterfaceMap.get(vpnInterfaceOp.getVpnInstanceName()) + 1);
}
}
session.getConsole().println("-----------------------------------------------------------------------");
session.getConsole().println(String.format(" %s %14s %5s %5s", "VpnInstanceName", "RD", "Config Count", "Oper Count"));
session.getConsole().println("\n-----------------------------------------------------------------------");
for (VpnInstance vpnInstance : vpnInstanceList) {
configCount = 0;
operCount = 0;
Integer count = vpnNameToConfigInterfaceMap.get(vpnInstance.getVpnInstanceName());
if (count != null) {
configCount = vpnNameToConfigInterfaceMap.get(vpnInstance.getVpnInstanceName());
totalConfigCount = totalConfigCount + configCount;
}
count = vpnNameToOperInterfaceMap.get(vpnInstance.getVpnInstanceName());
if (count != null) {
operCount = vpnNameToOperInterfaceMap.get(vpnInstance.getVpnInstanceName());
totalOperCount = totalOperCount + operCount;
}
session.getConsole().println(String.format("%-32s %-10s %-10s %-10s", vpnInstance.getVpnInstanceName(), vpnInstance.getRouteDistinguisher(), configCount, operCount));
}
session.getConsole().println("-----------------------------------------------------------------------");
session.getConsole().println(String.format("Total Count: %19s %8s", totalConfigCount, totalOperCount));
session.getConsole().println(getshowVpnCLIHelp());
} else {
showVpn();
session.getConsole().println("Present Config VpnInterfaces are:");
for (VpnInterface vpnInterface : vpnInterfaceConfigList) {
if (vpnInterface.getVpnInstanceNames() != null && VpnHelper.doesVpnInterfaceBelongToVpnInstance(detail, new ArrayList<VpnInstanceNames>(vpnInterface.getVpnInstanceNames().values()))) {
session.getConsole().println(vpnInterface.getName());
}
}
session.getConsole().println("Present Oper VpnInterfaces are:");
for (VpnInterfaceOpDataEntry vpnInterfaceOp : vpnInterfaceOpList) {
if (Objects.equals(vpnInterfaceOp.getVpnInstanceName(), detail)) {
session.getConsole().println(vpnInterfaceOp.getName());
}
}
}
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class InterVpnLinkLocator method getRts.
private List<String> getRts(VpnInstanceOpDataEntry vpnInstance, VpnTarget.VrfRTType rtType) {
String name = vpnInstance.getVpnInstanceName();
VpnTargets targets = vpnInstance.getVpnTargets();
if (targets == null) {
LOG.trace("vpn targets not available for {}", name);
return new ArrayList<>();
}
Map<VpnTargetKey, VpnTarget> vpnTargets = targets.nonnullVpnTarget();
if (vpnTargets == null) {
LOG.trace("vpnTarget values not available for {}", name);
return new ArrayList<>();
}
return vpnTargets.values().stream().filter(target -> Objects.equals(target.getVrfRTType(), rtType) || Objects.equals(target.getVrfRTType(), VpnTarget.VrfRTType.Both)).map(VpnTarget::getVrfRTValue).collect(Collectors.toList());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance 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());
}
}
Aggregations