use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry in project netvirt by opendaylight.
the class VpnInterfaceManager method addNewAdjToVpnInterface.
protected void addNewAdjToVpnInterface(InstanceIdentifier<VpnInterfaceOpDataEntry> identifier, String primaryRd, Adjacency adj, BigInteger dpnId, WriteTransaction writeOperTxn, WriteTransaction writeConfigTxn) {
Optional<VpnInterfaceOpDataEntry> optVpnInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier);
if (optVpnInterface.isPresent()) {
VpnInterfaceOpDataEntry currVpnIntf = optVpnInterface.get();
String prefix = VpnUtil.getIpPrefix(adj.getIpAddress());
String vpnName = currVpnIntf.getVpnInstanceName();
VpnInstanceOpDataEntry vpnInstanceOpData = VpnUtil.getVpnInstanceOpData(dataBroker, primaryRd);
InstanceIdentifier<AdjacenciesOp> adjPath = identifier.augmentation(AdjacenciesOp.class);
Optional<AdjacenciesOp> optAdjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, adjPath);
boolean isL3VpnOverVxLan = VpnUtil.isL3VpnOverVxLan(vpnInstanceOpData.getL3vni());
VrfEntry.EncapType encapType = VpnUtil.getEncapType(isL3VpnOverVxLan);
long l3vni = vpnInstanceOpData.getL3vni() == null ? 0L : vpnInstanceOpData.getL3vni();
VpnPopulator populator = L3vpnRegistry.getRegisteredPopulator(encapType);
List<Adjacency> adjacencies;
if (optAdjacencies.isPresent()) {
adjacencies = optAdjacencies.get().getAdjacency();
} else {
// This code will be hit in case of first PNF adjacency
adjacencies = new ArrayList<>();
}
long vpnId = VpnUtil.getVpnId(dataBroker, vpnName);
L3vpnInput input = new L3vpnInput().setNextHop(adj).setVpnName(vpnName).setInterfaceName(currVpnIntf.getName()).setPrimaryRd(primaryRd).setRd(primaryRd);
Adjacency operationalAdjacency = null;
if (adj.getNextHopIpList() != null && !adj.getNextHopIpList().isEmpty()) {
RouteOrigin origin = adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency ? RouteOrigin.LOCAL : RouteOrigin.STATIC;
String nh = adj.getNextHopIpList().get(0);
String vpnPrefixKey = VpnUtil.getVpnNamePrefixKey(vpnName, prefix);
synchronized (vpnPrefixKey.intern()) {
java.util.Optional<String> rdToAllocate = VpnUtil.allocateRdForExtraRouteAndUpdateUsedRdsMap(dataBroker, vpnId, null, prefix, vpnName, nh, dpnId);
if (rdToAllocate.isPresent()) {
input.setRd(rdToAllocate.get());
operationalAdjacency = populator.createOperationalAdjacency(input);
int label = operationalAdjacency.getLabel().intValue();
vpnManager.addExtraRoute(vpnName, adj.getIpAddress(), nh, rdToAllocate.get(), currVpnIntf.getVpnInstanceName(), l3vni, origin, currVpnIntf.getName(), operationalAdjacency, encapType, writeConfigTxn);
LOG.info("addNewAdjToVpnInterface: Added extra route ip {} nh {} rd {} vpnname {} label {}" + " Interface {} on dpn {}", adj.getIpAddress(), nh, rdToAllocate.get(), vpnName, label, currVpnIntf.getName(), dpnId);
} else {
LOG.error("addNewAdjToVpnInterface: No rds to allocate extraroute vpn {} prefix {}", vpnName, prefix);
return;
}
// Keeping the MPLS check for now.
if (encapType.equals(VrfEntryBase.EncapType.Mplsgre)) {
final Adjacency opAdjacency = new AdjacencyBuilder(operationalAdjacency).build();
List<VpnInstanceOpDataEntry> vpnsToImportRoute = VpnUtil.getVpnsImportingMyRoute(dataBroker, vpnName);
vpnsToImportRoute.forEach(vpn -> {
if (vpn.getVrfId() != null) {
VpnUtil.allocateRdForExtraRouteAndUpdateUsedRdsMap(dataBroker, vpn.getVpnId(), vpnId, prefix, VpnUtil.getVpnName(dataBroker, vpn.getVpnId()), nh, dpnId).ifPresent(rds -> vpnManager.addExtraRoute(VpnUtil.getVpnName(dataBroker, vpn.getVpnId()), adj.getIpAddress(), nh, rds, currVpnIntf.getVpnInstanceName(), l3vni, RouteOrigin.SELF_IMPORTED, currVpnIntf.getName(), opAdjacency, encapType, writeConfigTxn));
}
});
}
}
} else if (adj.isPhysNetworkFunc()) {
// PNF adjacency.
LOG.trace("addNewAdjToVpnInterface: Adding prefix {} to interface {} for vpn {}", prefix, currVpnIntf.getName(), vpnName);
String parentVpnRd = getParentVpnRdForExternalSubnet(adj);
writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(VpnUtil.getVpnId(dataBroker, adj.getSubnetId().getValue()), prefix), VpnUtil.getPrefixToInterface(BigInteger.ZERO, currVpnIntf.getName(), prefix, adj.getSubnetId(), Prefixes.PrefixCue.PhysNetFunc), true);
fibManager.addOrUpdateFibEntry(adj.getSubnetId().getValue(), adj.getMacAddress(), adj.getIpAddress(), Collections.emptyList(), null, /* EncapType */
0, /* label */
0, /*l3vni*/
null, /* gw-mac */
parentVpnRd, RouteOrigin.LOCAL, writeConfigTxn);
input.setRd(adj.getVrfId());
}
if (operationalAdjacency == null) {
operationalAdjacency = populator.createOperationalAdjacency(input);
}
adjacencies.add(operationalAdjacency);
AdjacenciesOp aug = VpnUtil.getVpnInterfaceOpDataEntryAugmentation(adjacencies);
VpnInterfaceOpDataEntry newVpnIntf = VpnUtil.getVpnInterfaceOpDataEntry(currVpnIntf.getName(), currVpnIntf.getVpnInstanceName(), aug, dpnId, currVpnIntf.isScheduledForRemove(), currVpnIntf.getLportTag(), currVpnIntf.getGatewayMacAddress());
writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, identifier, newVpnIntf, true);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry 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.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry in project netvirt by opendaylight.
the class VpnInterfaceManager method processSavedInterface.
private void processSavedInterface(UnprocessedVpnInterfaceData intefaceData, String vpnName) {
if (!canHandleNewVpnInterface(intefaceData.identifier, intefaceData.vpnInterface, vpnName)) {
LOG.error("add: VpnInstance {} for vpnInterface {} not ready, holding on ", vpnName, intefaceData.vpnInterface.getName());
return;
}
final VpnInterfaceKey key = intefaceData.identifier.firstKeyOf(VpnInterface.class, VpnInterfaceKey.class);
final String interfaceName = key.getName();
InstanceIdentifier<VpnInterfaceOpDataEntry> vpnInterfaceOpIdentifier = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
addVpnInterfaceToVpn(vpnInterfaceOpIdentifier, intefaceData.vpnInterface, null, null, intefaceData.identifier, vpnName);
return;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry in project netvirt by opendaylight.
the class VpnInterfaceOpListener method remove.
@Override
protected void remove(final InstanceIdentifier<VpnInterfaceOpDataEntry> identifier, final VpnInterfaceOpDataEntry del) {
final VpnInterfaceOpDataEntryKey key = identifier.firstKeyOf(VpnInterfaceOpDataEntry.class, VpnInterfaceOpDataEntryKey.class);
final String interfaceName = key.getName();
jobCoordinator.enqueueJob("VPNINTERFACE-" + interfaceName, () -> {
WriteTransaction writeOperTxn = dataBroker.newWriteOnlyTransaction();
postProcessVpnInterfaceRemoval(identifier, del, writeOperTxn);
List<ListenableFuture<Void>> futures = new ArrayList<>();
futures.add(writeOperTxn.submit());
LOG.info("remove: Removed vpn operational data for interface {} on dpn {} vpn {}", del.getName(), del.getDpnId(), del.getVpnInstanceName());
return futures;
});
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry 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);
}
}
Aggregations