Loading...
Searching...
No Matches
Mac_table< Size > Class Template Reference
Virtio Net Switch

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

  port | Pointer 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.

## 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

  src | MAC address
  port | Pointer to the port object that can be used to reach MAC address src
  vlan_id | VLAN 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 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

  dst | MAC address
  vlan_id | VLAN id

Return values

  nullptr | The MAC address is not known (yet)
  other | Pointer to the destination port

Definition at line 58 of file mac_table.h.

Referenced by learn().

Here is the caller graph for this function:

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

- pkg/virtio-net-switch/server/switch/mac_table.h