BUG-608 : added prefix-sid tlv
[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.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertNull;
14
15 import com.google.common.collect.Lists;
16 import com.google.common.collect.Sets;
17 import io.netty.buffer.ByteBuf;
18 import io.netty.buffer.Unpooled;
19 import java.io.ByteArrayOutputStream;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.math.BigInteger;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.List;
26 import java.util.Set;
27 import org.junit.BeforeClass;
28 import org.junit.Test;
29 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
30 import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
31 import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunityUtil;
32 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
33 import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
34 import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
35 import org.opendaylight.protocol.util.ByteArray;
36 import org.opendaylight.protocol.util.NoopReferenceCache;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.AreaIdentifier;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.DomainIdentifier;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Identifier;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv4InterfaceIdentifier;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateSubsequentAddressFamily;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NlriType;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.OspfInterfaceIdentifier;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestination;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestinationBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.c.linkstate.destination.LinkDescriptorsBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.c.linkstate.destination.LocalNodeDescriptorsBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptorsBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfNodeCaseBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfPseudonodeCaseBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.ospf.node._case.OspfNodeBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonodeBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.path.attributes.LinkstatePathAttributeBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.path.attributes.linkstate.path.attribute.link.state.attribute.LinkAttributesCaseBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.path.attributes.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributesBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCaseBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Open;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.UpdateBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.BgpParameters;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.bgp.parameters.OptionalCapabilities;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.bgp.parameters.optional.capabilities.CParameters;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Aggregator;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AggregatorBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AsPathBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AtomicAggregateBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.ClusterIdBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Communities;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.ExtendedCommunities;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.ExtendedCommunitiesBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.LocalPrefBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.MultiExitDiscBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.OriginBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.OriginatorIdBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.as.path.Segments;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.as.path.SegmentsBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.Nlri;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.NlriBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributes;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.WithdrawnRoutesBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1Builder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes2;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.destination.type.DestinationIpv6CaseBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.destination.type.destination.ipv6._case.DestinationIpv6Builder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.optional.capabilities.c.parameters.MultiprotocolCase;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlri;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlriBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.AListCaseBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.ASetCaseBuilder;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.a.list._case.AListBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.a.list._case.a.list.AsSequence;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.a.list._case.a.list.AsSequenceBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.a.set._case.ASetBuilder;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.Inet4SpecificExtendedCommunityCaseBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.inet4.specific.extended.community._case.Inet4SpecificExtendedCommunityBuilder;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCase;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCaseBuilder;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv6.next.hop._case.Ipv6NextHopBuilder;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric;
123 import org.opendaylight.yangtools.yang.binding.Notification;
124
125 public class BGPParserTest {
126
127     /**
128      * Used by other tests as well
129      */
130     static final List<byte[]> inputBytes = new ArrayList<byte[]>();
131
132     private static int COUNTER = 17;
133
134     private static int MAX_SIZE = 300;
135
136     private static BGPUpdateMessageParser updateParser;
137
138     private static final int LENGTH_FIELD_LENGTH = 2;
139
140     @BeforeClass
141     public static void setUp() throws Exception {
142         updateParser = new BGPUpdateMessageParser(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry());
143         for (int i = 1; i <= COUNTER; i++) {
144             final String name = "/up" + i + ".bin";
145             try (final InputStream is = BGPParserTest.class.getResourceAsStream(name)){
146                 if (is == null) {
147                     throw new IOException("Failed to get resource " + name);
148                 }
149                 final ByteArrayOutputStream bis = new ByteArrayOutputStream();
150                 final byte[] data = new byte[MAX_SIZE];
151                 int nRead = 0;
152                 while ((nRead = is.read(data, 0, data.length)) != -1) {
153                     bis.write(data, 0, nRead);
154                 }
155                 bis.flush();
156
157                 inputBytes.add(bis.toByteArray());
158                 is.close();
159             }
160         }
161     }
162
163
164     @Test
165     public void testResource() {
166         assertNotNull(inputBytes);
167     }
168
169     /*
170      * Tests IPv4 NEXT_HOP, ATOMIC_AGGREGATE, COMMUNITY, NLRI
171      *
172      * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
173      * 00 54 <- length (84) - including header
174      * 02 <- message type
175      * 00 00 <- withdrawn routes length
176      * 00 31 <- total path attribute length (49)
177      * 40 <- attribute flags
178      * 01 <- attribute type code (origin)
179      * 01 <- attribute length
180      * 00 <- Origin value (IGP)
181      * 40 <- attribute flags
182      * 02 <- attribute type code (as path)
183      * 06 <- attribute length
184      * 02 <- AS_SEQUENCE
185      * 01 <- path segment count
186      * 00 00 fd ea <- path segment value (65002)
187      * 40 <- attribute flags
188      * 03 <- attribute type code (Next Hop)
189      * 04 <- attribute length
190      * 10 00 00 02 <- value (10.0.0.2)
191      * 80 <- attribute flags
192      * 04 <- attribute type code (multi exit disc)
193      * 04 <- attribute length
194      * 00 00 00 00 <- value
195      * 60 <- attribute flags
196      * 06 <- attribute type code (atomic aggregate)
197      * 00 <- attribute length
198      * 40 <- attribute flags
199      * 08 <- attribute type code (community)
200      * 10 <- attribute length FF FF FF
201      * 01 <- value (NO_EXPORT)
202      * FF FF FF 02 <- value (NO_ADVERTISE)
203      * FF FF FF 03 <- value (NO_EXPORT_SUBCONFED)
204      * FF FF FF 10 <- unknown Community
205      *
206      * //NLRI
207      * 18 ac 11 02 <- IPv4 Prefix (172.17.2.0 / 24)
208      * 18 ac 11 01 <- IPv4 Prefix (172.17.1.0 / 24)
209      * 18 ac 11 00 <- IPv4 Prefix (172.17.0.0 / 24)
210      */
211     @Test
212     public void testGetUpdateMessage1() throws Exception {
213
214         final byte[] body = ByteArray.cutBytes(inputBytes.get(0), MessageUtil.COMMON_HEADER_LENGTH);
215         final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(0), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
216         final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
217
218         // check fields
219
220         assertNull(message.getWithdrawnRoutes());
221
222         // attributes
223
224         final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65002L)).build());
225         final List<Segments> asPath = Lists.newArrayList();
226         asPath.add(new SegmentsBuilder().setCSegment(
227             new AListCaseBuilder().setAList(new AListBuilder().setAsSequence(asnums).build()).build()).build());
228
229         final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
230             new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build();
231
232         final List<Communities> comms = Lists.newArrayList();
233         comms.add((Communities) CommunityUtil.NO_EXPORT);
234         comms.add((Communities) CommunityUtil.NO_ADVERTISE);
235         comms.add((Communities) CommunityUtil.NO_EXPORT_SUBCONFED);
236         comms.add((Communities) CommunityUtil.create(NoopReferenceCache.getInstance(), 0xFFFF, 0xFF10));
237
238         final UpdateBuilder builder = new UpdateBuilder();
239
240         // check nlri
241
242         final List<Ipv4Prefix> prefs = Lists.newArrayList();
243         prefs.add(new Ipv4Prefix("172.17.2.0/24"));
244         prefs.add(new Ipv4Prefix("172.17.1.0/24"));
245         prefs.add(new Ipv4Prefix("172.17.0.0/24"));
246
247         final Nlri nlri = new NlriBuilder().setNlri(prefs).build();
248
249         assertEquals(nlri, message.getNlri());
250
251         builder.setNlri(nlri);
252
253         // check path attributes
254
255         final PathAttributes attrs = message.getPathAttributes();
256
257         final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
258
259         paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
260         assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
261
262         paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
263         assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
264
265         paBuilder.setCNextHop(nextHop);
266         assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
267
268         paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
269         assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
270
271         paBuilder.setAtomicAggregate(new AtomicAggregateBuilder().build());
272         assertEquals(paBuilder.getAtomicAggregate(), attrs.getAtomicAggregate());
273
274         paBuilder.setCommunities(comms);
275         assertEquals(paBuilder.getCommunities(), attrs.getCommunities());
276
277         builder.setPathAttributes(paBuilder.build());
278
279         assertEquals(builder.build(), message);
280
281         final ByteBuf buffer = Unpooled.buffer();
282         BGPParserTest.updateParser.serializeMessage(message, buffer);
283         assertArrayEquals(inputBytes.get(0), ByteArray.readAllBytes(buffer));
284     }
285
286     /*
287      * Tests IPv6 NEXT_HOP, NLRI, ORIGIN.IGP, MULTI_EXIT_DISC, ORIGINATOR-ID, CLUSTER_LIST.
288      *
289      * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
290      * 00 80 <- length (128) - including header
291      * 02 <- message type
292      * 00 00 <- withdrawn routes length
293      * 00 69 <- total path attribute length (105)
294      * 40 <- attribute flags
295      * 01 <- attribute type code (origin)
296      * 01 <- attribute length
297      * 00 <- Origin value (IGP)
298      * 40 <- attribute flags
299      * 02 <- attribute type code (as path)
300      * 06 <- attribute length
301      * 02 <- AS_SEQUENCE
302      * 01 <- path segment count
303      * 00 00 fd e9 <- path segment value (65001)
304      * 40 <- attribute flags
305      * 03 <- attribute type code (next hop)
306      * 04 <- attribute length
307      * 0a 00 00 00 <- next hop value (10.0.0.0)
308      * 80 <- attribute flags
309      * 04 <- attribute type code (multi exit disc)
310      * 04 <- attribute length
311      * 00 00 00 00 <- value
312      * 80 <- attribute flags
313      * 09 <- attribute type code (originator id)
314      * 04 <- attribute length
315      * 7f 00 00 01 <- value (localhost ip)
316      * 80 <- attribute flags
317      * 0a <- attribute type code (cluster list)
318      * 08 <- attribute length
319      * 01 02 03 04 <- value
320      * 05 06 07 08 <- value
321      * 80 <- attribute flags
322      * 0e <- attribute type code (mp reach nlri)
323      * 40 <- attribute length
324      * 00 02 <- AFI (Ipv6)
325      * 01 <- SAFI (Unicast)
326      * 20 <- length of next hop
327      * 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 01 <- global
328      * fe 80 00 00 00 00 00 00 c0 01 0b ff fe 7e 00 <- link local
329      * 00 <- reserved
330      *
331      * //NLRI
332      * 40 20 01 0d b8 00 01 00 02 <- IPv6 Prefix (2001:db8:1:2:: / 64)
333      * 40 20 01 0d b8 00 01 00 01 <- IPv6 Prefix (2001:db8:1:1:: / 64)
334      * 40 20 01 0d b8 00 01 00 00 <- IPv6 Prefix (2001:db8:1:: / 64)
335      *
336      */
337     @Test
338     public void testGetUpdateMessage2() throws Exception {
339         final byte[] body = ByteArray.cutBytes(inputBytes.get(1), MessageUtil.COMMON_HEADER_LENGTH);
340         final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(1), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
341         final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
342
343         // check fields
344         assertNull(message.getWithdrawnRoutes());
345
346         final UpdateBuilder builder = new UpdateBuilder();
347
348         // check NLRI
349
350         final List<Ipv6Prefix> prefs = Lists.newArrayList();
351         prefs.add(new Ipv6Prefix("2001:db8:1:2::/64"));
352         prefs.add(new Ipv6Prefix("2001:db8:1:1::/64"));
353         prefs.add(new Ipv6Prefix("2001:db8:1::/64"));
354
355         assertNull(message.getNlri());
356
357         // attributes
358
359         final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65001L)).build());
360         final List<Segments> asPath = Lists.newArrayList();
361         asPath.add(new SegmentsBuilder().setCSegment(
362             new AListCaseBuilder().setAList(new AListBuilder().setAsSequence(asnums).build()).build()).build());
363
364         final Ipv6NextHopCase nextHop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(
365             new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
366
367         final List<ClusterIdentifier> clusters = Lists.newArrayList(new ClusterIdentifier(new Ipv4Address("1.2.3.4")),
368             new ClusterIdentifier(new Ipv4Address("5.6.7.8")));
369
370         // check path attributes
371
372         final PathAttributes attrs = message.getPathAttributes();
373
374         final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
375
376         paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
377         assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
378
379         paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
380         assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
381
382         paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
383         assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
384
385         paBuilder.setOriginatorId(new OriginatorIdBuilder().setOriginator(new Ipv4Address("127.0.0.1")).build());
386         assertEquals(paBuilder.getOriginatorId(), attrs.getOriginatorId());
387
388         paBuilder.setClusterId(new ClusterIdBuilder().setCluster(clusters).build());
389         assertEquals(paBuilder.getClusterId(), attrs.getClusterId());
390
391         final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
392         mpBuilder.setAfi(Ipv6AddressFamily.class);
393         mpBuilder.setSafi(UnicastSubsequentAddressFamily.class);
394         mpBuilder.setCNextHop(nextHop);
395         mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
396             new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(prefs).build()).build()).build());
397
398         paBuilder.addAugmentation(PathAttributes1.class, new PathAttributes1Builder().setMpReachNlri(mpBuilder.build()).build());
399         assertEquals(paBuilder.getAugmentation(PathAttributes1.class).getMpReachNlri(),
400             attrs.getAugmentation(PathAttributes1.class).getMpReachNlri());
401
402         // check API message
403
404         builder.setPathAttributes(paBuilder.build());
405         assertEquals(builder.build(), message);
406
407         final ByteBuf buffer = Unpooled.buffer();
408         BGPParserTest.updateParser.serializeMessage(message, buffer);
409         assertArrayEquals(inputBytes.get(1), ByteArray.readAllBytes(buffer));
410     }
411
412     /*
413      * Tests more AS Numbers in AS_PATH, AGGREGATOR, ORIGIN.INCOMPLETE
414      *
415      * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
416      * 00 4b <- length (75) - including header
417      * 02 <- message type
418      * 00 00 <- withdrawn routes length
419      * 00 30 <- total path attribute length (48)
420      * 40 <- attribute flags
421      * 01 <- attribute type code (origin)
422      * 01 <- attribute length
423      * 02 <- Origin value (Incomplete)
424      * 40 <- attribute flags
425      * 02 <- attribute type code (as path)
426      * 10 <- attribute length
427      * 02 <- AS_SEQUENCE
428      * 01 <- path segment count
429      * 00 00 00 1e <- path segment value (30)
430      * 01 <- AS_SET
431      * 02 <- path segment count
432      * 00 00 00 0a <- path segment value (10)
433      * 00 00 00 14 <- path segment value (20)
434      * 40 <- attribute flags
435      * 03 <- attribute type (Next hop)
436      * 04 <- attribute length
437      * 0a 00 00 09 <- value (10.0.0.9)
438      * 80 <- attribute flags
439      * 04 <- attribute type code (multi exit disc)
440      * 04 <- attribute length
441      * 00 00 00 00 <- value
442      * c0 <- attribute flags
443      * 07 <- attribute type (Aggregator)
444      * 08 <- attribute length
445      * 00 00 00 1e <- value (AS number = 30)
446      * 0a 00 00 09 <- value (IP address = 10.0.0.9)
447      *
448      * //NLRI
449      * 15 ac 10 00 <- IPv4 Prefix (172.16.0.0 / 21)
450      */
451     @Test
452     public void testGetUpdateMessage3() throws Exception {
453         final byte[] body = ByteArray.cutBytes(inputBytes.get(2), MessageUtil.COMMON_HEADER_LENGTH);
454         final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(2), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
455         final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
456
457         final UpdateBuilder builder = new UpdateBuilder();
458
459         // check nlri
460         final Ipv4Prefix pref1 = new Ipv4Prefix("172.16.0.0/21");
461
462         final List<Ipv4Prefix> nlri = Lists.newArrayList(pref1);
463         builder.setNlri(new NlriBuilder().setNlri(nlri).build());
464         assertEquals(builder.getNlri(), message.getNlri());
465
466         // check fields
467         assertNull(message.getWithdrawnRoutes());
468
469         // attributes
470         final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(30L)).build());
471         final List<Segments> asPath = Lists.newArrayList();
472         asPath.add(new SegmentsBuilder().setCSegment(
473             new AListCaseBuilder().setAList(new AListBuilder().setAsSequence(asnums).build()).build()).build());
474         asPath.add(new SegmentsBuilder().setCSegment(
475             new ASetCaseBuilder().setASet(new ASetBuilder().setAsSet(Lists.newArrayList(new AsNumber(10L), new AsNumber(20L))).build()).build()).build());
476
477         final Aggregator aggregator = new AggregatorBuilder().setAsNumber(new AsNumber((long) 30)).setNetworkAddress(
478             new Ipv4Address("10.0.0.9")).build();
479         final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
480             new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.9")).build()).build();
481
482         // check path attributes
483         final PathAttributes attrs = message.getPathAttributes();
484
485         final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
486
487         paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Incomplete).build());
488         assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
489
490         paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
491         assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
492
493         paBuilder.setCNextHop(nextHop);
494         assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
495
496         paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
497         assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
498
499         paBuilder.setAggregator(aggregator);
500         assertEquals(paBuilder.getAggregator(), attrs.getAggregator());
501
502         builder.setPathAttributes(paBuilder.build());
503
504         assertEquals(builder.build(), message);
505
506         final ByteBuf buffer = Unpooled.buffer();
507         BGPParserTest.updateParser.serializeMessage(message, buffer);
508         assertArrayEquals(inputBytes.get(2), ByteArray.readAllBytes(buffer));
509     }
510
511     /*
512      * Tests empty AS_PATH, ORIGIN.EGP, LOCAL_PREF, EXTENDED_COMMUNITIES (Ipv4 Addr specific)
513      *
514      * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
515      * 00 4A <- length (73) - including header
516      * 02 <- message type
517      * 00 00 <- withdrawn routes length
518      * 00 27 <- total path attribute length (39)
519      * 40 <- attribute flags
520      * 01 <- attribute type code (Origin)
521      * 01 <- attribute length
522      * 01 <- Origin value (EGP)
523      * 40 <- attribute flags
524      * 02 <- attribute type code (As path)
525      * 00 <- attribute length
526      * 40 <- attribute flags
527      * 03 <- attribute type (Next hop)
528      * 04 <- attribute length
529      * 03 03 03 03 <- value (3.3.3.3)
530      * 80 <- attribute flags
531      * 04 <- attribute type code (Multi exit disc)
532      * 04 <- attribute length
533      * 00 00 00 00 <- value
534      * 40 <- attribute flags
535      * 05 <- attribute type (Local Pref)
536      * 04 <- attribute length
537      * 00 00 00 64 <- value (100)
538      * c0 <- attribute flags
539      * 10 <- attribute type (extended community)
540      * 08 <- attribute length
541      * 01 04 <- value (type - Ipv4 Address Specific Extended Community)
542      * c0 a8 01 00 <- value (global adm. 198.162.1.0)
543      * 12 34 <- value (local adm. 4660)
544      *
545      * //NLRI
546      * 18 0a 1e 03 <- IPv4 Prefix (10.30.3.0 / 24)
547      * 18 0a 1e 02 <- IPv4 Prefix (10.30.2.0 / 24)
548      * 18 0a 1e 01 <- IPv4 Prefix (10.30.1.0 / 24)
549      */
550     @Test
551     public void testGetUpdateMessage4() throws Exception {
552         final byte[] body = ByteArray.cutBytes(inputBytes.get(3), MessageUtil.COMMON_HEADER_LENGTH);
553         final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(3), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
554         final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
555
556         final UpdateBuilder builder = new UpdateBuilder();
557
558         // check fields
559         assertNull(message.getWithdrawnRoutes());
560
561         // check nlri
562         final Ipv4Prefix pref1 = new Ipv4Prefix("10.30.3.0/24");
563         final Ipv4Prefix pref2 = new Ipv4Prefix("10.30.2.0/24");
564         final Ipv4Prefix pref3 = new Ipv4Prefix("10.30.1.0/24");
565
566         final List<Ipv4Prefix> nlri = Lists.newArrayList(pref1, pref2, pref3);
567         builder.setNlri(new NlriBuilder().setNlri(nlri).build());
568         assertEquals(builder.getNlri(), message.getNlri());
569
570         // attributes
571         final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
572             new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("3.3.3.3")).build()).build();
573
574         final List<ExtendedCommunities> comms = Lists.newArrayList();
575         comms.add(new ExtendedCommunitiesBuilder().setCommType((short) 1).setCommSubType((short) 4).setExtendedCommunity(
576             new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
577                 new Inet4SpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(
578                     new Ipv4Address("192.168.1.0")).setLocalAdministrator(new byte[] { 0x12, 0x34 }).build()).build()).build());
579
580         // check path attributes
581         final PathAttributes attrs = message.getPathAttributes();
582
583         final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
584
585         paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build());
586         assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
587
588         paBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.<Segments> emptyList()).build());
589         assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
590
591         paBuilder.setCNextHop(nextHop);
592         assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
593
594         paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
595         assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
596
597         paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
598         assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
599
600         paBuilder.setExtendedCommunities(comms);
601         assertEquals(paBuilder.getExtendedCommunities(), attrs.getExtendedCommunities());
602
603         // check API message
604         builder.setPathAttributes(paBuilder.build());
605         assertEquals(builder.build(), message);
606
607         final ByteBuf buffer = Unpooled.buffer();
608         BGPParserTest.updateParser.serializeMessage(message, buffer);
609         assertArrayEquals(inputBytes.get(3), ByteArray.readAllBytes(buffer));
610     }
611
612     /*
613      * Tests withdrawn routes.
614      *
615      * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
616      * 00 1c <- length (28) - including header
617      * 02 <- message type
618      * 00 05 <- withdrawn routes length (5)
619      * 1e ac 10 00 04 <- route (172.16.0.4)
620      * 00 00 <- total path attribute length
621      */
622     @Test
623     public void testGetUpdateMessage5() throws Exception {
624         final byte[] body = ByteArray.cutBytes(inputBytes.get(4), MessageUtil.COMMON_HEADER_LENGTH);
625         final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(4), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
626         final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
627
628         // attributes
629         final List<Ipv4Prefix> prefs = Lists.newArrayList(new Ipv4Prefix("172.16.0.4/30"));
630
631         // check API message
632         final Update expectedMessage = new UpdateBuilder().setWithdrawnRoutes(
633             new WithdrawnRoutesBuilder().setWithdrawnRoutes(prefs).build()).build();
634
635         assertEquals(expectedMessage.getWithdrawnRoutes(), message.getWithdrawnRoutes());
636
637         final ByteBuf buffer = Unpooled.buffer();
638         BGPParserTest.updateParser.serializeMessage(message, buffer);
639         assertArrayEquals(inputBytes.get(4), ByteArray.readAllBytes(buffer));
640     }
641
642     /*
643      * End of Rib for Ipv4.
644      *
645      * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
646      * 00 17 <- length (23) - including header
647      * 02 <- message type
648      * 00 00 <- withdrawn routes length
649      * 00 00 <- total path attribute length
650      */
651     @Test
652     public void testEORIpv4() throws Exception {
653         final byte[] body = ByteArray.cutBytes(inputBytes.get(5), MessageUtil.COMMON_HEADER_LENGTH);
654         final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(5), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
655         final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
656
657         assertEquals(new UpdateBuilder().build(), message);
658
659         final ByteBuf buffer = Unpooled.buffer();
660         BGPParserTest.updateParser.serializeMessage(message, buffer);
661         assertArrayEquals(inputBytes.get(5), ByteArray.readAllBytes(buffer));
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     public void testEORIpv6() throws Exception {
680         final byte[] body = ByteArray.cutBytes(inputBytes.get(6), MessageUtil.COMMON_HEADER_LENGTH);
681         final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(6), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
682         final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
683
684         final Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getAfi();
685         final Class<? extends SubsequentAddressFamily> safi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getSafi();
686
687         assertEquals(Ipv6AddressFamily.class, afi);
688         assertEquals(UnicastSubsequentAddressFamily.class, safi);
689
690         final ByteBuf buffer = Unpooled.buffer();
691         BGPParserTest.updateParser.serializeMessage(message, buffer);
692         assertArrayEquals(inputBytes.get(6), ByteArray.readAllBytes(buffer));
693     }
694
695     /*
696      * End of Rib for Ipv6 consists of empty MP_UNREACH_NLRI, with AFI 2 and SAFI 1
697      *
698      * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
699      * 00 1e <- length (29) - including header
700      * 02 <- message type
701      * 00 00 <- withdrawn routes length
702      * 00 07 <- total path attribute length
703      * 90 <- attribute flags
704      * 0f <- attribute type (15 - MP_UNREACH_NLRI)
705      * 00 03 <- attribute length
706      * 00 02 <- value (AFI 2: IPv6)
707      * 01 <- value (SAFI 1)
708      */
709     @Test
710     public void testEORIpv6exLength() throws Exception {
711         final byte[] body = ByteArray.cutBytes(inputBytes.get(6), MessageUtil.COMMON_HEADER_LENGTH);
712         final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(6), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
713         final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
714
715         final Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getAfi();
716         final Class<? extends SubsequentAddressFamily> safi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getSafi();
717
718         assertEquals(Ipv6AddressFamily.class, afi);
719         assertEquals(UnicastSubsequentAddressFamily.class, safi);
720
721         final ByteBuf buffer = Unpooled.buffer();
722         BGPParserTest.updateParser.serializeMessage(message, buffer);
723         assertArrayEquals(inputBytes.get(6), ByteArray.readAllBytes(buffer));
724     }
725
726     /*
727      * End of Rib for LS consists of empty MP_UNREACH_NLRI, with AFI 16388 and SAFI 71
728      *
729      * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
730      * 00 1d <- length (29) - including header
731      * 02 <- message type
732      * 00 00 <- withdrawn routes length
733      * 00 06 <- total path attribute length
734      * 80 <- attribute flags
735      * 0f <- attribute type (15 - MP_UNREACH_NLRI)
736      * 03 <- attribute length
737      * 40 04 <- value (AFI 16388: LS)
738      * 47 <- value (SAFI 71)
739      */
740     @Test
741     public void testEORLS() throws Exception {
742         final byte[] body = ByteArray.cutBytes(inputBytes.get(7), MessageUtil.COMMON_HEADER_LENGTH);
743         final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(7), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
744         final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
745
746         final Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getAfi();
747         final Class<? extends SubsequentAddressFamily> safi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getSafi();
748
749         assertEquals(LinkstateAddressFamily.class, afi);
750         assertEquals(LinkstateSubsequentAddressFamily.class, safi);
751
752         final ByteBuf buffer = Unpooled.buffer();
753         BGPParserTest.updateParser.serializeMessage(message, buffer);
754         assertArrayEquals(inputBytes.get(7), ByteArray.readAllBytes(buffer));
755     }
756
757     /*
758      * Tests BGP Link Ipv4
759      *
760      * 00 00 <- withdrawn routes length
761      * 01 48 <- total path attribute length (328)
762      * 90 <- attribute flags
763         0e <- attribute type code (MP reach)
764         01 2c <- attribute extended length (300)
765         40 04 <- AFI (16388 - Linkstate)
766         47 <- SAFI (71 - Linkstate)
767         04 <- next hop length
768         19 19 19 01 <- nexthop (25.25.25.1)
769         00 <- reserved
770
771         00 02 <- NLRI type (2 - linkNLRI)
772         00 5d <- NLRI length (93)
773         03 <- ProtocolID - OSPF
774         00 00 00 00 00 00 00 01 <- identifier
775
776         01 00 <- local node descriptor type (256)
777         00 24 <- length (36)
778         02 00 <- node descriptor type (member AS - 512)
779         00 04 <- length
780         00 00 00 64 <- value (100)
781         02 01 <- node descriptor type (bgpId - 513)
782         00 04 <- length
783         19 19 19 01 <- bgpId (25.25.25.1)
784         02 02 <- node descriptor type (areaId - 514)
785         00 04 <- length
786         00 00 00 00 <- value
787         02 03 <- node descriptor type (routeId - 515)
788         00 08 <- length
789         03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
790
791         01 01 <- remote node descriptor type (257)
792         00 20 <- length (32)
793         02 00 <- node descriptor type (member AS - 512)
794         00 04 <- length
795         00 00 00 64 <- value (100)
796         02 01 <- node descriptor type (bgpId - 513)
797         00 04 <- length
798         19 19 19 01 <- bgpId (25.25.25.1)
799         02 02 <- node descriptor type (areaId - 514)
800         00 04 <- length
801         00 00 00 00 <- value
802         02 03 <- node descriptor type (routeId - 515)
803         00 04 <- length
804         03 03 03 04 <- OSPF Router Id
805
806         01 03 <- link descriptor type (IPv4 interface address - 259)
807         00 04 <- length (4)
808         0b 0b 0b 03 <- value (11.11.11.3)
809
810         00 02 <- NLRI type (2 - linkNLRI)
811         00 5d <- NLRI length (93)
812         03 <- ProtocolID - OSPF
813         00 00 00 00 00 00 00 01 <- identifier
814
815         01 00 <- local node descriptor type (256)
816         00 24 <- length (36)
817         02 00 <- node descriptor type (member AS - 512)
818         00 04 <- length
819         00 00 00 64 <- value (100)
820         02 01 <- node descriptor type (bgpId - 513)
821         00 04 <- length
822         19 19 19 01 <- bgpId (25.25.25.1)
823         02 02 <- node descriptor type (areaId - 514)
824         00 04 <- length
825         00 00 00 00 <- value
826         02 03 <- node descriptor type (routeId - 515)
827         00 08 <- length
828         03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
829
830         01 01 <- remote node descriptor type (257)
831         00 20 <- length (32)
832         02 00 <- node descriptor type (member AS - 512)
833         00 04 <- length
834         00 00 00 64 <- value (100)
835         02 01 <- node descriptor type (bgpId - 513)
836         00 04 <- length
837         19 19 19 01 <- bgpId (25.25.25.1)
838         02 02 <- node descriptor type (areaId - 514)
839         00 04 <- length
840         00 00 00 00 <- value
841         02 03 <- node descriptor type (routeId - 515)
842         00 04 <- length
843         01 01 01 02 <- OSPF Router Id
844
845         01 03 <- link descriptor type (IPv4 interface address - 259)
846         00 04 <- length
847         0b 0b 0b 01 <- value (11.11.11.1)
848
849         00 02 <- NLRI type (2 - linkNLRI)
850         00 5d <- NLRI length (93)
851         03 <- ProtocolID - OSPF
852         00 00 00 00 00 00 00 01 <- identifier
853
854         01 00 <- local node descriptor type (256)
855         00 20 <- length (32)
856         02 00 <- node descriptor type (member AS - 512)
857         00 04 <- length
858         00 00 00 64 <- value (100)
859         02 01 <- node descriptor type (bgpId - 513)
860         00 04 <- length
861         19 19 19 01 <- bgpId (25.25.25.1)
862         02 02 <- node descriptor type (areaId - 514)
863         00 04 <- length
864         00 00 00 00 <- value
865         02 03 <- node descriptor type (routeId - 515)
866         00 04 <- length
867         01 01 01 02 <- OSPF Router Id
868
869         01 01 <- remote node descriptor type (257)
870         00 24 <- length (36)
871         02 00 <- node descriptor type (member AS - 512)
872         00 04 <- length
873         00 00 00 64 <- value (100)
874         02 01 <- node descriptor type (bgpId - 513)
875         00 04 <- length
876         19 19 19 01 <- bgpId (25.25.25.1)
877         02 02 <- node descriptor type (areaId - 514)
878         00 04 <- length
879         00 00 00 00 <- value
880         02 03 <- node descriptor type (routeId - 515)
881         00 08 <- length
882         03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
883
884         01 03 <- link descriptor type (IPv4 interface address - 259)
885         00 04 <- length
886         0b 0b 0b 01 <- value (11.11.11.1)
887
888         40 <- attribute flags
889         01 <- attribute type (Origin)
890         01 <- attribute length
891         00 <- value (IGP)
892         40 <- attribute flags
893         02 <- attribute type (AS Path)
894         00 <- length
895         40 <- attribute flags
896         05 <- attribute type (local pref)
897         04 <- length
898         00 00 00 64 <- value
899         c0 <- attribute flags
900         1D <- attribute type (Link STATE - 29)
901         07 <- length
902         04 47 <- link attribute (1095 - Metric)
903         00 03 <- length
904         00 00 01 <- value
905      */
906     @Test
907     public void testBGPLink() throws Exception {
908         final byte[] body = ByteArray.cutBytes(inputBytes.get(8), MessageUtil.COMMON_HEADER_LENGTH);
909         final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(8), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
910         final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
911
912         final UpdateBuilder builder = new UpdateBuilder();
913
914         // check fields
915
916         assertNull(message.getWithdrawnRoutes());
917
918         final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
919             new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
920
921         final LocalNodeDescriptorsBuilder lndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
922             new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
923
924         final RemoteNodeDescriptorsBuilder rndBuilder = new RemoteNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
925             new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
926
927         final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
928         clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
929         clBuilder.setNlriType(NlriType.Link);
930         clBuilder.setProtocolId(ProtocolId.Ospf);
931
932         final PathAttributes1Builder lsBuilder = new PathAttributes1Builder();
933         final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
934         mpBuilder.setAfi(LinkstateAddressFamily.class);
935         mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
936         mpBuilder.setCNextHop(nextHop);
937
938         final List<CLinkstateDestination> linkstates = Lists.newArrayList();
939         clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
940             new OspfPseudonodeCaseBuilder().setOspfPseudonode(
941                 new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
942         clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
943             new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x03030304L).build()).build()).build());
944         clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
945             new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.3"))).build());
946         linkstates.add(clBuilder.build());
947
948         clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
949             new OspfPseudonodeCaseBuilder().setOspfPseudonode(
950                 new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
951         clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
952             new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
953         clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
954             new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
955         linkstates.add(clBuilder.build());
956
957         clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
958             new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
959         clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
960             new OspfPseudonodeCaseBuilder().setOspfPseudonode(
961                 new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
962         clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
963             new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
964         linkstates.add(clBuilder.build());
965
966         lsBuilder.setMpReachNlri(mpBuilder.build());
967
968         // check path attributes
969         final PathAttributes attrs = message.getPathAttributes();
970
971         final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
972
973         paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
974         assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
975
976         paBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.<Segments> emptyList()).build());
977         assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
978
979         paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
980         assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
981
982         final MpReachNlri mp = attrs.getAugmentation(PathAttributes1.class).getMpReachNlri();
983         assertEquals(mpBuilder.getAfi(), mp.getAfi());
984         assertEquals(mpBuilder.getSafi(), mp.getSafi());
985         assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
986
987         final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
988         dBuilder.setCLinkstateDestination(linkstates);
989
990         mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
991             new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
992         lsBuilder.setMpReachNlri(mpBuilder.build());
993
994         paBuilder.addAugmentation(PathAttributes1.class, lsBuilder.build());
995
996         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.PathAttributes1Builder lsAttrBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.PathAttributes1Builder();
997
998         lsAttrBuilder.setLinkstatePathAttribute(new LinkstatePathAttributeBuilder().setLinkStateAttribute(
999             new LinkAttributesCaseBuilder().setLinkAttributes(new LinkAttributesBuilder().setMetric(new Metric(1L)).build()).build()).build());
1000         paBuilder.addAugmentation(
1001             org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.PathAttributes1.class,
1002             lsAttrBuilder.build());
1003
1004         assertEquals(
1005             lsAttrBuilder.build().getLinkstatePathAttribute(),
1006             attrs.getAugmentation(
1007                 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.PathAttributes1.class).getLinkstatePathAttribute());
1008
1009         final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mp.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
1010
1011         assertEquals(linkstates.size(), dests.size());
1012
1013         assertEquals(linkstates, dests);
1014         // check API message
1015         builder.setPathAttributes(paBuilder.build());
1016         assertEquals(builder.build(), message);
1017
1018         final ByteBuf buffer = Unpooled.buffer();
1019         BGPParserTest.updateParser.serializeMessage(message, buffer);
1020         assertArrayEquals(inputBytes.get(8), ByteArray.readAllBytes(buffer));
1021     }
1022
1023     /*
1024      * TEST BGP Node
1025      *
1026      *  00 00 <- withdrawn routes length
1027         00 b1 <- total path attribute length (177)
1028         80 <- attribute flags
1029         0e <- attribute type code (MP reach)
1030         a0 <- attribute length (160)
1031         40 04 <- AFI (16388 - Linkstate)
1032         47 <- SAFI (71 - Linkstate)
1033         04 <- next hop length
1034         19 19 19 01 - nexthop (25.25.25.1)
1035         00 <- reserved
1036
1037         00 01 <- NLRI type (1 - nodeNLRI)
1038         00 31 <- NLRI length (49)
1039         03 <- ProtocolID - OSPF
1040         00 00 00 00 00 00 00 01 <- identifier
1041         01 00 <- local node descriptor type (256)
1042         00 24 <- length (36)
1043         02 00 <- node descriptor type (member AS - 512)
1044         00 04 <- length
1045         00 00 00 64 <- value (100)
1046         02 01 <- node descriptor type (bgpId - 513)
1047         00 04 <- length
1048         19 19 19 01 <- bgpId (25.25.25.1)
1049         02 02 <- node descriptor type (areaId - 514)
1050         00 04 <- length
1051         00 00 00 00 <- value
1052         02 03 <- node descriptor type (routeId - 515)
1053         00 08 <- length
1054         03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
1055
1056         00 01 <- NLRI type (1 - nodeNLRI)
1057         00 2d <- NLRI length (45)
1058         03 <- ProtocolID - OSPF
1059         00 00 00 00 00 00 00 01 <- identifier
1060         01 00 <- local node descriptor type (256)
1061         00 20 <- length (32)
1062         02 00 <- node descriptor type (member AS - 512)
1063         00 04 <- length
1064         00 00 00 64 <- value (100)
1065         02 01 <- node descriptor type (bgpId - 513)
1066         00 04 <- length
1067         19 19 19 01 <- bgpId (25.25.25.1)
1068         02 02 <- node descriptor type (areaId - 514)
1069         00 04 <- length
1070         00 00 00 00 <- value
1071         02 03 <- node descriptor type (routeId - 515)
1072         00 04 <- length
1073         03 03 03 04 <- OSPF Router Id
1074
1075         00 01 <- NLRI type (1 - nodeNLRI)
1076         00 2d <- NLRI length (45)
1077         03 <- ProtocolID - OSPF
1078         00 00 00 00 00 00 00 01 <- identifier
1079         01 00 <- local node descriptor type (256)
1080         00 20 <- length (32)
1081         02 00 <- node descriptor type (member AS - 512)
1082         00 04 <- length
1083         00 00 00 64 <- value (100)
1084         02 01 <- node descriptor type (bgpId - 513)
1085         00 04 <- length
1086         19 19 19 01 <- bgpId (25.25.25.1)
1087         02 02 <- node descriptor type (areaId - 514)
1088         00 04 <- length
1089         00 00 00 00 <- value
1090         02 03 <- node descriptor type (routeId - 515)
1091         00 04 <- length
1092         01 01 01 02  <- OSPF Router Id
1093
1094         40 <- attribute flags
1095         01 <- attribute type (Origin)
1096         01 <- attribute length
1097         00 <- value (IGP)
1098         40 <- attribute flags
1099         02 <- attribute type (AS Path)
1100         00 <- length
1101         40 <- attribute flags
1102         05 <- attribute type (local pref)
1103         04 <- length
1104         00 00 00 64 <- value
1105      */
1106     @Test
1107     public void testBGPNode() throws Exception {
1108         final byte[] body = ByteArray.cutBytes(inputBytes.get(9), MessageUtil.COMMON_HEADER_LENGTH);
1109         final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(9), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
1110         final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
1111
1112         final UpdateBuilder builder = new UpdateBuilder();
1113
1114         // check fields
1115
1116         assertNull(message.getWithdrawnRoutes());
1117
1118         // attributes
1119
1120         final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
1121             new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
1122
1123         final LocalNodeDescriptorsBuilder lndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
1124             new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
1125
1126         final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
1127         clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
1128         clBuilder.setNlriType(NlriType.Node);
1129         clBuilder.setProtocolId(ProtocolId.Ospf);
1130
1131         final List<CLinkstateDestination> linkstates = Lists.newArrayList();
1132         clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
1133             new OspfPseudonodeCaseBuilder().setOspfPseudonode(
1134                 new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
1135         linkstates.add(clBuilder.build());
1136
1137         clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
1138             new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x03030304L).build()).build()).build());
1139         linkstates.add(clBuilder.build());
1140
1141         clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
1142             new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
1143         linkstates.add(clBuilder.build());
1144
1145         final PathAttributes1Builder lsBuilder = new PathAttributes1Builder();
1146         final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
1147         mpBuilder.setAfi(LinkstateAddressFamily.class);
1148         mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
1149         mpBuilder.setCNextHop(nextHop);
1150
1151         final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
1152         dBuilder.setCLinkstateDestination(linkstates);
1153
1154         mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
1155             new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
1156         lsBuilder.setMpReachNlri(mpBuilder.build());
1157
1158         // check path attributes
1159         final PathAttributes attrs = message.getPathAttributes();
1160
1161         final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
1162
1163         paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
1164         assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
1165
1166         paBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.<Segments> emptyList()).build());
1167         assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
1168
1169         paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
1170         assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
1171
1172         paBuilder.addAugmentation(PathAttributes1.class, lsBuilder.build());
1173
1174         final MpReachNlri mp = attrs.getAugmentation(PathAttributes1.class).getMpReachNlri();
1175         assertEquals(mpBuilder.getAfi(), mp.getAfi());
1176         assertEquals(mpBuilder.getSafi(), mp.getSafi());
1177         assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
1178
1179         final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mp.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
1180
1181         assertEquals(linkstates.size(), dests.size());
1182
1183         assertEquals(linkstates, dests);
1184
1185         // check API message
1186         builder.setPathAttributes(paBuilder.build());
1187         assertEquals(builder.build(), message);
1188
1189         final ByteBuf buffer = Unpooled.buffer();
1190         BGPParserTest.updateParser.serializeMessage(message, buffer);
1191         assertArrayEquals(inputBytes.get(9), ByteArray.readAllBytes(buffer));
1192     }
1193
1194     /*
1195      * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
1196      * 00 3d <- length (61) - including header
1197      * 01 <- message type
1198      * 04 <- BGP version
1199      * 00 64 <- My AS Number (AS TRANS in this case)
1200      * 00 b4 <- Hold Time
1201      * 00 00 00 00 <- BGP Identifier
1202      * 20 <- Optional Parameters Length
1203      * 02 <- opt. param. type (capabilities)
1204      * 06 <- length
1205      * 01 <- capability code (MP Extensions for BGP4)
1206      * 04 <- length
1207      * 00 01 00 01 <- AFI 1, SAFI 1
1208      * 02 <- opt. param. type (capabilities)
1209      * 06 <- length
1210      * 01 <- capability code (MP Extensions for BGP4)
1211      * 04 <- length
1212      * 00 02 00 01 <- AFI 2, SAFI 1
1213      * 02 <- opt. param. type (capabilities)
1214      * 06 <- length
1215      * 01 <- capability code (MP Extensions for BGP4)
1216      * 04 <- length
1217      * 40 04 00 47 <- AFI 16388, SAFI 71
1218      * 02 <- opt. param. type (capabilities)
1219      * 06 <- length
1220      * 41 <- capability code (AS4 octet support)
1221      * 04 <- length
1222      * 00 00 00 64 <- AS number
1223      */
1224     @Test
1225     public void testOpenMessage() throws Exception {
1226         final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry();
1227         final Notification o = msgReg.parseMessage(Unpooled.copiedBuffer(inputBytes.get(13)));
1228         final Open open = (Open) o;
1229         final Set<BgpTableType> types = Sets.newHashSet();
1230         for (final BgpParameters param : open.getBgpParameters()) {
1231             for (final OptionalCapabilities optCapa : param.getOptionalCapabilities()) {
1232                 final CParameters p = optCapa.getCParameters();
1233                 if (p instanceof MultiprotocolCase) {
1234                     final BgpTableType type = new BgpTableTypeImpl(((MultiprotocolCase) p).getMultiprotocolCapability().getAfi(), ((MultiprotocolCase) p).getMultiprotocolCapability().getSafi());
1235                     types.add(type);
1236                 }
1237             }
1238         }
1239         final Set<BgpTableType> expected = Sets.newHashSet();
1240         expected.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
1241         expected.add(new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class));
1242         expected.add(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
1243         assertEquals(expected, types);
1244
1245         final ByteBuf buffer = Unpooled.buffer();
1246         msgReg.serializeMessage(o, buffer);
1247         assertArrayEquals(inputBytes.get(13), ByteArray.readAllBytes(buffer));
1248     }
1249 }