use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnInterface.
protected void updateVpnInterface(Uuid vpnId, Uuid oldVpnId, Port port, boolean isBeingAssociated, boolean isSubnetIp, WriteTransaction writeConfigTxn) {
if (vpnId == null || port == null) {
return;
}
boolean isLockAcquired = false;
String infName = port.getUuid().getValue();
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
try {
isLockAcquired = interfaceLock.tryLock(infName, LOCK_WAIT_TIME, TimeUnit.SECONDS);
Optional<VpnInterface> optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
if (optionalVpnInterface.isPresent()) {
VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
List<VpnInstanceNames> listVpn = new ArrayList<>(optionalVpnInterface.get().getVpnInstanceNames());
if (oldVpnId != null && VpnHelper.doesVpnInterfaceBelongToVpnInstance(oldVpnId.getValue(), listVpn)) {
VpnHelper.removeVpnInterfaceVpnInstanceNamesFromList(oldVpnId.getValue(), listVpn);
}
if (vpnId.getValue() != null && !VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnId.getValue(), listVpn)) {
listVpn.add(vpnInstance);
}
VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get()).setVpnInstanceNames(listVpn);
LOG.debug("Updating vpn interface {}", infName);
if (!isBeingAssociated) {
Adjacencies adjs = vpnIfBuilder.getAugmentation(Adjacencies.class);
List<Adjacency> adjacencyList = adjs != null ? adjs.getAdjacency() : new ArrayList<>();
Iterator<Adjacency> adjacencyIter = adjacencyList.iterator();
while (adjacencyIter.hasNext()) {
Adjacency adjacency = adjacencyIter.next();
String mipToQuery = adjacency.getIpAddress().split("/")[0];
InstanceIdentifier<LearntVpnVipToPort> id = NeutronvpnUtils.buildLearntVpnVipToPortIdentifier(oldVpnId.getValue(), mipToQuery);
Optional<LearntVpnVipToPort> optionalVpnVipToPort = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (optionalVpnVipToPort.isPresent()) {
LOG.trace("Removing adjacencies from vpninterface {} upon dissociation of router {} " + "from VPN {}", infName, vpnId, oldVpnId);
adjacencyIter.remove();
neutronvpnUtils.removeLearntVpnVipToPort(oldVpnId.getValue(), mipToQuery);
LOG.trace("Entry for fixedIP {} for port {} on VPN {} removed from VpnPortFixedIPToPortData", mipToQuery, infName, vpnId.getValue());
}
}
Adjacencies adjacencies = new AdjacenciesBuilder().setAdjacency(adjacencyList).build();
vpnIfBuilder.addAugmentation(Adjacencies.class, adjacencies);
}
List<FixedIps> ips = port.getFixedIps();
for (FixedIps ip : ips) {
String ipValue = String.valueOf(ip.getIpAddress().getValue());
if (oldVpnId != null) {
neutronvpnUtils.removeVpnPortFixedIpToPort(oldVpnId.getValue(), ipValue, writeConfigTxn);
}
neutronvpnUtils.createVpnPortFixedIpToPort(vpnId.getValue(), ipValue, infName, port.getMacAddress().getValue(), isSubnetIp, writeConfigTxn);
}
writeConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder.build());
} else {
LOG.error("VPN Interface {} not found", infName);
}
} catch (ReadFailedException ex) {
LOG.error("Updation of vpninterface {} failed", infName, ex);
} finally {
if (isLockAcquired) {
interfaceLock.unlock(infName);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface in project netvirt by opendaylight.
the class VpnUtil method getVpnHandlingIpv4AssociatedWithInterface.
public Optional<List<String>> getVpnHandlingIpv4AssociatedWithInterface(String interfaceName) {
InstanceIdentifier<VpnInterface> interfaceId = getVpnInterfaceIdentifier(interfaceName);
Optional<List<String>> vpnOptional = Optional.empty();
Optional<VpnInterface> optConfiguredVpnInterface = read(LogicalDatastoreType.CONFIGURATION, interfaceId);
if (optConfiguredVpnInterface.isPresent()) {
VpnInterface cfgVpnInterface = optConfiguredVpnInterface.get();
java.util.Optional<List<VpnInstanceNames>> optVpnInstanceList = java.util.Optional.ofNullable(new ArrayList<>(cfgVpnInterface.nonnullVpnInstanceNames().values()));
if (optVpnInstanceList.isPresent()) {
List<String> vpnList = new ArrayList<>();
for (VpnInstanceNames vpnInstance : optVpnInstanceList.get()) {
vpnList.add(vpnInstance.getVpnName());
}
vpnOptional = Optional.of(vpnList);
}
}
return vpnOptional;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface in project netvirt by opendaylight.
the class VpnUtil method removeMipAdjAndLearntIp.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void removeMipAdjAndLearntIp(String vpnName, String vpnInterface, String prefix) {
final ReentrantLock lock = lockFor(vpnName, prefix);
lock.lock();
try {
String ip = VpnUtil.getIpPrefix(prefix);
InstanceIdentifier<VpnInterfaceOpDataEntry> vpnInterfaceOpId = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(vpnInterface, vpnName);
InstanceIdentifier<AdjacenciesOp> path = vpnInterfaceOpId.augmentation(AdjacenciesOp.class);
Optional<AdjacenciesOp> adjacenciesOp = read(LogicalDatastoreType.OPERATIONAL, path);
if (adjacenciesOp.isPresent()) {
InstanceIdentifier<Adjacency> adjacencyIdentifier = InstanceIdentifier.builder(VpnInterfaces.class).child(VpnInterface.class, new VpnInterfaceKey(vpnInterface)).augmentation(Adjacencies.class).child(Adjacency.class, new AdjacencyKey(ip)).build();
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, adjacencyIdentifier);
LOG.info("removeMipAdjAndLearntIp: Successfully Deleted Adjacency {} from interface {} vpn {}", ip, vpnInterface, vpnName);
}
InstanceIdentifier<LearntVpnVipToPort> id = buildLearntVpnVipToPortIdentifier(vpnName, prefix);
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
LOG.info("removeMipAdjAndLearntIp: Delete learned ARP for fixedIp: {}, vpn {} removed from" + "VpnPortipToPort DS", prefix, vpnName);
} catch (Exception e) {
LOG.error("removeMipAdjAndLearntIp: Exception Deleting learned Ip: {} interface {} vpn {} from " + "LearntVpnPortipToPort DS", prefix, vpnInterface, vpnName, e);
} finally {
lock.unlock();
}
VpnUtil.removeVpnPortFixedIpToPort(dataBroker, vpnName, prefix, null);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface in project netvirt by opendaylight.
the class InterfaceStateChangeListener method add.
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public 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<?>> futures = new ArrayList<>(3);
futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, writeInvTxn -> {
// map of prefix and vpn name used, as entry in prefix-to-interface datastore
// is prerequisite for refresh Fib to avoid race condition leading to missing remote next hop
// in bucket actions on bgp-vpn delete
Map<String, Set<String>> mapOfRdAndPrefixesForRefreshFib = new HashMap<>();
ListenableFuture<?> configFuture = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, writeConfigTxn -> {
ListenableFuture<?> operFuture = txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, writeOperTxn -> {
final String interfaceName = intrf.getName();
LOG.info("Detected interface add event for interface {}", interfaceName);
final VpnInterface vpnIf = vpnUtil.getConfiguredVpnInterface(interfaceName);
if (vpnIf != null) {
for (VpnInstanceNames vpnInterfaceVpnInstance : vpnIf.nonnullVpnInstanceNames().values()) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
String primaryRd = vpnUtil.getPrimaryRd(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(primaryRd)) {
LOG.error("add: Ignoring addition of vpnInterface {}, as" + " vpnInstance {} with primaryRd {} is already marked for" + " deletion", interfaceName, vpnName, primaryRd);
} else {
Uint64 intfDpnId = Uint64.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;
}
LOG.error("InterfaceStateChangeListener- Processing ifState" + " {} add event with dpnId {}", intrf.getName(), intfDpnId);
final Uint64 dpnId = intfDpnId;
final int ifIndex = intrf.getIfIndex();
LOG.info("VPN Interface add event - intfName {} onto vpnName {}" + " running oper-driven", vpnIf.getName(), vpnName);
Set<String> prefixes = new HashSet<>();
vpnInterfaceManager.processVpnInterfaceUp(dpnId, vpnIf, primaryRd, ifIndex, false, writeConfigTxn, writeOperTxn, writeInvTxn, intrf, vpnName, prefixes);
mapOfRdAndPrefixesForRefreshFib.put(primaryRd, prefixes);
}
}
}
});
futures.add(operFuture);
// Synchronous submit of operTxn
operFuture.get();
});
Futures.addCallback(configFuture, new VpnInterfaceCallBackHandler(mapOfRdAndPrefixesForRefreshFib), MoreExecutors.directExecutor());
futures.add(configFuture);
// TODO: Allow immediateFailedFuture from writeCfgTxn to cancel writeInvTxn as well.
Futures.addCallback(configFuture, new PostVpnInterfaceThreadWorker(intrf.getName(), true, "Operational"), MoreExecutors.directExecutor());
}));
return futures;
});
}
} catch (Exception e) {
LOG.error("Exception caught in Interface {} Operational State Up event", intrf.getName(), e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface in project netvirt by opendaylight.
the class NeutronvpnNatManager method removeAdjacencyAndLearnedEntriesforExternalSubnet.
private void removeAdjacencyAndLearnedEntriesforExternalSubnet(Uuid extNetId, Uuid extSubnetId) {
Collection<String> extElanInterfaces = elanService.getExternalElanInterfaces(extNetId.getValue());
if (extElanInterfaces == null || extElanInterfaces.isEmpty()) {
LOG.error("No external ports attached to external network {}", extNetId.getValue());
return;
}
for (String infName : extElanInterfaces) {
InstanceIdentifier<VpnInterface> vpnIfIdentifier = InstanceIdentifier.builder(VpnInterfaces.class).child(VpnInterface.class, new VpnInterfaceKey(infName)).build();
InstanceIdentifier<Adjacencies> adjacenciesIdentifier = vpnIfIdentifier.augmentation(Adjacencies.class);
try {
// Looking for existing prefix in MDSAL database
Optional<Adjacencies> optionalAdjacencies = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, adjacenciesIdentifier);
if (optionalAdjacencies.isPresent()) {
Map<AdjacencyKey, Adjacency> keyAdjacencyMap = optionalAdjacencies.get().nonnullAdjacency();
Iterator<Adjacency> adjacencyIter = keyAdjacencyMap.values().iterator();
while (adjacencyIter.hasNext()) {
Adjacency adjacency = adjacencyIter.next();
if (!adjacency.getSubnetId().equals(extSubnetId)) {
continue;
}
InstanceIdentifier<Adjacency> adjacencyIdentifier = adjacenciesIdentifier.child(Adjacency.class, new AdjacencyKey(adjacency.getIpAddress()));
SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, adjacencyIdentifier);
LOG.trace("Removed Adjacency for fixedIP {} for port {} on external subnet {} ", adjacency.getIpAddress(), infName, extSubnetId);
String extNetVpnName = extNetId.getValue();
String learnedSrcIp = adjacency.getIpAddress().split("/")[0];
InstanceIdentifier<LearntVpnVipToPort> id = NeutronvpnUtils.buildLearntVpnVipToPortIdentifier(extNetVpnName, learnedSrcIp);
Optional<LearntVpnVipToPort> optionalLearntVpnVipToPort = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (optionalLearntVpnVipToPort.isPresent()) {
neutronvpnUtils.removeLearntVpnVipToPort(extNetVpnName, learnedSrcIp);
LOG.trace("Removed Learnt Entry for fixedIP {} for port {}", adjacency.getIpAddress(), infName);
}
}
}
} catch (TransactionCommitFailedException | ExecutionException | InterruptedException e) {
LOG.error("exception in removeAdjacencyAndLearnedEntriesforExternalSubnet for interface {}", infName, e);
}
}
}
Aggregations