Skip to content

Commit 71c2819

Browse files
committed
Bgp: refactor: split restartsConnectRetryTimer(bool); rename restart* timers
The bool argument of restartsConnectRetryTimer(bool start) was inverted and confusing: start=true cancelled the timer, start=false rescheduled it. Replace it with two clearly named methods: - restartConnectRetryTimer() -- cancel + reschedule at connectRetryTime - stopConnectRetryTimer() -- cancel Also fix the grammar of the sibling timer methods: restartsHoldTimer -> restartHoldTimer, restartsKeepAliveTimer -> restartKeepAliveTimer. Pure rename, no behavior change: call sites mapped (false) -> restartConnectRetryTimer(), () / (true) -> stopConnectRetryTimer().
1 parent d3e6854 commit 71c2819

3 files changed

Lines changed: 40 additions & 37 deletions

File tree

src/inet/routing/bgpv4/BgpFsm.cc

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void Idle::ManualStart()
3232
// - sets ConnectRetryCounter to zero,
3333
session._connectRetryCounter = 0;
3434
// - starts the ConnectRetryTimer with the initial value,
35-
session.restartsConnectRetryTimer();
35+
session.stopConnectRetryTimer();
3636
// - listens for a connection that may be initiated by the remote BGP peer,
3737
session.listenConnectionFromPeer();
3838
// - initiates a TCP connection to the other BGP peer and,
@@ -50,7 +50,7 @@ void Connect::ConnectRetryTimer_Expires()
5050
// - drops the TCP connection,
5151
session._info.socket->abort();
5252
// - restarts the ConnectRetryTimer,
53-
session.restartsConnectRetryTimer();
53+
session.stopConnectRetryTimer();
5454
// - initiates a TCP connection to the other BGP peer,
5555
// session._info.socket->renewSocket();
5656
session.openTCPConnectionToPeer();
@@ -66,7 +66,7 @@ void Connect::HoldTimer_Expires()
6666
// In response to any other events (Events 8, 10-11, 13, 19, 23, 25-28), the local system:
6767
// - if the ConnectRetryTimer is running, stops and resets the ConnectRetryTimer (sets to zero),
6868
if (session._ptrConnectRetryTimer->isScheduled()) {
69-
session.restartsConnectRetryTimer(false);
69+
session.restartConnectRetryTimer();
7070
}
7171
// - if the DelayOpenTimer is running, stops and resets the DelayOpenTimer (sets to zero),
7272
// - releases all BGP resources,
@@ -95,12 +95,12 @@ void Connect::TcpConnectionConfirmed()
9595
// system checks the DelayOpen attribute prior to processing.
9696
// If the DelayOpen attribute is set to FALSE, the local system:
9797
// - stops the ConnectRetryTimer (if running) and sets the ConnectRetryTimer to zero,
98-
session.restartsConnectRetryTimer(false);
98+
session.restartConnectRetryTimer();
9999
// - completes BGP initialization
100100
// - sends an OPEN message to its peer,
101101
session.sendOpenMessage();
102102
// - sets the HoldTimer to a large value, and
103-
session.restartsHoldTimer();
103+
session.restartHoldTimer();
104104
// - changes its state to OpenSent.
105105
setState<OpenSent>();
106106
}
@@ -133,7 +133,7 @@ void Active::ConnectRetryTimer_Expires()
133133
BgpSession& session = TopState::box().getModule();
134134
// In response to a ConnectRetryTimer_Expires event (Event 9), the local system:
135135
// - restarts the ConnectRetryTimer (with initial value),
136-
session.restartsConnectRetryTimer();
136+
session.stopConnectRetryTimer();
137137
// - initiates a TCP connection to the other BGP peer,T);
138138
// session._info.socket->renewSocket();
139139
session.openTCPConnectionToPeer();
@@ -148,7 +148,7 @@ void Active::HoldTimer_Expires()
148148
BgpSession& session = TopState::box().getModule();
149149
// In response to any other event (Events 8, 10-11, 13, 19, 23, 25-28), the local system:
150150
// - sets the ConnectRetryTimer to zero,
151-
session.restartsConnectRetryTimer(false);
151+
session.restartConnectRetryTimer();
152152
// - releases all BGP resources,
153153
// - drops the TCP connection,
154154
session._info.socket->abort();
@@ -173,11 +173,11 @@ void Active::TcpConnectionConfirmed()
173173
// In response to the success of a TCP connection (Event 16 or Event
174174
// 17), the local system :
175175
// - sets the ConnectRetryTimer to zero,
176-
session.restartsConnectRetryTimer(false);
176+
session.restartConnectRetryTimer();
177177
// - sends the OPEN message to its peer,
178178
session.sendOpenMessage();
179179
// - sets its HoldTimer to a large value, and
180-
session.restartsHoldTimer();
180+
session.restartHoldTimer();
181181
// - changes its state to OpenSent.
182182
setState<OpenSent>();
183183
}
@@ -221,7 +221,7 @@ void OpenSent::ConnectRetryTimer_Expires()
221221
// In response to any other event (Events 9, 11-13, 20, 25-28), the local system:
222222
// TODO- sends the NOTIFICATION with the Error Code Finite State Machine Error,
223223
// - sets the ConnectRetryTimer to zero,
224-
session.restartsConnectRetryTimer(false);
224+
session.restartConnectRetryTimer();
225225
// - releases all BGP resources,
226226
// - drops the TCP connection,
227227
session._info.socket->abort();
@@ -239,7 +239,7 @@ void OpenSent::HoldTimer_Expires()
239239
BgpSession& session = TopState::box().getModule();
240240
// If the HoldTimer_Expires (Event 10), the local system:
241241
// - sets the ConnectRetryTimer to zero,
242-
session.restartsConnectRetryTimer(false);
242+
session.restartConnectRetryTimer();
243243
// - releases all BGP resources,
244244
// - drops the TCP connection,
245245
session._info.socket->abort();
@@ -265,7 +265,7 @@ void OpenSent::TcpConnectionFails()
265265
// - closes the BGP connection,
266266
session._info.socket->abort();
267267
// - restarts the ConnectRetryTimer,
268-
session.restartsConnectRetryTimer();
268+
session.stopConnectRetryTimer();
269269
// - continues to listen for a connection that may be initiated by the remote BGP peer, and
270270
session.listenConnectionFromPeer();
271271
// - changes its state to Active.
@@ -280,13 +280,13 @@ void OpenSent::OpenMsgEvent()
280280
// When an OPEN message is received, all fields are checked for correctness.
281281
// If there are no errors in the OPEN message (Event 19), the local system:
282282
// - sets the BGP ConnectRetryTimer to zero,
283-
session.restartsConnectRetryTimer(false);
283+
session.restartConnectRetryTimer();
284284
// - sends a KEEPALIVE message, and
285285
session.sendKeepAliveMessage();
286286
// - sets a KeepaliveTimer
287-
session.restartsKeepAliveTimer();
287+
session.restartKeepAliveTimer();
288288
// - sets the HoldTimer according to the negotiated value (see Section 4.2),
289-
session.restartsHoldTimer();
289+
session.restartHoldTimer();
290290
// - changes its state to OpenConfirm.
291291
setState<OpenConfirm>();
292292
}
@@ -315,7 +315,7 @@ void OpenConfirm::ConnectRetryTimer_Expires()
315315
BgpSession& session = TopState::box().getModule();
316316
// - sends a NOTIFICATION with a Cease,
317317
// - sets the ConnectRetryTimer to zero,
318-
session.restartsConnectRetryTimer(false);
318+
session.restartConnectRetryTimer();
319319
// - releases all BGP resources,
320320
// - drops the TCP connection (send TCP FIN),
321321
session._info.socket->abort();
@@ -332,7 +332,7 @@ void OpenConfirm::HoldTimer_Expires()
332332
BgpSession& session = TopState::box().getModule();
333333
// If the HoldTimer_Expires event (Event 10) occurs before a KEEPALIVE message is received, the local system:
334334
// - sets the ConnectRetryTimer to zero,
335-
session.restartsConnectRetryTimer(false);
335+
session.restartConnectRetryTimer();
336336
// - releases all BGP resources,
337337
// - drops the TCP connection,
338338
session._info.socket->abort();
@@ -351,7 +351,7 @@ void OpenConfirm::KeepaliveTimer_Expires()
351351
// - sends a KEEPALIVE message,
352352
session.sendKeepAliveMessage();
353353
// - restarts the KeepaliveTimer, and
354-
session.restartsKeepAliveTimer();
354+
session.restartKeepAliveTimer();
355355
// - remains in the OpenConfirmed state.
356356
}
357357

