An upcoming commit will make use of this.

Signed-off-by: Ben Pfaff <b...@nicira.com>
---
 build-aux/extract-ofp-msgs | 9 +++++++++
 lib/ofp-msgs.c             | 9 ++++++++-
 lib/ofp-msgs.h             | 5 ++++-
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/build-aux/extract-ofp-msgs b/build-aux/extract-ofp-msgs
index 0ccd64e..b00039d 100755
--- a/build-aux/extract-ofp-msgs
+++ b/build-aux/extract-ofp-msgs
@@ -246,6 +246,7 @@ def extract_ofp_msgs(output_file_name):
         if re.match('enum ofptype', line):
             break
 
+    all_types = []
     while True:
         get_line()
         if re.match(r'\s*/?\*', line) or line.isspace():
@@ -280,6 +281,8 @@ def extract_ofp_msgs(output_file_name):
                       % (raw, all_raws[raw]["ofptype"]))
             all_raws[raw]["ofptype"] = ofptype
 
+        all_types.append(all_raws[raws[0]]["human_name"])
+
     input_file.close()
 
     if n_errors:
@@ -346,6 +349,12 @@ def extract_ofp_msgs(output_file_name):
                               % r["human_name"])
     output.append("};")
 
+    output.append("");
+    output.append("static const char *type_names[] = {");
+    for t in all_types:
+        output.append("    \"%s\"," % t)
+    output.append("};")
+
     if n_errors:
         sys.exit(1)
 
diff --git a/lib/ofp-msgs.c b/lib/ofp-msgs.c
index 4d14ff9..3a120e2 100644
--- a/lib/ofp-msgs.c
+++ b/lib/ofp-msgs.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, 2014 Nicira, Inc.
+ * Copyright (c) 2012, 2013, 2014, 2015 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -824,6 +824,13 @@ ofptype_from_ofpraw(enum ofpraw raw)
 {
     return raw_info_get(raw)->type;
 }
+
+const char *
+ofptype_get_name(enum ofptype type)
+{
+    ovs_assert(type < ARRAY_SIZE(type_names));
+    return type_names[type];
+}
 
 /* Updates the 'length' field of the OpenFlow message in 'buf' to
  * 'buf->size'. */
diff --git a/lib/ofp-msgs.h b/lib/ofp-msgs.h
index 29729c0..3d9fedf 100644
--- a/lib/ofp-msgs.h
+++ b/lib/ofp-msgs.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, 2014 Nicira, Inc.
+ * Copyright (c) 2012, 2013, 2014, 2015 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -653,6 +653,9 @@ enum ofptype {
 enum ofperr ofptype_decode(enum ofptype *, const struct ofp_header *);
 enum ofperr ofptype_pull(enum ofptype *, struct ofpbuf *);
 enum ofptype ofptype_from_ofpraw(enum ofpraw);
+
+/* Information about OFTYPE_* values. */
+const char *ofptype_get_name(enum ofptype);
 
 /* OpenFlow message properties. */
 void ofpmsg_update_length(struct ofpbuf *);
-- 
2.1.3

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to