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.assertNull;
13 import static org.opendaylight.protocol.bgp.linkstate.impl.tlvs.OspfRouteTlvParser.OSPF_ROUTE_NID;
14 import static org.opendaylight.protocol.bgp.linkstate.impl.tlvs.ReachTlvParser.IP_REACH_NID;
16 import com.google.common.collect.Lists;
17 import io.netty.buffer.ByteBuf;
18 import io.netty.buffer.Unpooled;
19 import java.util.List;
20 import org.junit.Test;
21 import org.opendaylight.protocol.bgp.linkstate.impl.BGPActivator;
22 import org.opendaylight.protocol.bgp.linkstate.impl.nlri.LinkNlriParser;
23 import org.opendaylight.protocol.bgp.linkstate.impl.nlri.LinkstateNlriParser;
24 import org.opendaylight.protocol.bgp.linkstate.impl.nlri.NodeNlriParser;
25 import org.opendaylight.protocol.bgp.linkstate.spi.AbstractTeLspNlriCodec;
26 import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
27 import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry;
28 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
29 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
30 import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
31 import org.opendaylight.protocol.rsvp.parser.spi.pojo.SimpleRSVPExtensionProviderContext;
32 import org.opendaylight.protocol.util.ByteArray;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.DomainIdentifier;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.OspfRouteType;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.ProtocolId;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.TopologyIdentifier;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.isis.lan.identifier.IsIsRouterIdentifierBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.destination.CLinkstateDestination;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.LinkCase;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.NodeCase;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.PrefixCase;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.TeLspCase;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.link._case.LinkDescriptors;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.link._case.LocalNodeDescriptors;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.link._case.RemoteNodeDescriptors;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.node._case.NodeDescriptors;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.prefix._case.AdvertisingNodeDescriptors;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.prefix._case.PrefixDescriptors;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.te.lsp._case.address.family.Ipv4Case;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.identifier.CRouterIdentifier;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.identifier.c.router.identifier.IsisNodeCaseBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.identifier.c.router.identifier.IsisPseudonodeCaseBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.identifier.c.router.identifier.OspfNodeCaseBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.identifier.c.router.identifier.isis.node._case.IsisNodeBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonodeBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.identifier.c.router.identifier.ospf.node._case.OspfNodeBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCaseBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.linkstate._case.DestinationLinkstate;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesReachBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesUnreachBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.MpReachNlriBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.mp.reach.nlri.AdvertizedRoutes;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.mp.reach.nlri.AdvertizedRoutesBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.MpUnreachNlriBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.mp.unreach.nlri.WithdrawnRoutes;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.mp.unreach.nlri.WithdrawnRoutesBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IsoSystemIdentifier;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId;
77 import org.opendaylight.yangtools.yang.common.Uint16;
78 import org.opendaylight.yangtools.yang.common.Uint32;
79 import org.opendaylight.yangtools.yang.common.Uint64;
80 import org.opendaylight.yangtools.yang.common.Uint8;
81 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
82 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
83 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
84 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
85 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
86 import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
87 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
88 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
89 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListEntryNodeBuilder;
91 public class LinkstateNlriParserTest {
93 private static final NodeIdentifier C_LINKSTATE_NID = new NodeIdentifier(CLinkstateDestination.QNAME);
94 private static final NodeIdentifier C_ROUTER_ID_NID = new NodeIdentifier(CRouterIdentifier.QNAME);
96 private final byte[] nodeNlri = new byte[] {
97 (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x30, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00,
98 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00,
99 (byte) 0x23, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00,
100 (byte) 0x48, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28,
101 (byte) 0x28, (byte) 0x02, (byte) 0x02, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x29, (byte) 0x29,
102 (byte) 0x29, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x07, (byte) 0x00, (byte) 0x00, (byte) 0x00,
103 (byte) 0x00, (byte) 0x00, (byte) 0x39, (byte) 0x05 };
105 private final byte[] linkNlri = new byte[] {
106 (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x85, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00,
107 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
109 // local node descriptors
110 (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x2a,
111 (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48,
112 (byte) 0x02, (byte) 0x01,
113 (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03,
114 (byte) 0x00, (byte) 0x06,
115 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42,
116 2, 4, 0, 4, 1, 1, 1, 1,
117 2, 5, 0, 4, 0, 0, 1, 2,
118 // remote node descriptors
119 (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x28,
120 (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48,
121 (byte) 0x02, (byte) 0x01,
122 (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03,
123 (byte) 0x00, (byte) 0x04,
124 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40,
125 2, 4, 0, 4, 1, 1, 1, 2,
126 2, 5, 0, 4, 0, 0, 1, 3,
128 1, 2, 0, 8, 1, 2, 3, 4, 0x0a,
129 0x0b, 0x0c, 0x0d, (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14, (byte) 0xa0,
131 (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14, (byte) 0xa0, (byte) 0x28,
134 private final byte[] prefixNlri = new byte[] {
135 (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x39, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00,
136 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00,
137 (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00,
138 (byte) 0x48, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28,
139 (byte) 0x28, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00,
140 (byte) 0x00, (byte) 0x00, (byte) 0x42, (byte) 0x01, (byte) 0x07, (byte) 0x00, (byte) 0x02, (byte) 0x00,
141 (byte) 0x0F, (byte) 0x01, (byte) 0x08, (byte) 0x00, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x09,
142 (byte) 0x00, (byte) 0x03, (byte) 0x10, (byte) 0xFF, (byte) 0xFF
145 private final byte[] teLspNlri = new byte[] {
146 (byte) 0x00, (byte) 0x05, //NLRI Type Te-IPV4
147 (byte) 0x00, (byte) 0x15, // length
148 (byte) 0x08, //Protocol-ID
150 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
151 (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, //IPv4 Tunnel Sender Address
152 (byte) 0x00, (byte) 0x01, //Tunnel ID
153 (byte) 0x00, (byte) 0x01, //LSP ID
154 (byte) 0x04, (byte) 0x03, (byte) 0x02, (byte) 0x01 }; // IPv4 Tunnel End-point Address
156 private CLinkstateDestination dest;
157 private SimpleNlriTypeRegistry registry;
159 private void setUp(final byte[] data) throws BGPParsingException {
160 final LinkstateNlriParser parser = new LinkstateNlriParser();
161 final MpReachNlriBuilder builder = new MpReachNlriBuilder();
162 this.registry = SimpleNlriTypeRegistry.getInstance();
163 final BGPActivator act = new BGPActivator(new SimpleRSVPExtensionProviderContext());
164 final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
167 parser.parseNlri(Unpooled.copiedBuffer(data), builder, null);
169 final DestinationLinkstate ls = ((DestinationLinkstateCase) builder.getAdvertizedRoutes().getDestinationType())
170 .getDestinationLinkstate();
171 assertEquals(1, ls.getCLinkstateDestination().size());
173 this.dest = ls.getCLinkstateDestination().get(0);
177 public void testNodeNlri() throws BGPParsingException {
178 setUp(this.nodeNlri);
181 assertNull(this.dest.getRouteDistinguisher());
182 assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
183 assertEquals(Uint64.ONE, this.dest.getIdentifier().getValue());
184 final NodeCase nCase = (NodeCase) this.dest.getObjectType();
186 final NodeDescriptors nodeD = nCase.getNodeDescriptors();
187 assertEquals(new AsNumber(Uint32.valueOf(72)), nodeD.getAsNumber());
188 assertEquals(new DomainIdentifier(Uint32.valueOf(0x28282828L)), nodeD.getDomainId());
189 assertEquals(new IsisPseudonodeCaseBuilder().setIsisPseudonode(
190 new IsisPseudonodeBuilder().setPsn(Uint8.valueOf(5)).setIsIsRouterIdentifier(
191 new IsIsRouterIdentifierBuilder().setIsoSystemId(
192 new IsoSystemIdentifier(new byte[] { 0, 0, 0, 0, 0, (byte) 0x39 })).build()).build()).build(),
193 nodeD.getCRouterIdentifier());
195 final ByteBuf buffer = Unpooled.buffer();
196 this.registry.serializeNlriType(this.dest, buffer);
197 assertArrayEquals(this.nodeNlri, ByteArray.readAllBytes(buffer));
200 final DataContainerNodeBuilder<NodeIdentifier, UnkeyedListEntryNode> linkstateBI =
201 ImmutableUnkeyedListEntryNodeBuilder.create();
202 linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
204 final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
205 protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
206 protocolId.withValue("isis-level2");
207 linkstateBI.addChild(protocolId.build());
209 final ImmutableLeafNodeBuilder<Uint64> identifier = new ImmutableLeafNodeBuilder<>();
210 identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
211 identifier.withValue(Uint64.ONE);
212 linkstateBI.addChild(identifier.build());
214 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
215 objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
217 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> nodeDescriptors = Builders.containerBuilder();
218 nodeDescriptors.withNodeIdentifier(LinkstateNlriParser.NODE_DESCRIPTORS_NID);
220 final ImmutableLeafNodeBuilder<Uint32> asNumber = new ImmutableLeafNodeBuilder<>();
221 asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID);
222 asNumber.withValue(Uint32.valueOf(72));
223 nodeDescriptors.addChild(asNumber.build());
225 final ImmutableLeafNodeBuilder<Uint32> areaID = new ImmutableLeafNodeBuilder<>();
226 areaID.withNodeIdentifier(NodeNlriParser.AREA_NID);
227 areaID.withValue(Uint32.valueOf(2697513L));
228 nodeDescriptors.addChild(areaID.build());
230 final ImmutableLeafNodeBuilder<Uint32> domainID = new ImmutableLeafNodeBuilder<>();
231 domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID);
232 domainID.withValue(Uint32.valueOf(0x28282828L));
233 nodeDescriptors.addChild(domainID.build());
235 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId = Builders.choiceBuilder();
236 crouterId.withNodeIdentifier(C_ROUTER_ID_NID);
238 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> isisNode = Builders.containerBuilder();
239 isisNode.withNodeIdentifier(NodeNlriParser.ISIS_PSEUDONODE_NID);
241 final ImmutableLeafNodeBuilder<byte[]> isoSystemID = new ImmutableLeafNodeBuilder<>();
242 isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID);
243 isoSystemID.withValue(new byte[]{0, 0, 0, 0, 0, (byte) 0x39});
245 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> isisPseudoRouter =
246 Builders.containerBuilder();
247 isisPseudoRouter.withNodeIdentifier(NodeNlriParser.ISIS_ROUTER_NID);
248 isisPseudoRouter.addChild(isoSystemID.build());
250 isisNode.addChild(isisPseudoRouter.build());
251 isisNode.addChild(Builders.leafBuilder().withNodeIdentifier(NodeNlriParser.PSN_NID).withValue(Uint8.valueOf(5))
253 crouterId.addChild(isisNode.build());
255 nodeDescriptors.addChild(crouterId.build());
256 objectType.addChild(nodeDescriptors.build());
257 linkstateBI.addChild(objectType.build());
259 assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
263 public void testLinkNlri() throws BGPParsingException {
264 setUp(this.linkNlri);
267 assertNull(this.dest.getRouteDistinguisher());
268 assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
269 assertEquals(Uint64.ONE, this.dest.getIdentifier().getValue());
271 final LinkCase lCase = (LinkCase) this.dest.getObjectType();
273 final LocalNodeDescriptors local = lCase.getLocalNodeDescriptors();
274 assertEquals(new AsNumber(Uint32.valueOf(72)), local.getAsNumber());
275 assertEquals(new DomainIdentifier(Uint32.valueOf(0x28282828L)), local.getDomainId());
277 new IsisNodeCaseBuilder().setIsisNode(
278 new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[] {
279 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42 })).build()).build(),
280 local.getCRouterIdentifier());
281 assertEquals("1.1.1.1", local.getBgpRouterId().getValue());
282 assertEquals(new AsNumber(Uint32.valueOf(258)), local.getMemberAsn());
284 final RemoteNodeDescriptors remote = lCase.getRemoteNodeDescriptors();
285 assertEquals(new AsNumber(Uint32.valueOf(72)), remote.getAsNumber());
286 assertEquals(new DomainIdentifier(Uint32.valueOf(0x28282828L)), remote.getDomainId());
287 assertEquals(new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder()
288 .setOspfRouterId(Uint32.valueOf(0x00000040L)).build())
289 .build(), remote.getCRouterIdentifier());
290 assertEquals(new AsNumber(Uint32.valueOf(259)), remote.getMemberAsn());
291 assertEquals("1.1.1.2", remote.getBgpRouterId().getValue());
293 final LinkDescriptors ld = lCase.getLinkDescriptors();
294 assertEquals("197.20.160.42", ld.getIpv4InterfaceAddress().getValue());
295 assertEquals("197.20.160.40", ld.getIpv4NeighborAddress().getValue());
297 final ByteBuf buffer = Unpooled.buffer();
298 this.registry.serializeNlriType(this.dest, buffer);
299 assertArrayEquals(this.linkNlri, ByteArray.readAllBytes(buffer));
302 final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI =
303 ImmutableUnkeyedListEntryNodeBuilder.create();
304 linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
306 final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
307 protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
308 protocolId.withValue("isis-level2");
309 linkstateBI.addChild(protocolId.build());
311 final ImmutableLeafNodeBuilder<Uint64> identifier = new ImmutableLeafNodeBuilder<>();
312 identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
313 identifier.withValue(Uint64.ONE);
314 linkstateBI.addChild(identifier.build());
316 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
317 objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
319 // local node descriptors
320 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> localNodeDescriptors =
321 Builders.containerBuilder();
322 localNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.LOCAL_NODE_DESCRIPTORS_NID);
324 final ImmutableLeafNodeBuilder<Uint32> asNumber = new ImmutableLeafNodeBuilder<>();
325 asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID);
326 asNumber.withValue(Uint32.valueOf(72));
327 localNodeDescriptors.addChild(asNumber.build());
329 final ImmutableLeafNodeBuilder<Uint32> domainID = new ImmutableLeafNodeBuilder<>();
330 domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID);
331 domainID.withValue(Uint32.valueOf(0x28282828L));
332 localNodeDescriptors.addChild(domainID.build());
334 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId = Builders.choiceBuilder();
335 crouterId.withNodeIdentifier(C_ROUTER_ID_NID);
337 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> isisNode = Builders.containerBuilder();
338 isisNode.withNodeIdentifier(NodeNlriParser.ISIS_NODE_NID);
340 final ImmutableLeafNodeBuilder<byte[]> isoSystemID = new ImmutableLeafNodeBuilder<>();
341 isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID);
342 isoSystemID.withValue(new byte[] { 0, 0, 0, 0, 0, (byte) 0x42 });
344 isisNode.addChild(isoSystemID.build());
345 crouterId.addChild(isisNode.build());
346 localNodeDescriptors.addChild(crouterId.build());
348 final ImmutableLeafNodeBuilder<String> bgpRouterId = new ImmutableLeafNodeBuilder<>();
349 bgpRouterId.withNodeIdentifier(NodeNlriParser.BGP_ROUTER_NID);
350 bgpRouterId.withValue("1.1.1.1");
352 final ImmutableLeafNodeBuilder<Uint32> memberAsn = new ImmutableLeafNodeBuilder<>();
353 memberAsn.withNodeIdentifier(NodeNlriParser.MEMBER_ASN_NID);
354 memberAsn.withValue(Uint32.valueOf(258L));
356 localNodeDescriptors.addChild(bgpRouterId.build());
357 localNodeDescriptors.addChild(memberAsn.build());
359 // remote descriptors
360 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> remoteNodeDescriptors =
361 Builders.containerBuilder();
362 remoteNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.REMOTE_NODE_DESCRIPTORS_NID);
363 remoteNodeDescriptors.addChild(asNumber.build());
364 remoteNodeDescriptors.addChild(domainID.build());
366 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId2 = Builders.choiceBuilder();
367 crouterId2.withNodeIdentifier(C_ROUTER_ID_NID);
369 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> ospfNode = Builders.containerBuilder();
370 ospfNode.withNodeIdentifier(NodeNlriParser.OSPF_NODE_NID);
372 final ImmutableLeafNodeBuilder<Uint32> ospfRouterId = new ImmutableLeafNodeBuilder<>();
373 ospfRouterId.withNodeIdentifier(NodeNlriParser.OSPF_ROUTER_NID);
374 ospfRouterId.withValue(Uint32.valueOf(0x00000040L));
375 ospfNode.addChild(ospfRouterId.build());
376 crouterId2.addChild(ospfNode.build());
377 remoteNodeDescriptors.addChild(crouterId2.build());
378 final ImmutableLeafNodeBuilder<String> bgpRouterIdRemote = new ImmutableLeafNodeBuilder<>();
379 bgpRouterIdRemote.withNodeIdentifier(NodeNlriParser.BGP_ROUTER_NID);
380 bgpRouterIdRemote.withValue("1.1.1.2");
381 remoteNodeDescriptors.addChild(bgpRouterIdRemote.build());
383 final ImmutableLeafNodeBuilder<Uint32> memberAsnRemote = new ImmutableLeafNodeBuilder<>();
384 memberAsnRemote.withNodeIdentifier(NodeNlriParser.MEMBER_ASN_NID);
385 memberAsnRemote.withValue(Uint32.valueOf(259));
386 remoteNodeDescriptors.addChild(memberAsnRemote.build());
389 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> linkDescriptors = Builders.containerBuilder();
390 linkDescriptors.withNodeIdentifier(LinkstateNlriParser.LINK_DESCRIPTORS_NID);
392 final ImmutableLeafNodeBuilder<Uint32> linkLocalIdentifier = new ImmutableLeafNodeBuilder<>();
393 linkLocalIdentifier.withNodeIdentifier(LinkNlriParser.LINK_LOCAL_NID);
394 linkLocalIdentifier.withValue(Uint32.valueOf(16909060L));
396 final ImmutableLeafNodeBuilder<Uint32> linkRemoteIdentifier = new ImmutableLeafNodeBuilder<>();
397 linkRemoteIdentifier.withNodeIdentifier(LinkNlriParser.LINK_REMOTE_NID);
398 linkRemoteIdentifier.withValue(Uint32.valueOf(168496141L));
400 final ImmutableLeafNodeBuilder<String> ipv4InterfaceAddress = new ImmutableLeafNodeBuilder<>();
401 ipv4InterfaceAddress.withNodeIdentifier(LinkNlriParser.IPV4_IFACE_NID);
402 ipv4InterfaceAddress.withValue("197.20.160.42");
404 final ImmutableLeafNodeBuilder<String> ipv4NeighborAddress = new ImmutableLeafNodeBuilder<>();
405 ipv4NeighborAddress.withNodeIdentifier(LinkNlriParser.IPV4_NEIGHBOR_NID);
406 ipv4NeighborAddress.withValue("197.20.160.40");
408 final ImmutableLeafNodeBuilder<Uint16> multiTopologyId = new ImmutableLeafNodeBuilder<>();
409 multiTopologyId.withNodeIdentifier(TlvUtil.MULTI_TOPOLOGY_NID);
410 multiTopologyId.withValue(Uint16.valueOf(3));
412 linkDescriptors.addChild(linkLocalIdentifier.build());
413 linkDescriptors.addChild(linkRemoteIdentifier.build());
414 linkDescriptors.addChild(ipv4InterfaceAddress.build());
415 linkDescriptors.addChild(ipv4NeighborAddress.build());
416 linkDescriptors.addChild(multiTopologyId.build());
418 objectType.addChild(localNodeDescriptors.build());
419 objectType.addChild(remoteNodeDescriptors.build());
420 objectType.addChild(linkDescriptors.build());
422 linkstateBI.addChild(objectType.build());
423 assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
427 public void testPrefixNlri() throws BGPParsingException {
428 setUp(this.prefixNlri);
431 assertNull(this.dest.getRouteDistinguisher());
432 assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
433 assertEquals(Uint64.ONE, this.dest.getIdentifier().getValue());
435 final PrefixCase pCase = (PrefixCase) this.dest.getObjectType();
437 final AdvertisingNodeDescriptors local = pCase.getAdvertisingNodeDescriptors();
438 assertEquals(new AsNumber(Uint32.valueOf(72)), local.getAsNumber());
439 assertEquals(new DomainIdentifier(Uint32.valueOf(0x28282828L)), local.getDomainId());
441 new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder().setIsoSystemId(
442 new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
443 (byte) 0x42 })).build()).build(), local.getCRouterIdentifier());
445 final PrefixDescriptors pd = pCase.getPrefixDescriptors();
446 assertEquals(OspfRouteType.External1, pd.getOspfRouteType());
447 assertEquals(new TopologyIdentifier(Uint16.valueOf(15)), pd.getMultiTopologyId());
448 assertEquals(new Ipv4Prefix("255.255.0.0/16"), pd.getIpReachabilityInformation().getIpv4Prefix());
450 final ByteBuf buffer = Unpooled.buffer();
451 this.registry.serializeNlriType(this.dest, buffer);
452 assertArrayEquals(this.prefixNlri, ByteArray.readAllBytes(buffer));
455 final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI =
456 ImmutableUnkeyedListEntryNodeBuilder.create();
457 linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
459 final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
460 protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
461 protocolId.withValue("isis-level2");
462 linkstateBI.addChild(protocolId.build());
464 final ImmutableLeafNodeBuilder<Uint64> identifier = new ImmutableLeafNodeBuilder<>();
465 identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
466 identifier.withValue(Uint64.ONE);
467 linkstateBI.addChild(identifier.build());
469 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
470 objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
472 // advertising node descriptors
473 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> advertisingNodeDescriptors =
474 Builders.containerBuilder();
475 advertisingNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.ADVERTISING_NODE_DESCRIPTORS_NID);
477 final ImmutableLeafNodeBuilder<Uint32> asNumber = new ImmutableLeafNodeBuilder<>();
478 asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID);
479 asNumber.withValue(Uint32.valueOf(72));
480 advertisingNodeDescriptors.addChild(asNumber.build());
482 final ImmutableLeafNodeBuilder<Uint32> domainID = new ImmutableLeafNodeBuilder<>();
483 domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID);
484 domainID.withValue(Uint32.valueOf(673720360L));
485 advertisingNodeDescriptors.addChild(domainID.build());
487 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId = Builders.choiceBuilder();
488 crouterId.withNodeIdentifier(C_ROUTER_ID_NID);
490 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> isisNode = Builders.containerBuilder();
491 isisNode.withNodeIdentifier(NodeNlriParser.ISIS_NODE_NID);
493 final ImmutableLeafNodeBuilder<byte[]> isoSystemID = new ImmutableLeafNodeBuilder<>();
494 isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID);
495 isoSystemID.withValue(new byte[] { 0, 0, 0, 0, 0, (byte) 0x42 });
497 isisNode.addChild(isoSystemID.build());
498 crouterId.addChild(isisNode.build());
499 advertisingNodeDescriptors.addChild(crouterId.build());
501 // prefix descriptors
502 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> prefixDescriptors =
503 Builders.containerBuilder();
504 prefixDescriptors.withNodeIdentifier(LinkstateNlriParser.PREFIX_DESCRIPTORS_NID);
505 prefixDescriptors.addChild(asNumber.build());
506 prefixDescriptors.addChild(domainID.build());
508 final ImmutableLeafNodeBuilder<Uint16> multiTopologyId = new ImmutableLeafNodeBuilder<>();
509 multiTopologyId.withNodeIdentifier(TlvUtil.MULTI_TOPOLOGY_NID);
510 multiTopologyId.withValue(Uint16.valueOf(15));
512 prefixDescriptors.addChild(multiTopologyId.build());
514 final ImmutableLeafNodeBuilder<String> ipReachabilityInformation = new ImmutableLeafNodeBuilder<>();
515 ipReachabilityInformation.withNodeIdentifier(IP_REACH_NID);
516 ipReachabilityInformation.withValue("255.255.0.0/16");
518 prefixDescriptors.addChild(ipReachabilityInformation.build());
520 final ImmutableLeafNodeBuilder<String> ospfRouteType = new ImmutableLeafNodeBuilder<>();
521 ospfRouteType.withNodeIdentifier(OSPF_ROUTE_NID);
522 ospfRouteType.withValue("external1");
524 prefixDescriptors.addChild(ospfRouteType.build());
526 objectType.addChild(advertisingNodeDescriptors.build());
527 objectType.addChild(prefixDescriptors.build());
529 linkstateBI.addChild(objectType.build());
530 assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
534 public void testTELspNlri() throws BGPParsingException {
535 setUp(this.teLspNlri);
537 assertNull(this.dest.getRouteDistinguisher());
538 assertEquals(ProtocolId.RsvpTe, this.dest.getProtocolId());
539 assertEquals(Uint64.ONE, this.dest.getIdentifier().getValue());
540 final TeLspCase teCase = (TeLspCase) this.dest.getObjectType();
542 assertEquals(new LspId(Uint32.ONE), teCase.getLspId());
543 assertEquals(new TunnelId(Uint16.ONE), teCase.getTunnelId());
544 assertEquals(new Ipv4Address("1.2.3.4"), ((Ipv4Case) teCase.getAddressFamily()).getIpv4TunnelSenderAddress());
545 assertEquals(new Ipv4Address("4.3.2.1"), ((Ipv4Case) teCase.getAddressFamily()).getIpv4TunnelEndpointAddress());
548 final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI =
549 ImmutableUnkeyedListEntryNodeBuilder.create();
550 linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
552 final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
553 protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
554 protocolId.withValue("rsvp-te");
555 linkstateBI.addChild(protocolId.build());
557 final ImmutableLeafNodeBuilder<Uint64> identifier = new ImmutableLeafNodeBuilder<>();
558 identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
559 identifier.withValue(Uint64.ONE);
560 linkstateBI.addChild(identifier.build());
562 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
563 objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
565 final ImmutableLeafNodeBuilder<Uint32> lspId = new ImmutableLeafNodeBuilder<>();
566 lspId.withNodeIdentifier(AbstractTeLspNlriCodec.LSP_ID);
567 lspId.withValue(Uint32.ONE);
569 final ImmutableLeafNodeBuilder<Uint16> tunnelId = new ImmutableLeafNodeBuilder<>();
570 tunnelId.withNodeIdentifier(AbstractTeLspNlriCodec.TUNNEL_ID);
571 tunnelId.withValue(Uint16.ONE);
573 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> addressFamily = Builders.choiceBuilder();
574 addressFamily.withNodeIdentifier(AbstractTeLspNlriCodec.ADDRESS_FAMILY);
576 final ImmutableLeafNodeBuilder<String> ipv4TunnelSenderAddress = new ImmutableLeafNodeBuilder<>();
577 ipv4TunnelSenderAddress.withNodeIdentifier(AbstractTeLspNlriCodec.IPV4_TUNNEL_SENDER_ADDRESS);
578 ipv4TunnelSenderAddress.withValue("1.2.3.4");
580 final ImmutableLeafNodeBuilder<String> ipv4TunnelEndPointAddress = new ImmutableLeafNodeBuilder<>();
581 ipv4TunnelEndPointAddress.withNodeIdentifier(AbstractTeLspNlriCodec.IPV4_TUNNEL_ENDPOINT_ADDRESS);
582 ipv4TunnelEndPointAddress.withValue("4.3.2.1");
584 addressFamily.addChild(ipv4TunnelSenderAddress.build());
585 addressFamily.addChild(ipv4TunnelEndPointAddress.build());
587 objectType.addChild(lspId.build());
588 objectType.addChild(tunnelId.build());
589 objectType.addChild(addressFamily.build());
591 linkstateBI.addChild(objectType.build());
592 assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
596 public void testSerializeAttribute() throws BGPParsingException {
597 final LinkstateNlriParser parser = new LinkstateNlriParser();
598 setUp(this.prefixNlri);
599 final List<CLinkstateDestination> dests = Lists.newArrayList(this.dest);
600 final DestinationLinkstateCase dlc = new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
601 new DestinationLinkstateBuilder().setCLinkstateDestination(dests).build()).build();
602 final AdvertizedRoutes aroutes = new AdvertizedRoutesBuilder().setDestinationType(dlc).build();
604 Attributes pa = new AttributesBuilder()
605 .addAugmentation(new AttributesReachBuilder()
606 .setMpReachNlri(new MpReachNlriBuilder().setAdvertizedRoutes(aroutes).build())
610 ByteBuf result = Unpooled.buffer();
611 parser.serializeAttribute(pa, result);
612 assertArrayEquals(this.prefixNlri, ByteArray.getAllBytes(result));
614 setUp(this.nodeNlri);
615 final List<CLinkstateDestination> destsU = Lists.newArrayList(this.dest);
616 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.update
617 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase dlcU =
618 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.update
619 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder()
620 .setDestinationLinkstate(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
621 .bgp.linkstate.rev200120.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
622 .destination.linkstate._case.DestinationLinkstateBuilder().setCLinkstateDestination(destsU)
624 final WithdrawnRoutes wroutes = new WithdrawnRoutesBuilder().setDestinationType(dlcU).build();
626 pa = new AttributesBuilder()
627 .addAugmentation(new AttributesUnreachBuilder()
628 .setMpUnreachNlri(new MpUnreachNlriBuilder().setWithdrawnRoutes(wroutes).build())
632 result = Unpooled.buffer();
633 parser.serializeAttribute(pa, result);
634 assertArrayEquals(this.nodeNlri, ByteArray.getAllBytes(result));