TCAM (ternary content-addressable memory)

acronym

networking

Kept in this browser · My desk

Stands for: ternary content-addressable memory: a CAM whose cells also store a don't-care state

A content-addressable memory whose cells store 0, 1 or X, a don't-care that matches either bit, so one entry can match a whole prefix or a masked pattern in a single lookup.

Pagiamtzis and Sheikholeslami: "Ternary cells, in addition, store an X value. The X value is a don't care, that represents both 0 and 1, allowing a wildcard operation", the feature routers use for packet forwarding. In switches and routers TCAM holds what needs masks: routes for longest prefix match, access lists, quality of service classes. A MAC table needs every bit of the key and so needs no wildcard; Juniper's unified forwarding table, for example, keeps MAC addresses in shared table memory and gives TCAM space to longest prefix match entries.

What it is. A ternary content-addressable memory (TCAM) is a content-addressable memory whose cells hold one of three states, 0, 1 or X (don't care), so that one stored entry matches every search word that agrees with it on the bits that are not X. A binary CAM answers "is this exact key stored?"; a TCAM answers "which stored pattern does this key fit, and which of those comes first?". That question is the shape of three jobs in a router or switch: longest prefix match on routes, access control lists (ACLs) and quality of service (QoS) classification.

How a cell holds three states. A ternary symbol takes two bits of storage, and a ternary cell adds transistors to a binary one, so TCAM costs more area and power per bit than binary CAM, which is already costlier than RAM (random-access memory). Pagiamtzis and Sheikholeslami's 2006 survey in the IEEE (Institute of Electrical and Electronics Engineers) Journal of Solid-State Circuits gives the ternary NOR and NAND cells with their encodings and makes reducing the power of the parallel match lines its main thread: every search precharges and evaluates every entry, so a TCAM's power grows with the number of entries searched, not with the number that match.

Priority. Because several entries can match one search, a priority encoder returns the highest-priority match, which is why the order of entries in a TCAM-backed access list matters. The survey's routing example shows the mechanism on 5-bit words: the destination 01101 matches two entries, and the encoder returns the upper one, which is the one with fewer X bits, the longer prefix; its location then indexes a RAM that holds the output port. Longest prefix match in a TCAM is therefore a matter of loading longer prefixes above shorter ones, and an ACL compiler must preserve the configured order of permit and deny lines when it writes them in.

Ranges, the expensive case. A TCAM matches prefixes natively but not ranges, so a rule on a port range must be split into prefixes. Rottenstreich and Keslassy (Technion, IEEE INFOCOM 2010) recall the classic bound: a range on a W-bit field can need up to 2W-2 entries, 30 for a 16-bit port field and 900 for a rule with ranges on both source and destination ports; their example, the 3-bit range 1 to 6, becomes 001, 01*, 10* and 110. Worked by hand for a common rule, destination ports 1024 to 65535: 000001 followed by ten X bits (1024 to 2047), 00001 and eleven X (2048 to 4095), 0001 and twelve X (4096 to 8191), 001 and thirteen X (8192 to 16383), 01 and fourteen X (16384 to 32767), and 1 followed by fifteen X (32768 to 65535): six entries for one line of configuration. The paper adds that range rules are typically a minority of rules but the majority of entries, and so of power, that their share grew from 1.3 to 13.3 per cent between databases of 1998 and 2004, and it proves that W entries are always enough with a smarter encoding.

Cost and scale. The same paper states that a TCAM chip can consume up to 30 times the power of an equivalent SRAM (static RAM) solution at the same access rate, that classification and forwarding took a third of the power of Cisco's CRS-1 core router, and that a 55 nm device of the time, the NLA9000XT, ran nearly 500 million searches a second. Those numbers explain why vendors ration TCAM: on Juniper's EX4600 and QFX5100 switches the TCAM allocation for IPv6 prefixes longer than /64 is configurable (up to 4,000 entries from Junos 13.2X51-D15, default 1,000), trading space against other longest prefix match entries, and QFX5210 switches from Junos 18.1R1 allow up to 8,000 such entries, with 2,000 by default. The binding limit of a hardware ACL is therefore TCAM space, not lines of configuration, a point the Learn article on access control lists works through with real platforms. Cisco does the rationing with templates: on Catalyst 9300 switches an SDM (Switch Database Management) template, Access or NAT (network address translation) on IOS XE 17.12, sizes the hardware tables together, MAC (media access control) addresses, routes and the access control entries for security, QoS and policy-based routing, so giving one feature more entries takes them from another; IPv6 entries are twice the size, so only half as many fit, and a new template takes effect only after a reload (sdm prefer, then show sdm prefer to check).

What goes wrong. A policy that looked small can overflow after range expansion multiplies its entries, and what a platform does when a policy does not fit is behaviour to read in its own documentation before deployment. Reordering lines changes behaviour because of the priority encoder. And hardware enforcement is only as good as its programming: the National Vulnerability Database (NVD) record CVE-2025-20316 describes an egress ACL on Cisco Catalyst 9500X and 9600X switches that flooded traffic from an unlearned MAC (media access control) address could bypass. Neighbours: content-addressable memory (the binary parent), ACL, longest prefix match, ASIC (application-specific integrated circuit) and the MAC address table, which needs exact matches and so usually lives in hashed RAM instead.

Also known as: ternary cam, ternary content addressable memory, cam ternária

Sources

← Back to T Back to the glossary