2 * Copyright (c) 2015 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
9 package org.opendaylight.protocol.rsvp.parser.impl.te;
11 import static org.junit.Assert.assertArrayEquals;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.protocol.rsvp.parser.impl.RSVPActivator;
19 import org.opendaylight.protocol.rsvp.parser.impl.subobject.ero.SEROBasicProtectionSubobjectParser;
20 import org.opendaylight.protocol.rsvp.parser.impl.subobject.ero.SERODynamicProtectionSubobjectParser;
21 import org.opendaylight.protocol.rsvp.parser.impl.subobject.rro.SRROBasicProtectionSubobjectParser;
22 import org.opendaylight.protocol.rsvp.parser.impl.subobject.rro.SRRODynamicProtectionSubobjectParser;
23 import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
24 import org.opendaylight.protocol.rsvp.parser.spi.pojo.SimpleRSVPExtensionProviderContext;
25 import org.opendaylight.protocol.util.ByteArray;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainerBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainer;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.secondary.explicit.route.object.secondary.explicit.route.object.subobject.container.subobject.type.DynamicControlProtectionCaseBuilder;
31 public class TEObjectTest {
33 SimpleRSVPExtensionProviderContext context;
37 this.act = new RSVPActivator();
38 this.context = new SimpleRSVPExtensionProviderContext();
39 this.act.start(this.context);
43 public void testAdminStatusObjectParser() throws RSVPParsingException {
44 final AdminStatusObjectParser admParser = new AdminStatusObjectParser();
45 final RsvpTeObject obj = admParser.parseObject(Unpooled.copiedBuffer(
46 ByteArray.subByte(TEObjectUtil.TE_LSP_ADMIN_STATUS, 4, TEObjectUtil.TE_LSP_ADMIN_STATUS.length - 4)));
47 final ByteBuf output = Unpooled.buffer();
48 admParser.serializeObject(obj, output);
49 assertArrayEquals(TEObjectUtil.TE_LSP_ADMIN_STATUS, ByteArray.getAllBytes(output));
53 public void testAssociationObjectParser1() throws RSVPParsingException {
54 final AssociationObjectParserIPV4 parser = new AssociationObjectParserIPV4();
55 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(
56 ByteArray.subByte(TEObjectUtil.TE_LSP_ASSOCIATION_1, 4, TEObjectUtil.TE_LSP_ASSOCIATION_1.length - 4)));
58 final ByteBuf output = Unpooled.buffer();
59 parser.serializeObject(obj, output);
60 assertArrayEquals(TEObjectUtil.TE_LSP_ASSOCIATION_1, ByteArray.getAllBytes(output));
64 public void testAssociationObjectParser2() throws RSVPParsingException {
65 final AssociationObjectParserIPV6 parser = new AssociationObjectParserIPV6();
66 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(
67 ByteArray.subByte(TEObjectUtil.TE_LSP_ASSOCIATION_2, 4, TEObjectUtil.TE_LSP_ASSOCIATION_2.length - 4)));
69 final ByteBuf output = Unpooled.buffer();
70 parser.serializeObject(obj, output);
71 assertArrayEquals(TEObjectUtil.TE_LSP_ASSOCIATION_2, ByteArray.getAllBytes(output));
75 public void testBandwidthObjectParser1() throws RSVPParsingException {
76 final BandwidthObjectParser parser = new BandwidthObjectParser();
77 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(
78 ByteArray.subByte(TEObjectUtil.TE_LSP_BANDWIDTH_1, 4, TEObjectUtil.TE_LSP_BANDWIDTH_1
81 final ByteBuf output = Unpooled.buffer();
82 parser.serializeObject(obj, output);
83 assertArrayEquals(TEObjectUtil.TE_LSP_BANDWIDTH_1, ByteArray.getAllBytes(output));
87 public void testBandwidthObjectParser2() throws RSVPParsingException {
88 final ReoptimizationBandwidthObjectParser parser = new ReoptimizationBandwidthObjectParser();
89 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(
90 ByteArray.subByte(TEObjectUtil.TE_LSP_BANDWIDTH_2, 4, TEObjectUtil.TE_LSP_BANDWIDTH_2
93 final ByteBuf output = Unpooled.buffer();
94 parser.serializeObject(obj, output);
95 assertArrayEquals(TEObjectUtil.TE_LSP_BANDWIDTH_2, ByteArray.getAllBytes(output));
99 public void testExcludeRouteParser() throws RSVPParsingException {
100 final ExcludeRouteObjectParser parser = new ExcludeRouteObjectParser(this.context.getXROSubobjectHandlerRegistry());
101 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(
102 ByteArray.subByte(TEObjectUtil.TE_LSP_EXCLUDE_ROUTE, 4, TEObjectUtil.TE_LSP_EXCLUDE_ROUTE.length - 4)));
104 final ByteBuf output = Unpooled.buffer();
105 parser.serializeObject(obj, output);
106 assertArrayEquals(TEObjectUtil.TE_LSP_EXCLUDE_ROUTE, ByteArray.getAllBytes(output));
110 public void testExplicitRouteParser() throws RSVPParsingException {
111 final ExplicitRouteObjectParser parser = new ExplicitRouteObjectParser(this.context.getEROSubobjectHandlerRegistry());
112 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(ByteArray.subByte(TEObjectUtil.TE_LSP_EXPLICIT, 4,
113 TEObjectUtil.TE_LSP_EXPLICIT.length - 4)));
115 final ByteBuf output = Unpooled.buffer();
116 parser.serializeObject(obj, output);
117 assertArrayEquals(TEObjectUtil.TE_LSP_EXPLICIT, ByteArray.getAllBytes(output));
121 public void testAttributesObject12Parser() throws RSVPParsingException {
122 final AttributesObjectParser parser = new AttributesObjectParser();
123 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(
124 ByteArray.subByte(TEObjectUtil.TE_LSP_ATTRIBUTES, 4, TEObjectUtil.TE_LSP_ATTRIBUTES.length - 4)));
126 final ByteBuf output = Unpooled.buffer();
127 parser.serializeObject(obj, output);
128 assertArrayEquals(TEObjectUtil.TE_LSP_ATTRIBUTES, ByteArray.getAllBytes(output));
132 public void testRequiredAttributesParser() throws RSVPParsingException {
133 final RequiredAttributesObjectParser parser = new RequiredAttributesObjectParser();
134 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(
135 ByteArray.subByte(TEObjectUtil.TE_LSP_REQUIRED_ATTRIBUTES, 4, TEObjectUtil.TE_LSP_REQUIRED_ATTRIBUTES.length - 4)));
137 final ByteBuf output = Unpooled.buffer();
138 parser.serializeObject(obj, output);
139 assertArrayEquals(TEObjectUtil.TE_LSP_REQUIRED_ATTRIBUTES, ByteArray.getAllBytes(output));
143 public void testPrimaryPathRouteParser() throws RSVPParsingException {
144 final PrimaryPathRouteObjectParser parser = new PrimaryPathRouteObjectParser(this.context.getEROSubobjectHandlerRegistry());
145 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(
146 ByteArray.subByte(TEObjectUtil.TE_LSP_PRIMARY_PATH_ROUTE, 4, TEObjectUtil.TE_LSP_PRIMARY_PATH_ROUTE
149 final ByteBuf output = Unpooled.buffer();
150 parser.serializeObject(obj, output);
151 assertArrayEquals(TEObjectUtil.TE_LSP_PRIMARY_PATH_ROUTE, ByteArray.getAllBytes(output));
156 public void testProtectionObjectParser1() throws RSVPParsingException {
157 final ProtectionObjectParser parser = new ProtectionObjectParser();
158 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(
159 ByteArray.subByte(TEObjectUtil.TE_LSP_PROTECTION_C1, 4, TEObjectUtil.TE_LSP_PROTECTION_C1.length - 4)));
160 final ByteBuf output = Unpooled.buffer();
161 parser.serializeObject(obj, output);
162 assertArrayEquals(TEObjectUtil.TE_LSP_PROTECTION_C1, ByteArray.getAllBytes(output));
166 public void testProtectionObjectParser2() throws RSVPParsingException {
167 final DynamicProtectionObjectParser parser = new DynamicProtectionObjectParser();
168 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(
169 ByteArray.subByte(TEObjectUtil.TE_LSP_PROTECTION_C2, 4, TEObjectUtil.TE_LSP_PROTECTION_C2.length - 4)));
170 final ByteBuf output = Unpooled.buffer();
171 parser.serializeObject(obj, output);
172 assertArrayEquals(TEObjectUtil.TE_LSP_PROTECTION_C2, ByteArray.getAllBytes(output));
176 public void testProtectionCommonParser() {
177 final ByteBuf emptyBuff = Unpooled.buffer();
179 ProtectionCommonParser.parseCommonProtectionBodyType2(emptyBuff);
181 } catch (final RSVPParsingException e) {
182 Assert.assertEquals("Wrong length of array of bytes. Passed: " + emptyBuff.readableBytes() + "; Expected:" +
183 " " + ProtectionCommonParser.CONTENT_LENGTH_C2 + ".", e.getMessage());
188 public void testRecordRouteParser() throws RSVPParsingException {
189 final RecordRouteObjectParser parser = new RecordRouteObjectParser(this.context.getRROSubobjectHandlerRegistry());
190 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(
191 ByteArray.subByte(TEObjectUtil.TE_LSP_RECORD_ROUTE, 4, TEObjectUtil.TE_LSP_RECORD_ROUTE.length - 4)));
193 final ByteBuf output = Unpooled.buffer();
194 parser.serializeObject(obj, output);
195 assertArrayEquals(TEObjectUtil.TE_LSP_RECORD_ROUTE, ByteArray.getAllBytes(output));
199 public void testSecondaryExplicitRouteParser() throws RSVPParsingException {
200 final SecondaryExplicitRouteObjectParser parser = new SecondaryExplicitRouteObjectParser(this.context.getEROSubobjectHandlerRegistry());
201 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(
202 ByteArray.subByte(TEObjectUtil.TE_LSP_SECONDARY_EXPLICIT, 4, TEObjectUtil.TE_LSP_SECONDARY_EXPLICIT
205 final ByteBuf output = Unpooled.buffer();
206 parser.serializeObject(obj, output);
207 assertArrayEquals(TEObjectUtil.TE_LSP_SECONDARY_EXPLICIT, ByteArray.getAllBytes(output));
211 public void testSecondaryRecordRouteObjectParser() throws RSVPParsingException {
212 final SecondaryRecordRouteObjectParser parser = new SecondaryRecordRouteObjectParser(this.context.getRROSubobjectHandlerRegistry());
213 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(
214 ByteArray.subByte(TEObjectUtil.TE_LSP_SECONDARY_RECORD_ROUTE, 4, TEObjectUtil.TE_LSP_SECONDARY_RECORD_ROUTE
217 final ByteBuf output = Unpooled.buffer();
218 parser.serializeObject(obj, output);
219 assertArrayEquals(TEObjectUtil.TE_LSP_SECONDARY_RECORD_ROUTE, ByteArray.getAllBytes(output));
223 public void testSSRODynamicProtectionSubobjectParser() throws RSVPParsingException {
224 final SRROBasicProtectionSubobjectParser parser = new SRROBasicProtectionSubobjectParser();
225 final SRRODynamicProtectionSubobjectParser dynamicParser = new SRRODynamicProtectionSubobjectParser();
226 final SubobjectContainer sub = parser.parseSubobject(Unpooled.copiedBuffer(
227 ByteArray.subByte(TEObjectUtil.TE_LSP_DYNAMIC_SRRO_PROTECTION, 2, TEObjectUtil.TE_LSP_DYNAMIC_SRRO_PROTECTION
230 final ByteBuf output = Unpooled.buffer();
231 dynamicParser.serializeSubobject(sub, output);
232 assertArrayEquals(TEObjectUtil.TE_LSP_DYNAMIC_SRRO_PROTECTION, ByteArray.getAllBytes(output));
236 public void testSSROBasicProtectionSubobjectParser() throws RSVPParsingException {
237 final SRROBasicProtectionSubobjectParser parser = new SRROBasicProtectionSubobjectParser();
238 final SubobjectContainer sub = parser.parseSubobject(Unpooled.copiedBuffer(
239 ByteArray.subByte(TEObjectUtil.TE_LSP_BASIC_SRRO_PROTECTION, 2, TEObjectUtil.TE_LSP_BASIC_SRRO_PROTECTION.length - 2)));
241 final ByteBuf output = Unpooled.buffer();
242 parser.serializeSubobject(sub, output);
243 assertArrayEquals(TEObjectUtil.TE_LSP_BASIC_SRRO_PROTECTION, ByteArray.getAllBytes(output));
246 @Test(expected = IllegalArgumentException.class)
247 public void testWrongParseSRRO() throws RSVPParsingException {
248 final SRROBasicProtectionSubobjectParser parser = new SRROBasicProtectionSubobjectParser();
249 parser.parseSubobject(null);
252 @Test(expected = IllegalArgumentException.class)
253 public void testWrongSerializeSRRO() throws RSVPParsingException {
254 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.secondary.record.route
255 .object.secondary.record.route.object.subobject.container.subobject.type
256 .DynamicControlProtectionCase dynamicProtection = new org.opendaylight.yang.gen.v1.urn
257 .opendaylight.params.xml.ns.yang.rsvp.rev150820.secondary.record.route.object.secondary.record.route
258 .object.subobject.container.subobject.type.DynamicControlProtectionCaseBuilder().build();
259 final SRROBasicProtectionSubobjectParser parser = new SRROBasicProtectionSubobjectParser();
260 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.
261 SubobjectContainer subContainer = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
262 .rsvp.rev150820.record.route.subobjects.list.SubobjectContainerBuilder().setSubobjectType(dynamicProtection).build();
263 parser.serializeSubobject(subContainer, Unpooled.buffer());
267 public void testSERODynamicProtectionSubobjectParser() throws RSVPParsingException {
268 final SEROBasicProtectionSubobjectParser parser = new SEROBasicProtectionSubobjectParser();
269 final SERODynamicProtectionSubobjectParser dynamicParser = new SERODynamicProtectionSubobjectParser();
270 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.
271 SubobjectContainer sub = parser.parseSubobject(Unpooled.copiedBuffer(
272 ByteArray.subByte(TEObjectUtil.TE_LSP_DYNAMIC_SERO_PROTECTION, 2, TEObjectUtil.TE_LSP_DYNAMIC_SERO_PROTECTION.length - 2)), true);
274 final ByteBuf output = Unpooled.buffer();
275 dynamicParser.serializeSubobject(sub, output);
276 assertArrayEquals(TEObjectUtil.TE_LSP_DYNAMIC_SERO_PROTECTION, ByteArray.getAllBytes(output));
279 @Test(expected = IllegalArgumentException.class)
280 public void testWrongParseSERO() throws RSVPParsingException {
281 final SEROBasicProtectionSubobjectParser parser = new SEROBasicProtectionSubobjectParser();
282 parser.parseSubobject(null, false);
285 @Test(expected = IllegalArgumentException.class)
286 public void testWrongSerializeSERO() throws RSVPParsingException {
287 final SEROBasicProtectionSubobjectParser parser = new SEROBasicProtectionSubobjectParser();
288 parser.serializeSubobject(new SubobjectContainerBuilder().setSubobjectType
289 (new DynamicControlProtectionCaseBuilder().build()).build(), Unpooled.buffer());
293 public void testSEROBasicProtectionSubobjectParser() throws RSVPParsingException {
294 final SEROBasicProtectionSubobjectParser parser = new SEROBasicProtectionSubobjectParser();
295 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.
296 SubobjectContainer sub = parser.parseSubobject(Unpooled.copiedBuffer(
297 ByteArray.subByte(TEObjectUtil.TE_LSP_BASIC_SERO_PROTECTION, 2, TEObjectUtil.TE_LSP_BASIC_SERO_PROTECTION.length - 2)), true);
299 final ByteBuf output = Unpooled.buffer();
300 parser.serializeSubobject(sub, output);
301 assertArrayEquals(TEObjectUtil.TE_LSP_BASIC_SERO_PROTECTION, ByteArray.getAllBytes(output));
305 public void testDetourObjectParser7() throws RSVPParsingException {
306 final DetourObjectIpv4Parser parser = new DetourObjectIpv4Parser();
307 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(
308 ByteArray.subByte(TEObjectUtil.TE_LSP_DETOUR7, 4, TEObjectUtil.TE_LSP_DETOUR7.length - 4)));
310 final ByteBuf output = Unpooled.buffer();
311 parser.serializeObject(obj, output);
312 assertArrayEquals(TEObjectUtil.TE_LSP_DETOUR7, ByteArray.getAllBytes(output));
316 public void testDetourObjectParser8() throws RSVPParsingException {
317 final DetourObjectIpv6Parser parser = new DetourObjectIpv6Parser();
318 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(
319 ByteArray.subByte(TEObjectUtil.TE_LSP_DETOUR8, 4, TEObjectUtil.TE_LSP_DETOUR8.length - 4)));
321 final ByteBuf output = Unpooled.buffer();
322 parser.serializeObject(obj, output);
323 assertArrayEquals(TEObjectUtil.TE_LSP_DETOUR8, ByteArray.getAllBytes(output));
327 public void testFastRerouteObjectParser1() throws RSVPParsingException {
328 final FastRerouteObjectParser parser = new FastRerouteObjectParser();
329 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(
330 ByteArray.subByte(TEObjectUtil.TE_LSP_FAST_REROUTE1, 4, TEObjectUtil.TE_LSP_FAST_REROUTE1.length - 4)));
332 final ByteBuf output = Unpooled.buffer();
333 parser.serializeObject(obj, output);
334 assertArrayEquals(TEObjectUtil.TE_LSP_FAST_REROUTE1, ByteArray.getAllBytes(output));
338 public void testFastRerouteObjectParser7() throws RSVPParsingException {
339 final InformationalFastRerouteObjectParser parser = new InformationalFastRerouteObjectParser();
340 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(
341 ByteArray.subByte(TEObjectUtil.TE_LSP_FAST_REROUTE7, 4, TEObjectUtil.TE_LSP_FAST_REROUTE7.length - 4)));
343 final ByteBuf output = Unpooled.buffer();
344 parser.serializeObject(obj, output);
345 assertArrayEquals(TEObjectUtil.TE_LSP_FAST_REROUTE7, ByteArray.getAllBytes(output));
349 public void testFlowSpecObjectParser_HEADER_5() throws RSVPParsingException {
350 final FlowSpecObjectParser parser = new FlowSpecObjectParser();
351 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(
352 ByteArray.subByte(TEObjectUtil.TE_LSP_FLOWSPEC_H5, 4, TEObjectUtil.TE_LSP_FLOWSPEC_H5.length - 4)));
354 final ByteBuf output = Unpooled.buffer();
355 parser.serializeObject(obj, output);
356 assertArrayEquals(TEObjectUtil.TE_LSP_FLOWSPEC_H5, ByteArray.getAllBytes(output));
360 public void testFlowSpecObjectParser_HEADER_2() throws RSVPParsingException {
361 final FlowSpecObjectParser parser = new FlowSpecObjectParser();
362 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(
363 ByteArray.subByte(TEObjectUtil.TE_LSP_FLOWSPEC_H2, 4, TEObjectUtil.TE_LSP_FLOWSPEC_H2.length - 4)));
365 final ByteBuf output = Unpooled.buffer();
366 parser.serializeObject(obj, output);
367 assertArrayEquals(TEObjectUtil.TE_LSP_FLOWSPEC_H2, ByteArray.getAllBytes(output));
371 public void testParser_HEADER_5() throws RSVPParsingException {
372 final SenderTspecObjectParser parser = new SenderTspecObjectParser();
373 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(
374 ByteArray.subByte(TEObjectUtil.TE_LSP_SENDER_TSPEC, 4, TEObjectUtil.TE_LSP_SENDER_TSPEC.length - 4)));
376 final ByteBuf output = Unpooled.buffer();
377 parser.serializeObject(obj, output);
378 assertArrayEquals(TEObjectUtil.TE_LSP_SENDER_TSPEC, ByteArray.getAllBytes(output));
382 public void testSessionAttributeParser1() throws RSVPParsingException {
383 final SessionAttributeLspRaObjectParser parser = new SessionAttributeLspRaObjectParser();
384 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(
385 ByteArray.subByte(TEObjectUtil.TE_LSP_SESSION_C1, 4, TEObjectUtil.TE_LSP_SESSION_C1
388 final ByteBuf output = Unpooled.buffer();
389 parser.serializeObject(obj, output);
390 assertArrayEquals(TEObjectUtil.TE_LSP_SESSION_C1, ByteArray.getAllBytes(output));
394 public void testSessionAttributeParser7() throws RSVPParsingException {
395 final SessionAttributeLspObjectParser parser = new SessionAttributeLspObjectParser();
396 final RsvpTeObject obj = parser.parseObject(Unpooled.copiedBuffer(
397 ByteArray.subByte(TEObjectUtil.TE_LSP_SESSION_C7, 4, TEObjectUtil.TE_LSP_SESSION_C7
400 final ByteBuf output = Unpooled.buffer();
401 parser.serializeObject(obj, output);
402 assertArrayEquals(TEObjectUtil.TE_LSP_SESSION_C7, ByteArray.getAllBytes(output));