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.pcep.impl;
10 import static org.junit.Assert.fail;
12 import java.io.IOException;
14 import org.junit.Ignore;
15 import org.junit.Test;
16 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
17 import org.opendaylight.protocol.pcep.impl.subobject.EROAsNumberSubobjectParser;
18 import org.opendaylight.protocol.pcep.impl.subobject.EROIpPrefixSubobjectParser;
19 import org.opendaylight.protocol.pcep.impl.subobject.EROUnnumberedInterfaceSubobjectParser;
22 * Tests for subobjects
24 public class PCEPSubobjectParserTest {
25 final byte[] ipv6bytes1 = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
26 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
27 final byte[] ipv6bytes2 = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12,
28 (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
30 final byte[] ipv4bytes1 = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
31 final byte[] ipv4bytes2 = { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 };
33 final byte[] asnumber = { (byte) 0xA0, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64 };
36 public void testSerDeser() throws PCEPDeserializerException, IOException {
37 // final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PackOfSubobjects.bin");
38 // final List<ExplicitRouteSubobject> objsToTest = PCEPEROSubobjectParser.parse(bytesFromFile);
40 // assertEquals(8, objsToTest.size());
42 // final EROAsNumberSubobjectParser parser = new EROAsNumberSubobjectParser();
43 // final CSubobject s = parser.parseSubobject(ByteArray.cutBytes(this.asnumber, 2));
45 // assertEquals(s, new AsNumberBuilder().setAsNumber(new AsNumber((long) 0x64)).build());
46 // assertEquals(objsToTest.get(1), new AsNumberBuilder().setAsNumber(new AsNumber(0x0010L)).build());
48 // assertEquals(objsToTest.get(2), new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new
49 // IPv4Address(this.ipv4bytes1), 0x20), true));
51 // assertEquals(objsToTest.get(3), new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new
52 // IPv4Address(this.ipv4bytes2), 0x15), false));
53 // assertEquals(objsToTest.get(4), new EROIPPrefixSubobject<IPv6Prefix>(new IPv6Prefix(new
54 // IPv6Address(this.ipv6bytes1), 0x80), true));
56 // assertEquals(objsToTest.get(5), new EROIPPrefixSubobject<IPv6Prefix>(new IPv6Prefix(new
57 // IPv6Address(this.ipv6bytes2), 0x16), false));
58 // final byte[] addr1 = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
59 // assertEquals(objsToTest.get(6),
60 // new EROUnnumberedInterfaceSubobject(new IPv4Address(addr1), new UnnumberedInterfaceIdentifier(0xFFFFFFFFL),
63 // final byte[] addr2 = { (byte) 0x01, (byte) 0x24, (byte) 0x56, (byte) 0x78 };
64 // assertEquals(objsToTest.get(7),
65 // new EROUnnumberedInterfaceSubobject(new IPv4Address(addr2), new UnnumberedInterfaceIdentifier(0x9ABCDEF0L),
68 // assertArrayEquals(bytesFromFile, PCEPEROSubobjectParser.put(objsToTest));
74 public void testEROSubojectsSerDeserWithoutBin() throws PCEPDeserializerException {
75 // final List<ExplicitRouteSubobject> objsToTest = new ArrayList<ExplicitRouteSubobject>();
76 // objsToTest.add(new EROType1LabelSubobject(0xFFFF51F2L, true, false));
77 // objsToTest.add(new EROType1LabelSubobject(0x12345648L, false, true));
78 // objsToTest.add(new EROGeneralizedLabelSubobject(new byte[] { (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte)
79 // 0xFF }, true, true));
80 // objsToTest.add(new EROWavebandSwitchingLabelSubobject(0x12345678L, 0x87654321L, 0xFFFFFFFFL, false, false));
81 // objsToTest.add(new EROPathKeyWith32PCEIDSubobject(0x1235, new byte[] { (byte) 0x00, (byte) 0x55, (byte) 0xFF,
82 // (byte) 0xF1 }, true));
83 // objsToTest.add(new EROPathKeyWith128PCEIDSubobject(0x5432, new byte[] { (byte) 0x00, (byte) 0x55, (byte)
85 // (byte) 0x00, (byte) 0x55, (byte) 0xFF, (byte) 0xF1, (byte) 0x00, (byte) 0x55, (byte) 0xFF, (byte) 0xF1,
87 // (byte) 0x55, (byte) 0xFF, (byte) 0xF1 }, true));
88 // objsToTest.add(new EROExplicitExclusionRouteSubobject(Arrays.asList((ExcludeRouteSubobject) new
89 // XROAsNumberSubobject(new AsNumber((long) 2588), true))));
91 // assertEquals(objsToTest, PCEPEROSubobjectParser.parse(PCEPEROSubobjectParser.put(objsToTest)));
95 public void testRROSubojectsSerDeserWithoutBin() throws PCEPDeserializerException {
96 // final List<ReportedRouteSubobject> objsToTest = new ArrayList<ReportedRouteSubobject>();
97 // objsToTest.add(new RROIPAddressSubobject(new IpPrefix(Ipv6Util.prefixForBytes(this.ipv6bytes2, 0x16)), true,
99 // objsToTest.add(new RROIPAddressSubobject(new IpPrefix(Ipv4Util.prefixForBytes(this.ipv4bytes1, 0x16)), true,
101 // objsToTest.add(new RROType1LabelSubobject(0xFFFF51F2L, true));
102 // objsToTest.add(new RROType1LabelSubobject(0x12345648L, false));
103 // objsToTest.add(new RROGeneralizedLabelSubobject(new byte[] { (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte)
105 // objsToTest.add(new RROWavebandSwitchingLabelSubobject(0x12345678L, 0x87654321L, 0xFFFFFFFFL, false));
106 // objsToTest.add(new RROPathKeyWith32PCEIDSubobject(0x1235, new byte[] { (byte) 0x00, (byte) 0x55, (byte) 0xFF,
108 // objsToTest.add(new RROPathKeyWith128PCEIDSubobject(0x5432, new byte[] { (byte) 0x00, (byte) 0x55, (byte)
109 // 0xFF, (byte) 0xF1,
110 // (byte) 0x00, (byte) 0x55, (byte) 0xFF, (byte) 0xF1, (byte) 0x00, (byte) 0x55, (byte) 0xFF, (byte) 0xF1,
112 // (byte) 0x55, (byte) 0xFF, (byte) 0xF1 }));
113 // objsToTest.add(new RROAttributesSubobject(new byte[] { (byte) 0x00, (byte) 0x55, (byte) 0xFF, (byte) 0xF1,
115 // (byte) 0x55, (byte) 0xFF, (byte) 0xF1, (byte) 0x00, (byte) 0x55, (byte) 0xFF, (byte) 0xF1, (byte) 0x00,
117 // (byte) 0xFF, (byte) 0xF1 }));
119 // assertEquals(objsToTest, PCEPRROSubobjectParser.parse(PCEPRROSubobjectParser.put(objsToTest)));
123 public void testXROSubojectsSerDeserWithoutBin() throws PCEPDeserializerException {
124 // final List<ExcludeRouteSubobject> objsToTest = new ArrayList<ExcludeRouteSubobject>();
125 // objsToTest.add(new XROIPPrefixSubobject(new IpPrefix(Ipv6Util.prefixForBytes(this.ipv6bytes2, 0x16)), true,
126 // XROSubobjectAttribute.INTERFACE));
127 // objsToTest.add(new XROIPPrefixSubobject(new IpPrefix(Ipv4Util.prefixForBytes(this.ipv4bytes1, 0x16)), false,
128 // XROSubobjectAttribute.INTERFACE));
129 // objsToTest.add(new XROAsNumberSubobject(new AsNumber((long) 0x1234), true));
130 // objsToTest.add(new XROUnnumberedInterfaceSubobject(new IPv4Address(this.ipv4bytes1), new
131 // UnnumberedInterfaceIdentifier(0xFFFFFFFFL), true, XROSubobjectAttribute.SRLG));
132 // objsToTest.add(new XROSRLGSubobject(new SharedRiskLinkGroup(0x12345678L), false));
134 // assertEquals(objsToTest, PCEPXROSubobjectParser.parse(PCEPXROSubobjectParser.put(objsToTest)));
139 // public void testDifferentLengthExceptions() {
140 // final byte[] bytes = { (byte) 0x00 }; // not empty but not enought data
141 // // for parsing subobjects
144 // EROAsNumberSubobjectParser.parse(bytes, true);
146 // } catch (final PCEPDeserializerException e) {
150 // EROUnnumberedInterfaceSubobjectParser.parse(bytes, true);
152 // } catch (final PCEPDeserializerException e) {
156 // EROIpPrefixSubobjectParser.parse(bytes, true);
158 // } catch (final PCEPDeserializerException e) {
163 public void testNullExceptions() throws PCEPDeserializerException {
164 final byte[] bytes = null; // not empty but not enought data for parsing
168 new EROAsNumberSubobjectParser().parseSubobject(bytes, false);
170 } catch (final IllegalArgumentException e) {
174 new EROUnnumberedInterfaceSubobjectParser().parseSubobject(bytes, false);
176 } catch (final IllegalArgumentException e) {
180 new EROIpPrefixSubobjectParser().parseSubobject(bytes, false);
182 } catch (final IllegalArgumentException e) {
187 public void testUnknownInstanceExceptions() {
189 // final ExplicitRouteSubobject instance = new ExplicitRouteSubobject() {
193 // new EROAsNumberSubobjectParser().serializeSubobject(instance);
195 // } catch (final IllegalArgumentException e) {
199 // EROUnnumberedInterfaceSubobjectParser.put(instance);
201 // } catch (final IllegalArgumentException e) {
205 // EROIpPrefixSubobjectParser.put(instance);
207 // } catch (final IllegalArgumentException e) {
211 // final byte[] ipv6addr = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
213 // (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
215 // EROIpPrefixSubobjectParser.put(new EROIPPrefixSubobject<IPv6Prefix>(new IPv6Prefix(new IPv6Address(ipv6addr),
218 // } catch (final IllegalArgumentException e) {
222 // EROIPv6PrefixSubobjectParser.put(instance);
224 // } catch (final IllegalArgumentException e) {
228 // final byte[] ipv4addr = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
229 // EROIPv6PrefixSubobjectParser.put(new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new
230 // IPv4Address(ipv4addr), 1), false));
232 // } catch (final IllegalArgumentException e) {