Switch forwarding table
openenoc_switch_table.hopenenoc_switch_table.cEach entry contains a destination MAC address, an output-interface bitmap, and
an enable flag. The shared pointer, serialization and return-value contracts
are specified in Switch API. Abbreviated status names use the
OPENENOC_SWITCH_STATUS_ prefix.
All table reads and writes require both pause_request and pause_done.
Reads are allowed in either operation mode. Writes require managed mode;
unmanaged writes return NOT_ALLOWED before pause readiness is checked.
Arguments are validated before these state checks. A data access never changes
the operation mode or pause request and never waits for a pause to complete.
Entry indices satisfy entry_index < table_depth. MAC octets use network
address order, with no unicast-only restriction: multicast and broadcast keys
are valid. Bitmap bits follow the RDL interface order and bits beyond the
generated interface count must be zero. An enabled entry with an empty bitmap
drops matching frames. Disabling an entry removes it from lookup, allowing a
different enabled match or the default bitmap to determine forwarding.
The API accepts duplicate MAC keys. The current table RTL resolves multiple enabled matches using the lowest entry index. The caller serializes table management and prevents another software context from changing mode or pause state until each access has finished.
Entry access
-
openenoc_switch_status_t openenoc_switch_table_get_entry(volatile const csr__switch_interface_t *switch_interface, uint16_t entry_index, openenoc_switch_table_entry_t *entry)
Read all fields of one forwarding-table entry.
- Parameters:
switch_interface – In; required mapped, word-aligned switch-interface pointer.
entry_index – In; zero-based index below the generated table depth.
entry – Out; required destination for the MAC, bitmap, and enable flag.
- Returns:
OK;INVALID_ARGUMENTfor an invalid switch pointer or missing output;OUT_OF_RANGEfor an invalid index;NOT_READYwithout a completed pause.- Preconditions:
A completed pause in either operation mode; serialize other software access.
- Side effects:
Reads forwarding-control and entry CSRs, unpacks the MAC into network-order octets, and updates the output only on success. Preserves mode, pause state, and table contents.
-
openenoc_switch_status_t openenoc_switch_table_set_entry(volatile csr__switch_interface_t *switch_interface, uint16_t entry_index, const openenoc_switch_table_entry_t *entry)
Set the complete contents and requested enable state of one entry.
- Parameters:
switch_interface – In; required mapped, word-aligned switch-interface pointer.
entry_index – In; zero-based index below the generated table depth.
entry – In; required MAC, valid output-interface bitmap, and desired enable state. Multicast and broadcast keys are valid; an enabled entry with bitmap zero drops matching frames.
- Returns:
OK;INVALID_ARGUMENTfor an invalid switch pointer or missing entry;OUT_OF_RANGEfor an invalid index or bitmap;NOT_ALLOWEDin unmanaged mode;NOT_READYin managed mode without a completed pause.- Preconditions:
Managed mode and a completed pause; serialize other software access. All argument checks complete before writing the entry.
- Side effects:
Disables the entry, writes lower and upper MAC fields and the bitmap, then writes the requested enable flag last. Preserves mode, pause state, and other entries.
Enable state and table clearing
-
openenoc_switch_status_t openenoc_switch_table_set_entry_enabled(volatile csr__switch_interface_t *switch_interface, uint16_t entry_index, bool enabled)
Change only the enable state of an existing entry.
- Parameters:
switch_interface – In; required mapped, word-aligned switch-interface pointer.
entry_index – In; zero-based index below the generated table depth.
enabled – In; true to enable lookup matching, false to ignore the entry.
- Returns:
OK;INVALID_ARGUMENTfor an invalid switch pointer;OUT_OF_RANGEfor an invalid index;NOT_ALLOWEDin unmanaged mode;NOT_READYin managed mode without a completed pause.- Preconditions:
Managed mode and a completed pause; the caller has supplied the intended entry MAC and bitmap before enabling it.
- Side effects:
Writes only the selected entry’s enable field. Preserves its MAC and bitmap, other entries, operation mode, and pause state.
-
openenoc_switch_status_t openenoc_switch_table_clear(volatile csr__switch_interface_t *switch_interface)
Disable all forwarding-table entries.
- Parameters:
switch_interface – In; required mapped, word-aligned switch-interface pointer.
- Returns:
OK;INVALID_ARGUMENTfor an invalid switch pointer;NOT_ALLOWEDin unmanaged mode;NOT_READYin managed mode without a completed pause.- Preconditions:
Managed mode and a completed pause; keep mode and pause state stable throughout the iteration.
- Side effects:
Clears every entry’s enable flag. Preserves stored MACs and bitmaps, the default bitmap, operation mode, and pause request. Subsequent lookups use the default bitmap until an entry is enabled.
Public declarations
The maintained header below provides the exact public entry type.
1typedef struct {
2 openenoc_switch_mac_t mac_address;
3 uint32_t interface_bitmap;
4 bool enabled;
5} openenoc_switch_table_entry_t;
6