Search in sources :

Example 26 with Uint32

use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.

the class BgpManagerTest method testAddSinglePrefix.

@Test
public void testAddSinglePrefix() {
    String rd = "101";
    String prefix = "10.10.10.10/32";
    List<String> nexthop = Collections.singletonList("100.100.100.100");
    Uint32 label = Uint32.valueOf(1234);
    bgpFibWriter.addFibEntryToDS(rd, /*macAddress*/
    prefix, nexthop, VrfEntry.EncapType.Mplsgre, label, Uint32.ZERO, /*l3vni*/
    null, /*gatewayMacAddress*/
    RouteOrigin.LOCAL);
    // assertEquals(1, fibManager.getDataChgCount());
    assertEquals(1, 1);
}
Also used : Uint32(org.opendaylight.yangtools.yang.common.Uint32) Test(org.junit.Test) AbstractConcurrentDataBrokerTest(org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest)

Example 27 with Uint32

use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.

the class ExternalRoutersListener method removeNaptFlowsFromActiveSwitch.

public void removeNaptFlowsFromActiveSwitch(Uint32 routerId, String routerName, Uint64 dpnId, Uuid networkId, String vpnName, @NonNull Collection<String> externalIps, Collection<Uuid> externalSubnetList, TypedReadWriteTransaction<Configuration> confTx, ProviderTypes extNwProvType) throws InterruptedException, ExecutionException {
    LOG.debug("removeNaptFlowsFromActiveSwitch : Remove NAPT flows from Active switch");
    Uint64 cookieSnatFlow = NatUtil.getCookieNaptFlow(routerId);
    // Remove the PSNAT entry which forwards the packet to Outbound NAPT Table (For the
    // traffic which comes from the  VMs of the NAPT switches)
    String preSnatFlowRef = getFlowRefSnat(dpnId, NwConstants.PSNAT_TABLE, routerName);
    FlowEntity preSnatFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.PSNAT_TABLE, preSnatFlowRef);
    LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch with the DPN ID {} " + "and router ID {}", NwConstants.PSNAT_TABLE, dpnId, routerId);
    mdsalManager.removeFlow(confTx, preSnatFlowEntity);
    // Remove the Terminating Service table entry which forwards the packet to Outbound NAPT Table (For the
    // traffic which comes from the VMs of the non NAPT switches)
    Uint64 tunnelId = NatUtil.getTunnelIdForNonNaptToNaptFlow(dataBroker, natOverVxlanUtil, elanManager, idManager, routerId, routerName);
    String tsFlowRef = getFlowRefTs(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, Uint32.valueOf(tunnelId.longValue()));
    FlowEntity tsNatFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, tsFlowRef);
    LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch with the DPN ID {} " + "and router ID {}", NwConstants.INTERNAL_TUNNEL_TABLE, dpnId, routerId);
    mdsalManager.removeFlow(confTx, tsNatFlowEntity);
    // Remove the flow table 25->44 from NAPT Switch
    if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
        NatUtil.removePreDnatToSnatTableEntry(confTx, mdsalManager, dpnId);
    }
    // Remove the Outbound flow entry which forwards the packet to FIB Table
    LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch with the DPN ID {}" + " and router ID {}", NwConstants.OUTBOUND_NAPT_TABLE, dpnId, routerId);
    String outboundTcpNatFlowRef = getFlowRefOutbound(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId, NwConstants.IP_PROT_TCP);
    FlowEntity outboundTcpNatFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, outboundTcpNatFlowRef);
    mdsalManager.removeFlow(confTx, outboundTcpNatFlowEntity);
    String outboundUdpNatFlowRef = getFlowRefOutbound(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId, NwConstants.IP_PROT_UDP);
    FlowEntity outboundUdpNatFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, outboundUdpNatFlowRef);
    mdsalManager.removeFlow(confTx, outboundUdpNatFlowEntity);
    String icmpDropFlowRef = getFlowRefOutbound(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId, NwConstants.IP_PROT_ICMP);
    FlowEntity icmpDropFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, icmpDropFlowRef);
    mdsalManager.removeFlow(confTx, icmpDropFlowEntity);
    boolean lastRouterOnExternalNetwork = !NatUtil.checkForRoutersWithSameExtNetAndNaptSwitch(dataBroker, networkId, routerName, dpnId);
    if (lastRouterOnExternalNetwork) {
        removeNaptFibExternalOutputFlows(routerId, dpnId, networkId, externalIps, confTx);
    }
    // External Subnet Vpn Id.
    for (Uuid externalSubnetId : externalSubnetList) {
        Uint32 subnetVpnId = NatUtil.getVpnId(dataBroker, externalSubnetId.getValue());
        if (subnetVpnId != NatConstants.INVALID_ID && !NatUtil.checkForRoutersWithSameExtSubnetAndNaptSwitch(dataBroker, externalSubnetId, routerName, dpnId)) {
            String natPfibSubnetFlowRef = getFlowRefTs(dpnId, NwConstants.NAPT_PFIB_TABLE, subnetVpnId);
            FlowEntity natPfibFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE, natPfibSubnetFlowRef);
            mdsalManager.removeFlow(confTx, natPfibFlowEntity);
            LOG.debug("removeNaptFlowsFromActiveSwitch : Removed the flow in table {} with external subnet " + "Vpn Id {} as metadata on Napt Switch {}", NwConstants.NAPT_PFIB_TABLE, subnetVpnId, dpnId);
        }
    }
    // Remove the NAPT PFIB TABLE which forwards the incoming packet to FIB Table matching on the router ID.
    String natPfibFlowRef = getFlowRefTs(dpnId, NwConstants.NAPT_PFIB_TABLE, routerId);
    FlowEntity natPfibFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE, natPfibFlowRef);
    LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch with the DPN ID {} " + "and router ID {}", NwConstants.NAPT_PFIB_TABLE, dpnId, routerId);
    mdsalManager.removeFlow(confTx, natPfibFlowEntity);
    if (lastRouterOnExternalNetwork) {
        // Long vpnId = NatUtil.getVpnId(dataBroker, routerId);
        // - This does not work since ext-routers is deleted already - no network info
        // Get the VPN ID from the ExternalNetworks model
        Uint32 vpnId = NatConstants.INVALID_ID;
        if (vpnName == null || vpnName.isEmpty()) {
            // ie called from router delete cases
            Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
            LOG.debug("removeNaptFlowsFromActiveSwitch : vpnUuid is {}", vpnUuid);
            if (vpnUuid != null) {
                vpnId = NatUtil.getVpnId(dataBroker, vpnUuid.getValue());
                LOG.debug("removeNaptFlowsFromActiveSwitch : vpnId {} for external  network {} router delete " + "or disableSNAT scenario", vpnId, networkId);
            }
        } else {
            // ie called from disassociate vpn case
            LOG.debug("removeNaptFlowsFromActiveSwitch : This is disassociate nw with vpn case with vpnName {}", vpnName);
            vpnId = NatUtil.getVpnId(dataBroker, vpnName);
            LOG.debug("removeNaptFlowsFromActiveSwitch : vpnId for disassociate nw with vpn scenario {}", vpnId);
        }
        if (vpnId != NatConstants.INVALID_ID) {
            // Remove the NAPT PFIB TABLE which forwards the outgoing packet to FIB Table matching on the VPN ID.
            String natPfibVpnFlowRef = getFlowRefTs(dpnId, NwConstants.NAPT_PFIB_TABLE, vpnId);
            FlowEntity natPfibVpnFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE, natPfibVpnFlowRef);
            LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in {} for the active switch with the " + "DPN ID {} and VPN ID {}", NwConstants.NAPT_PFIB_TABLE, dpnId, vpnId);
            mdsalManager.removeFlow(confTx, natPfibVpnFlowEntity);
        }
    }
    // For the router ID get the internal IP , internal port and the corresponding external IP and external Port.
    IpPortMapping ipPortMapping = NatUtil.getIportMapping(dataBroker, routerId);
    if (ipPortMapping == null) {
        LOG.error("removeNaptFlowsFromActiveSwitch : Unable to retrieve the IpPortMapping");
        return;
    }
    for (IntextIpProtocolType intextIpProtocolType : ipPortMapping.nonnullIntextIpProtocolType().values()) {
        String protocol = intextIpProtocolType.getProtocol().name();
        for (IpPortMap ipPortMap : intextIpProtocolType.nonnullIpPortMap().values()) {
            String ipPortInternal = ipPortMap.getIpPortInternal();
            String[] ipPortParts = ipPortInternal.split(":");
            if (ipPortParts.length != 2) {
                LOG.error("removeNaptFlowsFromActiveSwitch : Unable to retrieve the Internal IP and port");
                return;
            }
            String internalIp = ipPortParts[0];
            String internalPort = ipPortParts[1];
            // Build the flow for the outbound NAPT table
            naptPacketInHandler.removeIncomingPacketMap(routerId + NatConstants.COLON_SEPARATOR + internalIp + NatConstants.COLON_SEPARATOR + internalPort);
            String switchFlowRef = NatUtil.getNaptFlowRef(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, String.valueOf(routerId), internalIp, Integer.parseInt(internalPort), protocol);
            FlowEntity outboundNaptFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, cookieSnatFlow, switchFlowRef);
            LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch " + "with the DPN ID {} and router ID {}", NwConstants.OUTBOUND_NAPT_TABLE, dpnId, routerId);
            mdsalManager.removeFlow(confTx, outboundNaptFlowEntity);
            // Build the flow for the inbound NAPT table
            switchFlowRef = NatUtil.getNaptFlowRef(dpnId, NwConstants.INBOUND_NAPT_TABLE, String.valueOf(routerId), internalIp, Integer.parseInt(internalPort), protocol);
            FlowEntity inboundNaptFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.INBOUND_NAPT_TABLE, cookieSnatFlow, switchFlowRef);
            LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active active switch " + "with the DPN ID {} and router ID {}", NwConstants.INBOUND_NAPT_TABLE, dpnId, routerId);
            mdsalManager.removeFlow(confTx, inboundNaptFlowEntity);
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) IntextIpPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpPortMap) IpPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMap) IntextIpProtocolType(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.IntextIpProtocolType) IpPortMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.IpPortMapping) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Uint64(org.opendaylight.yangtools.yang.common.Uint64) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 28 with Uint32

