2 * Copyright (c) 2014 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.pcep.segment.routing;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
18 import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext;
19 import org.opendaylight.protocol.util.ByteArray;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.SidType;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.add.lsp.input.arguments.ero.subobject.subobject.type.SrEroTypeBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.sr.subobject.nai.IpAdjacencyBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.sr.subobject.nai.IpNodeIdBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.sr.subobject.nai.UnnumberedAdjacencyBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder;
30 public class SrEroSubobjectParserTest {
32 private static final byte[] SR_ERO_SUBOBJECT_WITH_IPV4_NODEID = {
33 0x05,0x0c,(byte) 0x10,0x00,
34 0x00,0x01,(byte) 0xe2,0x40,
38 private static final byte[] SR_ERO_SUBOBJECT_WITH_IPV6_NODEID = {
39 0x05,0x18,(byte) 0x20,0x00,
40 0x00,0x01,(byte) 0xe2,0x40,
41 (byte) 0xFE,(byte) 0x80,(byte) 0xCD,0x00,
44 0x21,0x1E,0x72,(byte) 0x9C,
47 private static final byte[] SR_ERO_SUBOBJECT_WITH_IPV4_ADJ = {
48 0x05,0x10,(byte) 0x30,0x00,
49 0x00,0x01,(byte) 0xe2,0x40,
54 private static final byte[] SR_ERO_SUBOBJECT_WITH_IPV6_ADJ = {
55 0x05,0x28,(byte) 0x40,0x00,
56 0x00,0x01,(byte) 0xe2,0x40,
57 (byte) 0xFE,(byte) 0x80,(byte) 0xCD,0x00,
60 0x21,0x1E,0x72,(byte) 0x9C,
61 (byte) 0xFE,(byte) 0x80,(byte) 0xCD,0x00,
64 0x21,0x1E,0x72,(byte) 0x9D,
67 private static final byte[] SR_ERO_SUBOBJECT_WITH_UNNUMBERED = {
68 0x05,0x18,(byte) 0x50,0x00,
69 0x00,0x01,(byte) 0xe2,0x40,
76 private static final byte[] SR_ERO_SUBOBJECT_WITHOUT_NAI = {
77 0x05,0x08,(byte) 0x10,0x08,
78 0x00,0x01,(byte) 0xe2,0x40
81 private static final byte[] SR_ERO_SUBOBJECT_WITHOUT_SID = {
82 0x05,0x08,(byte) 0x10,0x04,
86 private static final byte[] SR_ERO_SUBOBJECT_WITH_IPV4_NODEID_MFLAG = {
87 0x05,0x0c,(byte) 0x10,0x01,
88 0x07,0x5B,(byte) 0xCD,0x15,
91 private static final byte[] SR_ERO_SUBOBJECT_WITH_IPV4_NODEID_MFLAG_AFTER = {
92 0x05,0x0c,(byte) 0x10,0x01,
93 0x07,0x5B,(byte) 0xC0,0x00,
97 private SimplePCEPExtensionProviderContext ctx;
98 private SegmentRoutingActivator act;
99 private SrEroSubobjectParser parser;
102 public void setUp() {
103 this.ctx = new SimplePCEPExtensionProviderContext();
104 this.act = new SegmentRoutingActivator();
105 this.act.start(this.ctx);
106 final boolean isIanaAssignedType = false;
107 this.parser = new SrEroSubobjectParser(isIanaAssignedType);
111 public void testSrEroSubobjectIpv4NodeIdNAI() throws PCEPDeserializerException {
112 final SrEroTypeBuilder builder = new SrEroTypeBuilder();
113 builder.setSidType(SidType.Ipv4NodeId);
114 builder.setSid(123456L);
115 builder.setCFlag(false);
116 builder.setMFlag(false);
117 builder.setNai(new IpNodeIdBuilder().setIpAddress(new IpAddressNoZone(new Ipv4AddressNoZone("74.125.43.99")))
119 final SubobjectBuilder subobjBuilder = new SubobjectBuilder().setSubobjectType(builder.build()).setLoose(false);
121 assertEquals(subobjBuilder.build(), this.parser.parseSubobject(Unpooled.wrappedBuffer(
122 ByteArray.cutBytes(SR_ERO_SUBOBJECT_WITH_IPV4_NODEID, 2)), false));
123 final ByteBuf buffer = Unpooled.buffer();
124 this.parser.serializeSubobject(subobjBuilder.build(), buffer);
125 assertArrayEquals(SR_ERO_SUBOBJECT_WITH_IPV4_NODEID, ByteArray.getAllBytes(buffer));
129 public void testSrEroSubobjectIpv6NodeIdNAI() throws PCEPDeserializerException {
130 final SrEroTypeBuilder builder = new SrEroTypeBuilder();
131 builder.setSidType(SidType.Ipv6NodeId);
132 builder.setSid(123456L);
133 builder.setCFlag(false);
134 builder.setMFlag(false);
135 builder.setNai(new IpNodeIdBuilder().setIpAddress(new IpAddressNoZone(
136 new Ipv6AddressNoZone("fe80:cd00::211e:729c"))).build());
137 final SubobjectBuilder subobjBuilder = new SubobjectBuilder().setSubobjectType(builder.build()).setLoose(false);
139 assertEquals(subobjBuilder.build(), this.parser.parseSubobject(Unpooled.wrappedBuffer(
140 ByteArray.cutBytes(SR_ERO_SUBOBJECT_WITH_IPV6_NODEID, 2)), false));
141 final ByteBuf buffer = Unpooled.buffer();
142 this.parser.serializeSubobject(subobjBuilder.build(), buffer);
143 assertArrayEquals(SR_ERO_SUBOBJECT_WITH_IPV6_NODEID, ByteArray.getAllBytes(buffer));
147 public void testSrEroSubobjectIpv4AdjacencyNAI() throws PCEPDeserializerException {
148 final SrEroTypeBuilder builder = new SrEroTypeBuilder();
149 builder.setSidType(SidType.Ipv4Adjacency);
150 builder.setSid(123456L);
151 builder.setCFlag(false);
152 builder.setMFlag(false);
153 builder.setNai(new IpAdjacencyBuilder().setLocalIpAddress(new IpAddressNoZone(
154 new Ipv4AddressNoZone("74.125.43.99")))
155 .setRemoteIpAddress(new IpAddressNoZone(new Ipv4AddressNoZone("74.125.43.100"))).build());
156 final SubobjectBuilder subobjBuilder = new SubobjectBuilder().setSubobjectType(builder.build()).setLoose(false);
158 assertEquals(subobjBuilder.build(), this.parser.parseSubobject(Unpooled.wrappedBuffer(
159 ByteArray.cutBytes(SR_ERO_SUBOBJECT_WITH_IPV4_ADJ, 2)), false));
160 final ByteBuf buffer = Unpooled.buffer();
161 this.parser.serializeSubobject(subobjBuilder.build(), buffer);
162 assertArrayEquals(SR_ERO_SUBOBJECT_WITH_IPV4_ADJ, ByteArray.getAllBytes(buffer));
166 public void testSrEroSubobjectIpv6AdjacencyNAI() throws PCEPDeserializerException {
167 final SrEroTypeBuilder builder = new SrEroTypeBuilder();
168 builder.setSidType(SidType.Ipv6Adjacency);
169 builder.setSid(123456L);
170 builder.setCFlag(false);
171 builder.setMFlag(false);
172 builder.setNai(new IpAdjacencyBuilder().setLocalIpAddress(new IpAddressNoZone(
173 new Ipv6AddressNoZone("fe80:cd00::211e:729c")))
174 .setRemoteIpAddress(new IpAddressNoZone(new Ipv6AddressNoZone("fe80:cd00::211e:729d"))).build());
175 final SubobjectBuilder subobjBuilder = new SubobjectBuilder().setSubobjectType(builder.build()).setLoose(false);
177 assertEquals(subobjBuilder.build(), this.parser.parseSubobject(Unpooled.wrappedBuffer(
178 ByteArray.cutBytes(SR_ERO_SUBOBJECT_WITH_IPV6_ADJ, 2)), false));
179 final ByteBuf buffer = Unpooled.buffer();
180 this.parser.serializeSubobject(subobjBuilder.build(), buffer);
181 assertArrayEquals(SR_ERO_SUBOBJECT_WITH_IPV6_ADJ, ByteArray.getAllBytes(buffer));
185 public void testSrEroSubobjectUnnumberedNAI() throws PCEPDeserializerException {
186 final SrEroTypeBuilder builder = new SrEroTypeBuilder();
187 builder.setSidType(SidType.Unnumbered);
188 builder.setSid(123456L);
189 builder.setCFlag(false);
190 builder.setMFlag(false);
191 builder.setNai(new UnnumberedAdjacencyBuilder().setLocalNodeId(1L).setLocalInterfaceId(2L)
192 .setRemoteNodeId(3L).setRemoteInterfaceId(4L).build());
193 final SubobjectBuilder subobjBuilder = new SubobjectBuilder().setSubobjectType(builder.build()).setLoose(false);
195 assertEquals(subobjBuilder.build(), this.parser.parseSubobject(Unpooled.wrappedBuffer(
196 ByteArray.cutBytes(SR_ERO_SUBOBJECT_WITH_UNNUMBERED, 2)), false));
197 final ByteBuf buffer = Unpooled.buffer();
198 this.parser.serializeSubobject(subobjBuilder.build(), buffer);
199 assertArrayEquals(SR_ERO_SUBOBJECT_WITH_UNNUMBERED, ByteArray.getAllBytes(buffer));
203 public void testSrEroSubobjectWithoutNAI() throws PCEPDeserializerException {
204 final SrEroTypeBuilder builder = new SrEroTypeBuilder();
205 builder.setSidType(SidType.Ipv4NodeId);
206 builder.setSid(123456L);
207 builder.setCFlag(false);
208 builder.setMFlag(false);
209 final SubobjectBuilder subobjBuilder = new SubobjectBuilder().setSubobjectType(builder.build()).setLoose(false);
211 assertEquals(subobjBuilder.build(), this.parser.parseSubobject(Unpooled.wrappedBuffer(
212 ByteArray.cutBytes(SR_ERO_SUBOBJECT_WITHOUT_NAI, 2)), false));
213 final ByteBuf buffer = Unpooled.buffer();
214 this.parser.serializeSubobject(subobjBuilder.build(), buffer);
215 assertArrayEquals(SR_ERO_SUBOBJECT_WITHOUT_NAI, ByteArray.getAllBytes(buffer));
219 public void testSrEroSubobjectWithoutBody() throws PCEPDeserializerException {
220 final SrEroTypeBuilder builder = new SrEroTypeBuilder();
221 builder.setSidType(SidType.Ipv4NodeId);
222 builder.setCFlag(false);
223 builder.setMFlag(false);
224 builder.setNai(new IpNodeIdBuilder().setIpAddress(new IpAddressNoZone(
225 new Ipv4AddressNoZone("74.125.43.99"))).build());
226 final SubobjectBuilder subobjBuilder = new SubobjectBuilder().setSubobjectType(builder.build()).setLoose(false);
228 assertEquals(subobjBuilder.build(), this.parser.parseSubobject(Unpooled.wrappedBuffer(
229 ByteArray.cutBytes(SR_ERO_SUBOBJECT_WITHOUT_SID, 2)), false));
230 final ByteBuf buffer = Unpooled.buffer();
231 this.parser.serializeSubobject(subobjBuilder.build(), buffer);
232 assertArrayEquals(SR_ERO_SUBOBJECT_WITHOUT_SID, ByteArray.getAllBytes(buffer));
236 public void testSrEroSubobjectIpv4NodeIdNAIMFlag() throws PCEPDeserializerException {
237 final SrEroTypeBuilder builder = new SrEroTypeBuilder();
238 builder.setCFlag(false);
239 builder.setMFlag(true);
240 builder.setSidType(SidType.Ipv4NodeId);
241 builder.setSid(30140L);
242 builder.setNai(new IpNodeIdBuilder().setIpAddress(new IpAddressNoZone(new Ipv4AddressNoZone("74.125.43.99")))
244 final SubobjectBuilder subobjBuilder = new SubobjectBuilder().setSubobjectType(builder.build()).setLoose(false);
246 assertEquals(subobjBuilder.build(), this.parser.parseSubobject(Unpooled.wrappedBuffer(
247 ByteArray.cutBytes(SR_ERO_SUBOBJECT_WITH_IPV4_NODEID_MFLAG, 2)), false));
248 final ByteBuf buffer = Unpooled.buffer();
249 this.parser.serializeSubobject(subobjBuilder.build(), buffer);
250 assertArrayEquals(SR_ERO_SUBOBJECT_WITH_IPV4_NODEID_MFLAG_AFTER, ByteArray.getAllBytes(buffer));