aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPravin B Shelar <pshelar@nicira.com>2012-11-14 21:10:54 -0800
committerPravin B Shelar <pshelar@nicira.com>2012-11-14 21:24:42 -0800
commit8ac2a21cc8ec518b3359e1803eb3460e4743c59a (patch)
tree641a748d5606f114cb7bef657923e406ae91b5b4
parentd50a5bd434b8b383df883825fcb74a72a5e0a534 (diff)
odp-utils: Print human readable ipv4-tunnel-key flags.
Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
-rw-r--r--lib/odp-util.c43
-rw-r--r--tests/odp.at4
2 files changed, 39 insertions, 8 deletions
diff --git a/lib/odp-util.c b/lib/odp-util.c
index c3745f79..28944a00 100644
--- a/lib/odp-util.c
+++ b/lib/odp-util.c
@@ -700,6 +700,21 @@ ovs_frag_type_to_string(enum ovs_frag_type type)
}
}
+static const char *
+tun_flag_to_string(uint32_t flags)
+{
+ switch (flags) {
+ case OVS_TNL_F_DONT_FRAGMENT:
+ return "df";
+ case OVS_TNL_F_CSUM:
+ return "csum";
+ case OVS_TNL_F_KEY:
+ return "key";
+ default:
+ return NULL;
+ }
+}
+
static void
format_odp_key_attr(const struct nlattr *a, struct ds *ds)
{
@@ -745,12 +760,15 @@ format_odp_key_attr(const struct nlattr *a, struct ds *ds)
case OVS_KEY_ATTR_IPV4_TUNNEL:
ipv4_tun_key = nl_attr_get(a);
- ds_put_format(ds, "(tun_id=0x%"PRIx64",flags=0x%"PRIx32
- ",src="IP_FMT",dst="IP_FMT",tos=0x%"PRIx8",ttl=%"PRIu8")",
- ntohll(ipv4_tun_key->tun_id), ipv4_tun_key->tun_flags,
+ ds_put_format(ds, "(tun_id=0x%"PRIx64",src="IP_FMT",dst="IP_FMT","
+ "tos=0x%"PRIx8",ttl=%"PRIu8",flags",
+ ntohll(ipv4_tun_key->tun_id),
IP_ARGS(&ipv4_tun_key->ipv4_src),
IP_ARGS(&ipv4_tun_key->ipv4_dst),
ipv4_tun_key->ipv4_tos, ipv4_tun_key->ipv4_ttl);
+
+ format_flags(ds, tun_flag_to_string, ipv4_tun_key->tun_flags);
+ ds_put_format(ds, ")");
break;
case OVS_KEY_ATTR_IN_PORT:
@@ -968,21 +986,32 @@ parse_odp_key_attr(const char *s, const struct simap *port_names,
{
char tun_id_s[32];
- unsigned long long int flags;
int tos, ttl;
struct ovs_key_ipv4_tunnel tun_key;
int n = -1;
if (sscanf(s, "ipv4_tunnel(tun_id=%31[x0123456789abcdefABCDEF],"
- "flags=%lli,src="IP_SCAN_FMT",dst="IP_SCAN_FMT
- ",tos=%i,ttl=%i)%n", tun_id_s, &flags,
+ "src="IP_SCAN_FMT",dst="IP_SCAN_FMT
+ ",tos=%i,ttl=%i,flags%n", tun_id_s,
IP_SCAN_ARGS(&tun_key.ipv4_src),
IP_SCAN_ARGS(&tun_key.ipv4_dst), &tos, &ttl,
&n) > 0 && n > 0) {
+ int res;
+
tun_key.tun_id = htonll(strtoull(tun_id_s, NULL, 0));
- tun_key.tun_flags = flags;
tun_key.ipv4_tos = tos;
tun_key.ipv4_ttl = ttl;
+
+ res = parse_flags(&s[n], tun_flag_to_string, &tun_key.tun_flags);
+ if (res < 0) {
+ return res;
+ }
+ n += res;
+ if (s[n] != ')') {
+ return -EINVAL;
+ }
+ n++;
+
memset(&tun_key.pad, 0, sizeof tun_key.pad);
nl_msg_put_unspec(key, OVS_KEY_ATTR_IPV4_TUNNEL, &tun_key,
sizeof tun_key);
diff --git a/tests/odp.at b/tests/odp.at
index 505e4c83..8f5676d6 100644
--- a/tests/odp.at
+++ b/tests/odp.at
@@ -91,7 +91,9 @@ push_vlan(tpid=0x9100,vid=13,pcp=5)
push_vlan(tpid=0x9100,vid=13,pcp=5,cfi=0)
pop_vlan
sample(sample=9.7%,actions(1,2,3,push_vlan(vid=1,pcp=2)))
-set(ipv4_tunnel(tun_id=0xabcdef1234567890,flags=0x0,src=1.1.1.1,dst=2.2.2.2,tos=0x0,ttl=64))
+set(ipv4_tunnel(tun_id=0xabcdef1234567890,src=1.1.1.1,dst=2.2.2.2,tos=0x0,ttl=64,flags(df,csum,key)))
+set(ipv4_tunnel(tun_id=0xabcdef1234567890,src=1.1.1.1,dst=2.2.2.2,tos=0x0,ttl=64,flags(df,csum,key,0x20)))
+set(ipv4_tunnel(tun_id=0xabcdef1234567890,src=1.1.1.1,dst=2.2.2.2,tos=0x0,ttl=64,flags()))
])
AT_CHECK_UNQUOTED([test-odp parse-actions < actions.txt], [0],
[`cat actions.txt`