flexstack.btp Module
The flexstack.btp package implements ETSI EN 302 636-5-1 transport services.
Router
- class flexstack.btp.router.Router(gn_router)[source]
Bases:
objectBTP Router.
Handles the routing of BTP packets. As specified in ETSI EN 302 636-5-1 V2.1.0 (2017-05).
- Variables:
indication_callbacks (MappingProxyType[int, Callable[[BTPDataIndication], None]] | None) – MappingProxyType of indication callbacks. The key is the port and the value is the callback.
gn_router (GNRouter) – Geonetworking Router.
- Parameters:
gn_router (GNRouter) –
- freeze_callbacks()[source]
Freezes the indication callbacks. After calling this method, no more callbacks can be registered.
- register_indication_callback_btp(port, callback, *, accept_unsecured=False)[source]
Registers a callback for a given port.
- Parameters:
port (int) – Port to register the callback for.
callback (Callable[[BTPDataIndication], None]) – Callback to register.
accept_unsecured (bool) – Deliver unsecured packets to this port although
itsGnSecurityis ENABLED (a service whose payload authenticates itself). Otherwise an unsecured packet is discarded when GN security is enabled.
- Return type:
None
- btp_data_request(request)[source]
Handles a BTPDataRequest.
- Parameters:
request (BTPDataRequest) – BTPDataRequest to handle.
- Return type:
None
- btp_b_data_indication(gn_data_indication)[source]
Handles a BTPBDataIndication.
- Parameters:
gn_data_indication (GNDataIndication) – GNDataIndication to handle.
- Return type:
None
- btp_a_data_indication(gn_data_indication)[source]
Handles a BTPADataIndication.
- Parameters:
gn_data_indication (GNDataIndication) – GNDataIndication to handle.
- Return type:
None
- btp_data_indication(gn_data_indication)[source]
Handles a BTPDataIndication.
- Parameters:
gn_data_indication (GNDataIndication) – GNDataIndication to handle.
- Return type:
None
BTPHeader
- class flexstack.btp.btp_header.BTPAHeader(destination_port=0, source_port=0)[source]
Bases:
objectBTP-A Header class.
Specified in ETSI EN 302 636-5-1 V2.1.0 (2017-05). Section 7.2
- Variables:
destination_port (int) – (16 bit integer) Destination Port field of BTP-A Header
source_port (int) – (16 bit integer) Source Port field of BTP-A Header
- Parameters:
destination_port (int) –
source_port (int) –
- destination_port: int = 0
- source_port: int = 0
- classmethod initialize_with_request(request)[source]
Initialize a BTP-A Header from a BTPDataRequest.
- Parameters:
request (BTPDataRequest) – Request to use for initialization.
- Return type:
- encode_to_int()[source]
Encodes the BTP-A Header to an integer.
- Returns:
Encoded BTP-A Header
- Return type:
int
- encode()[source]
Encodes the BTP-A Header to bytes.
- Returns:
Encoded BTP-A Header
- Return type:
bytes
- class flexstack.btp.btp_header.BTPBHeader(destination_port=0, destination_port_info=0)[source]
Bases:
objectBTP-B Header class.
Specified in ETSI EN 302 636-5-1 V2.1.0 (2017-05). Section 7.3
- Variables:
destination_port (int) – (16 bit integer) Destination Port field of BTP-B Header
destination_port_info (int) – (16 bit integer) Destination Port Info field of BTP-B Header
- Parameters:
destination_port (int) –
destination_port_info (int) –
- destination_port: int = 0
- destination_port_info: int = 0
- classmethod initialize_with_request(request)[source]
Initialize a BTP-B Header from a BTPDataRequest.
- Parameters:
request (BTPDataRequest) – Request to use for initialization.
- Return type:
- encode_to_int()[source]
Encodes the BTP-B Header to an integer.
- Returns:
Encoded BTP-B Header
- Return type:
int
- encode()[source]
Encodes the BTP-B Header to bytes.
- Returns:
Encoded BTP-B Header
- Return type:
bytes
ServiceAccessPoint
- class flexstack.btp.service_access_point.BTPDataRequest(btp_type=CommonNH.BTP_B, source_port=0, destination_port=0, destination_port_info=0, gn_packet_transport_type=<factory>, gn_destination_address=<factory>, gn_area=<factory>, gn_max_hop_limit=0, gn_max_packet_lifetime=None, gn_repetition_interval=None, gn_max_repetition_time=None, communication_profile=CommunicationProfile.UNSPECIFIED, traffic_class=<factory>, security_profile=SecurityProfile.NO_SECURITY, its_aid=0, security_permissions=b'\x00', length=0, data=b'')[source]
Bases:
objectBTP Data Request class. As specified in ETSI EN 302 636-5-1 V2.2.1 (2019-05). Annex A.2
- Variables:
btp_type (CommonNH) – BTP Type (BTP-A for interactive, BTP-B for non-interactive transport).
source_port (int) – (16 bit integer) Source Port. Optional; only used for BTP-A.
destination_port (int) – (16 bit integer) Destination Port.
destination_port_info (int) – (16 bit integer) Destination Port Info. Optional; only used for BTP-B.
gn_packet_transport_type (PacketTransportType) – GN Packet Transport Type (GeoUnicast, SHB, TSB, GeoBroadcast, GeoAnycast).
gn_destination_address (GNAddress) – GN Destination Address. Used for GeoUnicast or geographical area for GeoBroadcast/GeoAnycast.
gn_area (Area) – GN Area for GeoBroadcast/GeoAnycast transport.
gn_max_hop_limit (int) – GN Maximum Hop Limit. Optional; specifies the number of hops a packet is allowed to have in the network.
gn_max_packet_lifetime (float or None) – GN Maximum Packet Lifetime in seconds. Optional; specifies the maximum tolerable time a GeoNetworking packet can be buffered until it reaches its destination.
gn_repetition_interval (int or None) – GN Repetition Interval in milliseconds. Optional; specifies the duration between two consecutive transmissions of the same packet during the maximum repetition time.
gn_max_repetition_time (int or None) – GN Maximum Repetition Time in milliseconds. Optional; specifies the duration for which the packet will be repeated if the repetition interval is set.
communication_profile (CommunicationProfile) – GN Communication Profile; determines the LL protocol entity.
traffic_class (TrafficClass) – GN Traffic Class.
security_profile (SecurityProfile) – Security profile to apply when the GN router signs the packet. Defaults to
SecurityProfile.NO_SECURITY(no signing).its_aid (int) – ITS-AID (PSID) of the service carried in this packet, used by the GN router to select the correct signing certificate. Only relevant when security_profile is not
NO_SECURITY.security_permissions (bytes) – Sender permissions forwarded to the sign service. Only relevant when security_profile is not
NO_SECURITY.length (int) – Length of the payload.
data (bytes) – Payload.
- Parameters:
btp_type (CommonNH) –
source_port (int) –
destination_port (int) –
destination_port_info (int) –
gn_packet_transport_type (PacketTransportType) –
gn_destination_address (GNAddress) –
gn_area (Area) –
gn_max_hop_limit (int) –
gn_max_packet_lifetime (float | None) –
gn_repetition_interval (int | None) –
gn_max_repetition_time (int | None) –
communication_profile (CommunicationProfile) –
traffic_class (TrafficClass) –
security_profile (SecurityProfile) –
its_aid (int) –
security_permissions (bytes) –
length (int) –
data (bytes) –
- source_port: int = 0
- destination_port: int = 0
- destination_port_info: int = 0
- gn_packet_transport_type: PacketTransportType
- gn_max_hop_limit: int = 0
- gn_max_packet_lifetime: float | None = None
- gn_repetition_interval: int | None = None
- gn_max_repetition_time: int | None = None
- communication_profile: CommunicationProfile = 0
- traffic_class: TrafficClass
- security_profile: SecurityProfile = 0
- its_aid: int = 0
- security_permissions: bytes = b'\x00'
- length: int = 0
- data: bytes = b''
- to_dict()[source]
Returns the BTPDataRequest as a dictionary.
- Returns:
Dictionary representation of the BTPDataRequest.
- Return type:
dict
- class flexstack.btp.service_access_point.BTPDataIndication(source_port=0, destination_port=0, destination_port_info=0, gn_packet_transport_type=<factory>, gn_destination_address=<factory>, gn_source_position_vector=<factory>, gn_security_report=None, gn_certificate_id=None, gn_permissions=None, gn_its_aid=None, gn_traffic_class=<factory>, gn_remaining_packet_lifetime=None, gn_destination_area=None, length=0, data=b'')[source]
Bases:
objectBTP Data Indication class. As specified in ETSI EN 302 636-5-1 V2.2.1 (2019-05). Annex A.3
- Variables:
source_port (int) – (16 bit integer) Source Port. Optional; only present for BTP-A.
destination_port (int) – (16 bit integer) Destination Port.
destination_port_info (int) – (16 bit integer) Destination Port Info. Optional; only present for BTP-B.
gn_packet_transport_type (PacketTransportType) – GN Packet Transport Type.
gn_destination_address (GNAddress) – GN Destination Address for GeoUnicast or geographical area for GeoBroadcast/GeoAnycast, as generated by the source.
gn_source_position_vector (LongPositionVector) – GN Source Position Vector; geographical position of the source.
gn_security_report (bytes or None) – GN Security Report. Optional; result of the security processing of the received packet.
gn_certificate_id (bytes or None) – GN Certificate Id. Optional; identifier of the certificate used by the sender.
gn_permissions (bytes or None) – GN Permissions. Optional; permissions (SSP) from the sender’s certificate.
gn_its_aid (int or None) – ITS-AID (PSID) of a secured packet, which the receiving facility checks against its own ITS-AID (e.g. ETSI TS 103 097 clause 7.1.1).
gn_traffic_class (TrafficClass) – GN Traffic Class.
gn_remaining_packet_lifetime (float or None) – GN Remaining Packet Lifetime in seconds. Optional.
gn_destination_area (Area or None) – Destination area of a GeoBroadcast / GeoAnycast packet (the geographical “GN destination address” of ETSI TS 103 836-5-1); None otherwise.
length (int) – Length of the payload.
data (bytes) – Payload.
- Parameters:
source_port (int) –
destination_port (int) –
destination_port_info (int) –
gn_packet_transport_type (PacketTransportType) –
gn_destination_address (GNAddress) –
gn_source_position_vector (LongPositionVector) –
gn_security_report (bytes | None) –
gn_certificate_id (bytes | None) –
gn_permissions (bytes | None) –
gn_its_aid (int | None) –
gn_traffic_class (TrafficClass) –
gn_remaining_packet_lifetime (float | None) –
gn_destination_area (Area | None) –
length (int) –
data (bytes) –
- source_port: int = 0
- destination_port: int = 0
- destination_port_info: int = 0
- gn_packet_transport_type: PacketTransportType
- gn_source_position_vector: LongPositionVector
- gn_security_report: bytes | None = None
- gn_certificate_id: bytes | None = None
- gn_permissions: bytes | None = None
- gn_its_aid: int | None = None
- gn_traffic_class: TrafficClass
- gn_remaining_packet_lifetime: float | None = None
- length: int = 0
- data: bytes = b''
- classmethod initialize_with_gn_data_indication(gn_data_indication)[source]
Construct a BTPDataIndication from a GNDataIndication.
- Parameters:
gn_data_indication (GNDataIndication) – GNDataIndication to construct from.
- Return type:
- set_destination_port_and_info(destination_port, destination_port_info)[source]
Sets the destination port and destination port info.
- Parameters:
destination_port (int) – Destination port to set.
destination_port_info (int) – Destination port info to set.
- Returns:
New BTPDataIndication with updated destination port and info.
- Return type:
- to_dict()[source]
Returns the BTPDataIndication as a dictionary.
- Returns:
Dictionary representation of the BTPDataIndication.
- Return type:
dict