use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.

the class ExternalRoutersListener method update.

@Override
public void update(InstanceIdentifier<Routers> identifier, Routers original, Routers update) {
    if (natMode != NatMode.Controller) {
        return;
    }
    LOG.trace("update : origRouter: {} updatedRouter: {}", original, update);
    String routerName = original.getRouterName();
    Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
    if (routerId == NatConstants.INVALID_ID) {
        LOG.error("update : external router event - Invalid routerId for routerName {}", routerName);
        return;
    }
    coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + update.key(), () -> {
        List<ListenableFuture<?>> futures = new ArrayList<>();
        futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, writeFlowInvTx -> {
            futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, removeFlowInvTx -> {
                Uint32 bgpVpnId = NatConstants.INVALID_ID;
                Uuid bgpVpnUuid = NatUtil.getVpnForRouter(dataBroker, routerName);
                if (bgpVpnUuid != null) {
                    bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
                }
                // BigInteger dpnId = getPrimaryNaptSwitch(routerName);
                /* Get Primary Napt Switch for existing router from "router-to-napt-switch" DS.
                     * if dpnId value is null or zero then go for electing new Napt switch for existing router.
                     */
                Uint64 dpnId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
                boolean isPrimaryNaptSwitchNotSelected = (dpnId == null || dpnId.equals(Uint64.valueOf(BigInteger.ZERO)));
                Uuid networkId = original.getNetworkId();
                // Check if its update on SNAT flag
                boolean originalSNATEnabled = original.isEnableSnat();
                boolean updatedSNATEnabled = update.isEnableSnat();
                LOG.debug("update :called with originalFlag and updatedFlag for SNAT enabled " + "as {} and {} with Elected Dpn {}(isPrimaryNaptSwitchNotSelected:{})", originalSNATEnabled, updatedSNATEnabled, dpnId, isPrimaryNaptSwitchNotSelected);
                // 3. First Elect dpnId and process other changes with valid dpnId
                if (originalSNATEnabled != updatedSNATEnabled || isPrimaryNaptSwitchNotSelected) {
                    if (originalSNATEnabled && !updatedSNATEnabled) {
                        if (isPrimaryNaptSwitchNotSelected) {
                            LOG.info("No Action to be taken when SNAT is disabled " + "with no Napt Switch Election for Router {}", routerName);
                            return;
                        }
                        // SNAT disabled for the router
                        Uuid networkUuid = original.getNetworkId();
                        LOG.info("update : SNAT disabled for Router {}", routerName);
                        Collection<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
                        final String vpnName = NatUtil.getAssociatedVPN(dataBroker, networkId);
                        handleDisableSnat(original, networkUuid, externalIps, false, vpnName, dpnId, routerId, removeFlowInvTx);
                    } else if (updatedSNATEnabled) {
                        LOG.info("update : SNAT enabled for Router {}", routerName);
                        addOrDelDefFibRouteToSNAT(routerName, routerId, bgpVpnId, bgpVpnUuid, true, writeFlowInvTx);
                        if (isPrimaryNaptSwitchNotSelected) {
                            dpnId = selectNewNAPTSwitch(routerName);
                            if (dpnId != null && !dpnId.equals(Uint64.valueOf(BigInteger.ZERO))) {
                                handleEnableSnat(update, routerId, dpnId, bgpVpnId, removeFlowInvTx);
                            } else {
                                LOG.error("update : Failed to elect Napt Switch During update event" + " of router {}", routerName);
                            }
                        }
                    }
                    LOG.info("update : no need to process external/subnet changes as it's will taken care" + "in handleDisableSnat/handleEnableSnat");
                    return;
                }
                if (!Objects.equals(original.getExtGwMacAddress(), update.getExtGwMacAddress())) {
                    NatUtil.installRouterGwFlows(txRunner, vpnManager, original, dpnId, NwConstants.DEL_FLOW);
                    NatUtil.installRouterGwFlows(txRunner, vpnManager, update, dpnId, NwConstants.ADD_FLOW);
                }
                if (updatedSNATEnabled != originalSNATEnabled) {
                    LOG.info("update : no need to process external/subnet changes as it's will taken care in " + "handleDisableSnat/handleEnableSnat");
                    return;
                }
                // Check if the Update is on External IPs
                LOG.debug("update : Checking if this is update on External IPs for router {}", routerName);
                List<String> originalExternalIps = NatUtil.getIpsListFromExternalIps(new ArrayList<ExternalIps>(original.nonnullExternalIps().values()));
                List<String> updatedExternalIps = NatUtil.getIpsListFromExternalIps(new ArrayList<ExternalIps>(update.nonnullExternalIps().values()));
                // Check if the External IPs are removed during the update.
                Set<String> removedExternalIps = new HashSet<>(originalExternalIps);
                removedExternalIps.removeAll(updatedExternalIps);
                if (removedExternalIps.size() > 0) {
                    LOG.debug("update : Start processing of the External IPs removal for router {}", routerName);
                    vpnManager.removeArpResponderFlowsToExternalNetworkIps(routerName, removedExternalIps, original.getExtGwMacAddress(), dpnId, networkId);
                    for (String removedExternalIp : removedExternalIps) {
                        /*
                    1) Remove the mappings in the IntExt IP model which has external IP.
                    2) Remove the external IP in the ExternalCounter model.
                    3) For the corresponding subnet IDs whose external IP mapping was removed, allocate one of the
                       least loaded external IP.
                       Store the subnet IP and the reallocated external IP mapping in the IntExtIp model.
                    4) Increase the count of the allocated external IP by one.
                    5) Advertise to the BGP if external IP is allocated for the first time for the router
                     i.e. the route for the external IP is absent.
                    6) Remove the NAPT translation entries from Inbound and Outbound NAPT tables for
                     the removed external IPs and also from the model.
                    7) Advertise to the BGP for removing the route for the removed external IPs.
                 */
                        String[] externalIpParts = NatUtil.getExternalIpAndPrefix(removedExternalIp);
                        String externalIp = externalIpParts[0];
                        String externalIpPrefix = externalIpParts[1];
                        String externalIpAddrStr = externalIp + "/" + externalIpPrefix;
                        LOG.debug("update : Clear the routes from the BGP and remove the FIB and TS " + "entries for removed external IP {}", externalIpAddrStr);
                        Uuid vpnUuId = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
                        String vpnName = "";
                        if (vpnUuId != null) {
                            vpnName = vpnUuId.getValue();
                        }
                        clrRtsFromBgpAndDelFibTs(dpnId, routerId, externalIpAddrStr, vpnName, networkId, update.getExtGwMacAddress(), removeFlowInvTx);
                        LOG.debug("update : Remove the mappings in the IntExtIP model which has external IP.");
                        // Get the internal IPs which are associated to the removed external IPs
                        List<IpMap> ipMaps = naptManager.getIpMapList(dataBroker, routerId);
                        List<String> removedInternalIps = new ArrayList<>();
                        for (IpMap ipMap : ipMaps) {
                            if (ipMap.getExternalIp().equals(externalIpAddrStr)) {
                                removedInternalIps.add(ipMap.getInternalIp());
                            }
                        }
                        LOG.debug("update : Remove the mappings of the internal IPs from the IntExtIP model.");
                        for (String removedInternalIp : removedInternalIps) {
                            LOG.debug("update : Remove the IP mapping of the internal IP {} for the " + "router ID {} from the IntExtIP model", removedInternalIp, routerId);
                            naptManager.removeFromIpMapDS(routerId, removedInternalIp);
                        }
                        LOG.debug("update : Remove the count mapping of the external IP {} for the " + "router ID {} from the ExternalIpsCounter model.", externalIpAddrStr, routerId);
                        naptManager.removeExternalIpCounter(routerId, externalIpAddrStr);
                        LOG.debug("update : Allocate the least loaded external IPs to the subnets " + "whose external IPs were removed.");
                        for (String removedInternalIp : removedInternalIps) {
                            allocateExternalIp(dpnId, update, routerId, routerName, networkId, removedInternalIp, writeFlowInvTx);
                        }
                        LOG.debug("update : Remove the NAPT translation entries from " + "Inbound and Outbound NAPT tables for the removed external IPs.");
                        // Get the internalIP and internal Port which were associated to the removed external IP.
                        Map<ProtocolTypes, List<String>> protoTypesIntIpPortsMap = new HashMap<>();
                        InstanceIdentifier<IpPortMapping> ipPortMappingId = InstanceIdentifier.builder(IntextIpPortMap.class).child(IpPortMapping.class, new IpPortMappingKey(routerId)).build();
                        Optional<IpPortMapping> ipPortMapping;
                        try {
                            ipPortMapping = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, ipPortMappingId);
                        } catch (InterruptedException | ExecutionException e) {
                            LOG.error("Failed to read ipPortMapping for router id {}", routerId, e);
                            ipPortMapping = Optional.empty();
                        }
                        if (ipPortMapping.isPresent()) {
                            for (IntextIpProtocolType intextIpProtocolType : ipPortMapping.get().nonnullIntextIpProtocolType().values()) {
                                ProtocolTypes protoType = intextIpProtocolType.getProtocol();
                                for (IpPortMap ipPortMap : intextIpProtocolType.nonnullIpPortMap().values()) {
                                    IpPortExternal ipPortExternal = ipPortMap.getIpPortExternal();
                                    if (ipPortExternal.getIpAddress().equals(externalIp)) {
                                        List<String> removedInternalIpPorts = protoTypesIntIpPortsMap.get(protoType);
                                        if (removedInternalIpPorts != null) {
                                            removedInternalIpPorts.add(ipPortMap.getIpPortInternal());
                                            protoTypesIntIpPortsMap.put(protoType, removedInternalIpPorts);
                                        } else {
                                            removedInternalIpPorts = new ArrayList<>();
                                            removedInternalIpPorts.add(ipPortMap.getIpPortInternal());
                                            protoTypesIntIpPortsMap.put(protoType, removedInternalIpPorts);
                                        }
                                    }
                                }
                            }
                        }
                        // Remove the IP port map from the intext-ip-port-map model, which were containing
                        // the removed external IP.
                        Set<Map.Entry<ProtocolTypes, List<String>>> protoTypesIntIpPorts = protoTypesIntIpPortsMap.entrySet();
                        Map<String, List<String>> internalIpPortMap = new HashMap<>();
                        for (Map.Entry protoTypesIntIpPort : protoTypesIntIpPorts) {
                            ProtocolTypes protocolType = (ProtocolTypes) protoTypesIntIpPort.getKey();
                            List<String> removedInternalIpPorts = (List<String>) protoTypesIntIpPort.getValue();
                            for (String removedInternalIpPort : removedInternalIpPorts) {
                                // Remove the IP port map from the intext-ip-port-map model,
                                // which were containing the removed external IP
                                naptManager.removeFromIpPortMapDS(routerId, removedInternalIpPort, protocolType);
                                // Remove the IP port incomint packer map.
                                naptPacketInHandler.removeIncomingPacketMap(routerId + NatConstants.COLON_SEPARATOR + removedInternalIpPort);
                                String[] removedInternalIpPortParts = removedInternalIpPort.split(NatConstants.COLON_SEPARATOR);
                                if (removedInternalIpPortParts.length == 2) {
                                    String removedInternalIp = removedInternalIpPortParts[0];
                                    String removedInternalPort = removedInternalIpPortParts[1];
                                    List<String> removedInternalPortsList = internalIpPortMap.get(removedInternalPort);
                                    if (removedInternalPortsList != null) {
                                        removedInternalPortsList.add(removedInternalPort);
                                        internalIpPortMap.put(removedInternalIp, removedInternalPortsList);
                                        naptPacketInHandler.removeIncomingPacketMap(routerId + NatConstants.COLON_SEPARATOR + removedInternalIp + NatConstants.COLON_SEPARATOR + removedInternalPort);
                                        // Remove the NAPT translation entries from Outbound NAPT table
                                        naptEventHandler.removeNatFlows(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId, removedInternalIp, Integer.parseInt(removedInternalPort), protocolType.getName());
                                        naptEventHandler.removeNatFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, routerId, removedInternalIp, Integer.parseInt(removedInternalPort), protocolType.getName());
                                    } else {
                                        removedInternalPortsList = new ArrayList<>();
                                        removedInternalPortsList.add(removedInternalPort);
                                        internalIpPortMap.put(removedInternalIp, removedInternalPortsList);
                                        naptPacketInHandler.removeIncomingPacketMap(routerId + NatConstants.COLON_SEPARATOR + removedInternalIp + NatConstants.COLON_SEPARATOR + removedInternalPort);
                                        // Remove the NAPT translation entries from Outbound NAPT table
                                        naptEventHandler.removeNatFlows(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId, removedInternalIp, Integer.parseInt(removedInternalPort), protocolType.getName());
                                        naptEventHandler.removeNatFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, routerId, removedInternalIp, Integer.parseInt(removedInternalPort), protocolType.getName());
                                    }
                                }
                            }
                        }
                        // Delete the entry from SnatIntIpPortMap DS
                        Set<String> internalIps = internalIpPortMap.keySet();
                        for (String internalIp : internalIps) {
                            LOG.debug("update : Removing IpPort having the internal IP {} from the " + "model SnatIntIpPortMap", internalIp);
                            naptManager.removeFromSnatIpPortDS(routerId, internalIp);
                        }
                        naptManager.removeNaptPortPool(externalIp);
                    }
                    LOG.debug("update : End processing of the External IPs removal for router {}", routerName);
                }
                // Check if the External IPs are added during the update.
                Set<String> addedExternalIps = new HashSet<>(updatedExternalIps);
                addedExternalIps.removeAll(originalExternalIps);
                if (addedExternalIps.size() != 0) {
                    LOG.debug("update : Start processing of the External IPs addition for router {}", routerName);
                    vpnManager.addArpResponderFlowsToExternalNetworkIps(routerName, addedExternalIps, update.getExtGwMacAddress(), dpnId, update.getNetworkId());
                    for (String addedExternalIp : addedExternalIps) {
                        /*
                    1) Do nothing in the IntExtIp model.
                    2) Initialise the count of the added external IP to 0 in the ExternalCounter model.
                 */
                        String[] externalIpParts = NatUtil.getExternalIpAndPrefix(addedExternalIp);
                        String externalIp = externalIpParts[0];
                        String externalIpPrefix = externalIpParts[1];
                        String externalpStr = externalIp + "/" + externalIpPrefix;
                        LOG.debug("update : Initialise the count mapping of the external IP {} for the " + "router ID {} in the ExternalIpsCounter model.", externalpStr, routerId);
                        naptManager.initialiseNewExternalIpCounter(routerId, externalpStr);
                        subnetRegisterMapping(update, routerId);
                        LOG.info("update : Installing fib flow fo newly added Ips");
                        handleSnatReverseTraffic(writeFlowInvTx, dpnId, update, routerId, routerName, externalpStr);
                    }
                    LOG.debug("update : End processing of the External IPs addition during the update operation");
                }
                // Check if its Update on subnets
                LOG.debug("update : Checking if this is update on subnets for router {}", routerName);
                List<Uuid> originalSubnetIds = original.getSubnetIds();
                List<Uuid> updatedSubnetIds = update.getSubnetIds();
                Set<Uuid> addedSubnetIds = updatedSubnetIds != null ? new HashSet<>(updatedSubnetIds) : new HashSet<>();
                if (originalSubnetIds != null) {
                    addedSubnetIds.removeAll(originalSubnetIds);
                }
                // Check if the Subnet IDs are added during the update.
                if (addedSubnetIds.size() != 0) {
                    LOG.debug("update : Start processing of the Subnet IDs addition for router {}", routerName);
                    for (Uuid addedSubnetId : addedSubnetIds) {
                        /*
                    1) Select the least loaded external IP for the subnet and store the mapping of the
                    subnet IP and the external IP in the IntExtIp model.
                    2) Increase the count of the selected external IP by one.
                    3) Advertise to the BGP if external IP is allocated for the first time for the
                    router i.e. the route for the external IP is absent.
                 */
                        String subnetIp = NatUtil.getSubnetIp(dataBroker, addedSubnetId);
                        if (subnetIp != null) {
                            allocateExternalIp(dpnId, update, routerId, routerName, networkId, subnetIp, writeFlowInvTx);
                        }
                    }
                    LOG.debug("update : End processing of the Subnet IDs addition for router {}", routerName);
                }
                // Check if the Subnet IDs are removed during the update.
                Set<Uuid> removedSubnetIds = new HashSet<>(originalSubnetIds);
                removedSubnetIds.removeAll(updatedSubnetIds);
                if (removedSubnetIds.size() != 0) {
                    LOG.debug("update : Start processing of the Subnet IDs removal for router {}", routerName);
                    for (Uuid removedSubnetId : removedSubnetIds) {
                        String[] subnetAddr = NatUtil.getSubnetIpAndPrefix(dataBroker, removedSubnetId);
                        if (subnetAddr != null) {
                            /*
                        1) Remove the subnet IP and the external IP in the IntExtIp map
                        2) Decrease the count of the coresponding external IP by one.
                        3) Advertise to the BGP for removing the routes of the corresponding external
                        IP if its not allocated to any other internal IP.
                    */
                            String externalIp = naptManager.getExternalIpAllocatedForSubnet(routerId, subnetAddr[0] + "/" + subnetAddr[1]);
                            if (externalIp == null) {
                                LOG.error("update : No mapping found for router ID {} and internal IP {}", routerId, subnetAddr[0]);
                                return;
                            }
                            naptManager.updateCounter(routerId, externalIp, false);
                            // used by any other internal ip in any router
                            if (!isExternalIpAllocated(externalIp)) {
                                LOG.debug("update : external ip is not allocated to any other " + "internal IP so proceeding to remove routes");
                                clrRtsFromBgpAndDelFibTs(dpnId, routerId, networkId, Collections.singleton(externalIp), null, update.getExtGwMacAddress(), removeFlowInvTx);
                                LOG.debug("update : Successfully removed fib entries in switch {} for " + "router {} with networkId {} and externalIp {}", dpnId, routerId, networkId, externalIp);
                            }
                            LOG.debug("update : Remove the IP mapping for the router ID {} and " + "internal IP {} external IP {}", routerId, subnetAddr[0], externalIp);
                            naptManager.removeIntExtIpMapDS(routerId, subnetAddr[0] + "/" + subnetAddr[1]);
                        }
                    }
                    LOG.debug("update : End processing of the Subnet IDs removal for router {}", routerName);
                }
            }));
        }));
        return futures;
    }, NatConstants.NAT_DJC_MAX_RETRIES);
}
Also used : NatserviceConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.config.rev170206.NatserviceConfig) Arrays(java.util.Arrays) RouterIds(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIds) ActionDrop(org.opendaylight.genius.mdsalutil.actions.ActionDrop) FibRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.FibRpcService) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) InetAddress(java.net.InetAddress) Future(java.util.concurrent.Future) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) IpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMap) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) Map(java.util.Map) IBgpManager(org.opendaylight.netvirt.bgpmanager.api.IBgpManager) TunnelTypeGre(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeGre) BigInteger(java.math.BigInteger) VpnRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.VpnRpcService) ActionLearn(org.opendaylight.genius.mdsalutil.actions.ActionLearn) MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) RouterIdName(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.RouterIdName) Set(java.util.Set) ActionNxLoadInPort(org.opendaylight.genius.mdsalutil.actions.ActionNxLoadInPort) RemoveFibEntryInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryInput) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) ProtocolTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProtocolTypes) IpPortMappingKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.IpPortMappingKey) GetTunnelInterfaceNameInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetTunnelInterfaceNameInputBuilder) TypedWriteTransaction(org.opendaylight.mdsal.binding.util.TypedWriteTransaction) CreateFibEntryInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInput) TypedReadWriteTransaction(org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction) NonNull(org.eclipse.jdt.annotation.NonNull) ActionSetFieldTunnelId(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId) Uint64(org.opendaylight.yangtools.yang.common.Uint64) OdlInterfaceRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) IElanService(org.opendaylight.netvirt.elanmanager.api.IElanService) NxmOfFieldType(org.opendaylight.genius.mdsalutil.NwConstants.NxmOfFieldType) ArrayList(java.util.ArrayList) TunnelTypeVxlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan) ActionPuntToController(org.opendaylight.genius.mdsalutil.actions.ActionPuntToController) RemoveVpnLabelOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveVpnLabelOutput) ActionPopMpls(org.opendaylight.genius.mdsalutil.actions.ActionPopMpls) MatchIpProtocol(org.opendaylight.genius.mdsalutil.matches.MatchIpProtocol) RouterIdsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIdsKey) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) GenerateVpnLabelInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.GenerateVpnLabelInputBuilder) AbstractAsyncDataTreeChangeListener(org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener) RemoveVpnLabelInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveVpnLabelInput) MatchFromField(org.opendaylight.genius.mdsalutil.actions.ActionLearn.MatchFromField) UnknownHostException(java.net.UnknownHostException) FutureCallback(com.google.common.util.concurrent.FutureCallback) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) RemoveFibEntryOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryOutput) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) IMdsalApiManager(org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) IpPortMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.IpPortMapping) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) GroupTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes) MetaDataUtil(org.opendaylight.genius.mdsalutil.MetaDataUtil) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) IFibManager(org.opendaylight.netvirt.fibmanager.api.IFibManager) IpMapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMapBuilder) GenerateVpnLabelOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.GenerateVpnLabelOutput) LoggerFactory(org.slf4j.LoggerFactory) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) ActionNxResubmit(org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) IpMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMapKey) PreDestroy(javax.annotation.PreDestroy) Nullable(org.eclipse.jdt.annotation.Nullable) IpPortExternal(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.ip.port.map.IpPortExternal) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) CreateFibEntryOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryOutput) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) GetTunnelInterfaceNameOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetTunnelInterfaceNameOutput) ExternalIpsCounter(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalIpsCounter) Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.Subnets) ExternalIpCounter(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounter) RouterToNaptSwitchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitchBuilder) Collection(java.util.Collection) Configuration(org.opendaylight.mdsal.binding.util.Datastore.Configuration) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) Objects(java.util.Objects) List(java.util.List) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) TunnelTypeBase(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeBase) NaptSwitches(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.NaptSwitches) ExtRouters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters) Optional(java.util.Optional) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps) InstructionKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey) MatchFromValue(org.opendaylight.genius.mdsalutil.actions.ActionLearn.MatchFromValue) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) SubnetmapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) CreateFibEntryInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInputBuilder) IntextIpProtocolType(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.IntextIpProtocolType) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ExternalCounters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.ExternalCounters) RouterToNaptSwitch(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitch) Executors(org.opendaylight.infrautils.utils.concurrent.Executors) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) InstructionWriteMetadata(org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata) JdkFutureAdapters(com.google.common.util.concurrent.JdkFutureAdapters) HashSet(java.util.HashSet) Inject(javax.inject.Inject) RoutersKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersKey) RemoveVpnLabelInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveVpnLabelInputBuilder) MatchTunnelId(org.opendaylight.genius.mdsalutil.matches.MatchTunnelId) RemoveFibEntryInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryInputBuilder) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) RouterIdsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIdsBuilder) MatchEthernetType(org.opendaylight.genius.mdsalutil.matches.MatchEthernetType) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) NatMode(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.config.rev170206.NatserviceConfig.NatMode) IInterfaceManager(org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager) IntextIpPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpPortMap) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Logger(org.slf4j.Logger) RouteOrigin(org.opendaylight.netvirt.fibmanager.api.RouteOrigin) Subnetmaps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) IVpnManager(org.opendaylight.netvirt.vpnmanager.api.IVpnManager) IpPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMap) GroupEntity(org.opendaylight.genius.mdsalutil.GroupEntity) IdManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService) Inet6Address(java.net.Inet6Address) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) GenerateVpnLabelInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.GenerateVpnLabelInput) MatchMplsLabel(org.opendaylight.genius.mdsalutil.matches.MatchMplsLabel) BucketInfo(org.opendaylight.genius.mdsalutil.BucketInfo) Collections(java.util.Collections) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) RouterToNaptSwitchKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitchKey) ItmRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IpPortMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.IpPortMapping) ProtocolTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProtocolTypes) ArrayList(java.util.ArrayList) List(java.util.List) IpPortExternal(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.ip.port.map.IpPortExternal) ExecutionException(java.util.concurrent.ExecutionException) Uint32(org.opendaylight.yangtools.yang.common.Uint32) HashSet(java.util.HashSet) IpPortMappingKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.IpPortMappingKey) IpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMap) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) IntextIpPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpPortMap) IpPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMap) IntextIpProtocolType(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.IntextIpProtocolType) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) IpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMap) Map(java.util.Map) HashMap(java.util.HashMap) IntextIpPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpPortMap) IpPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMap) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 29 with Uint32

