Note: You should read about Content Addressable Memory (CAM) before reading this post.
Today’s networking hardware operates a Layer 2, Layer 3 and Layer 4 of the OSI model. The device might switch Ethernet frames, route IP packets and implement filters based on the TCP segments. A MAC Address is always an exact match and uses Binary CAM but matching an IP Route or Access List requires partial matching. An IP Packet would have a specific destination IP address of 10.0.0.1 but the route is for 10.0.0.0/24.
A Ternary CAM (TCAM) stores 0, 1, and “don’t care”. The “Don’t Care” at an additional cost over binary CAM since the internal memory cell must now encode three possible states. This is usually implemented by adding a mask bit (“care” or “don’t care” bit) to every memory cell.
An access-list is a common function that uses TCAM (ternary content addressable memory) to have the flexibility to match on various layers of a packets L2-L4 headers. That TCAM memory has the ability to match (0), not match(1) (the binary is counterintuitive there) or not care (wildcard). Each field or tuple is searched in parallel all in one clock cycle. Computer science students would recognise a TCAM has an associative array implemented in hardware.
Since all words in a ternary CAM are compared with the input, multiple matches may occur but TCAM logic determines which of the multiple results is most explicit match (longest) to return as a positive result.
TCAM is crucial to OpenFlow because it is so flexible when performing matching. However, TCAM is the most expensive component in a switch which has a large footprint on the silicon die and requires a lot of power. This has secondary effects in packaging (cooling, thermal channels) and manufacturing (SRAM is expensive, difficult to produce at high yields). .
In a typical fixed format switch, the TCAM is the single largest component in the device. For chassis devices, its more complex due to the distributed forwarding planes on each line card.
Not possible in DRAM: Remember that using DRAM in networking is simply too slow to perform a lookup. DRAM memory lookups typically takes multiple clock cycles from the CPU to clock data in and out over the I/O bus (and operates at much lower clock speeds). There are some alternatives to implement hardware using Hash Based functions but these don’t seem have taken hold as yet.
TCAM is not the cure all for hardware search lookups. TCAM is expensive, power hungry and takes up quite a bit of silicon space. Currently, it would not be unusual for it to be the most expensive component on commodity switches. Many vendors use a blend of BCAM memory, SRAM, NPUs and software algorithms to perform OpenFlow actions (see Juniper MX trio chipset and EzChip NPUs in ASRs, Trie lookups).
Authors Note: You should also read about Binary CAM used for MAC address lookups.