11#include <condition_variable>
44 void Send(
const std::vector<std::uint8_t>&
frame)
override;
51 [[nodiscard]] std::vector<std::uint8_t>
Recv()
override;
123 const std::vector<std::uint8_t>&
frame);
Abstraction for sending and receiving raw Ethernet frames.
Abstract interface for raw Ethernet frame transport.
Small virtual Ethernet switch suitable for deterministic tests and demos.
void Transmit(InMemoryEthernetSocket &sender, const std::vector< std::uint8_t > &frame)
Route a frame to matching endpoints.
~InMemoryEthernetBus()=default
InMemoryEthernetBus()=default
Construct an empty bus.
std::size_t EndpointCount() const
Return the number of currently connected socket endpoints.
void Attach(InMemoryEthernetSocket *socket)
Attach one socket.
InMemoryEthernetBus & operator=(const InMemoryEthernetBus &)=delete
void Detach(InMemoryEthernetSocket *socket)
Detach one socket.
std::unique_ptr< InMemoryEthernetSocket > CreateSocket(MacAddress localMac)
Create one virtual raw-Ethernet endpoint.
void ClearQueues()
Remove all queued frames without disconnecting endpoints.
InMemoryEthernetBus(const InMemoryEthernetBus &)=delete
std::vector< InMemoryEthernetSocket * > endpoints
Injectable raw-Ethernet endpoint attached to an in-memory bus.
void Enqueue(const std::vector< std::uint8_t > &frame)
Queue one frame for this endpoint.
InMemoryEthernetSocket & operator=(const InMemoryEthernetSocket &)=delete
void SetTimeout(std::chrono::milliseconds timeout) override
Set the maximum time spent waiting for a frame.
void Send(const std::vector< std::uint8_t > &frame) override
Transmit one complete Ethernet frame onto the virtual bus.
~InMemoryEthernetSocket() override
Disconnect and detach the endpoint.
InMemoryEthernetSocket(const InMemoryEthernetSocket &)=delete
bool ReceiveEnabled() const noexcept
Return whether this endpoint currently accepts incoming frames.
std::chrono::milliseconds timeout
std::vector< std::uint8_t > Recv() override
Receive one frame or an empty vector after a timeout.
void SetReceiveEnabled(bool enabled)
Enable or disable frame delivery into this endpoint receive queue.
InMemoryEthernetBus & bus
std::deque< std::vector< std::uint8_t > > receiveQueue
std::condition_variable condition
const MacAddress & LocalMac() const noexcept
Return the endpoint MAC address.
std::array< std::uint8_t, macAddressLength > MacAddress
A 6-byte Ethernet MAC address.
Declares Linux Ethernet, addressing, timing, and utility helpers used by the PROFINET stack.