X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pcep%2Fimpl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fpcep%2Fimpl%2FPCEPObjectParserTest.java;h=bef70c455ac8bbc65c450fa30002db412390d4a8;hb=eee2e6c12ec171c7e7c3a7f938c66b75ae461cc4;hp=24aad5e64b751e52ac2cce77b3d19ddd38a184f3;hpb=7879172b57ef0be52fcae9096a926b1edc9446a5;p=bgpcep.git diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java index 24aad5e64b..bef70c455a 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java @@ -12,6 +12,7 @@ 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; @@ -22,28 +23,36 @@ import java.util.List; import org.junit.Before; import org.junit.Test; import org.opendaylight.protocol.pcep.impl.TestVendorInformationTlvParser.TestEnterpriseSpecificInformation; -import org.opendaylight.protocol.pcep.impl.object.PCEPBandwidthObjectParser; -import org.opendaylight.protocol.pcep.impl.object.PCEPClassTypeObjectParser; -import org.opendaylight.protocol.pcep.impl.object.PCEPCloseObjectParser; -import org.opendaylight.protocol.pcep.impl.object.PCEPEndPointsIpv4ObjectParser; -import org.opendaylight.protocol.pcep.impl.object.PCEPEndPointsIpv6ObjectParser; -import org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser; -import org.opendaylight.protocol.pcep.impl.object.PCEPExcludeRouteObjectParser; -import org.opendaylight.protocol.pcep.impl.object.PCEPExistingBandwidthObjectParser; -import org.opendaylight.protocol.pcep.impl.object.PCEPExplicitRouteObjectParser; -import org.opendaylight.protocol.pcep.impl.object.PCEPGlobalConstraintsObjectParser; -import org.opendaylight.protocol.pcep.impl.object.PCEPIncludeRouteObjectParser; -import org.opendaylight.protocol.pcep.impl.object.PCEPLoadBalancingObjectParser; -import org.opendaylight.protocol.pcep.impl.object.PCEPLspaObjectParser; -import org.opendaylight.protocol.pcep.impl.object.PCEPMetricObjectParser; -import org.opendaylight.protocol.pcep.impl.object.PCEPNoPathObjectParser; -import org.opendaylight.protocol.pcep.impl.object.PCEPNotificationObjectParser; -import org.opendaylight.protocol.pcep.impl.object.PCEPObjectiveFunctionObjectParser; -import org.opendaylight.protocol.pcep.impl.object.PCEPOpenObjectParser; -import org.opendaylight.protocol.pcep.impl.object.PCEPPathKeyObjectParser; -import org.opendaylight.protocol.pcep.impl.object.PCEPReportedRouteObjectParser; -import org.opendaylight.protocol.pcep.impl.object.PCEPRequestParameterObjectParser; -import org.opendaylight.protocol.pcep.impl.object.PCEPSvecObjectParser; +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; @@ -54,16 +63,17 @@ import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContex import org.opendaylight.protocol.util.ByteArray; 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.rev100924.AsNumber; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix; +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.PathKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId; 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; @@ -84,32 +94,47 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ 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.rev130820.AttributeFilter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ExcludeRouteSubobjects.Attribute; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.UnnumberedCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.as.number._case.AsNumberBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder; +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 { @@ -118,13 +143,13 @@ public class PCEPObjectParserTest { private VendorInformationTlvRegistry viTlvRegistry; private SimplePCEPExtensionProviderContext ctx; - private Activator act; + private BaseParserExtensionActivator act; private TestVendorInformationActivator viAct; @Before public void setUp() { this.ctx = new SimplePCEPExtensionProviderContext(); - this.act = new Activator(); + this.act = new BaseParserExtensionActivator(); this.viAct = new TestVendorInformationActivator(); this.act.start(this.ctx); this.viAct.start(this.ctx); @@ -148,9 +173,22 @@ public class PCEPObjectParserTest { 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))); - ByteBuf buf = Unpooled.buffer(); + 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 @@ -165,9 +203,22 @@ public class PCEPObjectParserTest { 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))); - ByteBuf buf = Unpooled.buffer(); + 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 @@ -182,9 +233,22 @@ public class PCEPObjectParserTest { 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))); - ByteBuf buf = Unpooled.buffer(); + 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 @@ -210,9 +274,16 @@ public class PCEPObjectParserTest { builder.setSubobject(subs); assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4))); - ByteBuf buf = Unpooled.buffer(); + 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 @@ -227,22 +298,35 @@ public class PCEPObjectParserTest { builder.setIgnore(false); final List 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()).build()); + 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()).build()); + 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()).build()); + 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()).build()); + 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))); - ByteBuf buf = Unpooled.buffer(); + 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 @@ -257,26 +341,39 @@ public class PCEPObjectParserTest { builder.setIgnore(false); final List 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.rev130820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder().setIpPrefix( - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder().setIpPrefix( + 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.rev130820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder().setIpPrefix( - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder().setIpPrefix( + 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.rev130820.record.route.subobjects.subobject.type.UnnumberedCaseBuilder().setUnnumbered( - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder().setRouterId( + 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))); - ByteBuf buf = Unpooled.buffer(); + 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 @@ -290,9 +387,22 @@ public class PCEPObjectParserTest { 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))); - ByteBuf buf = Unpooled.buffer(); + 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 @@ -300,15 +410,30 @@ public class PCEPObjectParserTest { final PCEPExistingBandwidthObjectParser parser = new PCEPExistingBandwidthObjectParser(); final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject2UpperBounds.bin")); - final BandwidthBuilder builder = new BandwidthBuilder(); + 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))); - ByteBuf buf = Unpooled.buffer(); + 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 @@ -323,13 +448,26 @@ public class PCEPObjectParserTest { builder.setProcessingRule(true); builder.setIgnore(false); builder.setAddressFamily(new Ipv4CaseBuilder().setIpv4( - new Ipv4Builder().setSourceIpv4Address(Ipv4Util.addressForBytes(srcIPBytes)).setDestinationIpv4Address( - Ipv4Util.addressForBytes(destIPBytes)).build()).build()); + 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))); - ByteBuf buf = Unpooled.buffer(); + 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 @@ -346,13 +484,26 @@ public class PCEPObjectParserTest { builder.setProcessingRule(true); builder.setIgnore(false); builder.setAddressFamily(new Ipv6CaseBuilder().setIpv6( - new Ipv6Builder().setSourceIpv6Address(Ipv6Util.addressForBytes(srcIPBytes)).setDestinationIpv6Address( - Ipv6Util.addressForBytes(destIPBytes)).build()).build()); + 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))); - ByteBuf buf = Unpooled.buffer(); - parser.serializeObject(builder.build(), buf); + 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 @@ -381,6 +532,19 @@ public class PCEPObjectParserTest { 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 @@ -417,6 +581,19 @@ public class PCEPObjectParserTest { 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 @@ -448,6 +625,19 @@ public class PCEPObjectParserTest { 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 @@ -481,6 +671,19 @@ public class PCEPObjectParserTest { 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 @@ -510,6 +713,19 @@ public class PCEPObjectParserTest { 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 @@ -556,6 +772,19 @@ public class PCEPObjectParserTest { 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 @@ -600,6 +829,19 @@ public class PCEPObjectParserTest { 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 @@ -613,9 +855,22 @@ public class PCEPObjectParserTest { builder.setClassType(new ClassType((short) 4)); assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4))); - ByteBuf buf = Unpooled.buffer(); + 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 @@ -637,9 +892,22 @@ public class PCEPObjectParserTest { builder.setSubobject(subs); assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4))); - ByteBuf buf = Unpooled.buffer(); + 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 @@ -656,9 +924,22 @@ public class PCEPObjectParserTest { builder.setPathKeys(list); assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4))); - ByteBuf buf = Unpooled.buffer(); + 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 @@ -673,9 +954,22 @@ public class PCEPObjectParserTest { 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))); - ByteBuf buf = Unpooled.buffer(); + 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 @@ -693,9 +987,22 @@ public class PCEPObjectParserTest { 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))); - ByteBuf buf = Unpooled.buffer(); + 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 @@ -723,7 +1030,7 @@ public class PCEPObjectParserTest { @Test public void testLspaObjectSerializerDefence() throws IOException, PCEPDeserializerException { final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry, this.viTlvRegistry); - ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin")); + final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin")); final LspaBuilder builder = new LspaBuilder(); builder.setProcessingRule(true); @@ -780,4 +1087,216 @@ public class PCEPObjectParserTest { 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)); + } }