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