P4学习:统计功能

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方式,启动失败

扫描二维码关注公众号,回复: 2159980 查看本文章

#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);
}

猜你喜欢

转载自www.cnblogs.com/soul-stone/p/9313218.html