]> git.proxmox.com Git - mirror_ovs.git/commitdiff
ofp-util: Add flow metadata to ofputil_packet_out
authorYi-Hung Wei <yihung.wei@gmail.com>
Mon, 15 May 2017 17:04:55 +0000 (10:04 -0700)
committerBen Pfaff <blp@ovn.org>
Wed, 31 May 2017 21:54:09 +0000 (14:54 -0700)
This patch adds flow metadata to ofputil_packet_out. It does not make any
functional change. The flow metadata will be useful to support new packet-out
message format in OpenFlow 1.5.

Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
include/openvswitch/ofp-util.h
lib/learning-switch.c
lib/ofp-parse.c
lib/ofp-print.c
lib/ofp-util.c
ofproto/ofproto.c
ovn/controller/ofctrl.c
ovn/controller/pinctrl.c
utilities/ovs-ofctl.c

index f37d181599b2489cedc678d305f52789fe7e02ba..a0a61cfac23a558624fd0599de6aed582d8d1f24 100644 (file)
@@ -526,7 +526,7 @@ struct ofputil_packet_out {
     const void *packet;         /* Packet data, if buffer_id == UINT32_MAX. */
     size_t packet_len;          /* Length of packet data in bytes. */
     uint32_t buffer_id;         /* Buffer id or UINT32_MAX if no buffer. */
-    ofp_port_t in_port;         /* Packet's input port. */
+    struct match flow_metadata; /* Packet's input port and other metadata. */
     struct ofpact *ofpacts;     /* Actions. */
     size_t ofpacts_len;         /* Size of ofpacts in bytes. */
 };
index 77155d04fcc0c5ebf7a924d541ab5e8176357414..4ff4e0db38be9bf8b8cf68cd4efda918d67aba31 100644 (file)
@@ -570,7 +570,8 @@ process_packet_in(struct lswitch *sw, const struct ofp_header *oh)
         po.packet = NULL;
         po.packet_len = 0;
     }
-    po.in_port = pi.flow_metadata.flow.in_port.ofp_port;
+    match_set_in_port(&po.flow_metadata,
+                      pi.flow_metadata.flow.in_port.ofp_port);
     po.ofpacts = ofpacts.data;
     po.ofpacts_len = ofpacts.size;
 
