SatCat5
eth_sw_cache.h
1 // Copyright 2024-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 // MAC-address cache plugin for the software-defined Ethernet switch
6 
7 #pragma once
8 
9 #include <satcat5/eth_plugin.h>
10 #include <satcat5/lru_cache.h>
11 
12 namespace satcat5 {
13  namespace eth {
26  public:
28  void query(satcat5::eth::PluginPacket& pkt) override;
29 
34  void set_miss_bcast(unsigned port_idx, bool enable);
35 
41  { m_miss_mask = mask; }
42 
46  { return m_miss_mask; }
47 
52  inline unsigned mactbl_size() const // Read maximum table length
53  { return m_size; }
54  bool mactbl_read( // Read Nth entry from table
55  unsigned tbl_idx, // Table index to be read
56  unsigned& port_idx, // Resulting port index
57  satcat5::eth::MacAddr& mac_addr); // Resulting MAC address
58  bool mactbl_write( // Write new entry to table
59  unsigned port_idx, // New port index
60  const satcat5::eth::MacAddr& mac_addr); // New MAC address
61  inline bool mactbl_clear() // Clear table contents
62  { m_cache.clear(); return true; }
63  inline bool mactbl_learn(bool enable) // Enable automatic learning?
64  { m_learn = enable; return true; }
65  inline bool mactbl_learn() const // Learning enabled?
66  { return m_learn; }
68 
69  protected:
71  struct CacheEntry {
72  public:
73  CacheEntry() = default;
74  CacheEntry(const CacheEntry& t) = delete;
75  CacheEntry& operator=(const CacheEntry& t) = delete;
76 
77  u64 m_key;
78  unsigned m_port;
79  private:
82  };
83 
87  CacheEntry* array, unsigned size);
88 
91 
92  // Internal configuration?
93  bool m_learn; // Enable learning?
94  SATCAT5_PMASK_TYPE m_miss_mask; // Cache miss policy
95 
96  // Backing array and LRU cache for MAC addresses.
97  CacheEntry* const m_array;
98  const unsigned m_size;
100  };
101 
104  template <unsigned SIZE = 64>
106  public:
109  : SwitchCacheInner(sw, m_table, SIZE) {}
110  protected:
112  };
113  }
114 }
Ethernet switch plugin API.
Definition: eth_plugin.h:166
Wrapper for SwitchCacheInner with the required working memory.
Definition: eth_sw_cache.h:105
SwitchCache(satcat5::eth::SwitchCore *sw)
Link this cache to the designated SwitchCore.
Definition: eth_sw_cache.h:108
MAC-address cache plugin for the software-defined Ethernet switch.
Definition: eth_sw_cache.h:25
void set_miss_bcast(unsigned port_idx, bool enable)
Enable or disable "miss-as-broadcast" flag for a specific port.
Definition: eth_sw_cache.cc:55
bool mactbl_clear()
Read or manipulate the contents of the MAC-address table.
Definition: eth_sw_cache.h:61
unsigned mactbl_size() const
Read or manipulate the contents of the MAC-address table.
Definition: eth_sw_cache.h:52
bool mactbl_learn(bool enable)
Read or manipulate the contents of the MAC-address table.
Definition: eth_sw_cache.h:63
SATCAT5_PMASK_TYPE get_miss_mask() const
Identify which ports are currently in "miss-as-broadcast" mode.
Definition: eth_sw_cache.h:45
SwitchCacheInner(satcat5::eth::SwitchCore *sw, CacheEntry *array, unsigned size)
Constructor accepts a child-allocated array for the cache.
Definition: eth_sw_cache.cc:17
bool mactbl_read(unsigned tbl_idx, unsigned &port_idx, satcat5::eth::MacAddr &mac_addr)
Read or manipulate the contents of the MAC-address table.
Definition: eth_sw_cache.cc:60
SATCAT5_PMASK_TYPE destination_mask(const PluginPacket &pkt)
Destination MAC-address lookup.
Definition: eth_sw_cache.cc:28
bool mactbl_write(unsigned port_idx, const satcat5::eth::MacAddr &mac_addr)
Read or manipulate the contents of the MAC-address table.
Definition: eth_sw_cache.cc:67
void set_miss_mask(SATCAT5_PMASK_TYPE mask)
Enable or disable "miss-as-broadcast" flag for all ports.
Definition: eth_sw_cache.h:40
void query(satcat5::eth::PluginPacket &pkt) override
Implement the required SwitchPlugin API.
Definition: eth_sw_cache.cc:43
bool mactbl_learn() const
Read or manipulate the contents of the MAC-address table.
Definition: eth_sw_cache.h:65
A shared-memory Ethernet switch based on the MultiBuffer class.
Definition: eth_switch.h:93
Template class implementing a least-recently-used (LRU) cache.
Definition: lru_cache.h:33
Plugins for the software-defined Ethernet switch and IPv4 router.
#define SATCAT5_PMASK_TYPE
Set the integer type used to identify source and destination ports.
Definition: eth_switch.h:41
An Ethernet MAC address (with serializable interface).
Definition: eth_header.h:29
Ephemeral data structure provided to plugin callbacks.
Definition: eth_plugin.h:48
Data structure for the internal cache.
Definition: eth_sw_cache.h:71
u64 m_key
MAC address as u64.
Definition: eth_sw_cache.h:77
CacheEntry * m_next
Linked list of cache entries.
Definition: eth_sw_cache.h:81
unsigned m_port
Associated port index.
Definition: eth_sw_cache.h:78