Content Addressable Memory (CAM) and Ternary CAM (TCAM)
CAM and TCAM tables
CAM and TCAM tables are specialized memory architectures used in high-speed networking devices. They are used in switches and routers for efficient lookup operations. They play a crucial role in forwarding decisions, access control lists (ACLs), and quality of service (QoS) implementations.
Content Addressable Memory (CAM)
A CAM is a type of computer memory that allows data to be accessed by its content rather than its address. It performs parallel searches across the entire memory to find a match for the input data.[1] CAMs store and query binary data (0s and 1s). They are useful for implementing tables that require exact match-based searching, such as MAC address tables in Ethernet switches.[2]
When a frame arrives at a switch, the source MAC address is learned and recorded in the CAM table along with the ingress port and VLAN information. For forwarding, the destination MAC address is looked up in the CAM table to determine the egress port.[4] This parallel search operation makes CAMs much faster than traditional RAM for lookup tasks.
Ternary Content Addressable Memory (TCAM)
A TCAM is a specialized type of CAM that introduces a third state, “don’t care” (represented as ‘X’), in addition to 0s and 1s.[3] This added flexibility allows TCAMs to perform longest prefix match (LPM) searches. This flexibility makes them ideal for IP routing table lookups and ACL implementations in routers and multilayer switches.[2][4]
In a TCAM, a stored entry like “10XX0” can match any of the four search words: “10000”, “10010”, “10100”, or “10110”. This reduces the number of entries required, improving search efficiency.[3] TCAMs are widely used for layer 3 and layer 4 packet classification for QoS purposes and implementing complex ACL rules.[2]
Key Differences
- Applications: CAMs are primarily used for MAC address lookups in layer 2 switches, while TCAMs are employed for IP routing table lookups, ACL implementation, and QoS in routers and multilayer switches.[2][4]
- Search Capability: CAMs perform exact match-based searches, while TCAMs can perform longest prefix match (LPM) searches using the “don’t care” state.[1][2]
- Memory Cells: CAMs store and query binary data (0s and 1s), while TCAMs store and query ternary data (0s, 1s, and “don’t care”).[1][3]
- Flexibility: TCAMs offer more flexibility in searching due to the “don’t care” state, reducing the number of entries required compared to CAMs.[3]
Here’s a comparison chart of CAM (Content Addressable Memory) vs TCAM (Ternary Content Addressable Memory) using 1, 0, and x:
Feature | CAM | TCAM |
---|---|---|
Search Input | 1, 0 | 1, 0, x |
Search Type | Exact match | Longest prefix match |
Use Cases | MAC address table lookups | Routing table lookups, ACLs, packet classification[1][2][4] |
Search Speed | Fast, single clock cycle | Fast, single clock cycle |
Flexibility | Limited to exact matches | More flexible due to “x” state[1][2][3][4] |
In the chart:
- “1” represents a binary match
- “0” represents a binary no-match
- “x” represents the “don’t care” state in TCAM, allowing for flexible matching[1][2][3][4]
The key difference is that CAM can only match binary 1s and 0s for exact matches, while TCAM adds the “x” state for flexible longest prefix matching. This makes TCAM more suitable for routing table lookups, access control lists (ACLs), and packet classification in network devices[1][2][3][4].
In summary, CAM and TCAM tables are specialized memory architectures that enable high-speed parallel searches in networking devices. CAMs are used for exact match-based searches. TCAMs provide added flexibility with the “don’t care” state, making them suitable for longest prefix match searches and complex ACL implementations.[1][2][3][4]
Citations:
[1] https://www.geeksforgeeks.org/difference-between-tcam-and-cam/
[2] https://www.geeksforgeeks.org/what-is-content-addressable-memory/
[3] https://www.synopsys.com/designware-ip/technical-bulletin/introduction-to-tcam.html
[4] https://community.cisco.com/t5/networking-knowledge-base/cam-content-addressable-memory-vs-tcam-ternary-content/ta-p/3107938
[5] https://en.wikipedia.org/wiki/Content-addressable_memory