Search in sources :

Example 46 with Metadata

use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project netvirt by opendaylight.

the class ElanServiceChainUtils method buildSetLportTagAndGotoLportDispInstructions.

/**
 * Builds a List of Instructions that set the ElanPseudoPort Tag in
 * metadata and sends to LPortDispatcher table (via Table 80).
 *
 * @param lportTag Dataplane identifier of the ElanPseudoPort
 *
 * @return the List of Instructions
 */
public static List<Instruction> buildSetLportTagAndGotoLportDispInstructions(int lportTag) {
    int instructionKey = 0;
    BigInteger metadata = MetaDataUtil.getMetaDataForLPortDispatcher(lportTag, ServiceIndex.getIndex(NwConstants.SCF_SERVICE_NAME, NwConstants.SCF_SERVICE_INDEX));
    List<Instruction> result = Arrays.asList(MDSALUtil.buildAndGetWriteMetadaInstruction(metadata, MetaDataUtil.getMetaDataMaskForLPortDispatcher(), ++instructionKey), MDSALUtil.buildAndGetGotoTableInstruction(NwConstants.L3_INTERFACE_TABLE, ++instructionKey));
    return result;
}
Also used : BigInteger(java.math.BigInteger) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)

Example 47 with Metadata

use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project netvirt by opendaylight.

the class ElanServiceChainUtils method programExternalTunnelTable.

/**
 * This flow is in charge of receiving packets from the TOR and sending
 * them to the SCF Pipeline by setting the LportTag of ElanPseudoPort.
 * Note that ELAN already has a flow in this table that redirects packets
 * to the ELAN Pipeline. However, the flow for the SCF Pipeline will have
 * higher priority, and will only be present when there is a ServiceChain
 * using this ElanPseudoPort.
 * <ul>
 *  <li> Matches on the VNI
 *  <li> Sets SI=1 and ElanPseudoPort tag in the Metadata and sends to
 *    LPortDispatcher via table 80.
 * </ul>
 * @param dpnId Dpn Id where the flow must be installed
 * @param elanLportTag the Elan Pseudo Lport Id to be used in the Dataplane
 * @param vni the VNI to which the Elan is related
 * @param elanTag the Elan Id to be used in the Dataplane
 * @param addOrRemove States if the flow must be added or removed
 */
public static void programExternalTunnelTable(IMdsalApiManager mdsalManager, BigInteger dpnId, int elanLportTag, long vni, int elanTag, int addOrRemove) {
    LOG.info("L2-ServiceChaining: programExternalTunnelTable dpId={} vni={} elanLportTag={} addOrRemove={} ", dpnId, vni, elanLportTag, addOrRemove);
    String flowRef = buildExtTunnelTblToLportDispFlowRef(vni, elanLportTag);
    if (addOrRemove == NwConstants.ADD_FLOW) {
        List<MatchInfo> matches = Collections.singletonList(new MatchTunnelId(BigInteger.valueOf(vni)));
        List<Instruction> instructions = buildSetLportTagAndGotoLportDispInstructions(elanLportTag);
        Flow flow = MDSALUtil.buildFlowNew(NwConstants.EXTERNAL_TUNNEL_TABLE, flowRef, CloudServiceChainConstants.DEFAULT_SCF_FLOW_PRIORITY, flowRef, 0, 0, NwConstants.TUNNEL_TABLE_COOKIE.add(BigInteger.valueOf(elanTag)), matches, instructions);
        mdsalManager.installFlow(dpnId, flow);
    } else {
        Flow flow = new FlowBuilder().setTableId(NwConstants.EXTERNAL_TUNNEL_TABLE).setId(new FlowId(flowRef)).build();
        mdsalManager.removeFlow(dpnId, flow);
    }
}
Also used : FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) MatchTunnelId(org.opendaylight.genius.mdsalutil.matches.MatchTunnelId) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)

Example 48 with Metadata

use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project netvirt by opendaylight.

the class RouterToVpnListener method handleDNATConfigurationForRouterAssociation.

void handleDNATConfigurationForRouterAssociation(String routerName, String vpnName, String externalNetwork) {
    InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerName);
    Optional<RouterPorts> optRouterPorts = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
    if (!optRouterPorts.isPresent()) {
        LOG.debug("handleDNATConfigurationForRouterAssociation : Could not read Router Ports data " + "object with id: {} to handle associate vpn {}", routerName, vpnName);
        return;
    }
    Uuid networkId = Uuid.getDefaultInstance(externalNetwork);
    RouterPorts routerPorts = optRouterPorts.get();
    List<Ports> interfaces = routerPorts.getPorts();
    for (Ports port : interfaces) {
        String portName = port.getPortName();
        BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
        if (dpnId.equals(BigInteger.ZERO)) {
            LOG.warn("handleDNATConfigurationForRouterAssociation : DPN not found for {}, " + "skip handling of router {} association with vpn {}", portName, routerName, vpnName);
            continue;
        }
        List<InternalToExternalPortMap> intExtPortMapList = port.getInternalToExternalPortMap();
        for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
            // remove all NAT related entries with routerName
            // floatingIpListener.removeNATOnlyFlowEntries(dpnId, portName, routerName, null,
            // intExtPortMap.getInternalIp(), externalIp);
            // Create NAT entries with VPN Id
            LOG.debug("handleDNATConfigurationForRouterAssociation : Updating DNAT flows with VPN metadata {} ", vpnName);
            floatingIpListener.createNATOnlyFlowEntries(dpnId, routerName, vpnName, networkId, intExtPortMap);
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports) BigInteger(java.math.BigInteger) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)

