use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project netvirt by opendaylight.
the class VpnUtil method getVpnsImportingMyRoute.
public static List<VpnInstanceOpDataEntry> getVpnsImportingMyRoute(final DataBroker broker, final String vpnName) {
List<VpnInstanceOpDataEntry> vpnsToImportRoute = new ArrayList<>();
final String vpnRd = getVpnRd(broker, vpnName);
if (vpnRd == null) {
LOG.error("getVpnsImportingMyRoute: vpn {} not present in config DS.", vpnName);
return vpnsToImportRoute;
}
final VpnInstanceOpDataEntry vpnInstanceOpDataEntry = VpnUtil.getVpnInstanceOpData(broker, vpnRd);
if (vpnInstanceOpDataEntry == null) {
LOG.error("getVpnsImportingMyRoute: Could not retrieve vpn instance op data for {}" + " to check for vpns importing the routes", vpnName);
return vpnsToImportRoute;
}
Predicate<VpnInstanceOpDataEntry> excludeVpn = input -> {
if (input.getVpnInstanceName() == null) {
LOG.error("getVpnsImportingMyRoute.excludeVpn: Received vpn instance with rd {} without a name.", input.getVrfId());
return false;
}
return !input.getVpnInstanceName().equals(vpnName);
};
Predicate<VpnInstanceOpDataEntry> matchRTs = input -> {
Iterable<String> commonRTs = intersection(getRts(vpnInstanceOpDataEntry, VpnTarget.VrfRTType.ExportExtcommunity), getRts(input, VpnTarget.VrfRTType.ImportExtcommunity));
return Iterators.size(commonRTs.iterator()) > 0;
};
vpnsToImportRoute = getAllVpnInstanceOpData(broker).stream().filter(excludeVpn).filter(matchRTs).collect(Collectors.toList());
return vpnsToImportRoute;
}
use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project netvirt by opendaylight.
the class IVpnLinkServiceImpl method leakRoute.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public void leakRoute(InterVpnLinkDataComposite interVpnLink, String srcVpnUuid, String dstVpnUuid, String prefix, Long label, RouteOrigin forcedOrigin) {
String ivpnLinkName = interVpnLink.getInterVpnLinkName();
// The source VPN must participate in the InterVpnLink
Preconditions.checkArgument(interVpnLink.isVpnLinked(srcVpnUuid), "The source VPN {} does not participate in the interVpnLink {}", srcVpnUuid, ivpnLinkName);
// The destination VPN must participate in the InterVpnLink
Preconditions.checkArgument(interVpnLink.isVpnLinked(dstVpnUuid), "The destination VPN {} does not participate in the interVpnLink {}", dstVpnUuid, ivpnLinkName);
String endpointIp = interVpnLink.getOtherEndpointIpAddr(dstVpnUuid);
String leakedOrigin = forcedOrigin != null ? forcedOrigin.getValue() : RouteOrigin.INTERVPN.getValue();
FibHelper.buildRoutePath(endpointIp, label);
VrfEntry newVrfEntry = new VrfEntryBuilder().setKey(new VrfEntryKey(prefix)).setDestPrefix(prefix).setRoutePaths(Collections.singletonList(FibHelper.buildRoutePath(endpointIp, label))).setOrigin(leakedOrigin).build();
String dstVpnRd = VpnUtil.getVpnRd(dataBroker, dstVpnUuid);
InstanceIdentifier<VrfEntry> newVrfEntryIid = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(dstVpnRd)).child(VrfEntry.class, new VrfEntryKey(newVrfEntry.getDestPrefix())).build();
VpnUtil.asyncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, newVrfEntryIid, newVrfEntry);
// Finally, route is advertised it to the DC-GW. But while in the FibEntries the nexthop is the other
// endpoint's IP, in the DC-GW the nexthop for those prefixes are the IPs of those DPNs where the target
// VPN has been instantiated
List<BigInteger> srcDpnList = interVpnLink.getEndpointDpnsByVpnName(srcVpnUuid);
List<String> nexthops = srcDpnList.stream().map(dpnId -> InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, dpnId)).collect(Collectors.toList());
LOG.debug("Advertising route in VPN={} [prefix={} label={} nexthops={}] to DC-GW", dstVpnRd, newVrfEntry.getDestPrefix(), label.intValue(), nexthops);
try {
bgpManager.advertisePrefix(dstVpnRd, null, /*macAddress*/
prefix, nexthops, VrfEntry.EncapType.Mplsgre, label.intValue(), 0, /*l3vni*/
0, /*l2vni*/
null);
} catch (Exception e) {
LOG.error("Exception while advertising prefix {} on vpnRd {} for intervpn link", prefix, dstVpnRd, e);
}
}
use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project netvirt by opendaylight.
the class VpnServiceElanDpnInterfacesListener method update.
@Override
protected void update(InstanceIdentifier<DpnInterfaces> identifier, DpnInterfaces original, DpnInterfaces update) {
LOG.info("received Dpninterfaces update event for dpn {}", update.getDpId());
BigInteger dpnId = update.getDpId();
String elanInstanceName = identifier.firstKeyOf(ElanDpnInterfacesList.class).getElanInstanceName();
ElanInstance elanInstance = VpnUtil.getElanInstanceByName(dataBroker, elanInstanceName);
String vpnName = VpnUtil.getVpnNameFromElanIntanceName(dataBroker, elanInstanceName);
if (vpnName == null) {
return;
}
String primaryRd = VpnUtil.getPrimaryRd(dataBroker, vpnName);
if (elanInstance != null && !elanInstance.isExternal() && VpnUtil.isVlan(elanInstance)) {
jobCoordinator.enqueueJob(elanInstance.getElanInstanceName(), () -> {
return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeConfigTxn -> {
List<String> addedInterfaces = getUpdatedInterfaceList(update.getInterfaces(), original.getInterfaces());
for (String addedInterface : addedInterfaces) {
if (interfaceManager.isExternalInterface(addedInterface)) {
InstanceIdentifier<VpnToDpnList> id = VpnUtil.getVpnToDpnListIdentifier(primaryRd, dpnId);
Optional<VpnToDpnList> dpnInVpn = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (!dpnInVpn.isPresent() || (dpnInVpn.get().getVpnInterfaces() != null && dpnInVpn.get().getVpnInterfaces().size() != 1)) {
return;
}
if (!VpnUtil.shouldPopulateFibForVlan(dataBroker, vpnName, elanInstanceName, dpnId, interfaceManager)) {
return;
}
long vpnId = VpnUtil.getVpnId(dataBroker, vpnName);
fibManager.populateFibOnNewDpn(dpnId, vpnId, primaryRd, null);
break;
}
}
List<String> deletedInterfaces = getUpdatedInterfaceList(original.getInterfaces(), update.getInterfaces());
if (!deletedInterfaces.isEmpty()) {
String routerPortUuid = VpnUtil.getRouterPordIdFromElanInstance(dataBroker, elanInstanceName);
if (update.getInterfaces().size() == 2 && update.getInterfaces().contains(routerPortUuid)) {
VpnUtil.removeRouterPortFromElanForVlanInDpn(vpnName, dpnId, dataBroker);
}
}
}));
});
}
}
use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project netvirt by opendaylight.
the class InterfaceStateChangeListener method add.
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected 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<Void>> futures = new ArrayList<>(3);
futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeInvTxn -> {
ListenableFuture<Void> configFuture = txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeConfigTxn -> {
ListenableFuture<Void> operFuture = txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeOperTxn -> {
final String interfaceName = intrf.getName();
LOG.info("Detected interface add event for interface {}", interfaceName);
final VpnInterface vpnIf = VpnUtil.getConfiguredVpnInterface(dataBroker, interfaceName);
if (vpnIf != null) {
for (VpnInstanceNames vpnInterfaceVpnInstance : vpnIf.getVpnInstanceNames()) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
String primaryRd = VpnUtil.getPrimaryRd(dataBroker, 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(dataBroker, primaryRd)) {
LOG.error("add: Ignoring addition of vpnInterface {}, as" + " vpnInstance {} with primaryRd {} is already marked for" + " deletion", interfaceName, vpnName, primaryRd);
} else {
BigInteger intfDpnId = BigInteger.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;
}
final BigInteger dpnId = intfDpnId;
final int ifIndex = intrf.getIfIndex();
LOG.info("VPN Interface add event - intfName {} onto vpnName {}" + " running oper-driven", vpnIf.getName(), vpnName);
vpnInterfaceManager.processVpnInterfaceUp(dpnId, vpnIf, primaryRd, ifIndex, false, writeConfigTxn, writeOperTxn, writeInvTxn, intrf, vpnName);
}
}
}
});
futures.add(operFuture);
// Synchronous submit of operTxn
operFuture.get();
});
futures.add(configFuture);
// TODO: Allow immediateFailedFuture from writeCfgTxn to cancel writeInvTxn as well.
Futures.addCallback(configFuture, new PostVpnInterfaceThreadWorker(intrf.getName(), true, "Operational"));
}));
return futures;
});
}
} catch (Exception e) {
LOG.error("Exception caught in Interface {} Operational State Up event", intrf.getName(), e);
}
}
use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project netvirt by opendaylight.
the class VpnServiceChainUtils method getAllVpnIfaceNames.
public static List<String> getAllVpnIfaceNames(DataBroker dataBroker, String vpnName) {
String vpnRd = getVpnRd(dataBroker, vpnName);
InstanceIdentifier<VpnInstanceOpDataEntry> vpnOpDataIid = InstanceIdentifier.builder(VpnInstanceOpData.class).child(VpnInstanceOpDataEntry.class, new VpnInstanceOpDataEntryKey(vpnRd)).build();
try {
VpnInstanceOpDataEntry vpnOpData = SingleTransactionDataBroker.syncRead(dataBroker, LogicalDatastoreType.OPERATIONAL, vpnOpDataIid);
if (vpnOpData == null) {
return Collections.emptyList();
}
List<VpnToDpnList> dpnToVpns = vpnOpData.getVpnToDpnList();
if (dpnToVpns == null) {
return Collections.emptyList();
}
return dpnToVpns.stream().filter(dpn -> dpn.getVpnInterfaces() != null).flatMap(dpn -> dpn.getVpnInterfaces().stream()).map(VpnInterfaces::getInterfaceName).collect(Collectors.toList());
} catch (ReadFailedException e) {
LOG.warn("getAllVpnInterfaces for vpn {}: Failure on read operation", vpnName, e);
return Collections.emptyList();
}
}
Aggregations