Interface

This class represents the interface. In the networking, we distinguish two types of interfaces; the first one are physical/non-virtual interfaces which correspond to the connector of the module, the second one is so-called virtual interface which is an additional interface of each module which serves as the main interface.

class Interface

Class representing the interface of a Module.

Supports both, physical (i.e., with a physical connector) and virtual flavours.

Public Types

enum class DHCP

Values:

enumerator SLAAC
enumerator STATEFULL
using Name = std::string

Type alias for the Interface’s name. Use this instead of string, it may change in the future.

Public Functions

template<typename NetmgCB, typename = std::is_invocable_r<void, NetmgCB, const Interface*, hal::ConnectorEvent>>
inline Interface(const PhysAddr &pAddr, std::optional<Connector> connector, const NetmgCB &networkManagerEventCB)
template<typename NetmgCB, typename = std::is_invocable_r<void, NetmgCB, const Interface*, hal::ConnectorEvent>>
inline Interface(const PhysAddr &pAddr, Logger::LogFunction lf, std::optional<Connector> connector, const NetmgCB &networkManagerEventCB)
inline ~Interface()
Interface(const Interface&) = delete
Interface &operator=(const Interface&) = delete
inline bool setUp()

Set the interface up so it starts processing traffic.

Returns:

true if the interface was set up correctly.

inline void setDown()

Set the interface down so it stops processing traffic.

inline bool isUp() const

Query on the state of the interface.

Returns:

true if the interface is up.

inline bool isDown() const

Query on the state of the interface.

Returns:

true if the interface is down.

inline bool isConnected()

Query on the state of the underlying connector.

Returns:

true if the connector of the interface is connected. For virtual interface this returns always false.

inline bool isVirtual() const

Returns true if the interface is virtual (i.e., does not have a physical connector).

template<typename OnMessage, typename = std::is_invocable_r<err_t, OnMessage, raw_pcb*, pbuf*, const ip_addr_t*>>
inline void setProtocol(const Ip6Addr &listenerAddr, OnMessage &&onMessage)

Set up a protocol listener on given address with given callback function.

Throws an exception if the protocol is already running on given interface.

inline void removeProtocol(const Ip6Addr &listenerAddr)

Remove protocol corresponding to the given address.

Stops corresponding listener.

inline bool sendProtocol(const Ip6Addr &listenerAddr, PBuf &&msg)

Sends a message onto the given address using the protocol corresponding to the handle.

Returns:

true if the message was sent correctly.

inline std::pair<Ip6Addr, uint8_t> getAddress(int index) const

Get an address on the given interface.

Number of addresses is determined by the underlying lwip library, namely by LWIP_IPV6_NUM_ADDRESSES macro.

Returns:

a pair – corresponding to IP address and the subnet mask.

inline std::vector<std::pair<Ip6Addr, uint8_t>> getAddress() const
inline Name name() const

Returns a name of the interface.

inline bool setName(const Name &name)

Sets the name of the interface.

The name has to be in form of two characters followed with up to 3 digits.

inline bool addAddress(const Ip6Addr &ip, uint8_t mask)

Add given address with the given mask to the interface.

Returns:

true if the address was correctly added.

inline bool removeAddress(const Ip6Addr &ip, uint8_t mask)

Removes given address with the given mask to the interface.

Returns:

true if the address was correctly removed.

inline void send(PBuf &&packet, uint16_t contentType)

Send given packet with the content type via the interface.

inline long long unsigned dataSent() const

Function that returns the amount of data sent (in bytes).

inline long long unsigned dataReceived() const

Function that returns the amount of data received (in bytes).

Friends

friend bool operator==(const Interface &i1, const Interface &i2)
friend std::ostream &operator<<(std::ostream &o, const Interface &i)

Outputs info about the interface.