use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey in project netvirt by opendaylight.
the class VpnElanInterfaceChangeListener method add.
@Override
protected void add(InstanceIdentifier<ElanInterface> key, ElanInterface elanInterface) {
String interfaceName = elanInterface.getName();
if (!elanService.isExternalInterface(interfaceName)) {
LOG.debug("add: Interface {} is not external. Ignoring", interfaceName);
return;
}
Uuid networkId;
try {
networkId = new Uuid(elanInterface.getElanInstanceName());
} catch (IllegalArgumentException e) {
LOG.debug("add: ELAN instance {} for interface {} is not Uuid", elanInterface.getElanInstanceName(), elanInterface.getName());
return;
}
Uuid vpnId = VpnUtil.getExternalNetworkVpnId(broker, networkId);
if (vpnId == null) {
LOG.debug("add: Network {} is not external or vpn-id missing. Ignoring interface {} on elan {}", networkId.getValue(), elanInterface.getName(), elanInterface.getElanInstanceName());
return;
}
VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
List<VpnInstanceNames> listVpn = new ArrayList<>();
listVpn.add(vpnInstance);
VpnInterface vpnInterface = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(interfaceName)).setVpnInstanceNames(listVpn).setScheduledForRemove(Boolean.FALSE).build();
InstanceIdentifier<VpnInterface> vpnInterfaceIdentifier = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
VpnUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, vpnInterfaceIdentifier, vpnInterface);
LOG.info("add: Added VPN interface {} with VPN-id {} elanInstance {}", interfaceName, vpnId.getValue(), elanInterface.getElanInstanceName());
}
use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey in project netvirt by opendaylight.
the class VpnInterfaceManager method remove.
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public void remove(InstanceIdentifier<VpnInterface> identifier, VpnInterface vpnInterface) {
final VpnInterfaceKey key = identifier.firstKeyOf(VpnInterface.class, VpnInterfaceKey.class);
final String interfaceName = key.getName();
for (VpnInstanceNames vpnInterfaceVpnInstance : vpnInterface.getVpnInstanceNames()) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
removeVpnInterfaceCall(identifier, vpnInterface, vpnName, interfaceName);
}
}
use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey 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.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey 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.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey in project netvirt by opendaylight.
the class VpnInterfaceManager method handleVpnSwapForVpnInterface.
private boolean handleVpnSwapForVpnInterface(InstanceIdentifier<VpnInterface> identifier, VpnInterface original, VpnInterface update) {
boolean isSwap = Boolean.FALSE;
final VpnInterfaceKey key = identifier.firstKeyOf(VpnInterface.class, VpnInterfaceKey.class);
final String interfaceName = key.getName();
List<String> oldVpnList = original.getVpnInstanceNames().stream().map(VpnInstanceNames::getVpnName).collect(Collectors.toList());
List<String> oldVpnListCopy = new ArrayList<>();
oldVpnListCopy.addAll(oldVpnList);
List<String> newVpnList = update.getVpnInstanceNames().stream().map(VpnInstanceNames::getVpnName).collect(Collectors.toList());
oldVpnList.removeAll(newVpnList);
newVpnList.removeAll(oldVpnListCopy);
if (!oldVpnList.isEmpty() || !newVpnList.isEmpty()) {
for (String oldVpnName : oldVpnList) {
isSwap = Boolean.TRUE;
LOG.info("handleVpnSwapForVpnInterface: VPN Interface update event - intfName {} remove vpnName {}" + " running config-driven swap removal", interfaceName, oldVpnName);
removeVpnInterfaceCall(identifier, original, oldVpnName, interfaceName);
LOG.info("handleVpnSwapForVpnInterface: Processed Remove for update on VPNInterface {} upon VPN swap" + "from old vpn {} to newVpn(s) {}", interfaceName, oldVpnName, newVpnList);
}
// Wait for previous interface bindings to be removed
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// Ignore
}
for (String newVpnName : newVpnList) {
String primaryRd = VpnUtil.getPrimaryRd(dataBroker, newVpnName);
isSwap = Boolean.TRUE;
if (!VpnUtil.isVpnPendingDelete(dataBroker, primaryRd)) {
LOG.info("handleVpnSwapForVpnInterface: VPN Interface update event - intfName {} onto vpnName {}" + "running config-driven swap addition", interfaceName, newVpnName);
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<>();
addVpnInterfaceCall(identifier, update, oldAdjs, newAdjs, newVpnName);
LOG.info("handleVpnSwapForVpnInterface: Processed Add for update on VPNInterface {}" + "from oldVpn(s) {} to newVpn {} upon VPN swap", interfaceName, oldVpnListCopy, newVpnName);
}
}
}
return isSwap;
}
Aggregations