/home/aaron/olsrd-current/olsrd/src/core/olsr_clock.c File Reference

#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <time.h>
#include "os_time.h"
#include "olsr_logging.h"
#include "olsr.h"
#include "olsr_clock.h"
Include dependency graph for olsr_clock.c:

Go to the source code of this file.

Defines

#define OLSR_TIMEZONE_UNINITIALIZED   -1

Functions

static int olsr_get_timezone (void)
void olsr_clock_init (void)
void olsr_clock_update (void)
uint32_t olsr_clock_getNow (void)
int32_t olsr_clock_getRelative (uint32_t absolute)
bool olsr_clock_isPast (uint32_t absolute)
uint8_t olsr_clock_encode_olsrv1 (const uint32_t interval)
uint32_t olsr_clock_decode_olsrv1 (const uint8_t me)
char * olsr_clock_to_string (struct millitxt_buf *buffer, uint32_t t)
uint32_t olsr_clock_parse_string (char *txt)
const char * olsr_clock_getWallclockString (struct timeval_buf *buf)
const char * olsr_clock_toClockString (struct timeval_buf *buf, uint32_t clk)

Variables

static uint32_t now_times
static struct timeval first_tv
static struct timeval last_tv

Define Documentation

#define OLSR_TIMEZONE_UNINITIALIZED   -1

Referenced by olsr_get_timezone().


Function Documentation

uint32_t olsr_clock_decode_olsrv1 ( const uint8_t  me  ) 

Function for converting a mantissa/exponent 8bit value back to double as described in RFC3626:

value = C*(1+a/16)*2^b [in seconds]

where a is the integer represented by the four highest bits of the field and b the integer represented by the four lowest bits of the field.

me is the 8 bit mantissa/exponent value

To avoid expensive floating maths, we transform the equation: value = C * (1 + a / 16) * 2^b first, we make an int addition from the floating point addition: value = C * ((16 + a) / 16) * 2^b then we get rid of a pair of parentheses value = C * (16 + a) / 16 * 2^b and now we make an int multiplication from the floating point one value = C * (16 + a) * 2^b / 16 so that we can make a shift from the multiplication value = C * ((16 + a) << b) / 16 and sionce C and 16 are constants value = ((16 + a) << b) * C / 16

VTIME_SCALE_FACTOR = 1/16

=> value(ms) = ((16 + a) << b) / 256 * 1000

1. case: b >= 8 = ((16 + a) << (b-8)) * 1000

2. case: b <= 8 = ((16 + a) * 1000) >> (8-b)

Definition at line 249 of file olsr_clock.c.

References olsr_clock_encode_olsrv1().

Referenced by pkt_get_reltime().

Here is the call graph for this function:

uint8_t olsr_clock_encode_olsrv1 ( const uint32_t  interval  ) 

Function that converts a double to a mantissa/exponent product as described in RFC3626:

value = C*(1+a/16)*2^b [in seconds]

where a is the integer represented by the four highest bits of the field and b the integer represented by the four lowest bits of the field.

Parameters:
interval the time interval to process
Returns:
a 8-bit mantissa/exponent product

Definition at line 179 of file olsr_clock.c.

Referenced by olsr_clock_decode_olsrv1(), and pkt_put_reltime().

uint32_t olsr_clock_getNow ( void   ) 

Calculates the current time in the internal OLSR representation

Returns:
current time

Definition at line 117 of file olsr_clock.c.

References now_times.

Referenced by olsr_clock_getAbsolute(), olsr_timer_init(), olsr_timer_walk(), txtinfo_hna(), txtinfo_link(), txtinfo_mid(), and txtinfo_topology().

int32_t olsr_clock_getRelative ( uint32_t  absolute  ) 

Returns the number of milliseconds until the timestamp will happen

Parameters:
absolute timestamp
Returns:
milliseconds until event will happen, negative if it already happened.

Definition at line 128 of file olsr_clock.c.

References now_times.

