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.util.ArrayList;
18 import java.util.Collections;
19 import java.util.HashSet;
20 import java.util.List;
23 import org.junit.BeforeClass;
24 import org.junit.Ignore;
25 import org.junit.Test;
26 import org.opendaylight.protocol.bgp.concepts.BGPObject;
27 import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
28 import org.opendaylight.protocol.bgp.linkstate.AreaIdentifier;
29 import org.opendaylight.protocol.bgp.linkstate.DomainIdentifier;
30 import org.opendaylight.protocol.bgp.linkstate.IPv4InterfaceIdentifier;
31 import org.opendaylight.protocol.bgp.linkstate.ISISAreaIdentifier;
32 import org.opendaylight.protocol.bgp.linkstate.LinkAnchor;
33 import org.opendaylight.protocol.bgp.linkstate.LinkIdentifier;
34 import org.opendaylight.protocol.bgp.linkstate.LinkProtectionType;
35 import org.opendaylight.protocol.bgp.linkstate.NetworkLinkState;
36 import org.opendaylight.protocol.bgp.linkstate.NetworkNodeState;
37 import org.opendaylight.protocol.bgp.linkstate.NetworkObjectState;
38 import org.opendaylight.protocol.bgp.linkstate.NetworkRouteState;
39 import org.opendaylight.protocol.bgp.linkstate.NodeIdentifier;
40 import org.opendaylight.protocol.bgp.linkstate.NodeIdentifierFactory;
41 import org.opendaylight.protocol.bgp.linkstate.OSPFInterfaceIdentifier;
42 import org.opendaylight.protocol.bgp.linkstate.OSPFRouterIdentifier;
43 import org.opendaylight.protocol.bgp.linkstate.OSPFv3LANIdentifier;
44 import org.opendaylight.protocol.bgp.linkstate.RouterIdentifier;
45 import org.opendaylight.protocol.bgp.linkstate.TopologyIdentifier;
46 import org.opendaylight.protocol.bgp.parser.BGPLink;
47 import org.opendaylight.protocol.bgp.parser.BGPNode;
48 import org.opendaylight.protocol.bgp.parser.BGPRoute;
49 import org.opendaylight.protocol.bgp.parser.BGPTableType;
50 import org.opendaylight.protocol.bgp.parser.BGPUpdateEvent;
51 import org.opendaylight.protocol.bgp.parser.BGPUpdateMessage;
52 import org.opendaylight.protocol.bgp.parser.BGPUpdateSynchronized;
53 import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
54 import org.opendaylight.protocol.bgp.util.BGPIPv4RouteImpl;
55 import org.opendaylight.protocol.bgp.util.BGPIPv6RouteImpl;
56 import org.opendaylight.protocol.bgp.util.BGPLinkImpl;
57 import org.opendaylight.protocol.bgp.util.BGPNodeImpl;
58 import org.opendaylight.protocol.concepts.IGPMetric;
59 import org.opendaylight.protocol.concepts.IPv4;
60 import org.opendaylight.protocol.concepts.IPv4Prefix;
61 import org.opendaylight.protocol.concepts.IPv6;
62 import org.opendaylight.protocol.concepts.Identifier;
63 import org.opendaylight.protocol.concepts.Metric;
64 import org.opendaylight.protocol.util.ByteArray;
65 import org.opendaylight.protocol.util.DefaultingTypesafeContainer;
66 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
67 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
68 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Open;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Update;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.CParameters;
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.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocol;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AsPathSegment;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpAggregator;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.CAListBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.CASetBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequence;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequenceBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.CInet4SpecificExtendedCommunityBuilder;
91 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;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv4NextHop;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv4NextHopBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv6NextHop;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv6NextHopBuilder;
96 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;
97 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;
99 import com.google.common.collect.Lists;
100 import com.google.common.collect.Sets;
102 public class BGPParserTest {
105 * Used by other tests as well
107 static final List<byte[]> inputBytes = new ArrayList<byte[]>();
109 private static int COUNTER = 17;
111 private static int MAX_SIZE = 300;
114 public static void setUp() throws Exception {
116 for (int i = 1; i <= COUNTER; i++) {
117 final String name = "/up" + i + ".bin";
118 final InputStream is = BGPParserTest.class.getResourceAsStream(name);
120 throw new IOException("Failed to get resource " + name);
123 final ByteArrayOutputStream bis = new ByteArrayOutputStream();
124 final byte[] data = new byte[MAX_SIZE];
126 while ((nRead = is.read(data, 0, data.length)) != -1) {
127 bis.write(data, 0, nRead);
131 inputBytes.add(bis.toByteArray());
136 public void testResource() {
137 assertNotNull(inputBytes);
141 * Tests IPv4 NEXT_HOP, ATOMIC_AGGREGATE, COMMUNITY, NLRI
143 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
144 * 00 54 <- length (84) - including header
146 * 00 00 <- withdrawn routes length
147 * 00 31 <- total path attribute length (49)
148 * 40 <- attribute flags
149 * 01 <- attribute type code (origin)
150 * 01 <- attribute length
151 * 00 <- Origin value (IGP)
152 * 40 <- attribute flags
153 * 02 <- attribute type code (as path)
154 * 06 <- attribute length
156 * 01 <- path segment count
157 * 00 00 fd ea <- path segment value (65002)
158 * 40 <- attribute flags
159 * 03 <- attribute type code (Next Hop)
160 * 04 <- attribute length
161 * 10 00 00 02 <- value (10.0.0.2)
162 * 80 <- attribute flags
163 * 04 <- attribute type code (multi exit disc)
164 * 04 <- attribute length
165 * 00 00 00 00 <- value
166 * 64 <- attribute flags
167 * 06 <- attribute type code (atomic aggregate)
168 * 00 <- attribute length
169 * 64 <- attribute flags
170 * 08 <- attribute type code (community)
171 * 10 <- attribute length FF FF FF
172 * 01 <- value (NO_EXPORT)
173 * FF FF FF 02 <- value (NO_ADVERTISE)
174 * FF FF FF 03 <- value (NO_EXPORT_SUBCONFED)
175 * FF FF FF 10 <- unknown Community
178 * 18 ac 11 02 <- IPv4 Prefix (172.17.2.0 / 24)
179 * 18 ac 11 01 <- IPv4 Prefix (172.17.1.0 / 24)
180 * 18 ac 11 00 <- IPv4 Prefix (172.17.0.0 / 24)
184 // FIXME: to be fixed in testing phase
185 public void testGetUpdateMessage1() throws Exception {
187 final byte[] body = ByteArray.cutBytes(inputBytes.get(0), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
188 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(0), BGPMessageFactoryImpl.MARKER_LENGTH,
189 BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
190 final Update ret = BGPUpdateMessageParser.parse(body, messageLength);
192 assertTrue(ret instanceof BGPUpdateMessage);
193 final BGPUpdateMessage message = (BGPUpdateMessage) ret;
197 assertEquals(Collections.EMPTY_SET, message.getRemovedObjects());
201 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65002L)).build());
202 final List<AsPathSegment> asPath = Lists.newArrayList();
203 asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
205 final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
206 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build();
208 final Set<Community> comms = new HashSet<>();
209 comms.add(CommunityUtil.NO_EXPORT);
210 comms.add(CommunityUtil.NO_ADVERTISE);
211 comms.add(CommunityUtil.NO_EXPORT_SUBCONFED);
212 comms.add(CommunityUtil.create(0xFFFF, 0xFF10));
214 // check path attributes
216 // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
217 // true, false, false, BGPOrigin.IGP);
218 // assertEquals(originAttr, attrs.get(0));
220 // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
221 // true, false, false, asPath);
222 // assertEquals(asPathAttr, attrs.get(1));
224 // final PathAttribute nextHopAttr = new PathAttribute(TypeCode.NEXT_HOP, false,
225 // true, false, false, nextHop);
226 // assertEquals(nextHopAttr, attrs.get(2));
228 // final PathAttribute multiExitDisc = new PathAttribute(
229 // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
230 // assertEquals(multiExitDisc, attrs.get(3));
232 // final PathAttribute atomic = new PathAttribute(TypeCode.ATOMIC_AGGREGATE, false,
233 // true, true, false, null);
234 // assertEquals(atomic, attrs.get(4));
236 // final PathAttribute comm = new PathAttribute(TypeCode.COMMUNITIES, false,
237 // true, true, false, comms);
238 // assertEquals(comm, attrs.get(5));
242 // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1, pref2, pref3);
243 // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
245 final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
246 final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath, comms, Collections.<ExtendedCommunity> emptySet()), nextHop);
250 final Set<BGPObject> addedObjects = Sets.newHashSet();
252 final BGPRoute route1 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.2.0/24"), state, routeState);
254 addedObjects.add(route1);
256 final BGPRoute route2 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.1.0/24"), state, routeState);
258 addedObjects.add(route2);
260 final BGPRoute route3 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.0.0/24"), state, routeState);
262 addedObjects.add(route3);
266 * Tests IPv6 NEXT_HOP, NLRI, ORIGIN.IGP, MULTI_EXIT_DISC, ORIGINATOR-ID, CLUSTER_LIST.
268 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
269 * 00 80 <- length (128) - including header
271 * 00 00 <- withdrawn routes length
272 * 00 69 <- total path attribute length (105)
273 * 40 <- attribute flags
274 * 01 <- attribute type code (origin)
275 * 01 <- attribute length
276 * 00 <- Origin value (IGP)
277 * 40 <- attribute flags
278 * 02 <- attribute type code (as path)
279 * 06 <- attribute length
281 * 01 <- path segment count
282 * 00 00 fd e9 <- path segment value (65001)
283 * 80 <- attribute flags
284 * 04 <- attribute type code (multi exit disc)
285 * 04 <- attribute length
286 * 00 00 00 00 <- value
287 * 80 <- attribute flags
288 * 09 <- attribute type code (originator id)
289 * 04 <- attribute length
290 * 7f 00 00 01 <- value (localhost ip)
291 * 80 <- attribute flags
292 * 0a <- attribute type code (cluster list)
293 * 08 <- attribute length
294 * 01 02 03 04 <- value
295 * 05 06 07 08 <- value
296 * 80 <- attribute flags
297 * 0e <- attribute type code (mp reach nlri)
298 * 40 <- attribute length
299 * 00 02 <- AFI (Ipv6)
300 * 01 <- SAFI (Unicast)
301 * 20 <- length of next hop
302 * 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 01 <- global
303 * fe 80 00 00 00 00 00 00 c0 01 0b ff fe 7e 00 <- link local
307 * 40 20 01 0d b8 00 01 00 02 <- IPv6 Prefix (2001:db8:1:2:: / 64)
308 * 40 20 01 0d b8 00 01 00 01 <- IPv6 Prefix (2001:db8:1:1:: / 64)
309 * 40 20 01 0d b8 00 01 00 00 <- IPv6 Prefix (2001:db8:1:: / 64)
314 // FIXME: to be fixed in testing phase
315 public void testGetUpdateMessage2() throws Exception {
316 final byte[] body = ByteArray.cutBytes(inputBytes.get(1), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
317 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(1), BGPMessageFactoryImpl.MARKER_LENGTH,
318 BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
319 final Update ret = BGPUpdateMessageParser.parse(body, messageLength);
321 assertTrue(ret instanceof BGPUpdateMessage);
322 final BGPUpdateMessage message = (BGPUpdateMessage) ret;
326 assertEquals(Collections.EMPTY_SET, message.getRemovedObjects());
329 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65001L)).build());
330 final List<AsPathSegment> asPath = Lists.newArrayList();
331 asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
333 final CIpv6NextHop nextHop = new CIpv6NextHopBuilder().setIpv6NextHop(
334 new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
336 // final List<ClusterIdentifier> clusters = Lists.newArrayList(
337 // new ClusterIdentifier(new byte[] { 1, 2, 3, 4}),
338 // new ClusterIdentifier(new byte[] { 5, 6, 7, 8}));
340 // check path attributes
342 // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
343 // true, false, false, BGPOrigin.IGP);
344 // assertEquals(originAttr, attrs.get(0));
346 // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
347 // true, false, false, asPath);
348 // assertEquals(asPathAttr, attrs.get(1));
350 // final PathAttribute multiExitDisc = new PathAttribute(
351 // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
352 // assertEquals(multiExitDisc, attrs.get(2));
354 // final PathAttribute originatorAttr = new PathAttribute(
355 // TypeCode.ORIGINATOR_ID, true, false, false, false, IPv4.FAMILY.addressForString("127.0.0.1"));
356 // assertEquals(originatorAttr, attrs.get(3));
358 // final PathAttribute clusterAttr = new PathAttribute(
359 // TypeCode.CLUSTER_LIST, true, false, false, false, clusters);
360 // assertEquals(clusterAttr, attrs.get(4));
362 final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
363 final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath, Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet()), nextHop);
367 final Set<BGPObject> addedObjects = Sets.newHashSet();
369 final BGPRoute route1 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1:2::/64"), state, routeState);
371 addedObjects.add(route1);
373 final BGPRoute route2 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1:1::/64"), state, routeState);
375 addedObjects.add(route2);
377 final BGPRoute route3 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1::/64"), state, routeState);
379 addedObjects.add(route3);
383 * Tests more AS Numbers in AS_PATH, AGGREGATOR, ORIGIN.INCOMPLETE
385 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
386 * 00 4b <- length (75) - including header
388 * 00 00 <- withdrawn routes length
389 * 00 30 <- total path attribute length (48)
390 * 40 <- attribute flags
391 * 01 <- attribute type code (origin)
392 * 01 <- attribute length
393 * 02 <- Origin value (Incomplete)
394 * 40 <- attribute flags
395 * 02 <- attribute type code (as path)
396 * 10 <- attribute length
398 * 01 <- path segment count
399 * 00 00 00 1e <- path segment value (30)
401 * 02 <- path segment count
402 * 00 00 00 0a <- path segment value (10)
403 * 00 00 00 14 <- path segment value (20)
404 * 40 <- attribute flags
405 * 03 <- attribute type (Next hop)
406 * 04 <- attribute length
407 * 0a 00 00 09 <- value (10.0.0.9)
408 * 80 <- attribute flags
409 * 04 <- attribute type code (multi exit disc)
410 * 04 <- attribute length
411 * 00 00 00 00 <- value
412 * c0 <- attribute flags
413 * 07 <- attribute type (Aggregator)
414 * 08 <- attribute length
415 * 00 00 00 1e <- value (AS number = 30)
416 * 0a 00 00 09 <- value (IP address = 10.0.0.9)
419 * 15 ac 10 00 <- IPv4 Prefix (172.16.0.0 / 21)
423 // FIXME: to be fixed in testing phase
424 public void testGetUpdateMessage3() throws Exception {
425 final byte[] body = ByteArray.cutBytes(inputBytes.get(2), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
426 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(2), BGPMessageFactoryImpl.MARKER_LENGTH,
427 BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
428 final Update ret = BGPUpdateMessageParser.parse(body, messageLength);
429 assertTrue(ret instanceof BGPUpdateMessage);
430 final BGPUpdateMessage message = (BGPUpdateMessage) ret;
433 assertEquals(Collections.EMPTY_SET, message.getRemovedObjects());
437 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(30L)).build());
438 final List<AsPathSegment> asPath = Lists.newArrayList();
439 asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
440 asPath.add(new SegmentsBuilder().setCSegment(
441 new CASetBuilder().setAsSet(Lists.newArrayList(new AsNumber(10L), new AsNumber(20L))).build()).build());
443 final BgpAggregator aggregator = new AggregatorBuilder().setAsNumber(new AsNumber((long) 30)).setNetworkAddress(
444 new Ipv4Address("10.0.0.9")).build();
445 final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
446 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.9")).build()).build();
448 final IPv4Prefix pref1 = IPv4.FAMILY.prefixForString("172.16.0.0/21");
450 // check path attributes
452 // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
453 // true, false, false, BGPOrigin.INCOMPLETE);
454 // assertEquals(originAttr, attrs.get(0));
456 // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
457 // true, false, false, asPath);
458 // assertEquals(asPathAttr, attrs.get(1));
460 // final PathAttribute nextHopAttr = new PathAttribute(TypeCode.NEXT_HOP, false,
461 // true, false, false, nextHop);
462 // assertEquals(nextHopAttr, attrs.get(2));
464 // final PathAttribute multiExitDisc = new PathAttribute(
465 // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
466 // assertEquals(multiExitDisc, attrs.get(3));
468 // final PathAttribute agg = new PathAttribute(TypeCode.AGGREGATOR, true, true,
469 // false, false, aggregator);
470 // assertEquals(agg, attrs.get(4));
474 // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1);
475 // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
477 final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Incomplete, aggregator);
478 final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath, Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet()), nextHop);
482 final Set<BGPObject> addedObjects = Sets.newHashSet();
484 final BGPRoute route1 = new BGPIPv4RouteImpl(pref1, state, routeState);
486 addedObjects.add(route1);
490 * Tests empty AS_PATH, ORIGIN.EGP, LOCAL_PREF, EXTENDED_COMMUNITIES (Ipv4 Addr specific)
492 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
493 * 00 4A <- length (73) - including header
495 * 00 00 <- withdrawn routes length
496 * 00 27 <- total path attribute length (39)
497 * 40 <- attribute flags
498 * 01 <- attribute type code (Origin)
499 * 01 <- attribute length
500 * 01 <- Origin value (EGP)
501 * 40 <- attribute flags
502 * 02 <- attribute type code (As path)
503 * 00 <- attribute length
504 * 40 <- attribute flags
505 * 03 <- attribute type (Next hop)
506 * 04 <- attribute length
507 * 03 03 03 03 <- value (3.3.3.3)
508 * 80 <- attribute flags
509 * 04 <- attribute type code (Multi exit disc)
510 * 04 <- attribute length
511 * 00 00 00 00 <- value
512 * 40 <- attribute flags
513 * 05 <- attribute type (Local Pref)
514 * 04 <- attribute length
515 * 00 00 00 64 <- value (100)
516 * 80 <- attribute flags
517 * 10 <- attribute type (extended community)
518 * 08 <- attribute length
519 * 01 04 <- value (type - Ipv4 Address Specific Extended Community)
520 * c0 a8 01 00 <- value (global adm. 198.162.1.0)
521 * 12 34 <- value (local adm. 4660)
524 * 18 0a 1e 03 <- IPv4 Prefix (10.30.3.0 / 24)
525 * 18 0a 1e 02 <- IPv4 Prefix (10.30.2.0 / 24)
526 * 18 0a 1e 01 <- IPv4 Prefix (10.30.1.0 / 24)
530 // FIXME: to be fixed in testing phase
531 public void testGetUpdateMessage4() throws Exception {
532 final byte[] body = ByteArray.cutBytes(inputBytes.get(3), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
533 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(3), BGPMessageFactoryImpl.MARKER_LENGTH,
534 BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
535 final Update ret = BGPUpdateMessageParser.parse(body, messageLength);
537 assertTrue(ret instanceof BGPUpdateMessage);
538 final BGPUpdateMessage message = (BGPUpdateMessage) ret;
542 assertEquals(Collections.EMPTY_SET, message.getRemovedObjects());
546 final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
547 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("3.3.3.3")).build()).build();
549 final Set<ExtendedCommunity> comms = Sets.newHashSet();
550 comms.add(new CInet4SpecificExtendedCommunityBuilder().setInet4SpecificExtendedCommunity(
551 new Inet4SpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(new Ipv4Address("192.168.1.0")).setLocalAdministrator(
552 new byte[] { 0x12, 0x34 }).build()).build());
554 // check path attributes
556 // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
557 // true, false, false, BGPOrigin.EGP);
558 // assertEquals(originAttr, attrs.get(0));
560 // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
561 // true, false, false, asPath);
562 // assertEquals(asPathAttr, attrs.get(1));
564 // final PathAttribute nextHopAttr = new PathAttribute(TypeCode.NEXT_HOP, false,
565 // true, false, false, nextHop);
566 // assertEquals(nextHopAttr, attrs.get(2));
568 // final PathAttribute multiExitDisc = new PathAttribute(
569 // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
570 // assertEquals(multiExitDisc, attrs.get(3));
572 // final PathAttribute localPref = new PathAttribute(TypeCode.LOCAL_PREF, false,
573 // true, false, false, 100);
574 // assertEquals(localPref, attrs.get(4));
578 // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1, pref2, pref3);
579 // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
581 final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Egp, null);
582 final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(Collections.<AsPathSegment> emptyList(), Collections.<Community> emptySet(), comms), nextHop);
586 final Set<BGPObject> addedObjects = Sets.newHashSet();
588 final BGPRoute route1 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.3.0/24"), state, routeState);
590 addedObjects.add(route1);
592 final BGPRoute route2 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.2.0/24"), state, routeState);
594 addedObjects.add(route2);
596 final BGPRoute route3 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.1.0/24"), state, routeState);
598 addedObjects.add(route3);
602 * Tests withdrawn routes.
604 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
605 * 00 1c <- length (28) - including header
607 * 00 05 <- withdrawn routes length (5)
608 * 1e ac 10 00 04 <- route (172.16.0.4)
609 * 00 00 <- total path attribute length
613 // FIXME: to be fixed in testing phase
614 public void testGetUpdateMessage5() throws Exception {
615 final byte[] body = ByteArray.cutBytes(inputBytes.get(4), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
616 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(4), BGPMessageFactoryImpl.MARKER_LENGTH,
617 BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
618 final Update ret = BGPUpdateMessageParser.parse(body, messageLength);
620 assertTrue(ret instanceof BGPUpdateMessage);
621 final BGPUpdateMessage message = (BGPUpdateMessage) ret;
625 final IPv4Prefix pref1 = IPv4.FAMILY.prefixForString("172.16.0.4/30");
629 final BGPUpdateEvent expectedMessage = new BGPUpdateMessageImpl(Collections.<BGPObject> emptySet(), Sets.newHashSet((Identifier) pref1));
631 assertEquals(expectedMessage, message);
637 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
638 * 00 17 <- length (23) - including header
640 * 00 00 <- withdrawn routes length
641 * 00 00 <- total path attribute length
645 // FIXME: to be fixed in testing phase
646 public void testEORIpv4() throws Exception {
647 final byte[] body = ByteArray.cutBytes(inputBytes.get(5), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
648 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(5), BGPMessageFactoryImpl.MARKER_LENGTH,
649 BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
650 final Update ret = BGPUpdateMessageParser.parse(body, messageLength);
652 assertTrue(ret instanceof BGPUpdateSynchronized);
653 final BGPUpdateSynchronized message = (BGPUpdateSynchronized) ret;
655 final BGPUpdateSynchronized expectedMessage = new BGPUpdateSynchronized() {
657 public BGPTableType getTableType() {
658 return new BGPTableType(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
661 assertEquals(expectedMessage.getTableType(), message.getTableType());
665 * End of Rib for Ipv6 consists of empty MP_UNREACH_NLRI, with AFI 2 and SAFI 1
667 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
668 * 00 1d <- length (29) - including header
670 * 00 00 <- withdrawn routes length
671 * 00 06 <- total path attribute length
672 * 80 <- attribute flags
673 * 0f <- attribute type (15 - MP_UNREACH_NLRI)
674 * 03 <- attribute length
675 * 00 02 <- value (AFI 2: IPv6)
676 * 01 <- value (SAFI 1)
680 // FIXME: to be fixed in testing phase
681 public void testEORIpv6() throws Exception {
682 final byte[] body = ByteArray.cutBytes(inputBytes.get(6), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
683 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(6), BGPMessageFactoryImpl.MARKER_LENGTH,
684 BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
685 final Update ret = BGPUpdateMessageParser.parse(body, messageLength);
687 assertTrue(ret instanceof BGPUpdateSynchronized);
688 final BGPUpdateSynchronized message = (BGPUpdateSynchronized) ret;
692 final BGPUpdateSynchronized expectedMessage = new BGPUpdateSynchronized() {
694 public BGPTableType getTableType() {
695 return new BGPTableType(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class);
698 assertEquals(expectedMessage.getTableType(), message.getTableType());
702 * End of Rib for LS consists of empty MP_UNREACH_NLRI, with AFI 16388 and SAFI 71
704 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
705 * 00 1d <- length (29) - including header
707 * 00 00 <- withdrawn routes length
708 * 00 06 <- total path attribute length
709 * 80 <- attribute flags
710 * 0f <- attribute type (15 - MP_UNREACH_NLRI)
711 * 03 <- attribute length
712 * 40 04 <- value (AFI 16388: LS)
713 * 47 <- value (SAFI 71)
717 // FIXME: to be fixed in testing phase
718 public void testEORLS() throws Exception {
719 final byte[] body = ByteArray.cutBytes(inputBytes.get(7), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
720 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(7), BGPMessageFactoryImpl.MARKER_LENGTH,
721 BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
722 final Update ret = BGPUpdateMessageParser.parse(body, messageLength);
724 assertTrue(ret instanceof BGPUpdateSynchronized);
725 final BGPUpdateSynchronized message = (BGPUpdateSynchronized) ret;
729 final BGPUpdateSynchronized expectedMessage = new BGPUpdateSynchronized() {
731 public BGPTableType getTableType() {
732 return new BGPTableType(LinkstateAddressFamily.class, UnicastSubsequentAddressFamily.class);
736 assertEquals(expectedMessage.getTableType(), message.getTableType());
740 * Tests BGP Link Ipv4
742 00 00 <- withdrawn routes length
743 01 48 <- total path attribute length (328)
744 90 <- attribute flags
745 0e <- attribute type code (MP reach)
746 01 2c <- attribute extended length (300)
747 40 04 <- AFI (16388 - Linkstate)
748 47 <- SAFI (71 - Linkstate)
749 04 <- next hop length
750 19 19 19 01 <- nexthop (25.25.25.1)
753 00 02 <- NLRI type (2 - linkNLRI)
754 00 5d <- NLRI length (93)
755 03 <- ProtocolID - OSPF
756 00 00 00 00 00 00 00 01 <- identifier
758 01 00 <- local node descriptor type (256)
760 02 00 <- node descriptor type (member AS - 512)
762 00 00 00 64 <- value (100)
763 02 01 <- node descriptor type (bgpId - 513)
765 19 19 19 01 <- bgpId (25.25.25.1)
766 02 02 <- node descriptor type (areaId - 514)
769 02 03 <- node descriptor type (routeId - 515)
771 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
773 01 01 <- remote node descriptor type (257)
775 02 00 <- node descriptor type (member AS - 512)
777 00 00 00 64 <- value (100)
778 02 01 <- node descriptor type (bgpId - 513)
780 19 19 19 01 <- bgpId (25.25.25.1)
781 02 02 <- node descriptor type (areaId - 514)
784 02 03 <- node descriptor type (routeId - 515)
786 03 03 03 04 <- OSPF Router Id
788 01 03 <- link descriptor type (IPv4 interface address - 259)
790 0b 0b 0b 03 <- value (11.11.11.3)
792 00 02 <- NLRI type (2 - linkNLRI)
793 00 5d <- NLRI length (93)
794 03 <- ProtocolID - OSPF
795 00 00 00 00 00 00 00 01 <- identifier
797 01 00 <- local node descriptor type (256)
799 02 00 <- node descriptor type (member AS - 512)
801 00 00 00 64 <- value (100)
802 02 01 <- node descriptor type (bgpId - 513)
804 19 19 19 01 <- bgpId (25.25.25.1)
805 02 02 <- node descriptor type (areaId - 514)
808 02 03 <- node descriptor type (routeId - 515)
810 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
812 01 01 <- remote node descriptor type (257)
814 02 00 <- node descriptor type (member AS - 512)
816 00 00 00 64 <- value (100)
817 02 01 <- node descriptor type (bgpId - 513)
819 19 19 19 01 <- bgpId (25.25.25.1)
820 02 02 <- node descriptor type (areaId - 514)
823 02 03 <- node descriptor type (routeId - 515)
825 01 01 01 02 <- OSPF Router Id
827 01 03 <- link descriptor type (IPv4 interface address - 259)
829 0b 0b 0b 01 <- value (11.11.11.1)
831 00 02 <- NLRI type (2 - linkNLRI)
832 00 5d <- NLRI length (93)
833 03 <- ProtocolID - OSPF
834 00 00 00 00 00 00 00 01 <- identifier
836 01 00 <- local node descriptor type (256)
838 02 00 <- node descriptor type (member AS - 512)
840 00 00 00 64 <- value (100)
841 02 01 <- node descriptor type (bgpId - 513)
843 19 19 19 01 <- bgpId (25.25.25.1)
844 02 02 <- node descriptor type (areaId - 514)
847 02 03 <- node descriptor type (routeId - 515)
849 01 01 01 02 <- OSPF Router Id
851 01 01 <- remote node descriptor type (257)
853 02 00 <- node descriptor type (member AS - 512)
855 00 00 00 64 <- value (100)
856 02 01 <- node descriptor type (bgpId - 513)
858 19 19 19 01 <- bgpId (25.25.25.1)
859 02 02 <- node descriptor type (areaId - 514)
862 02 03 <- node descriptor type (routeId - 515)
864 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
866 01 03 <- link descriptor type (IPv4 interface address - 259)
868 0b 0b 0b 01 <- value (11.11.11.1)
870 40 <- attribute flags
871 01 <- attribute type (Origin)
872 01 <- attribute length
874 40 <- attribute flags
875 02 <- attribute type (AS Path)
877 40 <- attribute flags
878 05 <- attribute type (local pref)
881 c0 <- attribute flags
882 63 <- attribute type (Link STATE - 99)
884 04 47 <- link attribute (1095 - Metric)
890 // FIXME: to be fixed in testing phase
891 public void testBGPLink() throws Exception {
892 final byte[] body = ByteArray.cutBytes(inputBytes.get(8), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
893 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(8), BGPMessageFactoryImpl.MARKER_LENGTH,
894 BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
895 final Update ret = BGPUpdateMessageParser.parse(body, messageLength);
897 assertTrue(ret instanceof BGPUpdateMessage);
898 final BGPUpdateMessage message = (BGPUpdateMessage) ret;
902 assertEquals(Collections.EMPTY_SET, message.getRemovedObjects());
904 // network object state
905 final NetworkObjectState objState = new NetworkObjectState(Collections.<AsPathSegment> emptyList(), Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
906 final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
908 // network link state
909 final DefaultingTypesafeContainer<Metric<?>> container = new DefaultingTypesafeContainer<Metric<?>>();
910 container.setDefaultEntry(new IGPMetric(1));
911 final NetworkLinkState linkState = new NetworkLinkState(objState, container, null, LinkProtectionType.UNPROTECTED, null, null, null);
913 final NodeIdentifierFactory f100 = new NodeIdentifierFactory(new AsNumber((long) 100), new DomainIdentifier(new byte[] { 25, 25,
914 25, 1 }), new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
916 final NodeIdentifier nodeid1 = f100.identifierForRouter(new OSPFv3LANIdentifier(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }), new OSPFInterfaceIdentifier(new byte[] {
917 0x0b, 0x0b, 0x0b, 0x03 })));
918 final NodeIdentifier nodeid2 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }));
920 final NodeIdentifier nodeid3 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 1, 1, 1, 2 }));
924 final LinkIdentifier linkId1 = new LinkIdentifier(null, new LinkAnchor(nodeid1, new IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.3"))), new LinkAnchor(nodeid2, null));
925 final LinkIdentifier linkId2 = new LinkIdentifier(null, new LinkAnchor(nodeid1, new IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.1"))), new LinkAnchor(nodeid3, null));
926 final LinkIdentifier linkId3 = new LinkIdentifier(null, new LinkAnchor(nodeid3, new IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.1"))), new LinkAnchor(nodeid1, null));
928 final BGPLink link1 = new BGPLinkImpl(state, linkId1, linkState);
929 final BGPLink link2 = new BGPLinkImpl(state, linkId2, linkState);
930 final BGPLink link3 = new BGPLinkImpl(state, linkId3, linkState);
932 final BGPUpdateMessage expectedMessage = new BGPUpdateMessageImpl(Sets.newHashSet((BGPObject) link1, (BGPObject) link2,
933 (BGPObject) link3), Collections.<Identifier> emptySet());
935 assertEquals(expectedMessage, message);
941 * 00 00 <- withdrawn routes length
942 00 b2 <- total path attribute length (178)
943 90 <- attribute flags
944 0e <- attribute type code (MP reach)
945 00 a0 <- attribute extended length (160)
946 40 04 <- AFI (16388 - Linkstate)
947 47 <- SAFI (71 - Linkstate)
948 04 <- next hop length
949 19 19 19 01 - nexthop (25.25.25.1)
951 00 01 <- NLRI type (1 - nodeNLRI)
952 00 31 <- NLRI length (49)
953 03 <- ProtocolID - OSPF
954 00 00 00 00 00 00 00 01 <- identifier
956 01 00 <- local node descriptor type (256)
958 02 00 <- node descriptor type (member AS - 512)
960 00 00 00 64 <- value (100)
961 02 01 <- node descriptor type (bgpId - 513)
963 19 19 19 01 <- bgpId (25.25.25.1)
964 02 02 <- node descriptor type (areaId - 514)
967 02 03 <- node descriptor type (routeId - 515)
969 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
971 00 01 <- NLRI type (1 - nodeNLRI)
972 00 2d <- NLRI length (45)
973 03 <- ProtocolID - OSPF
974 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 03 03 03 04 <- OSPF Router Id
991 00 01 <- NLRI type (1 - nodeNLRI)
992 00 2d <- NLRI length (45)
993 03 <- ProtocolID - OSPF
994 00 00 00 00 00 00 00 01 <- identifier
995 01 00 <- local node descriptor type (256)
997 02 00 <- node descriptor type (member AS - 512)
999 00 00 00 64 <- value (100)
1000 02 01 <- node descriptor type (bgpId - 513)
1002 19 19 19 01 <- bgpId (25.25.25.1)
1003 02 02 <- node descriptor type (areaId - 514)
1005 00 00 00 00 <- value
1006 02 03 <- node descriptor type (routeId - 515)
1008 01 01 01 02 <- OSPF Router Id
1010 40 <- attribute flags
1011 01 <- attribute type (Origin)
1012 01 <- attribute length
1014 40 <- attribute flags
1015 02 <- attribute type (AS Path)
1017 40 <- attribute flags
1018 05 <- attribute type (local pref)
1020 00 00 00 64 <- value
1024 // FIXME: to be fixed in testing phase
1025 public void testBGPNode() throws Exception {
1026 final byte[] body = ByteArray.cutBytes(inputBytes.get(9), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
1027 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(9), BGPMessageFactoryImpl.MARKER_LENGTH,
1028 BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
1029 final Update ret = BGPUpdateMessageParser.parse(body, messageLength);
1031 assertTrue(ret instanceof BGPUpdateMessage);
1032 final BGPUpdateMessage message = (BGPUpdateMessage) ret;
1036 assertEquals(Collections.EMPTY_SET, message.getRemovedObjects());
1038 // network object state
1039 final NetworkObjectState objState = new NetworkObjectState(Collections.<AsPathSegment> emptyList(), Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
1040 final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
1041 final NetworkNodeState nstate = new NetworkNodeState(objState, Collections.<TopologyIdentifier> emptySet(), Collections.<ISISAreaIdentifier> emptySet(), false, false, false, false, Collections.<RouterIdentifier> emptySet(), null);
1043 // network link state
1045 final NodeIdentifierFactory f100 = new NodeIdentifierFactory(new AsNumber((long) 100), new DomainIdentifier(new byte[] { 25, 25,
1046 25, 1 }), new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
1048 final NodeIdentifier nodeid1 = f100.identifierForRouter(new OSPFv3LANIdentifier(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }), new OSPFInterfaceIdentifier(new byte[] {
1049 0x0b, 0x0b, 0x0b, 0x03 })));
1050 final NodeIdentifier nodeid2 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }));
1052 final NodeIdentifier nodeid3 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 1, 1, 1, 2 }));
1054 // check API message
1056 final BGPNode node1 = new BGPNodeImpl(state, nodeid1, nstate);
1057 final BGPNode node2 = new BGPNodeImpl(state, nodeid2, nstate);
1058 final BGPNode node3 = new BGPNodeImpl(state, nodeid3, nstate);
1060 final BGPUpdateMessage expectedMessage = new BGPUpdateMessageImpl(Sets.newHashSet((BGPObject) node1, (BGPObject) node2,
1061 (BGPObject) node3), Collections.<Identifier> emptySet());
1063 assertEquals(expectedMessage, message);
1067 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
1068 * 00 98 <- length (69) - including header
1069 * 01 <- message type
1071 * 00 64 <- My AS Number (AS TRANS in this case)
1072 * 00 b4 <- Hold Time
1073 * 00 00 00 00 <- BGP Identifier
1074 * 28 <- Optional Parameters Length
1075 * 02 <- opt. param. type (capabilities)
1077 * 01 <- capability code (MP Extensions for BGP4)
1079 * 00 01 00 01 <- AFI 1, SAFI 1
1080 * 02 <- opt. param. type (capabilities)
1082 * 01 <- capability code (MP Extensions for BGP4)
1084 * 00 02 00 01 <- AFI 2, SAFI 1
1085 * 02 <- opt. param. type (capabilities)
1087 * 01 <- capability code (MP Extensions for BGP4)
1089 * 40 04 00 47 <- AFI 16388, SAFI 71
1090 * 02 <- opt. param. type (capabilities)
1092 * 80 <- capability code (private)
1094 * 02 <- opt. param. type (capabilities)
1096 * 02 <- capability code (Route refresh)
1098 * 02 <- opt. param. type (capabilities)
1100 * 41 <- capability code (AS4 octet support)
1102 * 00 00 00 64 <- AS number
1105 public void testOpenMessage() throws Exception {
1106 final BGPMessageFactoryImpl msgFactory = new BGPMessageFactoryImpl();
1107 final Open open = (Open) msgFactory.parse(inputBytes.get(13)).get(0);
1108 final Set<BGPTableType> types = Sets.newHashSet();
1109 for (final BgpParameters param : open.getBgpParameters()) {
1110 final CParameters p = param.getCParameters();
1111 if (p instanceof CMultiprotocol) {
1112 final BGPTableType type = new BGPTableType(((CMultiprotocol) p).getMultiprotocolCapability().getAfi(), ((CMultiprotocol) p).getMultiprotocolCapability().getSafi());
1116 final Set<BGPTableType> expected = Sets.newHashSet(new BGPTableType(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class),
1117 new BGPTableType(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class),
1118 new BGPTableType(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
1119 assertEquals(expected, types);