L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Mac_table< Size > Class Template Reference

Mac_table manages a 1:n association between ports and MAC addresses. More...

#include <mac_table.h>

+ Collaboration diagram for Mac_table< Size >:

Public Member Functions

Port_iface * lookup (Mac_addr dst, l4_uint16_t vlan_id) const
 Find the destination port for a MAC address and VLAN id.
 
void learn (Mac_addr src, Port_iface *port, l4_uint16_t vlan_id)
 Learn a MAC address (add it to the MAC table).
 
void flush (Port_iface *port)
 Flush all associations with a given port.
 

Detailed Description

template<std::size_t Size = 1024U>
class Mac_table< Size >

Mac_table manages a 1:n association between ports and MAC addresses.

There are different types of devices which might be attached to a port. For a normal device the switch sees exactly one MAC address per port - the MAC address of the device attached to it. But there might be other devices like software bridges attached to the port sending packets with different MAC addresses to the port. Therefore the switch has to manage a 1:n association between ports and MAC addresses. The MAC table manages this association.

When a packet comes in we need to find the destination port for the packet and therefore perform a lookup based on the MAC address.

To prevent unbounded growth of the lookup table, the number of entries is limited. Replacement is done on a round-robin basis. If the capacity was reached, the oldest entry is evicted.

Definition at line 40 of file mac_table.h.

Member Function Documentation

◆ flush()

template<std::size_t Size = 1024U>
void Mac_table< Size >::flush ( Port_iface *  port)
inline

Flush all associations with a given port.

Parameters
portPointer to port that is to be flushed

This function removes all references to a given port from the MAC table. Since we manage a 1:n association between ports and MAC addresses there might be more than one entry for a given port and we have to iterate over the whole array to delete every reference to the port.

Definition at line 129 of file mac_table.h.

Referenced by Virtio_switch::check_ports().

+ Here is the caller graph for this function:

◆ learn()

template<std::size_t Size = 1024U>
void Mac_table< Size >::learn ( Mac_addr  src,
Port_iface *  port,
l4_uint16_t  vlan_id 
)
inline

Learn a MAC address (add it to the MAC table).

Parameters
srcMAC address
portPointer to the port object that can be used to reach MAC address src
vlan_idVLAN id of the packet destination.

Will evict the oldest learned address from the table if the maximum capacity was reached and if the MAC address was not known yet. The source port of the table entry is always updated to cope with clients that move between ports.

Definition at line 78 of file mac_table.h.

References L4_UNLIKELY, and Mac_table< Size >::lookup().

+ Here is the call graph for this function:

◆ lookup()

template<std::size_t Size = 1024U>
Port_iface * Mac_table< Size >::lookup ( Mac_addr  dst,
l4_uint16_t  vlan_id 
) const
inline

Find the destination port for a MAC address and VLAN id.

Parameters
dstMAC address
vlan_idVLAN id
Return values
nullptrThe MAC address is not known (yet)
otherPointer to the destination port

Definition at line 58 of file mac_table.h.

Referenced by Mac_table< Size >::learn().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: