Search in sources :

Example 1 with LearntVpnVipToPortDataBuilder

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());
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) LearntVpnVipToPortDataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.LearntVpnVipToPortDataBuilder) ArrayList(java.util.ArrayList) LearntVpnVipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort) LearntVpnVipToPortData(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.LearntVpnVipToPortData) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)

Aggregations

ArrayList (java.util.ArrayList)1 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)1 LearntVpnVipToPortData (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.LearntVpnVipToPortData)1 LearntVpnVipToPortDataBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.LearntVpnVipToPortDataBuilder)1 LearntVpnVipToPort (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort)1 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)1