Drop unneeded inclusions of ofp-print.h.
[openvswitch] / lib / rconn.c
index ee995e499d7ec80310687fbb12d0cd071e045582..7eb93baf33845e355d471731c5754a04b28ec71d 100644 (file)
@@ -38,9 +38,8 @@
 #include <limits.h>
 #include <stdlib.h>
 #include <string.h>
-#include "buffer.h"
+#include "ofpbuf.h"
 #include "poll-loop.h"
-#include "ofp-print.h"
 #include "sat-math.h"
 #include "timeval.h"
 #include "util.h"
@@ -83,7 +82,7 @@ struct rconn {
     char *name;
     bool reliable;
 
-    struct queue txq;
+    struct ofp_queue txq;
 
     int backoff;
     int max_backoff;
@@ -304,7 +303,7 @@ run_CONNECTING(struct rconn *rc)
         VLOG_WARN("%s: connected", rc->name);
         rc->n_successful_connections++;
         if (vconn_is_passive(rc->vconn)) {
-            error(0, "%s: passive vconn not supported", rc->name);
+            ofp_error(0, "%s: passive vconn not supported", rc->name);
             state_transition(rc, S_VOID);
         } else {
             state_transition(rc, S_ACTIVE);
@@ -421,12 +420,12 @@ rconn_run_wait(struct rconn *rc)
 
 /* Attempts to receive a packet from 'rc'.  If successful, returns the packet;
  * otherwise, returns a null pointer.  The caller is responsible for freeing
- * the packet (with buffer_delete()). */
-struct buffer *
+ * the packet (with ofpbuf_delete()). */
+struct ofpbuf *
 rconn_recv(struct rconn *rc)
 {
     if (rc->state & (S_ACTIVE | S_IDLE)) {
-        struct buffer *buffer;
+        struct ofpbuf *buffer;
         int error = vconn_recv(rc->vconn, &buffer);
         if (!error) {
             rc->last_received = time_now();
@@ -466,7 +465,7 @@ rconn_recv_wait(struct rconn *rc)
  * takes care of sending if you call rconn_run(), which will have the side
  * effect of waking up poll_block(). */
 int
-rconn_send(struct rconn *rc, struct buffer *b, int *n_queued)
+rconn_send(struct rconn *rc, struct ofpbuf *b, int *n_queued)
 {
     if (rconn_is_connected(rc)) {
         b->private = n_queued;
@@ -496,13 +495,13 @@ rconn_send(struct rconn *rc, struct buffer *b, int *n_queued)
  * takes care of sending if you call rconn_run(), which will have the side
  * effect of waking up poll_block(). */
 int
-rconn_send_with_limit(struct rconn *rc, struct buffer *b,
+rconn_send_with_limit(struct rconn *rc, struct ofpbuf *b,
                       int *n_queued, int queue_limit)
 {
     int retval;
     retval = *n_queued >= queue_limit ? EAGAIN : rconn_send(rc, b, n_queued);
     if (retval) {
-        buffer_delete(b);
+        ofpbuf_delete(b);
     }
     return retval;
 }
@@ -623,6 +622,21 @@ rconn_get_total_time_connected(const struct rconn *rc)
     return (rc->total_time_connected
             + (rconn_is_connected(rc) ? elapsed_in_this_state(rc) : 0));
 }
+
+/* Returns the current amount of backoff, in seconds.  This is the amount of
+ * time after which the rconn will transition from BACKOFF to CONNECTING. */
+int
+rconn_get_backoff(const struct rconn *rc)
+{
+    return rc->backoff;
+}
+
+/* Returns the number of seconds spent in this state so far. */
+unsigned int
+rconn_get_state_elapsed(const struct rconn *rc)
+{
+    return elapsed_in_this_state(rc);
+}
 \f
 /* Tries to send a packet from 'rc''s send buffer.  Returns 0 if successful,
  * otherwise a positive errno value. */
@@ -630,7 +644,7 @@ static int
 try_send(struct rconn *rc)
 {
     int retval = 0;
-    struct buffer *next = rc->txq.head->next;
+    struct ofpbuf *next = rc->txq.head->next;
     int *n_queued = rc->txq.head->private;
     retval = vconn_send(rc->vconn, rc->txq.head);
     if (retval) {
@@ -698,12 +712,12 @@ flush_queue(struct rconn *rc)
         return;
     }
     while (rc->txq.n > 0) {
-        struct buffer *b = queue_pop_head(&rc->txq);
+        struct ofpbuf *b = queue_pop_head(&rc->txq);
         int *n_queued = b->private;
         if (n_queued) {
             --*n_queued;
         }
-        buffer_delete(b);
+        ofpbuf_delete(b);
     }
     poll_immediate_wake();
 }