use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency.AdjacencyType in project netvirt by opendaylight.
the class VpnInterfaceManager method removeAdjacenciesFromVpn.
private void removeAdjacenciesFromVpn(final Uint64 dpnId, final int lportTag, final String interfaceName, final String vpnName, final Uint32 vpnId, String gwMac, TypedWriteTransaction<Configuration> writeConfigTxn, TypedWriteTransaction<Operational> writeOperTxn, TypedReadWriteTransaction<Configuration> writeInvTxn) throws ExecutionException, InterruptedException {
// Read NextHops
try {
InstanceIdentifier<VpnInterfaceOpDataEntry> identifier = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
Optional<VpnInterfaceOpDataEntry> vpnInterfaceOpDataEnteryOptional = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier);
boolean isNonPrimaryAdjIp = false;
String primaryRd = vpnUtil.getVpnRd(vpnName);
LOG.info("removeAdjacenciesFromVpn: For interface {} on dpn {} RD recovered for vpn {} as rd {}", interfaceName, dpnId, vpnName, primaryRd);
if (!vpnInterfaceOpDataEnteryOptional.isPresent()) {
LOG.error("removeAdjacenciesFromVpn: VpnInterfaceOpDataEntry-Oper DS is absent for Interface {} " + "on vpn {} dpn {}", interfaceName, vpnName, dpnId);
return;
}
AdjacenciesOp adjacencies = vpnInterfaceOpDataEnteryOptional.get().augmentation(AdjacenciesOp.class);
if (adjacencies != null && adjacencies.getAdjacency() != null) {
Map<AdjacencyKey, Adjacency> nextHopsMap = adjacencies.nonnullAdjacency();
LOG.info("removeAdjacenciesFromVpn: NextHops for interface {} on dpn {} for vpn {} are {}", interfaceName, dpnId, vpnName, nextHopsMap);
for (Adjacency nextHop : nextHopsMap.values()) {
if (nextHop.isPhysNetworkFunc()) {
LOG.info("removeAdjacenciesFromVpn: Removing PNF FIB entry rd {} prefix {}", nextHop.getSubnetId().getValue(), nextHop.getIpAddress());
fibManager.removeFibEntry(nextHop.getSubnetId().getValue(), nextHop.getIpAddress(), null, null);
} else {
String rd = nextHop.getVrfId();
List<String> nhList;
if (nextHop.getAdjacencyType() != AdjacencyType.PrimaryAdjacency) {
nhList = getNextHopForNonPrimaryAdjacency(nextHop, vpnName, dpnId, interfaceName);
isNonPrimaryAdjIp = Boolean.TRUE;
} else {
// This is a primary adjacency
nhList = nextHop.getNextHopIpList() != null ? nextHop.getNextHopIpList() : emptyList();
removeGwMacAndArpResponderFlows(nextHop, vpnId, dpnId, lportTag, gwMac, vpnInterfaceOpDataEnteryOptional.get().getGatewayIpAddress(), interfaceName, writeInvTxn);
isNonPrimaryAdjIp = Boolean.FALSE;
}
if (!nhList.isEmpty()) {
if (Objects.equals(primaryRd, vpnName)) {
// this is an internal vpn - the rd is assigned to the vpn instance name;
// remove from FIB directly
nhList.forEach(removeAdjacencyFromInternalVpn(nextHop, vpnName, interfaceName, dpnId, writeConfigTxn, writeOperTxn));
} else {
removeAdjacencyFromBgpvpn(nextHop, nhList, vpnName, primaryRd, dpnId, rd, interfaceName, isNonPrimaryAdjIp, writeConfigTxn, writeOperTxn);
}
} else {
LOG.error("removeAdjacenciesFromVpn: nextHop empty for ip {} rd {} adjacencyType {}" + " interface {}", nextHop.getIpAddress(), rd, nextHop.getAdjacencyType().toString(), interfaceName);
bgpManager.withdrawPrefixIfPresent(rd, nextHop.getIpAddress());
fibManager.removeFibEntry(primaryRd, nextHop.getIpAddress(), null, writeConfigTxn);
}
}
String ip = nextHop.getIpAddress().split("/")[0];
LearntVpnVipToPort vpnVipToPort = vpnUtil.getLearntVpnVipToPort(vpnName, ip);
if (vpnVipToPort != null && vpnVipToPort.getPortName().equals(interfaceName)) {
vpnUtil.removeLearntVpnVipToPort(vpnName, ip, null);
LOG.info("removeAdjacenciesFromVpn: VpnInterfaceManager removed LearntVpnVipToPort entry" + " for Interface {} ip {} on dpn {} for vpn {}", vpnVipToPort.getPortName(), ip, dpnId, vpnName);
}
// Remove the MIP-IP from VpnPortIpToPort.
if (isNonPrimaryAdjIp) {
VpnPortipToPort persistedIp = vpnUtil.getVpnPortipToPort(vpnName, ip);
if (persistedIp != null && persistedIp.isLearntIp() && persistedIp.getPortName().equals(interfaceName)) {
VpnUtil.removeVpnPortFixedIpToPort(dataBroker, vpnName, ip, null);
LOG.info("removeAdjacenciesFromVpn: Learnt-IP: {} interface {} of vpn {} removed " + "from VpnPortipToPort", persistedIp.getPortFixedip(), persistedIp.getPortName(), vpnName);
}
}
VpnPortipToPort vpnPortipToPort = vpnUtil.getNeutronPortFromVpnPortFixedIp(vpnName, ip);
if (vpnPortipToPort != null) {
VpnUtil.removeVpnPortFixedIpToPort(dataBroker, vpnName, ip, null);
LOG.info("removeAdjacenciesFromVpn: VpnInterfaceManager removed vpnPortipToPort entry for " + "Interface {} ip {} on dpn {} for vpn {}", vpnPortipToPort.getPortName(), ip, dpnId, vpnName);
}
}
} else {
// this vpn interface has no more adjacency left, so clean up the vpn interface from Operational DS
LOG.info("removeAdjacenciesFromVpn: Vpn Interface {} on vpn {} dpn {} has no adjacencies." + " Removing it.", interfaceName, vpnName, dpnId);
writeOperTxn.delete(identifier);
}
} catch (InterruptedException | ExecutionException e) {
LOG.error("removeAdjacenciesFromVpn: Failed to read data store for interface {} dpn {} vpn {}", interfaceName, dpnId, vpnName);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency.AdjacencyType in project netvirt by opendaylight.
the class VpnInterfaceManager method removeAdjacenciesFromVpn.
private void removeAdjacenciesFromVpn(final BigInteger dpnId, final int lportTag, final String interfaceName, final String vpnName, final long vpnId, String gwMac, WriteTransaction writeConfigTxn, final WriteTransaction writeOperTxn, final WriteTransaction writeInvTxn) {
// Read NextHops
InstanceIdentifier<VpnInterfaceOpDataEntry> identifier = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
InstanceIdentifier<AdjacenciesOp> path = identifier.augmentation(AdjacenciesOp.class);
Optional<AdjacenciesOp> adjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, path);
String primaryRd = VpnUtil.getVpnRd(dataBroker, vpnName);
LOG.info("removeAdjacenciesFromVpn: For interface {} on dpn {} RD recovered for vpn {} as rd {}", interfaceName, dpnId, vpnName, primaryRd);
if (adjacencies.isPresent() && !adjacencies.get().getAdjacency().isEmpty()) {
List<Adjacency> nextHops = adjacencies.get().getAdjacency();
LOG.info("removeAdjacenciesFromVpn: NextHops for interface {} on dpn {} for vpn {} are {}", interfaceName, dpnId, vpnName, nextHops);
for (Adjacency nextHop : nextHops) {
if (nextHop.isPhysNetworkFunc()) {
LOG.info("removeAdjacenciesFromVpn: Removing PNF FIB entry rd {} prefix {}", nextHop.getSubnetId().getValue(), nextHop.getIpAddress());
fibManager.removeFibEntry(nextHop.getSubnetId().getValue(), nextHop.getIpAddress(), null);
} else {
String rd = nextHop.getVrfId();
List<String> nhList;
if (nextHop.getAdjacencyType() != AdjacencyType.PrimaryAdjacency) {
nhList = getNextHopForNonPrimaryAdjacency(nextHop, vpnName, dpnId, interfaceName);
} else {
// This is a primary adjacency
nhList = nextHop.getNextHopIpList() != null ? nextHop.getNextHopIpList() : Collections.emptyList();
removeGwMacAndArpResponderFlows(nextHop, vpnId, dpnId, lportTag, gwMac, interfaceName, writeInvTxn);
}
if (!nhList.isEmpty()) {
if (rd.equals(vpnName)) {
// this is an internal vpn - the rd is assigned to the vpn instance name;
// remove from FIB directly
nhList.forEach(removeAdjacencyFromInternalVpn(nextHop, vpnName, interfaceName, dpnId, writeConfigTxn));
} else {
removeAdjacencyFromBgpvpn(nextHop, nhList, vpnName, primaryRd, dpnId, rd, interfaceName, writeConfigTxn);
}
} else {
LOG.error("removeAdjacenciesFromVpn: nextHop empty for ip {} rd {} adjacencyType {}" + " interface {}", nextHop.getIpAddress(), rd, nextHop.getAdjacencyType().toString(), interfaceName);
bgpManager.withdrawPrefixIfPresent(rd, nextHop.getIpAddress());
fibManager.removeFibEntry(primaryRd, nextHop.getIpAddress(), writeConfigTxn);
}
}
String ip = nextHop.getIpAddress().split("/")[0];
LearntVpnVipToPort vpnVipToPort = VpnUtil.getLearntVpnVipToPort(dataBroker, vpnName, ip);
if (vpnVipToPort != null) {
VpnUtil.removeLearntVpnVipToPort(dataBroker, vpnName, ip);
LOG.info("removeAdjacenciesFromVpn: VpnInterfaceManager removed adjacency for Interface {}" + " ip {} on dpn {} for vpn {} from VpnPortData Entry", vpnVipToPort.getPortName(), ip, dpnId, vpnName);
}
}
} else {
// this vpn interface has no more adjacency left, so clean up the vpn interface from Operational DS
LOG.info("removeAdjacenciesFromVpn: Vpn Interface {} on vpn {} dpn {} has no adjacencies." + " Removing it.", interfaceName, vpnName, dpnId);
writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, identifier);
}
}
Aggregations