New function make_packet_out(), and reimplement helpers in terms of it.
authorBen Pfaff <blp@nicira.com>
Thu, 29 Jan 2009 00:39:16 +0000 (16:39 -0800)
committerBen Pfaff <blp@nicira.com>
Mon, 2 Mar 2009 20:51:59 +0000 (12:51 -0800)
lib/vconn.c
lib/vconn.h

index c9269b5fc4d59b71659dd91e15c49c99d203b539..bc01d4ac1328cc34980bbb07339ec7bd78246ec6 100644 (file)
@@ -920,54 +920,52 @@ make_add_simple_flow(const struct flow *flow,
 }
 
 struct ofpbuf *
-make_unbuffered_packet_out(const struct ofpbuf *packet,
-                           uint16_t in_port, uint16_t out_port)
+make_packet_out(const struct ofpbuf *packet, uint32_t buffer_id,
+                uint16_t in_port,
+                const struct ofp_action_header *actions, size_t n_actions)
 {
+    size_t actions_len = n_actions * sizeof *actions;
     struct ofp_packet_out *opo;
-    struct ofp_action_output *oao;
-    size_t size = sizeof *opo + sizeof *oao;
-    struct ofpbuf *out = ofpbuf_new(size + packet->size);
+    size_t size = sizeof *opo + actions_len + (packet ? packet->size : 0);
+    struct ofpbuf *out = ofpbuf_new(size);
 
-    opo = ofpbuf_put_zeros(out, size);
+    opo = ofpbuf_put_uninit(out, sizeof *opo);
     opo->header.version = OFP_VERSION;
     opo->header.type = OFPT_PACKET_OUT;
-    opo->buffer_id = htonl(UINT32_MAX);
+    opo->header.length = htons(size);
+    opo->header.xid = htonl(0);
+    opo->buffer_id = htonl(buffer_id);
     opo->in_port = htons(in_port);
-
-    oao = (struct ofp_action_output *)&opo->actions[0];
-    oao->type = htons(OFPAT_OUTPUT);
-    oao->len = htons(sizeof *oao);
-    oao->port = htons(out_port);
-
-    opo->actions_len = htons(sizeof *oao);
-
-    ofpbuf_put(out, packet->data, packet->size);
-    update_openflow_length(out);
+    opo->actions_len = htons(actions_len);
+    ofpbuf_put(out, actions, actions_len);
+    if (packet) {
+        ofpbuf_put(out, packet->data, packet->size);
+    }
     return out;
 }
 
+struct ofpbuf *
+make_unbuffered_packet_out(const struct ofpbuf *packet,
+                           uint16_t in_port, uint16_t out_port)
+{
+    struct ofp_action_output action;
+    action.type = htons(OFPAT_OUTPUT);
+    action.len = htons(sizeof action);
+    action.port = htons(out_port);
+    return make_packet_out(packet, UINT32_MAX, in_port,
+                           (struct ofp_action_header *) &action, 1);
+}
+
 struct ofpbuf *
 make_buffered_packet_out(uint32_t buffer_id,
                          uint16_t in_port, uint16_t out_port)
 {
-    struct ofp_packet_out *opo;
-    struct ofp_action_output *oao;
-    size_t size = sizeof *opo + sizeof *oao;
-    struct ofpbuf *out = ofpbuf_new(size);
-    opo = ofpbuf_put_zeros(out, size);
-    opo->header.version = OFP_VERSION;
-    opo->header.type = OFPT_PACKET_OUT;
-    opo->header.length = htons(size);
-    opo->buffer_id = htonl(buffer_id);
-    opo->in_port = htons(in_port);
-
-    oao = (struct ofp_action_output *)&opo->actions[0];
-    oao->type = htons(OFPAT_OUTPUT);
-    oao->len = htons(sizeof *oao);
-    oao->port = htons(out_port);
-
-    opo->actions_len = htons(sizeof *oao);
-    return out;
+    struct ofp_action_output action;
+    action.type = htons(OFPAT_OUTPUT);
+    action.len = htons(sizeof action);
+    action.port = htons(out_port);
+    return make_packet_out(NULL, buffer_id, in_port,
+                           (struct ofp_action_header *) &action, 1);
 }
 
 /* Creates and returns an OFPT_ECHO_REQUEST message with an empty payload. */
index fd3847521c9f6c5ab5229fb86509d05fc009a6eb..7916f86dfd711a150eafc34f7a5cdcc339caa1d0 100644 (file)
@@ -40,6 +40,7 @@
 
 struct ofpbuf;
 struct flow;
+struct ofp_action_header;
 struct ofp_header;
 struct ofp_stats_reply;
 struct pvconn;
@@ -95,6 +96,10 @@ struct ofpbuf *make_del_flow(const struct flow *);
 struct ofpbuf *make_add_simple_flow(const struct flow *,
                                     uint32_t buffer_id, uint16_t out_port,
                                     uint16_t max_idle);
+struct ofpbuf *make_packet_out(const struct ofpbuf *packet, uint32_t buffer_id,
+                               uint16_t in_port,
+                               const struct ofp_action_header *,
+                               size_t n_actions);
 struct ofpbuf *make_buffered_packet_out(uint32_t buffer_id,
                                         uint16_t in_port, uint16_t out_port);
 struct ofpbuf *make_unbuffered_packet_out(const struct ofpbuf *packet,