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.Test;
16 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
17 import org.opendaylight.protocol.util.ByteArray;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.sr.pce.capability.tlv.SrPceCapability;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.sr.pce.capability.tlv.SrPceCapabilityBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.setup.type.tlv.PathSetupType;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.setup.type.tlv.PathSetupTypeBuilder;
22 import org.opendaylight.yangtools.yang.common.Uint8;
24 public class SrTlvParserTest {
26 private static final byte[] SPC_TLV_BYTES = { 0x0, 0x1a, 0x0, 0x4, 0x0, 0x0, 0x0, 0x1 };
28 private static final byte[] SR_TE_PST_BYTES = { 0x0, 0x1C, 0x0, 0x4, 0x0, 0x0, 0x0, 0x1 };
31 public void testSrPceCapabilityParser() throws PCEPDeserializerException {
32 final SrPceCapabilityTlvParser parser = new SrPceCapabilityTlvParser();
33 final SrPceCapability spcTlv = new SrPceCapabilityBuilder().setMsd(Uint8.ONE).build();
34 assertEquals(spcTlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(SPC_TLV_BYTES, 4))));
35 final ByteBuf buff = Unpooled.buffer();
36 parser.serializeTlv(spcTlv, buff);
37 assertArrayEquals(SPC_TLV_BYTES, ByteArray.getAllBytes(buff));
41 public void testPathSetupTypeTlvParser() throws PCEPDeserializerException {
42 final SrPathSetupTypeTlvParser parser = new SrPathSetupTypeTlvParser();
43 final PathSetupType pstTlv = new PathSetupTypeBuilder().setPst(Uint8.ONE).build();
44 assertEquals(pstTlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(SR_TE_PST_BYTES, 4))));
45 final ByteBuf buff = Unpooled.buffer();
46 parser.serializeTlv(pstTlv, buff);
47 assertArrayEquals(SR_TE_PST_BYTES, ByteArray.getAllBytes(buff));