use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update in project netvirt by opendaylight.
the class VpnInterfaceManager method update.
@Override
protected void update(final InstanceIdentifier<VpnInterface> identifier, final VpnInterface original, final VpnInterface update) {
LOG.info("update: VPN Interface update event - intfName {} on dpn {} oldVpn {} newVpn {}", update.getName(), update.getDpnId(), original.getVpnInstanceNames(), update.getVpnInstanceNames());
final String vpnInterfaceName = update.getName();
final BigInteger dpnId = InterfaceUtils.getDpnForInterface(ifaceMgrRpcService, vpnInterfaceName);
final Adjacencies origAdjs = original.getAugmentation(Adjacencies.class);
final List<Adjacency> oldAdjs = origAdjs != null && origAdjs.getAdjacency() != null ? origAdjs.getAdjacency() : new ArrayList<>();
final Adjacencies updateAdjs = update.getAugmentation(Adjacencies.class);
final List<Adjacency> newAdjs = updateAdjs != null && updateAdjs.getAdjacency() != null ? updateAdjs.getAdjacency() : new ArrayList<>();
LOG.info("VPN Interface update event - intfName {}", vpnInterfaceName);
// handles switching between <internal VPN - external VPN>
if (handleVpnSwapForVpnInterface(identifier, original, update)) {
LOG.info("update: handled VPNInterface {} on dpn {} update" + "upon VPN swap from oldVpn(s) {} to newVpn(s) {}", original.getName(), dpnId, VpnHelper.getVpnInterfaceVpnInstanceNamesString(original.getVpnInstanceNames()), VpnHelper.getVpnInterfaceVpnInstanceNamesString(update.getVpnInstanceNames()));
return;
}
for (VpnInstanceNames vpnInterfaceVpnInstance : update.getVpnInstanceNames()) {
String newVpnName = vpnInterfaceVpnInstance.getVpnName();
List<Adjacency> copyNewAdjs = new ArrayList<>(newAdjs);
List<Adjacency> copyOldAdjs = new ArrayList<>(oldAdjs);
String primaryRd = VpnUtil.getPrimaryRd(dataBroker, newVpnName);
if (!VpnUtil.isVpnPendingDelete(dataBroker, primaryRd)) {
jobCoordinator.enqueueJob("VPNINTERFACE-" + vpnInterfaceName, () -> {
WriteTransaction writeConfigTxn = dataBroker.newWriteOnlyTransaction();
WriteTransaction writeOperTxn = dataBroker.newWriteOnlyTransaction();
InstanceIdentifier<VpnInterfaceOpDataEntry> vpnInterfaceOpIdentifier = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(vpnInterfaceName, newVpnName);
LOG.info("VPN Interface update event - intfName {} onto vpnName {} running config-driven", update.getName(), newVpnName);
// handle both addition and removal of adjacencies
// currently, new adjacency may be an extra route
boolean isBgpVpnInternetVpn = VpnUtil.isBgpVpnInternet(dataBroker, newVpnName);
if (!oldAdjs.equals(newAdjs)) {
for (Adjacency adj : copyNewAdjs) {
if (copyOldAdjs.contains(adj)) {
copyOldAdjs.remove(adj);
} else {
// add new adjacency - right now only extra route will hit this path
if (!isBgpVpnInternetVpn || VpnUtil.isAdjacencyEligibleToVpnInternet(dataBroker, adj)) {
addNewAdjToVpnInterface(vpnInterfaceOpIdentifier, primaryRd, adj, dpnId, writeOperTxn, writeConfigTxn);
}
LOG.info("update: new Adjacency {} with nextHop {} label {} subnet {} added to vpn " + "interface {} on vpn {} dpnId {}", adj.getIpAddress(), adj.getNextHopIpList(), adj.getLabel(), adj.getSubnetId(), update.getName(), newVpnName, dpnId);
}
}
for (Adjacency adj : copyOldAdjs) {
if (!isBgpVpnInternetVpn || VpnUtil.isAdjacencyEligibleToVpnInternet(dataBroker, adj)) {
delAdjFromVpnInterface(vpnInterfaceOpIdentifier, adj, dpnId, writeOperTxn, writeConfigTxn);
}
LOG.info("update: Adjacency {} with nextHop {} label {} subnet {} removed from" + " vpn interface {} on vpn {}", adj.getIpAddress(), adj.getNextHopIpList(), adj.getLabel(), adj.getSubnetId(), update.getName(), newVpnName);
}
}
ListenableFuture<Void> operFuture = writeOperTxn.submit();
try {
operFuture.get();
} catch (ExecutionException e) {
LOG.error("Exception encountered while submitting operational future for update" + " VpnInterface {} on vpn {}", vpnInterfaceName, newVpnName, e);
return null;
}
List<ListenableFuture<Void>> futures = new ArrayList<>();
futures.add(writeConfigTxn.submit());
LOG.info("update: vpn interface updated for interface {} oldVpn(s) {} newVpn {}" + "processed successfully", update.getName(), VpnHelper.getVpnInterfaceVpnInstanceNamesString(original.getVpnInstanceNames()), newVpnName);
return futures;
});
} else {
LOG.error("update: Ignoring update of vpnInterface {}, as newVpnInstance {} with primaryRd {}" + " is already marked for deletion", vpnInterfaceName, newVpnName, primaryRd);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update in project netvirt by opendaylight.
the class VpnInterfaceManager method updateVpnInterfaceOnTepDelete.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void updateVpnInterfaceOnTepDelete(VpnInterfaceOpDataEntry vpnInterface, StateTunnelList stateTunnelList, WriteTransaction writeConfigTxn, WriteTransaction writeOperTxn) {
AdjacenciesOp adjacencies = vpnInterface.getAugmentation(AdjacenciesOp.class);
List<Adjacency> adjList = adjacencies != null ? adjacencies.getAdjacency() : new ArrayList<>();
String prefix = null;
long label = 0;
boolean isNextHopRemoveReqd = false;
String srcTepIp = String.valueOf(stateTunnelList.getSrcInfo().getTepIp().getValue());
BigInteger srcDpnId = new BigInteger(stateTunnelList.getSrcInfo().getTepDeviceId());
String vpnName = vpnInterface.getVpnInstanceName();
long vpnId = VpnUtil.getVpnId(dataBroker, vpnName);
String primaryRd = VpnUtil.getVpnRd(dataBroker, vpnName);
if (adjList != null) {
List<Adjacency> value = new ArrayList<>();
LOG.info("updateVpnInterfaceOnTepDelete: AdjacencyList for interface {} on dpn {} vpn {} is {}", vpnInterface.getName(), vpnInterface.getDpnId(), vpnInterface.getVpnInstanceName(), adjList);
for (Adjacency adj : adjList) {
List<String> nhList = new ArrayList<>();
String rd = adj.getVrfId();
rd = rd != null ? rd : vpnName;
prefix = adj.getIpAddress();
List<String> nextHopList = adj.getNextHopIpList();
label = adj.getLabel();
if (nextHopList != null && !nextHopList.isEmpty()) {
isNextHopRemoveReqd = true;
}
// Secondary adj nexthop will continue to point to primary adj IP address.
if (adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
value.add(new AdjacencyBuilder(adj).setNextHopIpList(nhList).build());
} else {
Optional<VrfEntry> vrfEntryOptional = FibHelper.getVrfEntry(dataBroker, primaryRd, prefix);
if (!vrfEntryOptional.isPresent()) {
continue;
}
nhList = FibHelper.getNextHopListFromRoutePaths(vrfEntryOptional.get());
if (nhList.contains(srcTepIp)) {
nhList.remove(srcTepIp);
isNextHopRemoveReqd = true;
}
value.add(adj);
}
if (isNextHopRemoveReqd) {
updateLabelMapper(label, nhList);
LOG.info("updateVpnInterfaceOnTepDelete: Updated label mapper : label {} dpn {} prefix {}" + " nexthoplist {} vpn {} vpnid {} rd {} interface {}", label, srcDpnId, prefix, nhList, vpnName, vpnId, rd, vpnInterface.getName());
// Update the VRF entry with removed nextHop
fibManager.updateRoutePathForFibEntry(primaryRd, prefix, srcTepIp, label, false, writeConfigTxn);
// Get the list of VPN's importing this route(prefix) .
// Then update the VRF entry with nhList
List<VpnInstanceOpDataEntry> vpnsToImportRoute = VpnUtil.getVpnsImportingMyRoute(dataBroker, vpnName);
for (VpnInstanceOpDataEntry vpn : vpnsToImportRoute) {
String vpnRd = vpn.getVrfId();
if (vpnRd != null) {
fibManager.updateRoutePathForFibEntry(vpnRd, prefix, srcTepIp, label, false, writeConfigTxn);
LOG.info("updateVpnInterfaceOnTepDelete: Exported route with rd {} prefix {} nhList {}" + " label {} interface {} dpn {} from vpn {} to VPN {} vpnRd {}", rd, prefix, nhList, label, vpnInterface.getName(), srcDpnId, vpnName, vpn.getVpnInstanceName(), vpnRd);
}
}
// Withdraw prefix from BGP only for external vpn.
try {
if (!rd.equalsIgnoreCase(vpnName)) {
bgpManager.withdrawPrefix(rd, prefix);
}
LOG.info("updateVpnInterfaceOnTepDelete: Withdrawn rd {} prefix {} nhList {} label {}" + " for interface {} on dpn {} vpn {}", rd, prefix, nhList, label, vpnInterface.getName(), srcDpnId, vpnName);
} catch (Exception ex) {
LOG.error("updateVpnInterfaceOnTepDelete: Exception when withdrawing prefix {} nh {} label {}" + " on rd {} for interface {} on dpn {} vpn {}", prefix, nhList, label, rd, vpnInterface.getName(), srcDpnId, vpnName, ex);
}
}
}
AdjacenciesOp aug = VpnUtil.getVpnInterfaceOpDataEntryAugmentation(value);
VpnInterfaceOpDataEntry opInterface = new VpnInterfaceOpDataEntryBuilder(vpnInterface).setKey(new VpnInterfaceOpDataEntryKey(vpnInterface.getName(), vpnName)).addAugmentation(AdjacenciesOp.class, aug).build();
InstanceIdentifier<VpnInterfaceOpDataEntry> interfaceId = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(vpnInterface.getName(), vpnName);
writeOperTxn.put(LogicalDatastoreType.OPERATIONAL, interfaceId, opInterface, WriteTransaction.CREATE_MISSING_PARENTS);
LOG.info("updateVpnInterfaceOnTepDelete: interface {} updated successully on tep delete on dpn {} vpn {}", vpnInterface.getName(), srcDpnId, vpnName);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update in project netvirt by opendaylight.
the class VpnInterfaceManager method addVpnInterfaceToVpn.
private void addVpnInterfaceToVpn(final InstanceIdentifier<VpnInterfaceOpDataEntry> vpnInterfaceOpIdentifier, final VpnInterface vpnInterface, final List<Adjacency> oldAdjs, final List<Adjacency> newAdjs, final InstanceIdentifier<VpnInterface> identifier, String vpnName) {
final VpnInterfaceKey key = identifier.firstKeyOf(VpnInterface.class, VpnInterfaceKey.class);
final String interfaceName = key.getName();
String primaryRd = VpnUtil.getPrimaryRd(dataBroker, vpnName);
if (!VpnUtil.isVpnPendingDelete(dataBroker, primaryRd)) {
Interface interfaceState = InterfaceUtils.getInterfaceStateFromOperDS(dataBroker, interfaceName);
boolean isBgpVpnInternetVpn = VpnUtil.isBgpVpnInternet(dataBroker, vpnName);
if (interfaceState != null) {
try {
final BigInteger dpnId = InterfaceUtils.getDpIdFromInterface(interfaceState);
final int ifIndex = interfaceState.getIfIndex();
jobCoordinator.enqueueJob("VPNINTERFACE-" + interfaceName, () -> {
WriteTransaction writeConfigTxn = dataBroker.newWriteOnlyTransaction();
WriteTransaction writeOperTxn = dataBroker.newWriteOnlyTransaction();
WriteTransaction writeInvTxn = dataBroker.newWriteOnlyTransaction();
LOG.info("addVpnInterface: VPN Interface add event - intfName {} vpnName {} on dpn {}", vpnInterface.getName(), vpnName, vpnInterface.getDpnId());
processVpnInterfaceUp(dpnId, vpnInterface, primaryRd, ifIndex, false, writeConfigTxn, writeOperTxn, writeInvTxn, interfaceState, vpnName);
if (oldAdjs != null && !oldAdjs.equals(newAdjs)) {
LOG.info("addVpnInterface: Adjacency changed upon VPNInterface {}" + " Update for swapping VPN {} case.", interfaceName, vpnName);
if (newAdjs != null) {
for (Adjacency adj : newAdjs) {
if (oldAdjs.contains(adj)) {
oldAdjs.remove(adj);
} else {
if (!isBgpVpnInternetVpn || VpnUtil.isAdjacencyEligibleToVpnInternet(dataBroker, adj)) {
addNewAdjToVpnInterface(vpnInterfaceOpIdentifier, primaryRd, adj, dpnId, writeOperTxn, writeConfigTxn);
}
}
}
}
for (Adjacency adj : oldAdjs) {
if (!isBgpVpnInternetVpn || VpnUtil.isAdjacencyEligibleToVpnInternet(dataBroker, adj)) {
delAdjFromVpnInterface(vpnInterfaceOpIdentifier, adj, dpnId, writeOperTxn, writeConfigTxn);
}
}
}
ListenableFuture<Void> operFuture = writeOperTxn.submit();
try {
operFuture.get();
} catch (ExecutionException e) {
LOG.error("addVpnInterface: Exception encountered while submitting operational future for" + " addVpnInterface {} on vpn {}", vpnInterface.getName(), vpnName, e);
return null;
}
List<ListenableFuture<Void>> futures = new ArrayList<>();
ListenableFuture<Void> configFuture = writeConfigTxn.submit();
futures.add(configFuture);
Futures.addCallback(configFuture, new PostVpnInterfaceWorker(interfaceName, true, "Config"));
futures.add(writeInvTxn.submit());
LOG.info("addVpnInterface: Addition of interface {} in VPN {} on dpn {}" + " processed successfully", interfaceName, vpnName, dpnId);
return futures;
});
} catch (NumberFormatException | IllegalStateException e) {
LOG.error("addVpnInterface: Unable to retrieve dpnId from interface operational data store for " + "interface {}. Interface addition on vpn {} failed", interfaceName, vpnName, e);
return;
}
} else if (Boolean.TRUE.equals(vpnInterface.isRouterInterface())) {
jobCoordinator.enqueueJob("VPNINTERFACE-" + vpnInterface.getName(), () -> {
WriteTransaction writeConfigTxn = dataBroker.newWriteOnlyTransaction();
createFibEntryForRouterInterface(primaryRd, vpnInterface, interfaceName, writeConfigTxn, vpnName);
LOG.info("addVpnInterface: Router interface {} for vpn {} on dpn {}", interfaceName, vpnName, vpnInterface.getDpnId());
ListenableFuture<Void> futures = writeConfigTxn.submit();
String errorText = "addVpnInterfaceCall: Exception encountered while submitting writeConfigTxn" + " for interface " + vpnInterface.getName() + " on vpn " + vpnName;
ListenableFutures.addErrorLogging(futures, LOG, errorText);
return Collections.singletonList(futures);
});
} else {
LOG.info("addVpnInterface: Handling addition of VPN interface {} on vpn {} skipped as interfaceState" + " is not available", interfaceName, vpnName);
}
} else {
LOG.error("addVpnInterface: Handling addition of VPN interface {} on vpn {} dpn {} skipped" + " as vpn is pending delete", interfaceName, vpnName, vpnInterface.getDpnId());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update in project netvirt by opendaylight.
the class InterfaceStateChangeListener method update.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
protected void update(InstanceIdentifier<Interface> identifier, Interface original, Interface update) {
final String ifName = update.getName();
try {
OperStatus originalOperStatus = original.getOperStatus();
OperStatus updateOperStatus = update.getOperStatus();
if (originalOperStatus.equals(Interface.OperStatus.Unknown) || updateOperStatus.equals(Interface.OperStatus.Unknown)) {
LOG.debug("Interface {} state change is from/to null/UNKNOWN. Ignoring the update event.", ifName);
return;
}
if (update.getIfIndex() == null) {
return;
}
if (L2vlan.class.equals(update.getType())) {
LOG.info("VPN Interface update event - intfName {} from InterfaceStateChangeListener", update.getName());
jobCoordinator.enqueueJob("VPNINTERFACE-" + ifName, () -> {
List<ListenableFuture<Void>> futures = new ArrayList<>(3);
futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeOperTxn -> {
futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeConfigTxn -> {
futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeInvTxn -> {
final VpnInterface vpnIf = VpnUtil.getConfiguredVpnInterface(dataBroker, ifName);
if (vpnIf != null) {
final int ifIndex = update.getIfIndex();
BigInteger dpnId = BigInteger.ZERO;
try {
dpnId = InterfaceUtils.getDpIdFromInterface(update);
} catch (Exception e) {
LOG.error("remove: Unable to retrieve dpnId for interface {}", ifName, e);
return;
}
if (update.getOperStatus().equals(Interface.OperStatus.Up)) {
for (VpnInstanceNames vpnInterfaceVpnInstance : vpnIf.getVpnInstanceNames()) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
String primaryRd = VpnUtil.getPrimaryRd(dataBroker, vpnName);
if (!vpnInterfaceManager.isVpnInstanceReady(vpnName)) {
LOG.error("VPN Interface update event - intfName {} onto vpnName {} " + "running oper-driven UP, VpnInstance not ready," + " holding on", vpnIf.getName(), vpnName);
} else if (VpnUtil.isVpnPendingDelete(dataBroker, primaryRd)) {
LOG.error("update: Ignoring UP event for vpnInterface {}, as " + "vpnInstance {} with primaryRd {} is already marked for" + " deletion", vpnIf.getName(), vpnName, primaryRd);
} else {
vpnInterfaceManager.processVpnInterfaceUp(dpnId, vpnIf, primaryRd, ifIndex, true, writeConfigTxn, writeOperTxn, writeInvTxn, update, vpnName);
}
}
} else if (update.getOperStatus().equals(Interface.OperStatus.Down)) {
for (VpnInstanceNames vpnInterfaceVpnInstance : vpnIf.getVpnInstanceNames()) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
LOG.info("VPN Interface update event - intfName {} onto vpnName {}" + " running oper-driven DOWN", vpnIf.getName(), vpnName);
Optional<VpnInterfaceOpDataEntry> optVpnInterface = VpnUtil.getVpnInterfaceOpDataEntry(dataBroker, vpnIf.getName(), vpnName);
if (optVpnInterface.isPresent()) {
VpnInterfaceOpDataEntry vpnOpInterface = optVpnInterface.get();
vpnInterfaceManager.processVpnInterfaceDown(dpnId, vpnIf.getName(), ifIndex, update.getPhysAddress().getValue(), vpnOpInterface, true, writeConfigTxn, writeOperTxn, writeInvTxn);
} else {
LOG.error("InterfaceStateChangeListener Update DOWN - vpnInterface {}" + " not available, ignoring event", vpnIf.getName());
continue;
}
}
}
} else {
LOG.debug("Interface {} is not a vpninterface, ignoring.", ifName);
}
}));
}));
}));
return futures;
});
}
} catch (Exception e) {
LOG.error("Exception observed in handling updation of VPN Interface {}. ", update.getName(), e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update in project netvirt by opendaylight.
the class TunnelInterfaceStateListener method update.
@Override
protected void update(InstanceIdentifier<StateTunnelList> identifier, StateTunnelList original, StateTunnelList update) {
LOG.trace("update: Tunnel updation---- {}", update);
LOG.info("update: ITM Tunnel {} of type {} state event changed from :{} to :{}", update.getTunnelInterfaceName(), fibManager.getTransportTypeStr(update.getTransportType().toString()), original.getOperState(), update.getOperState());
TunnelOperStatus tunOpStatus = update.getOperState();
if (tunOpStatus != TunnelOperStatus.Down && tunOpStatus != TunnelOperStatus.Up) {
LOG.info("update: Returning from unsupported tunnelOperStatus {} for tunnel interface {}", tunOpStatus, update.getTunnelInterfaceName());
return;
}
if (isGreTunnel(update)) {
programDcGwLoadBalancingGroup(update, NwConstants.MOD_FLOW);
}
// Remove the corresponding nexthop from the routepath under extraroute in fibentries.
BigInteger srcDpnId = new BigInteger(update.getSrcInfo().getTepDeviceId());
String srcTepIp = String.valueOf(update.getSrcInfo().getTepIp().getValue());
List<VpnInstanceOpDataEntry> vpnInstanceOpData = VpnUtil.getAllVpnInstanceOpData(dataBroker);
if (vpnInstanceOpData == null) {
LOG.trace("update: No vpnInstanceOpdata present");
return;
}
WriteTransaction writeConfigTxn = dataBroker.newWriteOnlyTransaction();
if (tunOpStatus == TunnelOperStatus.Up) {
handleTunnelEventForDPN(update, TunnelAction.TUNNEL_EP_ADD);
} else {
vpnInstanceOpData.stream().filter(opData -> {
if (opData.getVpnToDpnList() == null) {
return false;
}
return opData.getVpnToDpnList().stream().anyMatch(vpnToDpn -> vpnToDpn.getDpnId().equals(srcDpnId));
}).forEach(opData -> {
List<DestPrefixes> prefixes = VpnExtraRouteHelper.getExtraRouteDestPrefixes(dataBroker, opData.getVpnId());
prefixes.forEach(destPrefix -> {
VrfEntry vrfEntry = VpnUtil.getVrfEntry(dataBroker, opData.getVrfId(), destPrefix.getDestPrefix());
if (vrfEntry == null || vrfEntry.getRoutePaths() == null) {
return;
}
List<RoutePaths> routePaths = vrfEntry.getRoutePaths();
routePaths.forEach(routePath -> {
if (routePath.getNexthopAddress().equals(srcTepIp)) {
fibManager.updateRoutePathForFibEntry(opData.getVrfId(), destPrefix.getDestPrefix(), srcTepIp, routePath.getLabel(), false, writeConfigTxn);
}
});
});
});
}
writeConfigTxn.submit();
}
Aggregations