Search in sources :

Example 36 with Routers

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers 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 37 with Routers

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

the class ExternalRoutersListener method allocateExternalIp.

private void allocateExternalIp(BigInteger dpnId, Routers router, long routerId, String routerName, Uuid networkId, String subnetIp, WriteTransaction writeFlowInvTx) {
    String[] subnetIpParts = NatUtil.getSubnetIpAndPrefix(subnetIp);
    try {
        InetAddress address = InetAddress.getByName(subnetIpParts[0]);
        if (address instanceof Inet6Address) {
            LOG.debug("allocateExternalIp : Skipping ipv6 address {} for the router {}.", address, routerName);
            return;
        }
    } catch (UnknownHostException e) {
        LOG.error("allocateExternalIp : Invalid ip address {}", subnetIpParts[0], e);
        return;
    }
    String leastLoadedExtIpAddr = NatUtil.getLeastLoadedExternalIp(dataBroker, routerId);
    if (leastLoadedExtIpAddr != null) {
        String[] externalIpParts = NatUtil.getExternalIpAndPrefix(leastLoadedExtIpAddr);
        String leastLoadedExtIp = externalIpParts[0];
        String leastLoadedExtIpPrefix = externalIpParts[1];
        IPAddress externalIpAddr = new IPAddress(leastLoadedExtIp, Integer.parseInt(leastLoadedExtIpPrefix));
        subnetIp = subnetIpParts[0];
        String subnetIpPrefix = subnetIpParts[1];
        IPAddress subnetIpAddr = new IPAddress(subnetIp, Integer.parseInt(subnetIpPrefix));
        LOG.debug("allocateExternalIp : Add the IP mapping for the router ID {} and internal " + "IP {} and prefix {} -> external IP {} and prefix {}", routerId, subnetIp, subnetIpPrefix, leastLoadedExtIp, leastLoadedExtIpPrefix);
        naptManager.registerMapping(routerId, subnetIpAddr, externalIpAddr);
        // Check if external IP is already assigned a route. (i.e. External IP is previously
        // allocated to any of the subnets)
        // If external IP is already assigned a route, (, do not re-advertise to the BGP
        String leastLoadedExtIpAddrStr = leastLoadedExtIp + "/" + leastLoadedExtIpPrefix;
        Long label = checkExternalIpLabel(routerId, leastLoadedExtIpAddrStr);
        if (label != null) {
            // update
            String internalIp = subnetIpParts[0] + "/" + subnetIpParts[1];
            IpMapKey ipMapKey = new IpMapKey(internalIp);
            LOG.debug("allocateExternalIp : Setting label {} for internalIp {} and externalIp {}", label, internalIp, leastLoadedExtIpAddrStr);
            IpMap newIpm = new IpMapBuilder().setKey(ipMapKey).setInternalIp(internalIp).setExternalIp(leastLoadedExtIpAddrStr).setLabel(label).build();
            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, naptManager.getIpMapIdentifier(routerId, internalIp), newIpm);
            return;
        }
        // Re-advertise to the BGP for the external IP, which is allocated to the subnet
        // for the first time and hence not having a route.
        // Get the VPN Name using the network ID
        final String vpnName = NatUtil.getAssociatedVPN(dataBroker, networkId);
        if (vpnName != null) {
            LOG.debug("allocateExternalIp : Retrieved vpnName {} for networkId {}", vpnName, networkId);
            if (dpnId == null || dpnId.equals(BigInteger.ZERO)) {
                LOG.debug("allocateExternalIp : Best effort for getting primary napt switch when router i/f are" + "added after gateway-set");
                dpnId = NatUtil.getPrimaryNaptfromRouterId(dataBroker, routerId);
                if (dpnId == null || dpnId.equals(BigInteger.ZERO)) {
                    LOG.error("allocateExternalIp : dpnId is null or Zero for the router {}", routerName);
                    return;
                }
            }
            advToBgpAndInstallFibAndTsFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, vpnName, routerId, routerName, leastLoadedExtIp + "/" + leastLoadedExtIpPrefix, networkId, router, writeFlowInvTx);
        }
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) IpMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMapKey) Inet6Address(java.net.Inet6Address) InetAddress(java.net.InetAddress) IpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMap) IpMapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMapBuilder)

Example 38 with Routers

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

the class ExternalRoutersListener method createFibTableCustomInstructions.

private List<Instruction> createFibTableCustomInstructions(short tableId, String routerName, String externalIp) {
    List<Instruction> fibTableCustomInstructions = new ArrayList<>();
    Routers router = NatUtil.getRoutersFromConfigDS(dataBroker, routerName);
    long externalSubnetVpnId = NatUtil.getExternalSubnetVpnIdForRouterExternalIp(dataBroker, externalIp, router);
    int instructionIndex = 0;
    if (externalSubnetVpnId != NatConstants.INVALID_ID) {
        BigInteger subnetIdMetaData = MetaDataUtil.getVpnIdMetadata(externalSubnetVpnId);
        fibTableCustomInstructions.add(new InstructionWriteMetadata(subnetIdMetaData, MetaDataUtil.METADATA_MASK_VRFID).buildInstruction(instructionIndex));
        instructionIndex++;
    }
    fibTableCustomInstructions.add(new InstructionGotoTable(tableId).buildInstruction(instructionIndex));
    return fibTableCustomInstructions;
}
Also used : InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) ExtRouters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) InstructionWriteMetadata(org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)

Example 39 with Routers

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers 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 40 with Routers

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

the class SnatCentralizedSwitchChangeListener method update.

@Override
protected void update(InstanceIdentifier<RouterToNaptSwitch> key, RouterToNaptSwitch origRouterToNaptSwitch, RouterToNaptSwitch updatedRouterToNaptSwitch) {
    LOG.debug("Updating old {} new {}", origRouterToNaptSwitch, updatedRouterToNaptSwitch);
    BigInteger primarySwitchId = origRouterToNaptSwitch.getPrimarySwitchId();
    Routers router = NatUtil.getRoutersFromConfigDS(dataBroker, origRouterToNaptSwitch.getRouterName());
    natDataUtil.updateRouterMap(router);
    snatServiceManger.notify(router, primarySwitchId, null, SnatServiceManager.Action.SNAT_ALL_SWITCH_DISBL);
}
Also used : Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) BigInteger(java.math.BigInteger)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)33 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)26 BigInteger (java.math.BigInteger)22 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)16 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)12 ArrayList (java.util.ArrayList)11 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)7 UnknownHostException (java.net.UnknownHostException)6 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)6 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)6 RoutersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersBuilder)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 ExecutionException (java.util.concurrent.ExecutionException)5 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)5 InetAddress (java.net.InetAddress)4 List (java.util.List)4 ExtRouters (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters)4 IpPortMapping (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.IpPortMapping)4 IntextIpProtocolType (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.IntextIpProtocolType)4 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)3