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