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.assertNull;
15 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.lang.reflect.Constructor;
20 import java.lang.reflect.InvocationTargetException;
21 import java.util.Arrays;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.opendaylight.protocol.bgp.linkstate.attribute.LinkAttributesParser;
25 import org.opendaylight.protocol.bgp.linkstate.attribute.LinkstateAttributeParser;
26 import org.opendaylight.protocol.bgp.linkstate.attribute.NodeAttributesParser;
27 import org.opendaylight.protocol.bgp.linkstate.attribute.PrefixAttributesParser;
28 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
29 import org.opendaylight.protocol.rsvp.parser.impl.RSVPActivator;
30 import org.opendaylight.protocol.rsvp.parser.spi.RSVPExtensionProviderContext;
31 import org.opendaylight.protocol.rsvp.parser.spi.pojo.SimpleRSVPExtensionProviderContext;
32 import org.opendaylight.protocol.util.ByteArray;
33 import org.opendaylight.protocol.util.Ipv4Util;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv4CaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Attributes1;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkProtectionType;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateSubsequentAddressFamily;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.link.state.PeerSetSids;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.link.state.PeerSetSidsBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestinationBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.LinkCaseBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCaseBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.PrefixCaseBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.TeLspCaseBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.prefix._case.PrefixDescriptorsBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.LinkAttributesCase;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.NodeAttributesCase;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.TeLspAttributesCase;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributes;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributes;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributes;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.te.lsp.attributes._case.TeLspAttributes;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCaseBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1Builder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2Builder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlriBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlriBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.Weight;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.adj.flags.Flags;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.adj.flags.flags.IsisAdjFlagsCase;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.adj.flags.flags.IsisAdjFlagsCaseBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.sid.label.index.sid.label.index.LocalLabelCase;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.sid.label.index.sid.label.index.SidCase;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.sid.label.index.sid.label.index.SidCaseBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AssociationType;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.association.object.AssociationObject;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.tspec.object.TspecObject;
82 public class LinkstateAttributeParserTest {
84 static final byte[] TE_LSP_ATTR = {0x00, (byte) 0x63, 0x00, (byte) 0x30, // TE LSP Attribute Type, lenght, value
85 0x00, (byte) 0x20, (byte) 0x0c, 0x02, // Lenght, Class, Ctype
86 0x00, 0x00, 0x00, 0x07,
87 0x01, 0x00, 0x00, 0x06,
88 (byte) 0x7f, 0x00, 0x00, 0x05,
89 0x00, 0x00, 0x00, 0x01, //Token Bucket Rate
90 0x00, 0x00, 0x00, 0x02, //Token Bucket Size
91 0x00, 0x00, 0x00, 0x03, //Peak Data Rate
92 0x00, 0x00, 0x00, 0x04, //Minimum Policed Unit
93 0x00, 0x00, 0x00, 0x05, //Maximum Packet Size
94 0x00, (byte) 0x08, (byte) 0xc7, 0x01, // Lenght, Class, Ctype
95 0x00, 0x01, 0x00, 0x02,
96 0x01, 0x02, 0x03, 0x04,};
98 private static final byte[] LINK_ATTR = {0x04, 0x04, 0, 0x04, 0x2a, 0x2a, 0x2a, 0x2a, 0x04, 0x06, 0, 0x04, 0x2b, 0x2b, 0x2b, 0x2b,
99 0x04, 0x40, 0, 0x04, 0, 0, 0, 0, 0x04, 0x41, 0, 0x04, 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80, 0x04, 0x42, 0, 0x04,
100 0x46, 0x43, 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, 0,
101 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, 0x04, 0x46, 0, 0x01,
102 (byte) 0xc0, 0x04, 0x47, 0, 0x03, 0, 0, 0x0a, 0x04, 0x48, 0, 0x08, 0x12, 0x34, 0x56, 0x78, 0x10, 0x30, 0x50, 0x70, 0x04, 0x4a,
103 0, 0x05, 0x31, 0x32, 0x4b, 0x2d, 0x32,
104 0x04, 0x4b, 0, 0x07, (byte)-80, 10, 0, 0, (byte)0x0f, (byte)0xff, (byte)0xff, // sr-adj
105 0x04, 0x4b, 0, 0x07, (byte)-80, 10, 0, 0, (byte)0x0f, (byte)0xff, (byte)0xef, // sr-adj
106 0x04, 0x4c, 0, 0x0d, (byte)-80, 10, 0, 0, 1, 2, 3, 4, 5, 6, (byte)0x0f, (byte)0xff, (byte)0xff, // sr-lan-adj
107 0x04, 0x4c, 0, 0x0d, (byte)-80, 10, 0, 0, 1, 2, 3, 4, 5, 6, (byte)0x0f, (byte)0xff, (byte)0xef, // sr-lan-adj
108 0x04, 0x4d, 0, 0x08, 0, 0x05, 0, 0, 0x0a, 0x0b, 0x0c, 0x0d, // peer-node-sid
109 0x04, 0x4e, 0, 0x08, 0, 0x05, 0, 0, 0x0a, 0x0b, 0x0c, 0x0f, // peer-adj-sid
110 0x04, 0x4f, 0, 0x08, 0, 0x05, 0, 0, 0x0a, 0x0b, 0x0c, 0x0e, // peer-set-sid
111 0x04, (byte) 0x88, 0, 0x01, 0x0a };
113 private static final byte[] NODE_ATTR = { 0x01, 0x07, 0, 0x04, 0, 0x2a, 0, 0x2b, 0x04, 0, 0, 0x01, (byte) 0xbc, 0x04, 0x02, 0,
114 0x05, 0x31, 0x32, 0x4b, 0x2d, 0x32, 0x04, 0x03, 0, 0x01, 0x72, 0x04, 0x03, 0, 0x01, 0x73, 0x04, 0x04, 0, 0x04,
115 0x29, 0x29, 0x29, 0x29, 0x04, (byte) 0x88, 0, 0x01, 0x0a,
116 4, 0x0a, 0, 0x0c, (byte)0xe0, 0, 1, 2, 3, 4, (byte)0x89, 0, 3, 1, 2, 0, // sr-caps
117 4, 0x0b, 0, 2, 0, 1 // sr-algorythms
120 private static final byte[] NODE_ATTR_S = { 0x01, 0x07, 0, 0x04, 0, 0x2a, 0, 0x2b, 0x04, 0, 0, 0x01, (byte) 0xbc, 0x04, 0x02, 0,
121 0x05, 0x31, 0x32, 0x4b, 0x2d, 0x32, 0x04, 0x03, 0, 0x01, 0x72, 0x04, 0x03, 0, 0x01, 0x73, 0x04, 0x04, 0, 0x04,
122 0x29, 0x29, 0x29, 0x29,
123 4, 0x0a, 0, 0x0c, (byte)0xe0, 0, 1, 2, 3, 4, (byte)0x89, 0, 3, 1, 2, 0, // sr-caps
124 4, 0x0b, 0, 2, 0, 1 // sr-algorythms
127 private static final byte[] P4_ATTR = { 0x04, (byte) 0x80, 0, 0x01, (byte) 0x80, 0x04, (byte) 0x81, 0, 0x08, 0x12, 0x34, 0x56, 0x78,
128 0x10, 0x30, 0x50, 0x70, 0x04, (byte) 0x82, 0, 0x08, 0x12, 0x34, 0x56, 0x78, 0x10, 0x30, 0x50, 0x70,
129 0x04, (byte) 0x83, 0, 0x04, 0, 0, 0, 0x0a, 0x04, (byte) 0x84, 0, 0x04, 0x0a, 0x19, 0x02, 0x1b,
130 4, (byte)0x86, 0,8, (byte)0xf0, 0, 0,0, 1,2,3,4, // prefix-sid tlv
131 4, (byte)0x87, 0,0x0c, 0, 0, 0, 5, 4, (byte)0x89, 0, 4, 1,2,3,4, // range tlv
132 4, (byte)0x88, 0, 4, 1, (byte)0xf0, 0, 0 // binding sid tlv
135 private RSVPExtensionProviderContext context;
136 private RSVPActivator rsvpActivator;
137 private LinkstateAttributeParser parser;
140 public final void setUp() {
141 this.context = new SimpleRSVPExtensionProviderContext();
142 this.rsvpActivator = new RSVPActivator();
143 this.rsvpActivator.start(this.context);
144 this.parser = new LinkstateAttributeParser(false,this.context.getRsvpRegistry());
146 private static AttributesBuilder createBuilder(final ObjectType type) {
147 return new AttributesBuilder().addAugmentation(
148 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1.class,
149 new Attributes1Builder().setMpReachNlri(
150 new MpReachNlriBuilder().setAfi(LinkstateAddressFamily.class).setSafi(LinkstateSubsequentAddressFamily.class).setAdvertizedRoutes(
151 new AdvertizedRoutesBuilder().setDestinationType(
152 new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
153 new DestinationLinkstateBuilder().setCLinkstateDestination(
154 Lists.newArrayList(new CLinkstateDestinationBuilder().setObjectType(type).setProtocolId(ProtocolId.IsisLevel1).build())).build()).build()).build()).build()).build());
157 private static AttributesBuilder createUnreachBuilder(final ObjectType type) {
158 return new AttributesBuilder().addAugmentation(
159 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2.class,
160 new Attributes2Builder().setMpUnreachNlri(
161 new MpUnreachNlriBuilder().setAfi(LinkstateAddressFamily.class).setSafi(LinkstateSubsequentAddressFamily.class).setWithdrawnRoutes(
162 new WithdrawnRoutesBuilder().setDestinationType(
163 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate(
164 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder().setCLinkstateDestination(
165 Lists.newArrayList(new CLinkstateDestinationBuilder().setObjectType(type).setProtocolId(ProtocolId.IsisLevel1).build())).build()).build()).build()).build()).build());
169 public void testGetNlriType() throws BGPParsingException {
170 final ByteBuf b = Unpooled.buffer();
171 AttributesBuilder builder = new AttributesBuilder();
172 this.parser.parseAttribute(b, builder);
173 assertEquals(0, b.readableBytes());
174 builder = new AttributesBuilder();
176 final Attributes1Builder builder1 = new Attributes1Builder();
177 builder.addAugmentation(Attributes1.class, builder1.build());
178 this.parser.parseAttribute(b, builder);
179 assertEquals(0, b.readableBytes());
180 builder = new AttributesBuilder();
182 builder.addAugmentation(Attributes1.class, builder1.setMpReachNlri(
183 new MpReachNlriBuilder().setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationIpv4CaseBuilder().build()).build()).build()).build());
184 this.parser.parseAttribute(b, builder);
185 assertEquals(0, b.readableBytes());
186 builder = new AttributesBuilder();
188 final Attributes2Builder builder2 = new Attributes2Builder();
189 builder.addAugmentation(Attributes2.class, builder2.build());
190 this.parser.parseAttribute(b, builder);
191 assertEquals(0, b.readableBytes());
192 builder = new AttributesBuilder();
194 builder.addAugmentation(Attributes2.class, builder2.setMpUnreachNlri(
195 new MpUnreachNlriBuilder().setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6CaseBuilder().build()).build()).build()).build());
196 this.parser.parseAttribute(b, builder);
197 assertEquals(0, b.readableBytes());
201 public void testPositiveLinks() throws BGPParsingException {
202 final AttributesBuilder builder = createBuilder(new LinkCaseBuilder().build());
203 this.parser.parseAttribute(Unpooled.copiedBuffer(LINK_ATTR), builder);
204 final Attributes1 attrs = builder.getAugmentation(Attributes1.class);
205 final LinkAttributes ls = ((LinkAttributesCase) attrs.getLinkStateAttribute()).getLinkAttributes();
208 assertEquals("42.42.42.42", ls.getLocalIpv4RouterId().getValue());
209 assertEquals("43.43.43.43", ls.getRemoteIpv4RouterId().getValue());
210 assertEquals(Long.valueOf(0L), ls.getAdminGroup().getValue());
211 assertArrayEquals(new byte[] { (byte) 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80 }, ls.getMaxLinkBandwidth().getValue());
212 assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 }, ls.getMaxReservableBandwidth().getValue());
213 assertNotNull(ls.getUnreservedBandwidth());
214 assertEquals(8, ls.getUnreservedBandwidth().size());
215 assertEquals(LinkProtectionType.Dedicated1to1, ls.getLinkProtection());
216 assertTrue(ls.getMplsProtocol().isLdp());
217 assertTrue(ls.getMplsProtocol().isRsvpte());
218 assertEquals(new Long(10), ls.getMetric().getValue());
219 assertEquals(2, ls.getSharedRiskLinkGroups().size());
220 assertEquals(305419896, ls.getSharedRiskLinkGroups().get(0).getValue().intValue());
221 assertEquals("12K-2", ls.getLinkName());
222 final IsisAdjFlagsCase flags = new IsisAdjFlagsCaseBuilder().setAddressFamily(Boolean.TRUE).setBackup(Boolean.FALSE).setSet(Boolean.FALSE).build();
223 assertEquals(flags, ls.getSrAdjIds().get(0).getFlags());
224 assertEquals(flags, ls.getSrAdjIds().get(1).getFlags());
225 assertNull(ls.getPeerNodeSid().getFlags());
226 assertNull(ls.getPeerSetSids().get(0).getFlags());
227 assertNull(ls.getPeerAdjSid().getFlags());
228 assertEquals(new Long(1048575L), ((LocalLabelCase)ls.getSrAdjIds().get(0).getSidLabelIndex()).getLocalLabel().getValue());
229 assertEquals(new Long(1048559L), ((LocalLabelCase)ls.getSrAdjIds().get(1).getSidLabelIndex()).getLocalLabel().getValue());
230 assertEquals(new Long(168496141L), ((SidCase) ls.getPeerNodeSid().getSidLabelIndex()).getSid());
231 assertEquals(new Short("5"), ls.getPeerNodeSid().getWeight().getValue());
232 assertEquals(new Long(168496142L), ((SidCase) ls.getPeerSetSids().get(0).getSidLabelIndex()).getSid());
233 assertEquals(new Short("5"), ls.getPeerSetSids().get(0).getWeight().getValue());
234 assertEquals(new Long(168496143L), ((SidCase) ls.getPeerAdjSid().getSidLabelIndex()).getSid());
235 assertEquals(new Short("5"), ls.getPeerAdjSid().getWeight().getValue());
238 final ByteBuf buff = Unpooled.buffer();
239 this.parser.serializeAttribute(builder.build(), buff);
241 // there is unresolved TLV at the end, that needs to be cut off
243 assertArrayEquals(ByteArray.subByte(LINK_ATTR, 0, LINK_ATTR.length -5), ByteArray.getAllBytes(buff));
246 private PeerSetSids buildPeerSetSid(final Flags flags, final long sid, final short weight) {
247 return new PeerSetSidsBuilder()
249 .setWeight(new Weight(new Short(weight)))
250 .setSidLabelIndex(new SidCaseBuilder().setSid(new Long(sid)).build()).build();
254 public void testPositiveNodes() throws BGPParsingException {
255 final AttributesBuilder builder = createBuilder(new NodeCaseBuilder().build());
256 this.parser.parseAttribute(Unpooled.copiedBuffer(NODE_ATTR), builder);
258 final Attributes1 attrs = builder.getAugmentation(Attributes1.class);
259 final NodeAttributes ls = ((NodeAttributesCase) attrs.getLinkStateAttribute()).getNodeAttributes();
262 assertEquals(2, ls.getTopologyIdentifier().size());
263 assertEquals(42, ls.getTopologyIdentifier().get(0).getValue().intValue());
264 assertTrue(ls.getNodeFlags().isOverload());
265 assertFalse(ls.getNodeFlags().isAttached());
266 assertTrue(ls.getNodeFlags().isExternal());
267 assertTrue(ls.getNodeFlags().isAbr());
268 assertTrue(ls.getNodeFlags().isRouter());
269 assertTrue(ls.getNodeFlags().isV6());
271 assertEquals("12K-2", ls.getDynamicHostname());
272 assertEquals(2, ls.getIsisAreaId().size());
273 assertEquals("41.41.41.41", ls.getIpv4RouterId().getValue());
276 final ByteBuf buff = Unpooled.buffer();
277 this.parser.serializeAttribute(builder.build(), buff);
279 assertArrayEquals(NODE_ATTR_S, ByteArray.getAllBytes(buff));
283 public void testPositiveV4Prefixes() throws BGPParsingException {
284 final AttributesBuilder builder = createUnreachBuilder(new PrefixCaseBuilder().setPrefixDescriptors(new PrefixDescriptorsBuilder().setIpReachabilityInformation(new IpPrefix(new Ipv4Prefix("127.0.0.1/32"))).build()).build());
285 this.parser.parseAttribute(Unpooled.copiedBuffer(P4_ATTR), builder);
287 final Attributes1 attrs = builder.getAugmentation(Attributes1.class);
288 final PrefixAttributes ls = ((PrefixAttributesCase) attrs.getLinkStateAttribute()).getPrefixAttributes();
291 assertNotNull(ls.getSrRange());
292 assertFalse(ls.getSrRange().isInterArea());
293 assertEquals(1, ls.getSrRange().getSubTlvs().size());
294 assertNotNull(ls.getSrBindingSidLabels());
295 assertTrue(ls.getIgpBits().getUpDown().isUpDown());
296 assertEquals(2, ls.getRouteTags().size());
297 assertArrayEquals(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }, ls.getRouteTags().get(0).getValue());
298 assertEquals(1, ls.getExtendedTags().size());
299 assertArrayEquals(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x10, (byte) 0x30, (byte) 0x50,
300 (byte) 0x70 }, ls.getExtendedTags().get(0).getValue());
301 assertEquals(10, ls.getPrefixMetric().getValue().intValue());
302 assertEquals("10.25.2.27", ls.getOspfForwardingAddress().getIpv4Address().getValue());
305 final ByteBuf buff = Unpooled.buffer();
306 this.parser.serializeAttribute(builder.build(), buff);
308 // there is unresolved TLV at the end, that needs to be cut off
309 assertArrayEquals(P4_ATTR, ByteArray.getAllBytes(buff));
313 public void testPositiveTELspAttribute() throws BGPParsingException {
314 final AttributesBuilder builder = createBuilder(new TeLspCaseBuilder().build());
315 this.parser.parseAttribute(Unpooled.copiedBuffer(TE_LSP_ATTR), builder);
317 final Attributes1 attrs = builder.getAugmentation(Attributes1.class);
318 final TeLspAttributes teLspAttributes = ((TeLspAttributesCase) attrs.getLinkStateAttribute()).getTeLspAttributes();
319 assertNotNull(teLspAttributes);
320 final TspecObject tSpec = teLspAttributes.getTspecObject();
321 assertNotNull(tSpec);
322 assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01}), tSpec.getTokenBucketRate());
323 assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02}), teLspAttributes.getTspecObject().getTokenBucketSize());
324 assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03}), tSpec.getPeakDataRate());
325 assertEquals(new Long("4"), tSpec.getMinimumPolicedUnit());
326 assertEquals(new Long("5"), tSpec.getMaximumPacketSize());
328 final AssociationObject associationObject = teLspAttributes.getAssociationObject();
329 assertEquals(AssociationType.Recovery, associationObject.getAssociationType());
330 final IpAddress ipv4 = new IpAddress(Ipv4Util.addressForByteBuf(Unpooled.copiedBuffer(new byte[]{0x01, 0x02, 0x03, 0x04})));
331 assertEquals(ipv4, associationObject.getIpAddress());
332 final short associationId = 2;
333 assertEquals(associationId, associationObject.getAssociationId().shortValue());
336 final ByteBuf buff = Unpooled.buffer();
337 this.parser.serializeAttribute(builder.build(), buff);
338 assertArrayEquals(TE_LSP_ATTR, ByteArray.getAllBytes(buff));
339 assertTrue(Arrays.equals(TE_LSP_ATTR, ByteArray.getAllBytes(buff)));
342 @Test(expected=UnsupportedOperationException.class)
343 public void testLinkAttributesPrivateConstructor() throws Throwable {
344 final Constructor<LinkAttributesParser> c = LinkAttributesParser.class.getDeclaredConstructor();
345 c.setAccessible(true);
348 } catch (final InvocationTargetException e) {
353 @Test(expected=UnsupportedOperationException.class)
354 public void testNodeAttributesPrivateConstructor() throws Throwable {
355 final Constructor<NodeAttributesParser> c = NodeAttributesParser.class.getDeclaredConstructor();
356 c.setAccessible(true);
359 } catch (final InvocationTargetException e) {
364 @Test(expected=UnsupportedOperationException.class)
365 public void testPrefixAttributesPrivateConstructor() throws Throwable {
366 final Constructor<PrefixAttributesParser> c = PrefixAttributesParser.class.getDeclaredConstructor();
367 c.setAccessible(true);
370 } catch (final InvocationTargetException e) {