Pavlin Radoslavov

ONOS-866: Refactor the storing and handling of BgpSession info.

Moved the local and remote BGP session info to a separate class BgpSessionInfo.
No functional changes.

Also, removed methods TestBgpPeerChannelHandler.prepareBgpKeepalive(),
prepareBgpNotification() and prepareBgpMessage() from the unit tests.
Instead, use the corresponding methods in the BGP implementation itself
to generate the BGP messages.

Change-Id: I7f4b6ad4f6995c242cd8a9848ea527b1fcac9c11
...@@ -51,7 +51,7 @@ final class BgpKeepalive { ...@@ -51,7 +51,7 @@ final class BgpKeepalive {
51 BgpConstants.BGP_KEEPALIVE_EXPECTED_LENGTH) { 51 BgpConstants.BGP_KEEPALIVE_EXPECTED_LENGTH) {
52 log.debug("BGP RX KEEPALIVE Error from {}: " + 52 log.debug("BGP RX KEEPALIVE Error from {}: " +
53 "Invalid total message length {}. Expected {}", 53 "Invalid total message length {}. Expected {}",
54 - bgpSession.getRemoteAddress(), 54 + bgpSession.remoteInfo().address(),
55 message.readableBytes() + BgpConstants.BGP_HEADER_LENGTH, 55 message.readableBytes() + BgpConstants.BGP_HEADER_LENGTH,
56 BgpConstants.BGP_KEEPALIVE_EXPECTED_LENGTH); 56 BgpConstants.BGP_KEEPALIVE_EXPECTED_LENGTH);
57 // 57 //
...@@ -70,7 +70,7 @@ final class BgpKeepalive { ...@@ -70,7 +70,7 @@ final class BgpKeepalive {
70 // Parse the KEEPALIVE message: nothing to do 70 // Parse the KEEPALIVE message: nothing to do
71 // 71 //
72 log.trace("BGP RX KEEPALIVE message from {}", 72 log.trace("BGP RX KEEPALIVE message from {}",
73 - bgpSession.getRemoteAddress()); 73 + bgpSession.remoteInfo().address());
74 74
75 // Start the Session Timeout timer 75 // Start the Session Timeout timer
76 bgpSession.restartSessionTimeoutTimer(ctx); 76 bgpSession.restartSessionTimeoutTimer(ctx);
......
...@@ -53,8 +53,8 @@ final class BgpNotification { ...@@ -53,8 +53,8 @@ final class BgpNotification {
53 if (message.readableBytes() < minLength) { 53 if (message.readableBytes() < minLength) {
54 log.debug("BGP RX NOTIFICATION Error from {}: " + 54 log.debug("BGP RX NOTIFICATION Error from {}: " +
55 "Message length {} too short. Must be at least {}", 55 "Message length {} too short. Must be at least {}",
56 - bgpSession.getRemoteAddress(), message.readableBytes(), 56 + bgpSession.remoteInfo().address(),
57 - minLength); 57 + message.readableBytes(), minLength);
58 // 58 //
59 // ERROR: Bad Message Length 59 // ERROR: Bad Message Length
60 // 60 //
...@@ -71,7 +71,7 @@ final class BgpNotification { ...@@ -71,7 +71,7 @@ final class BgpNotification {
71 71
72 log.debug("BGP RX NOTIFICATION message from {}: Error Code {} " + 72 log.debug("BGP RX NOTIFICATION message from {}: Error Code {} " +
73 "Error Subcode {} Data Length {}", 73 "Error Subcode {} Data Length {}",
74 - bgpSession.getRemoteAddress(), errorCode, errorSubcode, 74 + bgpSession.remoteInfo().address(), errorCode, errorSubcode,
75 dataLength); 75 dataLength);
76 76
77 // 77 //
......
...@@ -58,8 +58,8 @@ final class BgpOpen { ...@@ -58,8 +58,8 @@ final class BgpOpen {
58 if (message.readableBytes() < minLength) { 58 if (message.readableBytes() < minLength) {
59 log.debug("BGP RX OPEN Error from {}: " + 59 log.debug("BGP RX OPEN Error from {}: " +
60 "Message length {} too short. Must be at least {}", 60 "Message length {} too short. Must be at least {}",
61 - bgpSession.getRemoteAddress(), message.readableBytes(), 61 + bgpSession.remoteInfo().address(),
62 - minLength); 62 + message.readableBytes(), minLength);
63 // 63 //
64 // ERROR: Bad Message Length 64 // ERROR: Bad Message Length
65 // 65 //
...@@ -80,7 +80,7 @@ final class BgpOpen { ...@@ -80,7 +80,7 @@ final class BgpOpen {
80 if (remoteBgpVersion != BgpConstants.BGP_VERSION) { 80 if (remoteBgpVersion != BgpConstants.BGP_VERSION) {
81 log.debug("BGP RX OPEN Error from {}: " + 81 log.debug("BGP RX OPEN Error from {}: " +
82 "Unsupported BGP version {}. Should be {}", 82 "Unsupported BGP version {}. Should be {}",
83 - bgpSession.getRemoteAddress(), remoteBgpVersion, 83 + bgpSession.remoteInfo().address(), remoteBgpVersion,
84 BgpConstants.BGP_VERSION); 84 BgpConstants.BGP_VERSION);
85 // 85 //
86 // ERROR: Unsupported Version Number 86 // ERROR: Unsupported Version Number
...@@ -97,7 +97,7 @@ final class BgpOpen { ...@@ -97,7 +97,7 @@ final class BgpOpen {
97 bgpSession.closeSession(ctx); 97 bgpSession.closeSession(ctx);
98 return; 98 return;
99 } 99 }
100 - bgpSession.setRemoteBgpVersion(remoteBgpVersion); 100 + bgpSession.remoteInfo().setBgpVersion(remoteBgpVersion);
101 101
102 // Remote AS number 102 // Remote AS number
103 long remoteAs = message.readUnsignedShort(); 103 long remoteAs = message.readUnsignedShort();
...@@ -107,11 +107,12 @@ final class BgpOpen { ...@@ -107,11 +107,12 @@ final class BgpOpen {
107 // sessions are iBGP. 107 // sessions are iBGP.
108 // 108 //
109 for (BgpSession bs : bgpSession.getBgpSessionManager().getBgpSessions()) { 109 for (BgpSession bs : bgpSession.getBgpSessionManager().getBgpSessions()) {
110 - if ((bs.getRemoteAs() != 0) && (remoteAs != bs.getRemoteAs())) { 110 + if ((bs.remoteInfo().asNumber() != 0) &&
111 + (remoteAs != bs.remoteInfo().asNumber())) {
111 log.debug("BGP RX OPEN Error from {}: Bad Peer AS {}. " + 112 log.debug("BGP RX OPEN Error from {}: Bad Peer AS {}. " +
112 "Expected {}", 113 "Expected {}",
113 - bgpSession.getRemoteAddress(), remoteAs, 114 + bgpSession.remoteInfo().address(), remoteAs,
114 - bs.getRemoteAs()); 115 + bs.remoteInfo().asNumber());
115 // 116 //
116 // ERROR: Bad Peer AS 117 // ERROR: Bad Peer AS
117 // 118 //
...@@ -126,7 +127,14 @@ final class BgpOpen { ...@@ -126,7 +127,14 @@ final class BgpOpen {
126 return; 127 return;
127 } 128 }
128 } 129 }
129 - bgpSession.setRemoteAs(remoteAs); 130 + bgpSession.remoteInfo().setAsNumber(remoteAs);
131 + //
132 + // NOTE: Currently, the local AS number is always set to the remote AS.
133 + // This is done, because the peer setup is always iBGP.
134 + // In the future, the local AS number should be configured as part
135 + // of an explicit BGP peering configuration.
136 + //
137 + bgpSession.localInfo().setAsNumber(remoteAs);
130 138
131 // Remote Hold Time 139 // Remote Hold Time
132 long remoteHoldtime = message.readUnsignedShort(); 140 long remoteHoldtime = message.readUnsignedShort();
...@@ -135,7 +143,7 @@ final class BgpOpen { ...@@ -135,7 +143,7 @@ final class BgpOpen {
135 log.debug("BGP RX OPEN Error from {}: " + 143 log.debug("BGP RX OPEN Error from {}: " +
136 "Unacceptable Hold Time field {}. " + 144 "Unacceptable Hold Time field {}. " +
137 "Should be 0 or at least {}", 145 "Should be 0 or at least {}",
138 - bgpSession.getRemoteAddress(), remoteHoldtime, 146 + bgpSession.remoteInfo().address(), remoteHoldtime,
139 BgpConstants.BGP_KEEPALIVE_MIN_HOLDTIME); 147 BgpConstants.BGP_KEEPALIVE_MIN_HOLDTIME);
140 // 148 //
141 // ERROR: Unacceptable Hold Time 149 // ERROR: Unacceptable Hold Time
...@@ -150,12 +158,19 @@ final class BgpOpen { ...@@ -150,12 +158,19 @@ final class BgpOpen {
150 bgpSession.closeSession(ctx); 158 bgpSession.closeSession(ctx);
151 return; 159 return;
152 } 160 }
153 - bgpSession.setRemoteHoldtime(remoteHoldtime); 161 + bgpSession.remoteInfo().setHoldtime(remoteHoldtime);
162 + //
163 + // NOTE: Currently. the local BGP Holdtime is always set to the remote
164 + // BGP holdtime.
165 + // In the future, the local BGP Holdtime should be configured as part
166 + // of an explicit BGP peering configuration.
167 + //
168 + bgpSession.localInfo().setHoldtime(remoteHoldtime);
154 169
155 // Remote BGP Identifier 170 // Remote BGP Identifier
156 Ip4Address remoteBgpId = 171 Ip4Address remoteBgpId =
157 Ip4Address.valueOf((int) message.readUnsignedInt()); 172 Ip4Address.valueOf((int) message.readUnsignedInt());
158 - bgpSession.setRemoteBgpId(remoteBgpId); 173 + bgpSession.remoteInfo().setBgpId(remoteBgpId);
159 174
160 // Parse the Optional Parameters 175 // Parse the Optional Parameters
161 try { 176 try {
...@@ -164,7 +179,7 @@ final class BgpOpen { ...@@ -164,7 +179,7 @@ final class BgpOpen {
164 // ERROR: Error parsing optional parameters 179 // ERROR: Error parsing optional parameters
165 log.debug("BGP RX OPEN Error from {}: " + 180 log.debug("BGP RX OPEN Error from {}: " +
166 "Exception parsing Optional Parameters: {}", 181 "Exception parsing Optional Parameters: {}",
167 - bgpSession.getRemoteAddress(), e); 182 + bgpSession.remoteInfo().address(), e);
168 // 183 //
169 // ERROR: Invalid Optional Parameters: Unspecific 184 // ERROR: Invalid Optional Parameters: Unspecific
170 // 185 //
...@@ -181,11 +196,11 @@ final class BgpOpen { ...@@ -181,11 +196,11 @@ final class BgpOpen {
181 196
182 log.debug("BGP RX OPEN message from {}: " + 197 log.debug("BGP RX OPEN message from {}: " +
183 "BGPv{} AS {} BGP-ID {} Holdtime {}", 198 "BGPv{} AS {} BGP-ID {} Holdtime {}",
184 - bgpSession.getRemoteAddress(), remoteBgpVersion, remoteAs, 199 + bgpSession.remoteInfo().address(), remoteBgpVersion,
185 - remoteBgpId, remoteHoldtime); 200 + remoteAs, remoteBgpId, remoteHoldtime);
186 201
187 // Send my OPEN followed by KEEPALIVE 202 // Send my OPEN followed by KEEPALIVE
188 - ChannelBuffer txMessage = prepareBgpOpen(bgpSession); 203 + ChannelBuffer txMessage = prepareBgpOpen(bgpSession.localInfo());
189 ctx.getChannel().write(txMessage); 204 ctx.getChannel().write(txMessage);
190 // 205 //
191 txMessage = BgpKeepalive.prepareBgpKeepalive(); 206 txMessage = BgpKeepalive.prepareBgpKeepalive();
...@@ -201,24 +216,24 @@ final class BgpOpen { ...@@ -201,24 +216,24 @@ final class BgpOpen {
201 /** 216 /**
202 * Prepares BGP OPEN message. 217 * Prepares BGP OPEN message.
203 * 218 *
204 - * @param bgpSession the BGP Session to use 219 + * @param localInfo the BGP Session local information to use
205 * @return the message to transmit (BGP header included) 220 * @return the message to transmit (BGP header included)
206 */ 221 */
207 - private static ChannelBuffer prepareBgpOpen(BgpSession bgpSession) { 222 + private static ChannelBuffer prepareBgpOpen(BgpSessionInfo localInfo) {
208 ChannelBuffer message = 223 ChannelBuffer message =
209 ChannelBuffers.buffer(BgpConstants.BGP_MESSAGE_MAX_LENGTH); 224 ChannelBuffers.buffer(BgpConstants.BGP_MESSAGE_MAX_LENGTH);
210 225
211 // 226 //
212 // Prepare the OPEN message payload 227 // Prepare the OPEN message payload
213 // 228 //
214 - message.writeByte(bgpSession.getLocalBgpVersion()); 229 + message.writeByte(localInfo.bgpVersion());
215 - message.writeShort((int) bgpSession.getLocalAs()); 230 + message.writeShort((int) localInfo.asNumber());
216 - message.writeShort((int) bgpSession.getLocalHoldtime()); 231 + message.writeShort((int) localInfo.holdtime());
217 - message.writeInt(bgpSession.getLocalBgpId().toInt()); 232 + message.writeInt(localInfo.bgpId().toInt());
218 233
219 // Prepare the optional BGP Capabilities 234 // Prepare the optional BGP Capabilities
220 ChannelBuffer capabilitiesMessage = 235 ChannelBuffer capabilitiesMessage =
221 - prepareBgpOpenCapabilities(bgpSession); 236 + prepareBgpOpenCapabilities(localInfo);
222 message.writeByte(capabilitiesMessage.readableBytes()); 237 message.writeByte(capabilitiesMessage.readableBytes());
223 message.writeBytes(capabilitiesMessage); 238 message.writeBytes(capabilitiesMessage);
224 239
...@@ -309,18 +324,25 @@ final class BgpOpen { ...@@ -309,18 +324,25 @@ final class BgpOpen {
309 // 324 //
310 // Setup the AFI/SAFI in the BgpSession 325 // Setup the AFI/SAFI in the BgpSession
311 // 326 //
327 + // NOTE: For now we just copy the remote AFI/SAFI setting
328 + // to the local configuration.
329 + //
312 if (afi == MultiprotocolExtensions.AFI_IPV4 && 330 if (afi == MultiprotocolExtensions.AFI_IPV4 &&
313 safi == MultiprotocolExtensions.SAFI_UNICAST) { 331 safi == MultiprotocolExtensions.SAFI_UNICAST) {
314 - bgpSession.setRemoteIpv4Unicast(); 332 + bgpSession.remoteInfo().setIpv4Unicast();
333 + bgpSession.localInfo().setIpv4Unicast();
315 } else if (afi == MultiprotocolExtensions.AFI_IPV4 && 334 } else if (afi == MultiprotocolExtensions.AFI_IPV4 &&
316 safi == MultiprotocolExtensions.SAFI_MULTICAST) { 335 safi == MultiprotocolExtensions.SAFI_MULTICAST) {
317 - bgpSession.setRemoteIpv4Multicast(); 336 + bgpSession.remoteInfo().setIpv4Multicast();
337 + bgpSession.localInfo().setIpv4Multicast();
318 } else if (afi == MultiprotocolExtensions.AFI_IPV6 && 338 } else if (afi == MultiprotocolExtensions.AFI_IPV6 &&
319 safi == MultiprotocolExtensions.SAFI_UNICAST) { 339 safi == MultiprotocolExtensions.SAFI_UNICAST) {
320 - bgpSession.setRemoteIpv6Unicast(); 340 + bgpSession.remoteInfo().setIpv6Unicast();
341 + bgpSession.localInfo().setIpv6Unicast();
321 } else if (afi == MultiprotocolExtensions.AFI_IPV6 && 342 } else if (afi == MultiprotocolExtensions.AFI_IPV6 &&
322 safi == MultiprotocolExtensions.SAFI_MULTICAST) { 343 safi == MultiprotocolExtensions.SAFI_MULTICAST) {
323 - bgpSession.setRemoteIpv6Multicast(); 344 + bgpSession.remoteInfo().setIpv6Multicast();
345 + bgpSession.localInfo().setIpv6Multicast();
324 } else { 346 } else {
325 log.debug("BGP RX OPEN Capability: Unknown AFI = {} SAFI = {}", 347 log.debug("BGP RX OPEN Capability: Unknown AFI = {} SAFI = {}",
326 afi, safi); 348 afi, safi);
...@@ -336,13 +358,20 @@ final class BgpOpen { ...@@ -336,13 +358,20 @@ final class BgpOpen {
336 } 358 }
337 long as4Number = message.readUnsignedInt(); 359 long as4Number = message.readUnsignedInt();
338 360
339 - bgpSession.setRemoteAs4OctetCapability(); 361 + bgpSession.remoteInfo().setAs4OctetCapability();
340 - bgpSession.setRemoteAs4Octet(as4Number); 362 + bgpSession.remoteInfo().setAs4Number(as4Number);
363 + // Use the 4-octet AS number in lieu of the "My AS" field
364 + // See RFC 6793, Section 4.1, second paragraph.
365 + bgpSession.remoteInfo().setAsNumber(as4Number);
341 366
342 - // Copy remote 4-octet AS Number Capabilities and AS Number. 367 + //
343 - // This is temporary setting until local AS number configuration is supported. 368 + // Copy remote 4-octet AS Number Capabilities and AS
344 - bgpSession.setLocalAs4OctetCapability(); 369 + // Number. This is a temporary setting until local AS
345 - bgpSession.setRemoteAs(as4Number); 370 + // number configuration is supported.
371 + //
372 + bgpSession.localInfo().setAs4OctetCapability();
373 + bgpSession.localInfo().setAs4Number(as4Number);
374 + bgpSession.localInfo().setAsNumber(as4Number);
346 log.debug("BGP RX OPEN Capability: AS4 Number = {}", 375 log.debug("BGP RX OPEN Capability: AS4 Number = {}",
347 as4Number); 376 as4Number);
348 break; 377 break;
...@@ -370,11 +399,11 @@ final class BgpOpen { ...@@ -370,11 +399,11 @@ final class BgpOpen {
370 /** 399 /**
371 * Prepares the Capabilities for the BGP OPEN message. 400 * Prepares the Capabilities for the BGP OPEN message.
372 * 401 *
373 - * @param bgpSession the BGP Session to use 402 + * @param localInfo the BGP Session local information to use
374 * @return the buffer with the BGP Capabilities to transmit 403 * @return the buffer with the BGP Capabilities to transmit
375 */ 404 */
376 private static ChannelBuffer prepareBgpOpenCapabilities( 405 private static ChannelBuffer prepareBgpOpenCapabilities(
377 - BgpSession bgpSession) { 406 + BgpSessionInfo localInfo) {
378 ChannelBuffer message = 407 ChannelBuffer message =
379 ChannelBuffers.buffer(BgpConstants.BGP_MESSAGE_MAX_LENGTH); 408 ChannelBuffers.buffer(BgpConstants.BGP_MESSAGE_MAX_LENGTH);
380 409
...@@ -383,7 +412,7 @@ final class BgpOpen { ...@@ -383,7 +412,7 @@ final class BgpOpen {
383 // 412 //
384 413
385 // IPv4 unicast 414 // IPv4 unicast
386 - if (bgpSession.getLocalIpv4Unicast()) { 415 + if (localInfo.ipv4Unicast()) {
387 message.writeByte(Capabilities.TYPE); // Param type 416 message.writeByte(Capabilities.TYPE); // Param type
388 message.writeByte(Capabilities.MIN_LENGTH + 417 message.writeByte(Capabilities.MIN_LENGTH +
389 MultiprotocolExtensions.LENGTH); // Param len 418 MultiprotocolExtensions.LENGTH); // Param len
...@@ -394,7 +423,7 @@ final class BgpOpen { ...@@ -394,7 +423,7 @@ final class BgpOpen {
394 message.writeByte(MultiprotocolExtensions.SAFI_UNICAST); 423 message.writeByte(MultiprotocolExtensions.SAFI_UNICAST);
395 } 424 }
396 // IPv4 multicast 425 // IPv4 multicast
397 - if (bgpSession.getLocalIpv4Multicast()) { 426 + if (localInfo.ipv4Multicast()) {
398 message.writeByte(Capabilities.TYPE); // Param type 427 message.writeByte(Capabilities.TYPE); // Param type
399 message.writeByte(Capabilities.MIN_LENGTH + 428 message.writeByte(Capabilities.MIN_LENGTH +
400 MultiprotocolExtensions.LENGTH); // Param len 429 MultiprotocolExtensions.LENGTH); // Param len
...@@ -405,7 +434,7 @@ final class BgpOpen { ...@@ -405,7 +434,7 @@ final class BgpOpen {
405 message.writeByte(MultiprotocolExtensions.SAFI_MULTICAST); 434 message.writeByte(MultiprotocolExtensions.SAFI_MULTICAST);
406 } 435 }
407 // IPv6 unicast 436 // IPv6 unicast
408 - if (bgpSession.getLocalIpv6Unicast()) { 437 + if (localInfo.ipv6Unicast()) {
409 message.writeByte(Capabilities.TYPE); // Param type 438 message.writeByte(Capabilities.TYPE); // Param type
410 message.writeByte(Capabilities.MIN_LENGTH + 439 message.writeByte(Capabilities.MIN_LENGTH +
411 MultiprotocolExtensions.LENGTH); // Param len 440 MultiprotocolExtensions.LENGTH); // Param len
...@@ -416,7 +445,7 @@ final class BgpOpen { ...@@ -416,7 +445,7 @@ final class BgpOpen {
416 message.writeByte(MultiprotocolExtensions.SAFI_UNICAST); 445 message.writeByte(MultiprotocolExtensions.SAFI_UNICAST);
417 } 446 }
418 // IPv6 multicast 447 // IPv6 multicast
419 - if (bgpSession.getLocalIpv6Multicast()) { 448 + if (localInfo.ipv6Multicast()) {
420 message.writeByte(Capabilities.TYPE); // Param type 449 message.writeByte(Capabilities.TYPE); // Param type
421 message.writeByte(Capabilities.MIN_LENGTH + 450 message.writeByte(Capabilities.MIN_LENGTH +
422 MultiprotocolExtensions.LENGTH); // Param len 451 MultiprotocolExtensions.LENGTH); // Param len
...@@ -428,13 +457,13 @@ final class BgpOpen { ...@@ -428,13 +457,13 @@ final class BgpOpen {
428 } 457 }
429 458
430 // 4 octet AS path capability 459 // 4 octet AS path capability
431 - if (bgpSession.getLocalAs4OctetCapability()) { 460 + if (localInfo.as4OctetCapability()) {
432 message.writeByte(Capabilities.TYPE); // Param type 461 message.writeByte(Capabilities.TYPE); // Param type
433 message.writeByte(Capabilities.MIN_LENGTH + 462 message.writeByte(Capabilities.MIN_LENGTH +
434 As4Octet.LENGTH); // Param len 463 As4Octet.LENGTH); // Param len
435 message.writeByte(As4Octet.CODE); // Capab, code 464 message.writeByte(As4Octet.CODE); // Capab, code
436 message.writeByte(As4Octet.LENGTH); // Capab, len 465 message.writeByte(As4Octet.LENGTH); // Capab, len
437 - message.writeInt((int) bgpSession.getLocalAs()); 466 + message.writeInt((int) localInfo.as4Number());
438 } 467 }
439 return message; 468 return message;
440 } 469 }
......
...@@ -258,16 +258,16 @@ public class BgpRouteEntry extends RouteEntry { ...@@ -258,16 +258,16 @@ public class BgpRouteEntry extends RouteEntry {
258 } 258 }
259 259
260 // Compare the peer BGP ID: lower is better 260 // Compare the peer BGP ID: lower is better
261 - Ip4Address peerBgpId = getBgpSession().getRemoteBgpId(); 261 + Ip4Address peerBgpId = getBgpSession().remoteInfo().bgpId();
262 - Ip4Address otherPeerBgpId = other.getBgpSession().getRemoteBgpId(); 262 + Ip4Address otherPeerBgpId = other.getBgpSession().remoteInfo().bgpId();
263 if (!peerBgpId.equals(otherPeerBgpId)) { 263 if (!peerBgpId.equals(otherPeerBgpId)) {
264 return (peerBgpId.compareTo(otherPeerBgpId) < 0); 264 return (peerBgpId.compareTo(otherPeerBgpId) < 0);
265 } 265 }
266 266
267 // Compare the peer BGP address: lower is better 267 // Compare the peer BGP address: lower is better
268 - Ip4Address peerAddress = getBgpSession().getRemoteIp4Address(); 268 + Ip4Address peerAddress = getBgpSession().remoteInfo().ip4Address();
269 Ip4Address otherPeerAddress = 269 Ip4Address otherPeerAddress =
270 - other.getBgpSession().getRemoteIp4Address(); 270 + other.getBgpSession().remoteInfo().ip4Address();
271 if (!peerAddress.equals(otherPeerAddress)) { 271 if (!peerAddress.equals(otherPeerAddress)) {
272 return (peerAddress.compareTo(otherPeerAddress) < 0); 272 return (peerAddress.compareTo(otherPeerAddress) < 0);
273 } 273 }
...@@ -486,7 +486,7 @@ public class BgpRouteEntry extends RouteEntry { ...@@ -486,7 +486,7 @@ public class BgpRouteEntry extends RouteEntry {
486 return MoreObjects.toStringHelper(getClass()) 486 return MoreObjects.toStringHelper(getClass())
487 .add("prefix", prefix()) 487 .add("prefix", prefix())
488 .add("nextHop", nextHop()) 488 .add("nextHop", nextHop())
489 - .add("bgpId", bgpSession.getRemoteBgpId()) 489 + .add("bgpId", bgpSession.remoteInfo().bgpId())
490 .add("origin", Update.Origin.typeToString(origin)) 490 .add("origin", Update.Origin.typeToString(origin))
491 .add("asPath", asPath) 491 .add("asPath", asPath)
492 .add("localPref", localPref) 492 .add("localPref", localPref)
......
...@@ -17,7 +17,6 @@ package org.onosproject.sdnip.bgp; ...@@ -17,7 +17,6 @@ package org.onosproject.sdnip.bgp;
17 17
18 import java.net.InetAddress; 18 import java.net.InetAddress;
19 import java.net.InetSocketAddress; 19 import java.net.InetSocketAddress;
20 -import java.net.SocketAddress;
21 import java.util.Collection; 20 import java.util.Collection;
22 import java.util.Collections; 21 import java.util.Collections;
23 import java.util.concurrent.ConcurrentHashMap; 22 import java.util.concurrent.ConcurrentHashMap;
...@@ -56,36 +55,9 @@ public class BgpSession extends SimpleChannelHandler { ...@@ -56,36 +55,9 @@ public class BgpSession extends SimpleChannelHandler {
56 // It is used to avoid the Netty's asynchronous closing of a channel. 55 // It is used to avoid the Netty's asynchronous closing of a channel.
57 private boolean isClosed = false; 56 private boolean isClosed = false;
58 57
59 - private SocketAddress remoteAddress; // Peer IP addr/port 58 + // BGP session info: local and remote
60 - private Ip4Address remoteIp4Address; // Peer IPv4 address 59 + private final BgpSessionInfo localInfo; // BGP session local info
61 - private int remoteBgpVersion; // 1 octet 60 + private final BgpSessionInfo remoteInfo; // BGP session remote info
62 - private long remoteAs; // 2 octets
63 - private long remoteAs4Octet; // 4 octets
64 - private long remoteHoldtime; // 2 octets
65 - private Ip4Address remoteBgpId; // 4 octets -> IPv4 address
66 - private boolean remoteMpExtensions; // Peer Multiprotocol
67 - // Extensions enabled: RFC 4760
68 - private boolean remoteIpv4Unicast; // Peer IPv4/UNICAST AFI/SAFI
69 - private boolean remoteIpv4Multicast; // Peer IPv4/MULTICAST AFI/SAFI
70 - private boolean remoteIpv6Unicast; // Peer IPv6/UNICAST AFI/SAFI
71 - private boolean remoteIpv6Multicast; // Peer IPv6/MULTICAST AFI/SAFI
72 - private boolean remoteAs4OctetCapability; // Peer 4 octet AS path capability
73 - //
74 - private SocketAddress localAddress; // Local IP addr/port
75 - private Ip4Address localIp4Address; // Local IPv4 address
76 - private int localBgpVersion; // 1 octet
77 - private long localAs; // 2 octets
78 - private long localHoldtime; // 2 octets
79 - private Ip4Address localBgpId; // 4 octets -> IPv4 address
80 - private boolean localMpExtensions; // Local Multiprotocol
81 - // Extensions enabled: RFC 4760
82 - private boolean localIpv4Unicast; // Local IPv4/UNICAST AFI/SAFI
83 - private boolean localIpv4Multicast; // Local IPv4/MULTICAST AFI/SAFI
84 - private boolean localIpv6Unicast; // Local IPv6/UNICAST AFI/SAFI
85 - private boolean localIpv6Multicast; // Local IPv6/MULTICAST AFI/SAFI
86 - private boolean localAs4OctetCapability; // Local 4 octet AS path capability
87 - //
88 - private long localKeepaliveInterval; // Keepalive interval
89 61
90 // Timers state 62 // Timers state
91 private Timer timer = new HashedWheelTimer(); 63 private Timer timer = new HashedWheelTimer();
...@@ -105,9 +77,11 @@ public class BgpSession extends SimpleChannelHandler { ...@@ -105,9 +77,11 @@ public class BgpSession extends SimpleChannelHandler {
105 */ 77 */
106 BgpSession(BgpSessionManager bgpSessionManager) { 78 BgpSession(BgpSessionManager bgpSessionManager) {
107 this.bgpSessionManager = bgpSessionManager; 79 this.bgpSessionManager = bgpSessionManager;
80 + this.localInfo = new BgpSessionInfo();
81 + this.remoteInfo = new BgpSessionInfo();
108 82
109 // NOTE: We support only BGP4 83 // NOTE: We support only BGP4
110 - this.localBgpVersion = BgpConstants.BGP_VERSION; 84 + this.localInfo.setBgpVersion(BgpConstants.BGP_VERSION);
111 } 85 }
112 86
113 /** 87 /**
...@@ -120,6 +94,44 @@ public class BgpSession extends SimpleChannelHandler { ...@@ -120,6 +94,44 @@ public class BgpSession extends SimpleChannelHandler {
120 } 94 }
121 95
122 /** 96 /**
97 + * Gets the BGP Session local information.
98 + *
99 + * @return the BGP Session local information.
100 + */
101 + public BgpSessionInfo localInfo() {
102 + return localInfo;
103 + }
104 +
105 + /**
106 + * Gets the BGP Session remote information.
107 + *
108 + * @return the BGP Session remote information.
109 + */
110 + public BgpSessionInfo remoteInfo() {
111 + return remoteInfo;
112 + }
113 +
114 + /**
115 + * Gets the BGP Multiprotocol Extensions for the session.
116 + *
117 + * @return true if the BGP Multiprotocol Extensions are enabled for the
118 + * session, otherwise false
119 + */
120 + public boolean mpExtensions() {
121 + return remoteInfo.mpExtensions() && localInfo.mpExtensions();
122 + }
123 +
124 + /**
125 + * Gets the BGP session 4 octet AS path capability.
126 + *
127 + * @return true when the BGP session is 4 octet AS path capable
128 + */
129 + public boolean isAs4OctetCapable() {
130 + return remoteInfo.as4OctetCapability() &&
131 + localInfo.as4OctetCapability();
132 + }
133 +
134 + /**
123 * Gets the IPv4 BGP RIB-IN routing entries. 135 * Gets the IPv4 BGP RIB-IN routing entries.
124 * 136 *
125 * @return the IPv4 BGP RIB-IN routing entries 137 * @return the IPv4 BGP RIB-IN routing entries
...@@ -227,360 +239,6 @@ public class BgpSession extends SimpleChannelHandler { ...@@ -227,360 +239,6 @@ public class BgpSession extends SimpleChannelHandler {
227 } 239 }
228 240
229 /** 241 /**
230 - * Gets the BGP session remote address.
231 - *
232 - * @return the BGP session remote address
233 - */
234 - public SocketAddress getRemoteAddress() {
235 - return remoteAddress;
236 - }
237 -
238 - /**
239 - * Gets the BGP session remote IPv4 address.
240 - *
241 - * @return the BGP session remote IPv4 address
242 - */
243 - public Ip4Address getRemoteIp4Address() {
244 - return remoteIp4Address;
245 - }
246 -
247 - /**
248 - * Gets the BGP session remote BGP version.
249 - *
250 - * @return the BGP session remote BGP version
251 - */
252 - public int getRemoteBgpVersion() {
253 - return remoteBgpVersion;
254 - }
255 -
256 - /**
257 - * Sets the BGP session remote BGP version.
258 - *
259 - * @param remoteBgpVersion the BGP session remote BGP version to set
260 - */
261 - void setRemoteBgpVersion(int remoteBgpVersion) {
262 - this.remoteBgpVersion = remoteBgpVersion;
263 - }
264 -
265 - /**
266 - * Gets the BGP session remote AS number.
267 - *
268 - * @return the BGP session remote AS number
269 - */
270 - public long getRemoteAs() {
271 - return remoteAs;
272 - }
273 -
274 - /**
275 - * Sets the BGP session remote AS number.
276 - *
277 - * @param remoteAs the BGP session remote AS number to set
278 - */
279 - void setRemoteAs(long remoteAs) {
280 - this.remoteAs = remoteAs;
281 -
282 - //
283 - // NOTE: Currently, the local AS number is always set to the remote AS.
284 - // This is done, because the peer setup is always iBGP.
285 - // In the future the local AS number should be configured as part
286 - // of an explicit BGP peering configuration.
287 - //
288 - setLocalAs(remoteAs);
289 - }
290 -
291 - /**
292 - * Sets the BGP session remote 4 octet AS number.
293 - *
294 - * @param remoteAs4Octet the BGP session remote 4 octet AS number to set
295 - */
296 - void setRemoteAs4Octet(long remoteAs4Octet) {
297 - this.remoteAs4Octet = remoteAs4Octet;
298 - }
299 -
300 - /**
301 - * Gets the BGP session remote Holdtime.
302 - *
303 - * @return the BGP session remote Holdtime
304 - */
305 - public long getRemoteHoldtime() {
306 - return remoteHoldtime;
307 - }
308 -
309 - /**
310 - * Sets the BGP session remote Holdtime.
311 - *
312 - * @param remoteHoldtime the BGP session remote Holdtime to set
313 - */
314 - void setRemoteHoldtime(long remoteHoldtime) {
315 - this.remoteHoldtime = remoteHoldtime;
316 -
317 - //
318 - // NOTE: Currently. the local BGP Holdtime is always set to the remote
319 - // BGP holdtime.
320 - // In the future, the local BGP Holdtime should be configured as part
321 - // of an explicit BGP peering configuration.
322 - //
323 - this.localHoldtime = remoteHoldtime;
324 -
325 - // Set the local Keepalive interval
326 - if (localHoldtime == 0) {
327 - localKeepaliveInterval = 0;
328 - } else {
329 - localKeepaliveInterval = Math.max(localHoldtime /
330 - BgpConstants.BGP_KEEPALIVE_PER_HOLD_INTERVAL,
331 - BgpConstants.BGP_KEEPALIVE_MIN_INTERVAL);
332 - }
333 - }
334 -
335 - /**
336 - * Gets the BGP session remote BGP Identifier as an IPv4 address.
337 - *
338 - * @return the BGP session remote BGP Identifier as an IPv4 address
339 - */
340 - public Ip4Address getRemoteBgpId() {
341 - return remoteBgpId;
342 - }
343 -
344 - /**
345 - * Sets the BGP session remote BGP Identifier as an IPv4 address.
346 - *
347 - * @param remoteBgpId the BGP session remote BGP Identifier to set
348 - */
349 - void setRemoteBgpId(Ip4Address remoteBgpId) {
350 - this.remoteBgpId = remoteBgpId;
351 - }
352 -
353 - /**
354 - * Gets the BGP Multiprotocol Extensions for the session.
355 - *
356 - * @return true if the BGP Multiprotocol Extensions are enabled for the
357 - * session, otherwise false
358 - */
359 - public boolean getMpExtensions() {
360 - return remoteMpExtensions && localMpExtensions;
361 - }
362 -
363 - /**
364 - * Gets the BGP session remote AFI/SAFI configuration for IPv4 unicast.
365 - *
366 - * @return the BGP session remote AFI/SAFI configuration for IPv4 unicast
367 - */
368 - public boolean getRemoteIpv4Unicast() {
369 - return remoteIpv4Unicast;
370 - }
371 -
372 - /**
373 - * Sets the BGP session remote AFI/SAFI configuration for IPv4 unicast.
374 - */
375 - void setRemoteIpv4Unicast() {
376 - this.remoteMpExtensions = true;
377 - this.remoteIpv4Unicast = true;
378 - // Copy the remote AFI/SAFI setting to the local configuration
379 - this.localMpExtensions = true;
380 - this.localIpv4Unicast = true;
381 - }
382 -
383 - /**
384 - * Gets the BGP session remote AFI/SAFI configuration for IPv4 multicast.
385 - *
386 - * @return the BGP session remote AFI/SAFI configuration for IPv4 multicast
387 - */
388 - public boolean getRemoteIpv4Multicast() {
389 - return remoteIpv4Multicast;
390 - }
391 -
392 - /**
393 - * Sets the BGP session remote AFI/SAFI configuration for IPv4 multicast.
394 - */
395 - void setRemoteIpv4Multicast() {
396 - this.remoteMpExtensions = true;
397 - this.remoteIpv4Multicast = true;
398 - // Copy the remote AFI/SAFI setting to the local configuration
399 - this.localMpExtensions = true;
400 - this.localIpv4Multicast = true;
401 - }
402 -
403 - /**
404 - * Gets the BGP session remote AFI/SAFI configuration for IPv6 unicast.
405 - *
406 - * @return the BGP session remote AFI/SAFI configuration for IPv6 unicast
407 - */
408 - public boolean getRemoteIpv6Unicast() {
409 - return remoteIpv6Unicast;
410 - }
411 -
412 - /**
413 - * Sets the BGP session remote AFI/SAFI configuration for IPv6 unicast.
414 - */
415 - void setRemoteIpv6Unicast() {
416 - this.remoteMpExtensions = true;
417 - this.remoteIpv6Unicast = true;
418 - // Copy the remote AFI/SAFI setting to the local configuration
419 - this.localMpExtensions = true;
420 - this.localIpv6Unicast = true;
421 - }
422 -
423 - /**
424 - * Gets the BGP session remote AFI/SAFI configuration for IPv6 multicast.
425 - *
426 - * @return the BGP session remote AFI/SAFI configuration for IPv6 multicast
427 - */
428 - public boolean getRemoteIpv6Multicast() {
429 - return remoteIpv6Multicast;
430 - }
431 -
432 - /**
433 - * Sets the BGP session remote AFI/SAFI configuration for IPv6 multicast.
434 - */
435 - void setRemoteIpv6Multicast() {
436 - this.remoteMpExtensions = true;
437 - this.remoteIpv6Multicast = true;
438 - // Copy the remote AFI/SAFI setting to the local configuration
439 - this.localMpExtensions = true;
440 - this.localIpv6Multicast = true;
441 - }
442 -
443 - /**
444 - * Gets the BGP session remote 4 octet AS path capability.
445 - *
446 - * @return true when the BGP session remote has 4 octet AS path capability
447 - */
448 - public boolean getRemoteAs4OctetCapability() {
449 - return remoteAs4OctetCapability;
450 - }
451 -
452 - /**
453 - * Sets the BGP session remote 4 octet AS path capability.
454 - */
455 - void setRemoteAs4OctetCapability() {
456 - this.remoteAs4OctetCapability = true;
457 - }
458 -
459 - /**
460 - * Gets the BGP session local 4 octet AS path capability.
461 - *
462 - * @return true when the BGP session local has 4 octet AS path capability
463 - */
464 - public boolean getLocalAs4OctetCapability() {
465 - return localAs4OctetCapability;
466 - }
467 -
468 - /**
469 - * Sets the BGP session local 4 octet AS path capability.
470 - */
471 - void setLocalAs4OctetCapability() {
472 - this.localAs4OctetCapability = true;
473 - }
474 -
475 - /**
476 - * Gets the BGP session 4 octet AS path capability.
477 - *
478 - * @return true when the BGP session is 4 octet AS path capable
479 - */
480 - public boolean isAs4OctetCapable() {
481 - return getRemoteAs4OctetCapability() && getLocalAs4OctetCapability();
482 - }
483 -
484 - /**
485 - * Gets the BGP session local address.
486 - *
487 - * @return the BGP session local address
488 - */
489 - public SocketAddress getLocalAddress() {
490 - return localAddress;
491 - }
492 -
493 - /**
494 - * Gets the BGP session local IPv4 address.
495 - *
496 - * @return the BGP session local IPv4 address
497 - */
498 - public Ip4Address getLocalIp4Address() {
499 - return localIp4Address;
500 - }
501 -
502 - /**
503 - * Gets the BGP session local BGP version.
504 - *
505 - * @return the BGP session local BGP version
506 - */
507 - public int getLocalBgpVersion() {
508 - return localBgpVersion;
509 - }
510 -
511 - /**
512 - * Gets the BGP session local AS number.
513 - *
514 - * @return the BGP session local AS number
515 - */
516 - public long getLocalAs() {
517 - return localAs;
518 - }
519 -
520 - /**
521 - * Sets the BGP session local AS number.
522 - *
523 - * @param localAs the BGP session local AS number to set
524 - */
525 - public void setLocalAs(long localAs) {
526 - this.localAs = localAs;
527 - }
528 -
529 - /**
530 - * Gets the BGP session local Holdtime.
531 - *
532 - * @return the BGP session local Holdtime
533 - */
534 - public long getLocalHoldtime() {
535 - return localHoldtime;
536 - }
537 -
538 - /**
539 - * Gets the BGP session local BGP Identifier as an IPv4 address.
540 - *
541 - * @return the BGP session local BGP Identifier as an IPv4 address
542 - */
543 - public Ip4Address getLocalBgpId() {
544 - return localBgpId;
545 - }
546 -
547 - /**
548 - * Gets the BGP session local AFI/SAFI configuration for IPv4 unicast.
549 - *
550 - * @return the BGP session local AFI/SAFI configuration for IPv4 unicast
551 - */
552 - public boolean getLocalIpv4Unicast() {
553 - return localIpv4Unicast;
554 - }
555 -
556 - /**
557 - * Gets the BGP session local AFI/SAFI configuration for IPv4 multicast.
558 - *
559 - * @return the BGP session local AFI/SAFI configuration for IPv4 multicast
560 - */
561 - public boolean getLocalIpv4Multicast() {
562 - return localIpv4Multicast;
563 - }
564 -
565 - /**
566 - * Gets the BGP session local AFI/SAFI configuration for IPv6 unicast.
567 - *
568 - * @return the BGP session local AFI/SAFI configuration for IPv6 unicast
569 - */
570 - public boolean getLocalIpv6Unicast() {
571 - return localIpv6Unicast;
572 - }
573 -
574 - /**
575 - * Gets the BGP session local AFI/SAFI configuration for IPv6 multicast.
576 - *
577 - * @return the BGP session local AFI/SAFI configuration for IPv6 multicast
578 - */
579 - public boolean getLocalIpv6Multicast() {
580 - return localIpv6Multicast;
581 - }
582 -
583 - /**
584 * Tests whether the session is closed. 242 * Tests whether the session is closed.
585 * <p> 243 * <p>
586 * NOTE: We use this method to avoid the Netty's asynchronous closing 244 * NOTE: We use this method to avoid the Netty's asynchronous closing
...@@ -627,25 +285,25 @@ public class BgpSession extends SimpleChannelHandler { ...@@ -627,25 +285,25 @@ public class BgpSession extends SimpleChannelHandler {
627 @Override 285 @Override
628 public void channelConnected(ChannelHandlerContext ctx, 286 public void channelConnected(ChannelHandlerContext ctx,
629 ChannelStateEvent channelEvent) { 287 ChannelStateEvent channelEvent) {
630 - localAddress = ctx.getChannel().getLocalAddress(); 288 + localInfo.setAddress(ctx.getChannel().getLocalAddress());
631 - remoteAddress = ctx.getChannel().getRemoteAddress(); 289 + remoteInfo.setAddress(ctx.getChannel().getRemoteAddress());
632 290
633 // Assign the local and remote IPv4 addresses 291 // Assign the local and remote IPv4 addresses
634 InetAddress inetAddr; 292 InetAddress inetAddr;
635 - if (localAddress instanceof InetSocketAddress) { 293 + if (localInfo.address() instanceof InetSocketAddress) {
636 - inetAddr = ((InetSocketAddress) localAddress).getAddress(); 294 + inetAddr = ((InetSocketAddress) localInfo.address()).getAddress();
637 - localIp4Address = Ip4Address.valueOf(inetAddr.getAddress()); 295 + localInfo.setIp4Address(Ip4Address.valueOf(inetAddr.getAddress()));
638 } 296 }
639 - if (remoteAddress instanceof InetSocketAddress) { 297 + if (remoteInfo.address() instanceof InetSocketAddress) {
640 - inetAddr = ((InetSocketAddress) remoteAddress).getAddress(); 298 + inetAddr = ((InetSocketAddress) remoteInfo.address()).getAddress();
641 - remoteIp4Address = Ip4Address.valueOf(inetAddr.getAddress()); 299 + remoteInfo.setIp4Address(Ip4Address.valueOf(inetAddr.getAddress()));
642 } 300 }
643 301
644 log.debug("BGP Session Connected from {} on {}", 302 log.debug("BGP Session Connected from {} on {}",
645 - remoteAddress, localAddress); 303 + remoteInfo.address(), localInfo.address());
646 if (!bgpSessionManager.peerConnected(this)) { 304 if (!bgpSessionManager.peerConnected(this)) {
647 log.debug("Cannot setup BGP Session Connection from {}. Closing...", 305 log.debug("Cannot setup BGP Session Connection from {}. Closing...",
648 - remoteAddress); 306 + remoteInfo.address());
649 ctx.getChannel().close(); 307 ctx.getChannel().close();
650 } 308 }
651 309
...@@ -653,7 +311,7 @@ public class BgpSession extends SimpleChannelHandler { ...@@ -653,7 +311,7 @@ public class BgpSession extends SimpleChannelHandler {
653 // Assign the local BGP ID 311 // Assign the local BGP ID
654 // NOTE: This should be configuration-based 312 // NOTE: This should be configuration-based
655 // 313 //
656 - localBgpId = bgpSessionManager.getMyBgpId(); 314 + localInfo.setBgpId(bgpSessionManager.getMyBgpId());
657 } 315 }
658 316
659 @Override 317 @Override
...@@ -706,6 +364,18 @@ public class BgpSession extends SimpleChannelHandler { ...@@ -706,6 +364,18 @@ public class BgpSession extends SimpleChannelHandler {
706 * @param ctx the Channel Handler Context to use 364 * @param ctx the Channel Handler Context to use
707 */ 365 */
708 void restartKeepaliveTimer(ChannelHandlerContext ctx) { 366 void restartKeepaliveTimer(ChannelHandlerContext ctx) {
367 + long localKeepaliveInterval = 0;
368 +
369 + //
370 + // Compute the local Keepalive interval
371 + //
372 + if (localInfo.holdtime() != 0) {
373 + localKeepaliveInterval = Math.max(localInfo.holdtime() /
374 + BgpConstants.BGP_KEEPALIVE_PER_HOLD_INTERVAL,
375 + BgpConstants.BGP_KEEPALIVE_MIN_INTERVAL);
376 + }
377 +
378 + // Restart the Keepalive timer
709 if (localKeepaliveInterval == 0) { 379 if (localKeepaliveInterval == 0) {
710 return; // Nothing to do 380 return; // Nothing to do
711 } 381 }
...@@ -753,14 +423,14 @@ public class BgpSession extends SimpleChannelHandler { ...@@ -753,14 +423,14 @@ public class BgpSession extends SimpleChannelHandler {
753 * @param ctx the Channel Handler Context to use 423 * @param ctx the Channel Handler Context to use
754 */ 424 */
755 void restartSessionTimeoutTimer(ChannelHandlerContext ctx) { 425 void restartSessionTimeoutTimer(ChannelHandlerContext ctx) {
756 - if (remoteHoldtime == 0) { 426 + if (remoteInfo.holdtime() == 0) {
757 return; // Nothing to do 427 return; // Nothing to do
758 } 428 }
759 if (sessionTimeout != null) { 429 if (sessionTimeout != null) {
760 sessionTimeout.cancel(); 430 sessionTimeout.cancel();
761 } 431 }
762 sessionTimeout = timer.newTimeout(new SessionTimeoutTask(ctx), 432 sessionTimeout = timer.newTimeout(new SessionTimeoutTask(ctx),
763 - remoteHoldtime, 433 + remoteInfo.holdtime(),
764 TimeUnit.SECONDS); 434 TimeUnit.SECONDS);
765 } 435 }
766 436
...@@ -788,7 +458,7 @@ public class BgpSession extends SimpleChannelHandler { ...@@ -788,7 +458,7 @@ public class BgpSession extends SimpleChannelHandler {
788 return; 458 return;
789 } 459 }
790 460
791 - log.debug("BGP Session Timeout: peer {}", remoteAddress); 461 + log.debug("BGP Session Timeout: peer {}", remoteInfo.address());
792 // 462 //
793 // ERROR: Invalid Optional Parameter Length field: Unspecific 463 // ERROR: Invalid Optional Parameter Length field: Unspecific
794 // 464 //
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.sdnip.bgp;
17 +
18 +import java.net.SocketAddress;
19 +import org.onlab.packet.Ip4Address;
20 +
21 +/**
22 + * Class for keeping information about a BGP session.
23 + *
24 + * There are two instances per each BGP peer session: one to keep the local
25 + * information about the BGP session, and another to keep information about
26 + * the remote BGP peer.
27 + */
28 +public class BgpSessionInfo {
29 + private SocketAddress address; // IP addr/port
30 + private Ip4Address ip4Address; // IPv4 address
31 + private int bgpVersion; // 1 octet
32 + private long asNumber; // AS number: 2 octets
33 + private long as4Number; // AS4 number: 4 octets
34 + private long holdtime; // 2 octets
35 + private Ip4Address bgpId; // 4 octets -> IPv4 address
36 + private boolean mpExtensions; // Multiprotocol Extensions
37 + // enabled: RFC 4760
38 + private boolean ipv4Unicast; // IPv4/UNICAST AFI/SAFI
39 + private boolean ipv4Multicast; // IPv4/MULTICAST AFI/SAFI
40 + private boolean ipv6Unicast; // IPv6/UNICAST AFI/SAFI
41 + private boolean ipv6Multicast; // IPv6/MULTICAST AFI/SAFI
42 + private boolean as4OctetCapability; // AS 4 octet path capability
43 +
44 + /**
45 + * Gets the BGP session address: local or remote.
46 + *
47 + * @return the BGP session address
48 + */
49 + public SocketAddress address() {
50 + return this.address;
51 + }
52 +
53 + /**
54 + * Sets the BGP session address: local or remote.
55 + *
56 + * @param address the BGP session address to set
57 + */
58 + public void setAddress(SocketAddress address) {
59 + this.address = address;
60 + }
61 +
62 + /**
63 + * Gets the BGP session IPv4 address: local or remote.
64 + *
65 + * @return the BGP session IPv4 address
66 + */
67 + public Ip4Address ip4Address() {
68 + return this.ip4Address;
69 + }
70 +
71 + /**
72 + * Sets the BGP session IPv4 address: local or remote.
73 + *
74 + * @param ip4Address the BGP session IPv4 address to set
75 + */
76 + public void setIp4Address(Ip4Address ip4Address) {
77 + this.ip4Address = ip4Address;
78 + }
79 +
80 + /**
81 + * Gets the BGP session BGP version: local or remote.
82 + *
83 + * @return the BGP session BGP version
84 + */
85 + public int bgpVersion() {
86 + return this.bgpVersion;
87 + }
88 +
89 + /**
90 + * Sets the BGP session BGP version: local or remote.
91 + *
92 + * @param bgpVersion the BGP session BGP version to set
93 + */
94 + public void setBgpVersion(int bgpVersion) {
95 + this.bgpVersion = bgpVersion;
96 + }
97 +
98 + /**
99 + * Gets the BGP session AS number: local or remote.
100 + *
101 + * @return the BGP session AS number
102 + */
103 + public long asNumber() {
104 + return this.asNumber;
105 + }
106 +
107 + /**
108 + * Sets the BGP session AS number: local or remote.
109 + *
110 + * @param asNumber the BGP session AS number to set
111 + */
112 + public void setAsNumber(long asNumber) {
113 + this.asNumber = asNumber;
114 + }
115 +
116 + /**
117 + * Gets the BGP session AS4 number: local or remote.
118 + *
119 + * @return the BGP session AS4 number
120 + */
121 + public long as4Number() {
122 + return this.as4Number;
123 + }
124 +
125 + /**
126 + * Sets the BGP session AS4 number: local or remote.
127 + *
128 + * @param as4Number the BGP session AS4 number to set
129 + */
130 + public void setAs4Number(long as4Number) {
131 + this.as4Number = as4Number;
132 + }
133 +
134 + /**
135 + * Gets the BGP session holdtime: local or remote.
136 + *
137 + * @return the BGP session holdtime
138 + */
139 + public long holdtime() {
140 + return this.holdtime;
141 + }
142 +
143 + /**
144 + * Sets the BGP session holdtime: local or remote.
145 + *
146 + * @param holdtime the BGP session holdtime to set
147 + */
148 + public void setHoldtime(long holdtime) {
149 + this.holdtime = holdtime;
150 + }
151 +
152 + /**
153 + * Gets the BGP session BGP Identifier as an IPv4 address: local or remote.
154 + *
155 + * @return the BGP session BGP Identifier as an IPv4 address
156 + */
157 + public Ip4Address bgpId() {
158 + return this.bgpId;
159 + }
160 +
161 + /**
162 + * Sets the BGP session BGP Identifier as an IPv4 address: local or remote.
163 + *
164 + * @param bgpId the BGP session BGP Identifier to set
165 + */
166 + public void setBgpId(Ip4Address bgpId) {
167 + this.bgpId = bgpId;
168 + }
169 +
170 + /**
171 + * Gets the BGP Multiprotocol Extensions: local or remote.
172 + *
173 + * @return true if the BGP Multiprotocol Extensions are enabled, otherwise
174 + * false
175 + */
176 + public boolean mpExtensions() {
177 + return this.mpExtensions;
178 + }
179 +
180 + /**
181 + * Gets the BGP session AFI/SAFI configuration for IPv4 unicast: local or
182 + * remote.
183 + *
184 + * @return the BGP session AFI/SAFI configuration for IPv4 unicast
185 + */
186 + public boolean ipv4Unicast() {
187 + return ipv4Unicast;
188 + }
189 +
190 + /**
191 + * Sets the BGP session AFI/SAFI configuration for IPv4 unicast: local or
192 + * remote.
193 + */
194 + public void setIpv4Unicast() {
195 + this.mpExtensions = true;
196 + this.ipv4Unicast = true;
197 + }
198 +
199 + /**
200 + * Gets the BGP session AFI/SAFI configuration for IPv4 multicast: local or
201 + * remote.
202 + *
203 + * @return the BGP session AFI/SAFI configuration for IPv4 multicast
204 + */
205 + public boolean ipv4Multicast() {
206 + return ipv4Multicast;
207 + }
208 +
209 + /**
210 + * Sets the BGP session AFI/SAFI configuration for IPv4 multicast: local or
211 + * remote.
212 + */
213 + public void setIpv4Multicast() {
214 + this.mpExtensions = true;
215 + this.ipv4Multicast = true;
216 + }
217 +
218 + /**
219 + * Gets the BGP session AFI/SAFI configuration for IPv6 unicast: local or
220 + * remote.
221 + *
222 + * @return the BGP session AFI/SAFI configuration for IPv6 unicast
223 + */
224 + public boolean ipv6Unicast() {
225 + return ipv6Unicast;
226 + }
227 +
228 + /**
229 + * Sets the BGP session AFI/SAFI configuration for IPv6 unicast: local or
230 + * remote.
231 + */
232 + void setIpv6Unicast() {
233 + this.mpExtensions = true;
234 + this.ipv6Unicast = true;
235 + }
236 +
237 + /**
238 + * Gets the BGP session AFI/SAFI configuration for IPv6 multicast: local or
239 + * remote.
240 + *
241 + * @return the BGP session AFI/SAFI configuration for IPv6 multicast
242 + */
243 + public boolean ipv6Multicast() {
244 + return ipv6Multicast;
245 + }
246 +
247 + /**
248 + * Sets the BGP session AFI/SAFI configuration for IPv6 multicast: local or
249 + * remote.
250 + */
251 + public void setIpv6Multicast() {
252 + this.mpExtensions = true;
253 + this.ipv6Multicast = true;
254 + }
255 +
256 + /**
257 + * Gets the BGP session 4 octet AS path capability: local or remote.
258 + *
259 + * @return true when the BGP session has 4 octet AS path capability
260 + */
261 + public boolean as4OctetCapability() {
262 + return this.as4OctetCapability;
263 + }
264 +
265 + /**
266 + * Sets the BGP session 4 octet AS path capability.
267 + */
268 + public void setAs4OctetCapability() {
269 + this.as4OctetCapability = true;
270 + }
271 +}
...@@ -189,18 +189,18 @@ public class BgpSessionManager { ...@@ -189,18 +189,18 @@ public class BgpSessionManager {
189 boolean peerConnected(BgpSession bgpSession) { 189 boolean peerConnected(BgpSession bgpSession) {
190 190
191 // Test whether there is already a session from the same remote 191 // Test whether there is already a session from the same remote
192 - if (bgpSessions.get(bgpSession.getRemoteAddress()) != null) { 192 + if (bgpSessions.get(bgpSession.remoteInfo().address()) != null) {
193 return false; // Duplicate BGP session 193 return false; // Duplicate BGP session
194 } 194 }
195 - bgpSessions.put(bgpSession.getRemoteAddress(), bgpSession); 195 + bgpSessions.put(bgpSession.remoteInfo().address(), bgpSession);
196 196
197 // 197 //
198 // If the first connection, set my BGP ID to the local address 198 // If the first connection, set my BGP ID to the local address
199 // of the socket. 199 // of the socket.
200 // 200 //
201 - if (bgpSession.getLocalAddress() instanceof InetSocketAddress) { 201 + if (bgpSession.localInfo().address() instanceof InetSocketAddress) {
202 InetAddress inetAddr = 202 InetAddress inetAddr =
203 - ((InetSocketAddress) bgpSession.getLocalAddress()).getAddress(); 203 + ((InetSocketAddress) bgpSession.localInfo().address()).getAddress();
204 Ip4Address ip4Address = Ip4Address.valueOf(inetAddr.getAddress()); 204 Ip4Address ip4Address = Ip4Address.valueOf(inetAddr.getAddress());
205 updateMyBgpId(ip4Address); 205 updateMyBgpId(ip4Address);
206 } 206 }
...@@ -213,7 +213,7 @@ public class BgpSessionManager { ...@@ -213,7 +213,7 @@ public class BgpSessionManager {
213 * @param bgpSession the BGP session for the peer 213 * @param bgpSession the BGP session for the peer
214 */ 214 */
215 void peerDisconnected(BgpSession bgpSession) { 215 void peerDisconnected(BgpSession bgpSession) {
216 - bgpSessions.remove(bgpSession.getRemoteAddress()); 216 + bgpSessions.remove(bgpSession.remoteInfo().address());
217 } 217 }
218 218
219 /** 219 /**
......
...@@ -68,8 +68,8 @@ final class BgpUpdate { ...@@ -68,8 +68,8 @@ final class BgpUpdate {
68 if (message.readableBytes() < minLength) { 68 if (message.readableBytes() < minLength) {
69 log.debug("BGP RX UPDATE Error from {}: " + 69 log.debug("BGP RX UPDATE Error from {}: " +
70 "Message length {} too short. Must be at least {}", 70 "Message length {} too short. Must be at least {}",
71 - bgpSession.getRemoteAddress(), message.readableBytes(), 71 + bgpSession.remoteInfo().address(),
72 - minLength); 72 + message.readableBytes(), minLength);
73 // 73 //
74 // ERROR: Bad Message Length 74 // ERROR: Bad Message Length
75 // 75 //
...@@ -83,7 +83,7 @@ final class BgpUpdate { ...@@ -83,7 +83,7 @@ final class BgpUpdate {
83 } 83 }
84 84
85 log.debug("BGP RX UPDATE message from {}", 85 log.debug("BGP RX UPDATE message from {}",
86 - bgpSession.getRemoteAddress()); 86 + bgpSession.remoteInfo().address());
87 87
88 // 88 //
89 // Parse the UPDATE message 89 // Parse the UPDATE message
...@@ -105,13 +105,13 @@ final class BgpUpdate { ...@@ -105,13 +105,13 @@ final class BgpUpdate {
105 } catch (BgpParseException e) { 105 } catch (BgpParseException e) {
106 // ERROR: Invalid Network Field 106 // ERROR: Invalid Network Field
107 log.debug("Exception parsing Withdrawn Prefixes from BGP peer {}: ", 107 log.debug("Exception parsing Withdrawn Prefixes from BGP peer {}: ",
108 - bgpSession.getRemoteBgpId(), e); 108 + bgpSession.remoteInfo().bgpId(), e);
109 actionsBgpUpdateInvalidNetworkField(bgpSession, ctx); 109 actionsBgpUpdateInvalidNetworkField(bgpSession, ctx);
110 return; 110 return;
111 } 111 }
112 for (Ip4Prefix prefix : withdrawnPrefixes) { 112 for (Ip4Prefix prefix : withdrawnPrefixes) {
113 log.debug("BGP RX UPDATE message WITHDRAWN from {}: {}", 113 log.debug("BGP RX UPDATE message WITHDRAWN from {}: {}",
114 - bgpSession.getRemoteAddress(), prefix); 114 + bgpSession.remoteInfo().address(), prefix);
115 BgpRouteEntry bgpRouteEntry = bgpSession.findBgpRoute(prefix); 115 BgpRouteEntry bgpRouteEntry = bgpSession.findBgpRoute(prefix);
116 if (bgpRouteEntry != null) { 116 if (bgpRouteEntry != null) {
117 decodedBgpRoutes.deletedUnicastRoutes4.put(prefix, 117 decodedBgpRoutes.deletedUnicastRoutes4.put(prefix,
...@@ -126,7 +126,7 @@ final class BgpUpdate { ...@@ -126,7 +126,7 @@ final class BgpUpdate {
126 parsePathAttributes(bgpSession, ctx, message, decodedBgpRoutes); 126 parsePathAttributes(bgpSession, ctx, message, decodedBgpRoutes);
127 } catch (BgpParseException e) { 127 } catch (BgpParseException e) {
128 log.debug("Exception parsing Path Attributes from BGP peer {}: ", 128 log.debug("Exception parsing Path Attributes from BGP peer {}: ",
129 - bgpSession.getRemoteBgpId(), e); 129 + bgpSession.remoteInfo().bgpId(), e);
130 // NOTE: The session was already closed, so nothing else to do 130 // NOTE: The session was already closed, so nothing else to do
131 return; 131 return;
132 } 132 }
...@@ -366,7 +366,7 @@ final class BgpUpdate { ...@@ -366,7 +366,7 @@ final class BgpUpdate {
366 // Skip the data from the unrecognized attribute 366 // Skip the data from the unrecognized attribute
367 log.debug("BGP RX UPDATE message from {}: " + 367 log.debug("BGP RX UPDATE message from {}: " +
368 "Unrecognized Attribute Type {}", 368 "Unrecognized Attribute Type {}",
369 - bgpSession.getRemoteAddress(), attrTypeCode); 369 + bgpSession.remoteInfo().address(), attrTypeCode);
370 message.skipBytes(attrLen); 370 message.skipBytes(attrLen);
371 break; 371 break;
372 } 372 }
...@@ -384,7 +384,7 @@ final class BgpUpdate { ...@@ -384,7 +384,7 @@ final class BgpUpdate {
384 } catch (BgpParseException e) { 384 } catch (BgpParseException e) {
385 // ERROR: Invalid Network Field 385 // ERROR: Invalid Network Field
386 log.debug("Exception parsing NLRI from BGP peer {}: ", 386 log.debug("Exception parsing NLRI from BGP peer {}: ",
387 - bgpSession.getRemoteBgpId(), e); 387 + bgpSession.remoteInfo().bgpId(), e);
388 actionsBgpUpdateInvalidNetworkField(bgpSession, ctx); 388 actionsBgpUpdateInvalidNetworkField(bgpSession, ctx);
389 // Rethrow the exception 389 // Rethrow the exception
390 throw e; 390 throw e;
...@@ -433,15 +433,15 @@ final class BgpUpdate { ...@@ -433,15 +433,15 @@ final class BgpUpdate {
433 new BgpRouteEntry(bgpSession, prefix, mpNlri.nextHop4, 433 new BgpRouteEntry(bgpSession, prefix, mpNlri.nextHop4,
434 origin.byteValue(), asPath, localPref); 434 origin.byteValue(), asPath, localPref);
435 bgpRouteEntry.setMultiExitDisc(multiExitDisc); 435 bgpRouteEntry.setMultiExitDisc(multiExitDisc);
436 - if (bgpRouteEntry.hasAsPathLoop(bgpSession.getLocalAs())) { 436 + if (bgpRouteEntry.hasAsPathLoop(bgpSession.localInfo().asNumber())) {
437 log.debug("BGP RX UPDATE message IGNORED from {}: {} " + 437 log.debug("BGP RX UPDATE message IGNORED from {}: {} " +
438 "nextHop {}: contains AS Path loop", 438 "nextHop {}: contains AS Path loop",
439 - bgpSession.getRemoteAddress(), prefix, 439 + bgpSession.remoteInfo().address(), prefix,
440 mpNlri.nextHop4); 440 mpNlri.nextHop4);
441 continue; 441 continue;
442 } else { 442 } else {
443 log.debug("BGP RX UPDATE message ADDED from {}: {} nextHop {}", 443 log.debug("BGP RX UPDATE message ADDED from {}: {} nextHop {}",
444 - bgpSession.getRemoteAddress(), prefix, 444 + bgpSession.remoteInfo().address(), prefix,
445 mpNlri.nextHop4); 445 mpNlri.nextHop4);
446 } 446 }
447 // Remove from the collection of deleted routes 447 // Remove from the collection of deleted routes
...@@ -456,15 +456,15 @@ final class BgpUpdate { ...@@ -456,15 +456,15 @@ final class BgpUpdate {
456 new BgpRouteEntry(bgpSession, prefix, mpNlri.nextHop6, 456 new BgpRouteEntry(bgpSession, prefix, mpNlri.nextHop6,
457 origin.byteValue(), asPath, localPref); 457 origin.byteValue(), asPath, localPref);
458 bgpRouteEntry.setMultiExitDisc(multiExitDisc); 458 bgpRouteEntry.setMultiExitDisc(multiExitDisc);
459 - if (bgpRouteEntry.hasAsPathLoop(bgpSession.getLocalAs())) { 459 + if (bgpRouteEntry.hasAsPathLoop(bgpSession.localInfo().asNumber())) {
460 log.debug("BGP RX UPDATE message IGNORED from {}: {} " + 460 log.debug("BGP RX UPDATE message IGNORED from {}: {} " +
461 "nextHop {}: contains AS Path loop", 461 "nextHop {}: contains AS Path loop",
462 - bgpSession.getRemoteAddress(), prefix, 462 + bgpSession.remoteInfo().address(), prefix,
463 mpNlri.nextHop6); 463 mpNlri.nextHop6);
464 continue; 464 continue;
465 } else { 465 } else {
466 log.debug("BGP RX UPDATE message ADDED from {}: {} nextHop {}", 466 log.debug("BGP RX UPDATE message ADDED from {}: {} nextHop {}",
467 - bgpSession.getRemoteAddress(), prefix, 467 + bgpSession.remoteInfo().address(), prefix,
468 mpNlri.nextHop6); 468 mpNlri.nextHop6);
469 } 469 }
470 // Remove from the collection of deleted routes 470 // Remove from the collection of deleted routes
...@@ -507,7 +507,7 @@ final class BgpUpdate { ...@@ -507,7 +507,7 @@ final class BgpUpdate {
507 // Multiprotocol Extensions are not enabled, even if the UPDATE 507 // Multiprotocol Extensions are not enabled, even if the UPDATE
508 // message doesn't contain the legacy NLRI (per RFC 4271). 508 // message doesn't contain the legacy NLRI (per RFC 4271).
509 // 509 //
510 - if (!bgpSession.getMpExtensions()) { 510 + if (!bgpSession.mpExtensions()) {
511 hasNlri = true; 511 hasNlri = true;
512 hasLegacyNlri = true; 512 hasLegacyNlri = true;
513 } else { 513 } else {
...@@ -838,7 +838,7 @@ final class BgpUpdate { ...@@ -838,7 +838,7 @@ final class BgpUpdate {
838 // Here we check only (a), because (b) doesn't apply for us: all our 838 // Here we check only (a), because (b) doesn't apply for us: all our
839 // peers are iBGP. 839 // peers are iBGP.
840 // 840 //
841 - if (nextHopAddress.equals(bgpSession.getLocalIp4Address())) { 841 + if (nextHopAddress.equals(bgpSession.localInfo().ip4Address())) {
842 // ERROR: Invalid NEXT_HOP Attribute 842 // ERROR: Invalid NEXT_HOP Attribute
843 message.resetReaderIndex(); 843 message.resetReaderIndex();
844 actionsBgpUpdateInvalidNextHopAttribute( 844 actionsBgpUpdateInvalidNextHopAttribute(
...@@ -1297,7 +1297,7 @@ final class BgpUpdate { ...@@ -1297,7 +1297,7 @@ final class BgpUpdate {
1297 BgpSession bgpSession, 1297 BgpSession bgpSession,
1298 ChannelHandlerContext ctx) { 1298 ChannelHandlerContext ctx) {
1299 log.debug("BGP RX UPDATE Error from {}: Invalid Network Field", 1299 log.debug("BGP RX UPDATE Error from {}: Invalid Network Field",
1300 - bgpSession.getRemoteAddress()); 1300 + bgpSession.remoteInfo().address());
1301 1301
1302 // 1302 //
1303 // ERROR: Invalid Network Field 1303 // ERROR: Invalid Network Field
...@@ -1323,7 +1323,7 @@ final class BgpUpdate { ...@@ -1323,7 +1323,7 @@ final class BgpUpdate {
1323 BgpSession bgpSession, 1323 BgpSession bgpSession,
1324 ChannelHandlerContext ctx) { 1324 ChannelHandlerContext ctx) {
1325 log.debug("BGP RX UPDATE Error from {}: Malformed Attribute List", 1325 log.debug("BGP RX UPDATE Error from {}: Malformed Attribute List",
1326 - bgpSession.getRemoteAddress()); 1326 + bgpSession.remoteInfo().address());
1327 1327
1328 // 1328 //
1329 // ERROR: Malformed Attribute List 1329 // ERROR: Malformed Attribute List
...@@ -1352,7 +1352,7 @@ final class BgpUpdate { ...@@ -1352,7 +1352,7 @@ final class BgpUpdate {
1352 ChannelHandlerContext ctx, 1352 ChannelHandlerContext ctx,
1353 int missingAttrTypeCode) { 1353 int missingAttrTypeCode) {
1354 log.debug("BGP RX UPDATE Error from {}: Missing Well-known Attribute: {}", 1354 log.debug("BGP RX UPDATE Error from {}: Missing Well-known Attribute: {}",
1355 - bgpSession.getRemoteAddress(), missingAttrTypeCode); 1355 + bgpSession.remoteInfo().address(), missingAttrTypeCode);
1356 1356
1357 // 1357 //
1358 // ERROR: Missing Well-known Attribute 1358 // ERROR: Missing Well-known Attribute
...@@ -1390,7 +1390,7 @@ final class BgpUpdate { ...@@ -1390,7 +1390,7 @@ final class BgpUpdate {
1390 ChannelBuffer message, 1390 ChannelBuffer message,
1391 short origin) { 1391 short origin) {
1392 log.debug("BGP RX UPDATE Error from {}: Invalid ORIGIN Attribute", 1392 log.debug("BGP RX UPDATE Error from {}: Invalid ORIGIN Attribute",
1393 - bgpSession.getRemoteAddress()); 1393 + bgpSession.remoteInfo().address());
1394 1394
1395 // 1395 //
1396 // ERROR: Invalid ORIGIN Attribute 1396 // ERROR: Invalid ORIGIN Attribute
...@@ -1427,7 +1427,7 @@ final class BgpUpdate { ...@@ -1427,7 +1427,7 @@ final class BgpUpdate {
1427 int attrFlags, 1427 int attrFlags,
1428 ChannelBuffer message) { 1428 ChannelBuffer message) {
1429 log.debug("BGP RX UPDATE Error from {}: Attribute Flags Error", 1429 log.debug("BGP RX UPDATE Error from {}: Attribute Flags Error",
1430 - bgpSession.getRemoteAddress()); 1430 + bgpSession.remoteInfo().address());
1431 1431
1432 // 1432 //
1433 // ERROR: Attribute Flags Error 1433 // ERROR: Attribute Flags Error
...@@ -1467,7 +1467,7 @@ final class BgpUpdate { ...@@ -1467,7 +1467,7 @@ final class BgpUpdate {
1467 ChannelBuffer message, 1467 ChannelBuffer message,
1468 Ip4Address nextHop) { 1468 Ip4Address nextHop) {
1469 log.debug("BGP RX UPDATE Error from {}: Invalid NEXT_HOP Attribute {}", 1469 log.debug("BGP RX UPDATE Error from {}: Invalid NEXT_HOP Attribute {}",
1470 - bgpSession.getRemoteAddress(), nextHop); 1470 + bgpSession.remoteInfo().address(), nextHop);
1471 1471
1472 // 1472 //
1473 // ERROR: Invalid NEXT_HOP Attribute 1473 // ERROR: Invalid NEXT_HOP Attribute
...@@ -1506,7 +1506,7 @@ final class BgpUpdate { ...@@ -1506,7 +1506,7 @@ final class BgpUpdate {
1506 ChannelBuffer message) { 1506 ChannelBuffer message) {
1507 log.debug("BGP RX UPDATE Error from {}: " + 1507 log.debug("BGP RX UPDATE Error from {}: " +
1508 "Unrecognized Well-known Attribute Error: {}", 1508 "Unrecognized Well-known Attribute Error: {}",
1509 - bgpSession.getRemoteAddress(), attrTypeCode); 1509 + bgpSession.remoteInfo().address(), attrTypeCode);
1510 1510
1511 // 1511 //
1512 // ERROR: Unrecognized Well-known Attribute 1512 // ERROR: Unrecognized Well-known Attribute
...@@ -1545,7 +1545,7 @@ final class BgpUpdate { ...@@ -1545,7 +1545,7 @@ final class BgpUpdate {
1545 int attrFlags, 1545 int attrFlags,
1546 ChannelBuffer message) { 1546 ChannelBuffer message) {
1547 log.debug("BGP RX UPDATE Error from {}: Optional Attribute Error: {}", 1547 log.debug("BGP RX UPDATE Error from {}: Optional Attribute Error: {}",
1548 - bgpSession.getRemoteAddress(), attrTypeCode); 1548 + bgpSession.remoteInfo().address(), attrTypeCode);
1549 1549
1550 // 1550 //
1551 // ERROR: Optional Attribute Error 1551 // ERROR: Optional Attribute Error
...@@ -1583,7 +1583,7 @@ final class BgpUpdate { ...@@ -1583,7 +1583,7 @@ final class BgpUpdate {
1583 int attrFlags, 1583 int attrFlags,
1584 ChannelBuffer message) { 1584 ChannelBuffer message) {
1585 log.debug("BGP RX UPDATE Error from {}: Attribute Length Error", 1585 log.debug("BGP RX UPDATE Error from {}: Attribute Length Error",
1586 - bgpSession.getRemoteAddress()); 1586 + bgpSession.remoteInfo().address());
1587 1587
1588 // 1588 //
1589 // ERROR: Attribute Length Error 1589 // ERROR: Attribute Length Error
...@@ -1612,7 +1612,7 @@ final class BgpUpdate { ...@@ -1612,7 +1612,7 @@ final class BgpUpdate {
1612 BgpSession bgpSession, 1612 BgpSession bgpSession,
1613 ChannelHandlerContext ctx) { 1613 ChannelHandlerContext ctx) {
1614 log.debug("BGP RX UPDATE Error from {}: Malformed AS Path", 1614 log.debug("BGP RX UPDATE Error from {}: Malformed AS Path",
1615 - bgpSession.getRemoteAddress()); 1615 + bgpSession.remoteInfo().address());
1616 1616
1617 // 1617 //
1618 // ERROR: Malformed AS_PATH 1618 // ERROR: Malformed AS_PATH
......
...@@ -60,7 +60,7 @@ public class BgpNeighborsListCommand extends AbstractShellCommand { ...@@ -60,7 +60,7 @@ public class BgpNeighborsListCommand extends AbstractShellCommand {
60 // Print a single neighbor (if found) 60 // Print a single neighbor (if found)
61 BgpSession foundBgpSession = null; 61 BgpSession foundBgpSession = null;
62 for (BgpSession bgpSession : bgpSessions) { 62 for (BgpSession bgpSession : bgpSessions) {
63 - if (bgpSession.getRemoteBgpId().toString().equals(bgpNeighbor)) { 63 + if (bgpSession.remoteInfo().bgpId().toString().equals(bgpNeighbor)) {
64 foundBgpSession = bgpSession; 64 foundBgpSession = bgpSession;
65 break; 65 break;
66 } 66 }
...@@ -99,33 +99,34 @@ public class BgpNeighborsListCommand extends AbstractShellCommand { ...@@ -99,33 +99,34 @@ public class BgpNeighborsListCommand extends AbstractShellCommand {
99 */ 99 */
100 private void printNeighbor(BgpSession bgpSession) { 100 private void printNeighbor(BgpSession bgpSession) {
101 print(FORMAT_NEIGHBOR_LINE1, 101 print(FORMAT_NEIGHBOR_LINE1,
102 - bgpSession.getRemoteBgpId().toString(), 102 + bgpSession.remoteInfo().bgpId().toString(),
103 - bgpSession.getRemoteAs(), 103 + bgpSession.remoteInfo().asNumber(),
104 - bgpSession.getLocalAs()); 104 + bgpSession.localInfo().asNumber());
105 print(FORMAT_NEIGHBOR_LINE2, 105 print(FORMAT_NEIGHBOR_LINE2,
106 - bgpSession.getRemoteBgpId().toString(), 106 + bgpSession.remoteInfo().bgpId().toString(),
107 - bgpSession.getRemoteAddress().toString(), 107 + bgpSession.remoteInfo().address().toString(),
108 - bgpSession.getRemoteBgpVersion(), 108 + bgpSession.remoteInfo().bgpVersion(),
109 - bgpSession.getRemoteHoldtime()); 109 + bgpSession.remoteInfo().holdtime());
110 print(FORMAT_NEIGHBOR_LINE3, 110 print(FORMAT_NEIGHBOR_LINE3,
111 - bgpSession.getRemoteIpv4Unicast() ? "YES" : "NO", 111 + bgpSession.remoteInfo().ipv4Unicast() ? "YES" : "NO",
112 - bgpSession.getRemoteIpv4Multicast() ? "YES" : "NO", 112 + bgpSession.remoteInfo().ipv4Multicast() ? "YES" : "NO",
113 - bgpSession.getRemoteIpv6Unicast() ? "YES" : "NO", 113 + bgpSession.remoteInfo().ipv6Unicast() ? "YES" : "NO",
114 - bgpSession.getRemoteIpv6Multicast() ? "YES" : "NO"); 114 + bgpSession.remoteInfo().ipv6Multicast() ? "YES" : "NO");
115 print(FORMAT_NEIGHBOR_LINE4, 115 print(FORMAT_NEIGHBOR_LINE4,
116 - bgpSession.getLocalBgpId().toString(), 116 + bgpSession.localInfo().bgpId().toString(),
117 - bgpSession.getLocalAddress().toString(), 117 + bgpSession.localInfo().address().toString(),
118 - bgpSession.getLocalBgpVersion(), 118 + bgpSession.localInfo().bgpVersion(),
119 - bgpSession.getLocalHoldtime()); 119 + bgpSession.localInfo().holdtime());
120 print(FORMAT_NEIGHBOR_LINE5, 120 print(FORMAT_NEIGHBOR_LINE5,
121 - bgpSession.getLocalIpv4Unicast() ? "YES" : "NO", 121 + bgpSession.localInfo().ipv4Unicast() ? "YES" : "NO",
122 - bgpSession.getLocalIpv4Multicast() ? "YES" : "NO", 122 + bgpSession.localInfo().ipv4Multicast() ? "YES" : "NO",
123 - bgpSession.getLocalIpv6Unicast() ? "YES" : "NO", 123 + bgpSession.localInfo().ipv6Unicast() ? "YES" : "NO",
124 - bgpSession.getLocalIpv6Multicast() ? "YES" : "NO"); 124 + bgpSession.localInfo().ipv6Multicast() ? "YES" : "NO");
125 - if (bgpSession.getLocalAs4OctetCapability() || bgpSession.getRemoteAs4OctetCapability()) { 125 + if (bgpSession.localInfo().as4OctetCapability() ||
126 + bgpSession.remoteInfo().as4OctetCapability()) {
126 print(FORMAT_NEIGHBOR_LINE6, 127 print(FORMAT_NEIGHBOR_LINE6,
127 - bgpSession.getLocalAs4OctetCapability() ? "Advertised" : "", 128 + bgpSession.localInfo().as4OctetCapability() ? "Advertised" : "",
128 - bgpSession.getRemoteAs4OctetCapability() ? "Received" : ""); 129 + bgpSession.remoteInfo().as4OctetCapability() ? "Received" : "");
129 } 130 }
130 } 131 }
131 132
...@@ -155,25 +156,27 @@ public class BgpNeighborsListCommand extends AbstractShellCommand { ...@@ -155,25 +156,27 @@ public class BgpNeighborsListCommand extends AbstractShellCommand {
155 private ObjectNode json(ObjectMapper mapper, BgpSession bgpSession) { 156 private ObjectNode json(ObjectMapper mapper, BgpSession bgpSession) {
156 ObjectNode result = mapper.createObjectNode(); 157 ObjectNode result = mapper.createObjectNode();
157 158
158 - result.put("remoteAddress", bgpSession.getRemoteAddress().toString()); 159 + result.put("remoteAddress", bgpSession.remoteInfo().address().toString());
159 - result.put("remoteBgpVersion", bgpSession.getRemoteBgpVersion()); 160 + result.put("remoteBgpVersion", bgpSession.remoteInfo().bgpVersion());
160 - result.put("remoteAs", bgpSession.getRemoteAs()); 161 + result.put("remoteAs", bgpSession.remoteInfo().asNumber());
161 - result.put("remoteHoldtime", bgpSession.getRemoteHoldtime()); 162 + result.put("remoteAs4", bgpSession.remoteInfo().as4Number());
162 - result.put("remoteBgpId", bgpSession.getRemoteBgpId().toString()); 163 + result.put("remoteHoldtime", bgpSession.remoteInfo().holdtime());
163 - result.put("remoteIpv4Unicast", bgpSession.getRemoteIpv4Unicast()); 164 + result.put("remoteBgpId", bgpSession.remoteInfo().bgpId().toString());
164 - result.put("remoteIpv4Multicast", bgpSession.getRemoteIpv4Multicast()); 165 + result.put("remoteIpv4Unicast", bgpSession.remoteInfo().ipv4Unicast());
165 - result.put("remoteIpv6Unicast", bgpSession.getRemoteIpv6Unicast()); 166 + result.put("remoteIpv4Multicast", bgpSession.remoteInfo().ipv4Multicast());
166 - result.put("remoteIpv6Multicast", bgpSession.getRemoteIpv6Multicast()); 167 + result.put("remoteIpv6Unicast", bgpSession.remoteInfo().ipv6Unicast());
168 + result.put("remoteIpv6Multicast", bgpSession.remoteInfo().ipv6Multicast());
167 // 169 //
168 - result.put("localAddress", bgpSession.getLocalAddress().toString()); 170 + result.put("localAddress", bgpSession.localInfo().address().toString());
169 - result.put("localBgpVersion", bgpSession.getLocalBgpVersion()); 171 + result.put("localBgpVersion", bgpSession.localInfo().bgpVersion());
170 - result.put("localAs", bgpSession.getLocalAs()); 172 + result.put("localAs", bgpSession.localInfo().asNumber());
171 - result.put("localHoldtime", bgpSession.getLocalHoldtime()); 173 + result.put("localAs4", bgpSession.localInfo().as4Number());
172 - result.put("localBgpId", bgpSession.getLocalBgpId().toString()); 174 + result.put("localHoldtime", bgpSession.localInfo().holdtime());
173 - result.put("localIpv4Unicast", bgpSession.getLocalIpv4Unicast()); 175 + result.put("localBgpId", bgpSession.localInfo().bgpId().toString());
174 - result.put("localIpv4Multicast", bgpSession.getLocalIpv4Multicast()); 176 + result.put("localIpv4Unicast", bgpSession.localInfo().ipv4Unicast());
175 - result.put("localIpv6Unicast", bgpSession.getLocalIpv6Unicast()); 177 + result.put("localIpv4Multicast", bgpSession.localInfo().ipv4Multicast());
176 - result.put("localIpv6Multicast", bgpSession.getLocalIpv6Multicast()); 178 + result.put("localIpv6Unicast", bgpSession.localInfo().ipv6Unicast());
179 + result.put("localIpv6Multicast", bgpSession.localInfo().ipv6Multicast());
177 180
178 return result; 181 return result;
179 } 182 }
......
...@@ -71,7 +71,7 @@ public class BgpRoutesListCommand extends AbstractShellCommand { ...@@ -71,7 +71,7 @@ public class BgpRoutesListCommand extends AbstractShellCommand {
71 if (bgpNeighbor != null) { 71 if (bgpNeighbor != null) {
72 // Print the routes from a single neighbor (if found) 72 // Print the routes from a single neighbor (if found)
73 for (BgpSession bgpSession : service.getBgpSessions()) { 73 for (BgpSession bgpSession : service.getBgpSessions()) {
74 - if (bgpSession.getRemoteBgpId().toString().equals(bgpNeighbor)) { 74 + if (bgpSession.remoteInfo().bgpId().toString().equals(bgpNeighbor)) {
75 foundBgpSession = bgpSession; 75 foundBgpSession = bgpSession;
76 break; 76 break;
77 } 77 }
...@@ -152,7 +152,7 @@ public class BgpRoutesListCommand extends AbstractShellCommand { ...@@ -152,7 +152,7 @@ public class BgpRoutesListCommand extends AbstractShellCommand {
152 print(FORMAT_ROUTE_LINE1, route.prefix(), route.nextHop(), 152 print(FORMAT_ROUTE_LINE1, route.prefix(), route.nextHop(),
153 Update.Origin.typeToString(route.getOrigin()), 153 Update.Origin.typeToString(route.getOrigin()),
154 route.getLocalPref(), route.getMultiExitDisc(), 154 route.getLocalPref(), route.getMultiExitDisc(),
155 - route.getBgpSession().getRemoteBgpId()); 155 + route.getBgpSession().remoteInfo().bgpId());
156 print(FORMAT_ROUTE_LINE2, asPath4Cli(route.getAsPath())); 156 print(FORMAT_ROUTE_LINE2, asPath4Cli(route.getAsPath()));
157 } 157 }
158 } 158 }
...@@ -245,7 +245,8 @@ public class BgpRoutesListCommand extends AbstractShellCommand { ...@@ -245,7 +245,8 @@ public class BgpRoutesListCommand extends AbstractShellCommand {
245 245
246 result.put("prefix", route.prefix().toString()); 246 result.put("prefix", route.prefix().toString());
247 result.put("nextHop", route.nextHop().toString()); 247 result.put("nextHop", route.nextHop().toString());
248 - result.put("bgpId", route.getBgpSession().getRemoteBgpId().toString()); 248 + result.put("bgpId",
249 + route.getBgpSession().remoteInfo().bgpId().toString());
249 result.put("origin", Update.Origin.typeToString(route.getOrigin())); 250 result.put("origin", Update.Origin.typeToString(route.getOrigin()));
250 result.put("asPath", json(mapper, route.getAsPath())); 251 result.put("asPath", json(mapper, route.getAsPath()));
251 result.put("localPref", route.getLocalPref()); 252 result.put("localPref", route.getLocalPref());
......
...@@ -51,6 +51,15 @@ public class BgpRouteEntryTest { ...@@ -51,6 +51,15 @@ public class BgpRouteEntryTest {
51 private static final Ip4Address BGP_SESSION_IP_ADDRESS3 = 51 private static final Ip4Address BGP_SESSION_IP_ADDRESS3 =
52 Ip4Address.valueOf("20.0.0.2"); 52 Ip4Address.valueOf("20.0.0.2");
53 53
54 + private final BgpSessionInfo localInfo = new BgpSessionInfo();
55 + private final BgpSessionInfo remoteInfo = new BgpSessionInfo();
56 +
57 + private final BgpSessionInfo localInfo2 = new BgpSessionInfo();
58 + private final BgpSessionInfo remoteInfo2 = new BgpSessionInfo();
59 +
60 + private final BgpSessionInfo localInfo3 = new BgpSessionInfo();
61 + private final BgpSessionInfo remoteInfo3 = new BgpSessionInfo();
62 +
54 @Before 63 @Before
55 public void setUp() throws Exception { 64 public void setUp() throws Exception {
56 // Mock objects for testing 65 // Mock objects for testing
...@@ -59,20 +68,19 @@ public class BgpRouteEntryTest { ...@@ -59,20 +68,19 @@ public class BgpRouteEntryTest {
59 bgpSession3 = createMock(BgpSession.class); 68 bgpSession3 = createMock(BgpSession.class);
60 69
61 // Setup the BGP Sessions 70 // Setup the BGP Sessions
62 - expect(bgpSession.getRemoteBgpId()) 71 + remoteInfo.setIp4Address(BGP_SESSION_IP_ADDRESS);
63 - .andReturn(BGP_SESSION_BGP_ID).anyTimes(); 72 + remoteInfo2.setIp4Address(BGP_SESSION_IP_ADDRESS2);
64 - expect(bgpSession.getRemoteIp4Address()) 73 + remoteInfo3.setIp4Address(BGP_SESSION_IP_ADDRESS3);
65 - .andReturn(BGP_SESSION_IP_ADDRESS).anyTimes(); 74 + remoteInfo.setBgpId(BGP_SESSION_BGP_ID);
66 - // 75 + remoteInfo2.setBgpId(BGP_SESSION_BGP_ID2);
67 - expect(bgpSession2.getRemoteBgpId()) 76 + remoteInfo3.setBgpId(BGP_SESSION_BGP_ID3);
68 - .andReturn(BGP_SESSION_BGP_ID2).anyTimes(); 77 +
69 - expect(bgpSession2.getRemoteIp4Address()) 78 + expect(bgpSession.localInfo()).andReturn(localInfo).anyTimes();
70 - .andReturn(BGP_SESSION_IP_ADDRESS2).anyTimes(); 79 + expect(bgpSession.remoteInfo()).andReturn(remoteInfo).anyTimes();
71 - // 80 + expect(bgpSession2.localInfo()).andReturn(localInfo2).anyTimes();
72 - expect(bgpSession3.getRemoteBgpId()) 81 + expect(bgpSession2.remoteInfo()).andReturn(remoteInfo2).anyTimes();
73 - .andReturn(BGP_SESSION_BGP_ID3).anyTimes(); 82 + expect(bgpSession3.localInfo()).andReturn(localInfo3).anyTimes();
74 - expect(bgpSession3.getRemoteIp4Address()) 83 + expect(bgpSession3.remoteInfo()).andReturn(remoteInfo3).anyTimes();
75 - .andReturn(BGP_SESSION_IP_ADDRESS3).anyTimes();
76 84
77 replay(bgpSession); 85 replay(bgpSession);
78 replay(bgpSession2); 86 replay(bgpSession2);
......
...@@ -179,13 +179,13 @@ public class BgpSessionManagerTest { ...@@ -179,13 +179,13 @@ public class BgpSessionManagerTest {
179 assertThat(result, is(true)); 179 assertThat(result, is(true));
180 180
181 for (BgpSession bgpSession : bgpSessionManager.getBgpSessions()) { 181 for (BgpSession bgpSession : bgpSessionManager.getBgpSessions()) {
182 - if (bgpSession.getRemoteBgpId().equals(BGP_PEER1_ID)) { 182 + if (bgpSession.remoteInfo().bgpId().equals(BGP_PEER1_ID)) {
183 bgpSession1 = bgpSession; 183 bgpSession1 = bgpSession;
184 } 184 }
185 - if (bgpSession.getRemoteBgpId().equals(BGP_PEER2_ID)) { 185 + if (bgpSession.remoteInfo().bgpId().equals(BGP_PEER2_ID)) {
186 bgpSession2 = bgpSession; 186 bgpSession2 = bgpSession;
187 } 187 }
188 - if (bgpSession.getRemoteBgpId().equals(BGP_PEER3_ID)) { 188 + if (bgpSession.remoteInfo().bgpId().equals(BGP_PEER3_ID)) {
189 bgpSession3 = bgpSession; 189 bgpSession3 = bgpSession;
190 } 190 }
191 } 191 }
...@@ -394,7 +394,7 @@ public class BgpSessionManagerTest { ...@@ -394,7 +394,7 @@ public class BgpSessionManagerTest {
394 assertThat(bgpSession2, notNullValue()); 394 assertThat(bgpSession2, notNullValue());
395 assertThat(bgpSession3, notNullValue()); 395 assertThat(bgpSession3, notNullValue());
396 for (BgpSession bgpSession : bgpSessionManager.getBgpSessions()) { 396 for (BgpSession bgpSession : bgpSessionManager.getBgpSessions()) {
397 - long sessionAs = TestUtils.getField(bgpSession, "localAs"); 397 + long sessionAs = bgpSession.localInfo().asNumber();
398 assertThat(sessionAs, is(TestBgpPeerChannelHandler.PEER_AS)); 398 assertThat(sessionAs, is(TestBgpPeerChannelHandler.PEER_AS));
399 } 399 }
400 } 400 }
......
...@@ -59,7 +59,7 @@ class TestBgpPeerChannelHandler extends SimpleChannelHandler { ...@@ -59,7 +59,7 @@ class TestBgpPeerChannelHandler extends SimpleChannelHandler {
59 ctx.getChannel().write(message); 59 ctx.getChannel().write(message);
60 60
61 // Prepare and transmit BGP KEEPALIVE message 61 // Prepare and transmit BGP KEEPALIVE message
62 - message = prepareBgpKeepalive(); 62 + message = BgpKeepalive.prepareBgpKeepalive();
63 ctx.getChannel().write(message); 63 ctx.getChannel().write(message);
64 } 64 }
65 65
...@@ -82,7 +82,8 @@ class TestBgpPeerChannelHandler extends SimpleChannelHandler { ...@@ -82,7 +82,8 @@ class TestBgpPeerChannelHandler extends SimpleChannelHandler {
82 message.writeShort(PEER_HOLDTIME); 82 message.writeShort(PEER_HOLDTIME);
83 message.writeInt(bgpId.toInt()); 83 message.writeInt(bgpId.toInt());
84 message.writeByte(0); // No Optional Parameters 84 message.writeByte(0); // No Optional Parameters
85 - return prepareBgpMessage(BgpConstants.BGP_TYPE_OPEN, message); 85 + return BgpMessage.prepareBgpMessage(BgpConstants.BGP_TYPE_OPEN,
86 + message);
86 } 87 }
87 88
88 /** 89 /**
...@@ -155,7 +156,8 @@ class TestBgpPeerChannelHandler extends SimpleChannelHandler { ...@@ -155,7 +156,8 @@ class TestBgpPeerChannelHandler extends SimpleChannelHandler {
155 message.writeBytes(pathAttributes); 156 message.writeBytes(pathAttributes);
156 message.writeBytes(encodedPrefixes); 157 message.writeBytes(encodedPrefixes);
157 158
158 - return prepareBgpMessage(BgpConstants.BGP_TYPE_UPDATE, message); 159 + return BgpMessage.prepareBgpMessage(BgpConstants.BGP_TYPE_UPDATE,
160 + message);
159 } 161 }
160 162
161 /** 163 /**
...@@ -214,64 +216,4 @@ class TestBgpPeerChannelHandler extends SimpleChannelHandler { ...@@ -214,64 +216,4 @@ class TestBgpPeerChannelHandler extends SimpleChannelHandler {
214 216
215 return message; 217 return message;
216 } 218 }
217 -
218 - /**
219 - * Prepares BGP KEEPALIVE message.
220 - *
221 - * @return the message to transmit (BGP header included)
222 - */
223 - ChannelBuffer prepareBgpKeepalive() {
224 - ChannelBuffer message =
225 - ChannelBuffers.buffer(BgpConstants.BGP_MESSAGE_MAX_LENGTH);
226 - return prepareBgpMessage(BgpConstants.BGP_TYPE_KEEPALIVE, message);
227 - }
228 -
229 - /**
230 - * Prepares BGP NOTIFICATION message.
231 - *
232 - * @param errorCode the BGP NOTIFICATION Error Code
233 - * @param errorSubcode the BGP NOTIFICATION Error Subcode if applicable,
234 - * otherwise BgpConstants.Notifications.ERROR_SUBCODE_UNSPECIFIC
235 - * @param payload the BGP NOTIFICATION Data if applicable, otherwise null
236 - * @return the message to transmit (BGP header included)
237 - */
238 - ChannelBuffer prepareBgpNotification(int errorCode, int errorSubcode,
239 - ChannelBuffer data) {
240 - ChannelBuffer message =
241 - ChannelBuffers.buffer(BgpConstants.BGP_MESSAGE_MAX_LENGTH);
242 - // Prepare the NOTIFICATION message payload
243 - message.writeByte(errorCode);
244 - message.writeByte(errorSubcode);
245 - if (data != null) {
246 - message.writeBytes(data);
247 - }
248 - return prepareBgpMessage(BgpConstants.BGP_TYPE_NOTIFICATION, message);
249 - }
250 -
251 - /**
252 - * Prepares BGP message.
253 - *
254 - * @param type the BGP message type
255 - * @param payload the message payload to transmit (BGP header excluded)
256 - * @return the message to transmit (BGP header included)
257 - */
258 - private ChannelBuffer prepareBgpMessage(int type, ChannelBuffer payload) {
259 - ChannelBuffer message =
260 - ChannelBuffers.buffer(BgpConstants.BGP_HEADER_LENGTH +
261 - payload.readableBytes());
262 -
263 - // Write the marker
264 - for (int i = 0; i < BgpConstants.BGP_HEADER_MARKER_LENGTH; i++) {
265 - message.writeByte(0xff);
266 - }
267 -
268 - // Write the rest of the BGP header
269 - message.writeShort(BgpConstants.BGP_HEADER_LENGTH +
270 - payload.readableBytes());
271 - message.writeByte(type);
272 -
273 - // Write the payload
274 - message.writeBytes(payload);
275 - return message;
276 - }
277 } 219 }
......