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