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.ServiceLoaderRSVPExtensionProviderContext;
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.rev180329.DomainIdentifier;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.OspfRouteType;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.ProtocolId;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.TopologyIdentifier;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.isis.lan.identifier.IsIsRouterIdentifierBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.destination.CLinkstateDestination;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.LinkCase;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.NodeCase;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.PrefixCase;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.TeLspCase;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.LinkDescriptors;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.LocalNodeDescriptors;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.RemoteNodeDescriptors;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.node._case.NodeDescriptors;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.prefix._case.AdvertisingNodeDescriptors;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.prefix._case.PrefixDescriptors;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.te.lsp._case.address.family.Ipv4Case;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.identifier.CRouterIdentifier;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.identifier.c.router.identifier.IsisNodeCaseBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.identifier.c.router.identifier.IsisPseudonodeCaseBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.identifier.c.router.identifier.OspfNodeCaseBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.identifier.c.router.identifier.isis.node._case.IsisNodeBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonodeBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.identifier.c.router.identifier.ospf.node._case.OspfNodeBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.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.rev180329.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.rev180329.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.rev180329.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.rev180329.path.attributes.Attributes;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1Builder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2Builder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlriBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlriBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutes;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutes;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IsoSystemIdentifier;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId;
79 import org.opendaylight.yangtools.yang.common.Uint32;
80 import org.opendaylight.yangtools.yang.common.Uint64;
81 import org.opendaylight.yangtools.yang.common.Uint8;
82 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
83 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
84 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
85 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
86 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
87 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
88 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
89 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
90 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListEntryNodeBuilder;
92 public class LinkstateNlriParserTest {
94 private static final NodeIdentifier C_LINKSTATE_NID = new NodeIdentifier(CLinkstateDestination.QNAME);
95 private static final NodeIdentifier C_ROUTER_ID_NID = new NodeIdentifier(CRouterIdentifier.QNAME);
97 private final byte[] nodeNlri = new byte[] {
98 (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x30, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00,
99 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00,
100 (byte) 0x23, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00,
101 (byte) 0x48, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28,
102 (byte) 0x28, (byte) 0x02, (byte) 0x02, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x29, (byte) 0x29,
103 (byte) 0x29, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x07, (byte) 0x00, (byte) 0x00, (byte) 0x00,
104 (byte) 0x00, (byte) 0x00, (byte) 0x39, (byte) 0x05 };
106 private final byte[] linkNlri = new byte[] {
107 (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x85, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00,
108 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
110 // local node descriptors
111 (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x2a,
112 (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48,
113 (byte) 0x02, (byte) 0x01,
114 (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03,
115 (byte) 0x00, (byte) 0x06,
116 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42,
117 2, 4, 0, 4, 1, 1, 1, 1,
118 2, 5, 0, 4, 0, 0, 1, 2,
119 // remote node descriptors
120 (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x28,
121 (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48,
122 (byte) 0x02, (byte) 0x01,
123 (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03,
124 (byte) 0x00, (byte) 0x04,
125 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40,
126 2, 4, 0, 4, 1, 1, 1, 2,
127 2, 5, 0, 4, 0, 0, 1, 3,
129 1, 2, 0, 8, 1, 2, 3, 4, 0x0a,
130 0x0b, 0x0c, 0x0d, (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14, (byte) 0xa0,
132 (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14, (byte) 0xa0, (byte) 0x28,
135 private final byte[] prefixNlri = new byte[] {
136 (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x39, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00,
137 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00,
138 (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00,
139 (byte) 0x48, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28,
140 (byte) 0x28, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00,
141 (byte) 0x00, (byte) 0x00, (byte) 0x42, (byte) 0x01, (byte) 0x07, (byte) 0x00, (byte) 0x02, (byte) 0x00,
142 (byte) 0x0F, (byte) 0x01, (byte) 0x08, (byte) 0x00, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x09,
143 (byte) 0x00, (byte) 0x03, (byte) 0x10, (byte) 0xFF, (byte) 0xFF
146 private final byte[] teLspNlri = new byte[] {
147 (byte) 0x00, (byte) 0x05, //NLRI Type Te-IPV4
148 (byte) 0x00, (byte) 0x15, // length
149 (byte) 0x08, //Protocol-ID
151 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
152 (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, //IPv4 Tunnel Sender Address
153 (byte) 0x00, (byte) 0x01, //Tunnel ID
154 (byte) 0x00, (byte) 0x01, //LSP ID
155 (byte) 0x04, (byte) 0x03, (byte) 0x02, (byte) 0x01 }; // IPv4 Tunnel End-point Address
157 private CLinkstateDestination dest;
158 private SimpleNlriTypeRegistry registry;
160 private void setUp(final byte[] data) throws BGPParsingException {
161 final LinkstateNlriParser parser = new LinkstateNlriParser();
162 final MpReachNlriBuilder builder = new MpReachNlriBuilder();
163 this.registry = SimpleNlriTypeRegistry.getInstance();
164 final BGPActivator act = new BGPActivator(true,
165 ServiceLoaderRSVPExtensionProviderContext.getSingletonInstance().getRsvpRegistry());
166 final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
169 parser.parseNlri(Unpooled.copiedBuffer(data), builder, null);
171 final DestinationLinkstate ls = ((DestinationLinkstateCase) builder.getAdvertizedRoutes().getDestinationType())
172 .getDestinationLinkstate();
173 assertEquals(1, ls.getCLinkstateDestination().size());
175 this.dest = ls.getCLinkstateDestination().get(0);
179 public void testNodeNlri() throws BGPParsingException {
180 setUp(this.nodeNlri);
183 assertNull(this.dest.getRouteDistinguisher());
184 assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
185 assertEquals(Uint64.ONE, this.dest.getIdentifier().getValue());
186 final NodeCase nCase = (NodeCase) this.dest.getObjectType();
188 final NodeDescriptors nodeD = nCase.getNodeDescriptors();
189 assertEquals(new AsNumber(72L), nodeD.getAsNumber());
190 assertEquals(new DomainIdentifier(0x28282828L), nodeD.getDomainId());
191 assertEquals(new IsisPseudonodeCaseBuilder().setIsisPseudonode(
192 new IsisPseudonodeBuilder().setPsn((short) 5).setIsIsRouterIdentifier(
193 new IsIsRouterIdentifierBuilder().setIsoSystemId(
194 new IsoSystemIdentifier(new byte[] { 0, 0, 0, 0, 0, (byte) 0x39 })).build()).build()).build(),
195 nodeD.getCRouterIdentifier());
197 final ByteBuf buffer = Unpooled.buffer();
198 this.registry.serializeNlriType(this.dest, buffer);
199 assertArrayEquals(this.nodeNlri, ByteArray.readAllBytes(buffer));
202 final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI =
203 ImmutableUnkeyedListEntryNodeBuilder.create();
204 linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
206 final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
207 protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
208 protocolId.withValue("isis-level2");
209 linkstateBI.addChild(protocolId.build());
211 final ImmutableLeafNodeBuilder<Uint64> identifier = new ImmutableLeafNodeBuilder<>();
212 identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
213 identifier.withValue(Uint64.ONE);
214 linkstateBI.addChild(identifier.build());
216 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
217 objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
219 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> nodeDescriptors = Builders.containerBuilder();
220 nodeDescriptors.withNodeIdentifier(LinkstateNlriParser.NODE_DESCRIPTORS_NID);
222 final ImmutableLeafNodeBuilder<Uint32> asNumber = new ImmutableLeafNodeBuilder<>();
223 asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID);
224 asNumber.withValue(Uint32.valueOf(72));
225 nodeDescriptors.addChild(asNumber.build());
227 final ImmutableLeafNodeBuilder<Uint32> areaID = new ImmutableLeafNodeBuilder<>();
228 areaID.withNodeIdentifier(NodeNlriParser.AREA_NID);
229 areaID.withValue(Uint32.valueOf(2697513L));
230 nodeDescriptors.addChild(areaID.build());
232 final ImmutableLeafNodeBuilder<Uint32> domainID = new ImmutableLeafNodeBuilder<>();
233 domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID);
234 domainID.withValue(Uint32.valueOf(0x28282828L));
235 nodeDescriptors.addChild(domainID.build());
237 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId = Builders.choiceBuilder();
238 crouterId.withNodeIdentifier(C_ROUTER_ID_NID);
240 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> isisNode = Builders.containerBuilder();
241 isisNode.withNodeIdentifier(NodeNlriParser.ISIS_PSEUDONODE_NID);
243 final ImmutableLeafNodeBuilder<byte[]> isoSystemID = new ImmutableLeafNodeBuilder<>();
244 isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID);
245 isoSystemID.withValue(new byte[]{0, 0, 0, 0, 0, (byte) 0x39});
247 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> isisPseudoRouter =
248 Builders.containerBuilder();
249 isisPseudoRouter.withNodeIdentifier(NodeNlriParser.ISIS_ROUTER_NID);
250 isisPseudoRouter.addChild(isoSystemID.build());
252 isisNode.addChild(isisPseudoRouter.build());
253 isisNode.addChild(Builders.leafBuilder().withNodeIdentifier(NodeNlriParser.PSN_NID).withValue(Uint8.valueOf(5))
255 crouterId.addChild(isisNode.build());
257 nodeDescriptors.addChild(crouterId.build());
258 objectType.addChild(nodeDescriptors.build());
259 linkstateBI.addChild(objectType.build());
261 assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
265 public void testLinkNlri() throws BGPParsingException {
266 setUp(this.linkNlri);
269 assertNull(this.dest.getRouteDistinguisher());
270 assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
271 assertEquals(Uint64.ONE, this.dest.getIdentifier().getValue());
273 final LinkCase lCase = (LinkCase) this.dest.getObjectType();
275 final LocalNodeDescriptors local = lCase.getLocalNodeDescriptors();
276 assertEquals(new AsNumber(72L), local.getAsNumber());
277 assertEquals(new DomainIdentifier(0x28282828L), local.getDomainId());
279 new IsisNodeCaseBuilder().setIsisNode(
280 new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[] {
281 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42 })).build()).build(),
282 local.getCRouterIdentifier());
283 assertEquals("1.1.1.1", local.getBgpRouterId().getValue());
284 assertEquals(new AsNumber(258L), local.getMemberAsn());
286 final RemoteNodeDescriptors remote = lCase.getRemoteNodeDescriptors();
287 assertEquals(new AsNumber(72L), remote.getAsNumber());
288 assertEquals(new DomainIdentifier(0x28282828L), remote.getDomainId());
289 assertEquals(new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x00000040L).build())
291 remote.getCRouterIdentifier());
292 assertEquals(new AsNumber(259L), remote.getMemberAsn());
293 assertEquals("1.1.1.2", remote.getBgpRouterId().getValue());
295 final LinkDescriptors ld = lCase.getLinkDescriptors();
296 assertEquals("197.20.160.42", ld.getIpv4InterfaceAddress().getValue());
297 assertEquals("197.20.160.40", ld.getIpv4NeighborAddress().getValue());
299 final ByteBuf buffer = Unpooled.buffer();
300 this.registry.serializeNlriType(this.dest, buffer);
301 assertArrayEquals(this.linkNlri, ByteArray.readAllBytes(buffer));
304 final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI =
305 ImmutableUnkeyedListEntryNodeBuilder.create();
306 linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
308 final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
309 protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
310 protocolId.withValue("isis-level2");
311 linkstateBI.addChild(protocolId.build());
313 final ImmutableLeafNodeBuilder<Uint64> identifier = new ImmutableLeafNodeBuilder<>();
314 identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
315 identifier.withValue(Uint64.ONE);
316 linkstateBI.addChild(identifier.build());
318 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
319 objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
321 // local node descriptors
322 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> localNodeDescriptors =
323 Builders.containerBuilder();
324 localNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.LOCAL_NODE_DESCRIPTORS_NID);
326 final ImmutableLeafNodeBuilder<Uint32> asNumber = new ImmutableLeafNodeBuilder<>();
327 asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID);
328 asNumber.withValue(Uint32.valueOf(72));
329 localNodeDescriptors.addChild(asNumber.build());
331 final ImmutableLeafNodeBuilder<Uint32> domainID = new ImmutableLeafNodeBuilder<>();
332 domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID);
333 domainID.withValue(Uint32.valueOf(0x28282828L));
334 localNodeDescriptors.addChild(domainID.build());
336 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId = Builders.choiceBuilder();
337 crouterId.withNodeIdentifier(C_ROUTER_ID_NID);
339 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> isisNode = Builders.containerBuilder();
340 isisNode.withNodeIdentifier(NodeNlriParser.ISIS_NODE_NID);
342 final ImmutableLeafNodeBuilder<byte[]> isoSystemID = new ImmutableLeafNodeBuilder<>();
343 isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID);
344 isoSystemID.withValue(new byte[] { 0, 0, 0, 0, 0, (byte) 0x42 });
346 isisNode.addChild(isoSystemID.build());
347 crouterId.addChild(isisNode.build());
348 localNodeDescriptors.addChild(crouterId.build());
350 final ImmutableLeafNodeBuilder<String> bgpRouterId = new ImmutableLeafNodeBuilder<>();
351 bgpRouterId.withNodeIdentifier(NodeNlriParser.BGP_ROUTER_NID);
352 bgpRouterId.withValue("1.1.1.1");
354 final ImmutableLeafNodeBuilder<Uint32> memberAsn = new ImmutableLeafNodeBuilder<>();
355 memberAsn.withNodeIdentifier(NodeNlriParser.MEMBER_ASN_NID);
356 memberAsn.withValue(Uint32.valueOf(258L));
358 localNodeDescriptors.addChild(bgpRouterId.build());
359 localNodeDescriptors.addChild(memberAsn.build());
361 // remote descriptors
362 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> remoteNodeDescriptors =
363 Builders.containerBuilder();
364 remoteNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.REMOTE_NODE_DESCRIPTORS_NID);
365 remoteNodeDescriptors.addChild(asNumber.build());
366 remoteNodeDescriptors.addChild(domainID.build());
368 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId2 = Builders.choiceBuilder();
369 crouterId2.withNodeIdentifier(C_ROUTER_ID_NID);
371 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> ospfNode = Builders.containerBuilder();
372 ospfNode.withNodeIdentifier(NodeNlriParser.OSPF_NODE_NID);
374 final ImmutableLeafNodeBuilder<Uint32> ospfRouterId = new ImmutableLeafNodeBuilder<>();
375 ospfRouterId.withNodeIdentifier(NodeNlriParser.OSPF_ROUTER_NID);
376 ospfRouterId.withValue(Uint32.valueOf(0x00000040L));
377 ospfNode.addChild(ospfRouterId.build());
378 crouterId2.addChild(ospfNode.build());
379 remoteNodeDescriptors.addChild(crouterId2.build());
380 final ImmutableLeafNodeBuilder<String> bgpRouterIdRemote = new ImmutableLeafNodeBuilder<>();
381 bgpRouterIdRemote.withNodeIdentifier(NodeNlriParser.BGP_ROUTER_NID);
382 bgpRouterIdRemote.withValue("1.1.1.2");
383 remoteNodeDescriptors.addChild(bgpRouterIdRemote.build());
385 final ImmutableLeafNodeBuilder<Uint32> memberAsnRemote = new ImmutableLeafNodeBuilder<>();
386 memberAsnRemote.withNodeIdentifier(NodeNlriParser.MEMBER_ASN_NID);
387 memberAsnRemote.withValue(Uint32.valueOf(259));
388 remoteNodeDescriptors.addChild(memberAsnRemote.build());
391 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> linkDescriptors = Builders.containerBuilder();
392 linkDescriptors.withNodeIdentifier(LinkstateNlriParser.LINK_DESCRIPTORS_NID);
394 final ImmutableLeafNodeBuilder<Uint32> linkLocalIdentifier = new ImmutableLeafNodeBuilder<>();
395 linkLocalIdentifier.withNodeIdentifier(LinkNlriParser.LINK_LOCAL_NID);
396 linkLocalIdentifier.withValue(Uint32.valueOf(16909060L));
398 final ImmutableLeafNodeBuilder<Uint32> linkRemoteIdentifier = new ImmutableLeafNodeBuilder<>();
399 linkRemoteIdentifier.withNodeIdentifier(LinkNlriParser.LINK_REMOTE_NID);
400 linkRemoteIdentifier.withValue(Uint32.valueOf(168496141L));
402 final ImmutableLeafNodeBuilder<String> ipv4InterfaceAddress = new ImmutableLeafNodeBuilder<>();
403 ipv4InterfaceAddress.withNodeIdentifier(LinkNlriParser.IPV4_IFACE_NID);
404 ipv4InterfaceAddress.withValue("197.20.160.42");
406 final ImmutableLeafNodeBuilder<String> ipv4NeighborAddress = new ImmutableLeafNodeBuilder<>();
407 ipv4NeighborAddress.withNodeIdentifier(LinkNlriParser.IPV4_NEIGHBOR_NID);
408 ipv4NeighborAddress.withValue("197.20.160.40");
410 final ImmutableLeafNodeBuilder<Integer> multiTopologyId = new ImmutableLeafNodeBuilder<>();
411 multiTopologyId.withNodeIdentifier(TlvUtil.MULTI_TOPOLOGY_NID);
412 multiTopologyId.withValue(3);
414 linkDescriptors.addChild(linkLocalIdentifier.build());
415 linkDescriptors.addChild(linkRemoteIdentifier.build());
416 linkDescriptors.addChild(ipv4InterfaceAddress.build());
417 linkDescriptors.addChild(ipv4NeighborAddress.build());
418 linkDescriptors.addChild(multiTopologyId.build());
420 objectType.addChild(localNodeDescriptors.build());
421 objectType.addChild(remoteNodeDescriptors.build());
422 objectType.addChild(linkDescriptors.build());
424 linkstateBI.addChild(objectType.build());
425 assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
429 public void testPrefixNlri() throws BGPParsingException {
430 setUp(this.prefixNlri);
433 assertNull(this.dest.getRouteDistinguisher());
434 assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
435 assertEquals(Uint64.ONE, this.dest.getIdentifier().getValue());
437 final PrefixCase pCase = (PrefixCase) this.dest.getObjectType();
439 final AdvertisingNodeDescriptors local = pCase.getAdvertisingNodeDescriptors();
440 assertEquals(new AsNumber(72L), local.getAsNumber());
441 assertEquals(new DomainIdentifier(0x28282828L), local.getDomainId());
443 new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder().setIsoSystemId(
444 new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
445 (byte) 0x42 })).build()).build(), local.getCRouterIdentifier());
447 final PrefixDescriptors pd = pCase.getPrefixDescriptors();
448 assertEquals(OspfRouteType.External1, pd.getOspfRouteType());
449 assertEquals(new TopologyIdentifier(15), pd.getMultiTopologyId());
450 assertEquals(new Ipv4Prefix("255.255.0.0/16"), pd.getIpReachabilityInformation().getIpv4Prefix());
452 final ByteBuf buffer = Unpooled.buffer();
453 this.registry.serializeNlriType(this.dest, buffer);
454 assertArrayEquals(this.prefixNlri, ByteArray.readAllBytes(buffer));
457 final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI =
458 ImmutableUnkeyedListEntryNodeBuilder.create();
459 linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
461 final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
462 protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
463 protocolId.withValue("isis-level2");
464 linkstateBI.addChild(protocolId.build());
466 final ImmutableLeafNodeBuilder<Uint64> identifier = new ImmutableLeafNodeBuilder<>();
467 identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
468 identifier.withValue(Uint64.ONE);
469 linkstateBI.addChild(identifier.build());
471 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
472 objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
474 // advertising node descriptors
475 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> advertisingNodeDescriptors =
476 Builders.containerBuilder();
477 advertisingNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.ADVERTISING_NODE_DESCRIPTORS_NID);
479 final ImmutableLeafNodeBuilder<Uint32> asNumber = new ImmutableLeafNodeBuilder<>();
480 asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID);
481 asNumber.withValue(Uint32.valueOf(72));
482 advertisingNodeDescriptors.addChild(asNumber.build());
484 final ImmutableLeafNodeBuilder<Uint32> domainID = new ImmutableLeafNodeBuilder<>();
485 domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID);
486 domainID.withValue(Uint32.valueOf(673720360L));
487 advertisingNodeDescriptors.addChild(domainID.build());
489 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId = Builders.choiceBuilder();
490 crouterId.withNodeIdentifier(C_ROUTER_ID_NID);
492 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> isisNode = Builders.containerBuilder();
493 isisNode.withNodeIdentifier(NodeNlriParser.ISIS_NODE_NID);
495 final ImmutableLeafNodeBuilder<byte[]> isoSystemID = new ImmutableLeafNodeBuilder<>();
496 isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID);
497 isoSystemID.withValue(new byte[] { 0, 0, 0, 0, 0, (byte) 0x42 });
499 isisNode.addChild(isoSystemID.build());
500 crouterId.addChild(isisNode.build());
501 advertisingNodeDescriptors.addChild(crouterId.build());
503 // prefix descriptors
504 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> prefixDescriptors =
505 Builders.containerBuilder();
506 prefixDescriptors.withNodeIdentifier(LinkstateNlriParser.PREFIX_DESCRIPTORS_NID);
507 prefixDescriptors.addChild(asNumber.build());
508 prefixDescriptors.addChild(domainID.build());
510 final ImmutableLeafNodeBuilder<Integer> multiTopologyId = new ImmutableLeafNodeBuilder<>();
511 multiTopologyId.withNodeIdentifier(TlvUtil.MULTI_TOPOLOGY_NID);
512 multiTopologyId.withValue(15);
514 prefixDescriptors.addChild(multiTopologyId.build());
516 final ImmutableLeafNodeBuilder<String> ipReachabilityInformation = new ImmutableLeafNodeBuilder<>();
517 ipReachabilityInformation.withNodeIdentifier(IP_REACH_NID);
518 ipReachabilityInformation.withValue("255.255.0.0/16");
520 prefixDescriptors.addChild(ipReachabilityInformation.build());
522 final ImmutableLeafNodeBuilder<String> ospfRouteType = new ImmutableLeafNodeBuilder<>();
523 ospfRouteType.withNodeIdentifier(OSPF_ROUTE_NID);
524 ospfRouteType.withValue("external1");
526 prefixDescriptors.addChild(ospfRouteType.build());
528 objectType.addChild(advertisingNodeDescriptors.build());
529 objectType.addChild(prefixDescriptors.build());
531 linkstateBI.addChild(objectType.build());
532 assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
536 public void testTELspNlri() throws BGPParsingException {
537 setUp(this.teLspNlri);
539 assertNull(this.dest.getRouteDistinguisher());
540 assertEquals(ProtocolId.RsvpTe, this.dest.getProtocolId());
541 assertEquals(Uint64.ONE, this.dest.getIdentifier().getValue());
542 final TeLspCase teCase = (TeLspCase) this.dest.getObjectType();
544 assertEquals(new LspId(1L), teCase.getLspId());
545 assertEquals(new TunnelId(1), teCase.getTunnelId());
546 assertEquals(new Ipv4Address("1.2.3.4"), ((Ipv4Case) teCase.getAddressFamily()).getIpv4TunnelSenderAddress());
547 assertEquals(new Ipv4Address("4.3.2.1"), ((Ipv4Case) teCase.getAddressFamily()).getIpv4TunnelEndpointAddress());
550 final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI =
551 ImmutableUnkeyedListEntryNodeBuilder.create();
552 linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
554 final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
555 protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
556 protocolId.withValue("rsvp-te");
557 linkstateBI.addChild(protocolId.build());
559 final ImmutableLeafNodeBuilder<Uint64> identifier = new ImmutableLeafNodeBuilder<>();
560 identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
561 identifier.withValue(Uint64.ONE);
562 linkstateBI.addChild(identifier.build());
564 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
565 objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
567 final ImmutableLeafNodeBuilder<Long> lspId = new ImmutableLeafNodeBuilder<>();
568 lspId.withNodeIdentifier(AbstractTeLspNlriCodec.LSP_ID);
571 final ImmutableLeafNodeBuilder<Integer> tunnelId = new ImmutableLeafNodeBuilder<>();
572 tunnelId.withNodeIdentifier(AbstractTeLspNlriCodec.TUNNEL_ID);
573 tunnelId.withValue(1);
575 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> addressFamily = Builders.choiceBuilder();
576 addressFamily.withNodeIdentifier(AbstractTeLspNlriCodec.ADDRESS_FAMILY);
578 final ImmutableLeafNodeBuilder<String> ipv4TunnelSenderAddress = new ImmutableLeafNodeBuilder<>();
579 ipv4TunnelSenderAddress.withNodeIdentifier(AbstractTeLspNlriCodec.IPV4_TUNNEL_SENDER_ADDRESS);
580 ipv4TunnelSenderAddress.withValue("1.2.3.4");
582 final ImmutableLeafNodeBuilder<String> ipv4TunnelEndPointAddress = new ImmutableLeafNodeBuilder<>();
583 ipv4TunnelEndPointAddress.withNodeIdentifier(AbstractTeLspNlriCodec.IPV4_TUNNEL_ENDPOINT_ADDRESS);
584 ipv4TunnelEndPointAddress.withValue("4.3.2.1");
586 addressFamily.addChild(ipv4TunnelSenderAddress.build());
587 addressFamily.addChild(ipv4TunnelEndPointAddress.build());
589 objectType.addChild(lspId.build());
590 objectType.addChild(tunnelId.build());
591 objectType.addChild(addressFamily.build());
593 linkstateBI.addChild(objectType.build());
594 assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
598 public void testSerializeAttribute() throws BGPParsingException {
599 final LinkstateNlriParser parser = new LinkstateNlriParser();
600 setUp(this.prefixNlri);
601 final List<CLinkstateDestination> dests = Lists.newArrayList(this.dest);
602 final DestinationLinkstateCase dlc = new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
603 new DestinationLinkstateBuilder().setCLinkstateDestination(dests).build()).build();
604 final AdvertizedRoutes aroutes = new AdvertizedRoutesBuilder().setDestinationType(dlc).build();
605 final Attributes1 reach = new Attributes1Builder().setMpReachNlri(new MpReachNlriBuilder()
606 .setAdvertizedRoutes(aroutes).build()).build();
608 Attributes pa = new AttributesBuilder().addAugmentation(Attributes1.class, reach).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.rev180329.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.rev180329.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.bgp
621 .linkstate.rev180329.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();
625 final Attributes2 unreach = new Attributes2Builder().setMpUnreachNlri(new MpUnreachNlriBuilder()
626 .setWithdrawnRoutes(wroutes).build()).build();
628 pa = new AttributesBuilder().addAugmentation(Attributes2.class, unreach).build();
630 result = Unpooled.buffer();
631 parser.serializeAttribute(pa, result);
632 assertArrayEquals(this.nodeNlri, ByteArray.getAllBytes(result));