ofproto: connmgr_send_packet_in() doesn't need buffer_id and total_len.
[sliver-openvswitch.git] / ofproto / connmgr.c
index c820ad5..1f5fbed 100644 (file)
@@ -58,9 +58,8 @@ struct ofconn {
 
     /* OpenFlow state. */
     enum nx_role role;           /* Role. */
-    enum nx_flow_format flow_format; /* Currently selected flow format. */
+    enum ofputil_protocol protocol; /* Current protocol variant. */
     enum nx_packet_in_format packet_in_format; /* OFPT_PACKET_IN format. */
-    bool flow_mod_table_id;     /* NXT_FLOW_MOD_TABLE_ID enabled? */
 
     /* Asynchronous flow table operation support. */
     struct list opgroups;       /* Contains pending "ofopgroups", if any. */
@@ -276,7 +275,7 @@ connmgr_run(struct connmgr *mgr,
         struct vconn *vconn;
         int retval;
 
-        retval = pvconn_accept(ofservice->pvconn, OFP_VERSION, &vconn);
+        retval = pvconn_accept(ofservice->pvconn, OFP10_VERSION, &vconn);
         if (!retval) {
             struct rconn *rconn;
             char *name;
@@ -299,7 +298,7 @@ connmgr_run(struct connmgr *mgr,
         struct vconn *vconn;
         int retval;
 
-        retval = pvconn_accept(mgr->snoops[i], OFP_VERSION, &vconn);
+        retval = pvconn_accept(mgr->snoops[i], OFP10_VERSION, &vconn);
         if (!retval) {
             add_snooper(mgr, vconn);
         } else if (retval != EAGAIN) {
@@ -786,20 +785,23 @@ ofconn_get_invalid_ttl_to_controller(struct ofconn *ofconn)
     return (ofconn->master_async_config[OAM_PACKET_IN] & bit) != 0;
 }
 
-/* Returns the currently configured flow format for 'ofconn', one of NXFF_*.
+/* Returns the currently configured protocol for 'ofconn', one of OFPUTIL_P_*.
  *
- * The default, if no other format has been set, is NXFF_OPENFLOW10. */
-enum nx_flow_format
-ofconn_get_flow_format(struct ofconn *ofconn)
+ * The default, if no other format has been set, is OFPUTIL_P_OPENFLOW10. */
+enum ofputil_protocol
+ofconn_get_protocol(struct ofconn *ofconn)
 {
-    return ofconn->flow_format;
+    return ofconn->protocol;
 }
 
-/* Sets the flow format for 'ofconn' to 'flow_format' (one of NXFF_*). */
+/* Sets the protocol for 'ofconn' to 'protocol' (one of OFPUTIL_P_*).
+ *
+ * (This doesn't actually send anything to accomplish this.  Presumably the
+ * caller already did that.) */
 void
-ofconn_set_flow_format(struct ofconn *ofconn, enum nx_flow_format flow_format)
+ofconn_set_protocol(struct ofconn *ofconn, enum ofputil_protocol protocol)
 {
-    ofconn->flow_format = flow_format;
+    ofconn->protocol = protocol;
 }
 
 /* Returns the currently configured packet in format for 'ofconn', one of
@@ -831,24 +833,6 @@ ofconn_set_controller_id(struct ofconn *ofconn, uint16_t controller_id)
     ofconn->controller_id = controller_id;
 }
 
-/* Returns true if the NXT_FLOW_MOD_TABLE_ID extension is enabled, false
- * otherwise.
- *
- * By default the extension is not enabled. */
-bool
-ofconn_get_flow_mod_table_id(const struct ofconn *ofconn)
-{
-    return ofconn->flow_mod_table_id;
-}
-
-/* Enables or disables (according to 'enable') the NXT_FLOW_MOD_TABLE_ID
- * extension on 'ofconn'. */
-void
-ofconn_set_flow_mod_table_id(struct ofconn *ofconn, bool enable)
-{
-    ofconn->flow_mod_table_id = enable;
-}
-
 /* Returns the default miss send length for 'ofconn'. */
 int
 ofconn_get_miss_send_len(const struct ofconn *ofconn)
@@ -994,9 +978,8 @@ ofconn_flush(struct ofconn *ofconn)
     int i;
 
     ofconn->role = NX_ROLE_OTHER;
-    ofconn->flow_format = NXFF_OPENFLOW10;
+    ofconn->protocol = OFPUTIL_P_OF10;
     ofconn->packet_in_format = NXPIF_OPENFLOW10;
-    ofconn->flow_mod_table_id = false;
 
     /* Disassociate 'ofconn' from all of the ofopgroups that it initiated that
      * have not yet completed.  (Those ofopgroups will still run to completion
@@ -1247,27 +1230,26 @@ ofconn_send(const struct ofconn *ofconn, struct ofpbuf *msg,
 \f
 /* Sending asynchronous messages. */
 
-static void schedule_packet_in(struct ofconn *, struct ofputil_packet_in,
-                               const struct flow *);
+static void schedule_packet_in(struct ofconn *, struct ofputil_packet_in);
 
 /* Sends an OFPT_PORT_STATUS message with 'opp' and 'reason' to appropriate
  * controllers managed by 'mgr'. */
 void
-connmgr_send_port_status(struct connmgr *mgr, const struct ofp_phy_port *opp,
-                         uint8_t reason)
+connmgr_send_port_status(struct connmgr *mgr,
+                         const struct ofputil_phy_port *pp, uint8_t reason)
 {
     /* XXX Should limit the number of queued port status change messages. */
+    struct ofputil_port_status ps;
     struct ofconn *ofconn;
 
+    ps.reason = reason;
+    ps.desc = *pp;
     LIST_FOR_EACH (ofconn, node, &mgr->all_conns) {
         if (ofconn_receives_async_msg(ofconn, OAM_PORT_STATUS, reason)) {
-            struct ofp_port_status *ops;
-            struct ofpbuf *b;
+            struct ofpbuf *msg;
 
-            ops = make_openflow_xid(sizeof *ops, OFPT_PORT_STATUS, 0, &b);
-            ops->reason = reason;
-            ops->desc = *opp;
-            ofconn_send(ofconn, b, NULL);
+            msg = ofputil_encode_port_status(&ps, ofconn->protocol);
+            ofconn_send(ofconn, msg, NULL);
         }
     }
 }
@@ -1289,25 +1271,26 @@ connmgr_send_flow_removed(struct connmgr *mgr,
              * also prevents new flows from being added (and expiring).  (It
              * also prevents processing OpenFlow requests that would not add
              * new flows, so it is imperfect.) */
-            msg = ofputil_encode_flow_removed(fr, ofconn->flow_format);
+            msg = ofputil_encode_flow_removed(fr, ofconn->protocol);
             ofconn_send_reply(ofconn, msg);
         }
     }
 }
 
 /* Given 'pin', sends an OFPT_PACKET_IN message to each OpenFlow controller as
- * necessary according to their individual configurations. */
+ * necessary according to their individual configurations.
+ *
+ * The caller doesn't need to fill in pin->buffer_id or pin->total_len. */
 void
 connmgr_send_packet_in(struct connmgr *mgr,
-                       const struct ofputil_packet_in *pin,
-                       const struct flow *flow)
+                       const struct ofputil_packet_in *pin)
 {
     struct ofconn *ofconn;
 
     LIST_FOR_EACH (ofconn, node, &mgr->all_conns) {
         if (ofconn_receives_async_msg(ofconn, OAM_PACKET_IN, pin->reason)
             && ofconn->controller_id == pin->controller_id) {
-            schedule_packet_in(ofconn, *pin, flow);
+            schedule_packet_in(ofconn, *pin);
         }
     }
 }
@@ -1322,15 +1305,15 @@ do_send_packet_in(struct ofpbuf *ofp_packet_in, void *ofconn_)
                           ofconn->packet_in_counter, 100);
 }
 
