Search in sources :

Example 56 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.

the class SubnetRoutePacketInHandler method handlePacketFromTunnelToExternalNetwork.

private void handlePacketFromTunnelToExternalNetwork(String vpnIdVpnInstanceName, String srcIpStr, byte[] dstIp, String dstIpStr, long elanTag) throws UnknownHostException {
    String routerId = vpnUtil.getAssociatedExternalRouter(srcIpStr);
    if (null == routerId) {
        LOG.debug("This ip is not associated with any external router: {}", srcIpStr);
        return;
    }
    handlePacketToExternalNetwork(new Uuid(vpnIdVpnInstanceName), routerId, dstIp, dstIpStr, elanTag);
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 57 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.

the class SubnetRoutePacketInHandler method handlePacketToExternalNetwork.

private void handlePacketToExternalNetwork(Uuid vpnInstanceNameUuid, String routerId, byte[] dstIp, String dstIpStr, long elanTag) throws UnknownHostException {
    Routers externalRouter = vpnUtil.getExternalRouter(routerId);
    if (externalRouter == null) {
        Counter counter = packetInCounter.label(CounterUtility.subnet_route_packet_failed.toString()).label("." + dstIpStr);
        counter.increment();
        LOG.debug("{} handlePacketToExternalNetwork: Can't find external router with id {}", LOGGING_PREFIX, routerId);
        return;
    }
    Map<ExternalIpsKey, ExternalIps> externalIpsMap = externalRouter.getExternalIps();
    if (externalIpsMap == null || externalIpsMap.isEmpty()) {
        Counter counter = packetInCounter.label(CounterUtility.subnet_route_packet_failed.toString()).label("." + dstIpStr);
        counter.increment();
        LOG.debug("{} handlePacketToExternalNetwork: Router {} doesn't have any external ips.", LOGGING_PREFIX, externalRouter.getRouterName());
        return;
    }
    java.util.Optional<ExternalIps> externalIp = externalRouter.getExternalIps().values().stream().filter(eip -> vpnInstanceNameUuid.equals(eip.getSubnetId())).findFirst();
    if (!externalIp.isPresent()) {
        Counter counter = packetInCounter.label(CounterUtility.subnet_route_packet_failed.toString()).label(externalIp.get().getIpAddress() + "." + dstIpStr);
        counter.increment();
        LOG.debug("{} handlePacketToExternalNetwork: Router {} doesn't have an external ip for subnet id {}.", LOGGING_PREFIX, externalRouter.getRouterName(), vpnInstanceNameUuid);
        return;
    }
    Uint64 dpnId = centralizedSwitchProvider.getPrimarySwitchForRouter(externalRouter.getRouterName());
    if (Uint64.ZERO.equals(dpnId)) {
        Counter counter = packetInCounter.label(CounterUtility.subnet_route_packet_failed.toString()).label(externalIp.get().getIpAddress() + "." + dstIpStr);
        counter.increment();
        LOG.debug("{} handlePacketToExternalNetwork: Could not find primary switch for router {}.", LOGGING_PREFIX, externalRouter.getRouterName());
        return;
    }
    transmitArpOrNsPacket(dpnId, externalIp.get().getIpAddress(), externalRouter.getExtGwMacAddress(), dstIp, dstIpStr, elanTag);
    Counter counter = packetInCounter.label(CounterUtility.subnet_route_packet_processed.toString()).label(externalIp.get().getIpAddress() + "." + dstIpStr);
    counter.increment();
}
Also used : SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) MetricDescriptor(org.opendaylight.infrautils.metrics.MetricDescriptor) BitBufferHelper(org.opendaylight.openflowplugin.libraries.liblldp.BitBufferHelper) LoggerFactory(org.slf4j.LoggerFactory) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) IPv4(org.opendaylight.genius.mdsalutil.packet.IPv4) InetAddress(java.net.InetAddress) PacketProcessingService(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService) Nullable(org.eclipse.jdt.annotation.Nullable) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) Map(java.util.Map) LoggingFutures(org.opendaylight.infrautils.utils.concurrent.LoggingFutures) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) ArpUtils(org.opendaylight.netvirt.vpnmanager.iplearn.ipv4.ArpUtils) ICentralizedSwitchProvider(org.opendaylight.netvirt.vpnmanager.api.ICentralizedSwitchProvider) Ipv6Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address) VpnIds(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.id.to.vpn.instance.VpnIds) Packet(org.opendaylight.openflowplugin.libraries.liblldp.Packet) Ethernet(org.opendaylight.genius.mdsalutil.packet.Ethernet) CounterUtility(org.opendaylight.netvirt.vpnmanager.utilities.CounterUtility) VpnHelper(org.opendaylight.netvirt.vpnmanager.api.VpnHelper) List(java.util.List) IpPrefixBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefixBuilder) ElanTagName(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.tag.name.map.ElanTagName) Labeled(org.opendaylight.infrautils.metrics.Labeled) Ipv6NdUtilService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.ipv6.nd.util.rev170210.Ipv6NdUtilService) Optional(java.util.Optional) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps) PacketReceived(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived) VpnInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface) NWUtil(org.opendaylight.genius.mdsalutil.NWUtil) MetricProvider(org.opendaylight.infrautils.metrics.MetricProvider) Uint64(org.opendaylight.yangtools.yang.common.Uint64) OdlInterfaceRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService) PacketProcessingListener(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingListener) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) NetworkMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMap) Inject(javax.inject.Inject) IfTunnel(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) BufferException(org.opendaylight.openflowplugin.libraries.liblldp.BufferException) IInterfaceManager(org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Logger(org.slf4j.Logger) TransmitPacketInput(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput) Ints(com.google.common.primitives.Ints) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry) VpnPortipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort) ExternalIpsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIpsKey) IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) Counter(org.opendaylight.infrautils.metrics.Counter) HexEncode(org.opendaylight.openflowplugin.libraries.liblldp.HexEncode) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) MetaDataUtil(org.opendaylight.genius.mdsalutil.MetaDataUtil) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) IpAddressBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder) ExternalIpsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIpsKey) Counter(org.opendaylight.infrautils.metrics.Counter) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 58 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.

