[ovs-dev] [ext-272 2/4] ofp-msgs: New function ofpraw_decode_assert().

Ben Pfaff blp at nicira.com
Tue Feb 12 08:03:59 UTC 2013


This will acquire a caller in an upcoming patch.

Signed-off-by: Ben Pfaff <blp at nicira.com>
---
 lib/ofp-msgs.c |   17 +++++++++++++++++
 lib/ofp-msgs.h |    3 ++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/lib/ofp-msgs.c b/lib/ofp-msgs.c
index 0574228..efc4198 100644
--- a/lib/ofp-msgs.c
+++ b/lib/ofp-msgs.c
@@ -320,6 +320,23 @@ ofpraw_decode(enum ofpraw *raw, const struct ofp_header *oh)
     return ofpraw_pull(raw, &msg);
 }
 
+/* Does the same job as ofpraw_decode(), except that it assert-fails if
+ * ofpraw_decode() would have reported an error.  Thus, it's able to use the
+ * return value for the OFPRAW_* message type instead of an error code.
+ *
+ * (It only makes sense to use this function if you previously called
+ * ofpraw_decode() on the message and thus know that it's OK.) */
+enum ofpraw
+ofpraw_decode_assert(const struct ofp_header *oh)
+{
+    enum ofperr error;
+    enum ofpraw raw;
+
+    error = ofpraw_decode(&raw, oh);
+    ovs_assert(!error);
+    return raw;
+}
+
 /* Determines the OFPRAW_* type of the OpenFlow message in 'msg', which starts
  * at 'msg->data' and has length 'msg->size' bytes.  On success, returns 0 and
  * stores the type into '*rawp'.  On failure, returns an OFPERR_* error code
diff --git a/lib/ofp-msgs.h b/lib/ofp-msgs.h
index 2db4fc9..66ec448 100644
--- a/lib/ofp-msgs.h
+++ b/lib/ofp-msgs.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012 Nicira, Inc.
+ * Copyright (c) 2012, 2013 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -387,6 +387,7 @@ enum ofpraw {
 
 /* Decoding messages into OFPRAW_* values. */
 enum ofperr ofpraw_decode(enum ofpraw *, const struct ofp_header *);
+enum ofpraw ofpraw_decode_assert(const struct ofp_header *);
 enum ofperr ofpraw_pull(enum ofpraw *, struct ofpbuf *);
 enum ofpraw ofpraw_pull_assert(struct ofpbuf *);
 
-- 
1.7.10.4




More information about the dev mailing list