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