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