SatCat5
eth_sw_vlan.h
Go to the documentation of this file.
1 // Copyright 2024-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
16 
17 #pragma once
18 
19 #include <satcat5/eth_plugin.h>
20 
21 namespace satcat5 {
22  namespace eth {
26  public:
29  : PluginPort(port) {}
30 
31  // Implement the required PluginPort API.
32  void egress(PluginPacket& pkt) override;
33  };
34 
43  , public satcat5::poll::Timer
44  {
45  public:
46  // Implement the required PluginCore API.
47  void query(PluginPacket& pkt) override;
48 
53  void vlan_reset(bool lockdown = false);
57  void vlan_set_mask(u16 vid, SATCAT5_PMASK_TYPE mask);
59  VtagPolicy vlan_get_port(unsigned port) const;
61  void vlan_set_port(const VtagPolicy& cfg);
63  void vlan_join(u16 vid, unsigned port);
65  void vlan_leave(u16 vid, unsigned port);
67  void vlan_set_rate(u16 vid, const satcat5::eth::VlanRate& cfg);
68 
69  protected:
70  // Data structure for the internal configuration tables.
71  struct VlanPolicy {
72  satcat5::eth::VlanRate vrate; // Rate-limiter policy
73  SATCAT5_PMASK_TYPE pmask; // Connected ports mask
74  u32 tcount; // Token-bucket counter
75 
76  VlanPolicy() = default;
77  VlanPolicy(const VlanPolicy& t) = default;
78  VlanPolicy& operator=(const VlanPolicy& t) = default;
79  };
80 
81  // Configure this object and link to the working buffer.
84  VlanPolicy* vptr, unsigned vmax, bool lockdown);
85 
86  // Timer-event handler for updating rate-limiter state.
87  void timer_event() override;
88 
89  // Store VLAN policy and rate-limiter state for each VID.
90  VlanPolicy* const m_policy; // Table of VLAN states
91  const unsigned m_vmax; // Supported VIDs = [1..N]
92  };
93 
100  template <unsigned VMAX = 4095>
102  {
103  public:
107  explicit SwitchVlan(satcat5::eth::SwitchCore* sw, bool lockdown = false)
108  : SwitchVlanInner(sw, m_vtable, VMAX, lockdown) {}
109  protected:
111  };
112  }
113 }
Ethernet switch plugin API.
Definition: eth_plugin.h:166
Ethernet port plugin API.
Definition: eth_plugin.h:198
A shared-memory Ethernet switch based on the MultiBuffer class.
Definition: eth_switch.h:93
Generic packetized I/O interface for use with SwitchCore.
Definition: eth_switch.h:245
Port plugin for egress formatting of Virtual-LAN tags.
Definition: eth_sw_vlan.h:25
void egress(PluginPacket &pkt) override
Packet-transmit callback.
Definition: eth_sw_vlan.cc:26
SwitchVlanEgress(satcat5::eth::SwitchPort *port)
Constructor links to a specified port.
Definition: eth_sw_vlan.h:28
Wrapper for SwitchVlanInner with statically-allocated working memory.
Definition: eth_sw_vlan.h:102
SwitchVlan(satcat5::eth::SwitchCore *sw, bool lockdown=false)
Create this plugin and link it to the designated switch.
Definition: eth_sw_vlan.h:107
Switch plugin for Virtual-LAN connectivity and rate-limiting rules.
Definition: eth_sw_vlan.h:44
void timer_event() override
Child class MUST override this method.
Definition: eth_sw_vlan.cc:175
void vlan_reset(bool lockdown=false)
Revert to default VLAN settings for all ports and VIDs.
Definition: eth_sw_vlan.cc:120
VtagPolicy vlan_get_port(unsigned port) const
Query a port's tag policy and other VLAN settings.
Definition: eth_sw_vlan.cc:149
SATCAT5_PMASK_TYPE vlan_get_mask(u16 vid)
Get allowed-connectivity port-mask for designated VID.
Definition: eth_sw_vlan.cc:139
void vlan_leave(u16 vid, unsigned port)
Port should leave VLAN, updating vlan_get_mask.
Definition: eth_sw_vlan.cc:164
void vlan_set_port(const VtagPolicy &cfg)
Set a port's tag policy and other VLAN settings.
Definition: eth_sw_vlan.cc:154
void vlan_join(u16 vid, unsigned port)
Port should join VLAN, updating vlan_get_mask.
Definition: eth_sw_vlan.cc:159
void vlan_set_rate(u16 vid, const satcat5::eth::VlanRate &cfg)
Set rate-limiting options for the designated VID.
Definition: eth_sw_vlan.cc:169
void vlan_set_mask(u16 vid, SATCAT5_PMASK_TYPE mask)
Limit the specified VID to the designated port(s).
Definition: eth_sw_vlan.cc:144
void query(PluginPacket &pkt) override
Packet-received callback.
Definition: eth_sw_vlan.cc:65
Timer objects are polled after a fixed delay or at a regular interval.
Definition: polling.h:213
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
Ephemeral data structure provided to plugin callbacks.
Definition: eth_plugin.h:48
Data structure for configuring VLAN rate-limiter parameters.
Definition: switch_cfg.h:107
Data structure for configuring VLAN tagging policy of each port.
Definition: switch_cfg.h:68