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.Test;
15 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
16 import org.opendaylight.protocol.pcep.impl.subobject.XROAsNumberSubobjectParser;
17 import org.opendaylight.protocol.pcep.impl.subobject.XROIpPrefixSubobjectParser;
18 import org.opendaylight.protocol.pcep.impl.subobject.XROUnnumberedInterfaceSubobjectParser;
19 import org.opendaylight.protocol.util.ByteArray;
21 public class PCEPXROSubobjectParserTest {
24 public void testSerDeser() throws PCEPDeserializerException, IOException {
25 final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PackOfXROSubobjects.bin");
26 // final List<ExcludeRouteSubobject> objsToTest = PCEPXROSubobjectParser.parse(bytesFromFile);
28 // assertEquals(5, objsToTest.size());
32 // new XROIPPrefixSubobject(new IpPrefix(Ipv4Util.prefixForBytes(new byte[] { (byte) 192, (byte) 168, (byte) 0,
33 // (byte) 0 }, 16)), true, XROSubobjectAttribute.NODE));
36 // new XROIPPrefixSubobject(new IpPrefix(Ipv6Util.prefixForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte)
38 // (byte) 0x78, (byte) 0x90, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x90, (byte) 0x12,
39 // (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0, (byte) 0 }, 112)), true, XROSubobjectAttribute.INTERFACE));
40 // assertEquals(objsToTest.get(2), new XROUnnumberedInterfaceSubobject(new IPv4Address(new byte[] { (byte) 0,
41 // (byte) 0, (byte) 0,
42 // (byte) 0x20 }), new UnnumberedInterfaceIdentifier(0x1234L), false, XROSubobjectAttribute.SRLG));
43 // assertEquals(objsToTest.get(3), new XROAsNumberSubobject(new AsNumber((long) 0x1234), false));
44 // assertEquals(objsToTest.get(4), new XROSRLGSubobject(new SharedRiskLinkGroup(0x12345678L), false));
46 // assertArrayEquals(bytesFromFile, PCEPXROSubobjectParser.put(objsToTest));
51 public void testDifferentLengthExceptions() {
52 final byte[] bytes = { (byte) 0x00 }; // not empty but not enought data for parsing subobjects
55 new XROAsNumberSubobjectParser().parseSubobject(bytes, true);
57 } catch (final PCEPDeserializerException e) {
61 new XROUnnumberedInterfaceSubobjectParser().parseSubobject(bytes, true);
63 } catch (final PCEPDeserializerException e) {
67 new XROIpPrefixSubobjectParser().parseSubobject(bytes, true);
69 } catch (final PCEPDeserializerException e) {