协议栈
具有如下五层:
TCP传输层:TCP提供面向连接的、可靠的数据链路。
TLS(Transport Layer Security,传输层安全)传输层:该层是可选的,设备和采集器可以基于TLS协议实现安全通信。
HTTP 2.0应用层:gRPC承载在HTTP 2.0协议上,利用了该协议的头部压缩、多路复用、流量控制等增强特性。
gRPC层:定义了RPC的协议交互格式。公共RPC方法定义在公共proto文件中,例如huawei-gRPC-dialout.proto。
数据模型层:用于承载编码后的业务数据。业务数据的编码格式包括:GPB,XML,JSON等。

服务模式
gRPC支持的四种服务(通过stream区分)
简单模式:一问一答的简单交互
例如:rpc Cancel(CancelArgs) returns(CancelReply) {};
服务端流模式:客户端发送一个请求,服务端不断返回数据给客户端
例如:rpc Subscribe(SubsArgs) returns(stream SubsReply) {};
客户端流模式:客户端不断向服务端推送数据,并等待服务端返回应答
例如:rpc LotsOfGreetings(stream HelloRequest) returns (HelloResponse) {};
双向流模式:客户端和服务端都可以发送一系列消息
例如:rpc dataPublish(stream serviceArgs) returns(stream serviceArgs) {};
GPB,Google Protocol Buffers
GPB编码提供了一种灵活、高效、自动序列化结构数据的机制。GPB与XML、JSON编码类似,不同之处在于GPB是一种二进制编码,性能更高。
因为Protocol Buffers是以二进制的形式进行传输的,字节数较少,传输效率相比XML、JSON有天然的优势,而数据采集效率是Telemetry考虑的重点之一。
更多学习请参考 https://developers.google.com/protocol-buffers/?hl=zh-CN
GPB编码解析前
{
1:"HUAWEI"
2:"s4"
3:"huawei-ifm:ifm/interfaces/interface"
4:46
5:1515727243419
6:1515727243514
7{
1[{
1: 1515727243419
2 {
5{
1[{
5:1
16:2
25:"Eth-Trunk1"
}]
}
}
}]
}
}
huawei-telemetry.proto
syntax = "proto3";
package telemetry;
message Telemetry {
string node_id_str = 1;
string subscription_id_str = 2;
string sensor_path = 3;
string proto_path = 13;
uint64 collection_id = 4;
uint64 collection_start_time = 5;
uint64 msg_timestamp = 6;
TelemetryGPBTable data_gpb = 7;
uint64 collection_end_time = 8;
uint32 current_period = 9;
string except_desc = 10;
string product_name = 11;
Encoding encoding =12;
string data_str = 14;
}
GPB编码解析后
{
"node_id_str":"HUAWEI",
"subscription_id_str":"s4",
"sensor_path":"huawei-ifm:ifm/interfaces/interface",
"collection_id":46,
"collection_start_time":"YY/MM/DD 11:20:43.419",
"msg_timestamp":"YY/MM/DD 11:20:43.514",
"data_gpb":{
"row":[{
"timestamp":“YY/MM/DD 11:20:43.419",
"content":{
"interfaces":{
"interface":[{
"ifAdminStatus":1,
"ifIndex":2,
"ifName":"Eth-Trunk1"
}]
}
}
}]
}