Process Switching Vs Fast Switching Vs CEF

In this article, we will discuss evolving packet-switching methods.

Packet Switching is the method of moving a packet from a router's input interface to an output interface. When Cisco routers were first developed and deployed, only one way existed to switch the packets; this was called process switching. As the networks evolved, Cisco developed more scalable, cache-based packet-switching methods, known as fast switching and Cisco Express Forwarding(CEF).

Process Switching:

Process switching refers to the process by which the router's CPU or processor is directly involved in the forwarding decision. As a packet is process-switched through the router, its CPU is responsible of choosing the appropriate process to handle the packet and scheduling the running of the process.

Below steps briefly outline the order of operation while it is being process-switched through a router.

  1. The data arrives on the inbound interface. 2. The router reads the packet and stores it the memory
  2. The router performs a lookup in the global routing table (show ip route) for the packet's destination IP address.
  3. Based on the outcome of this lookup, the process switches out the packet on a particular interface after it does some housekeeping on the IP header. This housekeeping includes the lowering of the Time To Live (TTL) field and the recalculation of the cyclic redundancy check (CRC) of the IP header.4. The router finds the next-hop IP address towards the destination by resolving any recursion within routing table.
  4. The router finds the physical layer 2 header and outbound interface for net-hop device. This information is written onto the packet to forward it to next hop towards destination. Generally, this involves looking into ARP cache/table or some table that maps a next-hop device to a layer 2 address.
  5. The router re-writes the physical layer 2 header address to the packet (i.e. frame building).
Early in the development of Cisco routers, it became clear to the Cisco engineers that process switching was no going to be able to handle packets fast enough to attain the speeds needed as the traffic flows were increasing at a rapid pace across the networks and the routers had to be designed to keep up.

A classic idea was applied to the problem. Why not cache the results of the IP next-hop and layer 2 look-ups and use them to switch the next packet towards a given destination. This concept gave birth to fast switching.


Fast Switching:

Fast Switching relies on a demand based cache to forward packets. The first packet is copied to packet memory, and the if the destination network is found in fast switching cache, the frame is rewritten and sent to outgoing interface. If the destination address is not present in the fast-switching cache, the packet is returned to process switching path, where the processor attempts to build a cache entry which can be used to forward packets to the destination.

In short, in fast switching, the 1st packet to a specific destination is process switched to outgoing interface and a cache is build. Next time if the packet to same destination enters the router's inbound interface, the cache build (fast switching) is used to switch the packet quickly without involving the router's CPU.

It was noticed that Demand based switching (fast switching) caches and rapid routing changes do no work well together. Each time the cache becomes settled, a new routing change in routing table used to clear portion of cache entry leading the packet to process switched. If the rate of routing changes become great enough, the percentage of packet switched via fast switching become so low and no efficiency is gained by caching mechanism.

Command to enable fast-switching

Router#conf t
Router (config)#int f1/0
Router(config-if)#ip route-cache


Cisco Express Forwarding (CEF)

CEF switching is a proprietary and advanced Layer3 IP switching mechanism that was designed to tackle the deficiencies associated with fast-switching. CEF optimizes performance, scalability, and resiliency for large and complex networks with dynamic traffic patterns. CEF's retrieval and packet forwarding technique is less CPU intensive than process or fast switching. This results in higher throughput when CEF is enabled.

There are 2 main components of CEF:
  • The Forwarding Information Base (FIB)
  • The adjacency table



Forwarding Information Base:

The FIB is a dynamically build database used by the router to make prefix based forwarding decisions. The information in FIB is all the necessary details copied from router's global routing table. The FIB also pre-computes recursive path look ups. The FIB is organized in a way to optimize fast retrieval and longest-match lookups. The FIB is a multi-way tree or simply an mtrie, that stores reachability of information about destinations and their respective next hops.

An mtrie is a searchable data structure, made up of nodes and leaves, that focuses on fast retrieval of data, rather than the primary concern of sorting and sorting information.

Useful commands:

To check FIB entries (all) or a specific entry, use below commands.

R1#show ip cef

R1#sh ip cef 192.9.1.5
192.9.1.5/32
  nexthop 10.10.12.2 FastEthernet1/0

R1#sh cef interface f1/0 | i IP
  IP unicast RPF check is disabled
  IP policy routing is disabled
  IP CEF switching enabled
  IP CEF switching turbo vector
  IP CEF turbo switching turbo vector
  IP prefix lookup IPv4 mtrie 8-8-8-8 optimized
  IP MTU 1500



Adjacency Table:

After the router has determined a destination's reachability and next hop, the next step is to discover the outbound interface, the layer 2 header rewrite string, and any other information that might be needed to transmit a packet toward the next-hop. This information is stored in Adjacency table.

R1#sh adjacency detail
Protocol Interface                 Address
IP       FastEthernet1/0           10.10.12.2(14)
                                   0 packets, 0 bytes
                                   epoch 0
                                   sourced in sev-epoch 0
                                   Encap length 14
                                   CA0220B4001CCA0120B4001C0800   >>> Layer2 rewrite
                                   L2 destination address byte offset 0
                                   L2 destination address byte length 6
                                   Link-type after encap: ip
                                   ARP