use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.

the class ExternalRoutersListener method installNaptPfibExternalOutputFlow.

protected void installNaptPfibExternalOutputFlow(String routerName, Uint32 routerId, Uint64 dpnId, TypedWriteTransaction<Configuration> confTx) {
    Uint32 extVpnId = NatUtil.getNetworkVpnIdFromRouterId(dataBroker, routerId);
    if (extVpnId == NatConstants.INVALID_ID) {
        LOG.error("installNaptPfibExternalOutputFlow - not found extVpnId for router {}", routerId);
        extVpnId = routerId;
    }
    List<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerName);
    if (externalIps.isEmpty()) {
        LOG.error("installNaptPfibExternalOutputFlow - empty external Ips list for dpnId {} extVpnId {}", dpnId, extVpnId);
        return;
    }
    for (String ip : externalIps) {
        Uuid subnetId = getSubnetIdForFixedIp(ip);
        if (subnetId != null) {
            Uint32 subnetVpnId = NatUtil.getExternalSubnetVpnId(dataBroker, subnetId);
            if (subnetVpnId != NatConstants.INVALID_ID) {
                extVpnId = subnetVpnId;
            }
            LOG.debug("installNaptPfibExternalOutputFlow - dpnId {} extVpnId {} subnetId {}", dpnId, extVpnId, subnetId);
            FlowEntity postNaptFlowEntity = buildNaptPfibFlowEntity(dpnId, extVpnId);
            if (postNaptFlowEntity != null) {
                mdsalManager.addFlow(confTx, postNaptFlowEntity);
            }
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Uint32(org.opendaylight.yangtools.yang.common.Uint32) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 30 with Uint32

use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.

the class ExternalRoutersListener method removeNaptFibExternalOutputFlows.

protected void removeNaptFibExternalOutputFlows(Uint32 routerId, Uint64 dpnId, Uuid networkId, @NonNull Collection<String> externalIps, TypedReadWriteTransaction<Configuration> writeFlowInvTx) throws ExecutionException, InterruptedException {
    Uint32 extVpnId = NatConstants.INVALID_ID;
    if (networkId != null) {
        Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
        if (vpnUuid != null) {
            extVpnId = NatUtil.getVpnId(dataBroker, vpnUuid.getValue());
        } else {
            LOG.debug("removeNaptFibExternalOutputFlows : vpnUuid is null");
        }
    } else {
        LOG.debug("removeNaptFibExternalOutputFlows : networkId is null");
        extVpnId = NatUtil.getNetworkVpnIdFromRouterId(dataBroker, routerId);
    }
    if (extVpnId == NatConstants.INVALID_ID) {
        LOG.warn("removeNaptFibExternalOutputFlows : extVpnId not found for routerId {}", routerId);
        extVpnId = routerId;
    }
    for (String ip : externalIps) {
        String extIp = removeMaskFromIp(ip);
        String naptFlowRef = getFlowRefNaptPreFib(dpnId, NwConstants.NAPT_PFIB_TABLE, extVpnId);
        LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in table {} for the active switch" + " with the DPN ID {} and router ID {} and IP {} flowRef {}", NwConstants.NAPT_PFIB_TABLE, dpnId, routerId, extIp, naptFlowRef);
        FlowEntity natPfibVpnFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE, naptFlowRef);
        mdsalManager.removeFlow(writeFlowInvTx, natPfibVpnFlowEntity);
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Uint32(org.opendaylight.yangtools.yang.common.Uint32) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Aggregations

Uint32 (org.opendaylight.yangtools.yang.common.Uint32)216 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)98 ArrayList (java.util.ArrayList)77 ExecutionException (java.util.concurrent.ExecutionException)68 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)68 DataBroker (org.opendaylight.mdsal.binding.api.DataBroker)44 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)44 Logger (org.slf4j.Logger)44 LoggerFactory (org.slf4j.LoggerFactory)44 ManagedNewTransactionRunner (org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner)42 ManagedNewTransactionRunnerImpl (org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl)42 Inject (javax.inject.Inject)41 Singleton (javax.inject.Singleton)41 LogicalDatastoreType (org.opendaylight.mdsal.common.api.LogicalDatastoreType)41 List (java.util.List)40 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)38 Optional (java.util.Optional)37 VpnInstanceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)36 VrfEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry)35 Collections (java.util.Collections)34