Search in sources :

Example 21 with ExternalIps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.

the class ExternalRoutersListener method removeNaptFlowsFromActiveSwitch.

public void removeNaptFlowsFromActiveSwitch(long routerId, String routerName, BigInteger dpnId, Uuid networkId, String vpnName, @Nonnull Collection<String> externalIps, Collection<Uuid> externalSubnetList, WriteTransaction removeFlowInvTx, ProviderTypes extNwProvType) {
    LOG.debug("removeNaptFlowsFromActiveSwitch : Remove NAPT flows from Active switch");
    BigInteger 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.removeFlowToTx(preSnatFlowEntity, removeFlowInvTx);
    // 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)
    long tunnelId = NatUtil.getTunnelIdForNonNaptToNaptFlow(dataBroker, elanManager, idManager, routerId, routerName);
    String tsFlowRef = getFlowRefTs(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, tunnelId);
    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.removeFlowToTx(tsNatFlowEntity, removeFlowInvTx);
    // Remove the flow table 25->44 from NAPT Switch
    if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
        NatUtil.removePreDnatToSnatTableEntry(mdsalManager, dpnId, removeFlowInvTx);
    }
    // Remove the Outbound flow entry which forwards the packet to FIB Table
    String outboundNatFlowRef = getFlowRefOutbound(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId);
    FlowEntity outboundNatFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, outboundNatFlowRef);
    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.removeFlowToTx(outboundNatFlowEntity, removeFlowInvTx);
    removeNaptFibExternalOutputFlows(routerId, dpnId, networkId, externalIps, removeFlowInvTx);
    // External Subnet Vpn Id.
    for (Uuid externalSubnetId : externalSubnetList) {
        long subnetVpnId = NatUtil.getVpnId(dataBroker, externalSubnetId.getValue());
        if (subnetVpnId != -1) {
            String natPfibSubnetFlowRef = getFlowRefTs(dpnId, NwConstants.NAPT_PFIB_TABLE, subnetVpnId);
            FlowEntity natPfibFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE, natPfibSubnetFlowRef);
            mdsalManager.removeFlowToTx(natPfibFlowEntity, removeFlowInvTx);
            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.removeFlowToTx(natPfibFlowEntity, removeFlowInvTx);
    // 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
    long vpnId = -1;
    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.removeFlowToTx(natPfibVpnFlowEntity, removeFlowInvTx);
    }
    // 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;
    }
    List<IntextIpProtocolType> intextIpProtocolTypes = ipPortMapping.getIntextIpProtocolType();
    for (IntextIpProtocolType intextIpProtocolType : intextIpProtocolTypes) {
        List<IpPortMap> ipPortMaps = intextIpProtocolType.getIpPortMap();
        for (IpPortMap ipPortMap : ipPortMaps) {
            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));
            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.removeFlowToTx(outboundNaptFlowEntity, removeFlowInvTx);
            IpPortExternal ipPortExternal = ipPortMap.getIpPortExternal();
            String externalIp = ipPortExternal.getIpAddress();
            int externalPort = ipPortExternal.getPortNum();
            // Build the flow for the inbound NAPT table
            switchFlowRef = NatUtil.getNaptFlowRef(dpnId, NwConstants.INBOUND_NAPT_TABLE, String.valueOf(routerId), externalIp, externalPort);
            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.removeFlowToTx(inboundNaptFlowEntity, removeFlowInvTx);
        }
    }
}
Also used : IpPortMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.IpPortMapping) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) 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) BigInteger(java.math.BigInteger) 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)

Example 22 with ExternalIps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.

the class ExternalRoutersListener method installNaptPfibExternalOutputFlow.

protected void installNaptPfibExternalOutputFlow(String routerName, Long routerId, BigInteger dpnId, WriteTransaction writeFlowInvTx) {
    Long 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) {
            long 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);
            mdsalManager.addFlowToTx(postNaptFlowEntity, writeFlowInvTx);
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 23 with ExternalIps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.

the class ExternalRoutersListener method handleEnableSnat.

public void handleEnableSnat(Routers routers, long routerId, BigInteger primarySwitchId, long bgpVpnId, WriteTransaction writeFlowInvTx) {
    String routerName = routers.getRouterName();
    LOG.info("handleEnableSnat : Handling SNAT for router {}", routerName);
    naptManager.initialiseExternalCounter(routers, routerId);
    subnetRegisterMapping(routers, routerId);
    LOG.debug("handleEnableSnat:About to create and install outbound miss entry in Primary Switch {} for router {}", primarySwitchId, routerName);
    ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, routers.getNetworkId());
    if (extNwProvType == null) {
        LOG.error("handleEnableSnat : External Network Provider Type missing");
        return;
    }
    if (bgpVpnId != NatConstants.INVALID_ID) {
        installFlowsWithUpdatedVpnId(primarySwitchId, routerName, bgpVpnId, routerId, false, writeFlowInvTx, extNwProvType);
    } else {
        // write metadata and punt
        installOutboundMissEntry(routerName, routerId, primarySwitchId, writeFlowInvTx);
        // Now install entries in SNAT tables to point to Primary for each router
        List<BigInteger> switches = naptSwitchSelector.getDpnsForVpn(routerName);
        for (BigInteger dpnId : switches) {
            // Handle switches and NAPT switches separately
            if (!dpnId.equals(primarySwitchId)) {
                LOG.debug("handleEnableSnat : Handle Ordinary switch");
                handleSwitches(dpnId, routerName, routerId, primarySwitchId);
            } else {
                LOG.debug("handleEnableSnat : Handle NAPT switch");
                handlePrimaryNaptSwitch(dpnId, routerName, routerId, writeFlowInvTx);
            }
        }
    }
    Collection<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
    if (externalIps.isEmpty()) {
        LOG.error("handleEnableSnat : Internal External mapping not found for router {}", routerName);
        return;
    } else {
        for (String externalIpAddrPrefix : externalIps) {
            LOG.debug("handleEnableSnat : Calling handleSnatReverseTraffic for primarySwitchId {}, " + "routerName {} and externalIpAddPrefix {}", primarySwitchId, routerName, externalIpAddrPrefix);
            handleSnatReverseTraffic(primarySwitchId, routers, routerId, routerName, externalIpAddrPrefix, writeFlowInvTx);
        }
    }
    LOG.debug("handleEnableSnat : Exit");
}
Also used : ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) BigInteger(java.math.BigInteger)

