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 //
......
...@@ -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)
......
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 }
......