the class VPNServiceChainHandler method programVpnToScfPipeline.

/**
 * Programs the necessary flows in LFIB and LPortDispatcher table so that
 * the packets coming from a given VPN are delivered to a given
 * ServiceChain Pipeline.
 *
 * @param vpnName Name of the VPN. Typically the UUID
 * @param tableId Table to which the LPortDispatcher table sends the packet
 *                 to (Uplink or Downlink Subsc table)
 * @param scfTag Scf tag to the SCF to which the Vpn is linked to.
 * @param lportTag VpnPseudo Port lportTag
 * @param addOrRemove States if the VPN2SCF Pipeline must be installed or
 *        removed
 */
public void programVpnToScfPipeline(String vpnName, short tableId, long scfTag, int lportTag, int addOrRemove) {
    // This entries must be created in the DPN where the CGNAT is installed. Since it is not possible
    // to know where CGNAT is located, this entries are installed in all the VPN footprint.
    // LFIB:
    // - Match: cgnatLabel   Instr: lportTag=vpnPseudoPortTag + SI=SCF  +  GOTO 17
    // LportDisp:
    // - Match: vpnPseudoPortTag + SI==SCF   Instr:  scfTag  +  GOTO 70
    LOG.info("programVpnToScfPipeline ({}) : Parameters VpnName:{} tableId:{} scftag:{}  lportTag:{}", addOrRemove == NwConstants.ADD_FLOW ? "Creation" : "Removal", vpnName, tableId, scfTag, lportTag);
    String rd = VpnServiceChainUtils.getVpnRd(dataBroker, vpnName);
    LOG.debug("Router distinguisher (rd):{}", rd);
    if (rd == null || rd.isEmpty()) {
        LOG.warn("programVpnToScfPipeline: Could not find Router-distinguisher for VPN {}. No further actions", vpnName);
        return;
    }
    VpnInstanceOpDataEntry vpnInstance = getVpnInstance(rd);
    if (vpnInstance == null) {
        LOG.warn("Could not find a suitable VpnInstance for Route-Distinguisher={}", rd);
        return;
    }
    // Find out the set of DPNs for the given VPN ID
    Collection<VpnToDpnList> vpnToDpnList = vpnInstance.getVpnToDpnList();
    List<VrfEntry> vrfEntries = VpnServiceChainUtils.getAllVrfEntries(dataBroker, rd);
    if (vrfEntries != null) {
        if (addOrRemove == NwConstants.ADD_FLOW) {
            AddVpnPseudoPortDataJob updateVpnToPseudoPortTask = new AddVpnPseudoPortDataJob(dataBroker, rd, lportTag, tableId, (int) scfTag);
            jobCoordinator.enqueueJob(updateVpnToPseudoPortTask.getDsJobCoordinatorKey(), updateVpnToPseudoPortTask);
        } else {
            RemoveVpnPseudoPortDataJob removeVpnPseudoPortDataTask = new RemoveVpnPseudoPortDataJob(dataBroker, rd);
            jobCoordinator.enqueueJob(removeVpnPseudoPortDataTask.getDsJobCoordinatorKey(), removeVpnPseudoPortDataTask);
        }
        for (VpnToDpnList dpnInVpn : vpnToDpnList) {
            BigInteger dpnId = dpnInVpn.getDpnId();
            programVpnToScfPipelineOnDpn(dpnId, vrfEntries, tableId, (int) scfTag, lportTag, addOrRemove);
            if (dpnInVpn.getVpnInterfaces() != null) {
                long vpnId = vpnInstance.getVpnId();
                Flow flow = VpnServiceChainUtils.buildLPortDispFromScfToL3VpnFlow(vpnId, dpnId, lportTag, NwConstants.ADD_FLOW);
                if (addOrRemove == NwConstants.ADD_FLOW) {
                    mdsalManager.installFlow(dpnId, flow);
                } else {
                    mdsalManager.removeFlow(dpnId, flow);
                }
                dpnInVpn.getVpnInterfaces().forEach(vpnIf -> {
                    if (addOrRemove == NwConstants.ADD_FLOW) {
                        bindScfOnVpnInterface(vpnIf.getInterfaceName(), (int) scfTag);
                    } else {
                        unbindScfOnVpnInterface(vpnIf.getInterfaceName());
                    }
                });
            }
        }
    }
}
Also used : VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) VpnToDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList) BigInteger(java.math.BigInteger) AddVpnPseudoPortDataJob(org.opendaylight.netvirt.cloudservicechain.jobs.AddVpnPseudoPortDataJob) RemoveVpnPseudoPortDataJob(org.opendaylight.netvirt.cloudservicechain.jobs.RemoveVpnPseudoPortDataJob) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)

