2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.parser.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
14 import java.io.ByteArrayOutputStream;
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.util.ArrayList;
18 import java.util.HashSet;
19 import java.util.List;
22 import org.junit.BeforeClass;
23 import org.junit.Ignore;
24 import org.junit.Test;
25 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
26 import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
27 import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunityUtil;
28 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
29 import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
30 import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
31 import org.opendaylight.protocol.util.ByteArray;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Open;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Update;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.UpdateBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.CParameters;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.AggregatorBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.as.path.SegmentsBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.WithdrawnRoutesBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocol;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AsPathSegment;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpAggregator;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.CAListBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.CASetBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequence;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequenceBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.CInet4SpecificExtendedCommunityBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.inet4.specific.extended.community.Inet4SpecificExtendedCommunityBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv4NextHop;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv4NextHopBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv6NextHop;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv6NextHopBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.c.ipv4.next.hop.Ipv4NextHopBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.c.ipv6.next.hop.Ipv6NextHopBuilder;
71 import com.google.common.collect.Lists;
72 import com.google.common.collect.Sets;
74 public class BGPParserTest {
77 * Used by other tests as well
79 static final List<byte[]> inputBytes = new ArrayList<byte[]>();
81 private static int COUNTER = 17;
83 private static int MAX_SIZE = 300;
85 private static BGPUpdateMessageParser updateParser;
88 public static void setUp() throws Exception {
89 updateParser = new BGPUpdateMessageParser(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getAttributeRegistry());
91 for (int i = 1; i <= COUNTER; i++) {
92 final String name = "/up" + i + ".bin";
93 final InputStream is = BGPParserTest.class.getResourceAsStream(name);
95 throw new IOException("Failed to get resource " + name);
98 final ByteArrayOutputStream bis = new ByteArrayOutputStream();
99 final byte[] data = new byte[MAX_SIZE];
101 while ((nRead = is.read(data, 0, data.length)) != -1) {
102 bis.write(data, 0, nRead);
106 inputBytes.add(bis.toByteArray());
111 public void testResource() {
112 assertNotNull(inputBytes);
116 * Tests IPv4 NEXT_HOP, ATOMIC_AGGREGATE, COMMUNITY, NLRI
118 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
119 * 00 54 <- length (84) - including header
121 * 00 00 <- withdrawn routes length
122 * 00 31 <- total path attribute length (49)
123 * 40 <- attribute flags
124 * 01 <- attribute type code (origin)
125 * 01 <- attribute length
126 * 00 <- Origin value (IGP)
127 * 40 <- attribute flags
128 * 02 <- attribute type code (as path)
129 * 06 <- attribute length
131 * 01 <- path segment count
132 * 00 00 fd ea <- path segment value (65002)
133 * 40 <- attribute flags
134 * 03 <- attribute type code (Next Hop)
135 * 04 <- attribute length
136 * 10 00 00 02 <- value (10.0.0.2)
137 * 80 <- attribute flags
138 * 04 <- attribute type code (multi exit disc)
139 * 04 <- attribute length
140 * 00 00 00 00 <- value
141 * 64 <- attribute flags
142 * 06 <- attribute type code (atomic aggregate)
143 * 00 <- attribute length
144 * 64 <- attribute flags
145 * 08 <- attribute type code (community)
146 * 10 <- attribute length FF FF FF
147 * 01 <- value (NO_EXPORT)
148 * FF FF FF 02 <- value (NO_ADVERTISE)
149 * FF FF FF 03 <- value (NO_EXPORT_SUBCONFED)
150 * FF FF FF 10 <- unknown Community
153 * 18 ac 11 02 <- IPv4 Prefix (172.17.2.0 / 24)
154 * 18 ac 11 01 <- IPv4 Prefix (172.17.1.0 / 24)
155 * 18 ac 11 00 <- IPv4 Prefix (172.17.0.0 / 24)
159 // FIXME: to be fixed in testing phase
160 public void testGetUpdateMessage1() throws Exception {
162 final byte[] body = ByteArray.cutBytes(inputBytes.get(0), MessageUtil.COMMON_HEADER_LENGTH);
163 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(0), MessageUtil.MARKER_LENGTH,
164 MessageUtil.LENGTH_FIELD_LENGTH));
165 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
169 assertNull(message.getWithdrawnRoutes());
173 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65002L)).build());
174 final List<AsPathSegment> asPath = Lists.newArrayList();
175 asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
177 final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
178 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build();
180 final Set<Community> comms = new HashSet<>();
181 comms.add(CommunityUtil.NO_EXPORT);
182 comms.add(CommunityUtil.NO_ADVERTISE);
183 comms.add(CommunityUtil.NO_EXPORT_SUBCONFED);
184 comms.add(CommunityUtil.create(0xFFFF, 0xFF10));
186 // check path attributes
188 // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
189 // true, false, false, BGPOrigin.IGP);
190 // assertEquals(originAttr, attrs.get(0));
192 // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
193 // true, false, false, asPath);
194 // assertEquals(asPathAttr, attrs.get(1));
196 // final PathAttribute nextHopAttr = new PathAttribute(TypeCode.NEXT_HOP, false,
197 // true, false, false, nextHop);
198 // assertEquals(nextHopAttr, attrs.get(2));
200 // final PathAttribute multiExitDisc = new PathAttribute(
201 // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
202 // assertEquals(multiExitDisc, attrs.get(3));
204 // final PathAttribute atomic = new PathAttribute(TypeCode.ATOMIC_AGGREGATE, false,
205 // true, true, false, null);
206 // assertEquals(atomic, attrs.get(4));
208 // final PathAttribute comm = new PathAttribute(TypeCode.COMMUNITIES, false,
209 // true, true, false, comms);
210 // assertEquals(comm, attrs.get(5));
214 // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1, pref2, pref3);
215 // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
217 // final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
218 // final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath, comms,
219 // Collections.<ExtendedCommunity> emptySet()), nextHop);
223 // final Set<BGPObject> addedObjects = Sets.newHashSet();
225 // final BGPRoute route1 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.2.0/24"), state,
228 // addedObjects.add(route1);
230 // final BGPRoute route2 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.1.0/24"), state,
233 // addedObjects.add(route2);
235 // final BGPRoute route3 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.0.0/24"), state,
238 // addedObjects.add(route3);
242 * Tests IPv6 NEXT_HOP, NLRI, ORIGIN.IGP, MULTI_EXIT_DISC, ORIGINATOR-ID, CLUSTER_LIST.
244 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
245 * 00 80 <- length (128) - including header
247 * 00 00 <- withdrawn routes length
248 * 00 69 <- total path attribute length (105)
249 * 40 <- attribute flags
250 * 01 <- attribute type code (origin)
251 * 01 <- attribute length
252 * 00 <- Origin value (IGP)
253 * 40 <- attribute flags
254 * 02 <- attribute type code (as path)
255 * 06 <- attribute length
257 * 01 <- path segment count
258 * 00 00 fd e9 <- path segment value (65001)
259 * 80 <- attribute flags
260 * 04 <- attribute type code (multi exit disc)
261 * 04 <- attribute length
262 * 00 00 00 00 <- value
263 * 80 <- attribute flags
264 * 09 <- attribute type code (originator id)
265 * 04 <- attribute length
266 * 7f 00 00 01 <- value (localhost ip)
267 * 80 <- attribute flags
268 * 0a <- attribute type code (cluster list)
269 * 08 <- attribute length
270 * 01 02 03 04 <- value
271 * 05 06 07 08 <- value
272 * 80 <- attribute flags
273 * 0e <- attribute type code (mp reach nlri)
274 * 40 <- attribute length
275 * 00 02 <- AFI (Ipv6)
276 * 01 <- SAFI (Unicast)
277 * 20 <- length of next hop
278 * 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 01 <- global
279 * fe 80 00 00 00 00 00 00 c0 01 0b ff fe 7e 00 <- link local
283 * 40 20 01 0d b8 00 01 00 02 <- IPv6 Prefix (2001:db8:1:2:: / 64)
284 * 40 20 01 0d b8 00 01 00 01 <- IPv6 Prefix (2001:db8:1:1:: / 64)
285 * 40 20 01 0d b8 00 01 00 00 <- IPv6 Prefix (2001:db8:1:: / 64)
290 // FIXME: to be fixed in testing phase
291 public void testGetUpdateMessage2() throws Exception {
292 final byte[] body = ByteArray.cutBytes(inputBytes.get(1), MessageUtil.COMMON_HEADER_LENGTH);
293 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(1), MessageUtil.MARKER_LENGTH,
294 MessageUtil.LENGTH_FIELD_LENGTH));
295 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
298 assertNull(message.getWithdrawnRoutes());
301 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65001L)).build());
302 final List<AsPathSegment> asPath = Lists.newArrayList();
303 asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
305 final CIpv6NextHop nextHop = new CIpv6NextHopBuilder().setIpv6NextHop(
306 new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
308 // final List<ClusterIdentifier> clusters = Lists.newArrayList(
309 // new ClusterIdentifier(new byte[] { 1, 2, 3, 4}),
310 // new ClusterIdentifier(new byte[] { 5, 6, 7, 8}));
312 // check path attributes
314 // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
315 // true, false, false, BGPOrigin.IGP);
316 // assertEquals(originAttr, attrs.get(0));
318 // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
319 // true, false, false, asPath);
320 // assertEquals(asPathAttr, attrs.get(1));
322 // final PathAttribute multiExitDisc = new PathAttribute(
323 // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
324 // assertEquals(multiExitDisc, attrs.get(2));
326 // final PathAttribute originatorAttr = new PathAttribute(
327 // TypeCode.ORIGINATOR_ID, true, false, false, false, IPv4.FAMILY.addressForString("127.0.0.1"));
328 // assertEquals(originatorAttr, attrs.get(3));
330 // final PathAttribute clusterAttr = new PathAttribute(
331 // TypeCode.CLUSTER_LIST, true, false, false, false, clusters);
332 // assertEquals(clusterAttr, attrs.get(4));
334 // final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
335 // final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath,
336 // Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet()), nextHop);
340 // final Set<BGPObject> addedObjects = Sets.newHashSet();
342 // final BGPRoute route1 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1:2::/64"), state,
345 // addedObjects.add(route1);
347 // final BGPRoute route2 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1:1::/64"), state,
350 // addedObjects.add(route2);
352 // final BGPRoute route3 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1::/64"), state,
355 // addedObjects.add(route3);
359 * Tests more AS Numbers in AS_PATH, AGGREGATOR, ORIGIN.INCOMPLETE
361 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
362 * 00 4b <- length (75) - including header
364 * 00 00 <- withdrawn routes length
365 * 00 30 <- total path attribute length (48)
366 * 40 <- attribute flags
367 * 01 <- attribute type code (origin)
368 * 01 <- attribute length
369 * 02 <- Origin value (Incomplete)
370 * 40 <- attribute flags
371 * 02 <- attribute type code (as path)
372 * 10 <- attribute length
374 * 01 <- path segment count
375 * 00 00 00 1e <- path segment value (30)
377 * 02 <- path segment count
378 * 00 00 00 0a <- path segment value (10)
379 * 00 00 00 14 <- path segment value (20)
380 * 40 <- attribute flags
381 * 03 <- attribute type (Next hop)
382 * 04 <- attribute length
383 * 0a 00 00 09 <- value (10.0.0.9)
384 * 80 <- attribute flags
385 * 04 <- attribute type code (multi exit disc)
386 * 04 <- attribute length
387 * 00 00 00 00 <- value
388 * c0 <- attribute flags
389 * 07 <- attribute type (Aggregator)
390 * 08 <- attribute length
391 * 00 00 00 1e <- value (AS number = 30)
392 * 0a 00 00 09 <- value (IP address = 10.0.0.9)
395 * 15 ac 10 00 <- IPv4 Prefix (172.16.0.0 / 21)
399 // FIXME: to be fixed in testing phase
400 public void testGetUpdateMessage3() throws Exception {
401 final byte[] body = ByteArray.cutBytes(inputBytes.get(2), MessageUtil.COMMON_HEADER_LENGTH);
402 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(2), MessageUtil.MARKER_LENGTH,
403 MessageUtil.LENGTH_FIELD_LENGTH));
404 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
407 assertNull(message.getWithdrawnRoutes());
411 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(30L)).build());
412 final List<AsPathSegment> asPath = Lists.newArrayList();
413 asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
414 asPath.add(new SegmentsBuilder().setCSegment(
415 new CASetBuilder().setAsSet(Lists.newArrayList(new AsNumber(10L), new AsNumber(20L))).build()).build());
417 final BgpAggregator aggregator = new AggregatorBuilder().setAsNumber(new AsNumber((long) 30)).setNetworkAddress(
418 new Ipv4Address("10.0.0.9")).build();
419 final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
420 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.9")).build()).build();
422 // final IPv4Prefix pref1 = IPv4.FAMILY.prefixForString("172.16.0.0/21");
424 // check path attributes
426 // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
427 // true, false, false, BGPOrigin.INCOMPLETE);
428 // assertEquals(originAttr, attrs.get(0));
430 // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
431 // true, false, false, asPath);
432 // assertEquals(asPathAttr, attrs.get(1));
434 // final PathAttribute nextHopAttr = new PathAttribute(TypeCode.NEXT_HOP, false,
435 // true, false, false, nextHop);
436 // assertEquals(nextHopAttr, attrs.get(2));
438 // final PathAttribute multiExitDisc = new PathAttribute(
439 // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
440 // assertEquals(multiExitDisc, attrs.get(3));
442 // final PathAttribute agg = new PathAttribute(TypeCode.AGGREGATOR, true, true,
443 // false, false, aggregator);
444 // assertEquals(agg, attrs.get(4));
448 // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1);
449 // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
451 // final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Incomplete, aggregator);
452 // final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath,
453 // Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet()), nextHop);
457 // final Set<BGPObject> addedObjects = Sets.newHashSet();
459 // final BGPRoute route1 = new BGPIPv4RouteImpl(pref1, state, routeState);
461 // addedObjects.add(route1);
465 * Tests empty AS_PATH, ORIGIN.EGP, LOCAL_PREF, EXTENDED_COMMUNITIES (Ipv4 Addr specific)
467 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
468 * 00 4A <- length (73) - including header
470 * 00 00 <- withdrawn routes length
471 * 00 27 <- total path attribute length (39)
472 * 40 <- attribute flags
473 * 01 <- attribute type code (Origin)
474 * 01 <- attribute length
475 * 01 <- Origin value (EGP)
476 * 40 <- attribute flags
477 * 02 <- attribute type code (As path)
478 * 00 <- attribute length
479 * 40 <- attribute flags
480 * 03 <- attribute type (Next hop)
481 * 04 <- attribute length
482 * 03 03 03 03 <- value (3.3.3.3)
483 * 80 <- attribute flags
484 * 04 <- attribute type code (Multi exit disc)
485 * 04 <- attribute length
486 * 00 00 00 00 <- value
487 * 40 <- attribute flags
488 * 05 <- attribute type (Local Pref)
489 * 04 <- attribute length
490 * 00 00 00 64 <- value (100)
491 * 80 <- attribute flags
492 * 10 <- attribute type (extended community)
493 * 08 <- attribute length
494 * 01 04 <- value (type - Ipv4 Address Specific Extended Community)
495 * c0 a8 01 00 <- value (global adm. 198.162.1.0)
496 * 12 34 <- value (local adm. 4660)
499 * 18 0a 1e 03 <- IPv4 Prefix (10.30.3.0 / 24)
500 * 18 0a 1e 02 <- IPv4 Prefix (10.30.2.0 / 24)
501 * 18 0a 1e 01 <- IPv4 Prefix (10.30.1.0 / 24)
505 // FIXME: to be fixed in testing phase
506 public void testGetUpdateMessage4() throws Exception {
507 final byte[] body = ByteArray.cutBytes(inputBytes.get(3), MessageUtil.COMMON_HEADER_LENGTH);
508 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(3), MessageUtil.MARKER_LENGTH,
509 MessageUtil.LENGTH_FIELD_LENGTH));
510 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
514 assertNull(message.getWithdrawnRoutes());
518 final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
519 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("3.3.3.3")).build()).build();
521 final Set<ExtendedCommunity> comms = Sets.newHashSet();
522 comms.add(new CInet4SpecificExtendedCommunityBuilder().setInet4SpecificExtendedCommunity(
523 new Inet4SpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(new Ipv4Address("192.168.1.0")).setLocalAdministrator(
524 new byte[] { 0x12, 0x34 }).build()).build());
526 // check path attributes
528 // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
529 // true, false, false, BGPOrigin.EGP);
530 // assertEquals(originAttr, attrs.get(0));
532 // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
533 // true, false, false, asPath);
534 // assertEquals(asPathAttr, attrs.get(1));
536 // final PathAttribute nextHopAttr = new PathAttribute(TypeCode.NEXT_HOP, false,
537 // true, false, false, nextHop);
538 // assertEquals(nextHopAttr, attrs.get(2));
540 // final PathAttribute multiExitDisc = new PathAttribute(
541 // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
542 // assertEquals(multiExitDisc, attrs.get(3));
544 // final PathAttribute localPref = new PathAttribute(TypeCode.LOCAL_PREF, false,
545 // true, false, false, 100);
546 // assertEquals(localPref, attrs.get(4));
550 // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1, pref2, pref3);
551 // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
553 // final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Egp, null);
554 // final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(Collections.<AsPathSegment>
555 // emptyList(), Collections.<Community> emptySet(), comms), nextHop);
559 // final Set<BGPObject> addedObjects = Sets.newHashSet();
561 // final BGPRoute route1 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.3.0/24"), state, routeState);
563 // addedObjects.add(route1);
565 // final BGPRoute route2 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.2.0/24"), state, routeState);
567 // addedObjects.add(route2);
569 // final BGPRoute route3 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.1.0/24"), state, routeState);
571 // addedObjects.add(route3);
575 * Tests withdrawn routes.
577 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
578 * 00 1c <- length (28) - including header
580 * 00 05 <- withdrawn routes length (5)
581 * 1e ac 10 00 04 <- route (172.16.0.4)
582 * 00 00 <- total path attribute length
586 // FIXME: to be fixed in testing phase
587 public void testGetUpdateMessage5() throws Exception {
588 final byte[] body = ByteArray.cutBytes(inputBytes.get(4), MessageUtil.COMMON_HEADER_LENGTH);
589 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(4), MessageUtil.MARKER_LENGTH,
590 MessageUtil.LENGTH_FIELD_LENGTH));
591 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
595 final List<Ipv4Prefix> prefs = Lists.newArrayList(new Ipv4Prefix("172.16.0.4/30"));
599 final Update expectedMessage = new UpdateBuilder().setWithdrawnRoutes(
600 new WithdrawnRoutesBuilder().setWithdrawnRoutes(prefs).build()).build();
602 assertEquals(expectedMessage.getWithdrawnRoutes().getWithdrawnRoutes().get(0).toString(),
603 message.getWithdrawnRoutes().getWithdrawnRoutes().get(0).toString());
609 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
610 * 00 17 <- length (23) - including header
612 * 00 00 <- withdrawn routes length
613 * 00 00 <- total path attribute length
616 public void testEORIpv4() throws Exception {
617 final byte[] body = ByteArray.cutBytes(inputBytes.get(5), MessageUtil.COMMON_HEADER_LENGTH);
618 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(5), MessageUtil.MARKER_LENGTH,
619 MessageUtil.LENGTH_FIELD_LENGTH));
620 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
622 assertEquals(new UpdateBuilder().build(), message);
626 * End of Rib for Ipv6 consists of empty MP_UNREACH_NLRI, with AFI 2 and SAFI 1
628 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
629 * 00 1d <- length (29) - including header
631 * 00 00 <- withdrawn routes length
632 * 00 06 <- total path attribute length
633 * 80 <- attribute flags
634 * 0f <- attribute type (15 - MP_UNREACH_NLRI)
635 * 03 <- attribute length
636 * 00 02 <- value (AFI 2: IPv6)
637 * 01 <- value (SAFI 1)
641 // FIXME: to be fixed in testing phase
642 public void testEORIpv6() throws Exception {
643 final byte[] body = ByteArray.cutBytes(inputBytes.get(6), MessageUtil.COMMON_HEADER_LENGTH);
644 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(6), MessageUtil.MARKER_LENGTH,
645 MessageUtil.LENGTH_FIELD_LENGTH));
646 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
650 final Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getAfi();
651 final SubsequentAddressFamily safi = message.getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getSafi().newInstance();
653 assertEquals(Ipv6AddressFamily.class, afi);
654 assertEquals(UnicastSubsequentAddressFamily.INSTANCE, safi);
658 * End of Rib for LS consists of empty MP_UNREACH_NLRI, with AFI 16388 and SAFI 71
660 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
661 * 00 1d <- length (29) - including header
663 * 00 00 <- withdrawn routes length
664 * 00 06 <- total path attribute length
665 * 80 <- attribute flags
666 * 0f <- attribute type (15 - MP_UNREACH_NLRI)
667 * 03 <- attribute length
668 * 40 04 <- value (AFI 16388: LS)
669 * 47 <- value (SAFI 71)
673 // FIXME: to be fixed in testing phase
674 public void testEORLS() throws Exception {
675 final byte[] body = ByteArray.cutBytes(inputBytes.get(7), MessageUtil.COMMON_HEADER_LENGTH);
676 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(7), MessageUtil.MARKER_LENGTH,
677 MessageUtil.LENGTH_FIELD_LENGTH));
678 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
680 final Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getAfi();
681 final SubsequentAddressFamily safi = message.getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getSafi().newInstance();
683 assertEquals(LinkstateAddressFamily.class, afi);
684 assertEquals(LinkstateSubsequentAddressFamily.INSTANCE, safi);
688 * Tests BGP Link Ipv4
690 00 00 <- withdrawn routes length
691 01 48 <- total path attribute length (328)
692 90 <- attribute flags
693 0e <- attribute type code (MP reach)
694 01 2c <- attribute extended length (300)
695 40 04 <- AFI (16388 - Linkstate)
696 47 <- SAFI (71 - Linkstate)
697 04 <- next hop length
698 19 19 19 01 <- nexthop (25.25.25.1)
701 00 02 <- NLRI type (2 - linkNLRI)
702 00 5d <- NLRI length (93)
703 03 <- ProtocolID - OSPF
704 00 00 00 00 00 00 00 01 <- identifier
706 01 00 <- local node descriptor type (256)
708 02 00 <- node descriptor type (member AS - 512)
710 00 00 00 64 <- value (100)
711 02 01 <- node descriptor type (bgpId - 513)
713 19 19 19 01 <- bgpId (25.25.25.1)
714 02 02 <- node descriptor type (areaId - 514)
717 02 03 <- node descriptor type (routeId - 515)
719 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
721 01 01 <- remote node descriptor type (257)
723 02 00 <- node descriptor type (member AS - 512)
725 00 00 00 64 <- value (100)
726 02 01 <- node descriptor type (bgpId - 513)
728 19 19 19 01 <- bgpId (25.25.25.1)
729 02 02 <- node descriptor type (areaId - 514)
732 02 03 <- node descriptor type (routeId - 515)
734 03 03 03 04 <- OSPF Router Id
736 01 03 <- link descriptor type (IPv4 interface address - 259)
738 0b 0b 0b 03 <- value (11.11.11.3)
740 00 02 <- NLRI type (2 - linkNLRI)
741 00 5d <- NLRI length (93)
742 03 <- ProtocolID - OSPF
743 00 00 00 00 00 00 00 01 <- identifier
745 01 00 <- local node descriptor type (256)
747 02 00 <- node descriptor type (member AS - 512)
749 00 00 00 64 <- value (100)
750 02 01 <- node descriptor type (bgpId - 513)
752 19 19 19 01 <- bgpId (25.25.25.1)
753 02 02 <- node descriptor type (areaId - 514)
756 02 03 <- node descriptor type (routeId - 515)
758 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
760 01 01 <- remote node descriptor type (257)
762 02 00 <- node descriptor type (member AS - 512)
764 00 00 00 64 <- value (100)
765 02 01 <- node descriptor type (bgpId - 513)
767 19 19 19 01 <- bgpId (25.25.25.1)
768 02 02 <- node descriptor type (areaId - 514)
771 02 03 <- node descriptor type (routeId - 515)
773 01 01 01 02 <- OSPF Router Id
775 01 03 <- link descriptor type (IPv4 interface address - 259)
777 0b 0b 0b 01 <- value (11.11.11.1)
779 00 02 <- NLRI type (2 - linkNLRI)
780 00 5d <- NLRI length (93)
781 03 <- ProtocolID - OSPF
782 00 00 00 00 00 00 00 01 <- identifier
784 01 00 <- local node descriptor type (256)
786 02 00 <- node descriptor type (member AS - 512)
788 00 00 00 64 <- value (100)
789 02 01 <- node descriptor type (bgpId - 513)
791 19 19 19 01 <- bgpId (25.25.25.1)
792 02 02 <- node descriptor type (areaId - 514)
795 02 03 <- node descriptor type (routeId - 515)
797 01 01 01 02 <- OSPF Router Id
799 01 01 <- remote node descriptor type (257)
801 02 00 <- node descriptor type (member AS - 512)
803 00 00 00 64 <- value (100)
804 02 01 <- node descriptor type (bgpId - 513)
806 19 19 19 01 <- bgpId (25.25.25.1)
807 02 02 <- node descriptor type (areaId - 514)
810 02 03 <- node descriptor type (routeId - 515)
812 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
814 01 03 <- link descriptor type (IPv4 interface address - 259)
816 0b 0b 0b 01 <- value (11.11.11.1)
818 40 <- attribute flags
819 01 <- attribute type (Origin)
820 01 <- attribute length
822 40 <- attribute flags
823 02 <- attribute type (AS Path)
825 40 <- attribute flags
826 05 <- attribute type (local pref)
829 c0 <- attribute flags
830 63 <- attribute type (Link STATE - 99)
832 04 47 <- link attribute (1095 - Metric)
838 // FIXME: to be fixed in testing phase
839 public void testBGPLink() throws Exception {
840 final byte[] body = ByteArray.cutBytes(inputBytes.get(8), MessageUtil.COMMON_HEADER_LENGTH);
841 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(8), MessageUtil.MARKER_LENGTH,
842 MessageUtil.LENGTH_FIELD_LENGTH));
843 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
847 assertNull(message.getWithdrawnRoutes());
849 // network object state
850 // final NetworkObjectState objState = new NetworkObjectState(Collections.<AsPathSegment> emptyList(),
851 // Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
852 // final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
854 // network link state
855 // final DefaultingTypesafeContainer<Metric<?>> container = new DefaultingTypesafeContainer<Metric<?>>();
856 // container.setDefaultEntry(new IGPMetric(1));
857 // final NetworkLinkState linkState = new NetworkLinkState(objState, container, null,
858 // LinkProtectionType.UNPROTECTED, null, null, null);
860 // final NodeIdentifierFactory f100 = new NodeIdentifierFactory(new AsNumber((long) 100), new
861 // DomainIdentifier(new byte[] { 25, 25,
862 // 25, 1 }), new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
864 // final NodeIdentifier nodeid1 = f100.identifierForRouter(new OSPFv3LANIdentifier(new OSPFRouterIdentifier(new
865 // byte[] { 3, 3, 3, 4 }), new OSPFInterfaceIdentifier(new byte[] {
866 // 0x0b, 0x0b, 0x0b, 0x03 })));
867 // final NodeIdentifier nodeid2 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }));
869 // final NodeIdentifier nodeid3 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 1, 1, 1, 2 }));
873 // final LinkIdentifier linkId1 = new LinkIdentifier(null, new LinkAnchor(nodeid1, new
874 // IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.3"))), new LinkAnchor(nodeid2, null));
875 // final LinkIdentifier linkId2 = new LinkIdentifier(null, new LinkAnchor(nodeid1, new
876 // IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.1"))), new LinkAnchor(nodeid3, null));
877 // final LinkIdentifier linkId3 = new LinkIdentifier(null, new LinkAnchor(nodeid3, new
878 // IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.1"))), new LinkAnchor(nodeid1, null));
880 // final BGPLink link1 = new BGPLinkImpl(state, linkId1, linkState);
881 // final BGPLink link2 = new BGPLinkImpl(state, linkId2, linkState);
882 // final BGPLink link3 = new BGPLinkImpl(state, linkId3, linkState);
884 // final BGPUpdateMessage expectedMessage = new BGPUpdateMessageImpl(Sets.newHashSet((BGPObject) link1,
885 // (BGPObject) link2,
886 // (BGPObject) link3), Collections.<Identifier> emptySet());
888 // assertEquals(expectedMessage, message);
894 * 00 00 <- withdrawn routes length
895 00 b2 <- total path attribute length (178)
896 90 <- attribute flags
897 0e <- attribute type code (MP reach)
898 00 a0 <- attribute extended length (160)
899 40 04 <- AFI (16388 - Linkstate)
900 47 <- SAFI (71 - Linkstate)
901 04 <- next hop length
902 19 19 19 01 - nexthop (25.25.25.1)
904 00 01 <- NLRI type (1 - nodeNLRI)
905 00 31 <- NLRI length (49)
906 03 <- ProtocolID - OSPF
907 00 00 00 00 00 00 00 01 <- identifier
909 01 00 <- local node descriptor type (256)
911 02 00 <- node descriptor type (member AS - 512)
913 00 00 00 64 <- value (100)
914 02 01 <- node descriptor type (bgpId - 513)
916 19 19 19 01 <- bgpId (25.25.25.1)
917 02 02 <- node descriptor type (areaId - 514)
920 02 03 <- node descriptor type (routeId - 515)
922 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
924 00 01 <- NLRI type (1 - nodeNLRI)
925 00 2d <- NLRI length (45)
926 03 <- ProtocolID - OSPF
927 00 00 00 00 00 00 00 01 <- identifier
929 01 00 <- local node descriptor type (256)
931 02 00 <- node descriptor type (member AS - 512)
933 00 00 00 64 <- value (100)
934 02 01 <- node descriptor type (bgpId - 513)
936 19 19 19 01 <- bgpId (25.25.25.1)
937 02 02 <- node descriptor type (areaId - 514)
940 02 03 <- node descriptor type (routeId - 515)
942 03 03 03 04 <- OSPF Router Id
944 00 01 <- NLRI type (1 - nodeNLRI)
945 00 2d <- NLRI length (45)
946 03 <- ProtocolID - OSPF
947 00 00 00 00 00 00 00 01 <- identifier
948 01 00 <- local node descriptor type (256)
950 02 00 <- node descriptor type (member AS - 512)
952 00 00 00 64 <- value (100)
953 02 01 <- node descriptor type (bgpId - 513)
955 19 19 19 01 <- bgpId (25.25.25.1)
956 02 02 <- node descriptor type (areaId - 514)
959 02 03 <- node descriptor type (routeId - 515)
961 01 01 01 02 <- OSPF Router Id
963 40 <- attribute flags
964 01 <- attribute type (Origin)
965 01 <- attribute length
967 40 <- attribute flags
968 02 <- attribute type (AS Path)
970 40 <- attribute flags
971 05 <- attribute type (local pref)
977 // FIXME: to be fixed in testing phase
978 public void testBGPNode() throws Exception {
979 final byte[] body = ByteArray.cutBytes(inputBytes.get(9), MessageUtil.COMMON_HEADER_LENGTH);
980 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(9), MessageUtil.MARKER_LENGTH,
981 MessageUtil.LENGTH_FIELD_LENGTH));
982 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
986 assertNull(message.getWithdrawnRoutes());
988 // network object state
989 // final NetworkObjectState objState = new NetworkObjectState(Collections.<AsPathSegment> emptyList(),
990 // Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
991 // final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
992 // final NetworkNodeState nstate = new NetworkNodeState(objState, Collections.<TopologyIdentifier> emptySet(),
993 // Collections.<ISISAreaIdentifier> emptySet(), false, false, false, false, Collections.<RouterIdentifier>
994 // emptySet(), null);
996 // network link state
998 // final NodeIdentifierFactory f100 = new NodeIdentifierFactory(new AsNumber((long) 100), new
999 // DomainIdentifier(new byte[] { 25, 25,
1000 // 25, 1 }), new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
1002 // final NodeIdentifier nodeid1 = f100.identifierForRouter(new OSPFv3LANIdentifier(new OSPFRouterIdentifier(new
1003 // byte[] { 3, 3, 3, 4 }), new OSPFInterfaceIdentifier(new byte[] {
1004 // 0x0b, 0x0b, 0x0b, 0x03 })));
1005 // final NodeIdentifier nodeid2 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }));
1007 // final NodeIdentifier nodeid3 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 1, 1, 1, 2 }));
1009 // check API message
1011 // final BGPNode node1 = new BGPNodeImpl(state, nodeid1, nstate);
1012 // final BGPNode node2 = new BGPNodeImpl(state, nodeid2, nstate);
1013 // final BGPNode node3 = new BGPNodeImpl(state, nodeid3, nstate);
1015 // final BGPUpdateMessage expectedMessage = new BGPUpdateMessageImpl(Sets.newHashSet((BGPObject) node1,
1016 // (BGPObject) node2,
1017 // (BGPObject) node3), Collections.<Identifier> emptySet());
1019 // assertEquals(expectedMessage, message);
1023 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
1024 * 00 98 <- length (69) - including header
1025 * 01 <- message type
1027 * 00 64 <- My AS Number (AS TRANS in this case)
1028 * 00 b4 <- Hold Time
1029 * 00 00 00 00 <- BGP Identifier
1030 * 28 <- Optional Parameters Length
1031 * 02 <- opt. param. type (capabilities)
1033 * 01 <- capability code (MP Extensions for BGP4)
1035 * 00 01 00 01 <- AFI 1, SAFI 1
1036 * 02 <- opt. param. type (capabilities)
1038 * 01 <- capability code (MP Extensions for BGP4)
1040 * 00 02 00 01 <- AFI 2, SAFI 1
1041 * 02 <- opt. param. type (capabilities)
1043 * 01 <- capability code (MP Extensions for BGP4)
1045 * 40 04 00 47 <- AFI 16388, SAFI 71
1046 * 02 <- opt. param. type (capabilities)
1048 * 80 <- capability code (private)
1050 * 02 <- opt. param. type (capabilities)
1052 * 02 <- capability code (Route refresh)
1054 * 02 <- opt. param. type (capabilities)
1056 * 41 <- capability code (AS4 octet support)
1058 * 00 00 00 64 <- AS number
1061 public void testOpenMessage() throws Exception {
1062 final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry();
1063 final Open open = (Open) msgReg.parseMessage(inputBytes.get(13));
1064 final Set<BgpTableType> types = Sets.newHashSet();
1065 for (final BgpParameters param : open.getBgpParameters()) {
1066 final CParameters p = param.getCParameters();
1067 if (p instanceof CMultiprotocol) {
1068 final BgpTableType type = new BgpTableTypeImpl(((CMultiprotocol) p).getMultiprotocolCapability().getAfi(), ((CMultiprotocol) p).getMultiprotocolCapability().getSafi());
1072 final Set<BgpTableType> expected = Sets.newHashSet();
1073 expected.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
1074 expected.add(new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class));
1075 expected.add(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
1076 assertEquals(expected, types);