P4学习:统计功能

杀马特。学长 韩版系。学妹 提交于 2020-01-19 21:31:35

https://www.cnblogs.com/soul-stone/p/9029480.html

基于behavioral-model的simple_route测试统计功能:

 

1、直接关联统计,这种方式可以工作:

// this counter can work!!
counter count_lpm_match {
type : packets_and_bytes;
direct : ipv4_lpm;
}

table ipv4_lpm {
reads {
ipv4.dstAddr : lpm;
}
actions {
set_nhop;
_drop;
}
size: 1024;
}

action set_dmac(dmac) {
modify_field(ethernet.dstAddr, dmac);
}

// this counter can work!!
counter count_pkt_fwd {
type : packets_and_bytes;
direct : fwd_set_dmac;
}

table fwd_set_dmac {
reads {
routing_metadata.nhop_ipv4 : exact;
}
actions {
set_dmac;
_drop;
}
size: 512;
}

 

2、table方式,启动失败

#define MAX_PORTS 256

counter ingress_port_counter {
type: packets_and_bytes; // bmv2 always counts both bytes and packets
instance_count: MAX_PORTS;
}

action update_counters() {

count(ingress_port_counter, 0);
//count(ingress_port_counter, standard_metadata.ingress_port);
//count(egress_port_counter, standard_metadata.egress_spec);
}

table do_process_counters {
actions {
update_counters;
}
}

control ingress {
if(valid(ipv4) and ipv4.ttl > 0) {
apply(ipv4_lpm);
apply(fwd_set_dmac);
//apply(do_process_counters);
}
}

 

3、调用方式,启动失败

// CANNOT WORK
action set_nhop(nhop_ipv4, port) {
modify_field(routing_metadata.nhop_ipv4, nhop_ipv4);
modify_field(standard_metadata.egress_spec, port);
modify_field(ipv4.ttl, ipv4.ttl - 1);
//count(ingress_port_counter, port);
}

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!