@@ -382,7 +382,7 @@ void OpenConfirm::KeepAliveMsgEvent()
382382
session._keepAliveMsgRcv++;
383383
// If the local system receives a KEEPALIVE message (KeepAliveMsg Event 26)), the local system:
384384
// - restarts the HoldTimer and
385-
session.restartsHoldTimer();
385+
session.restartHoldTimer();
386386
// - changes its state to Established.
387387
setState<Established>();
388388
}
@@ -405,9 +405,8 @@ void Established::entry()
405405
// We are connected: drop any pending reconnect so it cannot disrupt this session later.
406406
session.cancelReconnect();
407407
// RFC 4271: the ConnectRetryTimer MUST be zero in the Established state. It is (re)started
408-
// during connection setup; stop it here so it cannot later fire and abort a healthy session
409-
// (default arg true => cancel without rescheduling).
410-
session.restartsConnectRetryTimer();
408+
// during connection setup; stop it here so it cannot later fire and abort a healthy session.
409+
session.stopConnectRetryTimer();
411410

412411
// if it's an EGP Session, send update messages with all routing information to BGP peer
413412
// if it's an IGP Session, send update message with only the BGP routes learned by EGP
@@ -443,7 +442,7 @@ void Established::ConnectRetryTimer_Expires()
443442
// In response to any other event (Events 9, 12-13, 20-22), the local system:
444443
// TODO- deletes all routes associated with this connection,
445444
// - sets the ConnectRetryTimer to zero,
446-
session.restartsConnectRetryTimer(false);
445+
session.restartConnectRetryTimer();
447446
// - releases all BGP resources,
448447
// - drops the TCP connection,
449448
session._info.socket->abort();
@@ -461,7 +460,7 @@ void Established::HoldTimer_Expires()
461460
BgpSession& session = TopState::box().getModule();
462461
// If the HoldTimer_Expires event occurs (Event 10), the local system:
463462
// - sets the ConnectRetryTimer to zero,
464-
session.restartsConnectRetryTimer(false);
463+
session.restartConnectRetryTimer();
465464
// - releases all BGP resources,
466465
// - drops the TCP connection,
467466
session._info.socket->abort();
@@ -482,15 +481,15 @@ void Established::KeepaliveTimer_Expires()
482481
session.sendKeepAliveMessage();
483482
// - restarts the KeepaliveTimer, unless the negotiated HoldTime value is zero.
484483
if (session._holdTime != 0) {
485-
session.restartsKeepAliveTimer();
484+
session.restartKeepAliveTimer();
486485
}
487486
}
488487