Referenced by olsr_print_tc_table(), olsr_socket_handle(), and update_link_entry().

const char* olsr_clock_getWallclockString ( struct timeval_buf buf  ) 

Format an absolute wallclock system time string. May be called upto 4 times in a single printf() statement. Displays microsecond resolution.

Returns:
buffer to a formatted system time string.

Definition at line 311 of file olsr_clock.c.

References timeval_buf::buf, olsr_get_timezone(), and os_gettimeofday().

Referenced by olsr_calculate_routing_table(), olsr_print_duplicate_table(), olsr_print_hna_set(), olsr_print_link_set(), olsr_print_mid_set(), olsr_print_neighbor_table(), olsr_print_tc_table(), and olsr_timer_walk().

Here is the call graph for this function:

void olsr_clock_init ( void   ) 

Initialize olsr clock system

Definition at line 64 of file olsr_clock.c.

References first_tv, last_tv, LOG_TIMER, olsr_clock_update(), OLSR_ERROR, olsr_exit(), and os_gettimeofday().

Referenced by main().

Here is the call graph for this function:

bool olsr_clock_isPast ( uint32_t  absolute  ) 

Checks if a timestamp has already happened

Parameters:
absolute timestamp
Returns:
true if the event already happened, false otherwise

Definition at line 155 of file olsr_clock.c.

References now_times.

Referenced by check_interface_updates(), lookup_link_status(), olsr_timer_walk(), parse_challenge(), PrunePacketHistory(), and timeout_timestamps().

uint32_t olsr_clock_parse_string ( char *  txt  ) 

converts a floating point text into a unsigned integer representation (multiplied by 1000)

Definition at line 275 of file olsr_clock.c.

Referenced by parse_cfg_interface(), and parse_cfg_option().

char* olsr_clock_to_string ( struct millitxt_buf buffer,
uint32_t  t 
)

converts an unsigned integer value into a string representation (divided by 1000)

Definition at line 266 of file olsr_clock.c.

References millitxt_buf::buf.

Referenced by append_reltime(), build_config_body(), olsr_calculate_willingness(), olsr_print_tc_table(), olsr_sanity_check_cfg(), olsr_write_cnf_buf(), parse_cfg_option(), txtinfo_hna(), txtinfo_link(), txtinfo_mid(), and txtinfo_topology().

const char* olsr_clock_toClockString ( struct timeval_buf buf,
uint32_t  clk 
)

Format an relative non-wallclock system time string. Displays millisecond resolution.

Parameters:
absolute timestamp
Returns:
buffer to a formatted system time string.

Definition at line 335 of file olsr_clock.c.

References timeval_buf::buf, and MSEC_PER_SEC.

Referenced by olsr_print_duplicate_table(), olsr_timer_change(), and olsr_timer_start().

void olsr_clock_update ( void   ) 

Update the internal clock to current system time

Definition at line 78 of file olsr_clock.c.

References first_tv, last_tv, LOG_SCHEDULER, now_times, OLSR_ERROR, olsr_exit(), OLSR_WARN, and os_gettimeofday().

Referenced by main(), olsr_clock_init(), and olsr_socket_handle().

Here is the call graph for this function:

static int olsr_get_timezone ( void   )  [static]

Returns the difference between gmt and local time in seconds. Use gmtime() and localtime() to keep things simple.

taken and slightly modified from www.tcpdump.org.

Definition at line 353 of file olsr_clock.c.

References OLSR_TIMEZONE_UNINITIALIZED.

Referenced by olsr_clock_getWallclockString().


Variable Documentation

struct timeval first_tv [static]

Definition at line 55 of file olsr_clock.c.

Referenced by olsr_clock_init(), and olsr_clock_update().

struct timeval last_tv [static]

Definition at line 56 of file olsr_clock.c.

Referenced by olsr_clock_init(), and olsr_clock_update().

uint32_t now_times [static]
Generated on Sat May 25 06:00:05 2013 for olsrd by  doxygen 1.6.3