2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.bgp.linkstate;
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;
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;
27 import org.junit.Before;
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.spi.MessageRegistry;
32 import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
33 import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
34 import org.opendaylight.protocol.util.ByteArray;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.AreaIdentifier;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.DomainIdentifier;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Identifier;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv4InterfaceIdentifier;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateSubsequentAddressFamily;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.OspfInterfaceIdentifier;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestination;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestinationBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.LinkCaseBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCaseBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LinkDescriptorsBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LocalNodeDescriptorsBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.RemoteNodeDescriptorsBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.node._case.NodeDescriptorsBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.LinkAttributesCaseBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributesBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfNodeCaseBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfPseudonodeCaseBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.ospf.node._case.OspfNodeBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonodeBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCaseBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Open;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.UpdateBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.BgpParameters;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.bgp.parameters.OptionalCapabilities;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.bgp.parameters.optional.capabilities.CParameters;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.AsPathBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.LocalPrefBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.OriginBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.UnrecognizedAttributes;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.as.path.Segments;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1Builder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.optional.capabilities.c.parameters.MultiprotocolCase;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlri;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlriBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
91 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;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric;
93 import org.opendaylight.yangtools.yang.binding.Notification;
95 public class ParserTest {
98 * Used by other tests as well
100 static final List<byte[]> inputBytes = new ArrayList<byte[]>();
102 private static int COUNTER = 4;
104 private static int MAX_SIZE = 300;
106 private static BGPUpdateMessageParser updateParser;
108 private static final int LENGTH_FIELD_LENGTH = 2;
111 public void setUp() throws Exception {
112 updateParser = new BGPUpdateMessageParser(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry());
113 for (int i = 1; i <= COUNTER; i++) {
114 final String name = "/up" + i + ".bin";
115 try (final InputStream is = ParserTest.class.getResourceAsStream(name)){
117 throw new IOException("Failed to get resource " + name);
119 final ByteArrayOutputStream bis = new ByteArrayOutputStream();
120 final byte[] data = new byte[MAX_SIZE];
122 while ((nRead = is.read(data, 0, data.length)) != -1) {
123 bis.write(data, 0, nRead);
127 inputBytes.add(bis.toByteArray());
135 public void testResource() {
136 assertNotNull(inputBytes);
140 * End of Rib for LS consists of empty MP_UNREACH_NLRI, with AFI 16388 and SAFI 71
142 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
143 * 00 1d <- length (29) - including header
145 * 00 00 <- withdrawn routes length
146 * 00 06 <- total path attribute length
147 * 80 <- attribute flags
148 * 0f <- attribute type (15 - MP_UNREACH_NLRI)
149 * 03 <- attribute length
150 * 40 04 <- value (AFI 16388: LS)
151 * 47 <- value (SAFI 71)
154 public void testEORLS() throws Exception {
155 final byte[] body = ByteArray.cutBytes(inputBytes.get(0), MessageUtil.COMMON_HEADER_LENGTH);
156 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(0), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
157 final Update message = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
159 final Class<? extends AddressFamily> afi = message.getAttributes().getAugmentation(Attributes2.class).getMpUnreachNlri().getAfi();
160 final Class<? extends SubsequentAddressFamily> safi = message.getAttributes().getAugmentation(Attributes2.class).getMpUnreachNlri().getSafi();
162 assertEquals(LinkstateAddressFamily.class, afi);
163 assertEquals(LinkstateSubsequentAddressFamily.class, safi);
165 final ByteBuf buffer = Unpooled.buffer();
166 ParserTest.updateParser.serializeMessage(message, buffer);
167 assertArrayEquals(inputBytes.get(0), ByteArray.readAllBytes(buffer));
171 * Tests BGP Link Ipv4
173 * 00 00 <- withdrawn routes length
174 * 01 48 <- total path attribute length (328)
175 * 90 <- attribute flags
176 0e <- attribute type code (MP reach)
177 01 2c <- attribute extended length (300)
178 40 04 <- AFI (16388 - Linkstate)
179 47 <- SAFI (71 - Linkstate)
180 04 <- next hop length
181 19 19 19 01 <- nexthop (25.25.25.1)
184 00 02 <- NLRI type (2 - linkNLRI)
185 00 5d <- NLRI length (93)
186 03 <- ProtocolID - OSPF
187 00 00 00 00 00 00 00 01 <- identifier
189 01 00 <- local node descriptor type (256)
191 02 00 <- node descriptor type (member AS - 512)
193 00 00 00 64 <- value (100)
194 02 01 <- node descriptor type (bgpId - 513)
196 19 19 19 01 <- bgpId (25.25.25.1)
197 02 02 <- node descriptor type (areaId - 514)
200 02 03 <- node descriptor type (routeId - 515)
202 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
204 01 01 <- remote node descriptor type (257)
206 02 00 <- node descriptor type (member AS - 512)
208 00 00 00 64 <- value (100)
209 02 01 <- node descriptor type (bgpId - 513)
211 19 19 19 01 <- bgpId (25.25.25.1)
212 02 02 <- node descriptor type (areaId - 514)
215 02 03 <- node descriptor type (routeId - 515)
217 03 03 03 04 <- OSPF Router Id
219 01 03 <- link descriptor type (IPv4 interface address - 259)
221 0b 0b 0b 03 <- value (11.11.11.3)
223 00 02 <- NLRI type (2 - linkNLRI)
224 00 5d <- NLRI length (93)
225 03 <- ProtocolID - OSPF
226 00 00 00 00 00 00 00 01 <- identifier
228 01 00 <- local node descriptor type (256)
230 02 00 <- node descriptor type (member AS - 512)
232 00 00 00 64 <- value (100)
233 02 01 <- node descriptor type (bgpId - 513)
235 19 19 19 01 <- bgpId (25.25.25.1)
236 02 02 <- node descriptor type (areaId - 514)
239 02 03 <- node descriptor type (routeId - 515)
241 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
243 01 01 <- remote node descriptor type (257)
245 02 00 <- node descriptor type (member AS - 512)
247 00 00 00 64 <- value (100)
248 02 01 <- node descriptor type (bgpId - 513)
250 19 19 19 01 <- bgpId (25.25.25.1)
251 02 02 <- node descriptor type (areaId - 514)
254 02 03 <- node descriptor type (routeId - 515)
256 01 01 01 02 <- OSPF Router Id
258 01 03 <- link descriptor type (IPv4 interface address - 259)
260 0b 0b 0b 01 <- value (11.11.11.1)
262 00 02 <- NLRI type (2 - linkNLRI)
263 00 5d <- NLRI length (93)
264 03 <- ProtocolID - OSPF
265 00 00 00 00 00 00 00 01 <- identifier
267 01 00 <- local node descriptor type (256)
269 02 00 <- node descriptor type (member AS - 512)
271 00 00 00 64 <- value (100)
272 02 01 <- node descriptor type (bgpId - 513)
274 19 19 19 01 <- bgpId (25.25.25.1)
275 02 02 <- node descriptor type (areaId - 514)
278 02 03 <- node descriptor type (routeId - 515)
280 01 01 01 02 <- OSPF Router Id
282 01 01 <- remote node descriptor type (257)
284 02 00 <- node descriptor type (member AS - 512)
286 00 00 00 64 <- value (100)
287 02 01 <- node descriptor type (bgpId - 513)
289 19 19 19 01 <- bgpId (25.25.25.1)
290 02 02 <- node descriptor type (areaId - 514)
293 02 03 <- node descriptor type (routeId - 515)
295 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
297 01 03 <- link descriptor type (IPv4 interface address - 259)
299 0b 0b 0b 01 <- value (11.11.11.1)
301 40 <- attribute flags
302 01 <- attribute type (Origin)
303 01 <- attribute length
305 40 <- attribute flags
306 02 <- attribute type (AS Path)
308 40 <- attribute flags
309 05 <- attribute type (local pref)
312 c0 <- attribute flags
313 1D <- attribute type (Link STATE - 29)
315 04 47 <- link attribute (1095 - Metric)
320 public void testBGPLink() throws Exception {
321 final byte[] body = ByteArray.cutBytes(inputBytes.get(1), MessageUtil.COMMON_HEADER_LENGTH);
322 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(1), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
323 final Update message = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
325 final UpdateBuilder builder = new UpdateBuilder();
329 assertNull(message.getWithdrawnRoutes());
331 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
332 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
334 final LocalNodeDescriptorsBuilder ndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
335 new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
337 final RemoteNodeDescriptorsBuilder rdBuilder = new RemoteNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
338 new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
340 final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
341 clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
342 clBuilder.setProtocolId(ProtocolId.Ospf);
344 final Attributes1Builder lsBuilder = new Attributes1Builder();
345 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
346 mpBuilder.setAfi(LinkstateAddressFamily.class);
347 mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
348 mpBuilder.setCNextHop(nextHop);
350 final List<CLinkstateDestination> linkstates = Lists.newArrayList();
351 final LinkCaseBuilder lCase = new LinkCaseBuilder().setLocalNodeDescriptors(ndBuilder.setCRouterIdentifier(
352 new OspfPseudonodeCaseBuilder().setOspfPseudonode(
353 new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
354 lCase.setRemoteNodeDescriptors(rdBuilder.setCRouterIdentifier(
355 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x03030304L).build()).build()).build());
356 lCase.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
357 new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.3"))).build());
358 linkstates.add(clBuilder.setObjectType(lCase.build()).build());
360 lCase.setRemoteNodeDescriptors(rdBuilder.setCRouterIdentifier(
361 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
362 lCase.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
363 new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
364 linkstates.add(clBuilder.setObjectType(lCase.build()).build());
366 lCase.setLocalNodeDescriptors(ndBuilder.setCRouterIdentifier(
367 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
368 lCase.setRemoteNodeDescriptors(rdBuilder.setCRouterIdentifier(
369 new OspfPseudonodeCaseBuilder().setOspfPseudonode(new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
370 linkstates.add(clBuilder.setObjectType(lCase.build()).build());
372 lsBuilder.setMpReachNlri(mpBuilder.build());
374 // check path attributes
375 final Attributes attrs = message.getAttributes();
377 final AttributesBuilder paBuilder = new AttributesBuilder();
379 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
380 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
382 paBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.<Segments> emptyList()).build());
383 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
385 paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
386 assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
388 final MpReachNlri mp = attrs.getAugmentation(Attributes1.class).getMpReachNlri();
389 assertEquals(mpBuilder.getAfi(), mp.getAfi());
390 assertEquals(mpBuilder.getSafi(), mp.getSafi());
391 assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
393 final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
394 dBuilder.setCLinkstateDestination(linkstates);
396 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
397 new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
398 lsBuilder.setMpReachNlri(mpBuilder.build());
400 paBuilder.addAugmentation(Attributes1.class, lsBuilder.build());
402 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Attributes1Builder lsAttrBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Attributes1Builder();
404 lsAttrBuilder.setLinkStateAttribute(
405 new LinkAttributesCaseBuilder().setLinkAttributes(new LinkAttributesBuilder().setMetric(new Metric(1L)).build()).build());
406 paBuilder.addAugmentation(
407 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Attributes1.class,
408 lsAttrBuilder.build());
409 paBuilder.setUnrecognizedAttributes(Collections.<UnrecognizedAttributes> emptyList());
412 lsAttrBuilder.build(),
413 attrs.getAugmentation(
414 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Attributes1.class));
416 final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mp.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
418 assertEquals(linkstates.size(), dests.size());
420 assertEquals(linkstates, dests);
422 builder.setAttributes(paBuilder.build());
423 assertEquals(builder.build(), message);
425 final ByteBuf buffer = Unpooled.buffer();
426 ParserTest.updateParser.serializeMessage(message, buffer);
427 assertArrayEquals(inputBytes.get(1), ByteArray.readAllBytes(buffer));
433 * 00 00 <- withdrawn routes length
434 00 b1 <- total path attribute length (177)
435 80 <- attribute flags
436 0e <- attribute type code (MP reach)
437 a0 <- attribute length (160)
438 40 04 <- AFI (16388 - Linkstate)
439 47 <- SAFI (71 - Linkstate)
440 04 <- next hop length
441 19 19 19 01 - nexthop (25.25.25.1)
444 00 01 <- NLRI type (1 - nodeNLRI)
445 00 31 <- NLRI length (49)
446 03 <- ProtocolID - OSPF
447 00 00 00 00 00 00 00 01 <- identifier
448 01 00 <- local node descriptor type (256)
450 02 00 <- node descriptor type (member AS - 512)
452 00 00 00 64 <- value (100)
453 02 01 <- node descriptor type (bgpId - 513)
455 19 19 19 01 <- bgpId (25.25.25.1)
456 02 02 <- node descriptor type (areaId - 514)
459 02 03 <- node descriptor type (routeId - 515)
461 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
463 00 01 <- NLRI type (1 - nodeNLRI)
464 00 2d <- NLRI length (45)
465 03 <- ProtocolID - OSPF
466 00 00 00 00 00 00 00 01 <- identifier
467 01 00 <- local node descriptor type (256)
469 02 00 <- node descriptor type (member AS - 512)
471 00 00 00 64 <- value (100)
472 02 01 <- node descriptor type (bgpId - 513)
474 19 19 19 01 <- bgpId (25.25.25.1)
475 02 02 <- node descriptor type (areaId - 514)
478 02 03 <- node descriptor type (routeId - 515)
480 03 03 03 04 <- OSPF Router Id
482 00 01 <- NLRI type (1 - nodeNLRI)
483 00 2d <- NLRI length (45)
484 03 <- ProtocolID - OSPF
485 00 00 00 00 00 00 00 01 <- identifier
486 01 00 <- local node descriptor type (256)
488 02 00 <- node descriptor type (member AS - 512)
490 00 00 00 64 <- value (100)
491 02 01 <- node descriptor type (bgpId - 513)
493 19 19 19 01 <- bgpId (25.25.25.1)
494 02 02 <- node descriptor type (areaId - 514)
497 02 03 <- node descriptor type (routeId - 515)
499 01 01 01 02 <- OSPF Router Id
501 40 <- attribute flags
502 01 <- attribute type (Origin)
503 01 <- attribute length
505 40 <- attribute flags
506 02 <- attribute type (AS Path)
508 40 <- attribute flags
509 05 <- attribute type (local pref)
514 public void testBGPNode() throws Exception {
515 final byte[] body = ByteArray.cutBytes(inputBytes.get(2), MessageUtil.COMMON_HEADER_LENGTH);
516 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(2), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
517 final Update message = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
519 final UpdateBuilder builder = new UpdateBuilder();
523 assertNull(message.getWithdrawnRoutes());
527 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
528 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
530 final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
531 clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
532 clBuilder.setProtocolId(ProtocolId.Ospf);
534 final NodeDescriptorsBuilder n = new NodeDescriptorsBuilder();
535 n.setAsNumber(new AsNumber((long) 100)).setDomainId(new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
537 final List<CLinkstateDestination> linkstates = Lists.newArrayList();
538 final NodeCaseBuilder nCase = new NodeCaseBuilder();
539 nCase.setNodeDescriptors(n.setCRouterIdentifier(
540 new OspfPseudonodeCaseBuilder().setOspfPseudonode(
541 new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
542 linkstates.add(clBuilder.setObjectType(nCase.build()).build());
544 nCase.setNodeDescriptors(n.setCRouterIdentifier(
545 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x03030304L).build()).build()).build());
546 linkstates.add(clBuilder.setObjectType(nCase.build()).build());
548 nCase.setNodeDescriptors(n.setCRouterIdentifier(
549 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
550 linkstates.add(clBuilder.setObjectType(nCase.build()).build());
552 final Attributes1Builder lsBuilder = new Attributes1Builder();
553 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
554 mpBuilder.setAfi(LinkstateAddressFamily.class);
555 mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
556 mpBuilder.setCNextHop(nextHop);
558 final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
559 dBuilder.setCLinkstateDestination(linkstates);
561 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
562 new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
563 lsBuilder.setMpReachNlri(mpBuilder.build());
565 // check path attributes
566 final Attributes attrs = message.getAttributes();
568 final AttributesBuilder paBuilder = new AttributesBuilder();
570 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
571 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
573 paBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.<Segments> emptyList()).build());
574 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
576 paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
577 assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
579 paBuilder.addAugmentation(Attributes1.class, lsBuilder.build());
580 paBuilder.setUnrecognizedAttributes(Collections.<UnrecognizedAttributes> emptyList());
582 final MpReachNlri mp = attrs.getAugmentation(Attributes1.class).getMpReachNlri();
583 assertEquals(mpBuilder.getAfi(), mp.getAfi());
584 assertEquals(mpBuilder.getSafi(), mp.getSafi());
585 assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
587 final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mp.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
589 assertEquals(linkstates.size(), dests.size());
591 assertEquals(linkstates, dests);
594 builder.setAttributes(paBuilder.build());
595 assertEquals(builder.build(), message);
597 final ByteBuf buffer = Unpooled.buffer();
598 ParserTest.updateParser.serializeMessage(message, buffer);
599 assertArrayEquals(inputBytes.get(2), ByteArray.readAllBytes(buffer));
603 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
604 * 00 3d <- length (61) - including header
607 * 00 64 <- My AS Number (AS TRANS in this case)
609 * 00 00 00 00 <- BGP Identifier
610 * 20 <- Optional Parameters Length
611 * 02 <- opt. param. type (capabilities)
613 * 01 <- capability code (MP Extensions for BGP4)
615 * 00 01 00 01 <- AFI 1, SAFI 1
616 * 02 <- opt. param. type (capabilities)
618 * 01 <- capability code (MP Extensions for BGP4)
620 * 00 02 00 01 <- AFI 2, SAFI 1
621 * 02 <- opt. param. type (capabilities)
623 * 01 <- capability code (MP Extensions for BGP4)
625 * 40 04 00 47 <- AFI 16388, SAFI 71
626 * 02 <- opt. param. type (capabilities)
628 * 41 <- capability code (AS4 octet support)
630 * 00 00 00 64 <- AS number
633 public void testOpenMessage() throws Exception {
634 final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry();
635 final Notification o = msgReg.parseMessage(Unpooled.copiedBuffer(inputBytes.get(3)));
636 final Open open = (Open) o;
637 final Set<BgpTableType> types = Sets.newHashSet();
638 for (final BgpParameters param : open.getBgpParameters()) {
639 for (final OptionalCapabilities optCapa : param.getOptionalCapabilities()) {
640 final CParameters p = optCapa.getCParameters();
641 if (p instanceof MultiprotocolCase) {
642 final BgpTableType type = new BgpTableTypeImpl(((MultiprotocolCase) p).getMultiprotocolCapability().getAfi(), ((MultiprotocolCase) p).getMultiprotocolCapability().getSafi());
647 final Set<BgpTableType> expected = Sets.newHashSet();
648 expected.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
649 expected.add(new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class));
650 expected.add(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
651 assertEquals(expected, types);
653 final ByteBuf buffer = Unpooled.buffer();
654 msgReg.serializeMessage(o, buffer);
655 assertArrayEquals(inputBytes.get(3), ByteArray.readAllBytes(buffer));