convert all time related datastructure to struct timeval

This commit is contained in:
Christian Mehlis 2013-11-30 01:22:17 +01:00
parent af8e36b3e0
commit 2f7fd0b35c
7 changed files with 48 additions and 55 deletions

View File

@ -68,7 +68,7 @@ ccnl_run_events(void)
static struct timeval now; static struct timeval now;
long usec; long usec;
rtc_time(&now); ccnl_get_timeval(&now);
DEBUGMSG(1, "ccnl_run_events now: %ld:%ld\n", now.tv_sec, now.tv_usec); DEBUGMSG(1, "ccnl_run_events now: %ld:%ld\n", now.tv_sec, now.tv_usec);
while (eventqueue) { while (eventqueue) {
@ -382,10 +382,9 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl)
*/ */
void ccnl_riot_relay_start(int max_cache_entries, int fib_threshold_prefix, int fib_threshold_aggregate) void ccnl_riot_relay_start(int max_cache_entries, int fib_threshold_prefix, int fib_threshold_aggregate)
{ {
struct timeval now; ccnl_get_timeval(&theRelay.startup_time);
theRelay.startup_time = rtc_time(&now);
DEBUGMSG(1, "This is ccn-lite-relay, starting at %lu:%lu\n", now.tv_sec, now.tv_usec); DEBUGMSG(1, "This is ccn-lite-relay, starting at %lu:%lu\n", theRelay.startup_time.tv_sec, theRelay.startup_time.tv_usec);
DEBUGMSG(1, " compile time: %s %s\n", __DATE__, __TIME__); DEBUGMSG(1, " compile time: %s %s\n", __DATE__, __TIME__);
DEBUGMSG(1, " max_cache_entries: %d\n", max_cache_entries); DEBUGMSG(1, " max_cache_entries: %d\n", max_cache_entries);
DEBUGMSG(1, " threshold_prefix: %d\n", fib_threshold_prefix); DEBUGMSG(1, " threshold_prefix: %d\n", fib_threshold_prefix);

View File

@ -394,7 +394,7 @@ ccnl_get_face_or_create(struct ccnl_relay_s *ccnl, int ifndx, uint16_t sender_id
if (ifndx == f->ifndx && (f->faceid == sender_id)) { if (ifndx == f->ifndx && (f->faceid == sender_id)) {
DEBUGMSG(1, "face found! ifidx=%d sender_id=%d faceid=%d\n", ifndx, sender_id, f->faceid); DEBUGMSG(1, "face found! ifidx=%d sender_id=%d faceid=%d\n", ifndx, sender_id, f->faceid);
f->last_used = CCNL_NOW(); ccnl_get_timeval(&f->last_used);
return f; return f;
} }
} }
@ -459,7 +459,7 @@ ccnl_get_face_or_create(struct ccnl_relay_s *ccnl, int ifndx, uint16_t sender_id
#endif #endif
f->last_used = CCNL_NOW(); ccnl_get_timeval(&f->last_used);
DBL_LINKED_LIST_ADD(ccnl->faces, f); DBL_LINKED_LIST_ADD(ccnl->faces, f);
return f; return f;
@ -738,7 +738,7 @@ ccnl_interest_new(struct ccnl_relay_s *ccnl, struct ccnl_face_s *from,
*ppkd = 0; *ppkd = 0;
i->minsuffix = minsuffix; i->minsuffix = minsuffix;
i->maxsuffix = maxsuffix; i->maxsuffix = maxsuffix;
i->last_used = CCNL_NOW(); ccnl_get_timeval(&i->last_used);
DBL_LINKED_LIST_ADD(ccnl->pit, i); DBL_LINKED_LIST_ADD(ccnl->pit, i);
return i; return i;
} }
@ -752,7 +752,7 @@ int ccnl_interest_append_pending(struct ccnl_interest_s *i,
for (pi = i->pending; pi; pi = pi->next) { // check whether already listed for (pi = i->pending; pi; pi = pi->next) { // check whether already listed
if (pi->face == from) { if (pi->face == from) {
DEBUGMSG(40, " we found a matching interest, updating time\n"); DEBUGMSG(40, " we found a matching interest, updating time\n");
pi->last_used = CCNL_NOW(); ccnl_get_timeval(&pi->last_used);
return 0; return 0;
} }
@ -768,7 +768,7 @@ int ccnl_interest_append_pending(struct ccnl_interest_s *i,
} }
pi->face = from; pi->face = from;
pi->last_used = CCNL_NOW(); ccnl_get_timeval(&pi->last_used);
if (last) { if (last) {
last->next = pi; last->next = pi;
@ -890,7 +890,7 @@ ccnl_content_new(struct ccnl_relay_s *ccnl, struct ccnl_buf_s **pkt,
return NULL; return NULL;
} }
c->last_used = CCNL_NOW(); ccnl_get_timeval(&c->last_used);
c->content = content; c->content = content;
c->contentlen = contlen; c->contentlen = contlen;
c->pkt = *pkt; c->pkt = *pkt;
@ -1107,6 +1107,12 @@ ccnl_forward_remove(struct ccnl_relay_s *ccnl, struct ccnl_forward_s *fwd)
return fwd2; return fwd2;
} }
bool ccnl_is_timeouted(struct timeval *now, struct timeval *last_used, time_t timeout_s, time_t timeout_us)
{
struct timeval abs_timeout = { last_used->tv_sec + timeout_s, last_used->tv_usec + timeout_us };
return timevaldelta(now, &abs_timeout) > 0;
}
void ccnl_do_ageing(void *ptr, void *dummy) void ccnl_do_ageing(void *ptr, void *dummy)
{ {
@ -1116,11 +1122,12 @@ void ccnl_do_ageing(void *ptr, void *dummy)
struct ccnl_content_s *c = relay->contents; struct ccnl_content_s *c = relay->contents;
struct ccnl_interest_s *i = relay->pit; struct ccnl_interest_s *i = relay->pit;
struct ccnl_face_s *f = relay->faces; struct ccnl_face_s *f = relay->faces;
time_t t = CCNL_NOW(); struct timeval now;
DEBUGMSG(999, "ccnl_do_ageing %d\n", (int) t); ccnl_get_timeval(&now);
DEBUGMSG(999, "ccnl_do_ageing %ld:%ld\n", now.tv_sec, now.tv_usec);
while (c) { while (c) {
if ((c->last_used + CCNL_CONTENT_TIMEOUT) <= t if (ccnl_is_timeouted(&now, &c->last_used, CCNL_CONTENT_TIMEOUT_SEC, CCNL_CONTENT_TIMEOUT_USEC)
&& !(c->flags & CCNL_CONTENT_FLAGS_STATIC)) { && !(c->flags & CCNL_CONTENT_FLAGS_STATIC)) {
c = ccnl_content_remove(relay, c); c = ccnl_content_remove(relay, c);
} }
@ -1131,7 +1138,7 @@ void ccnl_do_ageing(void *ptr, void *dummy)
while (i) { // CONFORM: "Entries in the PIT MUST timeout rather while (i) { // CONFORM: "Entries in the PIT MUST timeout rather
// than being held indefinitely." // than being held indefinitely."
if ((i->last_used + CCNL_INTEREST_TIMEOUT) <= t || if (ccnl_is_timeouted(&now, &i->last_used, CCNL_INTEREST_TIMEOUT_SEC, CCNL_INTEREST_TIMEOUT_SEC) ||
i->retries > CCNL_MAX_INTEREST_RETRANSMIT) { i->retries > CCNL_MAX_INTEREST_RETRANSMIT) {
i = ccnl_interest_remove(relay, i); i = ccnl_interest_remove(relay, i);
} }
@ -1154,7 +1161,7 @@ void ccnl_do_ageing(void *ptr, void *dummy)
while (f) { while (f) {
if (!(f->flags & CCNL_FACE_FLAGS_STATIC) if (!(f->flags & CCNL_FACE_FLAGS_STATIC)
&& (f->last_used + CCNL_FACE_TIMEOUT) <= t) { && ccnl_is_timeouted(&now, &f->last_used, CCNL_FACE_TIMEOUT_SEC, CCNL_FACE_TIMEOUT_USEC)) {
f = ccnl_face_remove(relay, f); f = ccnl_face_remove(relay, f);
} }
else { else {

View File

@ -52,6 +52,7 @@ enum {STAT_RCV_I, STAT_RCV_C, STAT_SND_I, STAT_SND_C, STAT_QLEN, STAT_EOP1};
#include <inttypes.h> #include <inttypes.h>
#include <time.h> #include <time.h>
#include <sys/time.h>
#include "ccnl.h" #include "ccnl.h"
@ -84,7 +85,7 @@ struct ccnl_if_s { // interface for packet IO
}; };
struct ccnl_relay_s { struct ccnl_relay_s {
time_t startup_time; struct timeval startup_time;
int id; int id;
struct ccnl_face_s *faces; struct ccnl_face_s *faces;
struct ccnl_forward_s *fib; struct ccnl_forward_s *fib;
@ -146,7 +147,7 @@ struct ccnl_face_s {
int ifndx; int ifndx;
sockunion peer; sockunion peer;
int flags; int flags;
int last_used; // updated when we receive a packet struct timeval last_used; // updated when we receive a packet
struct ccnl_buf_s *outq, *outqend; // queue of packets to send struct ccnl_buf_s *outq, *outqend; // queue of packets to send
struct ccnl_frag_s *frag; // which special datagram armoring struct ccnl_frag_s *frag; // which special datagram armoring
struct ccnl_sched_s *sched; struct ccnl_sched_s *sched;
@ -168,7 +169,7 @@ struct ccnl_interest_s {
int minsuffix, maxsuffix; int minsuffix, maxsuffix;
struct ccnl_buf_s *ppkd; // publisher public key digest struct ccnl_buf_s *ppkd; // publisher public key digest
struct ccnl_buf_s *pkt; // full datagram struct ccnl_buf_s *pkt; // full datagram
int last_used; struct timeval last_used;
int retries; int retries;
struct ccnl_forward_s *forwarded_over; struct ccnl_forward_s *forwarded_over;
}; };
@ -176,7 +177,7 @@ struct ccnl_interest_s {
struct ccnl_pendint_s { // pending interest struct ccnl_pendint_s { // pending interest
struct ccnl_pendint_s *next; // , *prev; struct ccnl_pendint_s *next; // , *prev;
struct ccnl_face_s *face; struct ccnl_face_s *face;
int last_used; struct timeval last_used;
}; };
struct ccnl_content_s { struct ccnl_content_s {
@ -189,7 +190,7 @@ struct ccnl_content_s {
int contentlen; int contentlen;
// NON-CONFORM: "The [ContentSTore] MUST also implement the Staleness Bit." // NON-CONFORM: "The [ContentSTore] MUST also implement the Staleness Bit."
// >> CCNL: currently no stale bit, old content is fully removed << // >> CCNL: currently no stale bit, old content is fully removed <<
int last_used; struct timeval last_used;
int served_cnt; int served_cnt;
}; };

View File

@ -26,7 +26,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "rtc.h"
#include "sha256.h" #include "sha256.h"
#define RIOT_MSG_DEV (1) #define RIOT_MSG_DEV (1)

View File

@ -62,8 +62,7 @@ ccnl_set_timer(int usec, void (*fct)(void *aux1, void *aux2),
} }
t->fct2 = fct; t->fct2 = fct;
//gettimeofday(&t->timeout, NULL); ccnl_get_timeval(&t->timeout);
rtc_time(&t->timeout);
usec += t->timeout.tv_usec; usec += t->timeout.tv_usec;
t->timeout.tv_sec += usec / 1000000; t->timeout.tv_sec += usec / 1000000;
t->timeout.tv_usec = usec % 1000000; t->timeout.tv_usec = usec % 1000000;
@ -133,30 +132,14 @@ ccnl_rem_timer(void *h)
} }
} }
double
current_time(void)
{
struct timeval tv;
static time_t start;
static time_t start_usec;
ccnl_get_timeval(&tv);
if (!start) {
start = tv.tv_sec;
start_usec = tv.tv_usec;
}
return (double)(tv.tv_sec) - start +
((double)(tv.tv_usec) - start_usec) / 1000000;
}
char * char *
timestamp(void) timestamp(void)
{ {
static char ts[30], *cp; static char ts[30], *cp;
struct timeval now;
ccnl_get_timeval(&now);
sprintf(ts, "%.4g", CCNL_NOW()); sprintf(ts, "%.4lu", (time_t) 100000 * now.tv_sec + now.tv_usec);
cp = strchr(ts, '.'); cp = strchr(ts, '.');
if (!cp) { if (!cp) {

View File

@ -20,9 +20,6 @@
#include <sys/time.h> #include <sys/time.h>
double current_time(void);
#define CCNL_NOW() current_time()
// (ms) I moved the following struct def here because it is used by all // (ms) I moved the following struct def here because it is used by all
// containers apart from the kernel (this way I don't need to redefine it // containers apart from the kernel (this way I don't need to redefine it
// for omnet. // for omnet.
@ -39,6 +36,8 @@ struct ccnl_timer_s {
int handler; int handler;
}; };
void ccnl_get_timeval(struct timeval *tv);
long timevaldelta(struct timeval *a, struct timeval *b); long timevaldelta(struct timeval *a, struct timeval *b);
void *ccnl_set_timer(int usec, void (*fct)(void *aux1, void *aux2), void *ccnl_set_timer(int usec, void (*fct)(void *aux1, void *aux2),

View File

@ -21,21 +21,26 @@
* 2011-03-30 created * 2011-03-30 created
*/ */
#define CCNL_MAX_INTERFACES 10 #define CCNL_MAX_INTERFACES 2 /* transceiver and msg interfaces */
#define CCNL_MAX_PACKET_SIZE NATIVE_MAX_DATA_LENGTH
#define CCNL_CONTENT_TIMEOUT 30 // sec #define CCNL_CONTENT_TIMEOUT_SEC 2
#define CCNL_INTEREST_TIMEOUT 4 // sec #define CCNL_CONTENT_TIMEOUT_USEC 0
#define CCNL_MAX_INTEREST_RETRANSMIT 2
#define CCNL_FACE_TIMEOUT 15 // sec #define CCNL_INTEREST_TIMEOUT_SEC 2
#define CCNL_INTEREST_TIMEOUT_USEC 2
#define CCNL_MAX_NAME_COMP 16 #define CCNL_MAX_INTEREST_RETRANSMIT 4
#define CCNL_MAX_IF_QLEN 64
#define CCNL_DEFAULT_MAX_CACHE_ENTRIES 0 // means: no content caching #define CCNL_FACE_TIMEOUT_SEC 10
#define CCNL_MAX_NONCES 256 // for detected dups #define CCNL_FACE_TIMEOUT_USEC 0
#define CCNL_FWD_TIMEOUT_SEC 10
#define CCNL_FWD_TIMEOUT_USEC 0
#define CCNL_MAX_NAME_COMP 16
#define CCNL_MAX_IF_QLEN 64
#define CCNL_MAX_NONCES 256 // for detected dups
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// our own CCN-lite extensions for the ccnb encoding: // our own CCN-lite extensions for the ccnb encoding: