Moved stateful07 parser to their own project.
[bgpcep.git] / pcep / impl / src / test / java / org / opendaylight / protocol / pcep / impl / PCEPTlvParserTest.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.pcep.impl;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12
13 import java.util.List;
14
15 import org.junit.Test;
16 import org.opendaylight.protocol.pcep.impl.tlv.NoPathVectorTlvParser;
17 import org.opendaylight.protocol.pcep.impl.tlv.OFListTlvParser;
18 import org.opendaylight.protocol.pcep.impl.tlv.OrderTlvParser;
19 import org.opendaylight.protocol.pcep.impl.tlv.OverloadedDurationTlvParser;
20 import org.opendaylight.protocol.pcep.impl.tlv.ReqMissingTlvParser;
21 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfId;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.list.tlv.OfList;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.list.tlv.OfListBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.Order;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.OrderBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.duration.tlv.OverloadDuration;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.duration.tlv.OverloadDurationBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.no.path.tlvs.NoPathVectorBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.req.missing.tlv.ReqMissing;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.req.missing.tlv.ReqMissingBuilder;
34
35 import com.google.common.collect.Lists;
36
37 public class PCEPTlvParserTest {
38
39         private static final byte[] noPathVectorBytes = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xa7 };
40         private static final byte[] overloadedBytes = { (byte) 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff };
41         private static final byte[] reqMissingBytes = { (byte) 0xF7, (byte) 0x82, (byte) 0x35, (byte) 0x17 };
42         private static final byte[] orderBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0x00, (byte) 0x00,
43                         (byte) 0x01 };
44         private static final byte[] ofListBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 };
45
46         @Test
47         public void testNoPathVectorTlv() throws PCEPDeserializerException {
48                 final NoPathVectorTlvParser parser = new NoPathVectorTlvParser();
49                 final NoPathVectorTlv tlv = new NoPathVectorBuilder().setFlags(
50                                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv.Flags(false, true, false, true, false, true, true, true)).build();
51                 assertEquals(tlv, parser.parseTlv(noPathVectorBytes));
52                 assertArrayEquals(noPathVectorBytes, parser.serializeTlv(tlv));
53         }
54
55         @Test
56         public void testOverloadedDurationTlv() throws PCEPDeserializerException {
57                 final OverloadedDurationTlvParser parser = new OverloadedDurationTlvParser();
58                 final OverloadDuration tlv = new OverloadDurationBuilder().setDuration(0x7FFFFFFFL).build();
59                 assertEquals(tlv, parser.parseTlv(overloadedBytes));
60                 assertArrayEquals(overloadedBytes, parser.serializeTlv(tlv));
61         }
62
63         public void testReqMissingTlv() throws PCEPDeserializerException {
64                 final ReqMissingTlvParser parser = new ReqMissingTlvParser();
65                 final ReqMissing tlv = new ReqMissingBuilder().setRequestId(new RequestId(0xF7823517L)).build();
66                 assertEquals(tlv, parser.parseTlv(reqMissingBytes));
67                 assertArrayEquals(reqMissingBytes, parser.serializeTlv(tlv));
68         }
69
70         @Test
71         public void testOrderTlv() throws PCEPDeserializerException {
72                 final OrderTlvParser parser = new OrderTlvParser();
73                 final Order tlv = new OrderBuilder().setDelete(0xFFFFFFFFL).setSetup(0x00000001L).build();
74                 assertEquals(tlv, parser.parseTlv(orderBytes));
75                 assertArrayEquals(orderBytes, parser.serializeTlv(tlv));
76         }
77
78         @Test
79         public void testOFListTlv() throws PCEPDeserializerException {
80                 final OFListTlvParser parser = new OFListTlvParser();
81                 final List<OfId> ids = Lists.newArrayList();
82                 ids.add(new OfId(0x1234));
83                 ids.add(new OfId(0x5678));
84                 final OfList tlv = new OfListBuilder().setCodes(ids).build();
85                 assertEquals(tlv, parser.parseTlv(ofListBytes));
86                 assertArrayEquals(ofListBytes, parser.serializeTlv(tlv));
87         }
88 }