Bump versions to 0.21.8-SNAPSHOT
[bgpcep.git] / bgp / extensions / linkstate / src / test / java / org / opendaylight / protocol / bgp / linkstate / LinkstateAttributeParserTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.protocol.bgp.linkstate;
9
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;
15
16 import io.netty.buffer.ByteBuf;
17 import io.netty.buffer.Unpooled;
18 import java.util.Arrays;
19 import java.util.List;
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.rev200120.Attributes1;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.LinkProtectionType;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.LinkstateAddressFamily;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.LinkstateSubsequentAddressFamily;
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.linkstate.ObjectType;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.destination.CLinkstateDestinationBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.LinkCaseBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.NodeCaseBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.PrefixCaseBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.TeLspCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.prefix._case.PrefixDescriptorsBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.LinkAttributesCase;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.NodeAttributesCase;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.TeLspAttributesCase;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.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.rev200120.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.rev200120.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.rev200120.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.rev200120.prefix.state.IgpBits;
55 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;
56 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;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesReachBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesUnreachBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.MpReachNlriBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.mp.reach.nlri.AdvertizedRoutesBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.MpUnreachNlriBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.mp.unreach.nlri.WithdrawnRoutesBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.adj.flags.flags.IsisAdjFlagsCase;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.adj.flags.flags.IsisAdjFlagsCaseBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.adj.flags.flags.isis.adj.flags._case.IsisAdjFlagsBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.LocalLabelCase;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.SidCase;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AssociationType;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.association.object.AssociationObject;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.tspec.object.TspecObject;
73 import org.opendaylight.yangtools.yang.common.Uint16;
74 import org.opendaylight.yangtools.yang.common.Uint32;
75 import org.opendaylight.yangtools.yang.common.Uint8;
76
77 public class LinkstateAttributeParserTest {
78
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
93     };
94
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
118     };
119
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
126     };
127
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
133     };
134
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
142     };
143
144     private RSVPExtensionProviderContext context;
145     private RSVPActivator rsvpActivator;
146     private LinkstateAttributeParser parser;
147
148     @Before
149     public final void setUp() {
150         context = new SimpleRSVPExtensionProviderContext();
151         rsvpActivator = new RSVPActivator();
152         rsvpActivator.start(context);
153         parser = new LinkstateAttributeParser(false,context.getRsvpRegistry());
154     }
155
156     private static AttributesBuilder createBuilder(final ObjectType type) {
157         return new AttributesBuilder().addAugmentation(new AttributesReachBuilder()
158             .setMpReachNlri(new MpReachNlriBuilder()
159                 .setAfi(LinkstateAddressFamily.VALUE)
160                 .setSafi(LinkstateSubsequentAddressFamily.VALUE)
161                 .setAdvertizedRoutes(new AdvertizedRoutesBuilder()
162                     .setDestinationType(new DestinationLinkstateCaseBuilder()
163                         .setDestinationLinkstate(new DestinationLinkstateBuilder()
164                             .setCLinkstateDestination(List.of(new CLinkstateDestinationBuilder()
165                                 .setObjectType(type)
166                                 .setProtocolId(ProtocolId.IsisLevel1)
167                                 .build()))
168                             .build())
169                         .build())
170                     .build())
171                 .build())
172             .build());
173     }
174
175     private static AttributesBuilder createUnreachBuilder(final ObjectType type) {
176         return new AttributesBuilder().addAugmentation(new AttributesUnreachBuilder()
177             .setMpUnreachNlri(new MpUnreachNlriBuilder()
178                 .setAfi(LinkstateAddressFamily.VALUE)
179                 .setSafi(LinkstateSubsequentAddressFamily.VALUE)
180                 .setWithdrawnRoutes(new WithdrawnRoutesBuilder()
181                     .setDestinationType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp
182                         .linkstate.rev200120.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
183                         .DestinationLinkstateCaseBuilder()
184                             .setDestinationLinkstate(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns
185                                 .yang.bgp.linkstate.rev200120.update.attributes.mp.unreach.nlri.withdrawn.routes
186                                 .destination.type.destination.linkstate._case.DestinationLinkstateBuilder()
187                                     .setCLinkstateDestination(List.of(new CLinkstateDestinationBuilder()
188                                         .setObjectType(type)
189                                         .setProtocolId(ProtocolId.IsisLevel1)
190                                         .build()))
191                                     .build())
192                             .build())
193                     .build())
194                 .build())
195             .build());
196     }
197
198     @Test
199     public void testGetNlriType() throws BGPParsingException, BGPDocumentedException {
200         final ByteBuf b = Unpooled.buffer();
201         AttributesBuilder builder = new AttributesBuilder();
202         parser.parseAttribute(b, builder, null);
203         assertEquals(0, b.readableBytes());
204         builder = new AttributesBuilder();
205
206         final AttributesReachBuilder builder1 = new AttributesReachBuilder();
207         builder.addAugmentation(builder1.build());
208         parser.parseAttribute(b, builder, null);
209         assertEquals(0, b.readableBytes());
210         builder = new AttributesBuilder();
211
212         builder.addAugmentation(builder1
213             .setMpReachNlri(new MpReachNlriBuilder()
214                 .setAdvertizedRoutes(new AdvertizedRoutesBuilder()
215                     .setDestinationType(new DestinationIpv4CaseBuilder().build())
216                     .build())
217                 .build())
218             .build());
219         parser.parseAttribute(b, builder, null);
220         assertEquals(0, b.readableBytes());
221         builder = new AttributesBuilder();
222
223         final AttributesUnreachBuilder builder2 = new AttributesUnreachBuilder();
224         builder.addAugmentation(builder2.build());
225         parser.parseAttribute(b, builder, null);
226         assertEquals(0, b.readableBytes());
227         builder = new AttributesBuilder();
228
229         builder.addAugmentation(builder2
230             .setMpUnreachNlri(new MpUnreachNlriBuilder()
231                 .setWithdrawnRoutes(new WithdrawnRoutesBuilder()
232                     .setDestinationType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet
233                         .rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
234                         .DestinationIpv6CaseBuilder().build())
235                     .build())
236                 .build())
237             .build());
238         parser.parseAttribute(b, builder, null);
239         assertEquals(0, b.readableBytes());
240     }
241
242     @Test
243     public void testPositiveLinks() throws BGPParsingException, BGPDocumentedException {
244         final AttributesBuilder builder = createBuilder(new LinkCaseBuilder().build());
245         parser.parseAttribute(Unpooled.copiedBuffer(LINK_ATTR), builder, null);
246         final Attributes1 attrs = builder.augmentation(Attributes1.class);
247         final LinkAttributes ls = ((LinkAttributesCase) attrs.getLinkStateAttribute()).getLinkAttributes();
248         assertNotNull(ls);
249
250         assertEquals("42.42.42.42", ls.getLocalIpv4RouterId().getValue());
251         assertEquals("43.43.43.43", ls.getRemoteIpv4RouterId().getValue());
252         assertEquals(Uint32.ZERO, ls.getAdminGroup().getValue());
253         assertArrayEquals(new byte[] { (byte) 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80 },
254             ls.getMaxLinkBandwidth().getValue());
255         assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 },
256             ls.getMaxReservableBandwidth().getValue());
257         assertNotNull(ls.getUnreservedBandwidth());
258         assertEquals(8, ls.getUnreservedBandwidth().size());
259         assertEquals(LinkProtectionType.Dedicated1to1, ls.getLinkProtection());
260         assertTrue(ls.getMplsProtocol().getLdp());
261         assertTrue(ls.getMplsProtocol().getRsvpte());
262         assertEquals(Uint32.TEN, ls.getMetric().getValue());
263         assertEquals(2, ls.getSharedRiskLinkGroups().size());
264         assertEquals(305419896, ls.getSharedRiskLinkGroups().iterator().next().getValue().intValue());
265         assertEquals("12K-2", ls.getLinkName());
266         final IsisAdjFlagsCase flags = new IsisAdjFlagsCaseBuilder()
267                 .setIsisAdjFlags(new IsisAdjFlagsBuilder()
268                     .setAddressFamily(Boolean.TRUE)
269                     .setBackup(Boolean.FALSE)
270                     .setSet(Boolean.FALSE)
271                     .build())
272                 .build();
273         assertEquals(flags, ls.getSrAdjIds().get(0).getFlags());
274         assertEquals(flags, ls.getSrAdjIds().get(1).getFlags());
275         assertEquals(Uint32.valueOf(1048575L),
276             ((LocalLabelCase)ls.getSrAdjIds().get(0).getSidLabelIndex()).getLocalLabel().getValue());
277         assertEquals(Uint32.valueOf(1048559L),
278             ((LocalLabelCase)ls.getSrAdjIds().get(1).getSidLabelIndex()).getLocalLabel().getValue());
279         assertEquals(Uint32.valueOf(168496141L), ((SidCase) ls.getPeerNodeSid().getSidLabelIndex()).getSid());
280         assertEquals(Uint8.valueOf(5), ls.getPeerNodeSid().getWeight().getValue());
281         assertEquals(Uint32.valueOf(168496142L), ((SidCase) ls.getPeerSetSids().get(0).getSidLabelIndex()).getSid());
282         assertEquals(Uint8.valueOf(5), ls.getPeerSetSids().get(0).getWeight().getValue());
283         assertEquals(Uint32.valueOf(168496143L), ((SidCase) ls.getPeerAdjSid().getSidLabelIndex()).getSid());
284         assertEquals(Uint8.valueOf(5), ls.getPeerAdjSid().getWeight().getValue());
285
286         // Performance Metrics
287         assertEquals(Uint32.valueOf(10000L), ls.getLinkDelay().getValue());
288         assertEquals(Uint32.valueOf(5000L), ls.getLinkMinMaxDelay().getMinDelay().getValue());
289         assertEquals(Uint32.valueOf(20000L), ls.getLinkMinMaxDelay().getMaxDelay().getValue());
290         assertEquals(Uint32.valueOf(10000L), ls.getDelayVariation().getValue());
291         assertEquals(Uint32.ZERO, ls.getLinkLoss().getValue());
292         assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 },
293                 ls.getResidualBandwidth().getValue());
294         assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 },
295                 ls.getAvailableBandwidth().getValue());
296         assertArrayEquals(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 },
297                 ls.getUtilizedBandwidth().getValue());
298
299         //serialization
300         final ByteBuf buff = Unpooled.buffer();
301         parser.serializeAttribute(builder.build(), buff);
302         // The LINK_ATTR buffer is now greater than 255 bytes. Need to skip one more byte
303         buff.skipBytes(4);
304         // there is unresolved TLV at the end, that needs to be cut off
305
306         assertArrayEquals(ByteArray.subByte(LINK_ATTR, 0, LINK_ATTR.length - 5), ByteArray.getAllBytes(buff));
307     }
308
309     @Test
310     public void testPositiveNodes() throws BGPParsingException, BGPDocumentedException {
311         final AttributesBuilder builder = createBuilder(new NodeCaseBuilder().build());
312         parser.parseAttribute(Unpooled.copiedBuffer(NODE_ATTR), builder, null);
313
314         final Attributes1 attrs = builder.augmentation(Attributes1.class);
315         final NodeAttributes ls = ((NodeAttributesCase) attrs.getLinkStateAttribute()).getNodeAttributes();
316         assertNotNull(ls);
317
318         assertEquals(2, ls.getTopologyIdentifier().size());
319         assertEquals(Uint16.valueOf(42), ls.getTopologyIdentifier().iterator().next().getValue());
320         assertTrue(ls.getNodeFlags().getOverload());
321         assertFalse(ls.getNodeFlags().getAttached());
322         assertTrue(ls.getNodeFlags().getExternal());
323         assertTrue(ls.getNodeFlags().getAbr());
324         assertTrue(ls.getNodeFlags().getRouter());
325         assertTrue(ls.getNodeFlags().getV6());
326
327         assertEquals("12K-2", ls.getDynamicHostname());
328         assertEquals(2, ls.getIsisAreaId().size());
329         assertEquals("41.41.41.41", ls.getIpv4RouterId().getValue());
330
331         //serialization
332         final ByteBuf buff = Unpooled.buffer();
333         parser.serializeAttribute(builder.build(), buff);
334         buff.skipBytes(3);
335         assertArrayEquals(NODE_ATTR_S, ByteArray.getAllBytes(buff));
336     }
337
338     @Test
339     public void testPositiveV4Prefixes() throws BGPParsingException, BGPDocumentedException {
340         final AttributesBuilder builder = createUnreachBuilder(new PrefixCaseBuilder().setPrefixDescriptors(
341             new PrefixDescriptorsBuilder().setIpReachabilityInformation(new IpPrefix(new Ipv4Prefix("127.0.0.1/32")))
342             .build()).build());
343         parser.parseAttribute(Unpooled.copiedBuffer(P4_ATTR), builder, null);
344
345         final Attributes1 attrs = builder.augmentation(Attributes1.class);
346         final PrefixAttributes ls = ((PrefixAttributesCase) attrs.getLinkStateAttribute()).getPrefixAttributes();
347         assertNotNull(ls);
348
349         assertNotNull(ls.getSrRange());
350         assertFalse(ls.getSrRange().getInterArea());
351         assertEquals(1, ls.getSrRange().getSubTlvs().size());
352         assertNotNull(ls.getSrBindingSidLabels());
353         final IgpBits ispBits = ls.getIgpBits();
354         assertTrue(ispBits.getUpDown().getUpDown());
355         assertTrue(ispBits.getIsIsUpDown());
356         assertTrue(ispBits.getOspfNoUnicast());
357         assertTrue(ispBits.getOspfLocalAddress());
358         assertTrue(ispBits.getOspfPropagateNssa());
359         assertEquals(2, ls.getRouteTags().size());
360         assertArrayEquals(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 },
361             ls.getRouteTags().iterator().next().getValue());
362         assertEquals(1, ls.getExtendedTags().size());
363         assertArrayEquals(new byte[] {
364             (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x10, (byte) 0x30, (byte) 0x50, (byte) 0x70
365         }, ls.getExtendedTags().iterator().next().getValue());
366         assertEquals(10, ls.getPrefixMetric().getValue().intValue());
367         assertEquals("10.25.2.27", ls.getOspfForwardingAddress().getIpv4AddressNoZone().getValue());
368
369         //serialization
370         final ByteBuf buff = Unpooled.buffer();
371         parser.serializeAttribute(builder.build(), buff);
372         buff.skipBytes(3);
373         // there is unresolved TLV at the end, that needs to be cut off
374         assertArrayEquals(P4_ATTR, ByteArray.getAllBytes(buff));
375     }
376
377     @Test
378     public void testPositiveTELspAttribute() throws BGPParsingException, BGPDocumentedException {
379         final AttributesBuilder builder = createBuilder(new TeLspCaseBuilder().build());
380         parser.parseAttribute(Unpooled.copiedBuffer(TE_LSP_ATTR), builder, null);
381
382         final Attributes1 attrs = builder.augmentation(Attributes1.class);
383         final TeLspAttributes teLspAttributes = ((TeLspAttributesCase) attrs.getLinkStateAttribute())
384                 .getTeLspAttributes();
385         assertNotNull(teLspAttributes);
386         final TspecObject tSpec = teLspAttributes.getTspecObject();
387         assertNotNull(tSpec);
388         assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01}),
389             tSpec.getTokenBucketRate());
390         assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02}),
391             teLspAttributes.getTspecObject().getTokenBucketSize());
392         assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03}),
393             tSpec.getPeakDataRate());
394         assertEquals(Uint32.valueOf(4), tSpec.getMinimumPolicedUnit());
395         assertEquals(Uint32.valueOf(5), tSpec.getMaximumPacketSize());
396
397         final AssociationObject associationObject = teLspAttributes.getAssociationObject();
398         assertEquals(AssociationType.Recovery, associationObject.getAssociationType());
399         final IpAddressNoZone ipv4 = new IpAddressNoZone(Ipv4Util.addressForByteBuf(Unpooled.copiedBuffer(
400             new byte[]{0x01, 0x02, 0x03, 0x04})));
401         assertEquals(ipv4, associationObject.getIpAddress());
402         final short associationId = 2;
403         assertEquals(associationId, associationObject.getAssociationId().shortValue());
404
405         //serialization
406         final ByteBuf buff = Unpooled.buffer();
407         parser.serializeAttribute(builder.build(), buff);
408         assertArrayEquals(TE_LSP_ATTR, ByteArray.getAllBytes(buff));
409         assertTrue(Arrays.equals(TE_LSP_ATTR, ByteArray.getAllBytes(buff)));
410     }
411 }