Commit 6a0f4f73 authored by Baptiste Jonglez's avatar Baptiste Jonglez

Piggyback a timestamp on all outgoing Hello messages

We use a sub-TLV to do so, which we fill out at the very last moment
to get an accurate timing.

This timestamp will be used to compute the RTT to our neighbours.
parent f5189545
......@@ -519,6 +519,21 @@ check_bucket(struct interface *ifp)
}
}
static int
fill_rtt_message(struct interface *ifp)
{
if(ifp->buffered_hello >= 0) {
unsigned int time;
/* Change the type of sub-TLV. */
ifp->sendbuf[ifp->buffered_hello + 8] = SUBTLV_TIMESTAMP;
gettime(&now);
time = time_us(now);
DO_HTONL(ifp->sendbuf + ifp->buffered_hello + 10, time);
return 1;
}
return 0;
}
void
flushbuf(struct interface *ifp)
{
......@@ -539,6 +554,7 @@ flushbuf(struct interface *ifp)
sin6.sin6_port = htons(protocol_port);
sin6.sin6_scope_id = ifp->ifindex;
DO_HTONS(packet_header + 2, ifp->buffered);
fill_rtt_message(ifp);
rc = babel_send(protocol_socket,
packet_header, sizeof(packet_header),
ifp->sendbuf, ifp->buffered,
......@@ -737,12 +753,17 @@ send_hello_noupdate(struct interface *ifp, unsigned interval)
debugf("Sending hello %d (%d) to %s.\n",
ifp->hello_seqno, interval, ifp->name);
start_message(ifp, MESSAGE_HELLO, 6);
start_message(ifp, MESSAGE_HELLO, 12);
ifp->buffered_hello = ifp->buffered - 2;
accumulate_short(ifp, 0);
accumulate_short(ifp, ifp->hello_seqno);
accumulate_short(ifp, interval > 0xFFFF ? 0xFFFF : interval);
end_message(ifp, MESSAGE_HELLO, 6);
/* Sub-TLV containing the local time of emission. We use a Pad4
sub-TLV, which we'll fill just before sending. */
accumulate_byte(ifp, SUBTLV_PADN);
accumulate_byte(ifp, 4);
accumulate_int(ifp, 0);
end_message(ifp, MESSAGE_HELLO, 12);
}
void
......
......@@ -44,6 +44,7 @@ THE SOFTWARE.
#define SUBTLV_PAD1 0
#define SUBTLV_PADN 1
#define SUBTLV_DIVERSITY 2 /* Also known as babelz. */
#define SUBTLV_TIMESTAMP 3 /* Used to compute RTT. */
extern unsigned short myseqno;
extern struct timeval seqno_time;
......
......@@ -66,6 +66,14 @@ seqno_plus(unsigned short s, int plus)
return ((s + plus) & 0xFFFF);
}
/* Returns a time in microseconds on 32 bits (thus modulo 2^32,
i.e. about 4295 seconds). */
static inline unsigned int
time_us(const struct timeval t)
{
return (unsigned int) (t.tv_sec * 1000000 + t.tv_usec);
}
int roughly(int value);
void timeval_minus(struct timeval *d,
const struct timeval *s1, const struct timeval *s2);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment