Fix for BGP sessions not timing out
Change-Id: I57975fefe6d54934cbbde95b6d22e03bea835289
Showing
2 changed files
with
30 additions
and
21 deletions
... | @@ -93,7 +93,7 @@ class BgpFrameDecoder extends FrameDecoder { | ... | @@ -93,7 +93,7 @@ class BgpFrameDecoder extends FrameDecoder { |
93 | bgpSession.prepareBgpNotification(errorCode, errorSubcode, | 93 | bgpSession.prepareBgpNotification(errorCode, errorSubcode, |
94 | null); | 94 | null); |
95 | ctx.getChannel().write(txMessage); | 95 | ctx.getChannel().write(txMessage); |
96 | - bgpSession.closeChannel(ctx); | 96 | + bgpSession.closeSession(ctx); |
97 | return null; | 97 | return null; |
98 | } | 98 | } |
99 | } | 99 | } |
... | @@ -116,7 +116,7 @@ class BgpFrameDecoder extends FrameDecoder { | ... | @@ -116,7 +116,7 @@ class BgpFrameDecoder extends FrameDecoder { |
116 | ChannelBuffer txMessage = | 116 | ChannelBuffer txMessage = |
117 | bgpSession.prepareBgpNotificationBadMessageLength(length); | 117 | bgpSession.prepareBgpNotificationBadMessageLength(length); |
118 | ctx.getChannel().write(txMessage); | 118 | ctx.getChannel().write(txMessage); |
119 | - bgpSession.closeChannel(ctx); | 119 | + bgpSession.closeSession(ctx); |
120 | return null; | 120 | return null; |
121 | } | 121 | } |
122 | 122 | ||
... | @@ -169,7 +169,7 @@ class BgpFrameDecoder extends FrameDecoder { | ... | @@ -169,7 +169,7 @@ class BgpFrameDecoder extends FrameDecoder { |
169 | bgpSession.prepareBgpNotification(errorCode, errorSubcode, | 169 | bgpSession.prepareBgpNotification(errorCode, errorSubcode, |
170 | data); | 170 | data); |
171 | ctx.getChannel().write(txMessage); | 171 | ctx.getChannel().write(txMessage); |
172 | - bgpSession.closeChannel(ctx); | 172 | + bgpSession.closeSession(ctx); |
173 | return null; | 173 | return null; |
174 | } | 174 | } |
175 | return null; | 175 | return null; | ... | ... |
... | @@ -226,13 +226,22 @@ public class BgpSession extends SimpleChannelHandler { | ... | @@ -226,13 +226,22 @@ public class BgpSession extends SimpleChannelHandler { |
226 | } | 226 | } |
227 | 227 | ||
228 | /** | 228 | /** |
229 | - * Closes the channel. | 229 | + * Closes the session. |
230 | + * | ||
231 | + * @param ctx the Channel Handler Context | ||
232 | + */ | ||
233 | + void closeSession(ChannelHandlerContext ctx) { | ||
234 | + timer.stop(); | ||
235 | + closeChannel(ctx); | ||
236 | + } | ||
237 | + | ||
238 | + /** | ||
239 | + * Closes the netty channel. | ||
230 | * | 240 | * |
231 | * @param ctx the Channel Handler Context | 241 | * @param ctx the Channel Handler Context |
232 | */ | 242 | */ |
233 | void closeChannel(ChannelHandlerContext ctx) { | 243 | void closeChannel(ChannelHandlerContext ctx) { |
234 | isClosed = true; | 244 | isClosed = true; |
235 | - timer.stop(); | ||
236 | ctx.getChannel().close(); | 245 | ctx.getChannel().close(); |
237 | } | 246 | } |
238 | 247 | ||
... | @@ -320,7 +329,7 @@ public class BgpSession extends SimpleChannelHandler { | ... | @@ -320,7 +329,7 @@ public class BgpSession extends SimpleChannelHandler { |
320 | ChannelBuffer txMessage = prepareBgpNotificationBadMessageLength( | 329 | ChannelBuffer txMessage = prepareBgpNotificationBadMessageLength( |
321 | message.readableBytes() + BgpConstants.BGP_HEADER_LENGTH); | 330 | message.readableBytes() + BgpConstants.BGP_HEADER_LENGTH); |
322 | ctx.getChannel().write(txMessage); | 331 | ctx.getChannel().write(txMessage); |
323 | - closeChannel(ctx); | 332 | + closeSession(ctx); |
324 | return; | 333 | return; |
325 | } | 334 | } |
326 | 335 | ||
... | @@ -345,7 +354,7 @@ public class BgpSession extends SimpleChannelHandler { | ... | @@ -345,7 +354,7 @@ public class BgpSession extends SimpleChannelHandler { |
345 | ChannelBuffer txMessage = | 354 | ChannelBuffer txMessage = |
346 | prepareBgpNotification(errorCode, errorSubcode, data); | 355 | prepareBgpNotification(errorCode, errorSubcode, data); |
347 | ctx.getChannel().write(txMessage); | 356 | ctx.getChannel().write(txMessage); |
348 | - closeChannel(ctx); | 357 | + closeSession(ctx); |
349 | return; | 358 | return; |
350 | } | 359 | } |
351 | 360 | ||
... | @@ -370,7 +379,7 @@ public class BgpSession extends SimpleChannelHandler { | ... | @@ -370,7 +379,7 @@ public class BgpSession extends SimpleChannelHandler { |
370 | ChannelBuffer txMessage = | 379 | ChannelBuffer txMessage = |
371 | prepareBgpNotification(errorCode, errorSubcode, null); | 380 | prepareBgpNotification(errorCode, errorSubcode, null); |
372 | ctx.getChannel().write(txMessage); | 381 | ctx.getChannel().write(txMessage); |
373 | - closeChannel(ctx); | 382 | + closeSession(ctx); |
374 | return; | 383 | return; |
375 | } | 384 | } |
376 | } | 385 | } |
... | @@ -393,7 +402,7 @@ public class BgpSession extends SimpleChannelHandler { | ... | @@ -393,7 +402,7 @@ public class BgpSession extends SimpleChannelHandler { |
393 | ChannelBuffer txMessage = | 402 | ChannelBuffer txMessage = |
394 | prepareBgpNotification(errorCode, errorSubcode, null); | 403 | prepareBgpNotification(errorCode, errorSubcode, null); |
395 | ctx.getChannel().write(txMessage); | 404 | ctx.getChannel().write(txMessage); |
396 | - closeChannel(ctx); | 405 | + closeSession(ctx); |
397 | return; | 406 | return; |
398 | } | 407 | } |
399 | 408 | ||
... | @@ -416,7 +425,7 @@ public class BgpSession extends SimpleChannelHandler { | ... | @@ -416,7 +425,7 @@ public class BgpSession extends SimpleChannelHandler { |
416 | ChannelBuffer txMessage = | 425 | ChannelBuffer txMessage = |
417 | prepareBgpNotification(errorCode, errorSubcode, null); | 426 | prepareBgpNotification(errorCode, errorSubcode, null); |
418 | ctx.getChannel().write(txMessage); | 427 | ctx.getChannel().write(txMessage); |
419 | - closeChannel(ctx); | 428 | + closeSession(ctx); |
420 | return; | 429 | return; |
421 | } | 430 | } |
422 | // TODO: Parse the optional parameters (if needed) | 431 | // TODO: Parse the optional parameters (if needed) |
... | @@ -485,7 +494,7 @@ public class BgpSession extends SimpleChannelHandler { | ... | @@ -485,7 +494,7 @@ public class BgpSession extends SimpleChannelHandler { |
485 | ChannelBuffer txMessage = prepareBgpNotificationBadMessageLength( | 494 | ChannelBuffer txMessage = prepareBgpNotificationBadMessageLength( |
486 | message.readableBytes() + BgpConstants.BGP_HEADER_LENGTH); | 495 | message.readableBytes() + BgpConstants.BGP_HEADER_LENGTH); |
487 | ctx.getChannel().write(txMessage); | 496 | ctx.getChannel().write(txMessage); |
488 | - closeChannel(ctx); | 497 | + closeSession(ctx); |
489 | return; | 498 | return; |
490 | } | 499 | } |
491 | 500 | ||
... | @@ -1284,7 +1293,7 @@ public class BgpSession extends SimpleChannelHandler { | ... | @@ -1284,7 +1293,7 @@ public class BgpSession extends SimpleChannelHandler { |
1284 | ChannelBuffer txMessage = | 1293 | ChannelBuffer txMessage = |
1285 | prepareBgpNotification(errorCode, errorSubcode, null); | 1294 | prepareBgpNotification(errorCode, errorSubcode, null); |
1286 | ctx.getChannel().write(txMessage); | 1295 | ctx.getChannel().write(txMessage); |
1287 | - closeChannel(ctx); | 1296 | + closeSession(ctx); |
1288 | } | 1297 | } |
1289 | 1298 | ||
1290 | /** | 1299 | /** |
... | @@ -1307,7 +1316,7 @@ public class BgpSession extends SimpleChannelHandler { | ... | @@ -1307,7 +1316,7 @@ public class BgpSession extends SimpleChannelHandler { |
1307 | ChannelBuffer txMessage = | 1316 | ChannelBuffer txMessage = |
1308 | prepareBgpNotification(errorCode, errorSubcode, null); | 1317 | prepareBgpNotification(errorCode, errorSubcode, null); |
1309 | ctx.getChannel().write(txMessage); | 1318 | ctx.getChannel().write(txMessage); |
1310 | - closeChannel(ctx); | 1319 | + closeSession(ctx); |
1311 | } | 1320 | } |
1312 | 1321 | ||
1313 | /** | 1322 | /** |
... | @@ -1335,7 +1344,7 @@ public class BgpSession extends SimpleChannelHandler { | ... | @@ -1335,7 +1344,7 @@ public class BgpSession extends SimpleChannelHandler { |
1335 | ChannelBuffer txMessage = | 1344 | ChannelBuffer txMessage = |
1336 | prepareBgpNotification(errorCode, errorSubcode, data); | 1345 | prepareBgpNotification(errorCode, errorSubcode, data); |
1337 | ctx.getChannel().write(txMessage); | 1346 | ctx.getChannel().write(txMessage); |
1338 | - closeChannel(ctx); | 1347 | + closeSession(ctx); |
1339 | } | 1348 | } |
1340 | 1349 | ||
1341 | /** | 1350 | /** |
... | @@ -1371,7 +1380,7 @@ public class BgpSession extends SimpleChannelHandler { | ... | @@ -1371,7 +1380,7 @@ public class BgpSession extends SimpleChannelHandler { |
1371 | ChannelBuffer txMessage = | 1380 | ChannelBuffer txMessage = |
1372 | prepareBgpNotification(errorCode, errorSubcode, data); | 1381 | prepareBgpNotification(errorCode, errorSubcode, data); |
1373 | ctx.getChannel().write(txMessage); | 1382 | ctx.getChannel().write(txMessage); |
1374 | - closeChannel(ctx); | 1383 | + closeSession(ctx); |
1375 | } | 1384 | } |
1376 | 1385 | ||
1377 | /** | 1386 | /** |
... | @@ -1405,7 +1414,7 @@ public class BgpSession extends SimpleChannelHandler { | ... | @@ -1405,7 +1414,7 @@ public class BgpSession extends SimpleChannelHandler { |
1405 | ChannelBuffer txMessage = | 1414 | ChannelBuffer txMessage = |
1406 | prepareBgpNotification(errorCode, errorSubcode, data); | 1415 | prepareBgpNotification(errorCode, errorSubcode, data); |
1407 | ctx.getChannel().write(txMessage); | 1416 | ctx.getChannel().write(txMessage); |
1408 | - closeChannel(ctx); | 1417 | + closeSession(ctx); |
1409 | } | 1418 | } |
1410 | 1419 | ||
1411 | /** | 1420 | /** |
... | @@ -1442,7 +1451,7 @@ public class BgpSession extends SimpleChannelHandler { | ... | @@ -1442,7 +1451,7 @@ public class BgpSession extends SimpleChannelHandler { |
1442 | ChannelBuffer txMessage = | 1451 | ChannelBuffer txMessage = |
1443 | prepareBgpNotification(errorCode, errorSubcode, data); | 1452 | prepareBgpNotification(errorCode, errorSubcode, data); |
1444 | ctx.getChannel().write(txMessage); | 1453 | ctx.getChannel().write(txMessage); |
1445 | - closeChannel(ctx); | 1454 | + closeSession(ctx); |
1446 | } | 1455 | } |
1447 | 1456 | ||
1448 | /** | 1457 | /** |
... | @@ -1479,7 +1488,7 @@ public class BgpSession extends SimpleChannelHandler { | ... | @@ -1479,7 +1488,7 @@ public class BgpSession extends SimpleChannelHandler { |
1479 | ChannelBuffer txMessage = | 1488 | ChannelBuffer txMessage = |
1480 | prepareBgpNotification(errorCode, errorSubcode, data); | 1489 | prepareBgpNotification(errorCode, errorSubcode, data); |
1481 | ctx.getChannel().write(txMessage); | 1490 | ctx.getChannel().write(txMessage); |
1482 | - closeChannel(ctx); | 1491 | + closeSession(ctx); |
1483 | } | 1492 | } |
1484 | 1493 | ||
1485 | /** | 1494 | /** |
... | @@ -1513,7 +1522,7 @@ public class BgpSession extends SimpleChannelHandler { | ... | @@ -1513,7 +1522,7 @@ public class BgpSession extends SimpleChannelHandler { |
1513 | ChannelBuffer txMessage = | 1522 | ChannelBuffer txMessage = |
1514 | prepareBgpNotification(errorCode, errorSubcode, data); | 1523 | prepareBgpNotification(errorCode, errorSubcode, data); |
1515 | ctx.getChannel().write(txMessage); | 1524 | ctx.getChannel().write(txMessage); |
1516 | - closeChannel(ctx); | 1525 | + closeSession(ctx); |
1517 | } | 1526 | } |
1518 | 1527 | ||
1519 | /** | 1528 | /** |
... | @@ -1536,7 +1545,7 @@ public class BgpSession extends SimpleChannelHandler { | ... | @@ -1536,7 +1545,7 @@ public class BgpSession extends SimpleChannelHandler { |
1536 | ChannelBuffer txMessage = | 1545 | ChannelBuffer txMessage = |
1537 | prepareBgpNotification(errorCode, errorSubcode, null); | 1546 | prepareBgpNotification(errorCode, errorSubcode, null); |
1538 | ctx.getChannel().write(txMessage); | 1547 | ctx.getChannel().write(txMessage); |
1539 | - closeChannel(ctx); | 1548 | + closeSession(ctx); |
1540 | } | 1549 | } |
1541 | 1550 | ||
1542 | /** | 1551 | /** |
... | @@ -1602,7 +1611,7 @@ public class BgpSession extends SimpleChannelHandler { | ... | @@ -1602,7 +1611,7 @@ public class BgpSession extends SimpleChannelHandler { |
1602 | ChannelBuffer txMessage = prepareBgpNotificationBadMessageLength( | 1611 | ChannelBuffer txMessage = prepareBgpNotificationBadMessageLength( |
1603 | message.readableBytes() + BgpConstants.BGP_HEADER_LENGTH); | 1612 | message.readableBytes() + BgpConstants.BGP_HEADER_LENGTH); |
1604 | ctx.getChannel().write(txMessage); | 1613 | ctx.getChannel().write(txMessage); |
1605 | - closeChannel(ctx); | 1614 | + closeSession(ctx); |
1606 | return; | 1615 | return; |
1607 | } | 1616 | } |
1608 | 1617 | ... | ... |
-
Please register or login to post a comment