Pavlin Radoslavov

Work toward IPv6 support in BGP: implement decoding/encoding of the

BGP OPEN Multiprotocol Extensions Capabilities (RFC 4760).

The corresponding BGP UPDATE decoding is not done yet, hence for now
we don't include any Capabilities in the BGP OPEN message originated by us.

This work is in the context of ONOS-422.

Change-Id: I8e1c8838adc189aa32a8edf98be976d90fc4ad42
...@@ -80,6 +80,71 @@ public final class BgpConstants { ...@@ -80,6 +80,71 @@ public final class BgpConstants {
80 public static final long BGP_AS_0 = 0; 80 public static final long BGP_AS_0 = 0;
81 81
82 /** 82 /**
83 + * BGP OPEN related constants.
84 + */
85 + public static final class Open {
86 + /**
87 + * Default constructor.
88 + * <p>
89 + * The constructor is private to prevent creating an instance of
90 + * this utility class.
91 + */
92 + private Open() {
93 + }
94 +
95 + /**
96 + * BGP OPEN: Optional Parameters related constants.
97 + */
98 + public static final class OptionalParameters {
99 + }
100 +
101 + /**
102 + * BGP OPEN: Capabilities related constants (RFC 5492).
103 + */
104 + public static final class Capabilities {
105 + /** BGP OPEN Optional Parameter Type: Capabilities. */
106 + public static final int TYPE = 2;
107 +
108 + /** BGP OPEN Optional Parameter minimum length. */
109 + public static final int MIN_LENGTH = 2;
110 +
111 + /**
112 + * BGP OPEN: Multiprotocol Extensions Capabilities (RFC 4760).
113 + */
114 + public static final class MultiprotocolExtensions {
115 + /** BGP OPEN Multiprotocol Extensions code. */
116 + public static final int CODE = 1;
117 +
118 + /** BGP OPEN Multiprotocol Extensions length. */
119 + public static final int LENGTH = 4;
120 +
121 + /** BGP OPEN Multiprotocol Extensions AFI: IPv4. */
122 + public static final int AFI_IPV4 = 1;
123 +
124 + /** BGP OPEN Multiprotocol Extensions AFI: IPv6. */
125 + public static final int AFI_IPV6 = 2;
126 +
127 + /** BGP OPEN Multiprotocol Extensions SAFI: unicast. */
128 + public static final int SAFI_UNICAST = 1;
129 +
130 + /** BGP OPEN Multiprotocol Extensions SAFI: multicast. */
131 + public static final int SAFI_MULTICAST = 2;
132 + }
133 +
134 + /**
135 + * BGP OPEN: Support for 4-octet AS Number Capability (RFC 6793).
136 + */
137 + public static final class As4Octet {
138 + /** BGP OPEN Support for 4-octet AS Number Capability code. */
139 + public static final int CODE = 65;
140 +
141 + /** BGP OPEN 4-octet AS Number Capability length. */
142 + public static final int LENGTH = 4;
143 + }
144 + }
145 + }
146 +
147 + /**
83 * BGP UPDATE related constants. 148 * BGP UPDATE related constants.
84 */ 149 */
85 public static final class Update { 150 public static final class Update {
......
...@@ -62,4 +62,25 @@ final class BgpMessage { ...@@ -62,4 +62,25 @@ final class BgpMessage {
62 message.writeBytes(payload); 62 message.writeBytes(payload);
63 return message; 63 return message;
64 } 64 }
65 +
66 + /**
67 + * An exception indicating a parsing error of the BGP message.
68 + */
69 + static final class BgpParseException extends Exception {
70 + /**
71 + * Default constructor.
72 + */
73 + private BgpParseException() {
74 + super();
75 + }
76 +
77 + /**
78 + * Constructor for a specific exception details message.
79 + *
80 + * @param message the message with the exception details
81 + */
82 + BgpParseException(String message) {
83 + super(message);
84 + }
85 + }
65 } 86 }
......
...@@ -21,6 +21,9 @@ import org.jboss.netty.channel.ChannelHandlerContext; ...@@ -21,6 +21,9 @@ import org.jboss.netty.channel.ChannelHandlerContext;
21 import org.onlab.packet.Ip4Address; 21 import org.onlab.packet.Ip4Address;
22 import org.onosproject.sdnip.bgp.BgpConstants.Notifications; 22 import org.onosproject.sdnip.bgp.BgpConstants.Notifications;
23 import org.onosproject.sdnip.bgp.BgpConstants.Notifications.OpenMessageError; 23 import org.onosproject.sdnip.bgp.BgpConstants.Notifications.OpenMessageError;
24 +import org.onosproject.sdnip.bgp.BgpConstants.Open.Capabilities;
25 +import org.onosproject.sdnip.bgp.BgpConstants.Open.Capabilities.MultiprotocolExtensions;
26 +import org.onosproject.sdnip.bgp.BgpMessage.BgpParseException;
24 import org.slf4j.Logger; 27 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory; 28 import org.slf4j.LoggerFactory;
26 29
...@@ -153,16 +156,16 @@ final class BgpOpen { ...@@ -153,16 +156,16 @@ final class BgpOpen {
153 Ip4Address.valueOf((int) message.readUnsignedInt()); 156 Ip4Address.valueOf((int) message.readUnsignedInt());
154 bgpSession.setRemoteBgpId(remoteBgpId); 157 bgpSession.setRemoteBgpId(remoteBgpId);
155 158
156 - // Optional Parameters 159 + // Parse the Optional Parameters
157 - int optParamLen = message.readUnsignedByte(); 160 + try {
158 - if (message.readableBytes() < optParamLen) { 161 + parseOptionalParameters(bgpSession, ctx, message);
162 + } catch (BgpParseException e) {
163 + // ERROR: Error parsing optional parameters
159 log.debug("BGP RX OPEN Error from {}: " + 164 log.debug("BGP RX OPEN Error from {}: " +
160 - "Invalid Optional Parameter Length field {}. " + 165 + "Exception parsing Optional Parameters: {}",
161 - "Remaining Optional Parameters {}", 166 + bgpSession.getRemoteAddress(), e);
162 - bgpSession.getRemoteAddress(), optParamLen,
163 - message.readableBytes());
164 // 167 //
165 - // ERROR: Invalid Optional Parameter Length field: Unspecific 168 + // ERROR: Invalid Optional Parameters: Unspecific
166 // 169 //
167 // Send NOTIFICATION and close the connection 170 // Send NOTIFICATION and close the connection
168 int errorCode = OpenMessageError.ERROR_CODE; 171 int errorCode = OpenMessageError.ERROR_CODE;
...@@ -174,8 +177,6 @@ final class BgpOpen { ...@@ -174,8 +177,6 @@ final class BgpOpen {
174 bgpSession.closeSession(ctx); 177 bgpSession.closeSession(ctx);
175 return; 178 return;
176 } 179 }
177 - // NOTE: Parse the optional parameters (if needed)
178 - message.readBytes(optParamLen); // NOTE: data ignored
179 180
180 log.debug("BGP RX OPEN message from {}: " + 181 log.debug("BGP RX OPEN message from {}: " +
181 "BGPv{} AS {} BGP-ID {} Holdtime {}", 182 "BGPv{} AS {} BGP-ID {} Holdtime {}",
...@@ -213,8 +214,211 @@ final class BgpOpen { ...@@ -213,8 +214,211 @@ final class BgpOpen {
213 message.writeShort((int) bgpSession.getLocalAs()); 214 message.writeShort((int) bgpSession.getLocalAs());
214 message.writeShort((int) bgpSession.getLocalHoldtime()); 215 message.writeShort((int) bgpSession.getLocalHoldtime());
215 message.writeInt(bgpSession.getLocalBgpId().toInt()); 216 message.writeInt(bgpSession.getLocalBgpId().toInt());
216 - message.writeByte(0); // No Optional Parameters 217 +
218 + // Prepare the optional BGP Capabilities
219 + ChannelBuffer capabilitiesMessage =
220 + prepareBgpOpenCapabilities(bgpSession);
221 + message.writeByte(capabilitiesMessage.readableBytes());
222 + message.writeBytes(capabilitiesMessage);
223 +
217 return BgpMessage.prepareBgpMessage(BgpConstants.BGP_TYPE_OPEN, 224 return BgpMessage.prepareBgpMessage(BgpConstants.BGP_TYPE_OPEN,
218 message); 225 message);
219 } 226 }
227 +
228 + /**
229 + * Parses BGP OPEN Optional Parameters.
230 + *
231 + * @param bgpSession the BGP Session to use
232 + * @param ctx the Channel Handler Context
233 + * @param message the message to process
234 + * @throws BgpParseException
235 + */
236 + private static void parseOptionalParameters(BgpSession bgpSession,
237 + ChannelHandlerContext ctx,
238 + ChannelBuffer message)
239 + throws BgpParseException {
240 +
241 + //
242 + // Get and verify the Optional Parameters Length
243 + //
244 + int optParamLength = message.readUnsignedByte();
245 + if (optParamLength > message.readableBytes()) {
246 + // ERROR: Invalid Optional Parameter Length
247 + String errorMsg = "Invalid Optional Parameter Length field " +
248 + optParamLength + ". Remaining Optional Parameters " +
249 + message.readableBytes();
250 + throw new BgpParseException(errorMsg);
251 + }
252 + if (optParamLength == 0) {
253 + return; // No Optional Parameters
254 + }
255 +
256 + //
257 + // Parse the Optional Parameters
258 + //
259 + int optParamEnd = message.readerIndex() + optParamLength;
260 + while (message.readerIndex() < optParamEnd) {
261 + int paramType = message.readUnsignedByte();
262 + if (message.readerIndex() >= optParamEnd) {
263 + // ERROR: Malformed Optional Parameters
264 + String errorMsg = "Malformed Optional Parameters";
265 + throw new BgpParseException(errorMsg);
266 + }
267 + int paramLen = message.readUnsignedByte();
268 + if (message.readerIndex() + paramLen > optParamEnd) {
269 + // ERROR: Malformed Optional Parameters
270 + String errorMsg = "Malformed Optional Parameters";
271 + throw new BgpParseException(errorMsg);
272 + }
273 +
274 + //
275 + // Extract the Optional Parameter Value based on the Parameter Type
276 + //
277 + switch (paramType) {
278 + case Capabilities.TYPE:
279 + // Optional Parameter Type: Capabilities
280 + if (paramLen < Capabilities.MIN_LENGTH) {
281 + // ERROR: Malformed Capability
282 + String errorMsg = "Malformed Capability Type " + paramType;
283 + throw new BgpParseException(errorMsg);
284 + }
285 + int capabEnd = message.readerIndex() + paramLen;
286 + int capabCode = message.readUnsignedByte();
287 + int capabLen = message.readUnsignedByte();
288 + if (message.readerIndex() + capabLen > capabEnd) {
289 + // ERROR: Malformed Capability
290 + String errorMsg = "Malformed Capability Type " + paramType;
291 + throw new BgpParseException(errorMsg);
292 + }
293 +
294 + switch (capabCode) {
295 + case MultiprotocolExtensions.CODE:
296 + // Multiprotocol Extensions Capabilities (RFC 4760)
297 + if (capabLen != MultiprotocolExtensions.LENGTH) {
298 + // ERROR: Multiprotocol Extension Length Error
299 + String errorMsg = "Multiprotocol Extension Length Error";
300 + throw new BgpParseException(errorMsg);
301 + }
302 + // Decode the AFI (2 octets) and SAFI (1 octet)
303 + int afi = message.readUnsignedShort();
304 + int reserved = message.readUnsignedByte();
305 + int safi = message.readUnsignedByte();
306 + log.debug("BGP RX OPEN Capability: AFI = {} SAFI = {}",
307 + afi, safi);
308 + //
309 + // Setup the AFI/SAFI in the BgpSession
310 + //
311 + if (afi == MultiprotocolExtensions.AFI_IPV4 &&
312 + safi == MultiprotocolExtensions.SAFI_UNICAST) {
313 + bgpSession.setRemoteIpv4Unicast();
314 + } else if (afi == MultiprotocolExtensions.AFI_IPV4 &&
315 + safi == MultiprotocolExtensions.SAFI_MULTICAST) {
316 + bgpSession.setRemoteIpv4Multicast();
317 + } else if (afi == MultiprotocolExtensions.AFI_IPV6 &&
318 + safi == MultiprotocolExtensions.SAFI_UNICAST) {
319 + bgpSession.setRemoteIpv6Unicast();
320 + } else if (afi == MultiprotocolExtensions.AFI_IPV6 &&
321 + safi == MultiprotocolExtensions.SAFI_MULTICAST) {
322 + bgpSession.setRemoteIpv6Multicast();
323 + } else {
324 + log.debug("BGP RX OPEN Capability: Unknown AFI = {} SAFI = {}",
325 + afi, safi);
326 + }
327 + break;
328 +
329 + case Capabilities.As4Octet.CODE:
330 + // Support for 4-octet AS Number Capabilities (RFC 6793)
331 + if (capabLen != Capabilities.As4Octet.LENGTH) {
332 + // ERROR: 4-octet AS Number Capability Length Error
333 + String errorMsg = "4-octet AS Number Capability Length Error";
334 + throw new BgpParseException(errorMsg);
335 + }
336 + long as4Number = message.readUnsignedInt();
337 + // TODO: Implement support for 4-octet AS Numbers
338 + log.debug("BGP RX OPEN Capability: AS4 Number = {}",
339 + as4Number);
340 + break;
341 +
342 + default:
343 + // Unknown Capability: ignore it
344 + log.debug("BGP RX OPEN Capability Code = {} Length = {}",
345 + capabCode, capabLen);
346 + message.readBytes(capabLen);
347 + break;
348 + }
349 +
350 + break;
351 +
352 + default:
353 + // Unknown Parameter Type: ignore it
354 + log.debug("BGP RX OPEN Parameter Type = {} Length = {}",
355 + paramType, paramLen);
356 + message.readBytes(paramLen);
357 + break;
358 + }
359 + }
360 + }
361 +
362 + /**
363 + * Prepares the Capabilities for the BGP OPEN message.
364 + *
365 + * @param bgpSession the BGP Session to use
366 + * @return the buffer with the BGP Capabilities to transmit
367 + */
368 + private static ChannelBuffer prepareBgpOpenCapabilities(
369 + BgpSession bgpSession) {
370 + ChannelBuffer message =
371 + ChannelBuffers.buffer(BgpConstants.BGP_MESSAGE_MAX_LENGTH);
372 +
373 + //
374 + // Write the Multiprotocol Extensions Capabilities
375 + //
376 +
377 + // IPv4 unicast
378 + if (bgpSession.getLocalIpv4Unicast()) {
379 + message.writeByte(Capabilities.TYPE); // Param type
380 + message.writeByte(Capabilities.MIN_LENGTH +
381 + MultiprotocolExtensions.LENGTH); // Param len
382 + message.writeByte(MultiprotocolExtensions.CODE); // Capab. code
383 + message.writeByte(MultiprotocolExtensions.LENGTH); // Capab. len
384 + message.writeShort(MultiprotocolExtensions.AFI_IPV4);
385 + message.writeByte(0); // Reserved field
386 + message.writeByte(MultiprotocolExtensions.SAFI_UNICAST);
387 + }
388 + // IPv4 multicast
389 + if (bgpSession.getLocalIpv4Multicast()) {
390 + message.writeByte(Capabilities.TYPE); // Param type
391 + message.writeByte(Capabilities.MIN_LENGTH +
392 + MultiprotocolExtensions.LENGTH); // Param len
393 + message.writeByte(MultiprotocolExtensions.CODE); // Capab. code
394 + message.writeByte(MultiprotocolExtensions.LENGTH); // Capab. len
395 + message.writeShort(MultiprotocolExtensions.AFI_IPV4);
396 + message.writeByte(0); // Reserved field
397 + message.writeByte(MultiprotocolExtensions.SAFI_MULTICAST);
398 + }
399 + // IPv6 unicast
400 + if (bgpSession.getLocalIpv6Unicast()) {
401 + message.writeByte(Capabilities.TYPE); // Param type
402 + message.writeByte(Capabilities.MIN_LENGTH +
403 + MultiprotocolExtensions.LENGTH); // Param len
404 + message.writeByte(MultiprotocolExtensions.CODE); // Capab. code
405 + message.writeByte(MultiprotocolExtensions.LENGTH); // Capab. len
406 + message.writeShort(MultiprotocolExtensions.AFI_IPV6);
407 + message.writeByte(0); // Reserved field
408 + message.writeByte(MultiprotocolExtensions.SAFI_UNICAST);
409 + }
410 + // IPv6 multicast
411 + if (bgpSession.getLocalIpv6Multicast()) {
412 + message.writeByte(Capabilities.TYPE); // Param type
413 + message.writeByte(Capabilities.MIN_LENGTH +
414 + MultiprotocolExtensions.LENGTH); // Param len
415 + message.writeByte(MultiprotocolExtensions.CODE); // Capab. code
416 + message.writeByte(MultiprotocolExtensions.LENGTH); // Capab. len
417 + message.writeShort(MultiprotocolExtensions.AFI_IPV6);
418 + message.writeByte(0); // Reserved field
419 + message.writeByte(MultiprotocolExtensions.SAFI_MULTICAST);
420 + }
421 +
422 + return message;
423 + }
220 } 424 }
......
...@@ -61,6 +61,10 @@ public class BgpSession extends SimpleChannelHandler { ...@@ -61,6 +61,10 @@ public class BgpSession extends SimpleChannelHandler {
61 private long remoteAs; // 2 octets 61 private long remoteAs; // 2 octets
62 private long remoteHoldtime; // 2 octets 62 private long remoteHoldtime; // 2 octets
63 private Ip4Address remoteBgpId; // 4 octets -> IPv4 address 63 private Ip4Address remoteBgpId; // 4 octets -> IPv4 address
64 + private boolean remoteIpv4Unicast; // Peer IPv4/UNICAST AFI/SAFI
65 + private boolean remoteIpv4Multicast; // Peer IPv4/MULTICAST AFI/SAFI
66 + private boolean remoteIpv6Unicast; // Peer IPv6/UNICAST AFI/SAFI
67 + private boolean remoteIpv6Multicast; // Peer IPv6/MULTICAST AFI/SAFI
64 // 68 //
65 private SocketAddress localAddress; // Local IP addr/port 69 private SocketAddress localAddress; // Local IP addr/port
66 private Ip4Address localIp4Address; // Local IPv4 address 70 private Ip4Address localIp4Address; // Local IPv4 address
...@@ -68,6 +72,10 @@ public class BgpSession extends SimpleChannelHandler { ...@@ -68,6 +72,10 @@ public class BgpSession extends SimpleChannelHandler {
68 private long localAs; // 2 octets 72 private long localAs; // 2 octets
69 private long localHoldtime; // 2 octets 73 private long localHoldtime; // 2 octets
70 private Ip4Address localBgpId; // 4 octets -> IPv4 address 74 private Ip4Address localBgpId; // 4 octets -> IPv4 address
75 + private boolean localIpv4Unicast; // Local IPv4/UNICAST AFI/SAFI
76 + private boolean localIpv4Multicast; // Local IPv4/MULTICAST AFI/SAFI
77 + private boolean localIpv6Unicast; // Local IPv6/UNICAST AFI/SAFI
78 + private boolean localIpv6Multicast; // Local IPv6/MULTICAST AFI/SAFI
71 // 79 //
72 private long localKeepaliveInterval; // Keepalive interval 80 private long localKeepaliveInterval; // Keepalive interval
73 81
...@@ -236,6 +244,82 @@ public class BgpSession extends SimpleChannelHandler { ...@@ -236,6 +244,82 @@ public class BgpSession extends SimpleChannelHandler {
236 } 244 }
237 245
238 /** 246 /**
247 + * Gets the BGP session remote AFI/SAFI configuration for IPv4 unicast.
248 + *
249 + * @return the BGP session remote AFI/SAFI configuration for IPv4 unicast
250 + */
251 + public boolean getRemoteIpv4Unicast() {
252 + return remoteIpv4Unicast;
253 + }
254 +
255 + /**
256 + * Sets the BGP session remote AFI/SAFI configuration for IPv4 unicast.
257 + */
258 + void setRemoteIpv4Unicast() {
259 + this.remoteIpv4Unicast = true;
260 + // Copy the remote AFI/SAFI setting to the local configuration
261 + // NOTE: Uncomment the line below if the AFI/SAFI is supported locally
262 + // this.localIpv4Unicast = true;
263 + }
264 +
265 + /**
266 + * Gets the BGP session remote AFI/SAFI configuration for IPv4 multicast.
267 + *
268 + * @return the BGP session remote AFI/SAFI configuration for IPv4 multicast
269 + */
270 + public boolean getRemoteIpv4Multicast() {
271 + return remoteIpv4Multicast;
272 + }
273 +
274 + /**
275 + * Sets the BGP session remote AFI/SAFI configuration for IPv4 multicast.
276 + */
277 + void setRemoteIpv4Multicast() {
278 + this.remoteIpv4Multicast = true;
279 + // Copy the remote AFI/SAFI setting to the local configuration
280 + // NOTE: Uncomment the line below if the AFI/SAFI is supported locally
281 + // this.localIpv4Multicast = true;
282 + }
283 +
284 + /**
285 + * Gets the BGP session remote AFI/SAFI configuration for IPv6 unicast.
286 + *
287 + * @return the BGP session remote AFI/SAFI configuration for IPv6 unicast
288 + */
289 + public boolean getRemoteIpv6Unicast() {
290 + return remoteIpv6Unicast;
291 + }
292 +
293 + /**
294 + * Sets the BGP session remote AFI/SAFI configuration for IPv6 unicast.
295 + */
296 + void setRemoteIpv6Unicast() {
297 + this.remoteIpv6Unicast = true;
298 + // Copy the remote AFI/SAFI setting to the local configuration
299 + // NOTE: Uncomment the line below if the AFI/SAFI is supported locally
300 + // this.localIpv6Unicast = true;
301 + }
302 +
303 + /**
304 + * Gets the BGP session remote AFI/SAFI configuration for IPv6 multicast.
305 + *
306 + * @return the BGP session remote AFI/SAFI configuration for IPv6 multicast
307 + */
308 + public boolean getRemoteIpv6Multicast() {
309 + return remoteIpv6Multicast;
310 + }
311 +
312 + /**
313 + * Sets the BGP session remote AFI/SAFI configuration for IPv6 multicast.
314 + */
315 + void setRemoteIpv6Multicast() {
316 + this.remoteIpv6Multicast = true;
317 + // Copy the remote AFI/SAFI setting to the local configuration
318 + // NOTE: Uncomment the line below if the AFI/SAFI is supported locally
319 + // this.localIpv6Multicast = true;
320 + }
321 +
322 + /**
239 * Gets the BGP session local address. 323 * Gets the BGP session local address.
240 * 324 *
241 * @return the BGP session local address 325 * @return the BGP session local address
...@@ -290,6 +374,42 @@ public class BgpSession extends SimpleChannelHandler { ...@@ -290,6 +374,42 @@ public class BgpSession extends SimpleChannelHandler {
290 } 374 }
291 375
292 /** 376 /**
377 + * Gets the BGP session local AFI/SAFI configuration for IPv4 unicast.
378 + *
379 + * @return the BGP session local AFI/SAFI configuration for IPv4 unicast
380 + */
381 + public boolean getLocalIpv4Unicast() {
382 + return localIpv4Unicast;
383 + }
384 +
385 + /**
386 + * Gets the BGP session local AFI/SAFI configuration for IPv4 multicast.
387 + *
388 + * @return the BGP session local AFI/SAFI configuration for IPv4 multicast
389 + */
390 + public boolean getLocalIpv4Multicast() {
391 + return localIpv4Multicast;
392 + }
393 +
394 + /**
395 + * Gets the BGP session local AFI/SAFI configuration for IPv6 unicast.
396 + *
397 + * @return the BGP session local AFI/SAFI configuration for IPv6 unicast
398 + */
399 + public boolean getLocalIpv6Unicast() {
400 + return localIpv6Unicast;
401 + }
402 +
403 + /**
404 + * Gets the BGP session local AFI/SAFI configuration for IPv6 multicast.
405 + *
406 + * @return the BGP session local AFI/SAFI configuration for IPv6 multicast
407 + */
408 + public boolean getLocalIpv6Multicast() {
409 + return localIpv6Multicast;
410 + }
411 +
412 + /**
293 * Tests whether the session is closed. 413 * Tests whether the session is closed.
294 * <p> 414 * <p>
295 * NOTE: We use this method to avoid the Netty's asynchronous closing 415 * NOTE: We use this method to avoid the Netty's asynchronous closing
......
...@@ -27,6 +27,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; ...@@ -27,6 +27,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
27 import org.onlab.packet.Ip4Address; 27 import org.onlab.packet.Ip4Address;
28 import org.onlab.packet.Ip4Prefix; 28 import org.onlab.packet.Ip4Prefix;
29 import org.onosproject.sdnip.bgp.BgpConstants.Notifications.UpdateMessageError; 29 import org.onosproject.sdnip.bgp.BgpConstants.Notifications.UpdateMessageError;
30 +import org.onosproject.sdnip.bgp.BgpMessage.BgpParseException;
30 import org.slf4j.Logger; 31 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory; 32 import org.slf4j.LoggerFactory;
32 33
...@@ -1212,25 +1213,4 @@ final class BgpUpdate { ...@@ -1212,25 +1213,4 @@ final class BgpUpdate {
1212 data.writeBytes(message, attrLen); 1213 data.writeBytes(message, attrLen);
1213 return data; 1214 return data;
1214 } 1215 }
1215 -
1216 - /**
1217 - * An exception indicating a parsing error of the BGP message.
1218 - */
1219 - private static final class BgpParseException extends Exception {
1220 - /**
1221 - * Default constructor.
1222 - */
1223 - private BgpParseException() {
1224 - super();
1225 - }
1226 -
1227 - /**
1228 - * Constructor for a specific exception details message.
1229 - *
1230 - * @param message the message with the exception details
1231 - */
1232 - private BgpParseException(String message) {
1233 - super(message);
1234 - }
1235 - }
1236 } 1216 }
......
...@@ -43,7 +43,11 @@ public class BgpNeighborsListCommand extends AbstractShellCommand { ...@@ -43,7 +43,11 @@ public class BgpNeighborsListCommand extends AbstractShellCommand {
43 private static final String FORMAT_NEIGHBOR_LINE2 = 43 private static final String FORMAT_NEIGHBOR_LINE2 =
44 " Remote router ID %s, IP %s, BGP version %d, Hold time %d"; 44 " Remote router ID %s, IP %s, BGP version %d, Hold time %d";
45 private static final String FORMAT_NEIGHBOR_LINE3 = 45 private static final String FORMAT_NEIGHBOR_LINE3 =
46 + " Remote AFI/SAFI IPv4 Unicast %s Multicast %s, IPv6 Unicast %s Multicast %s";
47 + private static final String FORMAT_NEIGHBOR_LINE4 =
46 " Local router ID %s, IP %s, BGP version %d, Hold time %d"; 48 " Local router ID %s, IP %s, BGP version %d, Hold time %d";
49 + private static final String FORMAT_NEIGHBOR_LINE5 =
50 + " Local AFI/SAFI IPv4 Unicast %s Multicast %s, IPv6 Unicast %s Multicast %s";
47 51
48 @Override 52 @Override
49 protected void execute() { 53 protected void execute() {
...@@ -102,10 +106,20 @@ public class BgpNeighborsListCommand extends AbstractShellCommand { ...@@ -102,10 +106,20 @@ public class BgpNeighborsListCommand extends AbstractShellCommand {
102 bgpSession.getRemoteBgpVersion(), 106 bgpSession.getRemoteBgpVersion(),
103 bgpSession.getRemoteHoldtime()); 107 bgpSession.getRemoteHoldtime());
104 print(FORMAT_NEIGHBOR_LINE3, 108 print(FORMAT_NEIGHBOR_LINE3,
109 + bgpSession.getRemoteIpv4Unicast() ? "YES" : "NO",
110 + bgpSession.getRemoteIpv4Multicast() ? "YES" : "NO",
111 + bgpSession.getRemoteIpv6Unicast() ? "YES" : "NO",
112 + bgpSession.getRemoteIpv6Multicast() ? "YES" : "NO");
113 + print(FORMAT_NEIGHBOR_LINE4,
105 bgpSession.getLocalBgpId().toString(), 114 bgpSession.getLocalBgpId().toString(),
106 bgpSession.getLocalAddress().toString(), 115 bgpSession.getLocalAddress().toString(),
107 bgpSession.getLocalBgpVersion(), 116 bgpSession.getLocalBgpVersion(),
108 bgpSession.getLocalHoldtime()); 117 bgpSession.getLocalHoldtime());
118 + print(FORMAT_NEIGHBOR_LINE5,
119 + bgpSession.getLocalIpv4Unicast() ? "YES" : "NO",
120 + bgpSession.getLocalIpv4Multicast() ? "YES" : "NO",
121 + bgpSession.getLocalIpv6Unicast() ? "YES" : "NO",
122 + bgpSession.getLocalIpv6Multicast() ? "YES" : "NO");
109 } 123 }
110 124
111 /** 125 /**
...@@ -139,12 +153,20 @@ public class BgpNeighborsListCommand extends AbstractShellCommand { ...@@ -139,12 +153,20 @@ public class BgpNeighborsListCommand extends AbstractShellCommand {
139 result.put("remoteAs", bgpSession.getRemoteAs()); 153 result.put("remoteAs", bgpSession.getRemoteAs());
140 result.put("remoteHoldtime", bgpSession.getRemoteHoldtime()); 154 result.put("remoteHoldtime", bgpSession.getRemoteHoldtime());
141 result.put("remoteBgpId", bgpSession.getRemoteBgpId().toString()); 155 result.put("remoteBgpId", bgpSession.getRemoteBgpId().toString());
156 + result.put("remoteIpv4Unicast", bgpSession.getRemoteIpv4Unicast());
157 + result.put("remoteIpv4Multicast", bgpSession.getRemoteIpv4Multicast());
158 + result.put("remoteIpv6Unicast", bgpSession.getRemoteIpv6Unicast());
159 + result.put("remoteIpv6Multicast", bgpSession.getRemoteIpv6Multicast());
142 // 160 //
143 result.put("localAddress", bgpSession.getLocalAddress().toString()); 161 result.put("localAddress", bgpSession.getLocalAddress().toString());
144 result.put("localBgpVersion", bgpSession.getLocalBgpVersion()); 162 result.put("localBgpVersion", bgpSession.getLocalBgpVersion());
145 result.put("localAs", bgpSession.getLocalAs()); 163 result.put("localAs", bgpSession.getLocalAs());
146 result.put("localHoldtime", bgpSession.getLocalHoldtime()); 164 result.put("localHoldtime", bgpSession.getLocalHoldtime());
147 result.put("localBgpId", bgpSession.getLocalBgpId().toString()); 165 result.put("localBgpId", bgpSession.getLocalBgpId().toString());
166 + result.put("localIpv4Unicast", bgpSession.getLocalIpv4Unicast());
167 + result.put("localIpv4Multicast", bgpSession.getLocalIpv4Multicast());
168 + result.put("localIpv6Unicast", bgpSession.getLocalIpv6Unicast());
169 + result.put("localIpv6Multicast", bgpSession.getLocalIpv6Multicast());
148 170
149 return result; 171 return result;
150 } 172 }
......