IP       FastEthernet2/0           10.10.14.4(14)
                                   0 packets, 0 bytes
                                   epoch 0
                                   sourced in sev-epoch 0
                                   Encap length 14
                                   CA035F68001CCA0120B400380800
                                   L2 destination address byte offset 0
                                   L2 destination address byte length 6
                                   Link-type after encap: ip
                                   ARP



How to read the L2 rewrite "CA0220B4001CCA0120B4001C0800"

There is an fast-Ethernet link between R1 and R2. Taking example of an Ethernet II frame, we will have 1st the Destination MAC, 2nd Source MAC, 3rd the Type field

  • CA0220B4001C - Destination MAC (or MAC of F1/0 interface of R2)
  • CA0120B4001C - Source MAC (or MAC of F1/0 interface of R1)
  • 0800 - Type field in Ethernet II frame that resembles IP. i.e. the frame will be delivered to IP layer as per TCP/IP protocol stack.

CEF has 2 modes of operation

Centralized Mode of operation: The CEF FIB and adjacency tables reside on the RP(Route Processor or CPU - Control Plane), and the RP performs the express forwarding. You can use CEF mode when line cards are not available for CEF switching or when you need to use features not compatible with dCEF switching. Command to enable CEF in centralized mode (software mode).

R1(config)#ip cef

Distributed Mode of operation: When dCEF is enabled, line cards, such as VIP line cards or Cisco 7600 or 12000 Series line cards, maintain an identical copy of the FIB and adjacency tables. The line cards perform the express forwarding between port adapters, relieving the RSP of involvement in the switching operation. Command to enable CEF in distributed mode.

R1(config)#ip cef distributed

While we enabled dCEF on a Cisco 7600 node, we can see the packets are dCEF switched per line card.

Router#   sh int stats
ATM0/0/0
          Switching path    Pkts In   Chars In   Pkts Out  Chars Out
               Processor  169389656 103056618101  172702168 40544119598
             Route cache  102596370 16264833810       3078     795080
       Distributed cache 21675816612 8280306371084 23066687634 10029432488761
                   Total 21947802638 8399627822995 23239392880 10069977403439
FastEthernet0/1/0
          Switching path    Pkts In   Chars In   Pkts Out  Chars Out
               Processor   29755883 5287630381    5169010  311324825
             Route cache          0          0          0          0
       Distributed cache          0          0   28307490 6515084896
                   Total   29755883 5287630381   33476500 6826409721
ATM1/0/0
          Switching path    Pkts In   Chars In   Pkts Out  Chars Out
               Processor  104910587 5885001178  104892951 5923231448
             Route cache      12237    2141191          3        599
       Distributed cache 28818469356 8864504969469 28307872894 10698993329424
                   Total 28923392180 8870392111838 28412765848 10704916561471
Serial1/1/0
          Switching path    Pkts In   Chars In   Pkts Out  Chars Out
               Processor 1794153495 14768437601   13251408  533937190
             Route cache        271      70453          5        512
       Distributed cache  607447753 227898389080  638931401 437045815101
                   Total 2401601519 242666897134  652182814 437579752803


Resulting Switching method based on Ingress and Egress switching config:


One important thing to understand is CEF resides on the RP (route processor) and only the packet headers are processed by the CEF/dCEF table, residing on the Central RP or Line card processor respectively, and not the complete packet. Below are few informative snapshots from Cisco 7600 chassis that supports both

                                                           Centralized Forwarding
  1. Packet enters the inbound interface of a line card from a Source S and the Port ASIC forwards it to Fabric interface.
  2. Packet header (only and not complete packet) is forwarded to the RP (Route processor is combination of Switch processor and Route  processor) where CEF table is present.
  3. Centralized CEF (that resides on the RP) processes the packet. Processing the packet means it looks up the FIB for next hop and fetches the L2 rewrite(header), modifies the original header, and sends the updated header to the interface Fabric of same line card.
  4. The packet from the interface fabric is then forwarded to the interface fabric of outbound line card using the outbound Int + L2 rewrite details shared by CEF in step 3.
  5. The packet is forwarded from interface fabric of outbound interface to outbound port and released on wire towards Destination D.
                                                         Distributed Forwarding

  1. Packet enters the inbound interface of a line card from a Source S and the Port ASIC forwards it to Fabric interface replication engine.
  2. Packet header (only and not complete packet) is not forwarded to the RP but to the Line card processor (where a copy of CEF resides).
  3. dCEF (that resides on the Line card processor) processes the packet. Processing the packet means it looks up the FIB for next hop and fetches the L2 rewrite(header), modifies the original header and sends the updated header to the Fabric interface replication engine of same line card.
  4. The packet from the Fabric interface replication engine is then forwarded to the Fabric interface replication engine of outbound line card using the outbound Int + L2 rewrite details shared by dCEF in step 3.
  5. The packet is forwarded from Fabric interface replication engine of outbound interface to outbound port and released on wire towards Destination D.


If you understood the concept and liked this article, kindly share the same with your friends