Example 49 with Metadata

use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project netvirt by opendaylight.

the class NaptEventHandler method handleEvent.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void handleEvent(final NAPTEntryEvent naptEntryEvent) {
    /*
            Flow programming logic of the OUTBOUND NAPT TABLE :
            1) Get the internal IP address, port number, router ID from the event.
            2) Use the NAPT service getExternalAddressMapping() to get the External IP and the port.
            3) Build the flow for replacing the Internal IP and port with the External IP and port.
              a) Write the matching criteria.
              b) Match the router ID in the metadata.
              d) Write the VPN ID to the metadata.
              e) Write the other data.
              f) Set the apply actions instruction with the action setfield.
            4) Write the flow to the OUTBOUND NAPT Table and forward to FIB table for routing the traffic.

            Flow programming logic of the INBOUND NAPT TABLE :
            Same as Outbound table logic except that :
            1) Build the flow for replacing the External IP and port with the Internal IP and port.
            2) Match the VPN ID in the metadata.
            3) Write the router ID to the metadata.
            5) Write the flow to the INBOUND NAPT Table and forward to FIB table for routing the traffic.
    */
    try {
        Long routerId = naptEntryEvent.getRouterId();
        LOG.trace("handleEvent : Time Elapsed before procesing snat ({}:{}) packet is {} ms," + "routerId: {},isPktProcessed:{}", naptEntryEvent.getIpAddress(), naptEntryEvent.getPortNumber(), System.currentTimeMillis() - naptEntryEvent.getObjectCreationTime(), routerId, naptEntryEvent.isPktProcessed());
        // Get the DPN ID
        BigInteger dpnId = NatUtil.getPrimaryNaptfromRouterId(dataBroker, routerId);
        long bgpVpnId = NatConstants.INVALID_ID;
        if (dpnId == null) {
            LOG.warn("handleEvent : dpnId is null. Assuming the router ID {} as the BGP VPN ID and proceeding....", routerId);
            bgpVpnId = routerId;
            LOG.debug("handleEvent : BGP VPN ID {}", bgpVpnId);
            String vpnName = NatUtil.getRouterName(dataBroker, bgpVpnId);
            String routerName = NatUtil.getRouterIdfromVpnInstance(dataBroker, vpnName);
            if (routerName == null) {
                LOG.error("handleEvent : Unable to find router for VpnName {}", vpnName);
                return;
            }
            routerId = NatUtil.getVpnId(dataBroker, routerName);
            LOG.debug("handleEvent : Router ID {}", routerId);
            dpnId = NatUtil.getPrimaryNaptfromRouterId(dataBroker, routerId);
            if (dpnId == null) {
                LOG.error("handleEvent : dpnId is null for the router {}", routerId);
                return;
            }
        }
        if (naptEntryEvent.getOperation() == NAPTEntryEvent.Operation.ADD) {
            LOG.debug("handleEvent : Inside Add operation of NaptEventHandler");
            // Build and install the NAPT translation flows in the Outbound and Inbound NAPT tables
            if (!naptEntryEvent.isPktProcessed()) {
                // Get the External Gateway MAC Address
                String extGwMacAddress = NatUtil.getExtGwMacAddFromRouterId(dataBroker, routerId);
                if (extGwMacAddress != null) {
                    LOG.debug("handleEvent : External Gateway MAC address {} found for External Router ID {}", extGwMacAddress, routerId);
                } else {
                    LOG.error("handleEvent : No External Gateway MAC address found for External Router ID {}", routerId);
                    return;
                }
                // Get the external network ID from the ExternalRouter model
                Uuid networkId = NatUtil.getNetworkIdFromRouterId(dataBroker, routerId);
                if (networkId == null) {
                    LOG.error("handleEvent : networkId is null");
                    return;
                }
                // Get the VPN ID from the ExternalNetworks model
                Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
                if (vpnUuid == null) {
                    LOG.error("handleEvent : vpnUuid is null");
                    return;
                }
                Long vpnId = NatUtil.getVpnId(dataBroker, vpnUuid.getValue());
                // Get the internal IpAddress, internal port number from the event
                String internalIpAddress = naptEntryEvent.getIpAddress();
                int internalPort = naptEntryEvent.getPortNumber();
                SessionAddress internalAddress = new SessionAddress(internalIpAddress, internalPort);
                NAPTEntryEvent.Protocol protocol = naptEntryEvent.getProtocol();
                // Get the external IP address for the corresponding internal IP address
                SessionAddress externalAddress = naptManager.getExternalAddressMapping(routerId, internalAddress, naptEntryEvent.getProtocol());
                if (externalAddress == null) {
                    LOG.error("handleEvent : externalAddress is null");
                    return;
                }
                Long vpnIdFromExternalSubnet = getVpnIdFromExternalSubnet(routerId, externalAddress.getIpAddress());
                if (vpnIdFromExternalSubnet != NatConstants.INVALID_ID) {
                    vpnId = vpnIdFromExternalSubnet;
                }
                // Added External Gateway MAC Address
                Future<RpcResult<AddFlowOutput>> addFlowResult = buildAndInstallNatFlowsOptionalRpc(dpnId, NwConstants.INBOUND_NAPT_TABLE, vpnId, routerId, bgpVpnId, externalAddress, internalAddress, protocol, extGwMacAddress, true);
                final BigInteger finalDpnId = dpnId;
                final Long finalVpnId = vpnId;
                final Long finalRouterId = routerId;
                final long finalBgpVpnId = bgpVpnId;
                Futures.addCallback(JdkFutureAdapters.listenInPoolThread(addFlowResult), new FutureCallback<RpcResult<AddFlowOutput>>() {

                    @Override
                    public void onSuccess(@Nullable RpcResult<AddFlowOutput> result) {
                        LOG.debug("handleEvent : Configured inbound rule for {} to {}", internalAddress, externalAddress);
                        Future<RpcResult<AddFlowOutput>> addFlowResult = buildAndInstallNatFlowsOptionalRpc(finalDpnId, NwConstants.OUTBOUND_NAPT_TABLE, finalVpnId, finalRouterId, finalBgpVpnId, internalAddress, externalAddress, protocol, extGwMacAddress, true);
                        Futures.addCallback(JdkFutureAdapters.listenInPoolThread(addFlowResult), new FutureCallback<RpcResult<AddFlowOutput>>() {

                            @Override
                            public void onSuccess(@Nullable RpcResult<AddFlowOutput> result) {
                                LOG.debug("handleEvent : Configured outbound rule, sending packet out" + "from {} to {}", internalAddress, externalAddress);
                                prepareAndSendPacketOut(naptEntryEvent, finalRouterId);
                            }

                            @Override
                            public void onFailure(@Nonnull Throwable throwable) {
                                LOG.error("handleEvent : Error configuring outbound " + "SNAT flows using RPC for SNAT connection from {} to {}", internalAddress, externalAddress);
                            }
                        }, MoreExecutors.directExecutor());
                    }

                    @Override
                    public void onFailure(@Nonnull Throwable throwable) {
                        LOG.error("handleEvent : Error configuring inbound SNAT flows " + "using RPC for SNAT connection from {} to {}", internalAddress, externalAddress);
                    }
                }, MoreExecutors.directExecutor());
                NatPacketProcessingState state = naptEntryEvent.getState();
                if (state != null) {
                    state.setFlowInstalledTime(System.currentTimeMillis());
                }
            } else {
                prepareAndSendPacketOut(naptEntryEvent, routerId);
            }
            LOG.trace("handleEvent : Time elapsed after Processsing snat ({}:{}) packet: {}ms,isPktProcessed:{} ", naptEntryEvent.getIpAddress(), naptEntryEvent.getPortNumber(), System.currentTimeMillis() - naptEntryEvent.getObjectCreationTime(), naptEntryEvent.isPktProcessed());
        } else {
            LOG.debug("handleEvent : Inside delete Operation of NaptEventHandler");
            removeNatFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, routerId, naptEntryEvent.getIpAddress(), naptEntryEvent.getPortNumber());
            LOG.info("handleEvent : exited for removeEvent for IP {}, port {}, routerID : {}", naptEntryEvent.getIpAddress(), naptEntryEvent.getPortNumber(), routerId);
        }
    } catch (Exception e) {
        LOG.error("handleEvent :Exception in NaptEventHandler.handleEvent() payload {}", naptEntryEvent, e);
    }
}
Also used : AddFlowOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput) Nonnull(javax.annotation.Nonnull) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) NatPacketProcessingState(org.opendaylight.netvirt.natservice.internal.NaptPacketInHandler.NatPacketProcessingState) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) BigInteger(java.math.BigInteger) Future(java.util.concurrent.Future) FutureCallback(com.google.common.util.concurrent.FutureCallback) Nullable(javax.annotation.Nullable)

Example 50 with Metadata

use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata 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)

Aggregations

BigInteger (java.math.BigInteger)44 ArrayList (java.util.ArrayList)34 Test (org.junit.Test)22 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)14 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)13 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)13 ByteBuf (io.netty.buffer.ByteBuf)10 MetadataBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder)10 MatchEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry)8 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)7 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)7 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)7 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)7 MatchEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder)7 MatchTunnelId (org.opendaylight.genius.mdsalutil.matches.MatchTunnelId)6 PhysAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress)6 Metadata (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata)6 WriteMetadataCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteMetadataCaseBuilder)6 InstructionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder)6 List (java.util.List)5