[ovs-dev] [packet_in 03/13] flow: Improve flow_format() output.

Ethan Jackson ethan at nicira.com
Thu Dec 29 01:52:30 UTC 2011


I find this significantly easier to read.
---
 lib/flow.c         |   32 ++++++++++++++++----------------
 tests/ofp-print.at |    2 +-
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/lib/flow.c b/lib/flow.c
index fa7ae4f..5d18212 100644
--- a/lib/flow.c
+++ b/lib/flow.c
@@ -518,41 +518,41 @@ flow_to_string(const struct flow *flow)
 void
 flow_format(struct ds *ds, const struct flow *flow)
 {
-    ds_put_format(ds, "priority%"PRIu32
-                      ":tunnel%#"PRIx64
-                      ":in_port%04"PRIx16,
+    ds_put_format(ds, "priority:%"PRIu32
+                      ",tunnel:%#"PRIx64
+                      ",in_port:%04"PRIx16,
                       flow->skb_priority,
                       ntohll(flow->tun_id),
                       flow->in_port);
 
-    ds_put_format(ds, ":tci(");
+    ds_put_format(ds, ",tci(");
     if (flow->vlan_tci) {
-        ds_put_format(ds, "vlan%"PRIu16",pcp%d",
+        ds_put_format(ds, "vlan:%"PRIu16",pcp:%d",
                       vlan_tci_to_vid(flow->vlan_tci),
                       vlan_tci_to_pcp(flow->vlan_tci));
     } else {
         ds_put_char(ds, '0');
     }
-    ds_put_format(ds, ") mac"ETH_ADDR_FMT"->"ETH_ADDR_FMT
-                      " type%04"PRIx16,
+    ds_put_format(ds, ") mac("ETH_ADDR_FMT"->"ETH_ADDR_FMT
+                      ") type:%04"PRIx16,
                   ETH_ADDR_ARGS(flow->dl_src),
                   ETH_ADDR_ARGS(flow->dl_dst),
                   ntohs(flow->dl_type));
 
     if (flow->dl_type == htons(ETH_TYPE_IPV6)) {
-        ds_put_format(ds, " label%#"PRIx32" proto%"PRIu8" tos%#"PRIx8
-                          " ttl%"PRIu8" ipv6",
+        ds_put_format(ds, " label:%#"PRIx32" proto:%"PRIu8" tos:%#"PRIx8
+                          " ttl:%"PRIu8" ipv6(",
                       ntohl(flow->ipv6_label), flow->nw_proto,
                       flow->nw_tos, flow->nw_ttl);
         print_ipv6_addr(ds, &flow->ipv6_src);
         ds_put_cstr(ds, "->");
         print_ipv6_addr(ds, &flow->ipv6_dst);
-
+        ds_put_char(ds, ')');
     } else {
-        ds_put_format(ds, " proto%"PRIu8" tos%#"PRIx8" ttl%"PRIu8
-                          " ip"IP_FMT"->"IP_FMT,
-                      flow->nw_proto, flow->nw_tos, flow->nw_ttl,
-                      IP_ARGS(&flow->nw_src), IP_ARGS(&flow->nw_dst));
+        ds_put_format(ds, " proto:%"PRIu8" tos:%#"PRIx8" ttl:%"PRIu8
+                          " ip("IP_FMT"->"IP_FMT")",
+                          flow->nw_proto, flow->nw_tos, flow->nw_ttl,
+                          IP_ARGS(&flow->nw_src), IP_ARGS(&flow->nw_dst));
     }
     if (flow->nw_frag) {
         ds_put_format(ds, " frag(%s)",
@@ -561,11 +561,11 @@ flow_format(struct ds *ds, const struct flow *flow)
                       ? "later" : "<error>");
     }
     if (flow->tp_src || flow->tp_dst) {
-        ds_put_format(ds, " port%"PRIu16"->%"PRIu16,
+        ds_put_format(ds, " port(%"PRIu16"->%"PRIu16")",
                 ntohs(flow->tp_src), ntohs(flow->tp_dst));
     }
     if (!eth_addr_is_zero(flow->arp_sha) || !eth_addr_is_zero(flow->arp_tha)) {
-        ds_put_format(ds, " arp_ha"ETH_ADDR_FMT"->"ETH_ADDR_FMT,
+        ds_put_format(ds, " arp_ha("ETH_ADDR_FMT"->"ETH_ADDR_FMT")",
                 ETH_ADDR_ARGS(flow->arp_sha),
                 ETH_ADDR_ARGS(flow->arp_tha));
     }
diff --git a/tests/ofp-print.at b/tests/ofp-print.at
index df5dc9b..09b785b 100644
--- a/tests/ofp-print.at
+++ b/tests/ofp-print.at
@@ -237,7 +237,7 @@ dnl The tcpdump output format differs slightly from one version to another,
 dnl so trim off the end of the line where differences appear.
 AT_CHECK([sed 's/\(length 60:\).*/\1 .../' stdout], [0], [dnl
 OFPT_PACKET_IN (xid=0x0): total_len=60 in_port=3 data_len=60 buffer=0x00000111
-priority0:tunnel0:in_port0003:tci(0) mac50:54:00:00:00:05->50:54:00:00:00:06 type0800 proto6 tos0 ttl64 ip192.168.0.1->192.168.0.2 port10031->0
+priority:0,tunnel:0,in_port:0003,tci(0) mac(50:54:00:00:00:05->50:54:00:00:00:06) type:0800 proto:6 tos:0 ttl:64 ip(192.168.0.1->192.168.0.2) port(10031->0)
 50:54:00:00:00:05 > 50:54:00:00:00:06, ethertype IPv4 (0x0800), length 60: ...
 ])
 AT_CLEANUP
-- 
1.7.7.1




More information about the dev mailing list