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.assertFalse;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertTrue;
16 import com.google.common.collect.Lists;
17 import io.netty.buffer.ByteBuf;
18 import io.netty.buffer.Unpooled;
19 import java.util.Arrays;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.opendaylight.protocol.bgp.linkstate.impl.attribute.LinkstateAttributeParser;
23 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
24 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
25 import org.opendaylight.protocol.rsvp.parser.impl.RSVPActivator;
26 import org.opendaylight.protocol.rsvp.parser.spi.RSVPExtensionProviderContext;
27 import org.opendaylight.protocol.rsvp.parser.spi.pojo.SimpleRSVPExtensionProviderContext;
28 import org.opendaylight.protocol.util.ByteArray;
29 import org.opendaylight.protocol.util.Ipv4Util;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv4CaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.Attributes1;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.LinkProtectionType;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.LinkstateAddressFamily;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.LinkstateSubsequentAddressFamily;
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.linkstate.ObjectType;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.destination.CLinkstateDestinationBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.LinkCaseBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.NodeCaseBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.PrefixCaseBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.TeLspCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.prefix._case.PrefixDescriptorsBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.LinkAttributesCase;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.NodeAttributesCase;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.TeLspAttributesCase;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributes;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributes;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributes;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.te.lsp.attributes._case.TeLspAttributes;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.prefix.state.IgpBits;
55 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;
56 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;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1Builder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2Builder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlriBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlriBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.adj.flags.flags.IsisAdjFlagsCase;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.adj.flags.flags.IsisAdjFlagsCaseBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.adj.flags.flags.isis.adj.flags._case.IsisAdjFlagsBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.sid.label.index.sid.label.index.LocalLabelCase;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.sid.label.index.sid.label.index.SidCase;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AssociationType;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.association.object.AssociationObject;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.tspec.object.TspecObject;
74 import org.opendaylight.yangtools.yang.common.Uint32;
75 import org.opendaylight.yangtools.yang.common.Uint8;
77 public class LinkstateAttributeParserTest {
79 private static final byte[] TE_LSP_ATTR = {
80 0x00, (byte) 0x63, 0x00, (byte) 0x30, // TE LSP Attribute Type, length, value
81 0x00, (byte) 0x20, (byte) 0x0c, 0x02, // Length, Class, Ctype
82 0x00, 0x00, 0x00, 0x07,
83 0x01, 0x00, 0x00, 0x06,
84 (byte) 0x7f, 0x00, 0x00, 0x05,
85 0x00, 0x00, 0x00, 0x01, //Token Bucket Rate
86 0x00, 0x00, 0x00, 0x02, //Token Bucket Size
87 0x00, 0x00, 0x00, 0x03, //Peak Data Rate
88 0x00, 0x00, 0x00, 0x04, //Minimum Policed Unit
89 0x00, 0x00, 0x00, 0x05, //Maximum Packet Size
90 0x00, (byte) 0x08, (byte) 0xc7, 0x01, // Length, Class, Ctype
91 0x00, 0x01, 0x00, 0x02,
92 0x01, 0x02, 0x03, 0x04
95 private static final byte[] LINK_ATTR = {
96 0x04, 0x04, 0, 0x04, 0x2a, 0x2a, 0x2a, 0x2a, 0x04, 0x06, 0, 0x04, 0x2b, 0x2b, 0x2b, 0x2b, 0x04, 0x40, 0, 0x04,
97 0, 0, 0, 0, 0x04, 0x41, 0, 0x04, 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80, 0x04, 0x42, 0, 0x04, 0x46, 0x43,
98 0x50, 0, 0x04, 0x43, 0, 0x20, 0x46, 0x43, 0x50, 0, 0x46, 0x43, 0x50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x04, 0x44, 0, 0x08, 0, 0, 0, 0, 0, 0, 0, 0, 0x04, 0x45, 0, 0x02, 0, 0x08,
100 0x04, 0x46, 0, 0x01, (byte) 0xc0, 0x04, 0x47, 0, 0x03, 0, 0, 0x0a, 0x04, 0x48, 0, 0x08, 0x12, 0x34, 0x56, 0x78,
101 0x10, 0x30, 0x50, 0x70, 0x04, 0x4a, 0, 0x05, 0x31, 0x32, 0x4b, 0x2d, 0x32,
102 0x04, 0x4b, 0, 0x07, (byte)-80, 10, 0, 0, (byte)0x0f, (byte)0xff, (byte)0xff, // sr-adj
103 0x04, 0x4b, 0, 0x07, (byte)-80, 10, 0, 0, (byte)0x0f, (byte)0xff, (byte)0xef, // sr-adj
104 0x04, 0x4c, 0, 0x0d, (byte)-80, 10, 0, 0, 1, 2, 3, 4, 5, 6, (byte)0x0f, (byte)0xff, (byte)0xff, // sr-lan-adj
105 0x04, 0x4c, 0, 0x0d, (byte)-80, 10, 0, 0, 1, 2, 3, 4, 5, 6, (byte)0x0f, (byte)0xff, (byte)0xef, // sr-lan-adj
106 0x04, 0x4d, 0, 0x08, 0, 0x05, 0, 0, 0x0a, 0x0b, 0x0c, 0x0d, // peer-node-sid
107 0x04, 0x4e, 0, 0x08, 0, 0x05, 0, 0, 0x0a, 0x0b, 0x0c, 0x0f, // peer-adj-sid
108 0x04, 0x4f, 0, 0x08, 0, 0x05, 0, 0, 0x0a, 0x0b, 0x0c, 0x0e, // peer-set-sid
109 // Performace Metrics
110 0x04, 0x5a, 0, 0x04, 0, 0, 0x27, 0x10, // Link Delay
111 0x04, 0x5b, 0, 0x08, 0, 0, 0x13, (byte)0x88, 0, 0, 0x4e, 0x20, // Link Min-Max Delay
112 0x04, 0x5c, 0, 0x04, 0, 0, 0x27, 0x10, // Link Delay Variation
113 0x04, 0x5d, 0, 0x04, 0, 0, 0, 0, // Link Loss
114 0x04, 0x5e, 0, 0x04, 0x46, 0x43, 0x50, 0, // Residual Bandwidth
115 0x04, 0x5f, 0, 0x04, 0x46, 0x43, 0x50, 0, // Available Bandwidth
116 0x04, 0x60, 0, 0x04, 0, 0, 0, 0, // Utilized Bandwidth
117 0x04, (byte) 0x88, 0, 0x01, 0x0a
120 private static final byte[] NODE_ATTR = {
121 0x01, 0x07, 0, 0x04, 0, 0x2a, 0, 0x2b, 0x04, 0, 0, 0x01, (byte) 0xbc, 0x04, 0x02, 0, 0x05, 0x31, 0x32, 0x4b,
122 0x2d, 0x32, 0x04, 0x03, 0, 0x01, 0x72, 0x04, 0x03, 0, 0x01, 0x73, 0x04, 0x04, 0, 0x04, 0x29, 0x29, 0x29, 0x29,
123 0x04, (byte) 0x88, 0, 0x01, 0x0a,
124 4, 0x0a, 0, 0x0c, (byte)0xe0, 0, 1, 2, 3, 4, (byte)0x89, 0, 3, 1, 2, 0, // sr-caps
125 4, 0x0b, 0, 2, 0, 1 // sr-algorythms
128 private static final byte[] NODE_ATTR_S = {
129 0x01, 0x07, 0, 0x04, 0, 0x2a, 0, 0x2b, 0x04, 0, 0, 0x01, (byte) 0xbc, 0x04, 0x02, 0, 0x05, 0x31, 0x32, 0x4b,
130 0x2d, 0x32, 0x04, 0x03, 0, 0x01, 0x72, 0x04, 0x03, 0, 0x01, 0x73, 0x04, 0x04, 0, 0x04, 0x29, 0x29, 0x29, 0x29,
131 4, 0x0a, 0, 0x0c, (byte)0xe0, 0, 1, 2, 3, 4, (byte)0x89, 0, 3, 1, 2, 0, // sr-caps
132 4, 0x0b, 0, 2, 0, 1 // sr-algorythms
135 private static final byte[] P4_ATTR = {
136 0x04, (byte) 0x80, 0, 0x01, (byte) 0xF0, 0x04, (byte) 0x81, 0, 0x08, 0x12, 0x34, 0x56, 0x78,
137 0x10, 0x30, 0x50, 0x70, 0x04, (byte) 0x82, 0, 0x08, 0x12, 0x34, 0x56, 0x78, 0x10, 0x30, 0x50, 0x70,
138 0x04, (byte) 0x83, 0, 0x04, 0, 0, 0, 0x0a, 0x04, (byte) 0x84, 0, 0x04, 0x0a, 0x19, 0x02, 0x1b,
139 4, (byte)0x86, 0,8, (byte)0xf0, 0, 0,0, 1,2,3,4, // prefix-sid tlv
140 4, (byte)0x87, 0,0x0c, 0, 0, 0, 5, 4, (byte)0x89, 0, 4, 1,2,3,4, // range tlv
141 4, (byte)0x88, 0, 4, 1, (byte)0xf0, 0, 0 // binding sid tlv
144 private RSVPExtensionProviderContext context;
145 private RSVPActivator rsvpActivator;
146 private LinkstateAttributeParser parser;
149 public final void setUp() {
150 this.context = new SimpleRSVPExtensionProviderContext();
151 this.rsvpActivator = new RSVPActivator();
152 this.rsvpActivator.start(this.context);
153 this.parser = new LinkstateAttributeParser(false,this.context.getRsvpRegistry());
156 private static AttributesBuilder createBuilder(final ObjectType type) {
157 return new AttributesBuilder().addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
158 .bgp.multiprotocol.rev180329.Attributes1.class, new Attributes1Builder().setMpReachNlri(
159 new MpReachNlriBuilder().setAfi(LinkstateAddressFamily.class)
160 .setSafi(LinkstateSubsequentAddressFamily.class)
161 .setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
162 new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
163 new DestinationLinkstateBuilder().setCLinkstateDestination(
164 Lists.newArrayList(new CLinkstateDestinationBuilder().setObjectType(type)
165 .setProtocolId(ProtocolId.IsisLevel1).build())).build()).build()).build()).build())
169 private static AttributesBuilder createUnreachBuilder(final ObjectType type) {
170 return new AttributesBuilder().addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
171 .bgp.multiprotocol.rev180329.Attributes2.class, new Attributes2Builder().setMpUnreachNlri(
172 new MpUnreachNlriBuilder().setAfi(LinkstateAddressFamily.class)
173 .setSafi(LinkstateSubsequentAddressFamily.class)
174 .setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
175 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update
176 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder()
177 .setDestinationLinkstate(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
178 .bgp.linkstate.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
179 .destination.linkstate._case.DestinationLinkstateBuilder().setCLinkstateDestination(
180 Lists.newArrayList(new CLinkstateDestinationBuilder().setObjectType(type)
181 .setProtocolId(ProtocolId.IsisLevel1).build())).build()).build()).build()).build())
186 public void testGetNlriType() throws BGPParsingException, BGPDocumentedException {
187 final ByteBuf b = Unpooled.buffer();
188 AttributesBuilder builder = new AttributesBuilder();
189 this.parser.parseAttribute(b, builder, null);
190 assertEquals(0, b.readableBytes());
191 builder = new AttributesBuilder();
193 final Attributes1Builder builder1 = new Attributes1Builder();
194 builder.addAugmentation(Attributes1.class, builder1.build());
195 this.parser.parseAttribute(b, builder, null);
196 assertEquals(0, b.readableBytes());
197 builder = new AttributesBuilder();
199 builder.addAugmentation(Attributes1.class, builder1.setMpReachNlri(
200 new MpReachNlriBuilder().setAdvertizedRoutes(new AdvertizedRoutesBuilder()
201 .setDestinationType(new DestinationIpv4CaseBuilder().build()).build()).build()).build());
202 this.parser.parseAttribute(b, builder, null);
203 assertEquals(0, b.readableBytes());
204 builder = new AttributesBuilder();
206 final Attributes2Builder builder2 = new Attributes2Builder();
207 builder.addAugmentation(Attributes2.class, builder2.build());
208 this.parser.parseAttribute(b, builder, null);
209 assertEquals(0, b.readableBytes());
210 builder = new AttributesBuilder();
212 builder.addAugmentation(Attributes2.class, builder2.setMpUnreachNlri(
213 new MpUnreachNlriBuilder().setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
214 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329
215 .update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6CaseBuilder()
216 .build()).build()).build()).build());
217 this.parser.parseAttribute(b, builder, null);
218 assertEquals(0, b.readableBytes());
222 public void testPositiveLinks() throws BGPParsingException, BGPDocumentedException {
223 final AttributesBuilder builder = createBuilder(new LinkCaseBuilder().build());
224 this.parser.parseAttribute(Unpooled.copiedBuffer(LINK_ATTR), builder, null);
225 final Attributes1 attrs = builder.augmentation(Attributes1.class);
226 final LinkAttributes ls = ((LinkAttributesCase) attrs.getLinkStateAttribute()).getLinkAttributes();
229 assertEquals("42.42.42.42", ls.getLocalIpv4RouterId().getValue());
230 assertEquals("43.43.43.43", ls.getRemoteIpv4RouterId().getValue());
231 assertEquals(Uint32.ZERO, ls.getAdminGroup().getValue());
232 assertArrayEquals(new byte[] { (byte) 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80 },
233 ls.getMaxLinkBandwidth().getValue());
234 assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 },
235 ls.getMaxReservableBandwidth().getValue());
236 assertNotNull(ls.getUnreservedBandwidth());
237 assertEquals(8, ls.getUnreservedBandwidth().size());
238 assertEquals(LinkProtectionType.Dedicated1to1, ls.getLinkProtection());
239 assertTrue(ls.getMplsProtocol().isLdp());
240 assertTrue(ls.getMplsProtocol().isRsvpte());
241 assertEquals(Uint32.TEN, ls.getMetric().getValue());
242 assertEquals(2, ls.getSharedRiskLinkGroups().size());
243 assertEquals(305419896, ls.getSharedRiskLinkGroups().get(0).getValue().intValue());
244 assertEquals("12K-2", ls.getLinkName());
245 final IsisAdjFlagsCase flags = new IsisAdjFlagsCaseBuilder()
246 .setIsisAdjFlags(new IsisAdjFlagsBuilder()
247 .setAddressFamily(Boolean.TRUE)
248 .setBackup(Boolean.FALSE)
249 .setSet(Boolean.FALSE)
252 assertEquals(flags, ls.getSrAdjIds().get(0).getFlags());
253 assertEquals(flags, ls.getSrAdjIds().get(1).getFlags());
254 assertEquals(Uint32.valueOf(1048575L),
255 ((LocalLabelCase)ls.getSrAdjIds().get(0).getSidLabelIndex()).getLocalLabel().getValue());
256 assertEquals(Uint32.valueOf(1048559L),
257 ((LocalLabelCase)ls.getSrAdjIds().get(1).getSidLabelIndex()).getLocalLabel().getValue());
258 assertEquals(Uint32.valueOf(168496141L), ((SidCase) ls.getPeerNodeSid().getSidLabelIndex()).getSid());
259 assertEquals(Uint8.valueOf(5), ls.getPeerNodeSid().getWeight().getValue());
260 assertEquals(Uint32.valueOf(168496142L), ((SidCase) ls.getPeerSetSids().get(0).getSidLabelIndex()).getSid());
261 assertEquals(Uint8.valueOf(5), ls.getPeerSetSids().get(0).getWeight().getValue());
262 assertEquals(Uint32.valueOf(168496143L), ((SidCase) ls.getPeerAdjSid().getSidLabelIndex()).getSid());
263 assertEquals(Uint8.valueOf(5), ls.getPeerAdjSid().getWeight().getValue());
265 // Performance Metrics
266 assertEquals(Uint32.valueOf(10000L), ls.getLinkDelay().getValue());
267 assertEquals(Uint32.valueOf(5000L), ls.getLinkMinMaxDelay().getMinDelay().getValue());
268 assertEquals(Uint32.valueOf(20000L), ls.getLinkMinMaxDelay().getMaxDelay().getValue());
269 assertEquals(Uint32.valueOf(10000L), ls.getDelayVariation().getValue());
270 assertEquals(Uint32.ZERO, ls.getLinkLoss().getValue());
271 assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 },
272 ls.getResidualBandwidth().getValue());
273 assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 },
274 ls.getAvailableBandwidth().getValue());
275 assertArrayEquals(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 },
276 ls.getUtilizedBandwidth().getValue());
279 final ByteBuf buff = Unpooled.buffer();
280 this.parser.serializeAttribute(builder.build(), buff);
281 // The LINK_ATTR buffer is now greater than 255 bytes. Need to skip one more byte
283 // there is unresolved TLV at the end, that needs to be cut off
285 assertArrayEquals(ByteArray.subByte(LINK_ATTR, 0, LINK_ATTR.length - 5), ByteArray.getAllBytes(buff));
289 public void testPositiveNodes() throws BGPParsingException, BGPDocumentedException {
290 final AttributesBuilder builder = createBuilder(new NodeCaseBuilder().build());
291 this.parser.parseAttribute(Unpooled.copiedBuffer(NODE_ATTR), builder, null);
293 final Attributes1 attrs = builder.augmentation(Attributes1.class);
294 final NodeAttributes ls = ((NodeAttributesCase) attrs.getLinkStateAttribute()).getNodeAttributes();
297 assertEquals(2, ls.getTopologyIdentifier().size());
298 assertEquals(42, ls.getTopologyIdentifier().get(0).getValue().intValue());
299 assertTrue(ls.getNodeFlags().isOverload());
300 assertFalse(ls.getNodeFlags().isAttached());
301 assertTrue(ls.getNodeFlags().isExternal());
302 assertTrue(ls.getNodeFlags().isAbr());
303 assertTrue(ls.getNodeFlags().isRouter());
304 assertTrue(ls.getNodeFlags().isV6());
306 assertEquals("12K-2", ls.getDynamicHostname());
307 assertEquals(2, ls.getIsisAreaId().size());
308 assertEquals("41.41.41.41", ls.getIpv4RouterId().getValue());
311 final ByteBuf buff = Unpooled.buffer();
312 this.parser.serializeAttribute(builder.build(), buff);
314 assertArrayEquals(NODE_ATTR_S, ByteArray.getAllBytes(buff));
318 public void testPositiveV4Prefixes() throws BGPParsingException, BGPDocumentedException {
319 final AttributesBuilder builder = createUnreachBuilder(new PrefixCaseBuilder().setPrefixDescriptors(
320 new PrefixDescriptorsBuilder().setIpReachabilityInformation(new IpPrefix(new Ipv4Prefix("127.0.0.1/32")))
322 this.parser.parseAttribute(Unpooled.copiedBuffer(P4_ATTR), builder, null);
324 final Attributes1 attrs = builder.augmentation(Attributes1.class);
325 final PrefixAttributes ls = ((PrefixAttributesCase) attrs.getLinkStateAttribute()).getPrefixAttributes();
328 assertNotNull(ls.getSrRange());
329 assertFalse(ls.getSrRange().isInterArea());
330 assertEquals(1, ls.getSrRange().getSubTlvs().size());
331 assertNotNull(ls.getSrBindingSidLabels());
332 final IgpBits ispBits = ls.getIgpBits();
333 assertTrue(ispBits.getUpDown().isUpDown());
334 assertTrue(ispBits.isIsIsUpDown());
335 assertTrue(ispBits.isOspfNoUnicast());
336 assertTrue(ispBits.isOspfLocalAddress());
337 assertTrue(ispBits.isOspfPropagateNssa());
338 assertEquals(2, ls.getRouteTags().size());
339 assertArrayEquals(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }, ls.getRouteTags().get(0)
341 assertEquals(1, ls.getExtendedTags().size());
342 assertArrayEquals(new byte[] {
343 (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x10, (byte) 0x30, (byte) 0x50, (byte) 0x70
344 }, ls.getExtendedTags().get(0).getValue());
345 assertEquals(10, ls.getPrefixMetric().getValue().intValue());
346 assertEquals("10.25.2.27", ls.getOspfForwardingAddress().getIpv4Address().getValue());
349 final ByteBuf buff = Unpooled.buffer();
350 this.parser.serializeAttribute(builder.build(), buff);
352 // there is unresolved TLV at the end, that needs to be cut off
353 assertArrayEquals(P4_ATTR, ByteArray.getAllBytes(buff));
357 public void testPositiveTELspAttribute() throws BGPParsingException, BGPDocumentedException {
358 final AttributesBuilder builder = createBuilder(new TeLspCaseBuilder().build());
359 this.parser.parseAttribute(Unpooled.copiedBuffer(TE_LSP_ATTR), builder, null);
361 final Attributes1 attrs = builder.augmentation(Attributes1.class);
362 final TeLspAttributes teLspAttributes = ((TeLspAttributesCase) attrs.getLinkStateAttribute())
363 .getTeLspAttributes();
364 assertNotNull(teLspAttributes);
365 final TspecObject tSpec = teLspAttributes.getTspecObject();
366 assertNotNull(tSpec);
367 assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01}),
368 tSpec.getTokenBucketRate());
369 assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02}),
370 teLspAttributes.getTspecObject().getTokenBucketSize());
371 assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03}),
372 tSpec.getPeakDataRate());
373 assertEquals(Uint32.valueOf(4), tSpec.getMinimumPolicedUnit());
374 assertEquals(Uint32.valueOf(5), tSpec.getMaximumPacketSize());
376 final AssociationObject associationObject = teLspAttributes.getAssociationObject();
377 assertEquals(AssociationType.Recovery, associationObject.getAssociationType());
378 final IpAddressNoZone ipv4 = new IpAddressNoZone(Ipv4Util.noZoneAddressForByteBuf(Unpooled.copiedBuffer(
379 new byte[]{0x01, 0x02, 0x03, 0x04})));
380 assertEquals(ipv4, associationObject.getIpAddress());
381 final short associationId = 2;
382 assertEquals(associationId, associationObject.getAssociationId().shortValue());
385 final ByteBuf buff = Unpooled.buffer();
386 this.parser.serializeAttribute(builder.build(), buff);
387 assertArrayEquals(TE_LSP_ATTR, ByteArray.getAllBytes(buff));
388 assertTrue(Arrays.equals(TE_LSP_ATTR, ByteArray.getAllBytes(buff)));