use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.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;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterfaceKey in project netvirt by opendaylight.
the class CoeUtils method createVpnInterface.
public static void createVpnInterface(String vpnName, Pods pod, String interfaceName, String macAddress, boolean isRouterInterface, WriteTransaction wrtConfigTxn) {
LOG.trace("createVpnInterface for Port: {}, isRouterInterface: {}", interfaceName, isRouterInterface);
List<VpnInstanceNames> listVpn = new ArrayList<>();
listVpn.add(new VpnInstanceNamesBuilder().setKey(new VpnInstanceNamesKey(vpnName)).setVpnName(vpnName).setAssociatedSubnetType(VpnInstanceNames.AssociatedSubnetType.V4Subnet).build());
VpnInterfaceBuilder vpnb = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(interfaceName)).setName(interfaceName).setVpnInstanceNames(listVpn).setRouterInterface(isRouterInterface);
Adjacencies adjs = createPortIpAdjacencies(pod, interfaceName, macAddress, isRouterInterface);
if (adjs != null) {
vpnb.addAugmentation(Adjacencies.class, adjs);
}
VpnInterface vpnIf = vpnb.build();
LOG.info("Creating vpn interface {}", vpnIf);
InstanceIdentifier<VpnInterface> vpnIfIdentifier = buildVpnInterfaceIdentifier(interfaceName);
wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterfaceKey in project netvirt by opendaylight.
the class NeutronvpnManager method writeVpnInterfaceToDs.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void writeVpnInterfaceToDs(@Nonnull Collection<Uuid> vpnIdList, String infName, Adjacencies adjacencies, Boolean isRouterInterface, WriteTransaction wrtConfigTxn) {
if (vpnIdList.isEmpty() || infName == null) {
LOG.error("vpn id or interface is null");
return;
}
List<VpnInstanceNames> vpnIdListStruct = new ArrayList<>();
for (Uuid vpnId : vpnIdList) {
VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
vpnIdListStruct.add(vpnInstance);
}
Boolean wrtConfigTxnPresent = true;
if (wrtConfigTxn == null) {
wrtConfigTxnPresent = false;
wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
}
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
VpnInterfaceBuilder vpnb = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(infName)).setName(infName).setVpnInstanceNames(vpnIdListStruct).setRouterInterface(isRouterInterface);
if (adjacencies != null) {
vpnb.addAugmentation(Adjacencies.class, adjacencies);
}
VpnInterface vpnIf = vpnb.build();
try {
LOG.info("Creating vpn interface {}", vpnIf);
wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
} catch (Exception ex) {
LOG.error("Creation of vpninterface {} failed", infName, ex);
}
if (!wrtConfigTxnPresent) {
wrtConfigTxn.submit();
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterfaceKey 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.VpnInterfaceKey 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