Merge "BUG-113: introduce Activator and use it"
[bgpcep.git] / bgp / parser-impl / src / test / java / org / opendaylight / protocol / bgp / parser / impl / BGPParserTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.parser.impl;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
13
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;
20 import java.util.Set;
21
22 import org.junit.BeforeClass;
23 import org.junit.Ignore;
24 import org.junit.Test;
25 import org.opendaylight.protocol.bgp.parser.BGPMessageFactory;
26 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
27 import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
28 import org.opendaylight.protocol.bgp.parser.impl.message.update.SimpleAttributeRegistry;
29 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
30 import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
31 import org.opendaylight.protocol.concepts.IGPMetric;
32 import org.opendaylight.protocol.concepts.IPv4;
33 import org.opendaylight.protocol.concepts.IPv4Prefix;
34 import org.opendaylight.protocol.concepts.Metric;
35 import org.opendaylight.protocol.util.ByteArray;
36 import org.opendaylight.protocol.util.DefaultingTypesafeContainer;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Open;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Update;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.UpdateBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.CParameters;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.AggregatorBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.as.path.SegmentsBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.WithdrawnRoutesBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocol;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AsPathSegment;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpAggregator;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.CAListBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.CASetBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequence;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequenceBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.CInet4SpecificExtendedCommunityBuilder;
68 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;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv4NextHop;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv4NextHopBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv6NextHop;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv6NextHopBuilder;
73 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;
74 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;
75
76 import com.google.common.collect.Lists;
77 import com.google.common.collect.Sets;
78
79 public class BGPParserTest {
80
81         /**
82          * Used by other tests as well
83          */
84         static final List<byte[]> inputBytes = new ArrayList<byte[]>();
85
86         private static int COUNTER = 17;
87
88         private static int MAX_SIZE = 300;
89
90         private static MessageRegistry reg;
91
92         private static BGPUpdateMessageParser updateParser;
93
94         @BeforeClass
95         public static void setUp() throws Exception {
96                 reg = SimpleBGPMessageFactory.getInstance();
97                 updateParser = new BGPUpdateMessageParser(SimpleAttributeRegistry.getInstance());
98
99                 for (int i = 1; i <= COUNTER; i++) {
100                         final String name = "/up" + i + ".bin";
101                         final InputStream is = BGPParserTest.class.getResourceAsStream(name);
102                         if (is == null) {
103                                 throw new IOException("Failed to get resource " + name);
104                         }
105
106                         final ByteArrayOutputStream bis = new ByteArrayOutputStream();
107                         final byte[] data = new byte[MAX_SIZE];
108                         int nRead = 0;
109                         while ((nRead = is.read(data, 0, data.length)) != -1) {
110                                 bis.write(data, 0, nRead);
111                         }
112                         bis.flush();
113
114                         inputBytes.add(bis.toByteArray());
115                 }
116         }
117
118         @Test
119         public void testResource() {
120                 assertNotNull(inputBytes);
121         }
122
123         /*
124          * Tests IPv4 NEXT_HOP, ATOMIC_AGGREGATE, COMMUNITY, NLRI
125          * 
126          * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
127          * 00 54 <- length (84) - including header
128          * 02 <- message type
129          * 00 00 <- withdrawn routes length
130          * 00 31 <- total path attribute length (49)
131          * 40 <- attribute flags
132          * 01 <- attribute type code (origin)
133          * 01 <- attribute length
134          * 00 <- Origin value (IGP)
135          * 40 <- attribute flags
136          * 02 <- attribute type code (as path)
137          * 06 <- attribute length
138          * 02 <- AS_SEQUENCE
139          * 01 <- path segment count
140          * 00 00 fd ea <- path segment value (65002)
141          * 40 <- attribute flags
142          * 03 <- attribute type code (Next Hop)
143          * 04 <- attribute length
144          * 10 00 00 02 <- value (10.0.0.2)
145          * 80 <- attribute flags
146          * 04 <- attribute type code (multi exit disc)
147          * 04 <- attribute length
148          * 00 00 00 00 <- value
149          * 64 <- attribute flags
150          * 06 <- attribute type code (atomic aggregate)
151          * 00 <- attribute length
152          * 64 <- attribute flags
153          * 08 <- attribute type code (community)
154          * 10 <- attribute length FF FF FF
155          * 01 <- value (NO_EXPORT)
156          * FF FF FF 02 <- value (NO_ADVERTISE)
157          * FF FF FF 03 <- value (NO_EXPORT_SUBCONFED)
158          * FF FF FF 10 <- unknown Community
159          * 
160          * //NLRI
161          * 18 ac 11 02 <- IPv4 Prefix (172.17.2.0 / 24)
162          * 18 ac 11 01 <- IPv4 Prefix (172.17.1.0 / 24)
163          * 18 ac 11 00 <- IPv4 Prefix (172.17.0.0 / 24)
164          */
165         @Test
166         @Ignore
167         // FIXME: to be fixed in testing phase
168         public void testGetUpdateMessage1() throws Exception {
169
170                 final byte[] body = ByteArray.cutBytes(inputBytes.get(0), MessageUtil.COMMON_HEADER_LENGTH);
171                 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(0), MessageUtil.MARKER_LENGTH,
172                                 MessageUtil.LENGTH_FIELD_LENGTH));
173                 final Update message = updateParser.parseMessageBody(body, messageLength);
174
175                 // check fields
176
177                 assertNull(message.getWithdrawnRoutes());
178
179                 // attributes
180
181                 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65002L)).build());
182                 final List<AsPathSegment> asPath = Lists.newArrayList();
183                 asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
184
185                 final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
186                                 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build();
187
188                 final Set<Community> comms = new HashSet<>();
189                 comms.add(CommunityUtil.NO_EXPORT);
190                 comms.add(CommunityUtil.NO_ADVERTISE);
191                 comms.add(CommunityUtil.NO_EXPORT_SUBCONFED);
192                 comms.add(CommunityUtil.create(0xFFFF, 0xFF10));
193
194                 // check path attributes
195
196                 // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
197                 // true, false, false, BGPOrigin.IGP);
198                 // assertEquals(originAttr, attrs.get(0));
199                 //
200                 // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
201                 // true, false, false, asPath);
202                 // assertEquals(asPathAttr, attrs.get(1));
203                 //
204                 // final PathAttribute nextHopAttr = new PathAttribute(TypeCode.NEXT_HOP, false,
205                 // true, false, false, nextHop);
206                 // assertEquals(nextHopAttr, attrs.get(2));
207                 //
208                 // final PathAttribute multiExitDisc = new PathAttribute(
209                 // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
210                 // assertEquals(multiExitDisc, attrs.get(3));
211                 //
212                 // final PathAttribute atomic = new PathAttribute(TypeCode.ATOMIC_AGGREGATE, false,
213                 // true, true, false, null);
214                 // assertEquals(atomic, attrs.get(4));
215                 //
216                 // final PathAttribute comm = new PathAttribute(TypeCode.COMMUNITIES, false,
217                 // true, true, false, comms);
218                 // assertEquals(comm, attrs.get(5));
219
220                 // check nlri
221
222                 // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1, pref2, pref3);
223                 // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
224
225                 //              final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
226                 //              final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath, comms, Collections.<ExtendedCommunity> emptySet()), nextHop);
227
228                 // check API message
229
230                 //              final Set<BGPObject> addedObjects = Sets.newHashSet();
231                 //
232                 //              final BGPRoute route1 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.2.0/24"), state, routeState);
233                 //
234                 //              addedObjects.add(route1);
235                 //
236                 //              final BGPRoute route2 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.1.0/24"), state, routeState);
237                 //
238                 //              addedObjects.add(route2);
239                 //
240                 //              final BGPRoute route3 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.0.0/24"), state, routeState);
241                 //
242                 //              addedObjects.add(route3);
243         }
244
245         /*
246          * Tests IPv6 NEXT_HOP, NLRI, ORIGIN.IGP, MULTI_EXIT_DISC, ORIGINATOR-ID, CLUSTER_LIST.
247          * 
248          * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
249          * 00 80 <- length (128) - including header
250          * 02 <- message type
251          * 00 00 <- withdrawn routes length
252          * 00 69 <- total path attribute length (105)
253          * 40 <- attribute flags
254          * 01 <- attribute type code (origin)
255          * 01 <- attribute length
256          * 00 <- Origin value (IGP)
257          * 40 <- attribute flags
258          * 02 <- attribute type code (as path)
259          * 06 <- attribute length
260          * 02 <- AS_SEQUENCE
261          * 01 <- path segment count
262          * 00 00 fd e9 <- path segment value (65001)
263          * 80 <- attribute flags
264          * 04 <- attribute type code (multi exit disc)
265          * 04 <- attribute length
266          * 00 00 00 00 <- value
267          * 80 <- attribute flags
268          * 09 <- attribute type code (originator id)
269          * 04 <- attribute length
270          * 7f 00 00 01 <- value (localhost ip)
271          * 80 <- attribute flags
272          * 0a <- attribute type code (cluster list)
273          * 08 <- attribute length
274          * 01 02 03 04 <- value
275          * 05 06 07 08 <- value
276          * 80 <- attribute flags
277          * 0e <- attribute type code (mp reach nlri)
278          * 40 <- attribute length
279          * 00 02 <- AFI (Ipv6)
280          * 01 <- SAFI (Unicast)
281          * 20 <- length of next hop
282          * 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 01 <- global
283          * fe 80 00 00 00 00 00 00 c0 01 0b ff fe 7e 00 <- link local
284          * 00 <- reserved
285          * 
286          * //NLRI
287          * 40 20 01 0d b8 00 01 00 02 <- IPv6 Prefix (2001:db8:1:2:: / 64)
288          * 40 20 01 0d b8 00 01 00 01 <- IPv6 Prefix (2001:db8:1:1:: / 64)
289          * 40 20 01 0d b8 00 01 00 00 <- IPv6 Prefix (2001:db8:1:: / 64)
290          * 
291          */
292         @Test
293         @Ignore
294         // FIXME: to be fixed in testing phase
295         public void testGetUpdateMessage2() throws Exception {
296                 final byte[] body = ByteArray.cutBytes(inputBytes.get(1), MessageUtil.COMMON_HEADER_LENGTH);
297                 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(1), MessageUtil.MARKER_LENGTH,
298                                 MessageUtil.LENGTH_FIELD_LENGTH));
299                 final Update message = updateParser.parseMessageBody(body, messageLength);
300                 // check fields
301
302                 assertNull(message.getWithdrawnRoutes());
303
304                 // attributes
305                 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65001L)).build());
306                 final List<AsPathSegment> asPath = Lists.newArrayList();
307                 asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
308
309                 final CIpv6NextHop nextHop = new CIpv6NextHopBuilder().setIpv6NextHop(
310                                 new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
311
312                 // final List<ClusterIdentifier> clusters = Lists.newArrayList(
313                 // new ClusterIdentifier(new byte[] { 1, 2, 3, 4}),
314                 // new ClusterIdentifier(new byte[] { 5, 6, 7, 8}));
315
316                 // check path attributes
317
318                 // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
319                 // true, false, false, BGPOrigin.IGP);
320                 // assertEquals(originAttr, attrs.get(0));
321                 //
322                 // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
323                 // true, false, false, asPath);
324                 // assertEquals(asPathAttr, attrs.get(1));
325                 //
326                 // final PathAttribute multiExitDisc = new PathAttribute(
327                 // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
328                 // assertEquals(multiExitDisc, attrs.get(2));
329                 //
330                 // final PathAttribute originatorAttr = new PathAttribute(
331                 // TypeCode.ORIGINATOR_ID, true, false, false, false, IPv4.FAMILY.addressForString("127.0.0.1"));
332                 // assertEquals(originatorAttr, attrs.get(3));
333                 //
334                 // final PathAttribute clusterAttr = new PathAttribute(
335                 // TypeCode.CLUSTER_LIST, true, false, false, false, clusters);
336                 // assertEquals(clusterAttr, attrs.get(4));
337
338                 //              final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
339                 //              final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath, Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet()), nextHop);
340
341                 // check API message
342
343                 //              final Set<BGPObject> addedObjects = Sets.newHashSet();
344                 //
345                 //              final BGPRoute route1 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1:2::/64"), state, routeState);
346                 //
347                 //              addedObjects.add(route1);
348                 //
349                 //              final BGPRoute route2 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1:1::/64"), state, routeState);
350                 //
351                 //              addedObjects.add(route2);
352                 //
353                 //              final BGPRoute route3 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1::/64"), state, routeState);
354                 //
355                 //              addedObjects.add(route3);
356         }
357
358         /*
359          * Tests more AS Numbers in AS_PATH, AGGREGATOR, ORIGIN.INCOMPLETE
360          * 
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
363          * 02 <- message type
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
373          * 02 <- AS_SEQUENCE
374          * 01 <- path segment count
375          * 00 00 00 1e <- path segment value (30)
376          * 01 <- AS_SET
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)
393          * 
394          * //NLRI
395          * 15 ac 10 00 <- IPv4 Prefix (172.16.0.0 / 21)
396          */
397         @Test
398         @Ignore
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 = updateParser.parseMessageBody(body, messageLength);
405
406                 // check fields
407                 assertNull(message.getWithdrawnRoutes());
408
409                 // attributes
410
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());
416
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();
421
422                 final IPv4Prefix pref1 = IPv4.FAMILY.prefixForString("172.16.0.0/21");
423
424                 // check path attributes
425
426                 // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
427                 // true, false, false, BGPOrigin.INCOMPLETE);
428                 // assertEquals(originAttr, attrs.get(0));
429                 //
430                 // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
431                 // true, false, false, asPath);
432                 // assertEquals(asPathAttr, attrs.get(1));
433                 //
434                 // final PathAttribute nextHopAttr = new PathAttribute(TypeCode.NEXT_HOP, false,
435                 // true, false, false, nextHop);
436                 // assertEquals(nextHopAttr, attrs.get(2));
437                 //
438                 // final PathAttribute multiExitDisc = new PathAttribute(
439                 // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
440                 // assertEquals(multiExitDisc, attrs.get(3));
441                 //
442                 // final PathAttribute agg = new PathAttribute(TypeCode.AGGREGATOR, true, true,
443                 // false, false, aggregator);
444                 // assertEquals(agg, attrs.get(4));
445                 //
446                 // // check nlri
447                 //
448                 // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1);
449                 // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
450                 //
451                 //              final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Incomplete, aggregator);
452                 //              final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath, Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet()), nextHop);
453
454                 // check API message
455
456                 //              final Set<BGPObject> addedObjects = Sets.newHashSet();
457                 //
458                 //              final BGPRoute route1 = new BGPIPv4RouteImpl(pref1, state, routeState);
459                 //
460                 //              addedObjects.add(route1);
461         }
462
463         /*
464          * Tests empty AS_PATH, ORIGIN.EGP, LOCAL_PREF, EXTENDED_COMMUNITIES (Ipv4 Addr specific)
465          * 
466          * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
467          * 00 4A <- length (73) - including header
468          * 02 <- message type
469          * 00 00 <- withdrawn routes length
470          * 00 27 <- total path attribute length (39)
471          * 40 <- attribute flags
472          * 01 <- attribute type code (Origin)
473          * 01 <- attribute length
474          * 01 <- Origin value (EGP)
475          * 40 <- attribute flags
476          * 02 <- attribute type code (As path)
477          * 00 <- attribute length
478          * 40 <- attribute flags
479          * 03 <- attribute type (Next hop)
480          * 04 <- attribute length
481          * 03 03 03 03 <- value (3.3.3.3)
482          * 80 <- attribute flags
483          * 04 <- attribute type code (Multi exit disc)
484          * 04 <- attribute length
485          * 00 00 00 00 <- value
486          * 40 <- attribute flags
487          * 05 <- attribute type (Local Pref)
488          * 04 <- attribute length
489          * 00 00 00 64 <- value (100)
490          * 80 <- attribute flags
491          * 10 <- attribute type (extended community)
492          * 08 <- attribute length
493          * 01 04 <- value (type - Ipv4 Address Specific Extended Community)
494          * c0 a8 01 00 <- value (global adm. 198.162.1.0)
495          * 12 34 <- value (local adm. 4660)
496          * 
497          * //NLRI
498          * 18 0a 1e 03 <- IPv4 Prefix (10.30.3.0 / 24)
499          * 18 0a 1e 02 <- IPv4 Prefix (10.30.2.0 / 24)
500          * 18 0a 1e 01 <- IPv4 Prefix (10.30.1.0 / 24)
501          */
502         @Test
503         @Ignore
504         // FIXME: to be fixed in testing phase
505         public void testGetUpdateMessage4() throws Exception {
506                 final byte[] body = ByteArray.cutBytes(inputBytes.get(3), MessageUtil.COMMON_HEADER_LENGTH);
507                 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(3), MessageUtil.MARKER_LENGTH,
508                                 MessageUtil.LENGTH_FIELD_LENGTH));
509                 final Update message = updateParser.parseMessageBody(body, messageLength);
510
511                 // check fields
512
513                 assertNull(message.getWithdrawnRoutes());
514
515                 // attributes
516
517                 final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
518                                 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("3.3.3.3")).build()).build();
519
520                 final Set<ExtendedCommunity> comms = Sets.newHashSet();
521                 comms.add(new CInet4SpecificExtendedCommunityBuilder().setInet4SpecificExtendedCommunity(
522                                 new Inet4SpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(new Ipv4Address("192.168.1.0")).setLocalAdministrator(
523                                                 new byte[] { 0x12, 0x34 }).build()).build());
524
525                 // check path attributes
526
527                 // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
528                 // true, false, false, BGPOrigin.EGP);
529                 // assertEquals(originAttr, attrs.get(0));
530                 //
531                 // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
532                 // true, false, false, asPath);
533                 // assertEquals(asPathAttr, attrs.get(1));
534                 //
535                 // final PathAttribute nextHopAttr = new PathAttribute(TypeCode.NEXT_HOP, false,
536                 // true, false, false, nextHop);
537                 // assertEquals(nextHopAttr, attrs.get(2));
538                 //
539                 // final PathAttribute multiExitDisc = new PathAttribute(
540                 // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
541                 // assertEquals(multiExitDisc, attrs.get(3));
542                 //
543                 // final PathAttribute localPref = new PathAttribute(TypeCode.LOCAL_PREF, false,
544                 // true, false, false, 100);
545                 // assertEquals(localPref, attrs.get(4));
546
547                 // check nlri
548                 //
549                 // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1, pref2, pref3);
550                 // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
551
552                 //              final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Egp, null);
553                 //              final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(Collections.<AsPathSegment> emptyList(), Collections.<Community> emptySet(), comms), nextHop);
554
555                 // check API message
556
557                 //              final Set<BGPObject> addedObjects = Sets.newHashSet();
558                 //
559                 //              final BGPRoute route1 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.3.0/24"), state, routeState);
560                 //
561                 //              addedObjects.add(route1);
562                 //
563                 //              final BGPRoute route2 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.2.0/24"), state, routeState);
564                 //
565                 //              addedObjects.add(route2);
566                 //
567                 //              final BGPRoute route3 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.1.0/24"), state, routeState);
568                 //
569                 //              addedObjects.add(route3);
570         }
571
572         /*
573          * Tests withdrawn routes.
574          * 
575          * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
576          * 00 1c <- length (28) - including header
577          * 02 <- message type
578          * 00 05 <- withdrawn routes length (5)
579          * 1e ac 10 00 04 <- route (172.16.0.4)
580          * 00 00 <- total path attribute length
581          */
582         @Test
583         @Ignore
584         // FIXME: to be fixed in testing phase
585         public void testGetUpdateMessage5() throws Exception {
586                 final byte[] body = ByteArray.cutBytes(inputBytes.get(4), MessageUtil.COMMON_HEADER_LENGTH);
587                 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(4), MessageUtil.MARKER_LENGTH,
588                                 MessageUtil.LENGTH_FIELD_LENGTH));
589                 final Update message = updateParser.parseMessageBody(body, messageLength);
590
591                 // attributes
592
593                 List<Ipv4Prefix> prefs = Lists.newArrayList(new Ipv4Prefix("172.16.0.4/30"));
594
595                 // check API message
596
597                 final Update expectedMessage = new UpdateBuilder().setWithdrawnRoutes(new WithdrawnRoutesBuilder().setWithdrawnRoutes(prefs).build()).build();
598
599                 assertEquals(expectedMessage.getWithdrawnRoutes().getWithdrawnRoutes().get(0).toString(), message.getWithdrawnRoutes().getWithdrawnRoutes().get(0).toString());
600         }
601
602         /*
603          * Test EOR for IPv4.
604          * 
605          * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
606          * 00 17 <- length (23) - including header
607          * 02 <- message type
608          * 00 00 <- withdrawn routes length
609          * 00 00 <- total path attribute length
610          */
611         @Test
612         public void testEORIpv4() throws Exception {
613                 final byte[] body = ByteArray.cutBytes(inputBytes.get(5), MessageUtil.COMMON_HEADER_LENGTH);
614                 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(5), MessageUtil.MARKER_LENGTH,
615                                 MessageUtil.LENGTH_FIELD_LENGTH));
616                 final Update message = updateParser.parseMessageBody(body, messageLength);
617
618                 assertEquals(new UpdateBuilder().build(), message);
619         }
620
621         /*
622          * End of Rib for Ipv6 consists of empty MP_UNREACH_NLRI, with AFI 2 and SAFI 1
623          * 
624          * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
625          * 00 1d <- length (29) - including header
626          * 02 <- message type
627          * 00 00 <- withdrawn routes length
628          * 00 06 <- total path attribute length
629          * 80 <- attribute flags
630          * 0f <- attribute type (15 - MP_UNREACH_NLRI)
631          * 03 <- attribute length
632          * 00 02 <- value (AFI 2: IPv6)
633          * 01 <- value (SAFI 1)
634          */
635         @Test
636         @Ignore
637         //FIXME: to be fixed in testing phase
638         public void testEORIpv6() throws Exception {
639                 final byte[] body = ByteArray.cutBytes(inputBytes.get(6), MessageUtil.COMMON_HEADER_LENGTH);
640                 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(6), MessageUtil.MARKER_LENGTH,
641                                 MessageUtil.LENGTH_FIELD_LENGTH));
642                 final Update message = updateParser.parseMessageBody(body, messageLength);
643
644                 // check fields
645
646                 Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getAfi();
647                 SubsequentAddressFamily safi = message.getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getSafi().newInstance();
648
649                 assertEquals(Ipv6AddressFamily.class, afi);
650                 assertEquals(UnicastSubsequentAddressFamily.INSTANCE, safi);
651         }
652
653         /*
654          * End of Rib for LS consists of empty MP_UNREACH_NLRI, with AFI 16388 and SAFI 71
655          * 
656          * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
657          * 00 1d <- length (29) - including header
658          * 02 <- message type
659          * 00 00 <- withdrawn routes length
660          * 00 06 <- total path attribute length
661          * 80 <- attribute flags
662          * 0f <- attribute type (15 - MP_UNREACH_NLRI)
663          * 03 <- attribute length
664          * 40 04 <- value (AFI 16388: LS)
665          * 47 <- value (SAFI 71)
666          */
667         @Test
668         @Ignore
669         //FIXME: to be fixed in testing phase
670         public void testEORLS() throws Exception {
671                 final byte[] body = ByteArray.cutBytes(inputBytes.get(7), MessageUtil.COMMON_HEADER_LENGTH);
672                 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(7), MessageUtil.MARKER_LENGTH,
673                                 MessageUtil.LENGTH_FIELD_LENGTH));
674                 final Update message = updateParser.parseMessageBody(body, messageLength);
675
676                 Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getAfi();
677                 SubsequentAddressFamily safi = message.getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getSafi().newInstance();
678
679                 assertEquals(LinkstateAddressFamily.class, afi);
680                 assertEquals(LinkstateSubsequentAddressFamily.INSTANCE, safi);
681         }
682
683         /*
684          *  Tests BGP Link Ipv4
685          * 
686                 00 00 <- withdrawn routes length
687                 01 48 <- total path attribute length (328)
688                 90 <- attribute flags
689                 0e <- attribute type code (MP reach)
690                 01 2c <- attribute extended length (300)
691                 40 04 <- AFI (16388 - Linkstate)
692                 47 <- SAFI (71 - Linkstate)
693                 04 <- next hop length
694                 19 19 19 01 <- nexthop (25.25.25.1)
695                 00 <- reserved
696
697                 00 02 <- NLRI type (2 - linkNLRI)
698                 00 5d <- NLRI length (93)
699                 03 <- ProtocolID - OSPF
700                 00 00 00 00 00 00 00 01 <- identifier
701
702                 01 00 <- local node descriptor type (256)
703                 00 24 <- length (36)
704                 02 00 <- node descriptor type (member AS - 512)
705                 00 04 <- length
706                 00 00 00 64 <- value (100)
707                 02 01 <- node descriptor type (bgpId - 513)
708                 00 04 <- length
709                 19 19 19 01 <- bgpId (25.25.25.1)
710                 02 02 <- node descriptor type (areaId - 514)
711                 00 04 <- length
712                 00 00 00 00 <- value
713                 02 03 <- node descriptor type (routeId - 515)
714                 00 08 <- length
715                 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
716
717                 01 01 <- remote node descriptor type (257)
718                 00 20 <- length (32)
719                 02 00 <- node descriptor type (member AS - 512)
720                 00 04 <- length
721                 00 00 00 64 <- value (100)
722                 02 01 <- node descriptor type (bgpId - 513)
723                 00 04 <- length
724                 19 19 19 01 <- bgpId (25.25.25.1)
725                 02 02 <- node descriptor type (areaId - 514)
726                 00 04 <- length
727                 00 00 00 00 <- value
728                 02 03 <- node descriptor type (routeId - 515)
729                 00 04 <- length
730                 03 03 03 04 <- OSPF Router Id
731
732                 01 03 <- link descriptor type (IPv4 interface address - 259)
733                 00 04 <- length (4)
734                 0b 0b 0b 03 <- value (11.11.11.3)
735
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
740
741                 01 00 <- local node descriptor type (256)
742                 00 24 <- length (36)
743                 02 00 <- node descriptor type (member AS - 512)
744                 00 04 <- length
745                 00 00 00 64 <- value (100)
746                 02 01 <- node descriptor type (bgpId - 513)
747                 00 04 <- length
748                 19 19 19 01 <- bgpId (25.25.25.1)
749                 02 02 <- node descriptor type (areaId - 514)
750                 00 04 <- length
751                 00 00 00 00 <- value
752                 02 03 <- node descriptor type (routeId - 515)
753                 00 08 <- length
754                 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
755
756                 01 01 <- remote node descriptor type (257)
757                 00 20 <- length (32)
758                 02 00 <- node descriptor type (member AS - 512)
759                 00 04 <- length
760                 00 00 00 64 <- value (100)
761                 02 01 <- node descriptor type (bgpId - 513)
762                 00 04 <- length
763                 19 19 19 01 <- bgpId (25.25.25.1)
764                 02 02 <- node descriptor type (areaId - 514)
765                 00 04 <- length
766                 00 00 00 00 <- value
767                 02 03 <- node descriptor type (routeId - 515)
768                 00 04 <- length
769                 01 01 01 02 <- OSPF Router Id
770
771                 01 03 <- link descriptor type (IPv4 interface address - 259)
772                 00 04 <- length
773                 0b 0b 0b 01 <- value (11.11.11.1)
774
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
779
780                 01 00 <- local node descriptor type (256)
781                 00 20 <- length (32)
782                 02 00 <- node descriptor type (member AS - 512)
783                 00 04 <- length
784                 00 00 00 64 <- value (100)
785                 02 01 <- node descriptor type (bgpId - 513)
786                 00 04 <- length
787                 19 19 19 01 <- bgpId (25.25.25.1)
788                 02 02 <- node descriptor type (areaId - 514)
789                 00 04 <- length
790                 00 00 00 00 <- value
791                 02 03 <- node descriptor type (routeId - 515)
792                 00 04 <- length
793                 01 01 01 02 <- OSPF Router Id
794
795                 01 01 <- remote node descriptor type (257)
796                 00 24 <- length (36)
797                 02 00 <- node descriptor type (member AS - 512)
798                 00 04 <- length
799                 00 00 00 64 <- value (100)
800                 02 01 <- node descriptor type (bgpId - 513)
801                 00 04 <- length
802                 19 19 19 01 <- bgpId (25.25.25.1)
803                 02 02 <- node descriptor type (areaId - 514)
804                 00 04 <- length
805                 00 00 00 00 <- value
806                 02 03 <- node descriptor type (routeId - 515)
807                 00 08 <- length
808                 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
809
810                 01 03 <- link descriptor type (IPv4 interface address - 259)
811                 00 04 <- length
812                 0b 0b 0b 01 <- value (11.11.11.1)
813
814                 40 <- attribute flags
815                 01 <- attribute type (Origin)
816                 01 <- attribute length
817                 00 <- value (IGP)
818                 40 <- attribute flags
819                 02 <- attribute type (AS Path)
820                 00 <- length
821                 40 <- attribute flags
822                 05 <- attribute type (local pref)
823                 04 <- length
824                 00 00 00 64 <- value
825                 c0 <- attribute flags
826                 63 <- attribute type (Link STATE - 99)
827                 07 <- length
828                 04 47 <- link attribute (1095 - Metric)
829                 00 03 <- length
830                 00 00 01 <- value
831          */
832         @Test
833         @Ignore
834         // FIXME: to be fixed in testing phase
835         public void testBGPLink() throws Exception {
836                 final byte[] body = ByteArray.cutBytes(inputBytes.get(8), MessageUtil.COMMON_HEADER_LENGTH);
837                 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(8), MessageUtil.MARKER_LENGTH,
838                                 MessageUtil.LENGTH_FIELD_LENGTH));
839                 final Update message = updateParser.parseMessageBody(body, messageLength);
840
841                 // check fields
842
843                 assertNull(message.getWithdrawnRoutes());
844
845                 // network object state
846                 //              final NetworkObjectState objState = new NetworkObjectState(Collections.<AsPathSegment> emptyList(), Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
847                 //              final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
848
849                 // network link state
850                 final DefaultingTypesafeContainer<Metric<?>> container = new DefaultingTypesafeContainer<Metric<?>>();
851                 container.setDefaultEntry(new IGPMetric(1));
852                 //final NetworkLinkState linkState = new NetworkLinkState(objState, container, null, LinkProtectionType.UNPROTECTED, null, null, null);
853
854                 //              final NodeIdentifierFactory f100 = new NodeIdentifierFactory(new AsNumber((long) 100), new DomainIdentifier(new byte[] { 25, 25,
855                 //                              25, 1 }), new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
856                 //
857                 //              final NodeIdentifier nodeid1 = f100.identifierForRouter(new OSPFv3LANIdentifier(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }), new OSPFInterfaceIdentifier(new byte[] {
858                 //                              0x0b, 0x0b, 0x0b, 0x03 })));
859                 //              final NodeIdentifier nodeid2 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }));
860                 //
861                 //              final NodeIdentifier nodeid3 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 1, 1, 1, 2 }));
862
863                 // check API message
864
865                 //              final LinkIdentifier linkId1 = new LinkIdentifier(null, new LinkAnchor(nodeid1, new IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.3"))), new LinkAnchor(nodeid2, null));
866                 //              final LinkIdentifier linkId2 = new LinkIdentifier(null, new LinkAnchor(nodeid1, new IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.1"))), new LinkAnchor(nodeid3, null));
867                 //              final LinkIdentifier linkId3 = new LinkIdentifier(null, new LinkAnchor(nodeid3, new IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.1"))), new LinkAnchor(nodeid1, null));
868                 //
869                 //              final BGPLink link1 = new BGPLinkImpl(state, linkId1, linkState);
870                 //              final BGPLink link2 = new BGPLinkImpl(state, linkId2, linkState);
871                 //              final BGPLink link3 = new BGPLinkImpl(state, linkId3, linkState);
872                 //
873                 //              final BGPUpdateMessage expectedMessage = new BGPUpdateMessageImpl(Sets.newHashSet((BGPObject) link1, (BGPObject) link2,
874                 //                              (BGPObject) link3), Collections.<Identifier> emptySet());
875                 //
876                 //              assertEquals(expectedMessage, message);
877         }
878
879         /*
880          * TEST BGP Node
881          * 
882          *  00 00 <- withdrawn routes length
883                 00 b2 <- total path attribute length (178)
884                 90 <- attribute flags
885                 0e <- attribute type code (MP reach)
886                 00 a0 <- attribute extended length (160)
887                 40 04 <- AFI (16388 - Linkstate)
888                 47 <- SAFI (71 - Linkstate)
889                 04 <- next hop length
890                 19 19 19 01 - nexthop (25.25.25.1)
891                 00 <- reserved
892                 00 01 <- NLRI type (1 - nodeNLRI)
893                 00 31 <- NLRI length (49)
894                 03 <- ProtocolID - OSPF
895                 00 00 00 00 00 00 00 01 <- identifier
896
897                 01 00 <- local node descriptor type (256)
898                 00 24 <- length (36)
899                 02 00 <- node descriptor type (member AS - 512)
900                 00 04 <- length
901                 00 00 00 64 <- value (100)
902                 02 01 <- node descriptor type (bgpId - 513)
903                 00 04 <- length
904                 19 19 19 01 <- bgpId (25.25.25.1)
905                 02 02 <- node descriptor type (areaId - 514)
906                 00 04 <- length
907                 00 00 00 00 <- value
908                 02 03 <- node descriptor type (routeId - 515)
909                 00 08 <- length
910                 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
911
912                 00 01 <- NLRI type (1 - nodeNLRI)
913                 00 2d <- NLRI length (45)
914                 03 <- ProtocolID - OSPF
915                 00 00 00 00 00 00 00 01 <- identifier
916
917                 01 00 <- local node descriptor type (256)
918                 00 20 <- length (32)
919                 02 00 <- node descriptor type (member AS - 512)
920                 00 04 <- length
921                 00 00 00 64 <- value (100)
922                 02 01 <- node descriptor type (bgpId - 513)
923                 00 04 <- length
924                 19 19 19 01 <- bgpId (25.25.25.1)
925                 02 02 <- node descriptor type (areaId - 514)
926                 00 04 <- length
927                 00 00 00 00 <- value
928                 02 03 <- node descriptor type (routeId - 515)
929                 00 04 <- length
930                 03 03 03 04 <- OSPF Router Id
931
932                 00 01 <- NLRI type (1 - nodeNLRI)
933                 00 2d <- NLRI length (45)
934                 03 <- ProtocolID - OSPF
935                 00 00 00 00 00 00 00 01 <- identifier
936                 01 00 <- local node descriptor type (256)
937                 00 20 <- length (32)
938                 02 00 <- node descriptor type (member AS - 512)
939                 00 04 <- length
940                 00 00 00 64 <- value (100)
941                 02 01 <- node descriptor type (bgpId - 513)
942                 00 04 <- length
943                 19 19 19 01 <- bgpId (25.25.25.1)
944                 02 02 <- node descriptor type (areaId - 514)
945                 00 04 <- length
946                 00 00 00 00 <- value
947                 02 03 <- node descriptor type (routeId - 515)
948                 00 04 <- length
949                 01 01 01 02  <- OSPF Router Id
950
951                 40 <- attribute flags
952                 01 <- attribute type (Origin)
953                 01 <- attribute length
954                 00 <- value (IGP)
955                 40 <- attribute flags
956                 02 <- attribute type (AS Path)
957                 00 <- length
958                 40 <- attribute flags
959                 05 <- attribute type (local pref)
960                 04 <- length
961                 00 00 00 64 <- value
962          */
963         @Test
964         @Ignore
965         // FIXME: to be fixed in testing phase
966         public void testBGPNode() throws Exception {
967                 final byte[] body = ByteArray.cutBytes(inputBytes.get(9), MessageUtil.COMMON_HEADER_LENGTH);
968                 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(9), MessageUtil.MARKER_LENGTH,
969                                 MessageUtil.LENGTH_FIELD_LENGTH));
970                 final Update message = updateParser.parseMessageBody(body, messageLength);
971
972                 // check fields
973
974                 assertNull(message.getWithdrawnRoutes());
975
976                 // network object state
977                 //              final NetworkObjectState objState = new NetworkObjectState(Collections.<AsPathSegment> emptyList(), Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
978                 //              final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
979                 //              final NetworkNodeState nstate = new NetworkNodeState(objState, Collections.<TopologyIdentifier> emptySet(), Collections.<ISISAreaIdentifier> emptySet(), false, false, false, false, Collections.<RouterIdentifier> emptySet(), null);
980
981                 // network link state
982
983                 //              final NodeIdentifierFactory f100 = new NodeIdentifierFactory(new AsNumber((long) 100), new DomainIdentifier(new byte[] { 25, 25,
984                 //                              25, 1 }), new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
985                 //
986                 //              final NodeIdentifier nodeid1 = f100.identifierForRouter(new OSPFv3LANIdentifier(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }), new OSPFInterfaceIdentifier(new byte[] {
987                 //                              0x0b, 0x0b, 0x0b, 0x03 })));
988                 //              final NodeIdentifier nodeid2 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }));
989                 //
990                 //              final NodeIdentifier nodeid3 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 1, 1, 1, 2 }));
991
992                 // check API message
993
994                 //              final BGPNode node1 = new BGPNodeImpl(state, nodeid1, nstate);
995                 //              final BGPNode node2 = new BGPNodeImpl(state, nodeid2, nstate);
996                 //              final BGPNode node3 = new BGPNodeImpl(state, nodeid3, nstate);
997                 //
998                 //              final BGPUpdateMessage expectedMessage = new BGPUpdateMessageImpl(Sets.newHashSet((BGPObject) node1, (BGPObject) node2,
999                 //                              (BGPObject) node3), Collections.<Identifier> emptySet());
1000                 //
1001                 //              assertEquals(expectedMessage, message);
1002         }
1003
1004         /*
1005          * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
1006          * 00 98 <- length (69) - including header
1007          * 01 <- message type
1008          * 04 <- BGP version
1009          * 00 64 <- My AS Number (AS TRANS in this case)
1010          * 00 b4 <- Hold Time
1011          * 00 00 00 00 <- BGP Identifier
1012          * 28 <- Optional Parameters Length
1013          * 02 <- opt. param. type (capabilities)
1014          * 06 <- length
1015          * 01 <- capability code (MP Extensions for BGP4)
1016          * 04 <- length
1017          * 00 01 00 01 <- AFI 1, SAFI 1
1018          * 02 <- opt. param. type (capabilities)
1019          * 06 <- length
1020          * 01 <- capability code (MP Extensions for BGP4)
1021          * 04 <- length
1022          * 00 02 00 01 <- AFI 2, SAFI 1
1023          * 02 <- opt. param. type (capabilities)
1024          * 06 <- length
1025          * 01 <- capability code (MP Extensions for BGP4)
1026          * 04 <- length
1027          * 40 04 00 47 <- AFI 16388, SAFI 71
1028          * 02 <- opt. param. type (capabilities)
1029          * 02 <- length
1030          * 80 <- capability code (private)
1031          * 00 <- length
1032          * 02 <- opt. param. type (capabilities)
1033          * 02 <- length
1034          * 02 <- capability code (Route refresh)
1035          * 00 <- length
1036          * 02 <- opt. param. type (capabilities)
1037          * 06 <- length
1038          * 41 <- capability code (AS4 octet support)
1039          * 04 <- length
1040          * 00 00 00 64 <- AS number
1041          */
1042         @Test
1043         public void testOpenMessage() throws Exception {
1044                 final BGPMessageFactory msgFactory = SimpleBGPMessageFactory.getInstance();
1045                 final Open open = (Open) msgFactory.parse(inputBytes.get(13)).get(0);
1046                 final Set<BgpTableType> types = Sets.newHashSet();
1047                 for (final BgpParameters param : open.getBgpParameters()) {
1048                         final CParameters p = param.getCParameters();
1049                         if (p instanceof CMultiprotocol) {
1050                                 final BgpTableType type = new BgpTableTypeImpl(((CMultiprotocol) p).getMultiprotocolCapability().getAfi(), ((CMultiprotocol) p).getMultiprotocolCapability().getSafi());
1051                                 types.add(type);
1052                         }
1053                 }
1054                 final Set<BgpTableType> expected = Sets.newHashSet();
1055                 expected.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
1056                 expected.add(new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class));
1057                 expected.add(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
1058                 assertEquals(expected, types);
1059         }
1060 }