Example 59 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router 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 60 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.

the class ExternalRoutersListener method subnetRegisterMapping.

protected void subnetRegisterMapping(Routers routerEntry, Uint32 segmentId) {
    LOG.debug("subnetRegisterMapping : Fetching values from extRouters model");
    List<String> externalIps = NatUtil.getIpsListFromExternalIps(new ArrayList<ExternalIps>(routerEntry.nonnullExternalIps().values()));
    int counter = 0;
    int extIpCounter = externalIps.size();
    LOG.debug("subnetRegisterMapping : counter values before looping counter {} and extIpCounter {}", counter, extIpCounter);
    @Nullable List<Uuid> subnetIds = routerEntry.getSubnetIds();
    if (subnetIds == null) {
        return;
    }
    for (Uuid subnet : subnetIds) {
        LOG.debug("subnetRegisterMapping : Looping internal subnets for subnet {}", subnet);
        InstanceIdentifier<Subnetmap> subnetmapId = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnet)).build();
        Optional<Subnetmap> sn;
        try {
            sn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetmapId);
        } catch (InterruptedException | ExecutionException e) {
            LOG.error("Failed to read SubnetMap for  subnetmap Id {}", subnetmapId, e);
            sn = Optional.empty();
        }
        if (sn.isPresent()) {
            // subnets
            Subnetmap subnetmapEntry = sn.get();
            String subnetString = subnetmapEntry.getSubnetIp();
            String[] subnetSplit = subnetString.split("/");
            String subnetIp = subnetSplit[0];
            try {
                InetAddress address = InetAddress.getByName(subnetIp);
                if (address instanceof Inet6Address) {
                    LOG.debug("subnetRegisterMapping : Skipping ipv6 subnet {} for the router {} with ipv6 address " + "{} ", subnet, routerEntry.getRouterName(), address);
                    continue;
                }
            } catch (UnknownHostException e) {
                LOG.error("subnetRegisterMapping : Invalid ip address {}", subnetIp, e);
                return;
            }
            String subnetPrefix = "0";
            if (subnetSplit.length == 2) {
                subnetPrefix = subnetSplit[1];
            }
            IPAddress subnetAddr = new IPAddress(subnetIp, Integer.parseInt(subnetPrefix));
            LOG.debug("subnetRegisterMapping : subnetAddr is {} and subnetPrefix is {}", subnetAddr.getIpAddress(), subnetAddr.getPrefixLength());
            // externalIps
            LOG.debug("subnetRegisterMapping : counter values counter {} and extIpCounter {}", counter, extIpCounter);
            if (extIpCounter != 0) {
                if (counter < extIpCounter) {
                    String[] ipSplit = externalIps.get(counter).split("/");
                    String externalIp = ipSplit[0];
                    String extPrefix = Short.toString(NatConstants.DEFAULT_PREFIX);
                    if (ipSplit.length == 2) {
                        extPrefix = ipSplit[1];
                    }
                    IPAddress externalIpAddr = new IPAddress(externalIp, Integer.parseInt(extPrefix));
                    LOG.debug("subnetRegisterMapping : externalIp is {} and extPrefix  is {}", externalIpAddr.getIpAddress(), externalIpAddr.getPrefixLength());
                    naptManager.registerMapping(segmentId, subnetAddr, externalIpAddr);
                    LOG.debug("subnetRegisterMapping : Called registerMapping for subnetIp {}, prefix {}, " + "externalIp {}. prefix {}", subnetIp, subnetPrefix, externalIp, extPrefix);
                } else {
                    // Reset the counter which runs on externalIps for round-robbin effect
                    counter = 0;
                    LOG.debug("subnetRegisterMapping : Counter on externalIps got reset");
                    String[] ipSplit = externalIps.get(counter).split("/");
                    String externalIp = ipSplit[0];
                    String extPrefix = Short.toString(NatConstants.DEFAULT_PREFIX);
                    if (ipSplit.length == 2) {
                        extPrefix = ipSplit[1];
                    }
                    IPAddress externalIpAddr = new IPAddress(externalIp, Integer.parseInt(extPrefix));
                    LOG.debug("subnetRegisterMapping : externalIp is {} and extPrefix  is {}", externalIpAddr.getIpAddress(), externalIpAddr.getPrefixLength());
                    naptManager.registerMapping(segmentId, subnetAddr, externalIpAddr);
                    LOG.debug("subnetRegisterMapping : Called registerMapping for subnetIp {}, prefix {}, " + "externalIp {}. prefix {}", subnetIp, subnetPrefix, externalIp, extPrefix);
                }
            }
            counter++;
            LOG.debug("subnetRegisterMapping : Counter on externalIps incremented to {}", counter);
        } else {
            LOG.warn("subnetRegisterMapping : No internal subnets present in extRouters Model");
        }
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) Inet6Address(java.net.Inet6Address) 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) SubnetmapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey) ExecutionException(java.util.concurrent.ExecutionException) InetAddress(java.net.InetAddress) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)158 ArrayList (java.util.ArrayList)96 ExecutionException (java.util.concurrent.ExecutionException)88 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)77 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)71 BigInteger (java.math.BigInteger)47 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)47 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)45 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)37 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)37 Inject (javax.inject.Inject)33 Singleton (javax.inject.Singleton)33 Logger (org.slf4j.Logger)33 LoggerFactory (org.slf4j.LoggerFactory)33 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)31 List (java.util.List)29 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)28 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)27 DataBroker (org.opendaylight.mdsal.binding.api.DataBroker)26 UnknownHostException (java.net.UnknownHostException)25