ProtocolStack

Trait ProtocolStack 

Source
pub trait ProtocolStack: Send + Sync {
    // Required methods
    fn domain(&self) -> SocketDomain;
    fn create_socket(
        &self,
        socket_type: SocketType,
        protocol: SocketProtocol,
    ) -> Result<Arc<dyn SocketObject>, SocketError>;
    fn process_incoming_packet(
        &self,
        packet: &DevicePacket,
    ) -> Result<(), SocketError>;
    fn send_packet(&self, packet: DevicePacket) -> Result<(), SocketError>;
    fn statistics(&self) -> ProtocolStackStats;
    fn name(&self) -> &'static str;
    fn supports(
        &self,
        socket_type: SocketType,
        protocol: SocketProtocol,
    ) -> bool;
}
Expand description

Protocol stack trait for network protocols

This trait defines the interface for protocol stack implementations. ABI modules can implement this to provide TCP/IP, UDP, or other protocol support.

§Example: TCP/IP Stack

struct TcpIpStack {
    // TCP/IP implementation details
}

impl ProtocolStack for TcpIpStack {
    fn domain(&self) -> SocketDomain {
        SocketDomain::Inet
    }

    fn create_socket(&self, socket_type: SocketType, protocol: SocketProtocol)
        -> Result<Arc<dyn SocketObject>, SocketError> {
        match (socket_type, protocol) {
            (SocketType::Stream, SocketProtocol::Tcp) => {
                Ok(Arc::new(TcpSocket::new(self.clone())))
            }
            (SocketType::Datagram, SocketProtocol::Udp) => {
                Ok(Arc::new(UdpSocket::new(self.clone())))
            }
            _ => Err(SocketError::NotSupported),
        }
    }

    fn process_incoming_packet(&self, packet: &DevicePacket) -> Result<(), SocketError> {
        // Parse IP header, route to appropriate socket
        // ...
        Ok(())
    }
}

Required Methods§

Source

fn domain(&self) -> SocketDomain

Get the protocol stack domain

Returns which address family this stack handles (Inet, Inet6, etc.)

Source

fn create_socket( &self, socket_type: SocketType, protocol: SocketProtocol, ) -> Result<Arc<dyn SocketObject>, SocketError>

Create a socket for this protocol stack

§Arguments
  • socket_type - Type of socket (Stream, Datagram, etc.)
  • protocol - Specific protocol (Tcp, Udp, etc.)
§Returns

A new socket object that uses this protocol stack

Source

fn process_incoming_packet( &self, packet: &DevicePacket, ) -> Result<(), SocketError>

Process an incoming packet from the network device

The protocol stack should parse the packet and deliver it to the appropriate socket.

§Arguments
  • packet - Raw packet data from network device
§Errors

Returns an error if the packet is malformed or cannot be processed

Source

fn send_packet(&self, packet: DevicePacket) -> Result<(), SocketError>

Send a packet through the network device

The protocol stack should encapsulate the data with appropriate headers and send it through the network device.

§Arguments
  • packet - Packet to send
§Errors

Returns an error if the packet cannot be sent

Source

fn statistics(&self) -> ProtocolStackStats

Get protocol stack statistics

Source

fn name(&self) -> &'static str

Get a human-readable name for this protocol stack

Source

fn supports(&self, socket_type: SocketType, protocol: SocketProtocol) -> bool

Check if the protocol stack supports a specific socket type and protocol

Implementors§