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