489488
void Established::TcpConnectionFails()
490489
{
491490
EV_TRACE << "Processing Established::TcpConnectionFails" << std::endl;
492491
BgpSession& session = TopState::box().getModule();
493-
session.restartsConnectRetryTimer(false);
492+
session.restartConnectRetryTimer();
494493
session._info.socket->abort();
495494
++session._connectRetryCounter;
496495
session._info.sessionEstablished = false;
@@ -512,7 +511,7 @@ void Established::KeepAliveMsgEvent()
512511
session._keepAliveMsgRcv++;
513512
// If the local system receives a KEEPALIVE message (Event 26), the local system:
514513
// - restarts its HoldTimer, if the negotiated HoldTime value is non-zero, and
515-
session.restartsHoldTimer();
514+
session.restartHoldTimer();
516515
// - remains in the Established state.
517516
}
518517

@@ -524,7 +523,7 @@ void Established::UpdateMsgEvent()
524523
// If the local system receives an UPDATE message (Event 27), the local system:
525524
// - processes the message,
526525
// - restarts its HoldTimer, if the negotiated HoldTime value is non-zero, and
527-
session.restartsHoldTimer();
526+
session.restartHoldTimer();
528527
// - remains in the Established state.
529528
}
530529

src/inet/routing/bgpv4/BgpSession.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,26 +105,29 @@ void BgpSession::cancelReconnect()
105105
bgpRouter.getCancelEvent(_ptrStartEvent);
106106
}
107107

108-
void BgpSession::restartsHoldTimer()
108+
void BgpSession::restartHoldTimer()
109109
{
110110
if (_holdTime != 0) {
111111
bgpRouter.getCancelEvent(_ptrHoldTimer);
112112
bgpRouter.getScheduleAt(simTime() + _holdTime, _ptrHoldTimer);
113113
}
114114
}
115115

116-
void BgpSession::restartsKeepAliveTimer()
116+
void BgpSession::restartKeepAliveTimer()
117117
{
118118
bgpRouter.getCancelEvent(_ptrKeepAliveTimer);
119119
bgpRouter.getScheduleAt(simTime() + _keepAliveTime, _ptrKeepAliveTimer);
120120
}
121121

122-
void BgpSession::restartsConnectRetryTimer(bool start)
122+
void BgpSession::restartConnectRetryTimer()
123+
{
124+
bgpRouter.getCancelEvent(_ptrConnectRetryTimer);
125+
bgpRouter.getScheduleAt(simTime() + _connectRetryTime, _ptrConnectRetryTimer);
126+
}
127+
128+
void BgpSession::stopConnectRetryTimer()
123129
{
124130
bgpRouter.getCancelEvent(_ptrConnectRetryTimer);
125-
if (!start) {
126-
bgpRouter.getScheduleAt(simTime() + _connectRetryTime, _ptrConnectRetryTimer);
127-
}
128131
}
129132

130133
void BgpSession::sendOpenMessage()

src/inet/routing/bgpv4/BgpSession.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ class INET_API BgpSession : public cObject
6969
void startConnection();
7070
void scheduleReconnect();
7171
void cancelReconnect();
72-
void restartsHoldTimer();
73-
void restartsKeepAliveTimer();
74-
void restartsConnectRetryTimer(bool start = true);
72+
void restartHoldTimer();
73+
void restartKeepAliveTimer();
74+
void restartConnectRetryTimer();
75+
void stopConnectRetryTimer();
7576

7677
void sendOpenMessage();
7778
void sendUpdateMessage(std::vector<BgpUpdatePathAttributes *>& content, BgpUpdateNlri& NLRI);

0 commit comments

Comments
 (0)