import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import com.google.common.collect.Lists;
+import com.google.common.primitives.UnsignedBytes;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
-import java.util.NoSuchElementException;
-
-import org.junit.Ignore;
+import org.junit.Before;
import org.junit.Test;
-
+import org.opendaylight.protocol.pcep.impl.TestVendorInformationTlvParser.TestEnterpriseSpecificInformation;
+import org.opendaylight.protocol.pcep.parser.BaseParserExtensionActivator;
+import org.opendaylight.protocol.pcep.parser.object.PCEPBandwidthObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPClassTypeObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPCloseObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPEndPointsIpv4ObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPEndPointsIpv6ObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPErrorObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPExcludeRouteObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPExistingBandwidthObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPExplicitRouteObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPGlobalConstraintsObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPIncludeRouteObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPLoadBalancingObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPLspaObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPMetricObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPMonitoringObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPNoPathObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPNotificationObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPObjectiveFunctionObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPOpenObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPOverloadObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPPathKeyObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPPccIdReqIPv4ObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPPccIdReqIPv6ObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPPceIdIPv4ObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPPceIdIPv6ObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPProcTimeObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPReportedRouteObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPRequestParameterObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.PCEPSvecObjectParser;
+import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.spi.PCEPErrors;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
+import org.opendaylight.protocol.pcep.spi.UnknownObject;
+import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
+import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext;
import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.protocol.concepts.ASNumber;
-import org.opendaylight.protocol.concepts.Bandwidth;
-import org.opendaylight.protocol.concepts.IGPMetric;
-import org.opendaylight.protocol.concepts.IPv4Address;
-import org.opendaylight.protocol.concepts.IPv4Prefix;
-import org.opendaylight.protocol.concepts.IPv6Address;
-import org.opendaylight.protocol.concepts.IPv6Prefix;
-import org.opendaylight.protocol.concepts.TEMetric;
-import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.PCEPErrors;
-import org.opendaylight.protocol.pcep.PCEPOFCodes;
-import org.opendaylight.protocol.pcep.PCEPObject;
-import org.opendaylight.protocol.pcep.PCEPTlv;
-import org.opendaylight.protocol.pcep.impl.object.PCEPClassTypeObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser.PCEPErrorIdentifier;
-import org.opendaylight.protocol.pcep.impl.object.UnknownObject;
-import org.opendaylight.protocol.pcep.object.PCEPBranchNodeListObject;
-import org.opendaylight.protocol.pcep.object.PCEPClassTypeObject;
-import org.opendaylight.protocol.pcep.object.PCEPCloseObject;
-import org.opendaylight.protocol.pcep.object.PCEPCloseObject.Reason;
-import org.opendaylight.protocol.pcep.object.PCEPEndPointsObject;
-import org.opendaylight.protocol.pcep.object.PCEPErrorObject;
-import org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject;
-import org.opendaylight.protocol.pcep.object.PCEPGlobalConstraintsObject;
-import org.opendaylight.protocol.pcep.object.PCEPIncludeRouteObject;
-import org.opendaylight.protocol.pcep.object.PCEPLoadBalancingObject;
-import org.opendaylight.protocol.pcep.object.PCEPLspObject;
-import org.opendaylight.protocol.pcep.object.PCEPLspaObject;
-import org.opendaylight.protocol.pcep.object.PCEPMetricObject;
-import org.opendaylight.protocol.pcep.object.PCEPNoPathObject;
-import org.opendaylight.protocol.pcep.object.PCEPNonBranchNodeListObject;
-import org.opendaylight.protocol.pcep.object.PCEPNotificationObject;
-import org.opendaylight.protocol.pcep.object.PCEPObjectiveFunctionObject;
-import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
-import org.opendaylight.protocol.pcep.object.PCEPP2MPEndPointsObject;
-import org.opendaylight.protocol.pcep.object.PCEPReportedRouteObject;
-import org.opendaylight.protocol.pcep.object.PCEPRequestParameterObject;
-import org.opendaylight.protocol.pcep.object.PCEPRequestedPathBandwidthObject;
-import org.opendaylight.protocol.pcep.object.PCEPSecondaryExplicitRouteObject;
-import org.opendaylight.protocol.pcep.object.PCEPSecondaryRecordRouteObject;
-import org.opendaylight.protocol.pcep.object.PCEPSvecObject;
-import org.opendaylight.protocol.pcep.object.PCEPUnreachedDestinationObject;
-import org.opendaylight.protocol.pcep.subobject.EROIPPrefixSubobject;
-import org.opendaylight.protocol.pcep.subobject.ExcludeRouteSubobject;
-import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject;
-import org.opendaylight.protocol.pcep.subobject.RROIPAddressSubobject;
-import org.opendaylight.protocol.pcep.subobject.ReportedRouteSubobject;
-import org.opendaylight.protocol.pcep.subobject.XROAsNumberSubobject;
-import org.opendaylight.protocol.pcep.subobject.XROIPPrefixSubobject;
-import org.opendaylight.protocol.pcep.subobject.XROSubobjectAttribute;
-import org.opendaylight.protocol.pcep.tlv.LSPStateDBVersionTlv;
-import org.opendaylight.protocol.pcep.tlv.NoPathVectorTlv;
-import org.opendaylight.protocol.pcep.tlv.NodeIdentifierTlv;
-import org.opendaylight.protocol.pcep.tlv.OrderTlv;
-import org.opendaylight.protocol.pcep.tlv.OverloadedDurationTlv;
-import org.opendaylight.protocol.pcep.tlv.PCEStatefulCapabilityTlv;
-
-/**
- * Used resources<br/>
- * <br/>
- * PCEPOpenObject3.bin<br/>
- * objClass: 1<br/>
- * objType: 1<br/>
- * objLength: 8<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * keepAlive: 30<br/>
- * deadTimer: 120<br/>
- * sessionId: 1<br/>
- * tlvs:NO<br/>
- * <br/>
- * PCEPBandwidthObject1LowerBounds.bin<br/>
- * objClass: 5 <br/>
- * objType: 1<br/>
- * objLength: 16<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * Bandwidth: 0<br/>
- * <br/>
- * PCEPBandwidthObject2UpperBounds.bin<br/>
- * objClass: 5 <br/>
- * objType: 1<br/>
- * objLength: 16<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * Bandwidth: 0xFFFFFFFF<br/>
- * <br/>
- * PCEPEndPointsObject1IPv4.bin<br/>
- * objClass: 4 <br/>
- * objType: 1<br/>
- * objLength: 12<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * src IP: 0xA2F5110E <br/>
- * dest IP: 0xFFFFFFFF <br/>
- * <br/>
- * PCEPEndPointsObject2IPv6.bin<br/>
- * objClass: 4 <br/>
- * objType: 2<br/>
- * objLength: 36<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * src IP: 0xFFFFFFFFF FFFFFFFFF FFFFFFFFF FFFFFFFFF<br/>
- * dest IP: 0x00025DD2 FFECA1B6 581E9F50 00000000 <br/>
- * <br/>
- * PCEPErrorObject1.bin<br/>
- * objClass: 13 (RP)<br/>
- * objType: 1<br/>
- * objLength: 8<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * Error-type: 1<br/>
- * Error-value: 1<br/>
- * Tlvs: NO<br/>
- * <br/>
- * PCEPErrorObject2Invalid.bin<br/>
- * objClass: 13 (RP)<br/>
- * objType: 1<br/>
- * objLength: 8<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * Error-type: 3<br/>
- * Error-value: 0<br/>
- * Tlvs: NO<br/>
- * <br/>
- * PCEPErrorObject3.bin<br/>
- * objClass: 13 (RP)<br/>
- * objType: 1<br/>
- * objLength: 8<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * Error-type: 2<br/>
- * Error-value: 0<br/>
- * Tlvs: NO<br/>
- * <br/>
- * PCEPLspaObject1LowerBounds.bin<br/>
- * objClass: 9<br/>
- * objType: 1<br/>
- * objLength: 20<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * Exclude-any: 0x00000000L<br/>
- * Include-any: 0x00000000L<br/>
- * Include-all: 0x00000000L<br/>
- * Setup Prio: 0x00<br/>
- * Holding Prio: 0x00<br/>
- * Flags: - L : false<br/>
- * <br/>
- * PCEPLspaObject2UpperBounds.bin<br/>
- * objClass: 9<br/>
- * objType: 1<br/>
- * objLength: 20<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * Exclude-any: 0xFFFFFFFFL<br/>
- * Include-any: 0xFFFFFFFFL<br/>
- * Include-all: 0xFFFFFFFFL<br/>
- * Setup Prio: 0xFF<br/>
- * Holding Prio: 0xFF<br/>
- * Flags: - L : true<br/>
- * <br/>
- * PCEPLspaObject3RandVals.bin<br/>
- * objClass: 9<br/>
- * objType: 1<br/>
- * objLength: 20<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * Exclude-any: 0x20A1FEE3L<br/>
- * Include-any: 0x1A025CC7L<br/>
- * Include-all: 0x2BB66532L<br/>
- * Setup Prio: 0x03<br/>
- * Holding Prio: 0x02<br/>
- * Flags: - L : true<br/>
- * <br/>
- * NoPathObject1WithTLV.bin<br/>
- * objClass: 3 (RP)<br/>
- * objType: 1<br/>
- * objLength: 16<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * Nature of Issue: 2<br/>
- * No-Path flags:<br/>
- * - C: true<br/>
- * <br/>
- * tlvs:<br/>
- * -- NO-PATH-VECTOR<br/>
- * - flags (0x4000):<br/>
- * - PCE currently unavailable: false<br/>
- * - unknown destination: true<br/>
- * - unknown source: false<br/>
- *
- * <br/>
- * NoPathObject2WithoutTLV.bin<br/>
- * objClass: 3 (RP)<br/>
- * objType: 1<br/>
- * objLength: 8<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: true<br/>
- * <br/>
- * Nature of Issue: 16<br/>
- * No-Path flags:<br/>
- * - C: false<br/>
- * <br/>
- * tlvs:NO<br/>
- * <br/>
- * PCEPNotificationObject1WithTlv.bin <br/>
- * objClass: 12<br/>
- * objType: 1<br/>
- * objLength: 16<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * NT: 1<br/>
- * NV: 1<br/>
- * Tlvs:<br/>
- * - OverloaderDuration(0xFF0000A2L)<br/>
- * <br/>
- * PCEPNotificationObject2WithoutTlv.bin <br/>
- * objClass: 12<br/>
- * objType: 1<br/>
- * objLength: 8<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * NT: 0xFF<br/>
- * NV: 0xFF<br/>
- * Tlvs: NO<br/>
- * <br/>
- * PCEPOpenObject1.bin<br/>
- * objClass: 1<br/>
- * objType: 1<br/>
- * objLength: 28<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * keepAlive: 30<br/>
- * deadTimer: 120<br/>
- * sessionId: 1<br/>
- * tlvs:<br/>
- * - PCEPStatefulCapability<br/>
- * - LSPStateDBVersionTlv<br/>
- * - NodeIdentifierTlv<br/>
- * <br/>
- * PCEPOpenObject2UpperBoundsNoTlv.bin<br/>
- * objClass: 1<br/>
- * objType: 1<br/>
- * objLength: 34<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * keepAlive: 0xFF<br/>
- * deadTimer: 0xFF<br/>
- * sessionId: 0xFF<br/>
- * tlvs: NO<br/>
- * <br/>
- * PCEPRPObject1.bin<br/>
- * objClass: 2 (RP)<br/>
- * objType: 1<br/>
- * objLength: 12<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * RP flags:<br/>
- * - loose/strict: true<br/>
- * - Bi-directional: false<br/>
- * - Reoptimization: false<br/>
- * - Priority: 5<br/>
- * Request ID: 0xDEADBEEF<br/>
- * tlvs: NO<br/>
- * <br/>
- * PCEPSvecObject1_10ReqIDs.bin <br/>
- * objClass: 11<br/>
- * objType: 1<br/>
- * objLength: 48<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: false<br/>
- * <br/>
- * Flags:<br/>
- * - Link diverse: true<br/>
- * - Node diverse: false<br/>
- * - SRLG diverse: true<br/>
- * Reques-ID-numbers:<br/>
- * #1 - 0xFFFFFFFFL<br/>
- * #2 - 0x00000000L<br/>
- * #3 - 0x01234567L<br/>
- * #4 - 0x89ABCDEFL<br/>
- * #5 - 0xFEDCBA98L<br/>
- * #6 - 0x76543210L<br/>
- * #7 - 0x15825266L<br/>
- * #8 - 0x48120BBEL<br/>
- * #9 - 0x25FB7E52L<br/>
- * #10 - 0xB2F2546BL<br/>
- * <br/>
- * PCEPSvecObject2.bin <br/>
- * objClass: 11<br/>
- * objType: 1<br/>
- * objLength: 08<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * Flags:<br/>
- * - Link diverse: false<br/>
- * - Node diverse: false<br/>
- * - SRLG diverse: false<br/>
- * Reques-ID-numbers:<br/>
- * #1 - 0x000000FFL<br/>
- * PCEPExcludeRouteObject.1.bin <br/>
- * objClass: 17 <br/>
- * objType: 1 <br/>
- * objLength: 20 <br/>
- * version: 1 <br/>
- * Flags: <br/>
- * - fail: true <br/>
- * Subobjects: <br/>
- * - XROIPv4PreffixSubobject(192.168.0.0/16, exclude, node) <br/>
- * - XROASnumber(0x1234) <br/>
- */
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.protocol.util.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
+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.network.concepts.rev131125.Bandwidth;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
+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.bandwidth.object.BandwidthBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassTypeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv4CaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv6CaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv6._case.Ipv6Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObjBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.XroBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.SubobjectBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.GcBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.IroBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.load.balancing.object.LoadBalancingBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.LspaBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.MetricBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring.Flags;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.MonitoringBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotificationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.OfBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.OrderBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.duration.tlv.OverloadDurationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.Overload;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.OverloadBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKeyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeys;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeysBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.setup.type.tlv.PathSetupTypeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReq;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReqBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceIdBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.error.object.TlvsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.NoPathBuilder;
+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;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTime;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTimeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.RroBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.req.missing.tlv.ReqMissingBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.RpBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.SvecBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObjectBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlvBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.as.number._case.AsNumberBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder;
public class PCEPObjectParserTest {
- 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 });
-
- @SuppressWarnings("unchecked")
- private static <T extends PCEPObject> void serDeserTest(final String srcFile, final T specObject) throws IOException,
- PCEPDeserializerException, PCEPDocumentedException {
- final byte[] bytesFromFile = ByteArray.fileToBytes(srcFile);
- final T deserSpecObj = (T) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
- final byte[] serSpecObj = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObject));
-
- assertEquals(specObject, deserSpecObj);
- assertArrayEquals(bytesFromFile, serSpecObj);
- }
-
- /**
- * Standard serialization test<br/>
- * Used resources:<br/>
- * - PCEPOpenObject1.bin<br/>
- *
- * @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 testLoadBalancingObjSerDeser() throws IOException, PCEPDeserializerException,
- PCEPDocumentedException {
- serDeserTest("src/test/resources/PCEPLoadBalancingObject1.bin", new PCEPLoadBalancingObject(0xF1,
- new Bandwidth(Float.intBitsToFloat(0xFFFFFFFF)), true));
- }
-
- @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");
-
- final PCEPExplicitRouteObject specObj = (PCEPExplicitRouteObject) 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 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 for upper/lower bounds (Serialization/Deserialization)<br/>
- * Used resources:<br/>
- * - PCEPBandwidthObject2UpperBounds.bin<br/>
- * - PCEPBandwidthObject1LowerBounds.bin<br/>
- *
- * @throws IOException
- * @throws PCEPDeserializerException
- * @throws PCEPDocumentedException
- */
- @Test
- public void testBandwidthObjectBounds() throws IOException, PCEPDeserializerException,
- PCEPDocumentedException {
- final byte[] bytesFloat = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
- serDeserTest("src/test/resources/PCEPBandwidthObject2UpperBounds.bin",
- new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.bytesToFloat(bytesFloat)), true,
- true));
- serDeserTest("src/test/resources/PCEPBandwidthObject1LowerBounds.bin",
- new PCEPRequestedPathBandwidthObject(new Bandwidth(0), true, true));
- }
-
- /**
- * Test for upper/lower bounds of IPv4 EndPoints
- * (Serialization/Deserialization)<br/>
- * Used resources:<br/>
- * - PCEPEndPointsObject1IPv4.bin<br/>
- *
- * @throws IOException
- * @throws PCEPDeserializerException
- * @throws PCEPDocumentedException
- */
- @Test
- public void testEndPointsObjectSerDeserIPv4() 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 };
- serDeserTest("src/test/resources/PCEPEndPointsObject1IPv4.bin", new PCEPEndPointsObject<IPv4Address>(
- new IPv4Address(srcIPBytes), new IPv4Address(destIPBytes)));
- }
-
- /**
- * Test for upper/lower bounds of IPv6 EndPoints
- * (Serialization/Deserialization)<br/>
- * Used resources:<br/>
- * - PCEPEndPointsObject2IPv6.bin<br/>
- *
- * @throws IOException
- * @throws PCEPDeserializerException
- * @throws PCEPDocumentedException
- */
- @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 };
-
- serDeserTest("src/test/resources/PCEPEndPointsObject2IPv6.bin", new PCEPEndPointsObject<IPv6Address>(
- new IPv6Address(srcIPBytes), new IPv6Address(destIPBytes)));
- }
-
- /**
- * Test of Serialization/Deserialization of PCEPErrorObjectParser.<br/>
- * <br/>
- * Used resources:<br/>
- * - PCEPErrorObject1.bin<br/>
- * - PCEPErrorObject3.bin<br/>
- *
- * @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.<br/>
- * <br/>
- * Used resources:<br/>
- * - PCEPErrorObject2Invalid.bin<br/>
- *
- * @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)<br/>
- * Used resources:<br/>
- * - PCEPLspaObject1LowerBounds.bin<br/>
- * - PCEPLspaObject2UpperBounds.bin<br/>
- * - PCEPLspaObject3RandVals.bin<br/>
- *
- * @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 testMetricObjectSerDeserBounds() throws IOException, PCEPDeserializerException,
- PCEPDocumentedException {
- final byte[] bytesFromFileUB = ByteArray
- .fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin");
- final byte[] bytesFromFileLB = ByteArray
- .fileToBytes("src/test/resources/PCEPMetricObject1LowerBounds.bin");
-
- final PCEPMetricObject metricObjectLB = (PCEPMetricObject) PCEPObjectFactory.parseObjects(
- bytesFromFileLB).get(0);
- final PCEPMetricObject metricObjectUB = (PCEPMetricObject) PCEPObjectFactory.parseObjects(
- bytesFromFileUB).get(0);
-
- assertEquals(new PCEPMetricObject(false, false, new IGPMetric(0), true, true), metricObjectLB);
- assertEquals(new PCEPMetricObject(false, true, new TEMetric(4026531840L), true, true), metricObjectUB);
-
- final byte[] bytesActualLB = PCEPObjectFactory.put(Arrays.asList((PCEPObject) metricObjectLB));
- final byte[] bytesActualUB = PCEPObjectFactory.put(Arrays.asList((PCEPObject) metricObjectUB));
- assertArrayEquals(bytesFromFileLB, bytesActualLB);
- assertArrayEquals(bytesFromFileUB, bytesActualUB);
- }
-
- /**
- * Standard deserialization test + specific test without tlv<br/>
- * Used resources:<br/>
- * - NoPathObject1WithTLV.bin<br/>
- * - NoPathObject2WithoutTLV.bin<br/>
- *
- * @throws PCEPDeserializerException
- * @throws IOException
- * @throws PCEPDocumentedException
- */
- @Test
- public void testNoPathObjectDeserialization() throws PCEPDeserializerException, IOException,
- PCEPDocumentedException {
- final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>(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<br/>
- * Used resources:<br/>
- * - NoPathObject1WithTLV.bin<br/>
- * - NoPathObject2WithoutTLV.bin<br/>
- *
- * @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)<br/>
- * Used resources:<br/>
- * - PCEPNotificationObject1WithTlv.bin -
- * PCEPNotificationObject2WithoutTlv.bin
- *
- * @throws PCEPDeserializerException
- * @throws IOException
- * @throws PCEPDocumentedException
- */
- @Test
- public void testNotifyObjectSerDeserWithTlv() throws PCEPDeserializerException, IOException,
- PCEPDocumentedException {
- final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>(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<br/>
- * used resources:<br/>
- * - PCEPOpenObject1.bin
- *
- * @throws PCEPDeserializerException
- * @throws IOException
- * @throws PCEPDocumentedException
- */
- @Test
- @Ignore //FIXME: temporary
- public void testOpenObjectSerDeser() throws PCEPDeserializerException, IOException,
- PCEPDocumentedException {
- final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>();
- 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<br/>
- * Used resources:<br/>
- * - PCEPOpenObject2UpperBoundsNoTlv.bin
- *
- * @throws PCEPDeserializerException
- * @throws IOException
- * @throws PCEPDocumentedException
- */
- @Test
- public void testOpenObjectBoundsWithoutTlvs() throws IOException, PCEPDeserializerException,
- PCEPDocumentedException {
- final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>();
- 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<br/>
- * Used resources:<br/>
- * - 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<PCEPTlv>() {
- private static final long serialVersionUID = 1L;
-
- {
- this.add(new OrderTlv(0xFFFFFFFFL, 0x00000001L));
- }
- }, false, false));
- }
-
- /**
- * Test for upper/lower bounds of PCEPSvecObject
- * (Serialization/Deserialization)<br/>
- * Used resources:<br/>
- * - PCEPSvecObject1_10ReqIDs.bin<br/>
- *
- * @throws IOException
- * @throws PCEPDeserializerException
- * @throws PCEPDocumentedException
- */
- @Test
- public void testSvecObjectSerDeser() throws IOException, PCEPDeserializerException,
- PCEPDocumentedException {
- final List<Long> requestIDs = new ArrayList<Long>(10);
- requestIDs.add(0xFFFFFFFFL);
- requestIDs.add(0x00000000L);
- requestIDs.add(0x01234567L);
- requestIDs.add(0x89ABCDEFL);
- requestIDs.add(0xFEDCBA98L);
- requestIDs.add(0x76543210L);
- requestIDs.add(0x15825266L);
- requestIDs.add(0x48120BBEL);
- requestIDs.add(0x25FB7E52L);
- requestIDs.add(0xB2F2546BL);
-
- serDeserTest("src/test/resources/PCEPSvecObject1_10ReqIDs.bin", new PCEPSvecObject(true, false, true,
- false, true, requestIDs, true));
- }
-
- /**
- * Test for lowest bounds of PCEPSvecObject (Serialization/Deserialization)<br/>
- * Used resources:<br/>
- * - PCEPSvecObject2.bin<br/>
- *
- * @throws IOException
- * @throws PCEPDeserializerException
- * @throws PCEPDocumentedException
- */
- @Test
- public void testSvecObjectSerDeserNoReqIDs() throws IOException, PCEPDeserializerException,
- PCEPDocumentedException {
- final List<Long> requestIDs = new ArrayList<Long>();
- requestIDs.add(0xFFL);
- serDeserTest("src/test/resources/PCEPSvecObject2.bin", new PCEPSvecObject(false, false, false, false,
- false, requestIDs, false));
- }
-
- @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)<br/>
- * Used resources:<br/>
- * - PCEPExcludeRouteObject.1.bin<br/>
- *
- * @throws IOException
- * @throws PCEPDeserializerException
- * @throws PCEPDocumentedException
- */
- @Test
- public void testExcludeRouteObject() throws IOException, PCEPDeserializerException,
- PCEPDocumentedException {
- final List<ExcludeRouteSubobject> xroSubobjects = new ArrayList<ExcludeRouteSubobject>();
- xroSubobjects.add(new XROIPPrefixSubobject<IPv4Prefix>(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<PCEPObject> objs = new ArrayList<PCEPObject>();
- final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>();
- 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 <T extends PCEPObject> 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);
- }
-
- /*
- * tests without the need of binary files
- */
- @Test
- public void testBranchNodeObjects() throws PCEPDocumentedException, PCEPDeserializerException {
- final List<ExplicitRouteSubobject> eroSubobjects = new ArrayList<ExplicitRouteSubobject>();
- eroSubobjects.add(new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new IPv4Address(new byte[] {
- (byte) 192, (byte) 168, 1, 8 }), 16), false));
- eroSubobjects.add(new EROIPPrefixSubobject<IPv6Prefix>(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 PCEPBranchNodeListObject(eroSubobjects, true, false));
- serDeserTestWithoutBin(new PCEPNonBranchNodeListObject(eroSubobjects, true, false));
-
- }
-
- @Test
- public void testSERObjects() throws PCEPDocumentedException, PCEPDeserializerException {
- final List<ExplicitRouteSubobject> eroSubobjects = new ArrayList<ExplicitRouteSubobject>();
- eroSubobjects.add(new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new IPv4Address(new byte[] {
- (byte) 192, (byte) 168, 1, 8 }), 16), false));
- eroSubobjects.add(new EROIPPrefixSubobject<IPv6Prefix>(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<ReportedRouteSubobject> rroSubobjects = new ArrayList<ReportedRouteSubobject>();
- rroSubobjects.add(new RROIPAddressSubobject<IPv4Prefix>(new IPv4Prefix(this.ipv4addr, 16), true,
- false));
- rroSubobjects.add(new RROIPAddressSubobject<IPv6Prefix>(new IPv6Prefix(this.ipv6addr, 64), false,
- true));
-
- serDeserTestWithoutBin(new PCEPSecondaryRecordRouteObject(rroSubobjects, true, false));
- }
-
- @Test
- public void testP2MPEndpointsObjects() throws PCEPDeserializerException, PCEPDocumentedException {
- serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv4Address>(2, this.ipv4addr, Arrays.asList(
- this.ipv4addr, this.ipv4addr, this.ipv4addr), true, false));
- serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv4Address>(1, this.ipv4addr,
- Arrays.asList(this.ipv4addr), true, false));
- serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv6Address>(2, this.ipv6addr, Arrays.asList(
- this.ipv6addr, this.ipv6addr, this.ipv6addr), true, false));
- serDeserTestWithoutBin(new PCEPP2MPEndPointsObject<IPv6Address>(1, this.ipv6addr,
- Arrays.asList(this.ipv6addr), true, false));
- }
-
- @Test
- public void testUnreachedDestinationObjects() throws PCEPDeserializerException, PCEPDocumentedException {
- serDeserTestWithoutBin(new PCEPUnreachedDestinationObject<IPv4Address>(Arrays.asList(this.ipv4addr,
- this.ipv4addr, this.ipv4addr), true, false));
- serDeserTestWithoutBin(new PCEPUnreachedDestinationObject<IPv4Address>(Arrays.asList(this.ipv4addr),
- true, false));
- serDeserTestWithoutBin(new PCEPUnreachedDestinationObject<IPv6Address>(Arrays.asList(this.ipv6addr,
- this.ipv6addr, this.ipv6addr), true, false));
- serDeserTestWithoutBin(new PCEPUnreachedDestinationObject<IPv6Address>(Arrays.asList(this.ipv6addr),
- true, false));
- }
+ private TlvRegistry tlvRegistry;
+
+ private VendorInformationTlvRegistry viTlvRegistry;
+
+ private SimplePCEPExtensionProviderContext ctx;
+ private BaseParserExtensionActivator act;
+ private TestVendorInformationActivator viAct;
+
+ @Before
+ public void setUp() {
+ this.ctx = new SimplePCEPExtensionProviderContext();
+ this.act = new BaseParserExtensionActivator();
+ this.viAct = new TestVendorInformationActivator();
+ this.act.start(this.ctx);
+ this.viAct.start(this.ctx);
+ this.tlvRegistry = this.ctx.getTlvHandlerRegistry();
+ this.viTlvRegistry = this.ctx.getVendorInformationTlvRegistry();
+ }
+
+ @Test
+ public void testOpenObjectWOTLV() throws PCEPDeserializerException, IOException {
+ final PCEPOpenObjectParser parser = new PCEPOpenObjectParser(this.tlvRegistry, this.viTlvRegistry);
+ final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPOpenObject1.bin"));
+
+ final OpenBuilder builder = new OpenBuilder();
+ builder.setProcessingRule(false);
+ builder.setIgnore(false);
+ builder.setVersion(new ProtocolVersion((short) 1));
+ builder.setKeepalive((short) 30);
+ builder.setDeadTimer((short) 120);
+ builder.setSessionId((short) 1);
+
+ builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder().build());
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+ final ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testCloseObject() throws IOException, PCEPDeserializerException {
+ final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
+ final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPCloseObject1.bin"));
+
+ final CCloseBuilder builder = new CCloseBuilder();
+ builder.setProcessingRule(false);
+ builder.setIgnore(false);
+ builder.setReason((short) 5);
+ builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.c.close.TlvsBuilder().build());
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+ final ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testLoadBalancingObject() throws IOException, PCEPDeserializerException {
+ final PCEPLoadBalancingObjectParser parser = new PCEPLoadBalancingObjectParser();
+ final ByteBuf result = Unpooled.wrappedBuffer(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 Bandwidth(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
+ final ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testERObject() throws Exception {
+ final PCEPExplicitRouteObjectParser parser = new PCEPExplicitRouteObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
+ final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin"));
+
+ final EroBuilder builder = new EroBuilder();
+ builder.setProcessingRule(false);
+ builder.setIgnore(false);
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject> subs = Lists.newArrayList();
+ subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder().setLoose(
+ true).setSubobjectType(
+ new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0xffffL)).build()).build()).build());
+ subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder().setLoose(
+ true).setSubobjectType(
+ new IpPrefixCaseBuilder().setIpPrefix(
+ new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/32"))).build()).build()).build());
+ subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder().setLoose(
+ true).setSubobjectType(
+ new UnnumberedCaseBuilder().setUnnumbered(
+ new UnnumberedBuilder().setRouterId(0xffffffffL).setInterfaceId(0xffffffffL).build()).build()).build());
+ builder.setSubobject(subs);
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+ final ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testIRObject() throws Exception {
+ final PCEPIncludeRouteObjectParser parser = new PCEPIncludeRouteObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
+ final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPIncludeRouteObject1PackOfSubobjects.bin"));
+ final byte[] ip6PrefixBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
+
+ final IroBuilder builder = new IroBuilder();
+ builder.setProcessingRule(false);
+ builder.setIgnore(false);
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.Subobject> subs = Lists.newArrayList();
+ subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
+ new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x10L)).build()).build()).setLoose(true).build());
+ subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
+ new IpPrefixCaseBuilder().setIpPrefix(
+ new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("18.52.80.0/21"))).build()).build()).setLoose(true).build());
+ subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
+ new IpPrefixCaseBuilder().setIpPrefix(
+ new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(ip6PrefixBytes, 22))).build()).build()).setLoose(true).build());
+ subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.iro.SubobjectBuilder().setSubobjectType(
+ new UnnumberedCaseBuilder().setUnnumbered(
+ new UnnumberedBuilder().setRouterId(0x1245678L).setInterfaceId(0x9abcdef0L).build()).build()).setLoose(true).build());
+ builder.setSubobject(subs);
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+ final ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testRRObject() throws Exception {
+ final PCEPReportedRouteObjectParser parser = new PCEPReportedRouteObjectParser(this.ctx.getRROSubobjectHandlerRegistry());
+ final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPReportedRouteObject1PackOfSubobjects.bin"));
+ final byte[] ip6PrefixBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
+
+ final RroBuilder builder = new RroBuilder();
+ builder.setProcessingRule(false);
+ builder.setIgnore(false);
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.Subobject> subs = Lists.newArrayList();
+ subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder().setSubobjectType(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder().setIpPrefix(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder().setIpPrefix(
+ new IpPrefix(new Ipv4Prefix("255.255.255.255/32"))).build()).build()).setProtectionAvailable(false).setProtectionInUse(
+ false).build());
+ subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder().setSubobjectType(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder().setIpPrefix(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder().setIpPrefix(
+ new IpPrefix(Ipv6Util.prefixForBytes(ip6PrefixBytes, 22))).build()).build()).setProtectionAvailable(false).setProtectionInUse(
+ false).build());
+ subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder().setSubobjectType(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.UnnumberedCaseBuilder().setUnnumbered(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder().setRouterId(
+ 0x1245678L).setInterfaceId(0x9abcdef0L).build()).build()).setProtectionAvailable(false).setProtectionInUse(
+ false).build());
+ builder.setSubobject(subs);
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+ final ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testBandwidthObject() throws IOException, PCEPDeserializerException {
+ final PCEPBandwidthObjectParser parser = new PCEPBandwidthObjectParser();
+ final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject1LowerBounds.bin"));
+
+ final BandwidthBuilder builder = new BandwidthBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(true);
+ builder.setBandwidth(new Bandwidth(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
+ final ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testExistingBandwidthObject() throws IOException, PCEPDeserializerException {
+ final PCEPExistingBandwidthObjectParser parser = new PCEPExistingBandwidthObjectParser();
+ final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject2UpperBounds.bin"));
+
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization
+ .bandwidth.object.ReoptimizationBandwidthBuilder builder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml
+ .ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidthBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(true);
+ builder.setBandwidth(new Bandwidth(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
+ final ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testEndPointsObjectIPv4() throws IOException, PCEPDeserializerException {
+ final byte[] srcIPBytes = { (byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E };
+ final byte[] destIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
+
+ final PCEPEndPointsIpv4ObjectParser parser = new PCEPEndPointsIpv4ObjectParser();
+ final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject1IPv4.bin"));
+
+ final EndpointsObjBuilder builder = new EndpointsObjBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(false);
+ builder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(
+ new Ipv4Builder().setSourceIpv4Address(Ipv4Util.noZoneAddressForByteBuf(Unpooled.wrappedBuffer(srcIPBytes))).setDestinationIpv4Address(
+ Ipv4Util.noZoneAddressForByteBuf(Unpooled.wrappedBuffer(destIPBytes))).build()).build());
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
+ final ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testEndPointsObjectIPv6() throws IOException, PCEPDeserializerException {
+ 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 PCEPEndPointsIpv6ObjectParser parser = new PCEPEndPointsIpv6ObjectParser();
+ final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject2IPv6.bin"));
+
+ final EndpointsObjBuilder builder = new EndpointsObjBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(false);
+ builder.setAddressFamily(new Ipv6CaseBuilder().setIpv6(
+ new Ipv6Builder().setSourceIpv6Address(Ipv6Util.noZoneAddressForByteBuf(Unpooled.wrappedBuffer(srcIPBytes))).setDestinationIpv6Address(
+ Ipv6Util.noZoneAddressForByteBuf(Unpooled.wrappedBuffer(destIPBytes))).build()).build());
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
+ final ByteBuf buf = Unpooled.buffer();
+ PCEPEndPointsIpv6ObjectParser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testErrorObjectWithTlv() throws PCEPDeserializerException, IOException {
+ final PCEPErrorObjectParser parser = new PCEPErrorObjectParser(this.tlvRegistry, this.viTlvRegistry);
+ ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject1.bin"));
+
+ final ErrorObjectBuilder builder = new ErrorObjectBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(true);
+ builder.setType((short) 1);
+ builder.setValue((short) 1);
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
+ ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject3.bin"));
+
+ builder.setType((short) 7);
+ builder.setValue((short) 0);
+ builder.setTlvs(new TlvsBuilder().setReqMissing(new ReqMissingBuilder().setRequestId(new RequestId(0x00001155L)).build()).build());
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
+ buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testLspaObject() throws IOException, PCEPDeserializerException {
+ final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry, this.viTlvRegistry);
+ ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin"));
+
+ final LspaBuilder builder = new LspaBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(true);
+ builder.setExcludeAny(new AttributeFilter(0L));
+ builder.setIncludeAny(new AttributeFilter(0L));
+ builder.setIncludeAll(new AttributeFilter(0L));
+ builder.setHoldPriority((short) 0);
+ builder.setSetupPriority((short) 0);
+ builder.setLocalProtectionDesired(false);
+ builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.lspa.TlvsBuilder().build());
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
+ ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject2UpperBounds.bin"));
+
+ builder.setExcludeAny(new AttributeFilter(0xFFFFFFFFL));
+ builder.setIncludeAny(new AttributeFilter(0xFFFFFFFFL));
+ builder.setIncludeAll(new AttributeFilter(0xFFFFFFFFL));
+ builder.setHoldPriority((short) 0xFF);
+ builder.setSetupPriority((short) 0xFF);
+ builder.setLocalProtectionDesired(true);
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
+ buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testMetricObject() throws IOException, PCEPDeserializerException {
+ final PCEPMetricObjectParser parser = new PCEPMetricObjectParser();
+ ByteBuf result = Unpooled.wrappedBuffer(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.slice(4, result.readableBytes() - 4)));
+ ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ result = Unpooled.wrappedBuffer(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.slice(4, result.readableBytes() - 4)));
+ buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testNoPathObjectWithTlv() throws PCEPDeserializerException, IOException {
+ final PCEPNoPathObjectParser parser = new PCEPNoPathObjectParser(this.tlvRegistry, this.viTlvRegistry);
+ ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNoPathObject1WithoutTLV.bin"));
+
+ final NoPathBuilder builder = new NoPathBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(true);
+ builder.setNatureOfIssue((short) 1);
+ builder.setUnsatisfiedConstraints(true);
+ builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.no.path.TlvsBuilder().build());
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
+ ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNoPathObject2WithTLV.bin"));
+
+ builder.setNatureOfIssue((short) 0);
+ builder.setUnsatisfiedConstraints(false);
+
+ final NoPathVectorBuilder b = new NoPathVectorBuilder();
+ b.setFlags(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));
+ builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.no.path.TlvsBuilder().setNoPathVector(
+ b.build()).build());
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
+ buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testNotifyObjectWithTlv() throws PCEPDeserializerException, IOException {
+ final PCEPNotificationObjectParser parser = new PCEPNotificationObjectParser(this.tlvRegistry, this.viTlvRegistry);
+ ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNotificationObject2WithoutTlv.bin"));
+
+ final CNotificationBuilder builder = new CNotificationBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(true);
+ builder.setType((short) 0xff);
+ builder.setValue((short) 0xff);
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
+ ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+
+ result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPNotificationObject1WithTlv.bin"));
+
+ builder.setType((short) 2);
+ builder.setValue((short) 1);
+ builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.c.notification.TlvsBuilder().setOverloadDuration(
+ new OverloadDurationBuilder().setDuration(0xff0000a2L).build()).build());
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
+ buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testRPObjectWithTlv() throws PCEPDeserializerException, IOException {
+ final PCEPRequestParameterObjectParser parser = new PCEPRequestParameterObjectParser(this.tlvRegistry, this.viTlvRegistry);
+ ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRPObject1.bin"));
+
+ final RpBuilder builder = new RpBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(true);
+ builder.setReoptimization(true);
+ builder.setBiDirectional(false);
+ builder.setLoose(true);
+ builder.setMakeBeforeBreak(true);
+ builder.setOrder(false);
+ builder.setPathKey(false);
+ builder.setSupplyOf(false);
+ builder.setFragmentation(false);
+ builder.setP2mp(false);
+ builder.setEroCompression(false);
+ builder.setPriority((short) 5);
+ builder.setRequestId(new RequestId(0xdeadbeefL));
+ builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().build());
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
+ ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
+
+ result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRPObject2.bin"));
+
+ builder.setReoptimization(false);
+ builder.setFragmentation(true);
+ builder.setEroCompression(true);
+
+ final OrderBuilder b = new OrderBuilder();
+ b.setDelete(0xffffffffL);
+ b.setSetup(1L);
+
+ builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().setOrder(
+ b.build()).build());
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
+ buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testSvecObject() throws IOException, PCEPDeserializerException {
+ final PCEPSvecObjectParser parser = new PCEPSvecObjectParser();
+ ByteBuf result = Unpooled.wrappedBuffer(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.slice(4, result.readableBytes() - 4)));
+ ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPSvecObject1_10ReqIDs.bin"));
+
+ builder.setProcessingRule(true);
+ builder.setLinkDiverse(true);
+ builder.setSrlgDiverse(true);
+
+ final List<RequestId> requestIDs = Lists.newArrayList();
+ requestIDs.add(new RequestId(0xFFFFFFFFL));
+ requestIDs.add(new RequestId(0x00000001L));
+ 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.slice(4, result.readableBytes() - 4)));
+ buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testClassTypeObject() throws PCEPDeserializerException {
+ final PCEPClassTypeObjectParser parser = new PCEPClassTypeObjectParser();
+ final ByteBuf result = Unpooled.wrappedBuffer(new byte[] { (byte) 0x16, (byte) 0x12, (byte) 0x00, (byte) 0x08, 0, 0, 0, (byte) 0x04 });
+
+ final ClassTypeBuilder builder = new ClassTypeBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(false);
+ builder.setClassType(new ClassType((short) 4));
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
+ final ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testExcludeRouteObject() throws Exception {
+ final PCEPExcludeRouteObjectParser parser = new PCEPExcludeRouteObjectParser(this.ctx.getXROSubobjectHandlerRegistry());
+ final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPExcludeRouteObject.1.bin"));
+
+ final XroBuilder builder = new XroBuilder();
+ builder.setProcessingRule(false);
+ builder.setIgnore(false);
+ builder.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Xro.Flags(true));
+ final List<Subobject> subs = Lists.newArrayList();
+ subs.add(new SubobjectBuilder().setMandatory(true).setSubobjectType(
+ new IpPrefixCaseBuilder().setIpPrefix(
+ new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("192.168.0.0/16"))).build()).build()).setAttribute(
+ Attribute.Node).build());
+ subs.add(new SubobjectBuilder().setMandatory(false).setSubobjectType(
+ new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x1234L)).build()).build()).build());
+ builder.setSubobject(subs);
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+ final ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testPathKeyObject() throws Exception {
+ final PCEPPathKeyObjectParser parser = new PCEPPathKeyObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
+ final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPPathKeyObject.bin"));
+
+ final PathKeyBuilder builder = new PathKeyBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(false);
+ final List<PathKeys> list = Lists.newArrayList();
+ list.add(new PathKeysBuilder().setLoose(true).setPathKey(new PathKey(0x1234)).setPceId(
+ new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 })).build());
+ builder.setPathKeys(list);
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
+ final ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testObjectiveFunctionObject() throws IOException, PCEPDeserializerException {
+ final PCEPObjectiveFunctionObjectParser parser = new PCEPObjectiveFunctionObjectParser(this.tlvRegistry, this.viTlvRegistry);
+ final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPObjectiveFunctionObject.1.bin"));
+
+ final OfBuilder builder = new OfBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(false);
+ builder.setCode(new OfId(4));
+ builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.of.TlvsBuilder().build());
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
+ final ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testGlobalConstraintsObject() throws IOException, PCEPDeserializerException {
+ final PCEPGlobalConstraintsObjectParser parser = new PCEPGlobalConstraintsObjectParser(this.tlvRegistry, this.viTlvRegistry);
+ final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPGlobalConstraintsObject.1.bin"));
+
+ final GcBuilder builder = new GcBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(false);
+ builder.setMaxHop((short) 1);
+ builder.setMaxUtilization((short) 0);
+ builder.setMinUtilization((short) 100);
+ builder.setOverBookingFactor((short) 99);
+ builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.gc.TlvsBuilder().build());
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
+ final ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testIgnoreUknownObject() throws PCEPDeserializerException {
+ final Object object = this.ctx.getObjectHandlerRegistry().parseObject(35, 1, new ObjectHeaderImpl(false, false), null);
+ assertNull(object);
+ }
+
+ @Test
+ public void testUnrecognizedObjectType() throws PCEPDeserializerException {
+ final Object object = this.ctx.getObjectHandlerRegistry().parseObject(2, 2, new ObjectHeaderImpl(true, true), null);
+ assertNotNull(object);
+ assertTrue(object instanceof UnknownObject);
+ assertEquals(PCEPErrors.UNRECOGNIZED_OBJ_TYPE, ((UnknownObject) object).getError());
+ }
+
+ @Test
+ public void testUnrecognizedObjectClass() throws PCEPDeserializerException {
+ final Object object = this.ctx.getObjectHandlerRegistry().parseObject(35, 1, new ObjectHeaderImpl(true, true), null);
+ assertNotNull(object);
+ assertTrue(object instanceof UnknownObject);
+ assertEquals(PCEPErrors.UNRECOGNIZED_OBJ_CLASS, ((UnknownObject) object).getError());
+ }
+
+ @Test
+ public void testLspaObjectSerializerDefence() throws IOException, PCEPDeserializerException {
+ final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry, this.viTlvRegistry);
+ final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin"));
+
+ final LspaBuilder builder = new LspaBuilder();
+ builder.setProcessingRule(true);
+ builder.setIgnore(true);
+ builder.setLocalProtectionDesired(false);
+
+ final ByteBuf buf = Unpooled.buffer(result.readableBytes());
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+ }
+
+ @Test
+ public void testEmptyEroObject() throws PCEPDeserializerException {
+ final Object object = this.ctx.getObjectHandlerRegistry().parseObject(PCEPExplicitRouteObjectParser.CLASS, PCEPExplicitRouteObjectParser.TYPE, new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
+ assertNotNull(object);
+ assertTrue(object instanceof Ero);
+ final Ero eroObject = (Ero) object;
+ assertTrue(eroObject.getSubobject().isEmpty());
+
+ final ByteBuf buffer = Unpooled.buffer();
+ this.ctx.getObjectHandlerRegistry().serializeObject(eroObject, buffer);
+ final byte[] expected = {0x07, 0x13, 0x00, 0x04};
+ assertArrayEquals(expected, ByteArray.getAllBytes(buffer));
+ }
+
+ @Test
+ public void testCloseObjectWithVendorInformationTlv() throws IOException, PCEPDeserializerException {
+ final byte[] closeBytes = {
+ 0x0f, 0x10, 0x00, 0x14,
+ 0x00, 0x00, 0x00, 0x05,
+ /* vendor-information TLV */
+ 0x00, 0x07, 0x00, 0x08,
+ /* enterprise number */
+ 0x00, 0x00, 0x00, 0x00,
+ /* enterprise specific information */
+ 0x00, 0x00, 0x00, 0x05
+ };
+ final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
+ final ByteBuf result = Unpooled.wrappedBuffer(closeBytes);
+
+ final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
+ final VendorInformationTlv viTlv = new VendorInformationTlvBuilder().setEnterpriseNumber(new EnterpriseNumber(0L))
+ .setEnterpriseSpecificInformation(esInfo).build();
+ final CCloseBuilder builder = new CCloseBuilder();
+ builder.setProcessingRule(false);
+ builder.setIgnore(false);
+ builder.setReason((short) 5);
+ builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.c.close.TlvsBuilder()
+ .setVendorInformationTlv(Lists.newArrayList(viTlv)).build());
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+
+ final ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+ }
+
+ @Test
+ public void testVendorInformationObject() throws PCEPDeserializerException {
+ final byte[] viObjBytes = {
+ /* vendor-information object */
+ 0x22, 0x10, 0x00, 0x0C,
+ /* enterprise number */
+ 0x00, 0x00, 0x00, 0x00,
+ /* enterprise specific information */
+ 0x00, 0x00, 0x00, 0x05
+ };
+ final TestVendorInformationObjectParser parser = new TestVendorInformationObjectParser();
+ final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
+ final VendorInformationObject viObj = new VendorInformationObjectBuilder().setEnterpriseNumber(new EnterpriseNumber(0L))
+ .setEnterpriseSpecificInformation(esInfo).build();
+ final ByteBuf result = Unpooled.wrappedBuffer(viObjBytes);
+ result.readerIndex(8);
+ final VendorInformationObject o = (VendorInformationObject) parser.parseObject(new ObjectHeaderImpl(false, false), result.readSlice(result.readableBytes()));
+ assertEquals(viObj, o);
+
+ final ByteBuf buf = Unpooled.buffer(viObjBytes.length);
+ parser.serializeObject(viObj, buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+ }
+
+ @Test
+ public void testMonitoringObject() throws PCEPDeserializerException {
+ final byte[] monitoringBytes = {
+ /* object header */
+ 0x13, 0x10, 0x00, 0x0C,
+ /* flags */
+ 0x00, 0x00, 0x00, 0x01,
+ /* monitoring-id=16 */
+ 0x00, 0x00, 0x00, 0x10
+ };
+ final PCEPMonitoringObjectParser parser = new PCEPMonitoringObjectParser(this.tlvRegistry, this.viTlvRegistry);
+ final Monitoring monitoring = new MonitoringBuilder().setMonitoringId(16L).setFlags(new Flags(false, false, true, false, false)).setTlvs(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.monitoring.TlvsBuilder().build()).build();
+ final ByteBuf result = Unpooled.wrappedBuffer(monitoringBytes);
+ assertEquals(monitoring, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+
+ final ByteBuf buf = Unpooled.buffer(monitoringBytes.length);
+ parser.serializeObject(monitoring, buf);
+ assertArrayEquals(monitoringBytes, buf.array());
+ }
+
+ @Test
+ public void testPccIdReqIPv4Object() throws PCEPDeserializerException {
+ final byte[] pccIdReqBytes = {
+ /* object header */
+ 0x14, 0x10, 0x00, 0x08,
+ /* ipv4 address */
+ 0x7f, 0x00, 0x00, 0x01
+ };
+ final PCEPPccIdReqIPv4ObjectParser parser = new PCEPPccIdReqIPv4ObjectParser();
+ final PccIdReq pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddressNoZone(new Ipv4AddressNoZone("127.0.0.1"))).build();
+ final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
+ assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+
+ final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
+ parser.serializeObject(pccIdReq, buf);
+ assertArrayEquals(pccIdReqBytes, buf.array());
+ }
+
+ @Test
+ public void testPccIdReqIPv6Object() throws PCEPDeserializerException {
+ final byte[] pccIdReqBytes = {
+ /* object header */
+ 0x14, 0x20, 0x00, 0x14,
+ /* ipv6 address */
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x01
+ };
+ final PCEPPccIdReqIPv6ObjectParser parser = new PCEPPccIdReqIPv6ObjectParser();
+ final PccIdReq pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddressNoZone(new Ipv6AddressNoZone("::1"))).build();
+ final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
+ assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+
+ final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
+ parser.serializeObject(pccIdReq, buf);
+ assertArrayEquals(pccIdReqBytes, buf.array());
+ }
+
+ @Test
+ public void testPceIdIPv4Object() throws PCEPDeserializerException {
+ final byte[] pccIdReqBytes = {
+ /* object header */
+ 0x19, 0x10, 0x00, 0x08,
+ /* ipv4 address */
+ 0x7f, 0x00, 0x00, 0x01
+ };
+ final PCEPPceIdIPv4ObjectParser parser = new PCEPPceIdIPv4ObjectParser();
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId pceId = new PceIdBuilder().setIpAddress(new IpAddressNoZone(
+ new Ipv4AddressNoZone("127.0.0.1"))).build();
+ final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
+ assertEquals(pceId, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+
+ final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
+ parser.serializeObject(pceId, buf);
+ assertArrayEquals(pccIdReqBytes, buf.array());
+ }
+
+ @Test
+ public void testPceIdIPv6Object() throws PCEPDeserializerException {
+ final byte[] pccIdReqBytes = {
+ /* object header */
+ 0x19, 0x20, 0x00, 0x14,
+ /* ipv6 header */
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x01
+ };
+ final PCEPPceIdIPv6ObjectParser parser = new PCEPPceIdIPv6ObjectParser();
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId pccIdReq = new PceIdBuilder().setIpAddress(new IpAddressNoZone(
+ new Ipv6AddressNoZone("::1"))).build();
+ final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
+ assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+
+ final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
+ parser.serializeObject(pccIdReq, buf);
+ assertArrayEquals(pccIdReqBytes, buf.array());
+ }
+
+ @Test
+ public void testProcTimeObject() throws PCEPDeserializerException {
+ final byte[] proctimeBytes = {
+ /* object header */
+ 0x1A, 0x10, 0x00, 0x1C,
+ /* E flag */
+ 0x00, 0x00, 0x00, 0x01,
+ /* current proc. time */
+ 0x00, 0x00, 0x00, 0x01,
+ /* min proc. time */
+ 0x00, 0x00, 0x00, 0x02,
+ /* max proc time */
+ 0x00, 0x00, 0x00, 0x03,
+ /* average proc time */
+ 0x00, 0x00, 0x00, 0x04,
+ /* variance proc time */
+ 0x00, 0x00, 0x00, 0x05,
+ };
+ final PCEPProcTimeObjectParser parser = new PCEPProcTimeObjectParser();
+ final ProcTime procTime = new ProcTimeBuilder()
+ .setEstimated(true)
+ .setAverageProcTime(4L)
+ .setCurrentProcTime(1L)
+ .setMaxProcTime(3L)
+ .setMinProcTime(2L)
+ .setVarianceProcTime(5L).build();
+ final ByteBuf result = Unpooled.wrappedBuffer(proctimeBytes);
+ assertEquals(procTime, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+
+ final ByteBuf buf = Unpooled.buffer(proctimeBytes.length);
+ parser.serializeObject(procTime, buf);
+ assertArrayEquals(proctimeBytes, buf.array());
+ }
+
+ @Test
+ public void testOverloadObject() throws PCEPDeserializerException {
+ final byte[] overloadBytes = {
+ /* object header */
+ 0x1B, 0x10, 0x00, 0x08,
+ /* overload duration */
+ 0x00, 0x00, 0x00, 0x78
+ };
+ final PCEPOverloadObjectParser parser = new PCEPOverloadObjectParser();
+ final Overload overload = new OverloadBuilder().setDuration(120).build();
+ final ByteBuf result = Unpooled.wrappedBuffer(overloadBytes);
+ assertEquals(overload, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+
+ final ByteBuf buf = Unpooled.buffer(overloadBytes.length);
+ parser.serializeObject(overload, buf);
+ assertArrayEquals(overloadBytes, buf.array());
+ }
+
+ @Test
+ public void testRpObjectWithPstTlvParser() throws PCEPDeserializerException {
+
+ final byte[] rpObjectWithPstTlvBytes = { 0x2, 0x10, 0x0, 0x14, 0x0, 0x0, 0x4, 0x2d, (byte) 0xde,
+ (byte) 0xad, (byte) 0xbe, (byte) 0xef,
+ /* pst-tlv */
+ 0x0, 0x1C, 0x0, 0x4, 0x0, 0x0, 0x0, 0x0 };
+
+ final PCEPRequestParameterObjectParser parser = new PCEPRequestParameterObjectParser(this.tlvRegistry, this.viTlvRegistry);
+ final RpBuilder builder = new RpBuilder();
+ builder.setProcessingRule(false);
+ builder.setIgnore(false);
+ builder.setReoptimization(true);
+ builder.setBiDirectional(false);
+ builder.setLoose(true);
+ builder.setMakeBeforeBreak(true);
+ builder.setOrder(false);
+ builder.setPathKey(false);
+ builder.setSupplyOf(false);
+ builder.setFragmentation(false);
+ builder.setP2mp(false);
+ builder.setEroCompression(false);
+ builder.setPriority((short) 5);
+ builder.setRequestId(new RequestId(0xdeadbeefL));
+ builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().setPathSetupType(
+ new PathSetupTypeBuilder().setPst((short) 0).build()).build());
+
+ final ByteBuf result = Unpooled.wrappedBuffer(rpObjectWithPstTlvBytes);
+ assertEquals(builder.build(),
+ parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+ final ByteBuf buf = Unpooled.buffer();
+ parser.serializeObject(builder.build(), buf);
+ assertArrayEquals(rpObjectWithPstTlvBytes, ByteArray.getAllBytes(buf));
+ }
}