+
+ @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 IpAddress(new Ipv4Address("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 IpAddress(new Ipv6Address("::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 IpAddress(
+ new Ipv4Address("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 IpAddress(
+ new Ipv6Address("::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());
+ }