flexstack.linklayer Module
The flexstack.linklayer package abstracts layer-2 packet I/O.
RawLinkLayer
LinkLayer (Base Class)
- class flexstack.linklayer.link_layer.LinkLayer(receive_callback)[source]
Bases:
objectLink Layer class to connect layer 2 and layer 3.
- Variables:
receive_callback (Callable[[bytes], None]) – Callback function to receive packets.
- Parameters:
receive_callback (Callable[[bytes], None]) –
- send(bytes)[source]
Send a packet to the LL.
- Parameters:
packet (bytes) –
destination (bytes | None) –
- Return type:
None
- receive()
Receive a packet from the LL. (To be called in a thread)
- __init__(receive_callback)[source]
Create a Link Layer object.
- Parameters:
iface (str) – Interface to use. (Linux only)
mac_address (bytes) – MAC address of the interface.
receive_callback (Callable[[bytes], None]) – Callback function to receive packets.
- Raises:
OSError: – If the interface is not found.
Exception: – If the MAC address is not 6 bytes long.
- Return type:
None
- deliver(packet, sender_ll_address=None)[source]
Pass a received packet to the receive callback. The link-layer source address is passed as
sender_ll_addresswhen the callback declares that parameter (e.g.Router.gn_data_indicate), which lets the GeoNetworking CBF algorithms identify the previous sender.- Parameters:
packet (bytes) –
sender_ll_address (bytes | None) –
- Return type:
None
- media_dependent_mid()[source]
MID that the GeoNetworking address shall carry on this access layer (ETSI TS 103 836-4-2 clause 6.1, TS 103 836-4-3 clause 5.2), or None when the link layer does not know its address.
- Return type:
MID | None
- send(packet, destination=None)[source]
Send a packet to the lower layer.
- Parameters:
packet (bytes) – Packet to send.
destination (bytes | None) – Link-layer address of the next hop (6 octets) for a GeoNetworking unicast forwarding step (ETSI TS 103 836-4-1 clause E.2, NH_LL_ADDR); None for the broadcast address.
- Raises:
SendingException: – If the packet cannot be sent.
PacketTooLongException: – If the packet is too long.
NotImplementedError: – If the method is not implemented.
- Return type:
None