[ovs-dev] [PATCH 1/4] ofproto: Further factor out handling of port requests

Simon Horman horms at verge.net.au
Tue May 27 09:05:36 UTC 2014


handle_port_request() already provides common code to handle
both port desc and port stats request messages once they have been decoded
by using a callback.

This patch extends this common handling code to also perform decoding
of both port desc and port stats request messages by using one more callback.

Signed-off-by: Simon Horman <horms at verge.net.au>
---
 ofproto/ofproto.c | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 63f65c3..e3e1db9 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -3194,9 +3194,9 @@ append_port_stat(struct ofport *port, struct list *replies)
 }
 
 static void
-handle_port_request(struct ofconn *ofconn,
-                    const struct ofp_header *request, ofp_port_t port_no,
-                    void (*cb)(struct ofport *, struct list *replies))
+handle_port_request__(struct ofconn *ofconn,
+                      const struct ofp_header *request, ofp_port_t port_no,
+                      void (*cb)(struct ofport *, struct list *replies))
 {
     struct ofproto *ofproto = ofconn_get_ofproto(ofconn);
     struct ofport *port;
@@ -3218,19 +3218,31 @@ handle_port_request(struct ofconn *ofconn,
 }
 
 static enum ofperr
-handle_port_stats_request(struct ofconn *ofconn,
-                          const struct ofp_header *request)
+handle_port_request(struct ofconn *ofconn,
+                    const struct ofp_header *request,
+                    enum ofperr (*decode)(const struct ofp_header *,
+                                          ofp_port_t *),
+                    void (*append)(struct ofport *, struct list *replies))
 {
     ofp_port_t port_no;
     enum ofperr error;
 
-    error = ofputil_decode_port_stats_request(request, &port_no);
+    error = decode(request, &port_no);
     if (!error) {
-        handle_port_request(ofconn, request, port_no, append_port_stat);
+        handle_port_request__(ofconn, request, port_no, append);
     }
     return error;
 }
 
+static enum ofperr
+handle_port_stats_request(struct ofconn *ofconn,
+                          const struct ofp_header *request)
+{
+    return handle_port_request(ofconn, request,
+                               ofputil_decode_port_stats_request,
+                               append_port_stat);
+}
+
 static void
 append_port_desc(struct ofport *port, struct list *replies)
 {
@@ -3241,14 +3253,9 @@ static enum ofperr
 handle_port_desc_stats_request(struct ofconn *ofconn,
                                const struct ofp_header *request)
 {
-    ofp_port_t port_no;
-    enum ofperr error;
-
-    error = ofputil_decode_port_desc_stats_request(request, &port_no);
-    if (!error) {
-        handle_port_request(ofconn, request, port_no, append_port_desc);
-    }
-    return error;
+    return handle_port_request(ofconn, request,
+                               ofputil_decode_port_desc_stats_request,
+                               append_port_desc);
 }
 
 static uint32_t
-- 
1.8.5.2




More information about the dev mailing list