someip package¶
Submodules¶
someip.config module¶
Classes for defining a Service
or Eventgroup
.
These definitions will be used to match against, and to convert to SD service or
eventgroup entries as seen on the wire (see someip.header.SOMEIPSDEntry
).
- class someip.config.Eventgroup(service_id, instance_id, major_version, eventgroup_id, sockname, protocol)[source]¶
Bases:
object
Defines an Eventgroup that can be subscribed to.
- Parameters:
service_id (int) –
instance_id (int) –
major_version (int) –
eventgroup_id (int) –
sockname (tuple) – the socket address as returned by
socket.getsockname()
protocol (L4Protocols) – selects the layer 4 protocol
- as_service()[source]¶
returns a
Service
for this event group, e.g. for use withwatch_service()
.
- create_subscribe_entry(ttl=3, counter=0)[source]¶
Create a SD Subscribe entry for this eventgroup.
- Parameters:
ttl (int) – the TTL for this Subscribe entry
counter (int) – counter to identify this specific subscription in otherwise identical subscriptions
- Returns:
the Subscribe SD entry for this eventgroup
- Return type:
- eventgroup_id: int¶
- for_service(service)[source]¶
replace a generic definition (that may contain wildcards in
instance_id
andmajor_version
) with actual values from aService
.- Parameters:
service (Service) – actual service
- Returns:
A new
Eventgroup
withinstance_id
andmajor_version
from service. None if this eventgroup does not match the given service.- Return type:
Eventgroup | None
- instance_id: int¶
- major_version: int¶
- protocol: L4Protocols¶
- service_id: int¶
- sockname: Tuple[str, int] | Tuple[str, int, int, int]¶
- class someip.config.Service(service_id, instance_id=65535, major_version=255, minor_version=4294967295, options_1=(), options_2=(), eventgroups=frozenset({}))[source]¶
Bases:
object
Defines a Service that can be found and offered.
- Parameters:
service_id (int) –
instance_id (int) – may be 0xFFFF (default) to match any instance
major_version (int) – may be 0xFF (default) to match any major version
minor_version (int) – may be 0xFFFFFFFF (default) to match any major version
options_1 (Tuple[SOMEIPSDOption, ...]) – options that apply to this service (run 1)
options_2 (Tuple[SOMEIPSDOption, ...]) – options that apply to this service (run 2)
eventgroups (FrozenSet[int]) – offered eventgroup ids.
- create_find_entry(ttl=3)[source]¶
Create a SD FindService entry for this service.
- Parameters:
ttl – the TTL for this FindService entry
- Returns:
the FindService SD entry for this service
- create_offer_entry(ttl=3)[source]¶
Create a SD OfferService entry for this service.
- Parameters:
ttl – the TTL for this FindService entry
- Returns:
the OfferService SD entry for this service
- eventgroups: FrozenSet[int] = frozenset({})¶
- classmethod from_offer_entry(entry)[source]¶
Create a
Service
from a given OfferService SD entry.- Parameters:
entry (SOMEIPSDEntry) – the entry as seen on the wire
- Returns:
a new
Service
instance with values set from the given OfferService entry- Raises:
ValueError – if the entry is no OfferService, or the entry does not have resolved options (see
someip.header.SOMEIPSDEntry.options_resolved
)- Return type:
- instance_id: int = 65535¶
- major_version: int = 255¶
- matches_find(entry)[source]¶
Test if a received FindService
SOMEIPSDEntry
matches this service. This is the case if the service_id fields are equal, and instance_id, major_version and minor_version fields are either equal or set to wildcard values on the FindService SD entry.- Parameters:
entry (SOMEIPSDEntry) – the entry to match against
- Returns:
True if the given FindService entry matches this service
- Raises:
ValueError – if the entry is no FindService
- Return type:
bool
- matches_offer(entry)[source]¶
Test if a received OfferService
SOMEIPSDEntry
matches this service. This is the case if the service_id is identical, and instance_id, major_version and minor_version are either identical or set to wildcard values on thisService
instance.- Parameters:
entry (SOMEIPSDEntry) – the entry to match against
- Returns:
True if the given OfferService entry matches this service
- Raises:
ValueError – if the entry is no OfferService
- Return type:
bool
- matches_service(other)[source]¶
Test if a given service matches this service. This is the case if the
service_id
fields are equal, andinstance_id
,major_version
andminor_version
are either equal or set to wildcard values on eitherService
instance.- Parameters:
other (Service) – the service to match against
- Returns:
True if the given service matches this service
- Return type:
bool
- matches_subscribe(entry)[source]¶
Test if a received Subscribe
SOMEIPSDEntry
matches this service. This is the case if the service_id fields are equal, the eventgroup_id is ineventgroups
, and instance_id and major_version fields are either equal or set to wildcard values on thisService
instance.- Parameters:
entry (SOMEIPSDEntry) – the entry to match against
- Returns:
True if the given Subscribe entry matches this service
- Raises:
ValueError – if the entry is no Subscribe
- Return type:
bool
- minor_version: int = 4294967295¶
- options_1: Tuple[SOMEIPSDOption, ...] = ()¶
- options_2: Tuple[SOMEIPSDOption, ...] = ()¶
- service_id: int¶
someip.header module¶
- class someip.header.AbstractIPOption(address, l4proto, port)[source]¶
Bases:
SOMEIPSDAbstractOption
,Generic
[T
]Abstract base class for options with IP payloads. Generalizes parsing and building based on
_format
,_address_type
and_family
.- address: T¶
- async addrinfo()[source]¶
return address info for this IP option for use in socket-based functions, e.g.,
socket.connect()
orsocket.sendto()
.- Raises:
socket.gaierror – if the call to getaddrinfo failed or returned no result
- Returns:
the first resolved sockaddr tuple
- Return type:
Tuple[str, int] | Tuple[str, int, int, int]
- build()[source]¶
build the byte representation of this option.
- Raises:
struct.error – if
payload
is too big to be represented, ortype
is out of range- Returns:
the byte representation
- Return type:
bytes
- l4proto: L4Protocols | int¶
- classmethod parse_option(buf)[source]¶
parses SD option payload in buf.
- Parameters:
buf (bytes) – buffer containing SOMEIP SD option data
- Raises:
ParseError – if this option type fails to parse buf
- Returns:
the parsed instance
- Return type:
- port: int¶
- class someip.header.AbstractIPv4Option(address, l4proto, port)[source]¶
Bases:
AbstractIPOption
[IPv4Address
]Abstract base class for IPv4 options.
- class someip.header.AbstractIPv6Option(address, l4proto, port)[source]¶
Bases:
AbstractIPOption
[IPv6Address
]Abstract base class for IPv6 options.
- class someip.header.EndpointOption(address, l4proto, port)[source]¶
Bases:
AbstractIPOption
[T
]Abstract base class for endpoint options (IPv4 or IPv6).
- address: T¶
- l4proto: L4Protocols | int¶
- port: int¶
- type: ClassVar[int]¶
Class variable. Used to differentiate SD option types when parsing. See
SOMEIPSDOption.register()
andSOMEIPSDOption.parse()
- class someip.header.IPv4EndpointOption(address, l4proto, port)[source]¶
Bases:
AbstractIPv4Option
,EndpointOption
[IPv4Address
]- type: ClassVar[int] = 4¶
Class variable. Used to differentiate SD option types when parsing. See
SOMEIPSDOption.register()
andSOMEIPSDOption.parse()
- class someip.header.IPv4MulticastOption(address, l4proto, port)[source]¶
Bases:
AbstractIPv4Option
,MulticastOption
[IPv4Address
]- type: ClassVar[int] = 20¶
Class variable. Used to differentiate SD option types when parsing. See
SOMEIPSDOption.register()
andSOMEIPSDOption.parse()
- class someip.header.IPv4SDEndpointOption(*args, **kwds)[source]¶
Bases:
AbstractIPv4Option
,SDEndpointOption
[IPv4Address
]- type: ClassVar[int] = 36¶
Class variable. Used to differentiate SD option types when parsing. See
SOMEIPSDOption.register()
andSOMEIPSDOption.parse()
- class someip.header.IPv6EndpointOption(address, l4proto, port)[source]¶
Bases:
AbstractIPv6Option
,EndpointOption
[IPv6Address
]- type: ClassVar[int] = 6¶
Class variable. Used to differentiate SD option types when parsing. See
SOMEIPSDOption.register()
andSOMEIPSDOption.parse()
- class someip.header.IPv6MulticastOption(address, l4proto, port)[source]¶
Bases:
AbstractIPv6Option
,MulticastOption
[IPv6Address
]- type: ClassVar[int] = 22¶
Class variable. Used to differentiate SD option types when parsing. See
SOMEIPSDOption.register()
andSOMEIPSDOption.parse()
- class someip.header.IPv6SDEndpointOption(*args, **kwds)[source]¶
Bases:
AbstractIPv6Option
,SDEndpointOption
[IPv6Address
]- type: ClassVar[int] = 38¶
Class variable. Used to differentiate SD option types when parsing. See
SOMEIPSDOption.register()
andSOMEIPSDOption.parse()
- exception someip.header.IncompleteReadError[source]¶
Bases:
ParseError
- class someip.header.L4Protocols(value)[source]¶
Bases:
IntEnum
Enum for valid layer 4 protocol identifiers.
- TCP = 6¶
- UDP = 17¶
- class someip.header.MulticastOption(address, l4proto, port)[source]¶
Bases:
AbstractIPOption
[T
]Abstract base class for multicast options (IPv4 or IPv6).
- address: T¶
- l4proto: L4Protocols | int¶
- port: int¶
- type: ClassVar[int]¶
Class variable. Used to differentiate SD option types when parsing. See
SOMEIPSDOption.register()
andSOMEIPSDOption.parse()
- class someip.header.SDEndpointOption(address, l4proto, port)[source]¶
Bases:
AbstractIPOption
[T
]Abstract base class for SD Endpoint options (IPv4 or IPv6).
- address: T¶
- l4proto: L4Protocols | int¶
- port: int¶
- type: ClassVar[int]¶
Class variable. Used to differentiate SD option types when parsing. See
SOMEIPSDOption.register()
andSOMEIPSDOption.parse()
- class someip.header.SOMEIPHeader(service_id, method_id, client_id, session_id, interface_version, message_type, protocol_version=1, return_code=SOMEIPReturnCode.E_OK, payload=b'')[source]¶
Bases:
object
Represents a top-level SOMEIP packet (header and payload).
- Parameters:
service_id (int) –
method_id (int) –
client_id (int) –
session_id (int) –
interface_version (int) –
message_type (SOMEIPMessageType) –
protocol_version (int) –
return_code (SOMEIPReturnCode) –
payload (bytes) –
- build()[source]¶
builds the byte representation of this SOMEIP packet.
- Raises:
struct.error – if any attribute was out of range for serialization
- Returns:
the byte representation
- Return type:
bytes
- client_id: int¶
- property description¶
- interface_version: int¶
- message_type: SOMEIPMessageType¶
- method_id: int¶
- classmethod parse(buf)[source]¶
parses SOMEIP packet in buf
- Parameters:
buf (bytes) – buffer containing SOMEIP packet
- Raises:
IncompleteReadError – if the buffer did not contain enough data to unpack the SOMEIP packet. Either there was less data than one SOMEIP header length, or the size in the header was too big
ParseError – if the packet contained invalid data, such as an unknown message type or return code
- Returns:
tuple (S, B) where S is the parsed
SOMEIPHeader
instance and B is the unparsed rest of buf- Return type:
Tuple[SOMEIPHeader, bytes]
- payload: bytes = b''¶
- protocol_version: int = 1¶
- async classmethod read(reader)[source]¶
reads a SOMEIP packet from reader. Waits until one full SOMEIP packet is available from the stream.
- Parameters:
reader (StreamReader) – (usually TCP) stream to parse into SOMEIP packets
- Raises:
ParseError – if the packet contained invalid data, such as an unknown message type or return code
- Returns:
the parsed
SOMEIPHeader
instance- Return type:
- return_code: SOMEIPReturnCode = 0¶
- service_id: int¶
- session_id: int¶
- class someip.header.SOMEIPMessageType(value)[source]¶
Bases:
IntEnum
An enumeration.
- ERROR = 129¶
- ERROR_ACK = 193¶
- NOTIFICATION = 2¶
- NOTIFICATION_ACK = 66¶
- REQUEST = 0¶
- REQUEST_ACK = 64¶
- REQUEST_NO_RETURN = 1¶
- REQUEST_NO_RETURN_ACK = 65¶
- RESPONSE = 128¶
- RESPONSE_ACK = 192¶
- class someip.header.SOMEIPReader(reader)[source]¶
Bases:
object
Wrapper class around
asyncio.StreamReader
that returns parsedSOMEIPHeader
fromread()
- Parameters:
reader (asyncio.StreamReader) –
- async read()[source]¶
- Return type:
SOMEIPHeader | None
- class someip.header.SOMEIPReturnCode(value)[source]¶
Bases:
IntEnum
An enumeration.
- E_MALFORMED_MESSAGE = 9¶
- E_NOT_OK = 1¶
- E_NOT_REACHABLE = 5¶
- E_NOT_READY = 4¶
- E_OK = 0¶
- E_TIMEOUT = 6¶
- E_UNKNOWN_METHOD = 3¶
- E_UNKNOWN_SERVICE = 2¶
- E_WRONG_INTERFACE_VERSION = 8¶
- E_WRONG_MESSAGE_TYPE = 10¶
- E_WRONG_PROTOCOL_VERSION = 7¶
- class someip.header.SOMEIPSDAbstractOption[source]¶
Bases:
SOMEIPSDOption
Base class for specific option implementations.
- abstract classmethod parse_option(buf)[source]¶
parses SD option payload in buf.
- Parameters:
buf (bytes) – buffer containing SOMEIP SD option data
- Raises:
ParseError – if this option type fails to parse buf
- Returns:
the parsed instance
- Return type:
- type: ClassVar[int]¶
Class variable. Used to differentiate SD option types when parsing. See
SOMEIPSDOption.register()
andSOMEIPSDOption.parse()
- class someip.header.SOMEIPSDConfigOption(configs: 'typing.Tuple[typing.Tuple[str, typing.Optional[str]], ...]')[source]¶
Bases:
SOMEIPSDAbstractOption
- Parameters:
configs (Tuple[Tuple[str, str | None], ...]) –
- build()[source]¶
build the byte representation of this option.
- Raises:
struct.error – if
payload
is too big to be represented, ortype
is out of range- Returns:
the byte representation
- Return type:
bytes
- configs: Tuple[Tuple[str, str | None], ...]¶
- classmethod parse_option(buf)[source]¶
parses SD option payload in buf.
- Parameters:
buf (bytes) – buffer containing SOMEIP SD option data
- Raises:
ParseError – if this option type fails to parse buf
- Returns:
the parsed instance
- Return type:
- type: ClassVar[int] = 1¶
Class variable. Used to differentiate SD option types when parsing. See
SOMEIPSDOption.register()
andSOMEIPSDOption.parse()
- class someip.header.SOMEIPSDEntry(sd_type, service_id, instance_id, major_version, ttl, minver_or_counter, options_1=(), options_2=(), option_index_1=None, option_index_2=None, num_options_1=None, num_options_2=None)[source]¶
Bases:
object
Represents an Entry in SOMEIP SD packets.
- Parameters:
sd_type (SOMEIPSDEntryType) –
service_id (int) –
instance_id (int) –
major_version (int) –
ttl (int) –
minver_or_counter (int) – service minor version or eventgroup id and counter value
options_1 (Tuple[SOMEIPSDOption, ...]) – resolved options that apply to this entry (run 1)
options_2 (Tuple[SOMEIPSDOption, ...]) – resolved options that apply to this entry (run 2)
option_index_1 (int | None) – option index (for unresolved options, run 1)
option_index_2 (int | None) – option index (for unresolved options, run 2)
num_options_1 (int | None) – number of option (for unresolved options, run 1)
num_options_2 (int | None) – number of option (for unresolved options, run 2)
- assign_option_index(options)[source]¶
assigns option indexes, optionally inserting new options to the given option list. Index assignment is done in a simple manner by searching if a slice exists in options that matches the option runs (
options_1
andoptions_2
).- Returns:
a new
SOMEIPSDEntry
instance with assigned options indexes- Parameters:
options (List[SOMEIPSDOption]) –
- Return type:
- build()[source]¶
build the byte representation of this entry.
- Raises:
ValueError – if the option indexes on this entry were not resolved. see
assign_option_index()
struct.error – if any attribute was out of range for serialization
- Returns:
the byte representation
- Return type:
bytes
- property eventgroup_counter: int¶
the eventgroup counter
- Raises:
TypeError – if this entry is not a Subscribe or SubscribeAck
- property eventgroup_id: int¶
the eventgroup id
- Raises:
TypeError – if this entry is not a Subscribe or SubscribeAck
- instance_id: int¶
- major_version: int¶
- minver_or_counter: int¶
- num_options_1: int | None = None¶
- num_options_2: int | None = None¶
- option_index_1: int | None = None¶
- option_index_2: int | None = None¶
- property options: Tuple[SOMEIPSDOption, ...]¶
- options_1: Tuple[SOMEIPSDOption, ...] = ()¶
- options_2: Tuple[SOMEIPSDOption, ...] = ()¶
- property options_resolved: bool¶
indicates if the options on this instance are resolved
- classmethod parse(buf, num_options)[source]¶
parses SOMEIP SD entry in buf
- Parameters:
buf (bytes) – buffer containing SOMEIP SD entry
num_options (int) – number of known options in containing
SOMEIPSDHeader
- Raises:
ParseError – if the buffer did not parse as a SOMEIP SD entry, e.g., due to an unknown entry type or out-of-bounds option indexes
- Returns:
tuple (S, B) where S is the parsed
SOMEIPSDEntry
instance and B is the unparsed rest of buf- Return type:
Tuple[SOMEIPSDEntry, bytes]
- resolve_options(options)[source]¶
resolves this entry’s options with option list from containing
SOMEIPSDHeader
.- Returns:
a new
SOMEIPSDEntry
instance with resolved options- Parameters:
options (Tuple[SOMEIPSDOption, ...]) –
- Return type:
- sd_type: SOMEIPSDEntryType¶
- service_id: int¶
- property service_minor_version: int¶
the service minor version
- Raises:
TypeError – if this entry is not a FindService or OfferService
- ttl: int¶
- class someip.header.SOMEIPSDEntryType(value)[source]¶
Bases:
IntEnum
An enumeration.
- FindService = 0¶
- OfferService = 1¶
- Subscribe = 6¶
- SubscribeAck = 7¶
- class someip.header.SOMEIPSDHeader(entries, options=(), flag_reboot=False, flag_unicast=True, flags_unknown=0)[source]¶
Bases:
object
Represents a SOMEIP SD packet.
- Parameters:
entries (Tuple[SOMEIPSDEntry, ...]) –
options (Tuple[SOMEIPSDOption, ...]) –
flag_reboot (bool) –
flag_unicast (bool) –
flags_unknown (int) –
- assign_option_indexes()[source]¶
assigns option indexes to all entries and builds the options list.
- Returns:
a new
SOMEIPSDHeader
instance with entries with assigned options indexes
- build()[source]¶
builds the byte representation of this SOMEIP SD packet.
- Raises:
struct.error – if any attribute was out of range for serialization
ValueError – from
SOMEIPSDEntry.build()
- Returns:
the byte representation
- Return type:
bytes
- entries: Tuple[SOMEIPSDEntry, ...]¶
- flag_reboot: bool = False¶
- flag_unicast: bool = True¶
- flags_unknown: int = 0¶
- options: Tuple[SOMEIPSDOption, ...] = ()¶
- classmethod parse(buf)[source]¶
parses SOMEIP SD packet in buf
- Parameters:
buf (bytes) – buffer containing SOMEIP packet
- Raises:
ParseError – if the packet contained invalid data, such as out-of-bounds lengths or failing
SOMEIPSDEntry.parse()
andSOMEIPSDOption.parse()
- Returns:
tuple (S, B) where S is the parsed
SOMEIPSDHeader
instance and B is the unparsed rest of buf- Return type:
Tuple[SOMEIPSDHeader, bytes]
- resolve_options()[source]¶
resolves all entries’ options from options list.
- Returns:
a new
SOMEIPSDHeader
instance with entries with resolved options
- class someip.header.SOMEIPSDLoadBalancingOption(priority: 'int', weight: 'int')[source]¶
Bases:
SOMEIPSDAbstractOption
- Parameters:
priority (int) –
weight (int) –
- build()[source]¶
build the byte representation of this option.
- Raises:
struct.error – if
payload
is too big to be represented, ortype
is out of range- Returns:
the byte representation
- Return type:
bytes
- classmethod parse_option(buf)[source]¶
parses SD option payload in buf.
- Parameters:
buf (bytes) – buffer containing SOMEIP SD option data
- Raises:
ParseError – if this option type fails to parse buf
- Returns:
the parsed instance
- Return type:
- priority: int¶
- type: ClassVar[int] = 2¶
Class variable. Used to differentiate SD option types when parsing. See
SOMEIPSDOption.register()
andSOMEIPSDOption.parse()
- weight: int¶
- class someip.header.SOMEIPSDOption[source]¶
Bases:
object
Abstract base class representing SD options
- abstract build()[source]¶
build the byte representation of this option, must be implemented by actual options. Should use
build_option()
to build the option header.- Raises:
struct.error – if any attribute was out of range for serialization
- Returns:
the byte representation
- Return type:
bytes
- build_option(type_b, buf)[source]¶
Helper for SD option classes to build the byte representation of their option.
- Parameters:
type_b (int) – option type identifier
buf (bytes) – buffer SD option data
- Raises:
struct.error – if the buffer is too big to be represented, or type_b is out of range
- Returns:
the byte representation
- Return type:
bytes
- classmethod parse(buf)[source]¶
parses SOMEIP SD option in buf. Options with unknown types will be parsed as
SOMEIPSDUnknownOption
, known types will be parsed to their registered types.- Parameters:
buf (bytes) – buffer containing SOMEIP SD option
- Raises:
ParseError – if the buffer did not parse as a SOMEIP SD option, e.g., due to out-of-bounds lengths or the specific
SOMEIPSDAbstractOption.parse_option()
failed- Returns:
tuple (S, B) where S is the parsed
SOMEIPSDOption
instance and B is the unparsed rest of buf- Return type:
Tuple[SOMEIPSDOption, bytes]
- classmethod register(option_cls)[source]¶
Decorator for SD option classes, to register them for option parsing, identified by their
SOMEIPSDAbstractOption.type
members.- Parameters:
option_cls (Type[SOMEIPSDAbstractOption]) –
- Return type:
Type[SOMEIPSDAbstractOption]
- class someip.header.SOMEIPSDUnknownOption(type, payload)[source]¶
Bases:
SOMEIPSDOption
Received options with unknown option types are parsed as this generic class.
- Parameters:
type (int) – the type identifier for this unknown option
payload (bytes) – the option payload
- payload: bytes¶
- type: int¶
someip.sd module¶
- class someip.sd.AutoSubscribeServiceListener(subscriber: 'ServiceSubscriber', eventgroup: 'someip.config.Eventgroup')[source]¶
Bases:
ClientServiceListener
- Parameters:
subscriber (ServiceSubscriber) –
eventgroup (Eventgroup) –
- eventgroup: Eventgroup¶
- service_offered(service, source)[source]¶
- Parameters:
service (Service) –
source (Tuple[str, int] | Tuple[str, int, int, int]) –
- Return type:
None
- service_stopped(service, source)[source]¶
- Parameters:
service (Service) –
source (Tuple[str, int] | Tuple[str, int, int, int]) –
- Return type:
None
- subscriber: ServiceSubscriber¶
- class someip.sd.ClientServiceListener[source]¶
Bases:
object
- class someip.sd.DatagramProtocolAdapter(protocol, is_multicast)[source]¶
Bases:
DatagramProtocol
- Parameters:
protocol (SOMEIPDatagramProtocol) –
is_multicast (bool) –
- connection_lost(exc)[source]¶
Called when the connection is lost or closed.
The argument is an exception object or None (the latter meaning a regular EOF is received or the connection was aborted or closed).
- Parameters:
exc (Exception | None) –
- Return type:
None
- class someip.sd.EventgroupSubscription(service_id: 'int', instance_id: 'int', major_version: 'int', id: 'int', counter: 'int', ttl: 'int', endpoints: 'typing.FrozenSet[someip.header.EndpointOption[typing.Any]]' = <factory>, options: 'typing.Tuple[someip.header.SOMEIPSDOption, ...]' = <factory>)[source]¶
Bases:
object
- Parameters:
service_id (int) –
instance_id (int) –
major_version (int) –
id (int) –
counter (int) –
ttl (int) –
endpoints (FrozenSet[EndpointOption[Any]]) –
options (Tuple[SOMEIPSDOption, ...]) –
- counter: int¶
- endpoints: FrozenSet[EndpointOption[Any]]¶
- classmethod from_subscribe_entry(entry)[source]¶
- Parameters:
entry (SOMEIPSDEntry) –
- id: int¶
- instance_id: int¶
- major_version: int¶
- options: Tuple[SOMEIPSDOption, ...]¶
- service_id: int¶
- ttl: int¶
- class someip.sd.SOMEIPDatagramProtocol(logger='someip')[source]¶
Bases:
object
is actually not a subclass of asyncio.BaseProtocol or asyncio.DatagramProtocol, because datagram_received() has an additional parameter multicast: bool
TODO: fix misleading name
- Parameters:
logger (str) –
- async classmethod create_unicast_endpoint(*args, local_addr=None, remote_addr=None, loop=None, **kwargs)[source]¶
- Parameters:
local_addr (Tuple[str, int] | Tuple[str, int, int, int] | None) –
remote_addr (Tuple[str, int] | Tuple[str, int, int, int] | None) –
- datagram_received(data, addr, multicast)[source]¶
- Parameters:
addr (Tuple[str, int] | Tuple[str, int, int, int]) –
multicast (bool) –
- Return type:
None
- message_received(someip_message, addr, multicast)[source]¶
called when a well-formed SOME/IP datagram was received
- Parameters:
someip_message (SOMEIPHeader) –
addr (Tuple[str, int] | Tuple[str, int, int, int]) –
multicast (bool) –
- Return type:
None
- class someip.sd.ServerServiceListener[source]¶
Bases:
object
- client_subscribed(subscription, source)[source]¶
should raise someip.sd.NakSubscription if subscription should be rejected
- Parameters:
subscription (EventgroupSubscription) –
source (Tuple[str, int] | Tuple[str, int, int, int]) –
- Return type:
None
- client_unsubscribed(subscription, source)[source]¶
- Parameters:
subscription (EventgroupSubscription) –
source (Tuple[str, int] | Tuple[str, int, int, int]) –
- Return type:
None
- class someip.sd.ServiceAnnouncer(sd)[source]¶
Bases:
object
- Parameters:
sd (ServiceDiscoveryProtocol) –
- announce_service(instance)[source]¶
- Parameters:
instance (ServiceInstance) –
- Return type:
None
- handle_findservice(entry, addr, received_over_multicast)[source]¶
- Parameters:
entry (SOMEIPSDEntry) –
addr (Tuple[str, int] | Tuple[str, int, int, int]) –
received_over_multicast (bool) –
- Return type:
None
- handle_subscribe(entry, addr)[source]¶
- Parameters:
entry (SOMEIPSDEntry) –
addr (Tuple[str, int] | Tuple[str, int, int, int]) –
- Return type:
None
- queue_send(entry, remote=None)[source]¶
- Parameters:
entry (SOMEIPSDEntry) –
remote (Tuple[str, int] | Tuple[str, int, int, int] | None) –
- Return type:
None
- reboot_detected(addr)[source]¶
- Parameters:
addr (Tuple[str, int] | Tuple[str, int, int, int]) –
- Return type:
None
- stop_announce_service(instance, send_stop=True)[source]¶
stops announcing previously started service
- Parameters:
instance (ServiceInstance) – service instance to be stopped
- Raises:
ValueError – if the service was not announcing
- Return type:
None
- class someip.sd.ServiceDiscover(sd)[source]¶
Bases:
object
- Parameters:
sd (ServiceDiscoveryProtocol) –
- find_subscribe_eventgroup(eventgroup)[source]¶
- Parameters:
eventgroup (Eventgroup) –
- handle_offer(entry, addr)[source]¶
- Parameters:
entry (SOMEIPSDEntry) –
addr (Tuple[str, int] | Tuple[str, int, int, int]) –
- Return type:
None
- is_watching_service(entry)[source]¶
- Parameters:
entry (SOMEIPSDEntry) –
- reboot_detected(addr)[source]¶
- Parameters:
addr (Tuple[str, int] | Tuple[str, int, int, int]) –
- Return type:
None
- service_offer_stopped(addr, entry)[source]¶
- Parameters:
addr (Tuple[str, int] | Tuple[str, int, int, int]) –
entry (SOMEIPSDEntry) –
- Return type:
None
- service_offered(addr, entry)[source]¶
- Parameters:
addr (Tuple[str, int] | Tuple[str, int, int, int]) –
entry (SOMEIPSDEntry) –
- stop_find_subscribe_eventgroup(eventgroup)[source]¶
- Parameters:
eventgroup (Eventgroup) –
- stop_watch_all_services(listener)[source]¶
- Parameters:
listener (ClientServiceListener) –
- Return type:
None
- stop_watch_service(service, listener)[source]¶
- Parameters:
service (Service) –
listener (ClientServiceListener) –
- Return type:
None
- watch_all_services(listener)[source]¶
- Parameters:
listener (ClientServiceListener) –
- Return type:
None
- watch_service(service, listener)[source]¶
- Parameters:
service (Service) –
listener (ClientServiceListener) –
- Return type:
None
- class someip.sd.ServiceDiscoveryProtocol(multicast_addr, timings=None, logger='someip.sd')[source]¶
Bases:
SOMEIPDatagramProtocol
- Parameters:
multicast_addr (_T_SOCKADDR) –
timings (Optional[Timings]) –
logger (str) –
- async classmethod create_endpoints(family, local_addr, multicast_addr, multicast_interface=None, port=30490, ttl=1, loop=None)[source]¶
- Parameters:
family (AddressFamily) –
local_addr (str) –
multicast_addr (str) –
multicast_interface (str | None) –
port (int) –
- message_received(someip_message, addr, multicast)[source]¶
called when a well-formed SOME/IP datagram was received
- Parameters:
someip_message (SOMEIPHeader) –
addr (Tuple[str, int] | Tuple[str, int, int, int]) –
multicast (bool) –
- Return type:
None
- reboot_detected(addr)[source]¶
- Parameters:
addr (Tuple[str, int] | Tuple[str, int, int, int]) –
- Return type:
None
- sd_message_received(sdhdr, addr, multicast)[source]¶
called when a well-formed SOME/IP SD message was received
- Parameters:
sdhdr (SOMEIPSDHeader) –
addr (Tuple[str, int] | Tuple[str, int, int, int]) –
multicast (bool) –
- Return type:
None
- send_sd(entries, remote=None)[source]¶
- Parameters:
entries (Collection[SOMEIPSDEntry]) –
remote (Tuple[str, int] | Tuple[str, int, int, int] | None) –
- Return type:
None
- class someip.sd.ServiceInstance(service, listener, announcer, timings)[source]¶
Bases:
object
- Parameters:
service (someip.config.Service) –
listener (ServerServiceListener) –
announcer (ServiceAnnouncer) –
timings (Timings) –
- eventgroup_subscribe_stopped(addr, subscription)[source]¶
- Parameters:
addr (Tuple[str, int] | Tuple[str, int, int, int]) –
subscription (EventgroupSubscription) –
- Return type:
None
- handle_subscribe(entry, addr)[source]¶
- Parameters:
entry (SOMEIPSDEntry) –
addr (Tuple[str, int] | Tuple[str, int, int, int]) –
- Return type:
bool
- matches_find(entry, addr)[source]¶
- Parameters:
entry (SOMEIPSDEntry) –
addr (Tuple[str, int] | Tuple[str, int, int, int]) –
- Return type:
bool
- class someip.sd.ServiceSubscriber(sd)[source]¶
Bases:
object
datagram protocol for subscribing to eventgroups via SOME/IP SD
- example:
TODO
- Parameters:
sd (ServiceDiscoveryProtocol) –
- reboot_detected(addr)[source]¶
- Parameters:
addr (Tuple[str, int] | Tuple[str, int, int, int]) –
- Return type:
None
- stop_subscribe_eventgroup(eventgroup, endpoint, send=True)[source]¶
- eventgroup:
someip.config.Eventgroup that describes the eventgroup to unsubscribe from
- endpoint:
remote SD endpoint that will receive the subscription messages
- Parameters:
eventgroup (Eventgroup) –
endpoint (Tuple[str, int] | Tuple[str, int, int, int]) –
send (bool) –
- Return type:
None
- subscribe_eventgroup(eventgroup, endpoint)[source]¶
- eventgroup:
someip.config.Eventgroup that describes the eventgroup to subscribe to and the local endpoint that accepts the notifications
- endpoint:
remote SD endpoint that will receive the subscription messages
- Parameters:
eventgroup (Eventgroup) –
endpoint (Tuple[str, int] | Tuple[str, int, int, int]) –
- Return type:
None
- class someip.sd.TimedStore(log)[source]¶
Bases:
Generic
[KT
]- refresh(ttl, address, entry, callback_new, callback_expired)[source]¶
- Parameters:
address (Tuple[str, int] | Tuple[str, int, int, int]) –
entry (KT) –
callback_new (Callable[[KT, Tuple[str, int] | Tuple[str, int, int, int]], None]) –
callback_expired (Callable[[KT, Tuple[str, int] | Tuple[str, int, int, int]], None]) –
- Return type:
None
- stop(address, entry)[source]¶
- Parameters:
address (Tuple[str, int] | Tuple[str, int, int, int]) –
entry (KT) –
- Return type:
None
- class someip.sd.Timings(INITIAL_DELAY_MIN: 'float' = 0.0, INITIAL_DELAY_MAX: 'float' = 3, REQUEST_RESPONSE_DELAY_MIN: 'float' = 0.01, REQUEST_RESPONSE_DELAY_MAX: 'float' = 0.05, REPETITIONS_MAX: 'int' = 3, REPETITIONS_BASE_DELAY: 'float' = 0.01, CYCLIC_OFFER_DELAY: 'float' = 1, FIND_TTL: 'int' = 3, ANNOUNCE_TTL: 'int' = 3, SUBSCRIBE_TTL: 'int' = 5, SUBSCRIBE_REFRESH_INTERVAL: 'typing.Optional[float]' = 3, SEND_COLLECTION_TIMEOUT: 'float' = 0.005)[source]¶
Bases:
object
- Parameters:
INITIAL_DELAY_MIN (float) –
INITIAL_DELAY_MAX (float) –
REQUEST_RESPONSE_DELAY_MIN (float) –
REQUEST_RESPONSE_DELAY_MAX (float) –
REPETITIONS_MAX (int) –
REPETITIONS_BASE_DELAY (float) –
CYCLIC_OFFER_DELAY (float) –
FIND_TTL (int) –
ANNOUNCE_TTL (int) –
SUBSCRIBE_TTL (int) –
SUBSCRIBE_REFRESH_INTERVAL (float | None) –
SEND_COLLECTION_TIMEOUT (float) –
- ANNOUNCE_TTL: int = 3¶
- CYCLIC_OFFER_DELAY: float = 1¶
- FIND_TTL: int = 3¶
- INITIAL_DELAY_MAX: float = 3¶
- INITIAL_DELAY_MIN: float = 0.0¶
- REPETITIONS_BASE_DELAY: float = 0.01¶
- REPETITIONS_MAX: int = 3¶
- REQUEST_RESPONSE_DELAY_MAX: float = 0.05¶
- REQUEST_RESPONSE_DELAY_MIN: float = 0.01¶
- SEND_COLLECTION_TIMEOUT: float = 0.005¶
- SUBSCRIBE_REFRESH_INTERVAL: float | None = 3¶
- SUBSCRIBE_TTL: int = 5¶
someip.service module¶
Simple service implementation. Probably lacking a few things, such as multicast eventgroups and more than basic option handling.
See tools/simpleservice.py
for a basic usage example.
- class someip.service.SimpleEventgroup(service, id, interval=None)[source]¶
set
values
to the current value, callnotify_once()
to immediately notify subscribers about new value.New subscribers will be notified about the current
values
.- Parameters:
service (SimpleService) – the service this group belongs to
id (int) – the event group ID that this group can be subscribed on
interval (Optional[float]) –
- async cyclic_notify(interval)[source]¶
Schedule notifications for all events to all subscribers with a given interval. This coroutine is scheduled as a task by
__init__()
if given a non-zero interval.- Parameters:
interval (float) – how much time to wait before sending the next notification
- Return type:
None
- notify_once(events)[source]¶
Send a notification for all given event ids to all subscribers using the current event values set in
values
.- Parameters:
events (Iterable[int]) –
- subscribe(endpoint)[source]¶
Called by
SimpleService
when a new subscription for this eventgroup was received.Triggers a notification of the current value to be sent to the subscriber.
- Parameters:
endpoint (EndpointOption[Any]) –
- Return type:
None
- unsubscribe(endpoint)[source]¶
Called by
SimpleService
when a subscription for this eventgroup runs out.- Parameters:
endpoint (EndpointOption[Any]) –
- Return type:
None
- values: Dict[int, bytes]¶
the current value for each event to send out as notification payload.
- class someip.service.SimpleService(instance_id)[source]¶
override, call super().__init__() followed by
register_method()
andregister_cyclic_eventgroup()
- Parameters:
instance_id (int) –
- client_subscribed(subscription, source)[source]¶
should raise someip.sd.NakSubscription if subscription should be rejected
- Parameters:
subscription (EventgroupSubscription) –
source (Tuple[str, int] | Tuple[str, int, int, int]) –
- Return type:
None
- client_unsubscribed(subscription, source)[source]¶
- Parameters:
subscription (EventgroupSubscription) –
source (Tuple[str, int] | Tuple[str, int, int, int]) –
- Return type:
None
- message_received(someip_message, addr, multicast)[source]¶
called when a well-formed SOME/IP datagram was received
- Parameters:
someip_message (SOMEIPHeader) –
addr (Tuple[str, int] | Tuple[str, int, int, int]) –
multicast (bool) –
- Return type:
None
- register_eventgroup(eventgroup)[source]¶
register an eventgroup on this service. Incoming subscriptions will be handled and passed to the given eventgroup.
- Parameters:
eventgroup (SimpleEventgroup) –
- Return type:
None
- register_method(id, handler)[source]¶
register a SOME/IP method with the given id on this service. Incoming requests matching the given id will be dispatched to the handler.
Callbacks can raise
MalformedMessageError
to generate an error response with return codesomeip.header.SOMEIPReturnCode.E_MALFORMED_MESSAGE
- Parameters:
id (int) – the method ID
handler (Callable[[SOMEIPHeader, Tuple[str, int] | Tuple[str, int, int, int]], bytes | None]) – the callback to handle the request
- Return type:
None
- send_error_response(msg, addr, return_code)[source]¶
- Parameters:
msg (SOMEIPHeader) –
addr (Tuple[str, int] | Tuple[str, int, int, int]) –
return_code (SOMEIPReturnCode) –
- Return type:
None
- send_positive_response(msg, addr, payload=b'')[source]¶
- Parameters:
msg (SOMEIPHeader) –
addr (Tuple[str, int] | Tuple[str, int, int, int]) –
payload (bytes) –
- Return type:
None
- service_id: ClassVar[int]¶
- start_announce(announcer)[source]¶
- Parameters:
announcer (ServiceAnnouncer) –
- async classmethod start_datagram_endpoint(instance_id, announcer, local_addr=None)[source]¶
create a unicast datagram endpoint for this service and register it with the service discovery announcer.
- Parameters:
instance_id (int) – the service instance ID for this service
announcer (ServiceAnnouncer) – the SD protocol instance that will announce this service
local_addr (Tuple[str, int] | Tuple[str, int, int, int] | None) – a local address to bind to (default: any)
- stop_announce(announcer)[source]¶
- Parameters:
announcer (ServiceAnnouncer) –
- version_major: ClassVar[int]¶
- version_minor: ClassVar[int]¶
someip.utils module¶
- async someip.utils.getfirstaddrinfo(host, port, family=0, type=0, proto=0, sock=None, flags=0, loop=None)[source]¶
retrieve sockaddr for host/port pair with given family, type, proto settings. return first sockaddr. raises socket.gaierror if no result was returned.