use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project netvirt by opendaylight.
the class VpnInterfaceManager method removeVpnInterfaceFromVpn.
@SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
private void removeVpnInterfaceFromVpn(final InstanceIdentifier<VpnInterface> identifier, final VpnInterface vpnInterface, final String vpnName, final String interfaceName, final Interface interfaceState) {
LOG.info("remove: VPN Interface remove event - intfName {} vpn {} dpn {}", vpnInterface.getName(), vpnName, vpnInterface.getDpnId());
removeInterfaceFromUnprocessedList(identifier, vpnInterface);
jobCoordinator.enqueueJob("VPNINTERFACE-" + interfaceName, () -> {
List<ListenableFuture<Void>> futures = new ArrayList<>(3);
ListenableFuture<Void> configFuture = txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeConfigTxn -> {
futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeOperTxn -> {
futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeInvTxn -> {
LOG.info("remove: - intfName {} onto vpnName {} running config-driven", interfaceName, vpnName);
BigInteger dpId = BigInteger.ZERO;
int ifIndex = 0;
String gwMacAddress = null;
InstanceIdentifier<VpnInterfaceOpDataEntry> interfaceId = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
final Optional<VpnInterfaceOpDataEntry> optVpnInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, interfaceId);
if (interfaceState != null) {
try {
dpId = InterfaceUtils.getDpIdFromInterface(interfaceState);
} catch (NumberFormatException | IllegalStateException e) {
LOG.error("remove: Unable to retrieve dpnId from interface operational" + " data store for interface {} on dpn {} for vpn {} Fetching" + " from vpn interface op data store. ", interfaceName, vpnInterface.getDpnId(), vpnName, e);
dpId = BigInteger.ZERO;
}
ifIndex = interfaceState.getIfIndex();
gwMacAddress = interfaceState.getPhysAddress().getValue();
} else {
LOG.info("remove: Interface state not available for {}. Trying to fetch data" + " from vpn interface op.", interfaceName);
if (optVpnInterface.isPresent()) {
VpnInterfaceOpDataEntry vpnOpInterface = optVpnInterface.get();
dpId = vpnOpInterface.getDpnId();
ifIndex = vpnOpInterface.getLportTag().intValue();
gwMacAddress = vpnOpInterface.getGatewayMacAddress();
} else {
LOG.error("remove: Handling removal of VPN interface {} for vpn {} skipped" + " as interfaceState and vpn interface op is not" + " available", interfaceName, vpnName);
return;
}
}
processVpnInterfaceDown(dpId, interfaceName, ifIndex, gwMacAddress, optVpnInterface.isPresent() ? optVpnInterface.get() : null, false, writeConfigTxn, writeOperTxn, writeInvTxn);
LOG.info("remove: Removal of vpn interface {} on dpn {} for vpn {} processed " + "successfully", interfaceName, vpnInterface.getDpnId(), vpnName);
}));
}));
});
futures.add(configFuture);
Futures.addCallback(configFuture, new PostVpnInterfaceWorker(interfaceName, false, "Config"));
return futures;
}, DJC_MAX_RETRIES);
}
use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project netvirt by opendaylight.
the class VpnInterfaceManager method updateVpnInterfacesForUnProcessAdjancencies.
public void updateVpnInterfacesForUnProcessAdjancencies(String vpnName) {
String primaryRd = VpnUtil.getVpnRd(dataBroker, vpnName);
VpnInstanceOpDataEntry vpnInstanceOpData = VpnUtil.getVpnInstanceOpData(dataBroker, primaryRd);
if (vpnInstanceOpData == null) {
return;
}
List<VpnToDpnList> vpnToDpnLists = vpnInstanceOpData.getVpnToDpnList();
if (vpnToDpnLists == null || vpnToDpnLists.isEmpty()) {
return;
}
LOG.debug("Update the VpnInterfaces for Unprocessed Adjancencies for vpnName:{}", vpnName);
vpnToDpnLists.forEach(vpnToDpnList -> vpnToDpnList.getVpnInterfaces().forEach(vpnInterface -> {
InstanceIdentifier<VpnInterfaceOpDataEntry> existingVpnInterfaceId = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(vpnInterface.getInterfaceName(), vpnName);
Optional<VpnInterfaceOpDataEntry> vpnInterfaceOptional = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, existingVpnInterfaceId);
if (!vpnInterfaceOptional.isPresent()) {
return;
}
List<Adjacency> configVpnAdjacencies = VpnUtil.getAdjacenciesForVpnInterfaceFromConfig(dataBroker, vpnInterface.getInterfaceName());
if (configVpnAdjacencies == null) {
LOG.debug("There is no adjacency available for vpnInterface:{}", vpnInterface);
return;
}
List<Adjacency> operationVpnAdjacencies = vpnInterfaceOptional.get().getAugmentation(AdjacenciesOp.class).getAdjacency();
// Due to insufficient rds, some of the extra route wont get processed when it is added.
// The unprocessed adjacencies will be present in config vpn interface DS but will be missing
// in operational DS. These unprocessed adjacencies will be handled below.
// To obtain unprocessed adjacencies, filtering is done by which the missing adjacencies in operational
// DS are retrieved which is used to call addNewAdjToVpnInterface method.
configVpnAdjacencies.stream().filter(adjacency -> operationVpnAdjacencies.stream().noneMatch(operationalAdjacency -> operationalAdjacency.getIpAddress().equals(adjacency.getIpAddress()))).forEach(adjacency -> {
LOG.debug("Processing the vpnInterface{} for the Ajacency:{}", vpnInterface, adjacency);
jobCoordinator.enqueueJob("VPNINTERFACE-" + vpnInterface.getInterfaceName(), () -> {
WriteTransaction writeConfigTxn = dataBroker.newWriteOnlyTransaction();
WriteTransaction writeOperTxn = dataBroker.newWriteOnlyTransaction();
if (VpnUtil.isAdjacencyEligibleToVpn(dataBroker, adjacency, vpnName)) {
addNewAdjToVpnInterface(existingVpnInterfaceId, primaryRd, adjacency, vpnInterfaceOptional.get().getDpnId(), writeConfigTxn, writeOperTxn);
ListenableFuture<Void> operFuture = writeOperTxn.submit();
try {
operFuture.get();
} catch (ExecutionException | InterruptedException e) {
LOG.error("Exception encountered while submitting operational" + " future for vpnInterface {}", vpnInterface, e);
}
List<ListenableFuture<Void>> futures = new ArrayList<>();
futures.add(writeConfigTxn.submit());
return futures;
} else {
return Collections.emptyList();
}
});
});
}));
}
use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier 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.yangtools.yang.binding.InstanceIdentifier 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.yangtools.yang.binding.InstanceIdentifier in project netvirt by opendaylight.
the class InterVpnLinkNodeListener method remove.
@Override
protected void remove(InstanceIdentifier<Node> identifier, Node del) {
LOG.trace("Node {} has been deleted", identifier.firstKeyOf(Node.class).toString());
NodeId nodeId = del.getNodeId();
String[] node = nodeId.getValue().split(":");
if (node.length < 2) {
LOG.warn("Unexpected nodeId {}", nodeId.getValue());
return;
}
BigInteger dpId = new BigInteger(node[1]);
List<InterVpnLinkDataComposite> allInterVpnLinks = interVpnLinkCache.getAllInterVpnLinks();
allInterVpnLinks.stream().filter(// Only those affected by DPN going down
ivl -> ivl.stepsOnDpn(dpId)).forEach(// Move them somewhere else
this::reinstallInterVpnLink);
}
Aggregations