Commit 25573e36 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Implemented resending of requests.

parent c519a4b9
...@@ -415,6 +415,8 @@ main(int argc, char **argv) ...@@ -415,6 +415,8 @@ main(int argc, char **argv)
tv = check_neighbours_time; tv = check_neighbours_time;
timeval_min_sec(&tv, expiry_time); timeval_min_sec(&tv, expiry_time);
if(request_resend_time)
timeval_min_sec(&tv, request_resend_time);
for(i = 0; i < numnets; i++) { for(i = 0; i < numnets; i++) {
timeval_min(&tv, &nets[i].flush_time); timeval_min(&tv, &nets[i].flush_time);
timeval_min_sec(&tv, timeval_min_sec(&tv,
...@@ -517,6 +519,9 @@ main(int argc, char **argv) ...@@ -517,6 +519,9 @@ main(int argc, char **argv)
} }
} }
if(now.tv_sec >= request_resend_time)
resend_requests();
if(update_flush_time.tv_sec != 0) { if(update_flush_time.tv_sec != 0) {
if(now.tv_sec >= update_flush_time.tv_sec) if(now.tv_sec >= update_flush_time.tv_sec)
flushupdates(); flushupdates();
......
...@@ -250,7 +250,7 @@ handle_request(struct neighbour *neigh, const unsigned char *prefix, ...@@ -250,7 +250,7 @@ handle_request(struct neighbour *neigh, const unsigned char *prefix,
send_unicast_request(route->nexthop, prefix, plen, send_unicast_request(route->nexthop, prefix, plen,
hop_count - 1, seqno, router_hash); hop_count - 1, seqno, router_hash);
record_request(prefix, plen, seqno, router_hash, record_request(prefix, plen, seqno, router_hash,
neigh->network); neigh->network, 0);
} }
} else { } else {
send_update(neigh->network, 1, prefix, plen); send_update(neigh->network, 1, prefix, plen);
...@@ -456,6 +456,14 @@ send_request(struct network *net, ...@@ -456,6 +456,14 @@ send_request(struct network *net,
send_message(net, 2, 0xFF, 0, 0, 0, ones); send_message(net, 2, 0xFF, 0, 0, 0, ones);
} }
void
send_request_resend(const unsigned char *prefix, unsigned char plen,
unsigned short seqno, unsigned short router_hash)
{
send_request(NULL, prefix, plen, 127, seqno, router_hash);
record_request(prefix, plen, seqno, router_hash, NULL, 2);
}
static void static void
send_unicast_packet(struct neighbour *neigh, unsigned char *buf, int buflen) send_unicast_packet(struct neighbour *neigh, unsigned char *buf, int buflen)
{ {
......
...@@ -45,6 +45,8 @@ void send_request(struct network *net, ...@@ -45,6 +45,8 @@ void send_request(struct network *net,
const unsigned char *prefix, unsigned char plen, const unsigned char *prefix, unsigned char plen,
unsigned char hop_count, unsigned short seqno, unsigned char hop_count, unsigned short seqno,
unsigned short router_hash); unsigned short router_hash);
void send_request_resend(const unsigned char *prefix, unsigned char plen,
unsigned short seqno, unsigned short router_hash);
void send_unicast_request(struct neighbour *neigh, void send_unicast_request(struct neighbour *neigh,
const unsigned char *prefix, unsigned char plen, const unsigned char *prefix, unsigned char plen,
unsigned char hop_count, unsigned short seqno, unsigned char hop_count, unsigned short seqno,
......
...@@ -29,7 +29,9 @@ THE SOFTWARE. ...@@ -29,7 +29,9 @@ THE SOFTWARE.
#include "util.h" #include "util.h"
#include "neighbour.h" #include "neighbour.h"
#include "request.h" #include "request.h"
#include "message.h"
int request_resend_time = 0;
struct request *recorded_requests = NULL; struct request *recorded_requests = NULL;
static int static int
...@@ -63,19 +65,25 @@ find_request(const unsigned char *prefix, unsigned char plen, ...@@ -63,19 +65,25 @@ find_request(const unsigned char *prefix, unsigned char plen,
int int
record_request(const unsigned char *prefix, unsigned char plen, record_request(const unsigned char *prefix, unsigned char plen,
unsigned short seqno, unsigned short router_hash, unsigned short seqno, unsigned short router_hash,
struct network *network) struct network *network, int resend)
{ {
struct request *request; struct request *request;
request = find_request(prefix, plen, NULL); request = find_request(prefix, plen, NULL);
if(request) { if(request) {
if(request->resend && resend)
request->resend = MIN(request->resend, resend);
else if(resend)
request->resend = resend;
request->time = now.tv_sec;
request_resend_time = MIN(request_resend_time,
request->time + request->resend);
if(request->router_hash == router_hash && if(request->router_hash == router_hash &&
seqno_compare(request->seqno, seqno) > 0) { seqno_compare(request->seqno, seqno) > 0) {
return 0; return 0;
} else { } else {
request->router_hash = router_hash; request->router_hash = router_hash;
request->seqno = seqno; request->seqno = seqno;
request->time = now.tv_sec;
if(request->network != network) if(request->network != network)
request->network = NULL; request->network = NULL;
return 1; return 1;
...@@ -88,8 +96,11 @@ record_request(const unsigned char *prefix, unsigned char plen, ...@@ -88,8 +96,11 @@ record_request(const unsigned char *prefix, unsigned char plen,
request->plen = plen; request->plen = plen;
request->seqno = seqno; request->seqno = seqno;
request->router_hash = router_hash; request->router_hash = router_hash;
request->time = now.tv_sec;
request->network = network; request->network = network;
request->time = now.tv_sec;
request->resend = resend;
if(resend)
request_resend_time = MIN(request_resend_time, now.tv_sec + resend);
request->next = recorded_requests; request->next = recorded_requests;
recorded_requests = request; recorded_requests = request;
return 1; return 1;
...@@ -117,6 +128,7 @@ satisfy_request(const unsigned char *prefix, unsigned char plen, ...@@ -117,6 +128,7 @@ satisfy_request(const unsigned char *prefix, unsigned char plen,
else else
previous->next = request->next; previous->next = request->next;
free(request); free(request);
recompute_request_resend_time();
return 1; return 1;
} }
...@@ -127,11 +139,12 @@ void ...@@ -127,11 +139,12 @@ void
expire_requests() expire_requests()
{ {
struct request *request, *previous; struct request *request, *previous;
int recompute = 0;
previous = NULL; previous = NULL;
request = recorded_requests; request = recorded_requests;
while(request) { while(request) {
if(request->time < now.tv_sec - 60) { if(request->time < now.tv_sec - REQUEST_TIMEOUT) {
if(previous == NULL) { if(previous == NULL) {
recorded_requests = request->next; recorded_requests = request->next;
free(request); free(request);
...@@ -146,5 +159,43 @@ expire_requests() ...@@ -146,5 +159,43 @@ expire_requests()
request = request->next; request = request->next;
} }
} }
if(recompute)
recompute_request_resend_time();
}
int
recompute_request_resend_time()
{
struct request *request;
int resend = 0;
request = recorded_requests;
while(request) {
if(request->resend) {
if(resend)
resend = MIN(resend, request->time + request->resend);
else
resend = request->time + request->resend;
}
request = request->next;
}
request_resend_time = resend;
return resend;
} }
void
resend_requests()
{
struct request *request;
request = recorded_requests;
while(request) {
if(request->resend && now.tv_sec >= request->time + request->resend) {
send_request(NULL, request->prefix, request->plen, 127,
request->seqno, request->router_hash);
request->resend = 2 * request->resend;
}
request = request->next;
}
}
...@@ -20,6 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ...@@ -20,6 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
#define REQUEST_TIMEOUT 128
struct request { struct request {
unsigned char prefix[16]; unsigned char prefix[16];
unsigned char plen; unsigned char plen;
...@@ -27,18 +29,20 @@ struct request { ...@@ -27,18 +29,20 @@ struct request {
unsigned short router_hash; unsigned short router_hash;
struct network *network; struct network *network;
int time; int time;
int resend;
struct request *next; struct request *next;
}; };
extern int request_resend_time;
struct request *find_request(const unsigned char *prefix, unsigned char plen, struct request *find_request(const unsigned char *prefix, unsigned char plen,
struct request **previous_return); struct request **previous_return);
int record_request(const unsigned char *prefix, unsigned char plen, int record_request(const unsigned char *prefix, unsigned char plen,
unsigned short seqno, unsigned short router_hash, unsigned short seqno, unsigned short router_hash,
struct network *net); struct network *net, int resend);
int satisfy_request(const unsigned char *prefix, unsigned char plen, int satisfy_request(const unsigned char *prefix, unsigned char plen,
unsigned short seqno, unsigned short router_hash, unsigned short seqno, unsigned short router_hash,
struct network *net); struct network *net);
void expire_requests(void); void expire_requests(void);
int recompute_request_resend_time(void);
...@@ -462,10 +462,10 @@ send_triggered_update(struct route *route, struct source *oldsrc, int oldmetric) ...@@ -462,10 +462,10 @@ send_triggered_update(struct route *route, struct source *oldsrc, int oldmetric)
if(oldmetric < INFINITY) { if(oldmetric < INFINITY) {
if(newmetric >= INFINITY) if(newmetric >= INFINITY)
send_request(NULL, route->src->prefix, route->src->plen, send_request_resend(route->src->prefix, route->src->plen,
127,
route->src->metric >= INFINITY ? route->src->metric >= INFINITY ?
route->src->seqno : seqno_plus(route->src->seqno, 1), route->src->seqno :
seqno_plus(route->src->seqno, 1),
hash_id(route->src->address)); hash_id(route->src->address));
else if(newmetric >= oldmetric + 384) else if(newmetric >= oldmetric + 384)
send_request(NULL, route->src->prefix, route->src->plen, send_request(NULL, route->src->prefix, route->src->plen,
...@@ -512,7 +512,7 @@ route_lost(struct source *src, int oldmetric) ...@@ -512,7 +512,7 @@ route_lost(struct source *src, int oldmetric)
/* Complain loudly. */ /* Complain loudly. */
send_update(NULL, 1, src->prefix, src->plen); send_update(NULL, 1, src->prefix, src->plen);
if(oldmetric < INFINITY) if(oldmetric < INFINITY)
send_request(NULL, src->prefix, src->plen, 127, send_request_resend(src->prefix, src->plen,
src->metric >= INFINITY ? src->metric >= INFINITY ?
src->seqno : seqno_plus(src->seqno, 1), src->seqno : seqno_plus(src->seqno, 1),
hash_id(src->address)); hash_id(src->address));
......
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