Doip Server Module
This module implements all the functionality necessary to handle DoIP packets.
- class mtf.diag_port.diag_servers.doip_server.DoipRequest
DoIP request message implementation for generating response packets.
This class deserializes DoIP request packets in order to generate response packets matching to the given logical address, header, and payload data.
- __init__(payload: bytes, logical_add: bytes | None = None)
Create a new DoIP message with the given payload and logical address.
- Args:
payload (bytes): The payload of the DoIP message. logical_add (optional[bytes]): The logical address of the receiving server / target.
- Returns:
DoipRequest: The newly created DoIP message.
- generate_negative_response(nrc: int = 17, data: bytes = b'') bytes
Create a DoIP Negative Response message using the given NRC and UDS payload.
- Args:
nrc (int): The negative response Code (default: 0x11). data (bytes): The response data payload.
- Returns:
bytes: The generated DoIP message data (DoIP header + DoIP payload + UDS payload).
- generate_ack()
Generate a DoIP-over-TCP ACK packet.
- Returns:
bytes: The DoIP ACK packet data.
- generate_routing_activation_response() bytes
Generate a DoIP Routing Activation Response packet.
- Returns:
bytes: The routing activation response packet data.
- generate_positive_response(data: bytes = b'') bytes
Generate a DoIP response packet.
- Args:
data (bytes): The payload of the response message.
- Returns:
bytes: The doip response packet data.
- class mtf.diag_port.diag_servers.doip_server.DoipServer
Implement a basic DoIP server.
This class implements the functionality to (automatically) handle DoIP packets, prepare and send appropriate responses.
- __init__(ip: str, logical_address: int, port: int = 13400, buffer_size: int = 1024, sock_opts: dict = None)
Create a new DoIP server instance using the given parameters.
- Args:
ip (str): The IP address of the DoIP server. logical_address (int): The logical address of the DoIP server. port (int): The DoIP server port number (default: 13400). buffer_size (int): The buffer size of the DoIP server (default: 1024). sock_opts (dict): The socket arguments key-value pairs (default: None).
- Returns:
DoipServer: The newly created DoIP server instance.
Note
The IP address may be IPv6 as well as IPv4, though the DoIP specification prefers IPv6.
Socket argument keys can be either option names defaulting to SOL_SOCKET level or tuples explicitly specifying the socket level and the option name. And values represent the corresponding option values.
- trigger_vehicle_announcement(ip: str, occurrence: int = 1, cycle: int = 0, port: int | None = None, further_action: bytes = b'\x00')
Trigger the DoIP Vehicle Announcement Message to be sent.
- Args:
ip (str): The IP address to send the packet to. occurrence (int): The number of times the packet will be sent (default: 1). cycle (int): The time (in ms) to wait before the next packet is sent (default: 0). port (Optional[int]): The port to send the packet(s) on (default: None). further_action (bytes): Data bytes to be added to the packet (default: b’').
Note
This function sends the vehicle announcement message (0x0004). It creates the DoIP message payload and sends it at every cycle interval for a specified number of occurrence times to the given (IP, port).
- configure_socket_options(sock_opts)
Configure socket options based on the provided sock_opts dictionary.
- daemon_start()
Daemon thread that will run in the background of the main program.
- property positive_responding: bool
Getter of positive_responding attribute
- start()
Start the diagnostic server.
- stop()
Stop the diagnostic server and close the socket.
- wait_connection()
Wait for tcp connection with the diagnostic server.
- call_back(data: bytes, connection: socket, adrr: str)
Process the input data and, if necessary, generate an appropriate response.
- Args:
data (bytes): Doip request’s data that will be processed. connection (socket): Doip server socket. adrr (str): Doip server address.
Note
The DoipServer callback function orchestrates the Doip communication: It handles the incoming Doip requests, processes them based on their content and then sends appropriate responses back to the client.