Example 24 with ExternalIps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.

the class AbstractSnatService method installSnatCommonEntriesForNaptSwitch.

protected void installSnatCommonEntriesForNaptSwitch(Routers routers, BigInteger dpnId, int addOrRemove) {
    String routerName = routers.getRouterName();
    Long routerId = NatUtil.getVpnId(dataBroker, routerName);
    installDefaultFibRouteForSNAT(dpnId, routerId, addOrRemove);
    List<ExternalIps> externalIps = routers.getExternalIps();
    if (externalIps.isEmpty()) {
        LOG.error("AbstractSnatService: installSnatCommonEntriesForNaptSwitch no externalIP present" + " for routerId {}", routerId);
        return;
    }
    // The logic now handle only one external IP per router, others if present will be ignored.
    String externalIp = externalIps.get(0).getIpAddress();
    Uuid externalSubnetId = externalIps.get(0).getSubnetId();
    long extSubnetId = NatConstants.INVALID_ID;
    if (addOrRemove == NwConstants.ADD_FLOW) {
        extSubnetId = NatUtil.getExternalSubnetVpnId(dataBroker, externalSubnetId);
    }
    installInboundFibEntry(dpnId, externalIp, routerId, extSubnetId, addOrRemove);
    installInboundTerminatingServiceTblEntry(dpnId, routerId, extSubnetId, addOrRemove);
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)

Example 25 with ExternalIps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.

the class ConntrackBasedSnatService method installSnatSpecificEntriesForNaptSwitch.

@Override
protected void installSnatSpecificEntriesForNaptSwitch(Routers routers, BigInteger dpnId, int addOrRemove) {
    LOG.info("installSnatSpecificEntriesForNaptSwitch: called for router {}", routers.getRouterName());
    String routerName = routers.getRouterName();
    Long routerId = NatUtil.getVpnId(getDataBroker(), routerName);
    int elanId = NatUtil.getElanInstanceByName(routers.getNetworkId().getValue(), getDataBroker()).getElanTag().intValue();
    /* Install Outbound NAT entries */
    installSnatMissEntryForPrimrySwch(dpnId, routerId, elanId, addOrRemove);
    installTerminatingServiceTblEntry(dpnId, routerId, elanId, addOrRemove);
    String extGwMacAddress = NatUtil.getExtGwMacAddFromRouterName(getDataBroker(), routerName);
    createOutboundTblTrackEntry(dpnId, routerId, extGwMacAddress, addOrRemove);
    List<ExternalIps> externalIps = routers.getExternalIps();
    if (externalIps.isEmpty()) {
        LOG.error("AbstractSnatService: installSnatCommonEntriesForNaptSwitch no externalIP present" + " for routerId {}", routerId);
        return;
    }
    // The logic now handle only one external IP per router, others if present will be ignored.
    String externalIp = externalIps.get(0).getIpAddress();
    Uuid externalSubnetId = externalIps.get(0).getSubnetId();
    long extSubnetId = NatConstants.INVALID_ID;
    if (addOrRemove == NwConstants.ADD_FLOW) {
        extSubnetId = NatUtil.getExternalSubnetVpnId(getDataBroker(), externalSubnetId);
    }
    createOutboundTblEntry(dpnId, routerId, externalIp, elanId, extGwMacAddress, addOrRemove);
    installNaptPfibFlow(routers, dpnId, routerId, extSubnetId, addOrRemove);
    // Install Inbound NAT entries
    installInboundEntry(dpnId, routerId, externalIp, elanId, extSubnetId, addOrRemove);
    installNaptPfibEntry(dpnId, routerId, addOrRemove);
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)23 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)15 BigInteger (java.math.BigInteger)10 ArrayList (java.util.ArrayList)8 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)8 ExecutionException (java.util.concurrent.ExecutionException)6 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)6 UnknownHostException (java.net.UnknownHostException)5 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)5 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)4 IpPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMap)4 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)4 HashSet (java.util.HashSet)3 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)3 IntextIpPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpPortMap)3 IpPortMapping (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.IpPortMapping)3 IntextIpProtocolType (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.IntextIpProtocolType)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 InetAddress (java.net.InetAddress)2 List (java.util.List)2