码迷,mamicode.com
首页 > 其他好文 > 详细

P4学习:统计功能

时间:2018-07-15 13:02:33      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:gre   mode   tab   .com   nts   bytes   field   simple   process   

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

 

P4学习:统计功能

标签:gre   mode   tab   .com   nts   bytes   field   simple   process   

原文地址:https://www.cnblogs.com/soul-stone/p/9313218.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!