use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames in project netvirt by opendaylight.
the class NeutronvpnManager method removeVpnFromVpnInterface.
protected void removeVpnFromVpnInterface(Uuid vpnId, Port port, WriteTransaction writeConfigTxn, Subnetmap sm) {
if (vpnId == null || port == null) {
return;
}
String infName = port.getUuid().getValue();
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
try {
Optional<VpnInterface> optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
if (optionalVpnInterface.isPresent()) {
List<VpnInstanceNames> listVpn = optionalVpnInterface.get().getVpnInstanceNames();
if (listVpn != null && VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnId.getValue(), listVpn)) {
VpnHelper.removeVpnInterfaceVpnInstanceNamesFromList(vpnId.getValue(), listVpn);
}
VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get()).setVpnInstanceNames(listVpn);
Adjacencies adjs = vpnIfBuilder.getAugmentation(Adjacencies.class);
LOG.debug("Updating vpn interface {}", infName);
List<Adjacency> adjacencyList = adjs != null ? adjs.getAdjacency() : new ArrayList<>();
Iterator<Adjacency> adjacencyIter = adjacencyList.iterator();
while (adjacencyIter.hasNext()) {
Adjacency adjacency = adjacencyIter.next();
if (adjacency.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
continue;
}
String mipToQuery = adjacency.getIpAddress().split("/")[0];
InstanceIdentifier<LearntVpnVipToPort> id = NeutronvpnUtils.buildLearntVpnVipToPortIdentifier(vpnId.getValue(), mipToQuery);
Optional<LearntVpnVipToPort> optionalVpnVipToPort = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (optionalVpnVipToPort.isPresent()) {
LOG.trace("Removing adjacencies from vpninterface {} upon dissociation of router {}", infName, vpnId);
if (listVpn == null || listVpn.isEmpty()) {
adjacencyIter.remove();
}
neutronvpnUtils.removeLearntVpnVipToPort(vpnId.getValue(), mipToQuery);
LOG.trace("Entry for fixedIP {} for port {} on VPN {} removed from VpnPortFixedIPToPortData", mipToQuery, infName, vpnId.getValue());
}
}
List<FixedIps> ips = port.getFixedIps();
for (FixedIps ip : ips) {
String ipValue = String.valueOf(ip.getIpAddress().getValue());
neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipValue, writeConfigTxn);
}
if (listVpn == null || listVpn.isEmpty()) {
if (sm != null && sm.getRouterId() != null) {
removeFromNeutronRouterInterfacesMap(sm.getRouterId(), port.getUuid().getValue());
}
deleteVpnInterface(port.getUuid().getValue(), null, /* vpn-id */
writeConfigTxn);
} else {
writeConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder.build());
}
} else {
LOG.info("removeVpnFromVpnInterface: VPN Interface {} not found", infName);
}
} catch (ReadFailedException ex) {
LOG.error("Update of vpninterface {} failed", infName, ex);
}
}
use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames in project netvirt by opendaylight.
the class NeutronvpnManager method deleteVpnInterface.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected boolean deleteVpnInterface(String infName, @Nullable String vpnId, WriteTransaction wrtConfigTxn) {
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
Optional<VpnInterface> optionalVpnInterface = null;
try {
optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
} catch (ReadFailedException ex) {
LOG.error("Error during deletion of vpninterface {}", infName, ex);
return false;
}
if (!optionalVpnInterface.isPresent()) {
LOG.warn("Deletion of vpninterface {}, optionalVpnInterface is not present()", infName);
return false;
}
boolean wrtConfigTxnPresent = true;
if (wrtConfigTxn == null) {
wrtConfigTxnPresent = false;
wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
}
if (vpnId != null) {
VpnInterface vpnInterface = optionalVpnInterface.get();
List<VpnInstanceNames> vpnList = vpnInterface.getVpnInstanceNames();
if (vpnList != null && VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnId, vpnList)) {
VpnHelper.removeVpnInterfaceVpnInstanceNamesFromList(vpnId, vpnList);
if (!vpnList.isEmpty()) {
if (!wrtConfigTxnPresent) {
wrtConfigTxn.submit();
}
LOG.debug("Deleting vpn interface {} not immediately since vpnInstanceName " + "List not empty", infName);
return false;
}
VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get()).setVpnInstanceNames(vpnList);
wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder.build());
}
}
LOG.debug("Deleting vpn interface {}", infName);
wrtConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
if (!wrtConfigTxnPresent) {
wrtConfigTxn.submit();
}
return true;
}
use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames 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.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames in project netvirt by opendaylight.
the class VpnUtil method getVpnHandlingIpv4AssociatedWithInterface.
static Optional<List<String>> getVpnHandlingIpv4AssociatedWithInterface(DataBroker broker, String interfaceName) {
InstanceIdentifier<VpnInterface> interfaceId = getVpnInterfaceIdentifier(interfaceName);
Optional<List<String>> vpnOptional = Optional.absent();
Optional<VpnInterface> optConfiguredVpnInterface = read(broker, LogicalDatastoreType.CONFIGURATION, interfaceId);
if (optConfiguredVpnInterface.isPresent()) {
VpnInterface cfgVpnInterface = optConfiguredVpnInterface.get();
java.util.Optional<List<VpnInstanceNames>> optVpnInstanceList = java.util.Optional.ofNullable(cfgVpnInterface.getVpnInstanceNames());
if (optVpnInstanceList.isPresent()) {
List<String> vpnList = new ArrayList<>();
for (VpnInstanceNames vpnInstance : optVpnInstanceList.get()) {
if (vpnInstance.getAssociatedSubnetType().equals(AssociatedSubnetType.V6Subnet)) {
continue;
}
vpnList.add(vpnInstance.getVpnName());
}
vpnOptional = Optional.of(vpnList);
}
}
return vpnOptional;
}
use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames in project netvirt by opendaylight.
the class L3vpnPopulator method addToLabelMapper.
public void addToLabelMapper(Long label, BigInteger dpnId, String prefix, List<String> nextHopIpList, Long vpnId, String vpnInterfaceName, Long elanTag, boolean isSubnetRoute, String rd) {
Preconditions.checkNotNull(label, "addToLabelMapper: label cannot be null or empty!");
Preconditions.checkNotNull(prefix, "addToLabelMapper: prefix cannot be null or empty!");
Preconditions.checkNotNull(vpnId, "addToLabelMapper: vpnId cannot be null or empty!");
Preconditions.checkNotNull(rd, "addToLabelMapper: rd cannot be null or empty!");
if (!isSubnetRoute) {
// NextHop must be present for non-subnetroute entries
Preconditions.checkNotNull(nextHopIpList, "addToLabelMapper: nextHopIp cannot be null or empty!");
}
synchronized (label.toString().intern()) {
addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
LOG.info("addToLabelMapper: label {} dpn {} prefix {} nexthoplist {} vpnid {} vpnIntfcName {} rd {}" + " elanTag {}", label, dpnId, prefix, nextHopIpList, vpnId, vpnInterfaceName, rd, elanTag);
if (dpnId != null) {
LabelRouteInfoBuilder lriBuilder = new LabelRouteInfoBuilder();
lriBuilder.setLabel(label).setDpnId(dpnId).setPrefix(prefix).setNextHopIpList(nextHopIpList).setParentVpnid(vpnId).setIsSubnetRoute(isSubnetRoute);
if (elanTag != null) {
lriBuilder.setElanTag(elanTag);
} else {
LOG.warn("addToLabelMapper: elanTag is null for label {} prefix {} rd {} vpnId {}", label, prefix, rd, vpnId);
}
if (vpnInterfaceName != null) {
lriBuilder.setVpnInterfaceName(vpnInterfaceName);
} else {
LOG.warn("addToLabelMapper: vpn interface is null for label {} prefix {} rd {} vpnId {}", label, prefix, rd, vpnId);
}
lriBuilder.setParentVpnRd(rd);
VpnInstanceOpDataEntry vpnInstanceOpDataEntry = VpnUtil.getVpnInstanceOpData(broker, rd);
if (vpnInstanceOpDataEntry != null) {
List<String> vpnInstanceNames = Collections.singletonList(vpnInstanceOpDataEntry.getVpnInstanceName());
lriBuilder.setVpnInstanceList(vpnInstanceNames);
}
LabelRouteInfo lri = lriBuilder.build();
InstanceIdentifier<LabelRouteInfo> lriIid = InstanceIdentifier.builder(LabelRouteMap.class).child(LabelRouteInfo.class, new LabelRouteInfoKey(label)).build();
tx.merge(LogicalDatastoreType.OPERATIONAL, lriIid, lri, true);
LOG.info("addToLabelMapper: Added label route info to label {} prefix {} nextHopList {} vpnId {}" + " interface {} rd {} elantag {}", label, prefix, nextHopIpList, vpnId, vpnInterfaceName, rd, elanTag);
} else {
LOG.warn("addToLabelMapper: Can't add entry to label map for label {} prefix {} nextHopList {}" + " vpnId {} interface {} rd {} elantag {}, dpnId is null", label, prefix, nextHopIpList, vpnId, vpnInterfaceName, rd, elanTag);
}
}), LOG, "addToLabelMapper");
}
}
Aggregations