ProtoBuf格式介绍
NexusInfo
NexusInfo主要由tables、actions及type_info组成。
message NexusInfo {
repeated Table tables = 2;
repeated Action actions = 3;
NexusTypeInfo type_info = 200;
}
Table
message Table {
Preamble preamble = 1;
uint32 key_size_bit = 2;
uint32 key_size_byte = 3;
uint32 key_num = 4;
repeated MatchField match_fields = 5;
repeated ActionRef action_refs = 6;
ActionRef initial_default_action = 8;
int64 entry_num = 11;
string scope = 15;
string table_type = 16;
int32 aging_time = 18;
string dpdk_enum = 19;
}
关键字说明如表1所示。
关键字 |
说明 |
|---|---|
preamble |
包含了id、name和alias。
|
key_size_bit |
table size in bit,数值直接加总。 |
key_size_byte |
table size in byte,计算公式后续展开。 |
key_num |
key的数量。 |
match_fields |
一个MatchField结构的数组。 |
action_refs |
一个ActionRef结构的数组。 |
initial_default_action |
一个ActionRef结构的数组,包含了action ID和annotations。 |
entry_num |
entry的数量,预设为1024。 |
scope |
table所属的control块名字。 |
table_type |
表格类型。
|
aging_time |
老化时间。为0即内存会马上cacheout,为N则N秒后会cacheout,预设为30秒。 |
dpdk_enum |
与DPDK生成的枚举名称一致。 |
MatchField
message MatchField {
uint32 index = 1;
string alias = 2;
int32 size_bit = 5;
int32 size_byte = 6;
enum MatchType {
UNSPECIFIED = 0;
EXACT = 2;
LPM = 3;
TERNARY = 4;
RANGE = 5;
OPTIONAL = 6;
}
MatchType match_type = 8;
string typed_name = 11;
string dpdk_enum = 14;
string name = 15;
uint32 struct_id = 16;
}
关键字说明如表2所示。
关键字 |
说明 |
|---|---|
index |
MatchField的索引,由1开始递增。 |
alias |
格式为<variableName>.<fieldName>*,如hdr.ipv6,与用户撰写的代码一致。 |
size_bit |
bit的大小,与微码后端数值对齐。 |
size_byte |
byte的大小,与微码后端数值对齐。 |
match_type |
匹配类型,只能为EXACT等枚举值。 |
typed_name |
格式为<variableType>.<fieldName>*,如headers.ipv6,字段名字会被保留。 |
dpdk_enum |
与DPDK生成的枚举名称一致。 |
name |
格式为<controlScopeName>.<tableName>.<alias>,名字唯一,如MyIngress.MyTable.hdr.ipv6。 |
struct_id |
其对应的数据结构类型ID,由0x2001开始递增。 |
Action
message Action {
Preamble preamble = 1;
message Param {
uint32 id = 1;
string name = 2;
repeated string annotations = 3;
NexusNamedType type_name = 6;
}
repeated Param params = 2;
repeated string annotations = 3;
string dpdk_enum = 4;
uint32 size_byte = 5;
}
关键字说明如表3所示。
关键字 |
说明 |
|---|---|
preamble |
包含了id、name和alias。
|
params |
包含了id、name、annotations和type_name。
|
annotations |
与语言前端一致,当中有如"@pre"、"@dpdk"等注解,若action为miss action,则会额外有"defaultonly"的annotation。 |
dpdk_enum |
与dpdk生成的枚举名称一致。 |
size_byte |
为每个入参的字节大小总和。 |
ActionRef
message ActionRef {
uint32 id = 1;
string name = 2;
string dpdk_enum = 3;
uint32 size_byte = 8;
}
关键字说明如表4所示。
TypeInfo
message NexusTypeInfo {
map<string, NexusStructTypeSpec> struct_likes = 3;
repeated string struct_like_order = 4;
map<int32, ConstantValueArray> constants = 5;
repeated int32 constant_order = 6;
}
关键字说明如表5所示。
NexusStructTypeSpec
message NexusHeaderTypeSpec {
int32 size = 2;
message Member {
string name = 1;
int32 size = 3;
NexusDataTypeSpec type_spec = 4;
}
repeated Member members = 3;
repeated string annotations = 4;
}
关键字说明如表6所示。
ConstantValueArray
message ConstantValueArray {
message ConstantValue {
string value = 1;
}
repeated ConstantValue const_value = 1;
}
关键字说明如表7所示。