Enforce checkstyle in bgp-linkstate
[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 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.sid.label.index.sid.label.index.LocalLabelCase;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.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
74 public class LinkstateAttributeParserTest {
75
76     private static final byte[] TE_LSP_ATTR = {
77         0x00, (byte) 0x63, 0x00, (byte) 0x30, // TE LSP Attribute Type, length, value
78         0x00, (byte) 0x20, (byte) 0x0c, 0x02,  // Length, Class, Ctype
79         0x00, 0x00, 0x00, 0x07,
80         0x01, 0x00, 0x00, 0x06,
81         (byte) 0x7f, 0x00, 0x00, 0x05,
82         0x00, 0x00, 0x00, 0x01, //Token Bucket Rate
83         0x00, 0x00, 0x00, 0x02, //Token Bucket Size
84         0x00, 0x00, 0x00, 0x03, //Peak Data Rate
85         0x00, 0x00, 0x00, 0x04, //Minimum Policed Unit
86         0x00, 0x00, 0x00, 0x05, //Maximum Packet Size
87         0x00, (byte) 0x08, (byte) 0xc7, 0x01,  // Length, Class, Ctype
88         0x00, 0x01, 0x00, 0x02,
89         0x01, 0x02, 0x03, 0x04
90     };
91
92     private static final byte[] LINK_ATTR = {
93         0x04, 0x04, 0, 0x04, 0x2a, 0x2a, 0x2a, 0x2a, 0x04, 0x06, 0, 0x04, 0x2b, 0x2b, 0x2b, 0x2b, 0x04, 0x40, 0, 0x04,
94         0, 0, 0, 0, 0x04, 0x41, 0, 0x04, 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80, 0x04, 0x42, 0, 0x04, 0x46, 0x43,
95         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,
96         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,
97         0x04, 0x46, 0, 0x01, (byte) 0xc0, 0x04, 0x47, 0, 0x03, 0, 0, 0x0a, 0x04, 0x48, 0, 0x08, 0x12, 0x34, 0x56, 0x78,
98         0x10, 0x30, 0x50, 0x70, 0x04, 0x4a, 0, 0x05, 0x31, 0x32, 0x4b, 0x2d, 0x32,
99         0x04, 0x4b, 0, 0x07, (byte)-80, 10, 0, 0, (byte)0x0f, (byte)0xff, (byte)0xff, // sr-adj
100         0x04, 0x4b, 0, 0x07, (byte)-80, 10, 0, 0, (byte)0x0f, (byte)0xff, (byte)0xef, // sr-adj
101         0x04, 0x4c, 0, 0x0d, (byte)-80, 10, 0, 0, 1, 2, 3, 4, 5, 6, (byte)0x0f, (byte)0xff, (byte)0xff, // sr-lan-adj
102         0x04, 0x4c, 0, 0x0d, (byte)-80, 10, 0, 0, 1, 2, 3, 4, 5, 6, (byte)0x0f, (byte)0xff, (byte)0xef, // sr-lan-adj
103         0x04, 0x4d, 0, 0x08, 0, 0x05, 0, 0, 0x0a, 0x0b, 0x0c, 0x0d, // peer-node-sid
104         0x04, 0x4e, 0, 0x08, 0, 0x05, 0, 0, 0x0a, 0x0b, 0x0c, 0x0f, // peer-adj-sid
105         0x04, 0x4f, 0, 0x08, 0, 0x05, 0, 0, 0x0a, 0x0b, 0x0c, 0x0e, // peer-set-sid
106         // Performace Metrics
107         0x04, 0x5a, 0, 0x04, 0, 0, 0x27, 0x10, // Link Delay
108         0x04, 0x5b, 0, 0x08, 0, 0, 0x13, (byte)0x88, 0, 0, 0x4e, 0x20, // Link Min-Max Delay
109         0x04, 0x5c, 0, 0x04, 0, 0, 0x27, 0x10, // Link Delay Variation
110         0x04, 0x5d, 0, 0x04, 0, 0, 0, 0, // Link Loss
111         0x04, 0x5e, 0, 0x04, 0x46, 0x43, 0x50, 0, // Residual Bandwidth
112         0x04, 0x5f, 0, 0x04, 0x46, 0x43, 0x50, 0, // Available Bandwidth
113         0x04, 0x60, 0, 0x04, 0, 0, 0, 0,  // Utilized Bandwidth
114         0x04, (byte) 0x88, 0, 0x01, 0x0a
115     };
116
117     private static final byte[] NODE_ATTR = {
118         0x01, 0x07, 0, 0x04, 0, 0x2a, 0, 0x2b, 0x04, 0, 0, 0x01, (byte) 0xbc, 0x04, 0x02, 0, 0x05, 0x31, 0x32, 0x4b,
119         0x2d, 0x32, 0x04, 0x03, 0, 0x01, 0x72, 0x04, 0x03, 0, 0x01, 0x73, 0x04, 0x04, 0, 0x04, 0x29, 0x29, 0x29, 0x29,
120         0x04, (byte) 0x88, 0, 0x01, 0x0a,
121         4, 0x0a, 0, 0x0c, (byte)0xe0, 0, 1, 2, 3, 4, (byte)0x89, 0, 3, 1, 2, 0, // sr-caps
122         4, 0x0b, 0, 2, 0, 1 // sr-algorythms
123     };
124
125     private static final byte[] NODE_ATTR_S = {
126         0x01, 0x07, 0, 0x04, 0, 0x2a, 0, 0x2b, 0x04, 0, 0, 0x01, (byte) 0xbc, 0x04, 0x02, 0, 0x05, 0x31, 0x32, 0x4b,
127         0x2d, 0x32, 0x04, 0x03, 0, 0x01, 0x72, 0x04, 0x03, 0, 0x01, 0x73, 0x04, 0x04, 0, 0x04, 0x29, 0x29, 0x29, 0x29,
128         4, 0x0a, 0, 0x0c, (byte)0xe0, 0, 1, 2, 3, 4, (byte)0x89, 0, 3, 1, 2, 0, // sr-caps
129         4, 0x0b, 0, 2, 0, 1 // sr-algorythms
130     };
131
132     private static final byte[] P4_ATTR = {
133         0x04, (byte) 0x80, 0, 0x01, (byte) 0xF0, 0x04, (byte) 0x81, 0, 0x08, 0x12, 0x34, 0x56, 0x78,
134         0x10, 0x30, 0x50, 0x70, 0x04, (byte) 0x82, 0, 0x08, 0x12, 0x34, 0x56, 0x78, 0x10, 0x30, 0x50, 0x70,
135         0x04, (byte) 0x83, 0, 0x04, 0, 0, 0, 0x0a, 0x04, (byte) 0x84, 0, 0x04, 0x0a, 0x19, 0x02, 0x1b,
136         4, (byte)0x86, 0,8, (byte)0xf0, 0, 0,0, 1,2,3,4, // prefix-sid tlv
137         4, (byte)0x87, 0,0x0c, 0, 0, 0, 5, 4, (byte)0x89, 0, 4, 1,2,3,4, // range tlv
138         4, (byte)0x88, 0, 4, 1, (byte)0xf0, 0, 0 // binding sid tlv
139     };
140
141     private RSVPExtensionProviderContext context;
142     private RSVPActivator rsvpActivator;
143     private LinkstateAttributeParser parser;
144
145     @Before
146     public final void setUp() {
147         this.context = new SimpleRSVPExtensionProviderContext();
148         this.rsvpActivator = new RSVPActivator();
149         this.rsvpActivator.start(this.context);
150         this.parser = new LinkstateAttributeParser(false,this.context.getRsvpRegistry());
151     }
152
153     private static AttributesBuilder createBuilder(final ObjectType type) {
154         return new AttributesBuilder().addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
155             .bgp.multiprotocol.rev180329.Attributes1.class, new Attributes1Builder().setMpReachNlri(
156                 new MpReachNlriBuilder().setAfi(LinkstateAddressFamily.class)
157                 .setSafi(LinkstateSubsequentAddressFamily.class)
158                 .setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
159                     new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
160                         new DestinationLinkstateBuilder().setCLinkstateDestination(
161                             Lists.newArrayList(new CLinkstateDestinationBuilder().setObjectType(type)
162                                 .setProtocolId(ProtocolId.IsisLevel1).build())).build()).build()).build()).build())
163             .build());
164     }
165
166     private static AttributesBuilder createUnreachBuilder(final ObjectType type) {
167         return new AttributesBuilder().addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
168             .bgp.multiprotocol.rev180329.Attributes2.class, new Attributes2Builder().setMpUnreachNlri(
169                 new MpUnreachNlriBuilder().setAfi(LinkstateAddressFamily.class)
170                 .setSafi(LinkstateSubsequentAddressFamily.class)
171                 .setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
172                     new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update
173                         .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder()
174                         .setDestinationLinkstate(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
175                             .bgp.linkstate.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
176                             .destination.linkstate._case.DestinationLinkstateBuilder().setCLinkstateDestination(
177                                 Lists.newArrayList(new CLinkstateDestinationBuilder().setObjectType(type)
178                                     .setProtocolId(ProtocolId.IsisLevel1).build())).build()).build()).build()).build())
179             .build());
180     }
181
182     @Test
183     public void testGetNlriType() throws BGPParsingException, BGPDocumentedException {
184         final ByteBuf b = Unpooled.buffer();
185         AttributesBuilder builder = new AttributesBuilder();
186         this.parser.parseAttribute(b, builder, null);
187         assertEquals(0, b.readableBytes());
188         builder = new AttributesBuilder();
189
190         final Attributes1Builder builder1 = new Attributes1Builder();
191         builder.addAugmentation(Attributes1.class, builder1.build());
192         this.parser.parseAttribute(b, builder, null);
193         assertEquals(0, b.readableBytes());
194         builder = new AttributesBuilder();
195
196         builder.addAugmentation(Attributes1.class, builder1.setMpReachNlri(
197             new MpReachNlriBuilder().setAdvertizedRoutes(new AdvertizedRoutesBuilder()
198                 .setDestinationType(new DestinationIpv4CaseBuilder().build()).build()).build()).build());
199         this.parser.parseAttribute(b, builder, null);
200         assertEquals(0, b.readableBytes());
201         builder = new AttributesBuilder();
202
203         final Attributes2Builder builder2 = new Attributes2Builder();
204         builder.addAugmentation(Attributes2.class, builder2.build());
205         this.parser.parseAttribute(b, builder, null);
206         assertEquals(0, b.readableBytes());
207         builder = new AttributesBuilder();
208
209         builder.addAugmentation(Attributes2.class, builder2.setMpUnreachNlri(
210             new MpUnreachNlriBuilder().setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
211                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329
212                 .update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6CaseBuilder()
213                 .build()).build()).build()).build());
214         this.parser.parseAttribute(b, builder, null);
215         assertEquals(0, b.readableBytes());
216     }
217
218     @Test
219     public void testPositiveLinks() throws BGPParsingException, BGPDocumentedException {
220         final AttributesBuilder builder = createBuilder(new LinkCaseBuilder().build());
221         this.parser.parseAttribute(Unpooled.copiedBuffer(LINK_ATTR), builder, null);
222         final Attributes1 attrs = builder.augmentation(Attributes1.class);
223         final LinkAttributes ls = ((LinkAttributesCase) attrs.getLinkStateAttribute()).getLinkAttributes();
224         assertNotNull(ls);
225
226         assertEquals("42.42.42.42", ls.getLocalIpv4RouterId().getValue());
227         assertEquals("43.43.43.43", ls.getRemoteIpv4RouterId().getValue());
228         assertEquals(Long.valueOf(0L), ls.getAdminGroup().getValue());
229         assertArrayEquals(new byte[] { (byte) 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80 },
230             ls.getMaxLinkBandwidth().getValue());
231         assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 },
232             ls.getMaxReservableBandwidth().getValue());
233         assertNotNull(ls.getUnreservedBandwidth());
234         assertEquals(8, ls.getUnreservedBandwidth().size());
235         assertEquals(LinkProtectionType.Dedicated1to1, ls.getLinkProtection());
236         assertTrue(ls.getMplsProtocol().isLdp());
237         assertTrue(ls.getMplsProtocol().isRsvpte());
238         assertEquals(new Long(10), ls.getMetric().getValue());
239         assertEquals(2, ls.getSharedRiskLinkGroups().size());
240         assertEquals(305419896, ls.getSharedRiskLinkGroups().get(0).getValue().intValue());
241         assertEquals("12K-2", ls.getLinkName());
242         final IsisAdjFlagsCase flags = new IsisAdjFlagsCaseBuilder().setAddressFamily(Boolean.TRUE)
243                 .setBackup(Boolean.FALSE).setSet(Boolean.FALSE).build();
244         assertEquals(flags, ls.getSrAdjIds().get(0).getFlags());
245         assertEquals(flags, ls.getSrAdjIds().get(1).getFlags());
246         assertEquals(new Long(1048575L), ((LocalLabelCase)ls.getSrAdjIds().get(0).getSidLabelIndex()).getLocalLabel()
247             .getValue());
248         assertEquals(new Long(1048559L), ((LocalLabelCase)ls.getSrAdjIds().get(1).getSidLabelIndex()).getLocalLabel()
249             .getValue());
250         assertEquals(new Long(168496141L), ((SidCase) ls.getPeerNodeSid().getSidLabelIndex()).getSid());
251         assertEquals(new Short("5"), ls.getPeerNodeSid().getWeight().getValue());
252         assertEquals(new Long(168496142L), ((SidCase) ls.getPeerSetSids().get(0).getSidLabelIndex()).getSid());
253         assertEquals(new Short("5"), ls.getPeerSetSids().get(0).getWeight().getValue());
254         assertEquals(new Long(168496143L), ((SidCase) ls.getPeerAdjSid().getSidLabelIndex()).getSid());
255         assertEquals(new Short("5"), ls.getPeerAdjSid().getWeight().getValue());
256
257         // Performance Metrics
258         assertEquals(new Long(10000L), ls.getLinkDelay().getValue());
259         assertEquals(new Long(5000L), ls.getLinkMinMaxDelay().getMinDelay().getValue());
260         assertEquals(new Long(20000L), ls.getLinkMinMaxDelay().getMaxDelay().getValue());
261         assertEquals(new Long(10000L), ls.getDelayVariation().getValue());
262         assertEquals(new Long(0L), ls.getLinkLoss().getValue());
263         assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 },
264                 ls.getResidualBandwidth().getValue());
265         assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 },
266                 ls.getAvailableBandwidth().getValue());
267         assertArrayEquals(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 },
268                 ls.getUtilizedBandwidth().getValue());
269
270         //serialization
271         final ByteBuf buff = Unpooled.buffer();
272         this.parser.serializeAttribute(builder.build(), buff);
273         // The LINK_ATTR buffer is now greater than 255 bytes. Need to skip one more byte
274         buff.skipBytes(4);
275         // there is unresolved TLV at the end, that needs to be cut off
276
277         assertArrayEquals(ByteArray.subByte(LINK_ATTR, 0, LINK_ATTR.length - 5), ByteArray.getAllBytes(buff));
278     }
279
280     @Test
281     public void testPositiveNodes() throws BGPParsingException, BGPDocumentedException {
282         final AttributesBuilder builder = createBuilder(new NodeCaseBuilder().build());
283         this.parser.parseAttribute(Unpooled.copiedBuffer(NODE_ATTR), builder, null);
284
285         final Attributes1 attrs = builder.augmentation(Attributes1.class);
286         final NodeAttributes ls = ((NodeAttributesCase) attrs.getLinkStateAttribute()).getNodeAttributes();
287         assertNotNull(ls);
288
289         assertEquals(2, ls.getTopologyIdentifier().size());
290         assertEquals(42, ls.getTopologyIdentifier().get(0).getValue().intValue());
291         assertTrue(ls.getNodeFlags().isOverload());
292         assertFalse(ls.getNodeFlags().isAttached());
293         assertTrue(ls.getNodeFlags().isExternal());
294         assertTrue(ls.getNodeFlags().isAbr());
295         assertTrue(ls.getNodeFlags().isRouter());
296         assertTrue(ls.getNodeFlags().isV6());
297
298         assertEquals("12K-2", ls.getDynamicHostname());
299         assertEquals(2, ls.getIsisAreaId().size());
300         assertEquals("41.41.41.41", ls.getIpv4RouterId().getValue());
301
302         //serialization
303         final ByteBuf buff = Unpooled.buffer();
304         this.parser.serializeAttribute(builder.build(), buff);
305         buff.skipBytes(3);
306         assertArrayEquals(NODE_ATTR_S, ByteArray.getAllBytes(buff));
307     }
308
309     @Test
310     public void testPositiveV4Prefixes() throws BGPParsingException, BGPDocumentedException {
311         final AttributesBuilder builder = createUnreachBuilder(new PrefixCaseBuilder().setPrefixDescriptors(
312             new PrefixDescriptorsBuilder().setIpReachabilityInformation(new IpPrefix(new Ipv4Prefix("127.0.0.1/32")))
313             .build()).build());
314         this.parser.parseAttribute(Unpooled.copiedBuffer(P4_ATTR), builder, null);
315
316         final Attributes1 attrs = builder.augmentation(Attributes1.class);
317         final PrefixAttributes ls = ((PrefixAttributesCase) attrs.getLinkStateAttribute()).getPrefixAttributes();
318         assertNotNull(ls);
319
320         assertNotNull(ls.getSrRange());
321         assertFalse(ls.getSrRange().isInterArea());
322         assertEquals(1, ls.getSrRange().getSubTlvs().size());
323         assertNotNull(ls.getSrBindingSidLabels());
324         final IgpBits ispBits = ls.getIgpBits();
325         assertTrue(ispBits.getUpDown().isUpDown());
326         assertTrue(ispBits.isIsIsUpDown());
327         assertTrue(ispBits.isOspfNoUnicast());
328         assertTrue(ispBits.isOspfLocalAddress());
329         assertTrue(ispBits.isOspfPropagateNssa());
330         assertEquals(2, ls.getRouteTags().size());
331         assertArrayEquals(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }, ls.getRouteTags().get(0)
332             .getValue());
333         assertEquals(1, ls.getExtendedTags().size());
334         assertArrayEquals(new byte[] {
335             (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x10, (byte) 0x30, (byte) 0x50, (byte) 0x70
336         }, ls.getExtendedTags().get(0).getValue());
337         assertEquals(10, ls.getPrefixMetric().getValue().intValue());
338         assertEquals("10.25.2.27", ls.getOspfForwardingAddress().getIpv4Address().getValue());
339
340         //serialization
341         final ByteBuf buff = Unpooled.buffer();
342         this.parser.serializeAttribute(builder.build(), buff);
343         buff.skipBytes(3);
344         // there is unresolved TLV at the end, that needs to be cut off
345         assertArrayEquals(P4_ATTR, ByteArray.getAllBytes(buff));
346     }
347
348     @Test
349     public void testPositiveTELspAttribute() throws BGPParsingException, BGPDocumentedException {
350         final AttributesBuilder builder = createBuilder(new TeLspCaseBuilder().build());
351         this.parser.parseAttribute(Unpooled.copiedBuffer(TE_LSP_ATTR), builder, null);
352
353         final Attributes1 attrs = builder.augmentation(Attributes1.class);
354         final TeLspAttributes teLspAttributes = ((TeLspAttributesCase) attrs.getLinkStateAttribute())
355                 .getTeLspAttributes();
356         assertNotNull(teLspAttributes);
357         final TspecObject tSpec = teLspAttributes.getTspecObject();
358         assertNotNull(tSpec);
359         assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01}),
360             tSpec.getTokenBucketRate());
361         assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02}),
362             teLspAttributes.getTspecObject().getTokenBucketSize());
363         assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03}),
364             tSpec.getPeakDataRate());
365         assertEquals(new Long("4"), tSpec.getMinimumPolicedUnit());
366         assertEquals(new Long("5"), tSpec.getMaximumPacketSize());
367
368         final AssociationObject associationObject = teLspAttributes.getAssociationObject();
369         assertEquals(AssociationType.Recovery, associationObject.getAssociationType());
370         final IpAddressNoZone ipv4 = new IpAddressNoZone(Ipv4Util.noZoneAddressForByteBuf(Unpooled.copiedBuffer(
371             new byte[]{0x01, 0x02, 0x03, 0x04})));
372         assertEquals(ipv4, associationObject.getIpAddress());
373         final short associationId = 2;
374         assertEquals(associationId, associationObject.getAssociationId().shortValue());
375
376         //serialization
377         final ByteBuf buff = Unpooled.buffer();
378         this.parser.serializeAttribute(builder.build(), buff);
379         assertArrayEquals(TE_LSP_ATTR, ByteArray.getAllBytes(buff));
380         assertTrue(Arrays.equals(TE_LSP_ATTR, ByteArray.getAllBytes(buff)));
381     }
382 }