use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInstances in project netvirt by opendaylight.
the class TunnelEndPointChangeListener method add.
@Override
public void add(InstanceIdentifier<TunnelEndPoints> key, TunnelEndPoints tep) {
Uint64 dpnId = key.firstIdentifierOf(DPNTEPsInfo.class).firstKeyOf(DPNTEPsInfo.class).getDPNID();
if (Uint64.ZERO.equals(dpnId)) {
LOG.warn("add: Invalid DPN id for TEP {}", tep.getInterfaceName());
return;
}
List<VpnInstance> vpnInstances = VpnHelper.getAllVpnInstances(broker);
if (vpnInstances == null || vpnInstances.isEmpty()) {
LOG.warn("add: dpnId: {}: tep: {}: No VPN instances defined", dpnId, tep.getInterfaceName());
return;
}
for (VpnInstance vpnInstance : vpnInstances) {
final String vpnName = vpnInstance.getVpnInstanceName();
final Uint32 vpnId = vpnUtil.getVpnId(vpnName);
LOG.info("add: Handling TEP {} add for VPN instance {}", tep.getInterfaceName(), vpnName);
final String primaryRd = vpnUtil.getPrimaryRd(vpnName);
if (!vpnUtil.isVpnPendingDelete(primaryRd)) {
List<VpnInterfaces> vpnInterfaces = vpnUtil.getDpnVpnInterfaces(vpnInstance, dpnId);
if (vpnInterfaces != null) {
for (VpnInterfaces vpnInterface : vpnInterfaces) {
String vpnInterfaceName = vpnInterface.getInterfaceName();
jobCoordinator.enqueueJob("VPNINTERFACE-" + vpnInterfaceName, () -> {
final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState = InterfaceUtils.getInterfaceStateFromOperDS(broker, vpnInterfaceName);
if (interfaceState == null) {
LOG.debug("add: Cannot retrieve interfaceState for vpnInterfaceName {}, " + "cannot generate lPortTag and process adjacencies", vpnInterfaceName);
return Collections.emptyList();
}
final int lPortTag = interfaceState.getIfIndex();
List<ListenableFuture<?>> futures = new ArrayList<>();
Set<String> prefixesForRefreshFib = new HashSet<>();
ListenableFuture<?> writeConfigFuture = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, writeConfigTxn -> futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, writeOperTxn -> futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, writeInvTxn -> vpnInterfaceManager.processVpnInterfaceAdjacencies(dpnId, lPortTag, vpnName, primaryRd, vpnInterfaceName, vpnId, writeConfigTxn, writeOperTxn, writeInvTxn, interfaceState, prefixesForRefreshFib))))));
Futures.addCallback(writeConfigFuture, new FutureCallback<Object>() {
@Override
public void onSuccess(Object voidObj) {
prefixesForRefreshFib.forEach(prefix -> {
fibManager.refreshVrfEntry(primaryRd, prefix);
});
}
@Override
public void onFailure(Throwable throwable) {
LOG.debug("addVpnInterface: write Tx config execution failed", throwable);
}
}, MoreExecutors.directExecutor());
futures.add(writeConfigFuture);
LOG.trace("add: Handled TEP {} add for VPN instance {} VPN interface {}", tep.getInterfaceName(), vpnName, vpnInterfaceName);
return futures;
});
}
}
} else {
LOG.error("add: Ignoring addition of tunnel interface {} dpn {} for vpnInstance {} with primaryRd {}," + " as the VPN is already marked for deletion", tep.getInterfaceName(), dpnId, vpnName, primaryRd);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInstances in project netvirt by opendaylight.
the class ShowVpnInstanceOpData method doExecute.
@Override
@Nullable
protected Object doExecute() {
if (detail == null) {
getVpnInstanceOpData();
session.getConsole().println("For following vpnInstances vpnInstanceOpDataEntry is present: \n");
for (VpnInstance vpnInstance : vpnInstanceList) {
VpnInstanceOpDataEntry check = vpnInstanceOpDataEntryMap.get(vpnInstance.getVpnInstanceName());
if (check != null) {
session.getConsole().println(vpnInstance.getVpnInstanceName() + "\n");
}
}
session.getConsole().println("\n\nFor following vpnInstances vpnInstanceOpDataEntry is not present: \n");
for (VpnInstance vpnInstance : vpnInstanceList) {
VpnInstanceOpDataEntry check = vpnInstanceOpDataEntryMap.get(vpnInstance.getVpnInstanceName());
if (check == null) {
session.getConsole().println(vpnInstance.getVpnInstanceName() + "\n");
}
}
session.getConsole().println(getshowVpnCLIHelp());
} else {
getVpnInstanceOpData();
session.getConsole().println("Fetching details of given vpnInstance\n");
session.getConsole().println("------------------------------------------------------------------------------");
VpnInstanceOpDataEntry check = vpnInstanceOpDataEntryMap.get(detail);
Long intfCount = 0L;
Map<VpnToDpnListKey, VpnToDpnList> vpnToDpnListKeyVpnToDpnListMap = check.getVpnToDpnList();
if (vpnToDpnListKeyVpnToDpnListMap != null) {
for (VpnToDpnList dpn : vpnToDpnListKeyVpnToDpnListMap.values()) {
if (dpn.getVpnInterfaces() != null) {
intfCount = intfCount + dpn.getVpnInterfaces().size();
}
}
}
session.getConsole().println("VpnInstanceName: " + check.getVpnInstanceName() + "\nVpnId: " + check.getVpnId() + "\nVrfId: " + check.getVrfId() + "\nKey: " + check.key() + "\nVpnInterfaceCount: " + intfCount + "\nVpnToDpnList: " + check.getVpnToDpnList() + "\n");
session.getConsole().println("------------------------------------------------------------------------------");
}
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInstances 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.VpnInstances 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.VpnInstances in project netvirt by opendaylight.
the class NeutronvpnUtils method getVpnForRD.
public String getVpnForRD(String rd) {
InstanceIdentifier<VpnInstances> path = InstanceIdentifier.builder(VpnInstances.class).build();
Optional<VpnInstances> vpnInstancesOptional = read(LogicalDatastoreType.CONFIGURATION, path);
if (vpnInstancesOptional.isPresent() && vpnInstancesOptional.get().getVpnInstance() != null) {
for (VpnInstance vpnInstance : vpnInstancesOptional.get().getVpnInstance().values()) {
List<String> rds = vpnInstance.getRouteDistinguisher();
if (rds != null && rds.contains(rd)) {
return vpnInstance.getVpnInstanceName();
}
}
}
return null;
}
Aggregations