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.assertTrue;
14 import java.io.ByteArrayOutputStream;
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.net.UnknownHostException;
18 import java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.HashSet;
21 import java.util.List;
24 import org.junit.BeforeClass;
25 import org.junit.Test;
26 import org.opendaylight.protocol.bgp.concepts.BGPObject;
27 import org.opendaylight.protocol.bgp.concepts.BGPTableType;
28 import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
29 import org.opendaylight.protocol.bgp.linkstate.AreaIdentifier;
30 import org.opendaylight.protocol.bgp.linkstate.DomainIdentifier;
31 import org.opendaylight.protocol.bgp.linkstate.IPv4InterfaceIdentifier;
32 import org.opendaylight.protocol.bgp.linkstate.ISISAreaIdentifier;
33 import org.opendaylight.protocol.bgp.linkstate.LinkAnchor;
34 import org.opendaylight.protocol.bgp.linkstate.LinkIdentifier;
35 import org.opendaylight.protocol.bgp.linkstate.LinkProtectionType;
36 import org.opendaylight.protocol.bgp.linkstate.NetworkLinkState;
37 import org.opendaylight.protocol.bgp.linkstate.NetworkNodeState;
38 import org.opendaylight.protocol.bgp.linkstate.NetworkObjectState;
39 import org.opendaylight.protocol.bgp.linkstate.NetworkRouteState;
40 import org.opendaylight.protocol.bgp.linkstate.NodeIdentifier;
41 import org.opendaylight.protocol.bgp.linkstate.NodeIdentifierFactory;
42 import org.opendaylight.protocol.bgp.linkstate.OSPFInterfaceIdentifier;
43 import org.opendaylight.protocol.bgp.linkstate.OSPFRouterIdentifier;
44 import org.opendaylight.protocol.bgp.linkstate.OSPFv3LANIdentifier;
45 import org.opendaylight.protocol.bgp.linkstate.RouterIdentifier;
46 import org.opendaylight.protocol.bgp.linkstate.TopologyIdentifier;
47 import org.opendaylight.protocol.bgp.parser.BGPLink;
48 import org.opendaylight.protocol.bgp.parser.BGPNode;
49 import org.opendaylight.protocol.bgp.parser.BGPParameter;
50 import org.opendaylight.protocol.bgp.parser.BGPRoute;
51 import org.opendaylight.protocol.bgp.parser.BGPUpdateEvent;
52 import org.opendaylight.protocol.bgp.parser.BGPUpdateMessage;
53 import org.opendaylight.protocol.bgp.parser.BGPUpdateSynchronized;
54 import org.opendaylight.protocol.bgp.parser.impl.PathAttribute.TypeCode;
55 import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
56 import org.opendaylight.protocol.bgp.parser.message.BGPOpenMessage;
57 import org.opendaylight.protocol.bgp.parser.parameter.MultiprotocolCapability;
58 import org.opendaylight.protocol.bgp.util.BGPIPv4RouteImpl;
59 import org.opendaylight.protocol.bgp.util.BGPIPv6RouteImpl;
60 import org.opendaylight.protocol.bgp.util.BGPLinkImpl;
61 import org.opendaylight.protocol.bgp.util.BGPNodeImpl;
62 import org.opendaylight.protocol.concepts.IGPMetric;
63 import org.opendaylight.protocol.concepts.IPv4;
64 import org.opendaylight.protocol.concepts.IPv4Prefix;
65 import org.opendaylight.protocol.concepts.IPv6;
66 import org.opendaylight.protocol.concepts.Identifier;
67 import org.opendaylight.protocol.concepts.Metric;
68 import org.opendaylight.protocol.util.ByteArray;
69 import org.opendaylight.protocol.util.DefaultingTypesafeContainer;
70 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
71 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
72 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.AggregatorBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.as.path.SegmentsBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AsPathSegment;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpAggregator;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.CAListBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.CASetBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequence;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequenceBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.CInet4SpecificExtendedCommunityBuilder;
90 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;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv4NextHop;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv4NextHopBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv6NextHop;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv6NextHopBuilder;
95 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;
96 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;
98 import com.google.common.collect.Lists;
99 import com.google.common.collect.Sets;
101 public class BGPParserTest {
104 * Used by other tests as well
106 static final List<byte[]> inputBytes = new ArrayList<byte[]>();
108 private static int COUNTER = 17;
110 private static int MAX_SIZE = 300;
113 public static void setUp() throws Exception {
115 for (int i = 1; i <= COUNTER; i++) {
116 final String name = "/up" + i + ".bin";
117 final InputStream is = BGPParserTest.class.getResourceAsStream(name);
119 throw new IOException("Failed to get resource " + name);
122 final ByteArrayOutputStream bis = new ByteArrayOutputStream();
123 final byte[] data = new byte[MAX_SIZE];
125 while ((nRead = is.read(data, 0, data.length)) != -1) {
126 bis.write(data, 0, nRead);
130 inputBytes.add(bis.toByteArray());
135 public void testResource() {
136 assertNotNull(inputBytes);
140 * Tests IPv4 NEXT_HOP, ATOMIC_AGGREGATE, COMMUNITY, NLRI
142 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
143 * 00 54 <- length (84) - including header
145 * 00 00 <- withdrawn routes length
146 * 00 31 <- total path attribute length (49)
147 * 40 <- attribute flags
148 * 01 <- attribute type code (origin)
149 * 01 <- attribute length
150 * 00 <- Origin value (IGP)
151 * 40 <- attribute flags
152 * 02 <- attribute type code (as path)
153 * 06 <- attribute length
155 * 01 <- path segment count
156 * 00 00 fd ea <- path segment value (65002)
157 * 40 <- attribute flags
158 * 03 <- attribute type code (Next Hop)
159 * 04 <- attribute length
160 * 10 00 00 02 <- value (10.0.0.2)
161 * 80 <- attribute flags
162 * 04 <- attribute type code (multi exit disc)
163 * 04 <- attribute length
164 * 00 00 00 00 <- value
165 * 64 <- attribute flags
166 * 06 <- attribute type code (atomic aggregate)
167 * 00 <- attribute length
168 * 64 <- attribute flags
169 * 08 <- attribute type code (community)
170 * 10 <- attribute length FF FF FF
171 * 01 <- value (NO_EXPORT)
172 * FF FF FF 02 <- value (NO_ADVERTISE)
173 * FF FF FF 03 <- value (NO_EXPORT_SUBCONFED)
174 * FF FF FF 10 <- unknown Community
177 * 18 ac 11 02 <- IPv4 Prefix (172.17.2.0 / 24)
178 * 18 ac 11 01 <- IPv4 Prefix (172.17.1.0 / 24)
179 * 18 ac 11 00 <- IPv4 Prefix (172.17.0.0 / 24)
182 public void testGetUpdateMessage1() throws Exception {
184 final byte[] body = ByteArray.cutBytes(inputBytes.get(0), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
185 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(0), BGPMessageFactoryImpl.MARKER_LENGTH,
186 BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
187 final BGPUpdateEvent ret = BGPUpdateMessageParser.parse(body, messageLength);
189 assertTrue(ret instanceof BGPUpdateMessage);
190 final BGPUpdateMessage message = (BGPUpdateMessage) ret;
194 assertEquals(Collections.EMPTY_SET, message.getRemovedObjects());
198 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65002L)).build());
199 final List<AsPathSegment> asPath = Lists.newArrayList();
200 asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
202 final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
203 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build();
205 final Set<Community> comms = new HashSet<>();
206 comms.add(CommunityUtil.NO_EXPORT);
207 comms.add(CommunityUtil.NO_ADVERTISE);
208 comms.add(CommunityUtil.NO_EXPORT_SUBCONFED);
209 comms.add(CommunityUtil.create(0xFFFF, 0xFF10));
211 // check path attributes
213 // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
214 // true, false, false, BGPOrigin.IGP);
215 // assertEquals(originAttr, attrs.get(0));
217 // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
218 // true, false, false, asPath);
219 // assertEquals(asPathAttr, attrs.get(1));
221 // final PathAttribute nextHopAttr = new PathAttribute(TypeCode.NEXT_HOP, false,
222 // true, false, false, nextHop);
223 // assertEquals(nextHopAttr, attrs.get(2));
225 // final PathAttribute multiExitDisc = new PathAttribute(
226 // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
227 // assertEquals(multiExitDisc, attrs.get(3));
229 // final PathAttribute atomic = new PathAttribute(TypeCode.ATOMIC_AGGREGATE, false,
230 // true, true, false, null);
231 // assertEquals(atomic, attrs.get(4));
233 // final PathAttribute comm = new PathAttribute(TypeCode.COMMUNITIES, false,
234 // true, true, false, comms);
235 // assertEquals(comm, attrs.get(5));
239 // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1, pref2, pref3);
240 // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
242 final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
243 final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath, comms, Collections.<ExtendedCommunity> emptySet()), nextHop);
247 final Set<BGPObject> addedObjects = Sets.newHashSet();
249 final BGPRoute route1 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.2.0/24"), state, routeState);
251 addedObjects.add(route1);
253 final BGPRoute route2 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.1.0/24"), state, routeState);
255 addedObjects.add(route2);
257 final BGPRoute route3 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.0.0/24"), state, routeState);
259 addedObjects.add(route3);
263 * Tests IPv6 NEXT_HOP, NLRI, ORIGIN.IGP, MULTI_EXIT_DISC, ORIGINATOR-ID, CLUSTER_LIST.
265 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
266 * 00 80 <- length (128) - including header
268 * 00 00 <- withdrawn routes length
269 * 00 69 <- total path attribute length (105)
270 * 40 <- attribute flags
271 * 01 <- attribute type code (origin)
272 * 01 <- attribute length
273 * 00 <- Origin value (IGP)
274 * 40 <- attribute flags
275 * 02 <- attribute type code (as path)
276 * 06 <- attribute length
278 * 01 <- path segment count
279 * 00 00 fd e9 <- path segment value (65001)
280 * 80 <- attribute flags
281 * 04 <- attribute type code (multi exit disc)
282 * 04 <- attribute length
283 * 00 00 00 00 <- value
284 * 80 <- attribute flags
285 * 09 <- attribute type code (originator id)
286 * 04 <- attribute length
287 * 7f 00 00 01 <- value (localhost ip)
288 * 80 <- attribute flags
289 * 0a <- attribute type code (cluster list)
290 * 08 <- attribute length
291 * 01 02 03 04 <- value
292 * 05 06 07 08 <- value
293 * 80 <- attribute flags
294 * 0e <- attribute type code (mp reach nlri)
295 * 40 <- attribute length
296 * 00 02 <- AFI (Ipv6)
297 * 01 <- SAFI (Unicast)
298 * 20 <- length of next hop
299 * 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 01 <- global
300 * fe 80 00 00 00 00 00 00 c0 01 0b ff fe 7e 00 <- link local
304 * 40 20 01 0d b8 00 01 00 02 <- IPv6 Prefix (2001:db8:1:2:: / 64)
305 * 40 20 01 0d b8 00 01 00 01 <- IPv6 Prefix (2001:db8:1:1:: / 64)
306 * 40 20 01 0d b8 00 01 00 00 <- IPv6 Prefix (2001:db8:1:: / 64)
310 public void testGetUpdateMessage2() throws Exception {
311 final byte[] body = ByteArray.cutBytes(inputBytes.get(1), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
312 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(1), BGPMessageFactoryImpl.MARKER_LENGTH,
313 BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
314 final BGPUpdateEvent ret = BGPUpdateMessageParser.parse(body, messageLength);
316 assertTrue(ret instanceof BGPUpdateMessage);
317 final BGPUpdateMessage message = (BGPUpdateMessage) ret;
321 assertEquals(Collections.EMPTY_SET, message.getRemovedObjects());
324 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65001L)).build());
325 final List<AsPathSegment> asPath = Lists.newArrayList();
326 asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
328 final CIpv6NextHop nextHop = new CIpv6NextHopBuilder().setIpv6NextHop(
329 new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
331 // final List<ClusterIdentifier> clusters = Lists.newArrayList(
332 // new ClusterIdentifier(new byte[] { 1, 2, 3, 4}),
333 // new ClusterIdentifier(new byte[] { 5, 6, 7, 8}));
335 // check path attributes
337 // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
338 // true, false, false, BGPOrigin.IGP);
339 // assertEquals(originAttr, attrs.get(0));
341 // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
342 // true, false, false, asPath);
343 // assertEquals(asPathAttr, attrs.get(1));
345 // final PathAttribute multiExitDisc = new PathAttribute(
346 // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
347 // assertEquals(multiExitDisc, attrs.get(2));
349 // final PathAttribute originatorAttr = new PathAttribute(
350 // TypeCode.ORIGINATOR_ID, true, false, false, false, IPv4.FAMILY.addressForString("127.0.0.1"));
351 // assertEquals(originatorAttr, attrs.get(3));
353 // final PathAttribute clusterAttr = new PathAttribute(
354 // TypeCode.CLUSTER_LIST, true, false, false, false, clusters);
355 // assertEquals(clusterAttr, attrs.get(4));
357 final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
358 final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath, Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet()), nextHop);
362 final Set<BGPObject> addedObjects = Sets.newHashSet();
364 final BGPRoute route1 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1:2::/64"), state, routeState);
366 addedObjects.add(route1);
368 final BGPRoute route2 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1:1::/64"), state, routeState);
370 addedObjects.add(route2);
372 final BGPRoute route3 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1::/64"), state, routeState);
374 addedObjects.add(route3);
378 * Tests more AS Numbers in AS_PATH, AGGREGATOR, ORIGIN.INCOMPLETE
380 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
381 * 00 4b <- length (75) - including header
383 * 00 00 <- withdrawn routes length
384 * 00 30 <- total path attribute length (48)
385 * 40 <- attribute flags
386 * 01 <- attribute type code (origin)
387 * 01 <- attribute length
388 * 02 <- Origin value (Incomplete)
389 * 40 <- attribute flags
390 * 02 <- attribute type code (as path)
391 * 10 <- attribute length
393 * 01 <- path segment count
394 * 00 00 00 1e <- path segment value (30)
396 * 02 <- path segment count
397 * 00 00 00 0a <- path segment value (10)
398 * 00 00 00 14 <- path segment value (20)
399 * 40 <- attribute flags
400 * 03 <- attribute type (Next hop)
401 * 04 <- attribute length
402 * 0a 00 00 09 <- value (10.0.0.9)
403 * 80 <- attribute flags
404 * 04 <- attribute type code (multi exit disc)
405 * 04 <- attribute length
406 * 00 00 00 00 <- value
407 * c0 <- attribute flags
408 * 07 <- attribute type (Aggregator)
409 * 08 <- attribute length
410 * 00 00 00 1e <- value (AS number = 30)
411 * 0a 00 00 09 <- value (IP address = 10.0.0.9)
414 * 15 ac 10 00 <- IPv4 Prefix (172.16.0.0 / 21)
417 public void testGetUpdateMessage3() throws Exception {
418 final byte[] body = ByteArray.cutBytes(inputBytes.get(2), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
419 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(2), BGPMessageFactoryImpl.MARKER_LENGTH,
420 BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
421 final BGPUpdateEvent ret = BGPUpdateMessageParser.parse(body, messageLength);
422 assertTrue(ret instanceof BGPUpdateMessage);
423 final BGPUpdateMessage message = (BGPUpdateMessage) ret;
426 assertEquals(Collections.EMPTY_SET, message.getRemovedObjects());
430 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(30L)).build());
431 final List<AsPathSegment> asPath = Lists.newArrayList();
432 asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
433 asPath.add(new SegmentsBuilder().setCSegment(
434 new CASetBuilder().setAsSet(Lists.newArrayList(new AsNumber(10L), new AsNumber(20L))).build()).build());
436 final BgpAggregator aggregator = new AggregatorBuilder().setAsNumber(new AsNumber((long) 30)).setNetworkAddress(
437 new Ipv4Address("10.0.0.9")).build();
438 final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
439 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.9")).build()).build();
441 final IPv4Prefix pref1 = IPv4.FAMILY.prefixForString("172.16.0.0/21");
443 // check path attributes
445 // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
446 // true, false, false, BGPOrigin.INCOMPLETE);
447 // assertEquals(originAttr, attrs.get(0));
449 // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
450 // true, false, false, asPath);
451 // assertEquals(asPathAttr, attrs.get(1));
453 // final PathAttribute nextHopAttr = new PathAttribute(TypeCode.NEXT_HOP, false,
454 // true, false, false, nextHop);
455 // assertEquals(nextHopAttr, attrs.get(2));
457 // final PathAttribute multiExitDisc = new PathAttribute(
458 // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
459 // assertEquals(multiExitDisc, attrs.get(3));
461 // final PathAttribute agg = new PathAttribute(TypeCode.AGGREGATOR, true, true,
462 // false, false, aggregator);
463 // assertEquals(agg, attrs.get(4));
467 // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1);
468 // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
470 final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Incomplete, aggregator);
471 final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath, Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet()), nextHop);
475 final Set<BGPObject> addedObjects = Sets.newHashSet();
477 final BGPRoute route1 = new BGPIPv4RouteImpl(pref1, state, routeState);
479 addedObjects.add(route1);
483 * Tests empty AS_PATH, ORIGIN.EGP, LOCAL_PREF, EXTENDED_COMMUNITIES (Ipv4 Addr specific)
485 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
486 * 00 4A <- length (73) - including header
488 * 00 00 <- withdrawn routes length
489 * 00 27 <- total path attribute length (39)
490 * 40 <- attribute flags
491 * 01 <- attribute type code (Origin)
492 * 01 <- attribute length
493 * 01 <- Origin value (EGP)
494 * 40 <- attribute flags
495 * 02 <- attribute type code (As path)
496 * 00 <- attribute length
497 * 40 <- attribute flags
498 * 03 <- attribute type (Next hop)
499 * 04 <- attribute length
500 * 03 03 03 03 <- value (3.3.3.3)
501 * 80 <- attribute flags
502 * 04 <- attribute type code (Multi exit disc)
503 * 04 <- attribute length
504 * 00 00 00 00 <- value
505 * 40 <- attribute flags
506 * 05 <- attribute type (Local Pref)
507 * 04 <- attribute length
508 * 00 00 00 64 <- value (100)
509 * 80 <- attribute flags
510 * 10 <- attribute type (extended community)
511 * 08 <- attribute length
512 * 01 04 <- value (type - Ipv4 Address Specific Extended Community)
513 * c0 a8 01 00 <- value (global adm. 198.162.1.0)
514 * 12 34 <- value (local adm. 4660)
517 * 18 0a 1e 03 <- IPv4 Prefix (10.30.3.0 / 24)
518 * 18 0a 1e 02 <- IPv4 Prefix (10.30.2.0 / 24)
519 * 18 0a 1e 01 <- IPv4 Prefix (10.30.1.0 / 24)
522 public void testGetUpdateMessage4() throws Exception {
523 final byte[] body = ByteArray.cutBytes(inputBytes.get(3), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
524 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(3), BGPMessageFactoryImpl.MARKER_LENGTH,
525 BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
526 final BGPUpdateEvent ret = BGPUpdateMessageParser.parse(body, messageLength);
528 assertTrue(ret instanceof BGPUpdateMessage);
529 final BGPUpdateMessage message = (BGPUpdateMessage) ret;
533 assertEquals(Collections.EMPTY_SET, message.getRemovedObjects());
537 final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
538 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("3.3.3.3")).build()).build();
540 final Set<ExtendedCommunity> comms = Sets.newHashSet();
541 comms.add(new CInet4SpecificExtendedCommunityBuilder().setInet4SpecificExtendedCommunity(
542 new Inet4SpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(new Ipv4Address("192.168.1.0")).setLocalAdministrator(
543 new byte[] { 0x12, 0x34 }).build()).build());
545 // check path attributes
547 // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
548 // true, false, false, BGPOrigin.EGP);
549 // assertEquals(originAttr, attrs.get(0));
551 // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
552 // true, false, false, asPath);
553 // assertEquals(asPathAttr, attrs.get(1));
555 // final PathAttribute nextHopAttr = new PathAttribute(TypeCode.NEXT_HOP, false,
556 // true, false, false, nextHop);
557 // assertEquals(nextHopAttr, attrs.get(2));
559 // final PathAttribute multiExitDisc = new PathAttribute(
560 // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
561 // assertEquals(multiExitDisc, attrs.get(3));
563 // final PathAttribute localPref = new PathAttribute(TypeCode.LOCAL_PREF, false,
564 // true, false, false, 100);
565 // assertEquals(localPref, attrs.get(4));
569 // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1, pref2, pref3);
570 // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
572 final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Egp, null);
573 final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(Collections.<AsPathSegment> emptyList(), Collections.<Community> emptySet(), comms), nextHop);
577 final Set<BGPObject> addedObjects = Sets.newHashSet();
579 final BGPRoute route1 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.3.0/24"), state, routeState);
581 addedObjects.add(route1);
583 final BGPRoute route2 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.2.0/24"), state, routeState);
585 addedObjects.add(route2);
587 final BGPRoute route3 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.1.0/24"), state, routeState);
589 addedObjects.add(route3);
593 * Tests withdrawn routes.
595 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
596 * 00 1c <- length (28) - including header
598 * 00 05 <- withdrawn routes length (5)
599 * 1e ac 10 00 04 <- route (172.16.0.4)
600 * 00 00 <- total path attribute length
603 public void testGetUpdateMessage5() throws Exception {
604 final byte[] body = ByteArray.cutBytes(inputBytes.get(4), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
605 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(4), BGPMessageFactoryImpl.MARKER_LENGTH,
606 BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
607 final BGPUpdateEvent ret = BGPUpdateMessageParser.parse(body, messageLength);
609 assertTrue(ret instanceof BGPUpdateMessage);
610 final BGPUpdateMessage message = (BGPUpdateMessage) ret;
614 final IPv4Prefix pref1 = IPv4.FAMILY.prefixForString("172.16.0.4/30");
618 final BGPUpdateEvent expectedMessage = new BGPUpdateMessageImpl(Collections.<BGPObject> emptySet(), Sets.newHashSet((Identifier) pref1));
620 assertEquals(expectedMessage, message);
626 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
627 * 00 17 <- length (23) - including header
629 * 00 00 <- withdrawn routes length
630 * 00 00 <- total path attribute length
633 public void testEORIpv4() throws Exception {
634 final byte[] body = ByteArray.cutBytes(inputBytes.get(5), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
635 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(5), BGPMessageFactoryImpl.MARKER_LENGTH,
636 BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
637 final BGPUpdateEvent ret = BGPUpdateMessageParser.parse(body, messageLength);
639 assertTrue(ret instanceof BGPUpdateSynchronized);
640 final BGPUpdateSynchronized message = (BGPUpdateSynchronized) ret;
642 final BGPUpdateSynchronized expectedMessage = new BGPUpdateSynchronized() {
644 public BGPTableType getTableType() {
645 return new BGPTableType(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
648 assertEquals(expectedMessage.getTableType(), message.getTableType());
652 * End of Rib for Ipv6 consists of empty MP_UNREACH_NLRI, with AFI 2 and SAFI 1
654 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
655 * 00 1d <- length (29) - including header
657 * 00 00 <- withdrawn routes length
658 * 00 06 <- total path attribute length
659 * 80 <- attribute flags
660 * 0f <- attribute type (15 - MP_UNREACH_NLRI)
661 * 03 <- attribute length
662 * 00 02 <- value (AFI 2: IPv6)
663 * 01 <- value (SAFI 1)
666 public void testEORIpv6() throws Exception {
667 final byte[] body = ByteArray.cutBytes(inputBytes.get(6), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
668 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(6), BGPMessageFactoryImpl.MARKER_LENGTH,
669 BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
670 final BGPUpdateEvent ret = BGPUpdateMessageParser.parse(body, messageLength);
672 assertTrue(ret instanceof BGPUpdateSynchronized);
673 final BGPUpdateSynchronized message = (BGPUpdateSynchronized) ret;
677 final BGPUpdateSynchronized expectedMessage = new BGPUpdateSynchronized() {
679 public BGPTableType getTableType() {
680 return new BGPTableType(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class);
683 assertEquals(expectedMessage.getTableType(), message.getTableType());
687 * End of Rib for LS consists of empty MP_UNREACH_NLRI, with AFI 16388 and SAFI 71
689 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
690 * 00 1d <- length (29) - including header
692 * 00 00 <- withdrawn routes length
693 * 00 06 <- total path attribute length
694 * 80 <- attribute flags
695 * 0f <- attribute type (15 - MP_UNREACH_NLRI)
696 * 03 <- attribute length
697 * 40 04 <- value (AFI 16388: LS)
698 * 47 <- value (SAFI 71)
701 public void testEORLS() throws Exception {
702 final byte[] body = ByteArray.cutBytes(inputBytes.get(7), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
703 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(7), BGPMessageFactoryImpl.MARKER_LENGTH,
704 BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
705 final BGPUpdateEvent ret = BGPUpdateMessageParser.parse(body, messageLength);
707 assertTrue(ret instanceof BGPUpdateSynchronized);
708 final BGPUpdateSynchronized message = (BGPUpdateSynchronized) ret;
712 final BGPUpdateSynchronized expectedMessage = new BGPUpdateSynchronized() {
714 public BGPTableType getTableType() {
715 return new BGPTableType(LinkstateAddressFamily.class, UnicastSubsequentAddressFamily.class);
719 assertEquals(expectedMessage.getTableType(), message.getTableType());
723 * Tests BGP Link Ipv4
725 00 00 <- withdrawn routes length
726 01 48 <- total path attribute length (328)
727 90 <- attribute flags
728 0e <- attribute type code (MP reach)
729 01 2c <- attribute extended length (300)
730 40 04 <- AFI (16388 - Linkstate)
731 47 <- SAFI (71 - Linkstate)
732 04 <- next hop length
733 19 19 19 01 <- nexthop (25.25.25.1)
736 00 02 <- NLRI type (2 - linkNLRI)
737 00 5d <- NLRI length (93)
738 03 <- ProtocolID - OSPF
739 00 00 00 00 00 00 00 01 <- identifier
741 01 00 <- local node descriptor type (256)
743 02 00 <- node descriptor type (member AS - 512)
745 00 00 00 64 <- value (100)
746 02 01 <- node descriptor type (bgpId - 513)
748 19 19 19 01 <- bgpId (25.25.25.1)
749 02 02 <- node descriptor type (areaId - 514)
752 02 03 <- node descriptor type (routeId - 515)
754 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
756 01 01 <- remote node descriptor type (257)
758 02 00 <- node descriptor type (member AS - 512)
760 00 00 00 64 <- value (100)
761 02 01 <- node descriptor type (bgpId - 513)
763 19 19 19 01 <- bgpId (25.25.25.1)
764 02 02 <- node descriptor type (areaId - 514)
767 02 03 <- node descriptor type (routeId - 515)
769 03 03 03 04 <- OSPF Router Id
771 01 03 <- link descriptor type (IPv4 interface address - 259)
773 0b 0b 0b 03 <- value (11.11.11.3)
775 00 02 <- NLRI type (2 - linkNLRI)
776 00 5d <- NLRI length (93)
777 03 <- ProtocolID - OSPF
778 00 00 00 00 00 00 00 01 <- identifier
780 01 00 <- local node descriptor type (256)
782 02 00 <- node descriptor type (member AS - 512)
784 00 00 00 64 <- value (100)
785 02 01 <- node descriptor type (bgpId - 513)
787 19 19 19 01 <- bgpId (25.25.25.1)
788 02 02 <- node descriptor type (areaId - 514)
791 02 03 <- node descriptor type (routeId - 515)
793 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
795 01 01 <- remote node descriptor type (257)
797 02 00 <- node descriptor type (member AS - 512)
799 00 00 00 64 <- value (100)
800 02 01 <- node descriptor type (bgpId - 513)
802 19 19 19 01 <- bgpId (25.25.25.1)
803 02 02 <- node descriptor type (areaId - 514)
806 02 03 <- node descriptor type (routeId - 515)
808 01 01 01 02 <- OSPF Router Id
810 01 03 <- link descriptor type (IPv4 interface address - 259)
812 0b 0b 0b 01 <- value (11.11.11.1)
814 00 02 <- NLRI type (2 - linkNLRI)
815 00 5d <- NLRI length (93)
816 03 <- ProtocolID - OSPF
817 00 00 00 00 00 00 00 01 <- identifier
819 01 00 <- local node descriptor type (256)
821 02 00 <- node descriptor type (member AS - 512)
823 00 00 00 64 <- value (100)
824 02 01 <- node descriptor type (bgpId - 513)
826 19 19 19 01 <- bgpId (25.25.25.1)
827 02 02 <- node descriptor type (areaId - 514)
830 02 03 <- node descriptor type (routeId - 515)
832 01 01 01 02 <- OSPF Router Id
834 01 01 <- remote node descriptor type (257)
836 02 00 <- node descriptor type (member AS - 512)
838 00 00 00 64 <- value (100)
839 02 01 <- node descriptor type (bgpId - 513)
841 19 19 19 01 <- bgpId (25.25.25.1)
842 02 02 <- node descriptor type (areaId - 514)
845 02 03 <- node descriptor type (routeId - 515)
847 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
849 01 03 <- link descriptor type (IPv4 interface address - 259)
851 0b 0b 0b 01 <- value (11.11.11.1)
853 40 <- attribute flags
854 01 <- attribute type (Origin)
855 01 <- attribute length
857 40 <- attribute flags
858 02 <- attribute type (AS Path)
860 40 <- attribute flags
861 05 <- attribute type (local pref)
864 c0 <- attribute flags
865 63 <- attribute type (Link STATE - 99)
867 04 47 <- link attribute (1095 - Metric)
872 public void testBGPLink() throws Exception {
873 final byte[] body = ByteArray.cutBytes(inputBytes.get(8), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
874 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(8), BGPMessageFactoryImpl.MARKER_LENGTH,
875 BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
876 final BGPUpdateEvent ret = BGPUpdateMessageParser.parse(body, messageLength);
878 assertTrue(ret instanceof BGPUpdateMessage);
879 final BGPUpdateMessage message = (BGPUpdateMessage) ret;
883 assertEquals(Collections.EMPTY_SET, message.getRemovedObjects());
885 // network object state
886 final NetworkObjectState objState = new NetworkObjectState(Collections.<AsPathSegment> emptyList(), Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
887 final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
889 // network link state
890 final DefaultingTypesafeContainer<Metric<?>> container = new DefaultingTypesafeContainer<Metric<?>>();
891 container.setDefaultEntry(new IGPMetric(1));
892 final NetworkLinkState linkState = new NetworkLinkState(objState, container, null, LinkProtectionType.UNPROTECTED, null, null, null);
894 final NodeIdentifierFactory f100 = new NodeIdentifierFactory(new AsNumber((long) 100), new DomainIdentifier(new byte[] { 25, 25,
895 25, 1 }), new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
897 final NodeIdentifier nodeid1 = f100.identifierForRouter(new OSPFv3LANIdentifier(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }), new OSPFInterfaceIdentifier(new byte[] {
898 0x0b, 0x0b, 0x0b, 0x03 })));
899 final NodeIdentifier nodeid2 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }));
901 final NodeIdentifier nodeid3 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 1, 1, 1, 2 }));
905 final LinkIdentifier linkId1 = new LinkIdentifier(null, new LinkAnchor(nodeid1, new IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.3"))), new LinkAnchor(nodeid2, null));
906 final LinkIdentifier linkId2 = new LinkIdentifier(null, new LinkAnchor(nodeid1, new IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.1"))), new LinkAnchor(nodeid3, null));
907 final LinkIdentifier linkId3 = new LinkIdentifier(null, new LinkAnchor(nodeid3, new IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.1"))), new LinkAnchor(nodeid1, null));
909 final BGPLink link1 = new BGPLinkImpl(state, linkId1, linkState);
910 final BGPLink link2 = new BGPLinkImpl(state, linkId2, linkState);
911 final BGPLink link3 = new BGPLinkImpl(state, linkId3, linkState);
913 final BGPUpdateMessage expectedMessage = new BGPUpdateMessageImpl(Sets.newHashSet((BGPObject) link1, (BGPObject) link2,
914 (BGPObject) link3), Collections.<Identifier> emptySet());
916 assertEquals(expectedMessage, message);
922 * 00 00 <- withdrawn routes length
923 00 b2 <- total path attribute length (178)
924 90 <- attribute flags
925 0e <- attribute type code (MP reach)
926 00 a0 <- attribute extended length (160)
927 40 04 <- AFI (16388 - Linkstate)
928 47 <- SAFI (71 - Linkstate)
929 04 <- next hop length
930 19 19 19 01 - nexthop (25.25.25.1)
932 00 01 <- NLRI type (1 - nodeNLRI)
933 00 31 <- NLRI length (49)
934 03 <- ProtocolID - OSPF
935 00 00 00 00 00 00 00 01 <- identifier
937 01 00 <- local node descriptor type (256)
939 02 00 <- node descriptor type (member AS - 512)
941 00 00 00 64 <- value (100)
942 02 01 <- node descriptor type (bgpId - 513)
944 19 19 19 01 <- bgpId (25.25.25.1)
945 02 02 <- node descriptor type (areaId - 514)
948 02 03 <- node descriptor type (routeId - 515)
950 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
952 00 01 <- NLRI type (1 - nodeNLRI)
953 00 2d <- NLRI length (45)
954 03 <- ProtocolID - OSPF
955 00 00 00 00 00 00 00 01 <- identifier
957 01 00 <- local node descriptor type (256)
959 02 00 <- node descriptor type (member AS - 512)
961 00 00 00 64 <- value (100)
962 02 01 <- node descriptor type (bgpId - 513)
964 19 19 19 01 <- bgpId (25.25.25.1)
965 02 02 <- node descriptor type (areaId - 514)
968 02 03 <- node descriptor type (routeId - 515)
970 03 03 03 04 <- OSPF Router Id
972 00 01 <- NLRI type (1 - nodeNLRI)
973 00 2d <- NLRI length (45)
974 03 <- ProtocolID - OSPF
975 00 00 00 00 00 00 00 01 <- identifier
976 01 00 <- local node descriptor type (256)
978 02 00 <- node descriptor type (member AS - 512)
980 00 00 00 64 <- value (100)
981 02 01 <- node descriptor type (bgpId - 513)
983 19 19 19 01 <- bgpId (25.25.25.1)
984 02 02 <- node descriptor type (areaId - 514)
987 02 03 <- node descriptor type (routeId - 515)
989 01 01 01 02 <- OSPF Router Id
991 40 <- attribute flags
992 01 <- attribute type (Origin)
993 01 <- attribute length
995 40 <- attribute flags
996 02 <- attribute type (AS Path)
998 40 <- attribute flags
999 05 <- attribute type (local pref)
1001 00 00 00 64 <- value
1004 public void testBGPNode() throws Exception {
1005 final byte[] body = ByteArray.cutBytes(inputBytes.get(9), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
1006 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(9), BGPMessageFactoryImpl.MARKER_LENGTH,
1007 BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
1008 final BGPUpdateEvent ret = BGPUpdateMessageParser.parse(body, messageLength);
1010 assertTrue(ret instanceof BGPUpdateMessage);
1011 final BGPUpdateMessage message = (BGPUpdateMessage) ret;
1015 assertEquals(Collections.EMPTY_SET, message.getRemovedObjects());
1017 // network object state
1018 final NetworkObjectState objState = new NetworkObjectState(Collections.<AsPathSegment> emptyList(), Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
1019 final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
1020 final NetworkNodeState nstate = new NetworkNodeState(objState, Collections.<TopologyIdentifier> emptySet(), Collections.<ISISAreaIdentifier> emptySet(), false, false, false, false, Collections.<RouterIdentifier> emptySet(), null);
1022 // network link state
1024 final NodeIdentifierFactory f100 = new NodeIdentifierFactory(new AsNumber((long) 100), new DomainIdentifier(new byte[] { 25, 25,
1025 25, 1 }), new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
1027 final NodeIdentifier nodeid1 = f100.identifierForRouter(new OSPFv3LANIdentifier(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }), new OSPFInterfaceIdentifier(new byte[] {
1028 0x0b, 0x0b, 0x0b, 0x03 })));
1029 final NodeIdentifier nodeid2 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }));
1031 final NodeIdentifier nodeid3 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 1, 1, 1, 2 }));
1033 // check API message
1035 final BGPNode node1 = new BGPNodeImpl(state, nodeid1, nstate);
1036 final BGPNode node2 = new BGPNodeImpl(state, nodeid2, nstate);
1037 final BGPNode node3 = new BGPNodeImpl(state, nodeid3, nstate);
1039 final BGPUpdateMessage expectedMessage = new BGPUpdateMessageImpl(Sets.newHashSet((BGPObject) node1, (BGPObject) node2,
1040 (BGPObject) node3), Collections.<Identifier> emptySet());
1042 assertEquals(expectedMessage, message);
1046 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
1047 * 00 98 <- length (69) - including header
1048 * 01 <- message type
1050 * 00 64 <- My AS Number (AS TRANS in this case)
1051 * 00 b4 <- Hold Time
1052 * 00 00 00 00 <- BGP Identifier
1053 * 28 <- Optional Parameters Length
1054 * 02 <- opt. param. type (capabilities)
1056 * 01 <- capability code (MP Extensions for BGP4)
1058 * 00 01 00 01 <- AFI 1, SAFI 1
1059 * 02 <- opt. param. type (capabilities)
1061 * 01 <- capability code (MP Extensions for BGP4)
1063 * 00 02 00 01 <- AFI 2, SAFI 1
1064 * 02 <- opt. param. type (capabilities)
1066 * 01 <- capability code (MP Extensions for BGP4)
1068 * 40 04 00 47 <- AFI 16388, SAFI 71
1069 * 02 <- opt. param. type (capabilities)
1071 * 80 <- capability code (private)
1073 * 02 <- opt. param. type (capabilities)
1075 * 02 <- capability code (Route refresh)
1077 * 02 <- opt. param. type (capabilities)
1079 * 41 <- capability code (AS4 octet support)
1081 * 00 00 00 64 <- AS number
1084 public void testOpenMessage() throws Exception {
1085 final BGPMessageFactoryImpl msgFactory = new BGPMessageFactoryImpl();
1086 final BGPOpenMessage open = (BGPOpenMessage) msgFactory.parse(inputBytes.get(13)).get(0);
1087 final Set<BGPTableType> types = Sets.newHashSet();
1088 for (final BGPParameter param : open.getOptParams()) {
1089 if (param instanceof MultiprotocolCapability) {
1090 types.add(((MultiprotocolCapability) param).getTableType());
1093 final Set<BGPTableType> expected = Sets.newHashSet(new BGPTableType(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class),
1094 new BGPTableType(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class),
1095 new BGPTableType(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
1096 assertEquals(expected, types);
1100 public void testHashCodeEquals() throws UnknownHostException {
1101 final PathAttribute localPref1 = new PathAttribute(TypeCode.LOCAL_PREF, false, true, false, false, 100);
1103 final PathAttribute localPref2 = new PathAttribute(TypeCode.LOCAL_PREF, false, true, false, false, 100);
1105 assertEquals(localPref1, localPref2);
1106 assertEquals("HashCodes should be equal", localPref1.hashCode(), localPref2.hashCode());
1107 assertEquals("toString should be equal", localPref1.toString(), localPref2.toString());