ofp-msgs: New function ofpraw_decode_assert().
authorBen Pfaff <blp@nicira.com>
Tue, 12 Feb 2013 07:37:41 +0000 (23:37 -0800)
committerBen Pfaff <blp@nicira.com>
Tue, 12 Feb 2013 07:52:21 +0000 (23:52 -0800)
This will acquire a caller in an upcoming patch.

Signed-off-by: Ben Pfaff <blp@nicira.com>
lib/ofp-msgs.c
lib/ofp-msgs.h

index 0574228..efc4198 100644 (file)
@@ -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
index 2db4fc9..66ec448 100644 (file)
@@ -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 *);