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