SOMP/IP(Scalable service-oriented middleware over IP)
Definition
- SOME/IP provide service oriented comunication over network.
- It is based on service definitions that functionaities that the service provides.
- A service can consist of combinations of zero or multiple methods, events, and fields.
- Events provide data that are sent cyclically or on change from the provider to the subscriber.
- Methods provide the possibility to the subscriber to issue remote procedure calls which are executed on provider side
- Fields are combinations of one or more of the following three
- a notifier which sends data on change from the provider to the subscriber.
- a getter which can be called by the subscriber to explicitly query the provider for a value
- a setter which can be called by subscriber when it wants to change the value on provider side
SOME/IP header format
block-beta
columns 4
a1("Message ID(service ID/method ID) [32 bits]"):4
a2("Length [32 bits]"):4
a3("Request ID(client ID/session ID) [32 bits]"):4
a4("Protocol version [8 bits]") a5("Interface version [8 bits]") a6("Message type [8 bits]") a7("Return code [8 bits]")
a8("E2E header [variable size/depentent on selected E2E profiles]"):4
a9("Payload [variable size]"):4
classDef E2E_STYTE fill:#FFEC9E;
class a8 E2E_STYTE
- Header: 采用网络字节序(大端)
- Payload(E2E): 包含Event的数据元素,或者method参数
- Service ID
bit0 bit1-15 Service ID 0 [1 bit] Method ID[last 15 bits] Service ID 1 [1 bit] Event ID[last 15 bits] - Request ID: 请求报文和响应报文保持一致
- client ID: 唯一标识客户端
- session ID: 随每次调用增加[1, 0xffff]
- Protocal version: SOME/IP 版本
- Interface version: 服务接口主版本
- Message Type
value description 0x00 REQUEST a request expect a response(even void) 0x01 REQUEST_NO_RETURN a fire&forget request 0x02 NOTIFICATION a request notification/event callback without expecting no response 0x80 RESPONSE the response message 0x81 ERROR the response containing an error 0x20 TP_REQUEST a TP request expect a response(even void) 0x21 TP_REQUEST_NO_RETURN a TP fire&forget request 0x22 TP_NOTIFICATION a TP request notification/event callback without expecting no response 0xa0 TP_RESPONSE the TP response message 0xa1 TP_ERROR the TP response containing an error - Return code
- 针对response或者error报文有效
serialization
数据结构序列化: 将结构化的数据按照规则转换为字节流
-
结构体序列化: 内存对齐
-
带标签结构体序列化(=wireType + DataID): 每个数据配置DataID, 插入tag。对于基本类型(wireType4~7), 后面要加length Field
block-beta columns 8 a1("wire type") a2("data id(higher)") a3("data id(lower)"):2 a4("len(8/16/32 bits)"):2 a5("member data"):2 classDef WIRE_STYTE fill:#FFEC9E; class a1 WIRE_STYTE classDef DATA_STYTE fill:#3ABEF9; class a2 DATA_STYTE class a3 DATA_STYTE classDef LENTH_STYLE fill:#FFDB00; class a4 LENTH_STYLE
wireType following data 0 8 bit data base data type 1 16 bit data base data type 2 32 bit data base data type 3 64 bit data base data type 4 complex data type: array, struct, string, union with length field of static size(configured in data definition) 5 complex data type: array, struct, string, union with length field size 1 byte(ignore static definition) 6 complex data type: array, struct, string, union with length field size 2 byte(ignore static definition) 7 complex data type: array, struct, string, union with length field size 4 byte(ignore static definition) -
字符串序列化: 以ByteOrderMask起始, '\0’终止,变长要加length field
-
数组序列化: 变长要加length field
-
联合体序列化: length filed要考虑padding
protocal
- 支持UDP(单播/多播), TCP
- 一个传输层PDU中可能包含多个SOME/IP报文(UDP packet, TCP segment)
- 同一个服务的不同服务实例需要不同的端口
- 较长的UDP传输报文使用SOME/IP-TP协议,分段SessionID相同,messageType(0x20)带TP-Flag(1),offset(base 16)为已发送字节数, more flag标识是否有更多报文
- 基于UDP的SOME/IP报文payload不能超过1400字节
- 分段不能超过1392字节
block-beta columns 8 a1("Message ID(service ID/method ID) \n [32 bits]"):8 a2("Length [32 bits]"):8 a3("Request ID(client ID/session ID) [32 bits]"):8 a4("Protocol version [8 bits]"):2 a5("Interface version [8 bits]"):2 a6("Message type [8 bits]"):2 a7("Return code [8 bits]"):2 a8("offset [28 bits]"):7 a9("reserve [3 bits] \n More-flag [1 bits]") a10("payload"):8 classDef E2E_STYTE fill:#FFEC9E; class a6 E2E_STYTE class a8 E2E_STYTE class a9 E2E_STYTE
- Method
- request/response通信
- 请求报文: 序列化in, inout参数,报文类型REQUEST
- 响应报文: 序列化output, inout参数,报文类型为RESPONSE或者ERROR
- fire&forget通信(无响应请求)
- request/response通信
- Notification Event
- 通过SOME/IP-SD机制实现,服务端序列化event,周期或者变更时发送
- field:状态值
- setter, getter: request/response
- notify: Notification event
- 错误处理
- Error Message
- 联合体或者字符串说明错误信息
- Return Code
ID Name Description 0x00 E_OK no error occurred 0x01 E_NOT_OK an unspecified error occurred 0x02 E_UNKNOWN_SERVICE the request service ID is unkonwn 0x03 E_UNKNOWN_METHOD the request method ID is unknown, service ID is known 0x04 E_NOT_READY service ID and method ID is known, application is not running 0x05 E_NOT_READCHABLE system running the service is not reachable(internal code error only) 0x06 E_TIMEOUT a timeout occurred(internal code error only) 0x07 E_WRONG_PROTOCAL_VERSION version of SOME/IP not supported 0x08 E_WRONG_INTERFACE_VERSION interface version mismatch 0x09 E_MALFORMED_MESSAGE deserialization is not corrced so payload can’t be serialized 0x0a E_WRONG_MESSAGE_TYPE an unexcepted message type was received 0x0b E_E2E_REPEATED Repeated E2E calculation error 0x0c E_E2E_WRONG_SEQUENCE wrong E2E sequence error 0x0d E_E2E not further specified E2E error 0x0e E_E2E_NOT_AVALIABLE E2E not supported 0x0f E_E2E_NO_NEW_DATA no new data for E2E calculation present. 0x10-0x1f RESERVED reserved for generic SOME/IP errors. These errors will be specified in future versions of this document 0x20-0x5e RESERVED reserved for sepcific errors of services and methods, these error are specified by the interface specification
- Error Message
module features-SOME/IP-SD
- SOME/IP-SD用于定位服务实例,检测服务是否在运行,实现发现订阅
- UDP发送
- 报文格式:
- Header:
- Client ID:0
- Session ID:每发出一帧加1
block-beta columns 4 a1("Message ID(service ID/method ID) [32 bits]"):4 a2("Length [32 bits]"):4 a3("Request ID(client ID/session ID) [32 bits]"):4 a4("Protocol version [8 bits]") a5("Interface version [8 bits]") a6("Message type [8 bits]") a7("Return code [8 bits]") a8("Flags [8 bits]"):1 a9("Reserved [24 bits]"):3 a10("len of entries array [32 bits]"):4 a11("entries array [32 bits]"):4 a12("len of options array [32 bits]"):4 a13("options array [32 bits]"):4 classDef SD1_STYTE fill:#FFD0D0; class a8 SD1_STYTE class a9 SD1_STYTE classDef SD2_STYTE fill:#F9F9E0; class a10 SD2_STYTE class a11 SD2_STYTE classDef SD3_STYTE fill:#3AA6B9; class a12 SD3_STYTE class a13 SD3_STYTE
- Entry: 支持多组
- service Entry:
- Type:FindService(0x00), OfferService(0x01) and StopOfferService(0x01)
- Service ID, Instance ID: 一个service有多个instance
block-beta columns 8 a1("Type [8 bits]"):2 a2("Index 1st options [8 bits]"):2 a3("Index 1st options [8 bits]"):2 a4("# of opt 1 [4 bits]") a5("# of opt 2 [4 bits]") a6("Service ID [16 bits]"):4 a7("Instance ID [16 bits]"):4 a8("Major version [8 bits]"):2 a9("TTL [24 bits]"):6 a10("Minor version [32 bits]"):8
- Eventgroup Entry:
- Type: Subscribe(0x06), StopSubscribeEventgroup(0x06), SubscribeAck(0x07) and SubscribeEventgroupNack(0x07)
block-beta columns 8 a1("Type [8 bits]"):2 a2("Index 1st options [8 bits]"):2 a3("Index 1st options [8 bits]"):2 a4("# of opt 1 [4 bits]") a5("# of opt 2 [4 bits]") a6("Service ID [16 bits]"):4 a7("Instance ID [16 bits]"):4 a8("Major version [8 bits]"):2 a9("TTL [24 bits]"):6 a10("reserved [8 bits]"):2 a11("init-flag [1 bits]"):1 a12("Counter [4 bits]"):1 a13("Eventgroup ID [16 bits]"):4
- service Entry:
- option:
- Configuration Option: 传输任意配置字符串键值对
block-beta columns 4 a1("len [16 bits]"):2 a2("Type(=0x01) [8 bits]") a3("Reserved(=0x00) [8 bits]") a4("Zero-terminated configuration string \n ([len]id = value [len]id = value[0])"):4
- Loading Balancing Option: Service Instance = 0xFFFF时使用,根据权重选择优先级最高的服务
block-beta columns 4 a1("len (= 0x0005) [16 bits]"):2 a2("Type(=0x02) [8 bits]") a3("Reserved(=0x00) [8 bits]") a4("Priority [16 bits]"):2 a5("Weigth [16 bits]"):2
- IPv4 Endpoint Option: 在offer中代表事件源(发送方), subscribe Eventgroup中代表接收源(发送方)
block-beta columns 4 a1("len (= 0x0009) [16 bits]"):2 a2("Type(=0x04) [8 bits]") a3("Reserved(=0x00) [8 bits]") a4("ipv4 address [32 bits]"):4 a5("reserved(=0x00) [8 bits]") a6("L4-proto(UDP/TCP) [8 bits]") a7("port num [16 bits]"):2
- IPv4 Multicast Option: Subscribe eventgroup ack代表多播目的地,仅支持UDP
block-beta columns 4 a1("len (= 0x0009) [16 bits]"):2 a2("Type(=0x14) [8 bits]") a3("Reserved(=0x00) [8 bits]") a4("ipv4 address [32 bits]"):4 a5("reserved(=0x00) [8 bits]") a6("L4-proto(UDP) [8 bits]") a7("port num [16 bits]"):2
Endpoint Multicast Configuration Load Balancing FindService 0 0 0-1 0-1 OfferService 1-2 0 0-1 0-1 StopOfferService 1-2 0 0-1 0-1 Subcribe Eventgroup 0-2 0 0-1 0-1 StopSubscribe Eventgroup 0-2 0 0-1 0-1 Subscribe EventgroupAck 0 0-1 0-1 0-1 Subscribe EventgroupNack 0 0 0-1 0-1 - Configuration Option: 传输任意配置字符串键值对
- Header:
- 通信过程
- 启动阶段:
- 初始等待阶段(inital wait phase):随机等待时间发送SD报文
- wait for random-delay time in range(INITAL-DELAY-MIN, MAX)
- send message(find service and offer service entries)
- 重复阶段(repetition phase-REPETITIONS_BASE_DELAY = 100ms, REPETITIONS_MAX = 2):重复发送指定次数, 每次延时时间翻倍
- wait 2^0 * 100ms
- send message(find service and offer service entries)
- wait 2^1 * 100ms
- send message(find service and offer service entries)
- 运行阶段(main phase-as long message is active and CYCLIC_OFFER_DELAY is defined):周期发送offer报文
- wait CYCLIC_OFFER_DELAY
- send message (offer service entries)
- 初始等待阶段(inital wait phase):随机等待时间发送SD报文
- 服务应答:
- 收到多播find报文后延迟发送offer报文
- 收到多播offer报文后延迟发送subscribe报文
- 下电: 发送stopOffer报文,删除注册表
- 启动阶段:
- 订阅发布机制(注册/注销)
- 配置参数
Name Description INITAL_DELAY_MIN minimum duration of delay randomly the transmission of a message INITAL_DELAY_MAX maximum duration of delay randomly the transmission of a message REPETITIONS_BASE_DELAY duration of delay for repetition REPETITIIONS_NUM configuration for the maxinum number of repetitions REQUEST_RESPONSE_DELAY the service discovery shall delay answers using this configuration item CYCLIC_OFFER_DELAY interval for cyclic offers in the main phase SD_PORT is a UDP port for SD messagSe(30490 as default) SD_MULTICAST_IP address which shall be used by the SD multicast messages SUBSCRIBE_RETRY_MAX Max counts of retries for subscribe, as long as the Eventgrpup is requested(0 no retry, INF retry forever(as long as the Eventgroup is requested and no SubscribeEventgroupAck/Nack entry was received)) SUBSCRIBE_RETRY_DELAY duration of delay to send consecutive subscribe entries, if a Eventgroup is requested and no SubscribeEventgroupAck/Nack entry was received
module features-Runtime
- COM: SOC通信中间件
- 使用抽象的API与传输协议层绑定(SOMP/IP,IPC)
- SOME/IP:
- demon负责SOME/IP通信和服务发现
- APP通过IPC和daemon交互
- IPC: 本地节点多播监听和发送消息
- 版本控制: 大版本不兼容,小版本向下兼容
- Runtime处理模式:
- 线程驱动: 输入包到达后立即处理
- 轮询: 调用Skeleton::ProcessNextMethodCall()处理
module features-SOME/IP
- 通信
- 使能(默认),daemon处理sockets并路由method, events 和服务发现
- 禁用,daemon仅处理服务发现
- 连接
- 建立条件: proxy创建,或者收到服务
- 保持条件: 进程运行时
- 断开条件: skeleton或者proxy被销毁
- 服务发现
- deamon启动后被动监听
- 进程启动后主动请求
- event配置时间戳,E2E,过载保护
- 发送方: 调用skeleton::send()时依据配置生成
- 接收方: 调用ProxyEvent::update()/ProxyEvent::GetNewSamples()自动检查
- SecOC: FV, 完整性,身份认证