ofproto: Get rid of archaic "switch status" OpenFlow extension.
[sliver-openvswitch.git] / ofproto / ofproto.c
index 61d08ea..ffeb952 100644 (file)
@@ -54,7 +54,6 @@
 #include "poll-loop.h"
 #include "rconn.h"
 #include "shash.h"
-#include "status.h"
 #include "stream-ssl.h"
 #include "svec.h"
 #include "tag.h"
@@ -91,8 +90,6 @@ COVERAGE_DEFINE(ofproto_unexpected_rule);
 COVERAGE_DEFINE(ofproto_uninstallable);
 COVERAGE_DEFINE(ofproto_update_port);
 
-#include "sflow_api.h"
-
 /* Maximum depth of flow table recursion (due to NXAST_RESUBMIT actions) in a
  * flow translation. */
 #define MAX_RESUBMIT_RECURSION 16
@@ -336,7 +333,6 @@ struct ofconn {
     enum nx_role role;           /* Role. */
     struct hmap_node hmap_node;  /* In struct ofproto's "controllers" map. */
     struct discovery *discovery; /* Controller discovery object, if enabled. */
-    struct status_category *ss;  /* Switch status category. */
     enum ofproto_band band;      /* In-band or out-of-band? */
 };
 
@@ -375,7 +371,6 @@ struct ofproto {
     uint32_t max_ports;
 
     /* Configuration. */
-    struct switch_status *switch_status;
     struct fail_open *fail_open;
     struct netflow *netflow;
     struct ofproto_sflow *sflow;
@@ -490,7 +485,6 @@ ofproto_create(const char *datapath, const char *datapath_type,
     p->max_ports = dpif_get_max_ports(dpif);
 
     /* Initialize submodules. */
-    p->switch_status = switch_status_create(p);
     p->fail_open = NULL;
     p->netflow = NULL;
     p->sflow = NULL;
@@ -573,8 +567,7 @@ add_controller(struct ofproto *ofproto, const struct ofproto_controller *c)
 
     if (is_discovery_controller(c)) {
         int error = discovery_create(c->accept_re, c->update_resolv_conf,
-                                     ofproto->dpif, ofproto->switch_status,
-                                     &discovery);
+                                     ofproto->dpif, &discovery);
         if (error) {
             return;
         }
@@ -685,8 +678,7 @@ update_in_band_remotes(struct ofproto *ofproto)
      * even before we know any remote addresses. */
     if (n_addrs || discovery) {
         if (!ofproto->in_band) {
-            in_band_create(ofproto, ofproto->dpif, ofproto->switch_status,
-                           &ofproto->in_band);
+            in_band_create(ofproto, ofproto->dpif, &ofproto->in_band);
         }
         if (ofproto->in_band) {
             in_band_set_remotes(ofproto->in_band, addrs, n_addrs);
@@ -713,7 +705,7 @@ update_fail_open(struct ofproto *p)
         size_t n;
 
         if (!p->fail_open) {
-            p->fail_open = fail_open_create(p, p->switch_status);
+            p->fail_open = fail_open_create(p);
         }
 
         n = 0;
@@ -738,7 +730,6 @@ ofproto_set_controllers(struct ofproto *p,
     struct shash new_controllers;
     struct ofconn *ofconn, *next_ofconn;
     struct ofservice *ofservice, *next_ofservice;
-    bool ss_exists;
     size_t i;
 
     /* Create newly configured controllers and services.
@@ -766,7 +757,6 @@ ofproto_set_controllers(struct ofproto *p,
 
     /* Delete controllers that are no longer configured.
      * Update configuration of all now-existing controllers. */
-    ss_exists = false;
     HMAP_FOR_EACH_SAFE (ofconn, next_ofconn, hmap_node, &p->controllers) {
         struct ofproto_controller *c;
 
@@ -775,9 +765,6 @@ ofproto_set_controllers(struct ofproto *p,
             ofconn_destroy(ofconn);
         } else {
             update_controller(ofconn, c);
-            if (ofconn->ss) {
-                ss_exists = true;
-            }
         }
     }
 
@@ -799,13 +786,6 @@ ofproto_set_controllers(struct ofproto *p,
 
     update_in_band_remotes(p);
     update_fail_open(p);
-
-    if (!hmap_is_empty(&p->controllers) && !ss_exists) {
-        ofconn = CONTAINER_OF(hmap_first(&p->controllers),
-                              struct ofconn, hmap_node);
-        ofconn->ss = switch_status_register(p->switch_status, "remote",
-                                            rconn_status_cb, ofconn->rconn);
-    }
 }
 
 void
@@ -1080,7 +1060,6 @@ ofproto_destroy(struct ofproto *p)
     }
     shash_destroy(&p->port_by_name);
 
-    switch_status_destroy(p->switch_status);
     netflow_destroy(p->netflow);
     ofproto_sflow_destroy(p->sflow);
 
@@ -1367,7 +1346,7 @@ ofproto_is_alive(const struct ofproto *p)
 }
 
 void
-ofproto_get_ofproto_controller_info(const struct ofproto * ofproto,
+ofproto_get_ofproto_controller_info(const struct ofproto *ofproto,
                                     struct shash *info)
 {
     const struct ofconn *ofconn;
@@ -1376,6 +1355,9 @@ ofproto_get_ofproto_controller_info(const struct ofproto * ofproto,
 
     HMAP_FOR_EACH (ofconn, hmap_node, &ofproto->controllers) {
         const struct rconn *rconn = ofconn->rconn;
+        time_t now = time_now();
+        time_t last_connection = rconn_get_last_connection(rconn);
+        time_t last_disconnect = rconn_get_last_disconnect(rconn);
         const int last_error = rconn_get_last_error(rconn);
         struct ofproto_controller_info *cinfo = xmalloc(sizeof *cinfo);
 
@@ -1396,9 +1378,17 @@ ofproto_get_ofproto_controller_info(const struct ofproto * ofproto,
         cinfo->pairs.values[cinfo->pairs.n++] =
             xstrdup(rconn_get_state(rconn));
 
-        cinfo->pairs.keys[cinfo->pairs.n] = "time_in_state";
-        cinfo->pairs.values[cinfo->pairs.n++] =
-            xasprintf("%u", rconn_get_state_elapsed(rconn));
+        if (last_connection != TIME_MIN) {
+            cinfo->pairs.keys[cinfo->pairs.n] = "sec_since_connect";
+            cinfo->pairs.values[cinfo->pairs.n++]
+                = xasprintf("%ld", (long int) (now - last_connection));
+        }
+
+        if (last_disconnect != TIME_MIN) {
+            cinfo->pairs.keys[cinfo->pairs.n] = "sec_since_disconnect";
+            cinfo->pairs.values[cinfo->pairs.n++]
+                = xasprintf("%ld", (long int) (now - last_disconnect));
+        }
     }
 }
 
@@ -1834,7 +1824,6 @@ ofconn_destroy(struct ofconn *ofconn)
     discovery_destroy(ofconn->discovery);
 
     list_remove(&ofconn->node);
-    switch_status_unregister(ofconn->ss);
     rconn_destroy(ofconn->rconn);
     rconn_packet_counter_destroy(ofconn->packet_in_counter);
     rconn_packet_counter_destroy(ofconn->reply_counter);
@@ -1949,8 +1938,7 @@ ofconn_set_rate_limit(struct ofconn *ofconn, int rate, int burst)
 
         if (rate > 0) {
             if (!*s) {
-                *s = pinsched_create(rate, burst,
-                                     ofconn->ofproto->switch_status);
+                *s = pinsched_create(rate, burst);
             } else {
                 pinsched_set_limits(*s, rate, burst);
             }
@@ -2161,12 +2149,10 @@ facet_execute(struct ofproto *ofproto, struct facet *facet,
     assert(ofpbuf_headroom(packet) >= sizeof(struct ofp_packet_in));
 
     flow_extract_stats(&facet->flow, packet, &stats);
+    stats.used = time_msec();
     if (execute_odp_actions(ofproto, &facet->flow,
                             facet->actions, facet->actions_len, packet)) {
-        facet->used = time_msec();
         facet_update_stats(ofproto, facet, &stats);
-        netflow_flow_update_time(ofproto->netflow,
-                                 &facet->nf_flow, facet->used);
     }
 }
 
@@ -3543,7 +3529,16 @@ put_ofp_flow_stats(struct ofconn *ofconn, struct rule *rule,
 static bool
 is_valid_table(uint8_t table_id)
 {
-    return table_id == 0 || table_id == 0xff;
+    if (table_id == 0 || table_id == 0xff) {
+        return true;
+    } else {
+        /* It would probably be better to reply with an error but there doesn't
+         * seem to be any appropriate value, so that might just be
+         * confusing. */
+        VLOG_WARN_RL(&rl, "controller asked for invalid table %"PRIu8,
+                     table_id);
+        return false;
+    }
 }
 
 static int
@@ -3672,7 +3667,7 @@ flow_stats_ds(struct rule *rule, struct ds *results)
 }
 
 /* Adds a pretty-printed description of all flows to 'results', including
- * those marked hidden by secchan (e.g., by in-band control). */
+ * hidden flows (e.g., set up by in-band control). */
 void
 ofproto_get_all_flows(struct ofproto *p, struct ds *results)
 {
@@ -3887,7 +3882,7 @@ static void
 facet_update_stats(struct ofproto *ofproto, struct facet *facet,
                    const struct dpif_flow_stats *stats)
 {
-    if (stats->n_packets) {
+    if (stats->n_packets || stats->used > facet->used) {
         facet_update_time(ofproto, facet, stats->used);
         facet->packet_count += stats->n_packets;
         facet->byte_count += stats->n_bytes;
@@ -4343,10 +4338,6 @@ handle_openflow__(struct ofconn *ofconn, const struct ofpbuf *msg)
         return 0;
 
         /* Nicira extension requests. */
-    case OFPUTIL_NXT_STATUS_REQUEST:
-        return switch_status_handle_request(
-            ofconn->ofproto->switch_status, ofconn->rconn, oh);
-
     case OFPUTIL_NXT_TUN_ID_FROM_COOKIE:
         return handle_tun_id_from_cookie(ofconn, oh);
 
@@ -4402,7 +4393,6 @@ handle_openflow__(struct ofconn *ofconn, const struct ofpbuf *msg)
     case OFPUTIL_OFPST_PORT_REPLY:
     case OFPUTIL_OFPST_TABLE_REPLY:
     case OFPUTIL_OFPST_AGGREGATE_REPLY:
-    case OFPUTIL_NXT_STATUS_REPLY:
     case OFPUTIL_NXT_ROLE_REPLY:
     case OFPUTIL_NXT_FLOW_REMOVED:
     case OFPUTIL_NXST_FLOW_REPLY:
@@ -4991,7 +4981,8 @@ schedule_packet_in(struct ofconn *ofconn, struct dpif_upcall *upcall,
  * OFPT_PACKET_IN message to each OpenFlow controller as necessary according to
  * their individual configurations.
  *
- * Takes ownership of 'packet'. */
+ * If 'clone' is true, the caller retains ownership of 'upcall->packet'.
+ * Otherwise, ownership is transferred to this function. */
 static void
 send_packet_in(struct ofproto *ofproto, struct dpif_upcall *upcall,
                const struct flow *flow, bool clone)