/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.protocol.pcep.impl;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.protocol.concepts.Ipv4Util;
import org.opendaylight.protocol.concepts.Ipv6Util;
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
import org.opendaylight.protocol.pcep.impl.object.PCEPBandwidthObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPEndPointsObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPLoadBalancingObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPMetricObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPSvecObjectParser;
import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
import org.opendaylight.protocol.pcep.spi.pojo.PCEPExtensionProviderContextImpl;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.address.family.Ipv4Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.address.family.Ipv6Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.pcinitiate.message.requests.EndpointsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.SvecBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.LoadBalancingBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.reported.route.BandwidthBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.svec.MetricBuilder;
import com.google.common.collect.Lists;
import com.google.common.primitives.UnsignedBytes;
/*
* Used resources
*
* PCEPOpenObject3.bin
* objClass: 1
* objType: 1
* objLength: 8
* version: 1
* Flags:
* - processing: true
* - ignored: true
*
* keepAlive: 30
* deadTimer: 120
* sessionId: 1
* tlvs:NO
*
* PCEPBandwidthObject1LowerBounds.bin
* objClass: 5
* objType: 1
* objLength: 16
* version: 1
* Flags:
* - processing: true
* - ignored: true
*
* Bandwidth: 0
*
* PCEPBandwidthObject2UpperBounds.bin
* objClass: 5
* objType: 1
* objLength: 16
* version: 1
* Flags:
* - processing: true
* - ignored: true
*
* Bandwidth: 0xFFFFFFFF
*
* PCEPEndPointsObject1IPv4.bin
* objClass: 4
* objType: 1
* objLength: 12
* version: 1
* Flags:
* - processing: true
* - ignored: true
*
* src IP: 0xA2F5110E
* dest IP: 0xFFFFFFFF
*
* PCEPEndPointsObject2IPv6.bin
* objClass: 4
* objType: 2
* objLength: 36
* version: 1
* Flags:
* - processing: true
* - ignored: true
*
* src IP: 0xFFFFFFFFF FFFFFFFFF FFFFFFFFF FFFFFFFFF
* dest IP: 0x00025DD2 FFECA1B6 581E9F50 00000000
*
* PCEPErrorObject1.bin
* objClass: 13 (RP)
* objType: 1
* objLength: 8
* version: 1
* Flags:
* - processing: false
* - ignored: false
*
* Error-type: 1
* Error-value: 1
* Tlvs: NO
*
* PCEPErrorObject2Invalid.bin
* objClass: 13 (RP)
* objType: 1
* objLength: 8
* version: 1
* Flags:
* - processing: false
* - ignored: false
*
* Error-type: 3
* Error-value: 0
* Tlvs: NO
*
* PCEPErrorObject3.bin
* objClass: 13 (RP)
* objType: 1
* objLength: 8
* version: 1
* Flags:
* - processing: false
* - ignored: false
*
* Error-type: 2
* Error-value: 0
* Tlvs: NO
*
* PCEPLspaObject1LowerBounds.bin
* objClass: 9
* objType: 1
* objLength: 20
* version: 1
* Flags:
* - processing: true
* - ignored: true
*
* Exclude-any: 0x00000000L
* Include-any: 0x00000000L
* Include-all: 0x00000000L
* Setup Prio: 0x00
* Holding Prio: 0x00
* Flags: - L : false
*
* PCEPLspaObject2UpperBounds.bin
* objClass: 9
* objType: 1
* objLength: 20
* version: 1
* Flags:
* - processing: true
* - ignored: true
*
* Exclude-any: 0xFFFFFFFFL
* Include-any: 0xFFFFFFFFL
* Include-all: 0xFFFFFFFFL
* Setup Prio: 0xFF
* Holding Prio: 0xFF
* Flags: - L : true
*
* PCEPLspaObject3RandVals.bin
* objClass: 9
* objType: 1
* objLength: 20
* version: 1
* Flags:
* - processing: true
* - ignored: true
*
* Exclude-any: 0x20A1FEE3L
* Include-any: 0x1A025CC7L
* Include-all: 0x2BB66532L
* Setup Prio: 0x03
* Holding Prio: 0x02
* Flags: - L : true
*
* NoPathObject1WithTLV.bin
* objClass: 3 (RP)
* objType: 1
* objLength: 16
* version: 1
* Flags:
* - processing: false
* - ignored: false
*
* Nature of Issue: 2
* No-Path flags:
* - C: true
*
* tlvs:
* -- NO-PATH-VECTOR
* - flags (0x4000):
* - PCE currently unavailable: false
* - unknown destination: true
* - unknown source: false
*
*
* NoPathObject2WithoutTLV.bin
* objClass: 3 (RP)
* objType: 1
* objLength: 8
* version: 1
* Flags:
* - processing: false
* - ignored: true
*
* Nature of Issue: 16
* No-Path flags:
* - C: false
*
* tlvs:NO
*
* PCEPNotificationObject1WithTlv.bin
* objClass: 12
* objType: 1
* objLength: 16
* version: 1
* Flags:
* - processing: false
* - ignored: false
*
* NT: 1
* NV: 1
* Tlvs:
* - OverloaderDuration(0xFF0000A2L)
*
* PCEPNotificationObject2WithoutTlv.bin
* objClass: 12
* objType: 1
* objLength: 8
* version: 1
* Flags:
* - processing: false
* - ignored: false
*
* NT: 0xFF
* NV: 0xFF
* Tlvs: NO
*
* PCEPOpenObject1.bin
* objClass: 1
* objType: 1
* objLength: 28
* version: 1
* Flags:
* - processing: false
* - ignored: false
*
* keepAlive: 30
* deadTimer: 120
* sessionId: 1
* tlvs:
* - PCEPStatefulCapability
* - LSPStateDBVersionTlv
* - NodeIdentifierTlv
*
* PCEPOpenObject2UpperBoundsNoTlv.bin
* objClass: 1
* objType: 1
* objLength: 34
* version: 1
* Flags:
* - processing: false
* - ignored: false
*
* keepAlive: 0xFF
* deadTimer: 0xFF
* sessionId: 0xFF
* tlvs: NO
*
* PCEPRPObject1.bin
* objClass: 2 (RP)
* objType: 1
* objLength: 12
* version: 1
* Flags:
* - processing: false
* - ignored: false
*
* RP flags:
* - loose/strict: true
* - Bi-directional: false
* - Reoptimization: false
* - Priority: 5
* Request ID: 0xDEADBEEF
* tlvs: NO
*
* PCEPSvecObject1_10ReqIDs.bin
* objClass: 11
* objType: 1
* objLength: 48
* version: 1
* Flags:
* - processing: true
* - ignored: false
*
* Flags:
* - Link diverse: true
* - Node diverse: false
* - SRLG diverse: true
* Reques-ID-numbers:
* #1 - 0xFFFFFFFFL
* #2 - 0x00000000L
* #3 - 0x01234567L
* #4 - 0x89ABCDEFL
* #5 - 0xFEDCBA98L
* #6 - 0x76543210L
* #7 - 0x15825266L
* #8 - 0x48120BBEL
* #9 - 0x25FB7E52L
* #10 - 0xB2F2546BL
*
* PCEPSvecObject2.bin
* objClass: 11
* objType: 1
* objLength: 08
* version: 1
* Flags:
* - processing: false
* - ignored: false
*
* Flags:
* - Link diverse: false
* - Node diverse: false
* - SRLG diverse: false
* Reques-ID-numbers:
* #1 - 0x000000FFL
* PCEPExcludeRouteObject.1.bin
* objClass: 17
* objType: 1
* objLength: 20
* version: 1
* Flags:
* - fail: true
* Subobjects:
* - XROIPv4PreffixSubobject(192.168.0.0/16, exclude, node)
* - XROASnumber(0x1234)
*/
public class PCEPObjectParserTest {
private TlvHandlerRegistry tlvRegistry;
@Before
public void setUp() throws Exception {
this.tlvRegistry = PCEPExtensionProviderContextImpl.create().getTlvHandlerRegistry();
}
// IPv4Address ipv4addr = new IPv4Address(new byte[] { (byte) 192, (byte) 168, 1, 8 });
//
// IPv6Address ipv6addr = new IPv6Address(new byte[] { (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1,
// (byte) 192, (byte) 168,
// 2, 1, (byte) 192, (byte) 168, 2, 1 });
//
//
// /**
// * Standard serialization test
// * Used resources:
// * - PCEPOpenObject1.bin
// *
// * @throws PCEPDeserializerException
// * @throws IOException
// * @throws PCEPDocumentedException
// */
// @Test
// @Ignore
// // FIXME: temporary
// public void testObjectDeserialization() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
// PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPOpenObject1.bin"));
// }
//
// @Test
// public void testUnknownClass() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
//
// final PCEPObject obj =
// PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPObject1UnknownClass.bin")).get(
// 0);
//
// // assertTrue(obj instanceof UnknownObject);
// // assertEquals(((UnknownObject) obj).getError(), PCEPErrors.UNRECOGNIZED_OBJ_CLASS);
// }
//
// // @Test
// // public void testUnknownType() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
// // final PCEPObject obj =
// PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPObject2UnknownType.bin")).get(0);
// //
// // assertTrue(obj instanceof UnknownObject);
// // assertEquals(((UnknownObject) obj).getError(), PCEPErrors.UNRECOGNIZED_OBJ_TYPE);
// // }
// //
// // @Test
// // public void testCloseObjSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
// // serDeserTest("src/test/resources/PCEPCloseObject1.bin", new PCEPCloseObject(Reason.TOO_MANY_UNKNOWN_MSG));
// // }
//
@Test
public void testLoadBalancingObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
final PCEPLoadBalancingObjectParser parser = new PCEPLoadBalancingObjectParser(this.tlvRegistry);
final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPLoadBalancingObject1.bin");
final LoadBalancingBuilder builder = new LoadBalancingBuilder();
builder.setProcessingRule(true);
builder.setIgnore(false);
builder.setMaxLsp((short) UnsignedBytes.toInt((byte) 0xf1));
builder.setMinBandwidth(new Float32(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
assertArrayEquals(result, parser.serializeObject(builder.build()));
}
//
// @Test
// public void testLspObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
// serDeserTest("src/test/resources/PCEPLspObject1NoTlvsUpperBounds.bin", new PCEPLspObject(0xFFFFF, true, false,
// true, false, null));
// }
//
// @Test
// public void testERObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
// final byte[] bytesFromFile =
// ByteArray.fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin");
//
// MockitoAnnotations.initMocks(this);
// PCEPExplicitRouteObjectParser parser = new PCEPExplicitRouteObjectParser(registry);
// doReturn(parser).when(registry).getObjectParser(PCEPExplicitRouteObjectParser.TYPE,
// PCEPExplicitRouteObjectParser.CLASS);
// doReturn(new EROAsNumberSubobjectParser()).when(registry).getSubobjectParser(EROAsNumberSubobjectParser.TYPE);
// ObjectHeader h = new ObjectHeader() {
//
// @Override
// public Class extends DataContainer> getImplementedInterface() {
// // TODO Auto-generated method stub
// return null;
// }
//
// @Override
// public Boolean isProcessingRule() {
// return false;
// }
//
// @Override
// public Boolean isIgnore() {
// return false;
// }
// };
//
// final ExplicitRouteSubobject specObj = (ExplicitRouteSubobject)
// registry.getObjectParser(PCEPExplicitRouteObjectParser.TYPE, PCEPExplicitRouteObjectParser.CLASS).parseObject(h,
// bytesFromFile);
//
// System.out.println(specObj.toString());
//
// //final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
// //assertArrayEquals(bytesFromFile, bytesActual);
// }
//
// @Test
// public void testIRObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
// final byte[] bytesFromFile =
// ByteArray.fileToBytes("src/test/resources/PCEPIncludeRouteObject1PackOfSubobjects.bin");
//
// final PCEPIncludeRouteObject specObj = (PCEPIncludeRouteObject)
// PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
//
// assertEquals(8, specObj.getSubobjects().size());
//
// final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
// assertArrayEquals(bytesFromFile, bytesActual);
// }
//
// @Test
// public void tesRRObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
// final byte[] bytesFromFile =
// ByteArray.fileToBytes("src/test/resources/PCEPReportedRouteObject1PackOfSubobjects.bin");
//
// final PCEPReportedRouteObject specObj = (PCEPReportedRouteObject)
// PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
//
// assertEquals(6, specObj.getSubobjects().size());
//
// final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
// assertArrayEquals(bytesFromFile, bytesActual);
// }
//
@Test
public void testBandwidthObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
final PCEPBandwidthObjectParser parser = new PCEPBandwidthObjectParser(this.tlvRegistry);
byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject1LowerBounds.bin");
final BandwidthBuilder builder = new BandwidthBuilder();
builder.setProcessingRule(true);
builder.setIgnore(true);
builder.setBandwidth(new Float32(result));
assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
assertArrayEquals(result, parser.serializeObject(builder.build()));
result = ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject2UpperBounds.bin");
builder.setBandwidth(new Float32(result));
assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
assertArrayEquals(result, parser.serializeObject(builder.build()));
}
@Test
public void testEndPointsObjectIPv4() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
final byte[] srcIPBytes = { (byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E };
final byte[] destIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
final PCEPEndPointsObjectParser parser = new PCEPEndPointsObjectParser(this.tlvRegistry);
final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject1IPv4.bin");
final EndpointsBuilder builder = new EndpointsBuilder();
builder.setProcessingRule(true);
builder.setIgnore(false);
builder.setAddressFamily(new Ipv4Builder().setSourceIpv4Address(Ipv4Util.addressForBytes(srcIPBytes)).setDestinationIpv4Address(
Ipv4Util.addressForBytes(destIPBytes)).build());
assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
assertArrayEquals(result, parser.serializeObject(builder.build()));
}
@Test
public void testEndPointsObjectSerDeserIPv6() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
final byte[] destIPBytes = { (byte) 0x00, (byte) 0x02, (byte) 0x5D, (byte) 0xD2, (byte) 0xFF, (byte) 0xEC, (byte) 0xA1,
(byte) 0xB6, (byte) 0x58, (byte) 0x1E, (byte) 0x9F, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, };
final byte[] srcIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
final PCEPEndPointsObjectParser parser = new PCEPEndPointsObjectParser(this.tlvRegistry);
final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject2IPv6.bin");
final EndpointsBuilder builder = new EndpointsBuilder();
builder.setProcessingRule(true);
builder.setIgnore(false);
builder.setAddressFamily(new Ipv6Builder().setSourceIpv6Address(Ipv6Util.addressForBytes(srcIPBytes)).setDestinationIpv6Address(
Ipv6Util.addressForBytes(destIPBytes)).build());
assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
assertArrayEquals(result, parser.serializeObject(builder.build()));
}
//
// /**
// * Test of Serialization/Deserialization of PCEPErrorObjectParser.
// *
// * Used resources:
// * - PCEPErrorObject1.bin
// * - PCEPErrorObject3.bin
// *
// * @throws PCEPDeserializerException
// * @throws IOException
// * @throws PCEPDocumentedException
// */
// @Test
// public void testErrorObjectSerDeserWithTlv() throws PCEPDeserializerException, IOException,
// PCEPDocumentedException {
// serDeserTest("src/test/resources/PCEPErrorObject1.bin", new PCEPErrorObject(PCEPErrors.NON_OR_INVALID_OPEN_MSG));
// serDeserTest("src/test/resources/PCEPErrorObject3.bin", new
// PCEPErrorObject(PCEPErrors.CAPABILITY_NOT_SUPPORTED));
// }
//
// /**
// * Test of validity of PCEPErrorObjectParser. Expect throwed NoSuchElementException.
// *
// * Used resources:
// * - PCEPErrorObject2Invalid.bin
// *
// * @throws NoSuchElementException
// * @throws IOException
// * @throws PCEPDocumentedException
// */
// @Test(expected = PCEPDeserializerException.class)
// public void testUnknownError() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
// PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject2Invalid.bin")).get(0);
// }
//
// /**
// * Test for upper/lower bounds of PCEPLspaObject (Serialization/Deserialization)
// * Used resources:
// * - PCEPLspaObject1LowerBounds.bin
// * - PCEPLspaObject2UpperBounds.bin
// * - PCEPLspaObject3RandVals.bin
// *
// * @throws IOException
// * @throws PCEPDeserializerException
// * @throws PCEPDocumentedException
// */
// @Test
// public void testLspaObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
// serDeserTest("src/test/resources/PCEPLspaObject2UpperBounds.bin",
// new PCEPLspaObject(0xFFFFFFFFL, 0xFFFFFFFFL, 0xFFFFFFFFL, (short) 0xFF, (short) 0xFF, false, true, true, true));
// serDeserTest("src/test/resources/PCEPLspaObject1LowerBounds.bin",
// new PCEPLspaObject(0x00000000L, 0x00000000L, 0x00000000L, (short) 0x00, (short) 0x00, false, false, true, true));
// serDeserTest("src/test/resources/PCEPLspaObject3RandVals.bin",
// new PCEPLspaObject(0x20A1FEE3L, 0x1A025CC7L, 0x2BB66532L, (short) 0x03, (short) 0x02, false, true, true, true));
// }
//
@Test
public void testMetricObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
final PCEPMetricObjectParser parser = new PCEPMetricObjectParser(this.tlvRegistry);
byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPMetricObject1LowerBounds.bin");
final MetricBuilder builder = new MetricBuilder();
builder.setProcessingRule(true);
builder.setIgnore(true);
builder.setComputed(false);
builder.setBound(false);
builder.setMetricType((short) 1);
builder.setValue(new Float32(new byte[] { 0, 0, 0, 0 }));
assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
assertArrayEquals(result, parser.serializeObject(builder.build()));
result = ByteArray.fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin");
builder.setComputed(true);
builder.setBound(false);
builder.setMetricType((short) 2);
builder.setValue(new Float32(new byte[] { (byte) 0x4f, (byte) 0x70, (byte) 0x00, (byte) 0x00 }));
assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
assertArrayEquals(result, parser.serializeObject(builder.build()));
}
//
// /**
// * Standard deserialization test + specific test without tlv
// * Used resources:
// * - NoPathObject1WithTLV.bin
// * - NoPathObject2WithoutTLV.bin
// *
// * @throws PCEPDeserializerException
// * @throws IOException
// * @throws PCEPDocumentedException
// */
// @Test
// public void testNoPathObjectDeserialization() throws PCEPDeserializerException, IOException,
// PCEPDocumentedException {
// // final List tlvs = new ArrayList(1);
// // tlvs.add(new NoPathVectorTlv(false, false, true, false, false, false));
// // serDeserTest("src/test/resources/NoPathObject1WithTLV.bin", new PCEPNoPathObject((short) 2, true, tlvs,
// false));
// serDeserTest("src/test/resources/NoPathObject2WithoutTLV.bin", new PCEPNoPathObject((short) 0x10, false, true));
//
// }
//
// /**
// * Standard serialization test + without tlv
// * Used resources:
// * - NoPathObject1WithTLV.bin
// * - NoPathObject2WithoutTLV.bin
// *
// * @throws PCEPDeserializerException
// * @throws IOException
// * @throws PCEPDocumentedException
// */
// @Test
// public void testNoPathObjectSerialization() throws IOException, PCEPDeserializerException,
// PCEPDocumentedException {
// byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/NoPathObject2WithoutTLV.bin");
// PCEPNoPathObject noPathObject = (PCEPNoPathObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
// byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) noPathObject));
// assertArrayEquals(bytesFromFile, bytesActual);
//
// bytesFromFile = ByteArray.fileToBytes("src/test/resources/NoPathObject1WithTLV.bin");
// noPathObject = (PCEPNoPathObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
// bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) noPathObject));
// assertArrayEquals(bytesFromFile, bytesActual);
// }
//
// /**
// * Specific test with/without tlvs (Ser/Deser)
// * Used resources:
// * - PCEPNotificationObject1WithTlv.bin - PCEPNotificationObject2WithoutTlv.bin
// *
// * @throws PCEPDeserializerException
// * @throws IOException
// * @throws PCEPDocumentedException
// */
// @Test
// public void testNotifyObjectSerDeserWithTlv() throws PCEPDeserializerException, IOException,
// PCEPDocumentedException {
// // FINAL LIST TLVS = NEW ARRAYLIST(1);
// // TLVS.ADD(NEW OVERLOADEDDURATIONTLV(0XFF0000A2));
// // SERDESERTEST("src/test/resources/PCEPNotificationObject1WithTlv.bin", new PCEPNotificationObject((short) 1,
// (short) 1, tlvs));
// serDeserTest("src/test/resources/PCEPNotificationObject2WithoutTlv.bin", new PCEPNotificationObject((short) 0xFF,
// (short) 0xFF));
// }
//
// /**
// * Standard ser deser test
// * used resources:
// * - PCEPOpenObject1.bin
// *
// * @throws PCEPDeserializerException
// * @throws IOException
// * @throws PCEPDocumentedException
// */
// @Test
// @Ignore
// // FIXME: temporary
// public void testOpenObjectSerDeser() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
// // final List tlvs = new ArrayList();
// // tlvs.add(new PCEStatefulCapabilityTlv(false, true, true));
// // tlvs.add(new LSPStateDBVersionTlv(0x80));
// // final byte[] valueBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC,
// (byte) 0xDE, (byte) 0xF0 };
// // tlvs.add(new NodeIdentifierTlv(valueBytes));
// // final PCEPOpenObject specObject = new PCEPOpenObject(30, 120, 1, tlvs);
// //
// // serDeserTest("src/test/resources/PCEPOpenObject1.bin", specObject);
// }
//
// /**
// * Specific test for upper bounds and without tlvs
// * Used resources:
// * - PCEPOpenObject2UpperBoundsNoTlv.bin
// *
// * @throws PCEPDeserializerException
// * @throws IOException
// * @throws PCEPDocumentedException
// */
// @Test
// public void testOpenObjectBoundsWithoutTlvs() throws IOException, PCEPDeserializerException,
// PCEPDocumentedException {
// // final List tlvs = new ArrayList();
// // serDeserTest("src/test/resources/PCEPOpenObject2UpperBoundsNoTlv.bin", new PCEPOpenObject(0xFF, 0xFF, 0xFF,
// tlvs));
// serDeserTest("src/test/resources/PCEPOpenObject2UpperBoundsNoTlv.bin", new PCEPOpenObject(0xFF, 0xFF, 0xFF,
// null));
// }
//
// /**
// * Standard deserialization test
// * Used resources:
// * - PCEPRPObject1.bin
// *
// * @throws PCEPDeserializerException
// * @throws IOException
// * @throws PCEPDocumentedException
// */
// @Test
// public void testRPObjectSerDeser() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
// serDeserTest("src/test/resources/PCEPRPObject1.bin",
// new PCEPRequestParameterObject(true, false, true, true, false, false, false, false, (short) 5, 0xdeadbeefL,
// false, false));
// // serDeserTest(
// // "src/test/resources/PCEPRPObject2.bin",
// // new PCEPRequestParameterObject(true, false, false, false, true, false, true, false, true, (short) 5,
// 0xdeadbeefL, new ArrayList() {
// // private static final long serialVersionUID = 1L;
// //
// // {
// // this.add(new OrderTlv(0xFFFFFFFFL, 0x00000001L));
// // }
// // }, false, false));
// }
//
@Test
public void testSvecObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
final PCEPSvecObjectParser parser = new PCEPSvecObjectParser(this.tlvRegistry);
byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPSvecObject2.bin");
final SvecBuilder builder = new SvecBuilder();
builder.setProcessingRule(false);
builder.setIgnore(false);
builder.setLinkDiverse(false);
builder.setNodeDiverse(false);
builder.setSrlgDiverse(false);
builder.setRequestsIds(Lists.newArrayList(new RequestId(0xFFL)));
assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result));
assertArrayEquals(result, parser.serializeObject(builder.build()));
result = ByteArray.fileToBytes("src/test/resources/PCEPSvecObject1_10ReqIDs.bin");
builder.setProcessingRule(true);
builder.setLinkDiverse(true);
builder.setSrlgDiverse(true);
final List requestIDs = Lists.newArrayList();
requestIDs.add(new RequestId(0xFFFFFFFFL));
requestIDs.add(new RequestId(0x00000000L));
requestIDs.add(new RequestId(0x01234567L));
requestIDs.add(new RequestId(0x89ABCDEFL));
requestIDs.add(new RequestId(0xFEDCBA98L));
requestIDs.add(new RequestId(0x76543210L));
requestIDs.add(new RequestId(0x15825266L));
requestIDs.add(new RequestId(0x48120BBEL));
requestIDs.add(new RequestId(0x25FB7E52L));
requestIDs.add(new RequestId(0xB2F2546BL));
builder.setRequestsIds(requestIDs);
assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
assertArrayEquals(result, parser.serializeObject(builder.build()));
}
//
// @Test
// public void testClassTypeObject() throws PCEPDeserializerException, PCEPDocumentedException {
// final PCEPClassTypeObject ct = new PCEPClassTypeObject((short) 4);
// // final PCEPClassTypeObjectParser parser = new PCEPClassTypeObjectParser();
// // final byte[] bytes = parser.put(ct);
// // assertEquals(ct, parser.parse(bytes, true, false));
// }
//
// /**
// * Test PCEPExcludeRouteObjectObject (Serialization/Deserialization)
// * Used resources:
// * - PCEPExcludeRouteObject.1.bin
// *
// * @throws IOException
// * @throws PCEPDeserializerException
// * @throws PCEPDocumentedException
// */
// @Test
// public void testExcludeRouteObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
// final List xroSubobjects = new ArrayList();
// xroSubobjects.add(new XROIPPrefixSubobject(new IPv4Prefix(new IPv4Address(new byte[] { (byte) 192,
// (byte) 168,
// (byte) 100, (byte) 100 }), 16), true, XROSubobjectAttribute.NODE));
// xroSubobjects.add(new XROAsNumberSubobject(new AsNumber(0x1234L), false));
//
// }
//
// @Test
// public void tesObjectiveFunctionObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
// serDeserTest("src/test/resources/PCEPObjectiveFunctionObject.1.bin", new
// PCEPObjectiveFunctionObject(PCEPOFCodes.MBC, true, false));
// }
//
// @Test
// public void tesGlobalConstraintsObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
// serDeserTest("src/test/resources/PCEPGlobalConstraintsObject.1.bin",
// new PCEPGlobalConstraintsObject((short) 1, (short) 0, (short) 100, (short) 0xFF, true, false));
// }
//
// // FIXME: add at least one test with true value
// @Test
// public void openObjectWithTlv() throws PCEPDeserializerException, PCEPDocumentedException {
// // this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, false, false));
// // this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, false, true));
// // this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, true, false));
// // this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, true, true));
// }
//
// // private void testOpenObjectWithSpecTlv(final PCEPTlv tlv) throws PCEPDeserializerException,
// PCEPDocumentedException {
// // final List objs = new ArrayList();
// // final List tlvs = new ArrayList();
// // tlvs.add(tlv);
// // final PCEPOpenObject oo = new PCEPOpenObject(30, 120, 0, tlvs);
// // objs.add(oo);
// // final byte[] bytes = PCEPObjectFactory.put(objs);
// // final PCEPObject obj = PCEPObjectFactory.parseObjects(bytes).get(0);
// // assertEquals(oo, obj);
// // }
//
// @Test
// public void testErrorsMapping() {
// final PCEPErrorObjectParser.PCEPErrorsMaping mapper = PCEPErrorObjectParser.PCEPErrorsMaping.getInstance();
//
// for (final PCEPErrors error : PCEPErrors.values()) {
// final PCEPErrorIdentifier errorId = mapper.getFromErrorsEnum(error);
// assertEquals(error, mapper.getFromErrorIdentifier(errorId));
// }
// }
//
// @Test
// public void testOFCodesMapping() {
// final PCEPOFCodesMapping mapper = PCEPOFCodesMapping.getInstance();
//
// for (final PCEPOFCodes ofCode : PCEPOFCodes.values()) {
// final int ofCodeId = mapper.getFromOFCodesEnum(ofCode);
// assertEquals(ofCode, mapper.getFromCodeIdentifier(ofCodeId));
// }
// }
//
// @SuppressWarnings("unchecked")
// private static void serDeserTestWithoutBin(final T object) throws
// PCEPDeserializerException,
// PCEPDocumentedException {
// final byte[] serBytes = PCEPObjectFactory.put(Arrays.asList((PCEPObject) object));
// final T deserObj = (T) PCEPObjectFactory.parseObjects(serBytes).get(0);
//
// assertEquals(object, deserObj);
// }
//
// @Test
// public void testSERObjects() throws PCEPDocumentedException, PCEPDeserializerException {
// final List eroSubobjects = new ArrayList();
// eroSubobjects.add(new EROIPPrefixSubobject(new IPv4Prefix(new IPv4Address(new byte[] { (byte) 192,
// (byte) 168, 1, 8 }), 16), false));
// eroSubobjects.add(new EROIPPrefixSubobject(new IPv6Prefix(new IPv6Address(new byte[] { (byte) 192,
// (byte) 168, 2, 1,
// (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1 }), 64), false));
//
// serDeserTestWithoutBin(new PCEPSecondaryExplicitRouteObject(eroSubobjects, true, false));
// }
//
// @Test
// public void testSRRObject() throws PCEPDocumentedException, PCEPDeserializerException {
// final List rroSubobjects = new ArrayList();
// rroSubobjects.add(new RROIPAddressSubobject(new IPv4Prefix(this.ipv4addr, 16), true, false));
// rroSubobjects.add(new RROIPAddressSubobject(new IPv6Prefix(this.ipv6addr, 64), false, true));
//
// serDeserTestWithoutBin(new PCEPSecondaryRecordRouteObject(rroSubobjects, true, false));
// }
//
// @Test
// public void testP2MPEndpointsObjects() throws PCEPDeserializerException, PCEPDocumentedException {
// serDeserTestWithoutBin(new PCEPP2MPEndPointsObject(2, this.ipv4addr, Arrays.asList(this.ipv4addr,
// this.ipv4addr,
// this.ipv4addr), true, false));
// serDeserTestWithoutBin(new PCEPP2MPEndPointsObject(1, this.ipv4addr, Arrays.asList(this.ipv4addr),
// true, false));
// serDeserTestWithoutBin(new PCEPP2MPEndPointsObject(2, this.ipv6addr, Arrays.asList(this.ipv6addr,
// this.ipv6addr,
// this.ipv6addr), true, false));
// serDeserTestWithoutBin(new PCEPP2MPEndPointsObject(1, this.ipv6addr, Arrays.asList(this.ipv6addr),
// true, false));
// }
//
// @Test
// public void testUnreachedDestinationObjects() throws PCEPDeserializerException, PCEPDocumentedException {
// serDeserTestWithoutBin(new PCEPUnreachedDestinationObject(Arrays.asList(this.ipv4addr,
// this.ipv4addr, this.ipv4addr), true, false));
// serDeserTestWithoutBin(new PCEPUnreachedDestinationObject(Arrays.asList(this.ipv4addr), true,
// false));
// serDeserTestWithoutBin(new PCEPUnreachedDestinationObject(Arrays.asList(this.ipv6addr,
// this.ipv6addr, this.ipv6addr), true, false));
// serDeserTestWithoutBin(new PCEPUnreachedDestinationObject(Arrays.asList(this.ipv6addr), true,
// false));
// }
}