index c8cac5b4765c3db7f9c4134d0a0ce3abebad7abf..7b0d23feb0c367216235f29c14c4ba2714cd29cd 100644 (file)
@@ -621,8 +621,8 @@ parse_ofp_packet_out_str__(struct ofputil_packet_out *po, char *string,
 
     *po = (struct ofputil_packet_out) {
         .buffer_id = UINT32_MAX,
-        .in_port = OFPP_CONTROLLER,
     };
+    match_set_in_port(&po->flow_metadata, OFPP_CONTROLLER);
 
     act_str = extract_actions(string);
 
@@ -633,19 +633,21 @@ parse_ofp_packet_out_str__(struct ofputil_packet_out *po, char *string,
         }
 
         if (!strcmp(name, "in_port")) {
-            if (!ofputil_port_from_string(value, &po->in_port)) {
+            ofp_port_t in_port;
+            if (!ofputil_port_from_string(value, &in_port)) {
                 error = xasprintf("%s is not a valid OpenFlow port", value);
                 goto out;
             }
-            if (ofp_to_u16(po->in_port) > ofp_to_u16(OFPP_MAX)
-                && po->in_port != OFPP_LOCAL
-                && po->in_port != OFPP_NONE
-                && po->in_port != OFPP_CONTROLLER) {
+            if (ofp_to_u16(in_port) > ofp_to_u16(OFPP_MAX)
+                && in_port != OFPP_LOCAL
+                && in_port != OFPP_NONE
+                && in_port != OFPP_CONTROLLER) {
                 error = xasprintf(
                               "%s is not a valid OpenFlow port for PACKET_OUT",
                               value);
                 goto out;
             }
+            match_set_in_port(&po->flow_metadata, in_port);
         } else if (!strcmp(name, "packet")) {
             const char *error_msg = eth_from_hex(value, &packet);
             if (error_msg) {
index 7ca95310053976809b33e3bfbc791c7050df63dd..98cbf9c4b13c68d4cd44fcae50ef06352a676e85 100644 (file)
@@ -247,8 +247,8 @@ ofp_print_packet_out(struct ds *string, const struct ofp_header *oh,
         return;
     }
 
-    ds_put_cstr(string, " in_port=");
-    ofputil_format_port(po.in_port, string);
+    ds_put_char(string, ' ');
+    match_format(&po.flow_metadata, string, OFP_DEFAULT_PRIORITY);
 
     ds_put_cstr(string, " actions=");
     ofpacts_format(po.ofpacts, po.ofpacts_len, string);
index f05ca398c13e27c5ad471a75d98af1a6d2caa3a3..7037ec358d72cd92b58ee57a5aa16cc39302ba73 100644 (file)
@@ -4204,15 +4204,18 @@ ofputil_decode_packet_out(struct ofputil_packet_out *po,
     enum ofpraw raw = ofpraw_pull_assert(&b);
 
     ofpbuf_clear(ofpacts);
+    match_init_catchall(&po->flow_metadata);
     if (raw == OFPRAW_OFPT11_PACKET_OUT) {
         enum ofperr error;
+        ofp_port_t in_port;
         const struct ofp11_packet_out *opo = ofpbuf_pull(&b, sizeof *opo);
 
         po->buffer_id = ntohl(opo->buffer_id);
-        error = ofputil_port_from_ofp11(opo->in_port, &po->in_port);
+        error = ofputil_port_from_ofp11(opo->in_port, &in_port);
         if (error) {
             return error;
         }
+        match_set_in_port(&po->flow_metadata, in_port);
 
         error = ofpacts_pull_openflow_actions(&b, ntohs(opo->actions_len),
                                               oh->version, NULL, NULL,
@@ -4225,7 +4228,7 @@ ofputil_decode_packet_out(struct ofputil_packet_out *po,
         const struct ofp10_packet_out *opo = ofpbuf_pull(&b, sizeof *opo);
 
         po->buffer_id = ntohl(opo->buffer_id);
-        po->in_port = u16_to_ofp(ntohs(opo->in_port));
+        match_set_in_port(&po->flow_metadata, u16_to_ofp(ntohs(opo->in_port)));
 
         error = ofpacts_pull_openflow_actions(&b, ntohs(opo->actions_len),
                                               oh->version, NULL, NULL,
@@ -4237,11 +4240,13 @@ ofputil_decode_packet_out(struct ofputil_packet_out *po,
         OVS_NOT_REACHED();
     }
 
-    if (ofp_to_u16(po->in_port) >= ofp_to_u16(OFPP_MAX)
-        && po->in_port != OFPP_LOCAL
-        && po->in_port != OFPP_NONE && po->in_port != OFPP_CONTROLLER) {
+    ofp_port_t in_port = po->flow_metadata.flow.in_port.ofp_port;
+    if (ofp_to_u16(in_port) >= ofp_to_u16(OFPP_MAX)
+        && in_port != OFPP_LOCAL
+        && in_port != OFPP_NONE
+        && in_port != OFPP_CONTROLLER) {
         VLOG_WARN_RL(&bad_ofmsg_rl, "packet-out has bad input port %#"PRIx32,
-                     po->in_port);
+                     po->flow_metadata.flow.in_port.ofp_port);
         return OFPERR_OFPBRC_BAD_PORT;
     }
 
@@ -7051,7 +7056,8 @@ ofputil_encode_packet_out(const struct ofputil_packet_out *po,
 
         opo = msg->msg;
         opo->buffer_id = htonl(po->buffer_id);
-        opo->in_port = htons(ofp_to_u16(po->in_port));
+        opo->in_port =htons(ofp_to_u16(
+                                po->flow_metadata.flow.in_port.ofp_port));
         opo->actions_len = htons(msg->size - actions_ofs);
         break;
     }
@@ -7071,7 +7077,8 @@ ofputil_encode_packet_out(const struct ofputil_packet_out *po,
                                            ofp_version);
         opo = msg->msg;
         opo->buffer_id = htonl(po->buffer_id);
-        opo->in_port = ofputil_port_to_ofp11(po->in_port);
+        opo->in_port =
+            ofputil_port_to_ofp11(po->flow_metadata.flow.in_port.ofp_port);
         opo->actions_len = htons(len);
         break;
     }
index d5410fd1b20fe413c91a43d79250d26180a337ae..1bf4c82130939bb7ff216fae59f95c06bcc47d37 100644 (file)
@@ -3459,8 +3459,8 @@ ofproto_packet_out_init(struct ofproto *ofproto,
     enum ofperr error;
     struct match match;
 
-    if (ofp_to_u16(po->in_port) >= ofproto->max_ports
-        && ofp_to_u16(po->in_port) < ofp_to_u16(OFPP_MAX)) {
+    uint16_t in_port = ofp_to_u16(po->flow_metadata.flow.in_port.ofp_port);
+    if (in_port >= ofproto->max_ports && in_port < ofp_to_u16(OFPP_MAX)) {
         return OFPERR_OFPBRC_BAD_PORT;
     }
 
@@ -3475,7 +3475,7 @@ ofproto_packet_out_init(struct ofproto *ofproto,
     /* Store struct flow. */
     opo->flow = xmalloc(sizeof *opo->flow);
     flow_extract(opo->packet, opo->flow);
-    opo->flow->in_port.ofp_port = po->in_port;
+    opo->flow->in_port.ofp_port = po->flow_metadata.flow.in_port.ofp_port;
 
     /* Check actions like for flow mods.  We pass a 'table_id' of 0 to
      * ofproto_check_consistency(), which isn't strictly correct because these
index 417fdc9f52b2491a112ef0c94807243588c47ca7..804b162b51b1b623d8dfe7f481acd1e3ba40f669 100644 (file)
@@ -1165,10 +1165,10 @@ ofctrl_inject_pkt(const struct ovsrec_bridge *br_int, const char *flow_s,
         .packet = dp_packet_data(&packet),
         .packet_len = dp_packet_size(&packet),
         .buffer_id = UINT32_MAX,
-        .in_port = uflow.in_port.ofp_port,
         .ofpacts = ofpacts.data,
         .ofpacts_len = ofpacts.size,
     };
+    match_set_in_port(&po.flow_metadata, uflow.in_port.ofp_port);
     enum ofputil_protocol proto = ofputil_protocol_from_ofp_version(version);
     queue_msg(ofputil_encode_packet_out(&po, proto));
     dp_packet_uninit(&packet);
index 225f6a7563dc0908125bfccc9bafea8371a15be4..a77f85f2fb278f7a4cf2311e434c3a46b7651469 100644 (file)
@@ -183,10 +183,10 @@ pinctrl_handle_arp(const struct flow *ip_flow, const struct match *md,
         .packet = dp_packet_data(&packet),
         .packet_len = dp_packet_size(&packet),
         .buffer_id = UINT32_MAX,
-        .in_port = OFPP_CONTROLLER,
         .ofpacts = ofpacts.data,
         .ofpacts_len = ofpacts.size,
     };
+    match_set_in_port(&po.flow_metadata, OFPP_CONTROLLER);
     enum ofputil_protocol proto = ofputil_protocol_from_ofp_version(version);
     queue_msg(ofputil_encode_packet_out(&po, proto));
 
@@ -1391,10 +1391,10 @@ send_garp(struct garp_data *garp, long long int current_time)
         .packet = dp_packet_data(&packet),
         .packet_len = dp_packet_size(&packet),
         .buffer_id = UINT32_MAX,
-        .in_port = OFPP_CONTROLLER,
         .ofpacts = ofpacts.data,
         .ofpacts_len = ofpacts.size,
     };
+    match_set_in_port(&po.flow_metadata, OFPP_CONTROLLER);
     enum ofputil_protocol proto = ofputil_protocol_from_ofp_version(version);
     queue_msg(ofputil_encode_packet_out(&po, proto));
     dp_packet_uninit(&packet);
@@ -1790,10 +1790,10 @@ pinctrl_handle_nd_na(const struct flow *ip_flow, const struct match *md,
         .packet = dp_packet_data(&packet),
         .packet_len = dp_packet_size(&packet),
         .buffer_id = UINT32_MAX,
-        .in_port = OFPP_CONTROLLER,
         .ofpacts = ofpacts.data,
         .ofpacts_len = ofpacts.size,
     };
+    match_set_in_port(&po.flow_metadata, OFPP_CONTROLLER);
 
     queue_msg(ofputil_encode_packet_out(&po, proto));
 
index 1a5e2345b7d4cbc5298f22193ad1c5500a3455bb..17ee64649f7f27bdd4d19cf10a1971b9db47f68f 100644 (file)
@@ -2078,6 +2078,7 @@ ofctl_packet_out(struct ovs_cmdl_context *ctx)
     struct ofpbuf *opo;
     char *error;
 
+    match_init_catchall(&po.flow_metadata);
     /* Use the old syntax when more than 4 arguments are given. */
     if (ctx->argc > 4) {
         struct ofpbuf ofpacts;
@@ -2091,7 +2092,8 @@ ofctl_packet_out(struct ovs_cmdl_context *ctx)
         }
 
         po.buffer_id = UINT32_MAX;
-        po.in_port = str_to_port_no(ctx->argv[1], ctx->argv[2]);
+        match_set_in_port(&po.flow_metadata,
+                          str_to_port_no(ctx->argv[1], ctx->argv[2]));
         po.ofpacts = ofpacts.data;
         po.ofpacts_len = ofpacts.size;