Revision c8236a50

View differences:

proto/bgp/bgp.c
399 399
}
400 400

  
401 401
void
402
bgp_start_ms_timer(timer *t, uint value)
402
bgp_start_ms_timer(timer *t, uint value, uint jitter)
403 403
{
404 404
    if (value)
405 405
    {
406 406
        /* The randomization procedure is specified in RFC 4271 section 10 */
407 407
        btime time = value MS;
408
        btime randomize = random() % ((time / 20) + 1);
408
        if(jitter > 100){
409
            jitter = 25;
410
        } else if(jitter == 0) {
411
            jitter = 1;
412
        }
413
        int divisor = 100 / jitter;
414
        log(L_INFO "divisor: %d", divisor);
415
        btime randomize = random() % ((time / divisor) + 1);
409 416
        log(L_INFO "Timer avviato con un delay di %d ms", time - randomize);
410 417
        tm_start(t, time - randomize);
411 418
    }
proto/bgp/bgp.h
103 103
  unsigned hold_time, initial_hold_time;
104 104
  unsigned mrai_time;       /* MRAI TIMER */
105 105
  unsigned mrai_type;       /* MRAI TYPE, 0 PEER-BASED MRAI, !0 DESTINATION-BASED mrai */
106
  unsigned mrai_jitter;
106 107
  unsigned keepalive_time;
107 108
  unsigned error_amnesia_time;		/* Errors are forgotten after */
108 109
  unsigned error_delay_time_min;	/* Time to wait after an error is detected */
......
459 460

  
460 461

  
461 462
void bgp_start_timer(timer *t, uint value);
462
void bgp_start_ms_timer(timer *t, uint value);
463
void bgp_start_ms_timer(timer *t, uint value, uint jitter);
463 464
void bgp_check_config(struct bgp_config *c);
464 465
void bgp_error(struct bgp_conn *c, unsigned code, unsigned subcode, byte *data, int len);
465 466
void bgp_close_conn(struct bgp_conn *c);
proto/bgp/config.Y
28 28
	BGP_CLUSTER_LIST, IGP, TABLE, GATEWAY, DIRECT, RECURSIVE, MED, TTL,
29 29
	SECURITY, DETERMINISTIC, SECONDARY, ALLOW, BFD, ADD, PATHS, RX, TX,
30 30
	GRACEFUL, RESTART, AWARE, CHECK, LINK, PORT, EXTENDED, MESSAGES, SETKEY,
31
	STRICT, BIND, CONFEDERATION, MEMBER, MULTICAST, FLOW4, FLOW6)
31
	STRICT, BIND, CONFEDERATION, MEMBER, MULTICAST, FLOW4, FLOW6, JITTER)
32 32

  
33 33
%type <i32> bgp_afi
34 34

  
......
44 44
     BGP_CFG->hold_time = 240;
45 45
     BGP_CFG->mrai_time = 0;
46 46
     BGP_CFG->mrai_type = 0;
47
     BGP_CFG->mrai_jitter = 25;
47 48
     BGP_CFG->initial_hold_time = 240;
48 49
     BGP_CFG->compare_path_lengths = 1;
49 50
     BGP_CFG->igp_metric = 1;
......
101 102
 | bgp_proto HOLD TIME expr ';' { BGP_CFG->hold_time = $4; }
102 103
 | bgp_proto MRAI TIME expr ';' { BGP_CFG->mrai_time = $4; }
103 104
 | bgp_proto MRAI TYPE expr ';' { BGP_CFG->mrai_type = $4; }
105
 | bgp_proto MRAI JITTER expr ';' { BGP_CFG->mrai_jitter = $4; if (($4<1) || ($4>100)) cf_error("jitter must be in range 1-100");}
104 106
 | bgp_proto STARTUP HOLD TIME expr ';' { BGP_CFG->initial_hold_time = $5; }
105 107
 | bgp_proto DIRECT ';' { BGP_CFG->multihop = 0; }
106 108
 | bgp_proto MULTIHOP ';' { BGP_CFG->multihop = 64; }
proto/bgp/packets.c
1408 1408

  
1409 1409
                /* Timer settings */
1410 1410
                tmp_prefix->dest_mrai_timer = tm_new_init(proto_pool, dest_mrai_timeout, &tmp_prefix->connections, 0, 0);
1411
                bgp_start_ms_timer(tmp_prefix->dest_mrai_timer, conn->bgp->cf->mrai_time);
1411
                bgp_start_ms_timer(tmp_prefix->dest_mrai_timer, conn->bgp->cf->mrai_time, conn->bgp->cf->mrai_jitter);
1412 1412
                HASH_INSERT2(sent_prefix_hash, PXH, proto_pool, tmp_prefix);
1413 1413

  
1414 1414
                /* Add prefix to the delayed bucket */
......
1450 1450
                    tmp_prefix->end_mrai = current_time() + conn->bgp->cf->mrai_time MS;
1451 1451

  
1452 1452
                    tmp_prefix->dest_mrai_timer = tm_new_init(proto_pool, dest_mrai_timeout, &tmp_prefix->connections, 0, 0);
1453
                    bgp_start_ms_timer(tmp_prefix->dest_mrai_timer, conn->bgp->cf->mrai_time);
1453
                    bgp_start_ms_timer(tmp_prefix->dest_mrai_timer, conn->bgp->cf->mrai_time, conn->bgp->cf->mrai_jitter);
1454 1454

  
1455 1455
                    /* Encode path ID */
1456 1456
                    if (s->add_path) {
......
3522 3522
                                    BGP_TRACE(D_PACKETS,
3523 3523
                                              "CONFERMATO PKT UPDATE, avvio il timer considerando un delay di %d ms",
3524 3524
                                              conn->bgp->cf->mrai_time);
3525
                                    bgp_start_ms_timer(conn->conn_mrai_timer, conn->bgp->cf->mrai_time);
3525
                                    bgp_start_ms_timer(conn->conn_mrai_timer, conn->bgp->cf->mrai_time, conn->bgp->cf->mrai_jitter);
3526 3526
                                }
3527 3527
                                log(L_FATAL
3528 3528
                                "{type: UPDATE_TX, dest: %s, to: %d, as_path: %s}", dest_ip, p->remote_as, buf_as_path);

Also available in: Unified diff