use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.LearntVpnVipToPortDataBuilder in project netvirt by opendaylight.
the class AbstractSnatService method removeLearntIpPorts.
private void removeLearntIpPorts(Routers routers) {
LOG.info("removeLearntIpPorts for router {} and network {}", routers.getRouterName(), routers.getNetworkId());
String networkId = routers.getNetworkId().getValue();
LearntVpnVipToPortData learntVpnVipToPortData = NatUtil.getLearntVpnVipToPortData(dataBroker);
if (learntVpnVipToPortData == null) {
LOG.info("removeLearntIpPorts, no learned ports present");
return;
}
LearntVpnVipToPortDataBuilder learntVpnVipToPortDataBuilder = new LearntVpnVipToPortDataBuilder();
List<LearntVpnVipToPort> learntVpnVipToPortList = new ArrayList<>();
for (LearntVpnVipToPort learntVpnVipToPort : learntVpnVipToPortData.nonnullLearntVpnVipToPort().values()) {
if (!networkId.equals(learntVpnVipToPort.getVpnName())) {
LOG.info("The learned port belongs to Vpn {} hence not removing", learntVpnVipToPort.getVpnName());
learntVpnVipToPortList.add(learntVpnVipToPort);
} else {
String externalSubNetId = null;
for (ExternalIps externalIp : routers.nonnullExternalIps().values()) {
if (!NWUtil.isIpv4Address(externalIp.getIpAddress())) {
// In this class we handle only IPv4 use-cases.
continue;
}
externalSubNetId = externalIp.getSubnetId().getValue();
break;
}
if (externalSubNetId == null) {
LOG.info("removeLearntIpPorts no external Ipv4 address present on router {}", routers.getRouterName());
return;
}
String prefix = learntVpnVipToPort.getPortFixedip() + "/32";
NatUtil.deletePrefixToInterface(dataBroker, NatUtil.getVpnId(dataBroker, externalSubNetId), prefix);
}
}
try {
learntVpnVipToPortDataBuilder.setLearntVpnVipToPort(learntVpnVipToPortList);
InstanceIdentifier<LearntVpnVipToPortData> learntVpnVipToPortDataId = NatUtil.getLearntVpnVipToPortDataId();
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, learntVpnVipToPortDataId, learntVpnVipToPortDataBuilder.build());
} catch (TransactionCommitFailedException e) {
LOG.warn("Failed to remove removeLearntIpPorts with error {}", e.getMessage());
}
}
Aggregations