diff --git a/TestData/YangSource/YangSource.csproj b/TestData/YangSource/YangSource.csproj index 0a69f00..af1bf23 100644 --- a/TestData/YangSource/YangSource.csproj +++ b/TestData/YangSource/YangSource.csproj @@ -5,6 +5,7 @@ latest enable enable + true diff --git a/benchmarks/Program.cs b/benchmarks/Program.cs index 62efd74..961b0f6 100644 --- a/benchmarks/Program.cs +++ b/benchmarks/Program.cs @@ -2,9 +2,11 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Running; using Ietf.Inet.Types; +using Yang.Attributes; using YangParser; using YangParser.Parser; using YangParser.SemanticModel; +using YangSource; namespace Benchmarks; @@ -17,6 +19,34 @@ public class ParsingBenchmarks private IStatement model; private Ietf.Bfd.Ip.Mh.YangNode.MultihopNotification notification; private string serialized; + private IYangServer server; + private IChannel channel; + + private static readonly Ietf.Connection.Oriented.Oam.YangNode.TracerouteInput input = + new() + { + MaNameStringValue = new Ietf.Connection.Oriented.Oam.YangNode.TracerouteInput.MaNameString(), + MdNameStringValue = new Ietf.Connection.Oriented.Oam.YangNode.TracerouteInput.MdNameString(), + Ttl = 2, + Count = 4, + Interval = 6, + CosId = 2, + DestinationMep = new Ietf.Connection.Oriented.Oam.YangNode.TracerouteInput.DestinationMepContainer + { + MepAddress = + new Ietf.Connection.Oriented.Oam.YangNode.TracerouteInput.DestinationMepContainer.MepAddressChoice + { + IpAddressCaseValue = + new Ietf.Connection.Oriented.Oam.YangNode.TracerouteInput.DestinationMepContainer. + MepAddressChoice.IpAddressCaseValueCase + { + IpAddress = new YangNode.IpAddress(new YangNode.Ipv4Address("1.2.3.4")) + } + } + }, + SourceMepValue = new(), + CommandSubType = Ietf.Connection.Oriented.Oam.YangNode.CommandSubTypeIdentity.Proactive + }; [GlobalSetup] public void Setup() @@ -31,6 +61,8 @@ public void Setup() SourceAddr = new YangNode.IpAddress(new YangNode.Ipv4Address("2.3.4.5")) }; serialized = notification.ToXML().Result; + server = new ExampleYangServer(); + channel = new BenchmarkingChannel(server); } [Benchmark] @@ -68,6 +100,24 @@ public MemoryStream ToMemoryStream() using var ms = new MemoryStream(Encoding.UTF8.GetBytes(serialized)); return await Ietf.Bfd.Ip.Mh.YangNode.MultihopNotification.ParseAsync(ms); } + + [Benchmark] + public async Task TracerouteRoundTrip() + { + return await Ietf.Connection.Oriented.Oam.YangNode.Traceroute(channel, 123, input); + } +} + +internal class BenchmarkingChannel(IYangServer server) : IChannel +{ + public async Task Send(string xml) + { + using var input = new MemoryStream(Encoding.UTF8.GetBytes(xml)); + var output = new MemoryStream(); + await server.Receive(input, output); + output.Seek(0, SeekOrigin.Begin); + return output; + } } internal static class Program