记录在P4中简单的INT遥测中遇到的问题
记录在v1model下进行INT实验遇到的一系列问题
INT数据包结构
eth -> ipv4 -> int_count -> int_headers -> tcp
说明:这里的INTs应该在TCP前面,但是我太懒了,不想重新画
P4中遇到的问题
1、记录INT数量的header:int_count
// int_count结构
header int_count_t {
bit<16> num_switches;
}
int_count的初始化:
// int_count结构
hdr.int_count = {16w0}; // 正确用法
hdr.int_count.num_switches = 16w0; // 初始化会少一个,如下赋值,计算四次,最后结果应该是4,这种写法最后结果是3,原因还不清楚
hdr.int_count.num_switches = hdr.int_count.num_switches+16w1;
2、数据包长度:
只记录int的个数,TCP里面的所有值都不能动,不然经过几个交换机之后,IP头的Total Length会变得很奇怪,比如我遇到本来应该是60的长度,最后获取的结果是1万多,就会造成数据包变成坏包。如下,最开始我每加入一个INT就在IP的totalLen加上5:
hdr.int_headers.push_front(1);
hdr.int_headers[0].setValid();
hdr.int_header[0].id = 1;
...
hdr.ipv4.totalLen = hdr.ipv4.totalLen + 5; //这一步会造成数据包长度check的时候出现问题,即使在最后弹出INT的时候将长度减回去,也会造成数据包的长度问题
3、头部弹出的问题
INT头部弹出:
// 如果是数组
// int_header_t[5] int_headers;
hdr.int_headers.pop_front(5);
// 如果是头部
// int_count_t int_count;
hdr.int_count.setInvalid();
4、头部解析与头部顺序
INT是放在IP头后面,TCP前面,在parse里面这样的顺序解析,在headers的头部结构顺序也应该是这样:
struct headers {
ethernet_t ethernet;
ipv4_t ipv4;
int_count_t int_count;
int_header_t[5] int_headers;
tcp_t tcp;
}
这个顺序严格按照解析时的顺序,不然int header可能会跑到tcp的option里面去。