-/* Takes 'pin', whose packet has the flow specified by 'flow', composes an
- * OpenFlow packet-in message from it, and passes it to 'ofconn''s packet
- * scheduler for sending. */
+/* Takes 'pin', composes an OpenFlow packet-in message from it, and passes it
+ * to 'ofconn''s packet scheduler for sending. */
 static void
-schedule_packet_in(struct ofconn *ofconn, struct ofputil_packet_in pin,
-                   const struct flow *flow)
+schedule_packet_in(struct ofconn *ofconn, struct ofputil_packet_in pin)
 {
     struct connmgr *mgr = ofconn->connmgr;
 
+    pin.total_len = pin.packet_len;
+
     /* Get OpenFlow buffer_id. */
     if (pin.reason == OFPR_ACTION) {
         pin.buffer_id = UINT32_MAX;
@@ -1340,7 +1323,7 @@ schedule_packet_in(struct ofconn *ofconn, struct ofputil_packet_in pin,
         pin.buffer_id = UINT32_MAX;
     } else {
         pin.buffer_id = pktbuf_save(ofconn->pktbuf, pin.packet, pin.packet_len,
-                                    flow->in_port);
+                                    pin.fmd.in_port);
     }
 
     /* Figure out how much of the packet to send. */
@@ -1358,7 +1341,7 @@ schedule_packet_in(struct ofconn *ofconn, struct ofputil_packet_in pin,
      * immediately call into do_send_packet_in() or it might buffer it for a
      * while (until a later call to pinsched_run()). */
     pinsched_send(ofconn->schedulers[pin.reason == OFPR_NO_MATCH ? 0 : 1],
-                  flow->in_port,
+                  pin.fmd.in_port,
                   ofputil_encode_packet_in(&pin, ofconn->packet_in_format),
                   do_send_packet_in, ofconn);
 }
@@ -1577,7 +1560,7 @@ connmgr_flushed(struct connmgr *mgr)
         struct cls_rule rule;
 
         memset(&action, 0, sizeof action);
-        action.type = htons(OFPAT_OUTPUT);
+        action.type = htons(OFPAT10_OUTPUT);
         action.output.len = htons(sizeof action);
         action.output.port = htons(OFPP_NORMAL);
         cls_rule_init_catchall(&rule, 0);