use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class InterVpnLinkLocatorTest method populateL3Vpns.
// ////////////
// Stubbing //
// ////////////
public void populateL3Vpns(DataBroker broker, List<L3VpnComposite> vpns) throws ExecutionException, InterruptedException {
for (L3VpnComposite vpn : vpns) {
VpnInstance vpnInstance = new VpnInstanceBuilder().setVpnId(vpn.vpnOpData.getVpnId()).setVpnInstanceName(vpn.vpnOpData.getVpnInstanceName()).setVrfId(vpn.vpnOpData.getVrfId()).build();
WriteTransaction writeTx1 = broker.newWriteOnlyTransaction();
writeTx1.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, VpnOperDsUtils.getVpnInstanceToVpnIdIdentifier(vpn.vpnCfgData.getVpnInstanceName()), vpnInstance);
writeTx1.commit().get();
WriteTransaction writeTx2 = broker.newWriteOnlyTransaction();
writeTx2.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, VpnUtil.getVpnInstanceOpDataIdentifier(vpn.vpnOpData.getVrfId()), vpn.vpnOpData);
writeTx2.commit().get();
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class VpnServiceTest method test.
@Test
public void test() {
List<VpnTarget> vpnTargetList = new ArrayList<>();
VpnTarget vpneRTarget = new VpnTargetBuilder().withKey(new VpnTargetKey("100:1")).setVrfRTValue("100:1").setVrfRTType(VpnTarget.VrfRTType.ExportExtcommunity).build();
VpnTarget vpniRTarget = new VpnTargetBuilder().withKey(new VpnTargetKey("100:2")).setVrfRTValue("100:2").setVrfRTType(VpnTarget.VrfRTType.ImportExtcommunity).build();
vpnTargetList.add(vpneRTarget);
vpnTargetList.add(vpniRTarget);
VpnTargets vpnTargets = new VpnTargetsBuilder().setVpnTarget(vpnTargetList).build();
VpnInstanceBuilder builder = new VpnInstanceBuilder().withKey(new VpnInstanceKey("Vpn1")).setRouteDistinguisher(Arrays.asList("100:1", "100:2:")).setVpnTargets(vpnTargets);
VpnInstance instance = builder.build();
// TODO: Need to enhance the test case to handle ds read/write ops
// vpnManager.onDataChanged(event);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class VpnServiceTest method createVpnId.
private InstanceIdentifier<VpnInstance> createVpnId(String name) {
InstanceIdentifierBuilder<VpnInstance> idBuilder = InstanceIdentifier.builder(VpnInstances.class).child(VpnInstance.class, new VpnInstanceKey(name));
InstanceIdentifier<VpnInstance> id = idBuilder.build();
return id;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class InterfaceStateChangeListener method add.
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void add(InstanceIdentifier<Interface> identifier, Interface intrf) {
try {
if (L2vlan.class.equals(intrf.getType())) {
LOG.info("VPN Interface add event - intfName {} from InterfaceStateChangeListener", intrf.getName());
jobCoordinator.enqueueJob("VPNINTERFACE-" + intrf.getName(), () -> {
List<ListenableFuture<?>> futures = new ArrayList<>(3);
futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, writeInvTxn -> {
// map of prefix and vpn name used, as entry in prefix-to-interface datastore
// is prerequisite for refresh Fib to avoid race condition leading to missing remote next hop
// in bucket actions on bgp-vpn delete
Map<String, Set<String>> mapOfRdAndPrefixesForRefreshFib = new HashMap<>();
ListenableFuture<?> configFuture = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, writeConfigTxn -> {
ListenableFuture<?> operFuture = txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, writeOperTxn -> {
final String interfaceName = intrf.getName();
LOG.info("Detected interface add event for interface {}", interfaceName);
final VpnInterface vpnIf = vpnUtil.getConfiguredVpnInterface(interfaceName);
if (vpnIf != null) {
for (VpnInstanceNames vpnInterfaceVpnInstance : vpnIf.nonnullVpnInstanceNames().values()) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
String primaryRd = vpnUtil.getPrimaryRd(vpnName);
if (!vpnInterfaceManager.isVpnInstanceReady(vpnName)) {
LOG.info("VPN Interface add event - intfName {} onto vpnName {} " + "running oper-driven, VpnInstance not ready, holding" + " on", vpnIf.getName(), vpnName);
} else if (vpnUtil.isVpnPendingDelete(primaryRd)) {
LOG.error("add: Ignoring addition of vpnInterface {}, as" + " vpnInstance {} with primaryRd {} is already marked for" + " deletion", interfaceName, vpnName, primaryRd);
} else {
Uint64 intfDpnId = Uint64.ZERO;
try {
intfDpnId = InterfaceUtils.getDpIdFromInterface(intrf);
} catch (Exception e) {
LOG.error("Unable to retrieve dpnId for interface {}. " + "Process vpn interface add failed", intrf.getName(), e);
return;
}
LOG.error("InterfaceStateChangeListener- Processing ifState" + " {} add event with dpnId {}", intrf.getName(), intfDpnId);
final Uint64 dpnId = intfDpnId;
final int ifIndex = intrf.getIfIndex();
LOG.info("VPN Interface add event - intfName {} onto vpnName {}" + " running oper-driven", vpnIf.getName(), vpnName);
Set<String> prefixes = new HashSet<>();
vpnInterfaceManager.processVpnInterfaceUp(dpnId, vpnIf, primaryRd, ifIndex, false, writeConfigTxn, writeOperTxn, writeInvTxn, intrf, vpnName, prefixes);
mapOfRdAndPrefixesForRefreshFib.put(primaryRd, prefixes);
}
}
}
});
futures.add(operFuture);
// Synchronous submit of operTxn
operFuture.get();
});
Futures.addCallback(configFuture, new VpnInterfaceCallBackHandler(mapOfRdAndPrefixesForRefreshFib), MoreExecutors.directExecutor());
futures.add(configFuture);
// TODO: Allow immediateFailedFuture from writeCfgTxn to cancel writeInvTxn as well.
Futures.addCallback(configFuture, new PostVpnInterfaceThreadWorker(intrf.getName(), true, "Operational"), MoreExecutors.directExecutor());
}));
return futures;
});
}
} catch (Exception e) {
LOG.error("Exception caught in Interface {} Operational State Up event", intrf.getName(), e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class NeutronvpnManager method showVpnConfigCLI.
/**
* Implementation of the "vpnservice:l3vpn-config-show" karaf CLI command.
*
* @param vpnuuid Uuid of the VPN whose config must be shown
* @return formatted output list
* @throws InterruptedException if there was a thread related problem getting the data to display
* @throws ExecutionException if there was any other problem getting the data to display
*/
public List<String> showVpnConfigCLI(Uuid vpnuuid) throws InterruptedException, ExecutionException {
List<String> result = new ArrayList<>();
if (vpnuuid == null) {
result.add("");
result.add("Displaying VPN config for all VPNs");
result.add("To display VPN config for a particular VPN, use the following syntax");
result.add(getshowVpnConfigCLIHelp());
}
RpcResult<GetL3VPNOutput> rpcResult = getL3VPN(new GetL3VPNInputBuilder().setId(vpnuuid).build()).get();
if (rpcResult.isSuccessful()) {
result.add("");
result.add(String.format(" %-37s %-37s %-7s ", "VPN ID", "Tenant ID", "RD"));
result.add("");
result.add(String.format(" %-80s ", "Import-RTs"));
result.add("");
result.add(String.format(" %-80s ", "Export-RTs"));
result.add("");
result.add(String.format(" %-76s ", "Subnet IDs"));
result.add("");
result.add("------------------------------------------------------------------------------------");
result.add("");
for (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.VpnInstance vpn : rpcResult.getResult().nonnullL3vpnInstances()) {
String tenantId = vpn.getTenantId() != null ? vpn.getTenantId().getValue() : "\" " + " \"";
result.add(String.format(" %-37s %-37s %-7s ", vpn.getId().getValue(), tenantId, vpn.getRouteDistinguisher()));
result.add("");
result.add(String.format(" %-80s ", vpn.getImportRT()));
result.add("");
result.add(String.format(" %-80s ", vpn.getExportRT()));
result.add("");
Uuid vpnid = vpn.getId();
List<Uuid> subnetList = neutronvpnUtils.getSubnetsforVpn(vpnid);
if (!subnetList.isEmpty()) {
for (Uuid subnetuuid : subnetList) {
result.add(String.format(" %-76s ", subnetuuid.getValue()));
}
} else {
result.add(String.format(" %-76s ", "\" \""));
}
result.add("");
result.add("----------------------------------------");
result.add("");
}
} else {
String errortag = rpcResult.getErrors().iterator().next().getTag();
if (Objects.equals(errortag, "")) {
result.add("");
result.add("No VPN has been configured yet");
} else if (Objects.equals(errortag, "invalid-value")) {
result.add("");
result.add("VPN " + vpnuuid.getValue() + " is not present");
} else {
result.add("error getting VPN info : " + rpcResult.getErrors());
result.add(getshowVpnConfigCLIHelp());
}
}
return result;
}
Aggregations