diff options
author | zhaozhanxu <zhaozhanxu@163.com> | 2019-12-05 14:26:25 +0800 |
---|---|---|
committer | Simon Horman <simon.horman@netronome.com> | 2019-12-06 10:57:16 +0100 |
commit | 164413156cf94d0f4dd1971cf0cc820f8b86055b (patch) | |
tree | 3c4147b854e9cbfa15710a349cb37a7924affe35 /ofproto/ofproto.c | |
parent | 3843208ee019b8559dc02a01039b8d43cc4dac0b (diff) | |
download | openvswitch-164413156cf94d0f4dd1971cf0cc820f8b86055b.tar.gz |
Add offload packets statistics
Add argument '--offload-stats' for command ovs-appctl bridge/dump-flows
to display the offloaded packets statistics.
The commands display as below:
orignal command:
ovs-appctl bridge/dump-flows br0
duration=574s, n_packets=1152, n_bytes=110768, priority=0,actions=NORMAL
table_id=254, duration=574s, n_packets=0, n_bytes=0, priority=2,recirc_id=0,actions=drop
table_id=254, duration=574s, n_packets=0, n_bytes=0, priority=0,reg0=0x1,actions=controller(reason=)
table_id=254, duration=574s, n_packets=0, n_bytes=0, priority=0,reg0=0x2,actions=drop
table_id=254, duration=574s, n_packets=0, n_bytes=0, priority=0,reg0=0x3,actions=drop
new command with argument '--offload-stats'
Notice: 'n_offload_packets' are a subset of n_packets and 'n_offload_bytes' are
a subset of n_bytes.
ovs-appctl bridge/dump-flows --offload-stats br0
duration=582s, n_packets=1152, n_bytes=110768, n_offload_packets=1107, n_offload_bytes=107992, priority=0,actions=NORMAL
table_id=254, duration=582s, n_packets=0, n_bytes=0, n_offload_packets=0, n_offload_bytes=0, priority=2,recirc_id=0,actions=drop
table_id=254, duration=582s, n_packets=0, n_bytes=0, n_offload_packets=0, n_offload_bytes=0, priority=0,reg0=0x1,actions=controller(reason=)
table_id=254, duration=582s, n_packets=0, n_bytes=0, n_offload_packets=0, n_offload_bytes=0, priority=0,reg0=0x2,actions=drop
table_id=254, duration=582s, n_packets=0, n_bytes=0, n_offload_packets=0, n_offload_bytes=0, priority=0,reg0=0x3,actions=drop
Signed-off-by: zhaozhanxu <zhaozhanxu@163.com>
Signed-off-by: Simon Horman <simon.horman@netronome.com>
Diffstat (limited to 'ofproto/ofproto.c')
-rw-r--r-- | ofproto/ofproto.c | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 5795467c0..08830d837 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -4669,6 +4669,7 @@ handle_flow_stats_request(struct ofconn *ofconn, RULE_COLLECTION_FOR_EACH (rule, &rules) { long long int now = time_msec(); struct ofputil_flow_stats fs; + struct pkt_stats stats; long long int created, used, modified; const struct rule_actions *actions; enum ofputil_flow_mod_flags flags; @@ -4684,8 +4685,9 @@ handle_flow_stats_request(struct ofconn *ofconn, flags = rule->flags; ovs_mutex_unlock(&rule->mutex); - ofproto->ofproto_class->rule_get_stats(rule, &fs.packet_count, - &fs.byte_count, &used); + ofproto->ofproto_class->rule_get_stats(rule, &stats, &used); + fs.packet_count = stats.n_packets; + fs.byte_count = stats.n_bytes; minimatch_expand(&rule->cr.match, &fs.match); fs.table_id = rule->table_id; @@ -4710,14 +4712,14 @@ handle_flow_stats_request(struct ofconn *ofconn, } static void -flow_stats_ds(struct ofproto *ofproto, struct rule *rule, struct ds *results) +flow_stats_ds(struct ofproto *ofproto, struct rule *rule, struct ds *results, + bool offload_stats) { - uint64_t packet_count, byte_count; + struct pkt_stats stats; const struct rule_actions *actions; long long int created, used; - rule->ofproto->ofproto_class->rule_get_stats(rule, &packet_count, - &byte_count, &used); + rule->ofproto->ofproto_class->rule_get_stats(rule, &stats, &used); ovs_mutex_lock(&rule->mutex); actions = rule_get_actions(rule); @@ -4728,8 +4730,14 @@ flow_stats_ds(struct ofproto *ofproto, struct rule *rule, struct ds *results) ds_put_format(results, "table_id=%"PRIu8", ", rule->table_id); } ds_put_format(results, "duration=%llds, ", (time_msec() - created) / 1000); - ds_put_format(results, "n_packets=%"PRIu64", ", packet_count); - ds_put_format(results, "n_bytes=%"PRIu64", ", byte_count); + ds_put_format(results, "n_packets=%"PRIu64", ", stats.n_packets); + ds_put_format(results, "n_bytes=%"PRIu64", ", stats.n_bytes); + if (offload_stats) { + ds_put_format(results, "n_offload_packets=%"PRIu64", ", + stats.n_offload_packets); + ds_put_format(results, "n_offload_bytes=%"PRIu64", ", + stats.n_offload_bytes); + } cls_rule_format(&rule->cr, ofproto_get_tun_tab(ofproto), NULL, results); ds_put_char(results, ','); @@ -4743,7 +4751,8 @@ flow_stats_ds(struct ofproto *ofproto, struct rule *rule, struct ds *results) /* Adds a pretty-printed description of all flows to 'results', including * hidden flows (e.g., set up by in-band control). */ void -ofproto_get_all_flows(struct ofproto *p, struct ds *results) +ofproto_get_all_flows(struct ofproto *p, struct ds *results, + bool offload_stats) { struct oftable *table; @@ -4751,7 +4760,7 @@ ofproto_get_all_flows(struct ofproto *p, struct ds *results) struct rule *rule; CLS_FOR_EACH (rule, cr, &table->cls) { - flow_stats_ds(p, rule, results); + flow_stats_ds(p, rule, results, offload_stats); } } } @@ -4839,23 +4848,21 @@ handle_aggregate_stats_request(struct ofconn *ofconn, struct rule *rule; RULE_COLLECTION_FOR_EACH (rule, &rules) { - uint64_t packet_count; - uint64_t byte_count; + struct pkt_stats pkt_stats; long long int used; - ofproto->ofproto_class->rule_get_stats(rule, &packet_count, - &byte_count, &used); + ofproto->ofproto_class->rule_get_stats(rule, &pkt_stats, &used); - if (packet_count == UINT64_MAX) { + if (pkt_stats.n_packets == UINT64_MAX) { unknown_packets = true; } else { - stats.packet_count += packet_count; + stats.packet_count += pkt_stats.n_packets; } - if (byte_count == UINT64_MAX) { + if (pkt_stats.n_bytes == UINT64_MAX) { unknown_bytes = true; } else { - stats.byte_count += byte_count; + stats.byte_count += pkt_stats.n_bytes; } stats.flow_count++; @@ -6046,6 +6053,7 @@ ofproto_rule_send_removed(struct rule *rule) { struct ofputil_flow_removed fr; long long int used; + struct pkt_stats stats; minimatch_expand(&rule->cr.match, &fr.match); fr.priority = rule->cr.priority; @@ -6068,8 +6076,9 @@ ofproto_rule_send_removed(struct rule *rule) fr.idle_timeout = rule->idle_timeout; fr.hard_timeout = rule->hard_timeout; ovs_mutex_unlock(&rule->mutex); - rule->ofproto->ofproto_class->rule_get_stats(rule, &fr.packet_count, - &fr.byte_count, &used); + rule->ofproto->ofproto_class->rule_get_stats(rule, &stats, &used); + fr.packet_count += stats.n_packets; + fr.byte_count += stats.n_bytes; connmgr_send_flow_removed(connmgr, &fr); ovs_mutex_unlock(&ofproto_mutex); } @@ -8886,11 +8895,11 @@ rule_eviction_priority(struct ofproto *ofproto, struct rule *rule) expiration = modified + rule->hard_timeout * 1000; } if (rule->idle_timeout) { - uint64_t packets, bytes; + struct pkt_stats stats; long long int used; long long int idle_expiration; - ofproto->ofproto_class->rule_get_stats(rule, &packets, &bytes, &used); + ofproto->ofproto_class->rule_get_stats(rule, &stats, &used); idle_expiration = used + rule->idle_timeout * 1000; expiration = MIN(expiration, idle_expiration); } |