练习:链路监测
本练习的目的是编写一个P4程序,使主机能够监视网络中所有链路的使用情况。 这个练习建立在基本的IPv4转发练习的基础上,所以在尝试这个练习之前,请确保完成这个练习。 具体地说,我们将修改基本的P4程序来处理源路由探测包,使其能够在每个跳点获取出口链路利用率,并将其交付给主机进行监视。 我们的探测包将包含以下三种报头类型:
// Top-level probe header, indicates how many hops this probe
// packet has traversed so far.
header probe_t {
bit<8> hop_cnt;
}
// The data added to the probe by each switch at each hop.
header probe_data_t {
bit<1> bos;
bit<7> swid;
bit<8> port;
bit<32> byte_cnt;
time_t last_time;
time_t cur_time;
}
// Indicates the egress port the switch should send this probe
// packet out of. There is one of these headers for each hop.
header probe_fwd_t {
bit<8> egress_spec;
}
为了监控链路利用率,我们的交换机将保持
两个寄存器阵列:
- ’ byte_cnt_reg '—计算从端口发送最后一个探测包以来从每个端口发送的字节数。
- ’ last_time_reg '—存储探测包最后一次从每个端口发送出去的时间。