Use signal-based timekeeping functions throughout the source base.
authorBen Pfaff <blp@nicira.com>
Mon, 11 Aug 2008 20:44:29 +0000 (13:44 -0700)
committerBen Pfaff <blp@nicira.com>
Tue, 12 Aug 2008 22:21:30 +0000 (15:21 -0700)
lib/dhcp-client.c
lib/learning-switch.c
lib/netlink.c
lib/rconn.c
lib/vlog-socket.c
lib/vlog.c
secchan/secchan.c
switch/datapath.c
switch/switch-flow.c

index 3bed591..97ae318 100644 (file)
@@ -51,6 +51,7 @@
 #include "netdev.h"
 #include "ofp-print.h"
 #include "poll-loop.h"
+#include "timeval.h"
 
 #define THIS_MODULE VLM_dhcp_client
 #include "vlog.h"
@@ -194,7 +195,7 @@ dhclient_create(const char *netdev_name,
     cli->aux = aux;
     cli->netdev = netdev;
     cli->state = S_RELEASED;
-    cli->state_entered = time(0);
+    cli->state_entered = time_now();
     cli->xid = random_uint32();
     cli->ipaddr = 0;
     cli->server_ip = 0;
@@ -238,7 +239,7 @@ dhclient_release(struct dhclient *cli)
 static void
 do_force_renew(struct dhclient *cli, int deadline)
 {
-    time_t now = time(0);
+    time_t now = time_now();
     unsigned int lease_left = sat_sub(cli->lease_expiration, now);
     if (lease_left <= deadline) {
         if (cli->state & (S_RENEWING | S_REBINDING)) {
@@ -672,7 +673,7 @@ receive_ack(struct dhclient *cli)
             t1 = calc_t1(lease, t2);
         }
 
-        cli->lease_expiration = sat_add(time(0), lease);
+        cli->lease_expiration = sat_add(time_now(), lease);
         cli->bound_timeout = t1;
         cli->renewing_timeout = t2 - t1;
         cli->rebinding_timeout = lease - t2;
@@ -777,7 +778,7 @@ state_transition(struct dhclient *cli, enum dhclient_state state)
         VLOG_DBG("entering %s", state_name(state)); 
         cli->state = state;
     }
-    cli->state_entered = time(0);
+    cli->state_entered = time_now();
     cli->retransmit = cli->delay = 0;
     am_bound = dhclient_is_bound(cli);
     if (was_bound != am_bound) {
@@ -838,14 +839,14 @@ dhclient_msg_init(struct dhclient *cli, enum dhcp_msg_type type,
 static unsigned int
 elapsed_in_this_state(const struct dhclient *cli)
 {
-    return time(0) - cli->state_entered;
+    return time_now() - cli->state_entered;
 }
 
 static bool
 timeout(struct dhclient *cli, unsigned int secs)
 {
     cli->min_timeout = MIN(cli->min_timeout, secs);
-    return time(0) >= sat_add(cli->state_entered, secs);
+    return time_now() >= sat_add(cli->state_entered, secs);
 }
 
 static bool
index 0dfdeae..d41602d 100644 (file)
@@ -47,6 +47,7 @@
 #include "openflow.h"
 #include "queue.h"
 #include "rconn.h"
+#include "timeval.h"
 #include "vconn.h"
 #include "xtoxll.h"
 
@@ -88,7 +89,7 @@ lswitch_create(struct rconn *rconn, bool learn_macs, int max_idle)
     memset(sw, 0, sizeof *sw);
     sw->max_idle = max_idle;
     sw->datapath_id = 0;
-    sw->last_features_request = time(0) - 1;
+    sw->last_features_request = time_now() - 1;
     sw->ml = learn_macs ? mac_learning_create() : NULL;
     send_features_request(sw, rconn);
     return sw;
@@ -148,7 +149,7 @@ lswitch_process_packet(struct lswitch *sw, struct rconn *rconn,
 static void
 send_features_request(struct lswitch *sw, struct rconn *rconn)
 {
-    time_t now = time(0);
+    time_t now = time_now();
     if (now >= sw->last_features_request + 1) {
         struct buffer *b;
         struct ofp_header *ofr;
index d9dd435..9abe26a 100644 (file)
@@ -44,6 +44,7 @@
 #include "buffer.h"
 #include "netlink-protocol.h"
 #include "dynamic-string.h"
+#include "timeval.h"
 #include "util.h"
 
 #include "vlog.h"
@@ -99,7 +100,7 @@ nl_sock_create(int protocol, int multicast_group,
 
     if (next_seq == 0) {
         /* Pick initial sequence number. */
-        next_seq = getpid() ^ time(0);
+        next_seq = getpid() ^ time_now();
     }
 
     *sockp = NULL;
index 9bb2b5c..0093c3a 100644 (file)
@@ -161,7 +161,7 @@ rconn_create(int txq_limit, int probe_interval, int max_backoff)
     struct rconn *rc = xcalloc(1, sizeof *rc);
 
     rc->state = S_VOID;
-    rc->state_entered = time(0);
+    rc->state_entered = time_now();
 
     rc->vconn = NULL;
     rc->name = xstrdup("void");
@@ -174,13 +174,13 @@ rconn_create(int txq_limit, int probe_interval, int max_backoff)
     rc->backoff = 0;
     rc->max_backoff = max_backoff ? max_backoff : 60;
     rc->backoff_deadline = TIME_MIN;
-    rc->last_received = time(0);
-    rc->last_connected = time(0);
+    rc->last_received = time_now();
+    rc->last_connected = time_now();
 
     rc->packets_sent = 0;
 
     rc->questionable_connectivity = false;
-    rc->last_questioned = time(0);
+    rc->last_questioned = time_now();
 
     rc->probe_interval = probe_interval ? MAX(5, probe_interval) : 0;
 
@@ -207,7 +207,7 @@ rconn_connect_unreliably(struct rconn *rc,
     rc->name = xstrdup(name);
     rc->reliable = false;
     rc->vconn = vconn;
-    rc->last_connected = time(0);
+    rc->last_connected = time_now();
     state_transition(rc, S_ACTIVE);
 }
 
@@ -260,7 +260,7 @@ reconnect(struct rconn *rc)
     VLOG_WARN("%s: connecting...", rc->name);
     retval = vconn_open(rc->name, &rc->vconn);
     if (!retval) {
-        rc->backoff_deadline = time(0) + rc->backoff;
+        rc->backoff_deadline = time_now() + rc->backoff;
         state_transition(rc, S_CONNECTING);
     } else {
         VLOG_WARN("%s: connection failed (%s)", rc->name, strerror(retval));
@@ -341,7 +341,7 @@ run_ACTIVE(struct rconn *rc)
         unsigned int base = MAX(rc->last_received, rc->state_entered);
         queue_push_tail(&rc->txq, make_echo_request());
         VLOG_DBG("%s: idle %u seconds, sending inactivity probe",
-                 rc->name, (unsigned int) (time(0) - base));
+                 rc->name, (unsigned int) (time_now() - base));
         state_transition(rc, S_IDLE);
         return;
     }
@@ -413,7 +413,7 @@ rconn_recv(struct rconn *rc)
         struct buffer *buffer;
         int error = vconn_recv(rc->vconn, &buffer);
         if (!error) {
-            rc->last_received = time(0);
+            rc->last_received = time_now();
             if (rc->state == S_IDLE) {
                 state_transition(rc, S_ACTIVE);
             }
@@ -522,7 +522,7 @@ rconn_is_connected(const struct rconn *rconn)
 int
 rconn_disconnected_duration(const struct rconn *rconn)
 {
-    return rconn_is_connected(rconn) ? 0 : time(0) - rconn->last_received;
+    return rconn_is_connected(rconn) ? 0 : time_now() - rconn->last_received;
 }
 
 /* Returns the IP address of the peer, or 0 if the peer is not connected over
@@ -575,7 +575,7 @@ static void
 disconnect(struct rconn *rc, int error)
 {
     if (rc->reliable) {
-        time_t now = time(0);
+        time_t now = time_now();
 
         if (rc->state & (S_CONNECTING | S_ACTIVE | S_IDLE)) {
             if (error > 0) {
@@ -613,7 +613,7 @@ disconnect(struct rconn *rc, int error)
 static unsigned int
 elapsed_in_this_state(const struct rconn *rc)
 {
-    return time(0) - rc->state_entered;
+    return time_now() - rc->state_entered;
 }
 
 static unsigned int
@@ -631,7 +631,7 @@ timeout(const struct rconn *rc)
 static bool
 timed_out(const struct rconn *rc)
 {
-    return time(0) >= sat_add(rc->state_entered, timeout(rc));
+    return time_now() >= sat_add(rc->state_entered, timeout(rc));
 }
 
 static void
@@ -639,7 +639,7 @@ state_transition(struct rconn *rc, enum state state)
 {
     VLOG_DBG("%s: entering %s", rc->name, state_name(state));
     rc->state = state;
-    rc->state_entered = time(0);
+    rc->state_entered = time_now();
 }
 
 static unsigned int
@@ -658,7 +658,7 @@ sat_mul(unsigned int x, unsigned int y)
 static void
 question_connectivity(struct rconn *rc) 
 {
-    time_t now = time(0);
+    time_t now = time_now();
     if (now - rc->last_questioned > 60) {
         rc->questionable_connectivity = true;
         rc->last_questioned = now;
index a9f8a52..49d9589 100644 (file)
@@ -212,7 +212,7 @@ recv_with_creds(const struct vlog_server *server,
         fprintf(stderr, "vlog: config message not from a socket\n");
         return -1;
     }
-    recent = time(0) - 30;
+    recent = time_now() - 30;
     if (s.st_atime < recent || s.st_ctime < recent || s.st_mtime < recent) {
         fprintf(stderr, "vlog: config socket too old\n");
         return -1;
index 6e098ef..5216981 100644 (file)
@@ -43,6 +43,7 @@
 #include <syslog.h>
 #include <time.h>
 #include "dynamic-string.h"
+#include "timeval.h"
 #include "util.h"
 
 #define THIS_MODULE VLM_vlog
@@ -255,7 +256,7 @@ vlog_init(void)
     openlog(program_name, LOG_NDELAY, LOG_DAEMON);
     vlog_set_levels(VLM_ANY_MODULE, VLF_ANY_FACILITY, VLL_WARN);
 
-    now = time(0);
+    now = time_now();
     if (now < 0) {
         struct tm tm;
         char s[128];
@@ -323,7 +324,7 @@ vlog(enum vlog_module module, enum vlog_level level, const char *message, ...)
         char s[1024];
         size_t len, time_len;
 
-        now = time(0);
+        now = time_now();
         localtime_r(&now, &tm);
 
         len = time_len = strftime(s, sizeof s, "%b %d %H:%M:%S|", &tm);
index 6c0a70d..e4fc62f 100644 (file)
@@ -462,7 +462,7 @@ get_controller_mac(struct netdev *netdev, struct rconn *controller)
 
     uint32_t last_ip = ip;
 
-    time_t now = time(0);
+    time_t now = time_now();
 
     ip = rconn_get_ip(controller);
     if (last_ip != ip || !next_refresh || now >= next_refresh) {
index d0013d8..31b9af2 100644 (file)
@@ -48,6 +48,7 @@
 #include "rconn.h"
 #include "vconn.h"
 #include "table.h"
+#include "timeval.h"
 #include "xtoxll.h"
 
 #define THIS_MODULE VLM_datapath
@@ -191,7 +192,7 @@ dp_new(struct datapath **dp_, uint64_t dpid, struct rconn *rconn)
         return ENOMEM;
     }
 
-    dp->last_timeout = time(0);
+    dp->last_timeout = time_now();
     list_init(&dp->remotes);
     dp->controller = remote_create(dp, rconn);
     dp->listen_vconn = NULL;
@@ -269,7 +270,7 @@ dp_add_listen_vconn(struct datapath *dp, struct vconn *listen_vconn)
 void
 dp_run(struct datapath *dp)
 {
-    time_t now = time(0);
+    time_t now = time_now();
     struct sw_port *p, *pn;
     struct remote *r, *rn;
     struct buffer *buffer = NULL;
@@ -697,7 +698,7 @@ send_flow_expired(struct datapath *dp, struct sw_flow *flow,
     ofe->reason = reason;
     memset(ofe->pad, 0, sizeof ofe->pad);
 
-    ofe->duration     = htonl(time(0) - flow->created);
+    ofe->duration     = htonl(time_now() - flow->created);
     memset(ofe->pad2, 0, sizeof ofe->pad2);
     ofe->packet_count = htonll(flow->packet_count);
     ofe->byte_count   = htonll(flow->byte_count);
@@ -1078,7 +1079,7 @@ add_flow(struct datapath *dp, const struct ofp_flow_mod *ofm)
     flow->priority = flow->key.wildcards ? ntohs(ofm->priority) : -1;
     flow->idle_timeout = ntohs(ofm->idle_timeout);
     flow->hard_timeout = ntohs(ofm->hard_timeout);
-    flow->used = flow->created = time(0);
+    flow->used = flow->created = time_now();
     flow->n_actions = n_acts;
     flow->byte_count = 0;
     flow->packet_count = 0;
@@ -1174,7 +1175,7 @@ static int flow_stats_dump(struct datapath *dp, void *state,
 
     flow_extract_match(&match_key, &s->rq.match);
     s->buffer = buffer;
-    s->now = time(0);
+    s->now = time_now();
     while (s->table_idx < dp->chain->n_tables
            && (s->rq.table_id == 0xff || s->rq.table_id == s->table_idx))
     {
@@ -1585,7 +1586,7 @@ uint32_t save_buffer(struct buffer *buffer)
     if (p->buffer) {
         /* Don't buffer packet if existing entry is less than
          * OVERWRITE_SECS old. */
-        if (time(0) < p->timeout) { /* FIXME */
+        if (time_now() < p->timeout) { /* FIXME */
             return -1;
         } else {
             buffer_delete(p->buffer); 
@@ -1596,7 +1597,7 @@ uint32_t save_buffer(struct buffer *buffer)
     if (++p->cookie >= (1u << PKT_COOKIE_BITS) - 1)
         p->cookie = 0;
     p->buffer = buffer_clone(buffer);      /* FIXME */
-    p->timeout = time(0) + OVERWRITE_SECS; /* FIXME */
+    p->timeout = time_now() + OVERWRITE_SECS; /* FIXME */
     id = buffer_idx | (p->cookie << PKT_BUFFER_BITS);
 
     return id;
index 42ede87..eea201c 100644 (file)
@@ -40,6 +40,7 @@
 #include "buffer.h"
 #include "openflow.h"
 #include "packets.h"
+#include "timeval.h"
 
 /* Internal function used to compare fields in flow. */
 static inline
@@ -194,7 +195,7 @@ void print_flow(const struct sw_flow_key *key)
 
 bool flow_timeout(struct sw_flow *flow)
 {
-    time_t now = time(0);
+    time_t now = time_now();
     if (flow->idle_timeout != OFP_FLOW_PERMANENT
         && now > flow->used + flow->idle_timeout) {
         flow->reason = OFPER_IDLE_TIMEOUT;
@@ -210,7 +211,7 @@ bool flow_timeout(struct sw_flow *flow)
 
 void flow_used(struct sw_flow *flow, struct buffer *buffer)
 {
-    flow->used = time(0);
+    flow->used = time_now();
     flow->packet_count++;
     flow->byte_count += buffer->size;
 }