#include "netdev.h"
#include "ofp-print.h"
#include "poll-loop.h"
+#include "timeval.h"
#define THIS_MODULE VLM_dhcp_client
#include "vlog.h"
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;
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)) {
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;
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) {
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
#include "openflow.h"
#include "queue.h"
#include "rconn.h"
+#include "timeval.h"
#include "vconn.h"
#include "xtoxll.h"
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;
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;
#include "buffer.h"
#include "netlink-protocol.h"
#include "dynamic-string.h"
+#include "timeval.h"
#include "util.h"
#include "vlog.h"
if (next_seq == 0) {
/* Pick initial sequence number. */
- next_seq = getpid() ^ time(0);
+ next_seq = getpid() ^ time_now();
}
*sockp = NULL;
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");
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;
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);
}
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));
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;
}
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);
}
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
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) {
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
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
{
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
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;
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;
#include <syslog.h>
#include <time.h>
#include "dynamic-string.h"
+#include "timeval.h"
#include "util.h"
#define THIS_MODULE VLM_vlog
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];
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);
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) {
#include "rconn.h"
#include "vconn.h"
#include "table.h"
+#include "timeval.h"
#include "xtoxll.h"
#define THIS_MODULE VLM_datapath
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;
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;
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);
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;
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))
{
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);
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;
#include "buffer.h"
#include "openflow.h"
#include "packets.h"
+#include "timeval.h"
/* Internal function used to compare fields in flow. */
static inline
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;
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;
}