From 36969eede24eb68b2455ccf0f7b4837e24276ef4 Mon Sep 17 00:00:00 2001 From: feyris-tan <4116042+feyris-tan@users.noreply.github.com> Date: Mon, 17 Nov 2025 22:13:31 +0100 Subject: [PATCH] Refactored Tests. --- .../MySqlDataStorage.cs | 108 ++++ .../Handlers/IQHandler.cs | 1 + .../Handlers/PngHandler.cs | 1 + .../IFileTypeHandler.cs | 1 + .../skyscraper8.AnagramViewer.csproj | 4 + skyscraper8.Tests/AllureLog.cs | 13 + .../AsraBarkerTransponderTests/DummyFilter.cs | 18 - skyscraper8.Tests/RangingResponseTest.cs | 28 - .../ResourceTests/DocsisTests.cs | 152 +++++ .../ResourceTests/GsType1SanityTest.cs | 36 ++ .../ResourceTests/SkyscraperTests.cs | 43 ++ skyscraper8.Tests/RootTests/DocsisTests.cs | 590 ++++++++++++++++++ skyscraper8.Tests/RootTests/Mpeg2Tests.cs | 16 + skyscraper8.Tests/UselessCodeCoverageTests.cs | 242 ------- skyscraper8.Tests/skyscraper8.Tests.csproj | 15 + skyscraper8.sln.DotSettings.user | 10 +- .../AnnexC/GeneralPacketClassifierEncoding.cs | 2 +- .../Ipv6PacketClassificationEncoding.cs | 2 +- .../AnnexC/ModemCapabilitiesEncoding.cs | 10 +- .../Docsis/AnnexC/RangingHoldOffSupport.cs | 2 +- .../Skyscraper/Scraper/SkyscraperContext.cs | 10 + 21 files changed, 1006 insertions(+), 298 deletions(-) create mode 100644 skyscraper8.Tests/AllureLog.cs delete mode 100644 skyscraper8.Tests/ClassDependencies/AsraBarkerTransponderTests/DummyFilter.cs delete mode 100644 skyscraper8.Tests/RangingResponseTest.cs create mode 100644 skyscraper8.Tests/ResourceTests/DocsisTests.cs create mode 100644 skyscraper8.Tests/ResourceTests/GsType1SanityTest.cs create mode 100644 skyscraper8.Tests/ResourceTests/SkyscraperTests.cs create mode 100644 skyscraper8.Tests/RootTests/DocsisTests.cs create mode 100644 skyscraper8.Tests/RootTests/Mpeg2Tests.cs delete mode 100644 skyscraper8.Tests/UselessCodeCoverageTests.cs diff --git a/DataTableStorages/skyscraper5.Data.MySql/MySqlDataStorage.cs b/DataTableStorages/skyscraper5.Data.MySql/MySqlDataStorage.cs index 9ea36f7..004ba81 100644 --- a/DataTableStorages/skyscraper5.Data.MySql/MySqlDataStorage.cs +++ b/DataTableStorages/skyscraper5.Data.MySql/MySqlDataStorage.cs @@ -22,7 +22,9 @@ using skyscraper5.src.InteractionChannel.Model2; using skyscraper5.src.Skyscraper.FrequencyListGenerator; using skyscraper5.src.Skyscraper.Scraper.Dns; using skyscraper5.Teletext; +using skyscraper8.InteractionChannel.Model; using skyscraper8.InteractionChannel.Model2; +using skyscraper8.InteractionChannel.Model2.Descriptors; using skyscraper8.Skyscraper.Scraper.Storage; namespace skyscraper5.Data.MySql @@ -291,6 +293,112 @@ namespace skyscraper5.Data.MySql throw new NotImplementedException(); } + public bool TestForRcs2Nit(RcsNit nit) + { + throw new NotImplementedException(); + } + + public void InsertRcs2Nit(RcsNit nit) + { + throw new NotImplementedException(); + } + + public bool UpdateRcs2Tdt(ushort interactiveNetworkId, DateTime tdtTimestamp) + { + throw new NotImplementedException(); + } + + public bool TestForTmst2(ushort interactiveNetworkId, Tmst2.TransmissionMode mode) + { + throw new NotImplementedException(); + } + + public void InsertTmst2(ushort interactiveNetworkId, Tmst2.TransmissionMode mode) + { + throw new NotImplementedException(); + } + + public bool TestForTimFramePayloadFormat(ushort networkId, _0xb7_FramePayloadFormatDescriptor.TransmissionContext transmissionContext) + { + throw new NotImplementedException(); + } + + public void InsertTimFramePayloadFormat(ushort networkId, _0xb7_FramePayloadFormatDescriptor.TransmissionContext transmissionContext) + { + throw new NotImplementedException(); + } + + public bool TestForTimCorrectionMessageExtension(PhysicalAddress macAddress) + { + throw new NotImplementedException(); + } + + public void InsertTimCorrectionMessageExtension(PhysicalAddress macAddress, + _0xb1_CorrectionMessageExtensionDescriptor descriptor) + { + throw new NotImplementedException(); + } + + public bool TestForTimControlAssignment(PhysicalAddress macAddress) + { + throw new NotImplementedException(); + } + + public void InsertTimControlAssignment(PhysicalAddress macAddress, _0xa4_SyncAssignDescriptor descriptor) + { + throw new NotImplementedException(); + } + + public bool TestForTimSatelliteReturnLink(PhysicalAddress macAddress) + { + throw new NotImplementedException(); + } + + public void InsertTimSatelliteReturnLink(PhysicalAddress macAddress, _0xa9_SatelliteReturnLinkDescriptor descriptor) + { + throw new NotImplementedException(); + } + + public bool TestForLowerLayerService(PhysicalAddress macAddress) + { + throw new NotImplementedException(); + } + + public void InsertTimLowerLayerService(PhysicalAddress macAddress, _0xbb_LowerLayerServiceDescriptor descriptor) + { + throw new NotImplementedException(); + } + + public bool TestForHigherLayerServiceInitalization(PhysicalAddress macAddress, _0xc4_HigherLayersInitializeDescriptor.Layer2Interface layer2Interface) + { + throw new NotImplementedException(); + } + + public void InsertHigherLayerServiceInitalization(PhysicalAddress macAddress, _0xc4_HigherLayersInitializeDescriptor.Layer2Interface layer2Interface) + { + throw new NotImplementedException(); + } + + public bool TestForTimLogonResponse(PhysicalAddress macAddress) + { + throw new NotImplementedException(); + } + + public void InsertTimLogonResponse(PhysicalAddress macAddress, _0xb9_LogonResponseDescriptor descriptor) + { + throw new NotImplementedException(); + } + + public bool TestForTimForwardInteractionPath(PhysicalAddress macAddress, _0xad_ForwardInteractionPathDescriptor.ForwardInteractionPath forwardInteractionPath) + { + throw new NotImplementedException(); + } + + public void InsertTimForwardInteractionPath(PhysicalAddress macAddress, _0xad_ForwardInteractionPathDescriptor.ForwardInteractionPath forwardInteractionPath) + { + throw new NotImplementedException(); + } + public IEnumerable> SelectAllPmt() { throw new NotImplementedException(); diff --git a/GUIs/skyscraper8.AnagramViewer/Handlers/IQHandler.cs b/GUIs/skyscraper8.AnagramViewer/Handlers/IQHandler.cs index eda23f6..a0a12cd 100644 --- a/GUIs/skyscraper8.AnagramViewer/Handlers/IQHandler.cs +++ b/GUIs/skyscraper8.AnagramViewer/Handlers/IQHandler.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Drawing.Imaging; using System.Linq; using System.Runtime.InteropServices; diff --git a/GUIs/skyscraper8.AnagramViewer/Handlers/PngHandler.cs b/GUIs/skyscraper8.AnagramViewer/Handlers/PngHandler.cs index a06a9f9..27e50a5 100644 --- a/GUIs/skyscraper8.AnagramViewer/Handlers/PngHandler.cs +++ b/GUIs/skyscraper8.AnagramViewer/Handlers/PngHandler.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/GUIs/skyscraper8.AnagramViewer/IFileTypeHandler.cs b/GUIs/skyscraper8.AnagramViewer/IFileTypeHandler.cs index 39a4a6e..ea5f6f1 100644 --- a/GUIs/skyscraper8.AnagramViewer/IFileTypeHandler.cs +++ b/GUIs/skyscraper8.AnagramViewer/IFileTypeHandler.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/GUIs/skyscraper8.AnagramViewer/skyscraper8.AnagramViewer.csproj b/GUIs/skyscraper8.AnagramViewer/skyscraper8.AnagramViewer.csproj index ddc1459..bfa0a89 100644 --- a/GUIs/skyscraper8.AnagramViewer/skyscraper8.AnagramViewer.csproj +++ b/GUIs/skyscraper8.AnagramViewer/skyscraper8.AnagramViewer.csproj @@ -28,4 +28,8 @@ + + + + \ No newline at end of file diff --git a/skyscraper8.Tests/AllureLog.cs b/skyscraper8.Tests/AllureLog.cs new file mode 100644 index 0000000..b7eb358 --- /dev/null +++ b/skyscraper8.Tests/AllureLog.cs @@ -0,0 +1,13 @@ +using Allure.Commons; +using Allure.Xunit.Attributes.Steps; + +namespace skyscraper8.Tests; + +public class AllureLog +{ + [AllureStep("{0}")] + public static void Log(string msg) + { + + } +} diff --git a/skyscraper8.Tests/ClassDependencies/AsraBarkerTransponderTests/DummyFilter.cs b/skyscraper8.Tests/ClassDependencies/AsraBarkerTransponderTests/DummyFilter.cs deleted file mode 100644 index adbec99..0000000 --- a/skyscraper8.Tests/ClassDependencies/AsraBarkerTransponderTests/DummyFilter.cs +++ /dev/null @@ -1,18 +0,0 @@ -using skyscraper5.Mpeg2; -using skyscraper5.src.Mpeg2.PacketFilter; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace skyscraper8.Tests.ClassDependencies.AsraBarkerTransponderTests -{ - internal class DummyFilter : IPacketFilter - { - public bool PassPacket(TsPacket packet) - { - return true; - } - } -} diff --git a/skyscraper8.Tests/RangingResponseTest.cs b/skyscraper8.Tests/RangingResponseTest.cs deleted file mode 100644 index 4f94ac2..0000000 --- a/skyscraper8.Tests/RangingResponseTest.cs +++ /dev/null @@ -1,28 +0,0 @@ -using skyscraper5.Docsis.MacManagement; -using System.Net.NetworkInformation; -using skyscraper8.Tests.Properties; - -namespace skyscraper8.Tests -{ - public class RangingResponseTest - { - [Fact] - public void OffsetBreakerTest() - { - - byte[] blob = Resources.ranging_response_test; - Random rng = new Random(); - - byte[] sourceMacBuffer = new byte[6]; - rng.NextBytes(sourceMacBuffer); - PhysicalAddress sourceAddress = new PhysicalAddress(sourceMacBuffer); - - byte[] targetMacBuffer = new byte[6]; - rng.NextBytes(targetMacBuffer); - PhysicalAddress targetAddress = new PhysicalAddress(targetMacBuffer); - - RangingResponse rangingResponse = new RangingResponse(sourceAddress, targetAddress, blob); - Assert.True(rangingResponse.Valid); - } - } -} diff --git a/skyscraper8.Tests/ResourceTests/DocsisTests.cs b/skyscraper8.Tests/ResourceTests/DocsisTests.cs new file mode 100644 index 0000000..cce6293 --- /dev/null +++ b/skyscraper8.Tests/ResourceTests/DocsisTests.cs @@ -0,0 +1,152 @@ +using skyscraper5; +using skyscraper5.Docsis; +using skyscraper5.Docsis.AnnexC; +using skyscraper5.Docsis.MacManagement; +using skyscraper5.Mpeg2; +using skyscraper5.Skyscraper.Plugins; +using skyscraper5.Skyscraper.Scraper; +using skyscraper5.Skyscraper.Scraper.Storage; +using skyscraper5.Skyscraper.Scraper.Storage.Filesystem; +using skyscraper5.Skyscraper.Scraper.Storage.InMemory; +using skyscraper8.Skyscraper.IO; +using skyscraper8.Tests.ClassDependencies.DocsisTests; +using skyscraper8.Tests.Properties; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Net.NetworkInformation; +using System.Text; +using System.Threading.Tasks; +using Allure.Xunit.Attributes; +using Xunit.Sdk; + +namespace skyscraper8.Tests.ResourceTests +{ + public class DocsisTests + { + [Fact] + [AllureSuite("Resources")] + [AllureFeature("DOCSIS")] + public void ModemCapabilitiesEncoding() + { + byte[] buffer = Resources.ModemCapabilitiesEncodingTest; + ModemCapabilitiesEncoding modemCapabilitiesEncoding = new ModemCapabilitiesEncoding(buffer); + Assert.True(modemCapabilitiesEncoding.Valid); + } + + [Fact] + [AllureSuite("Resources")] + [AllureFeature("DOCSIS")] + public void MultipartRegistrationResponse() + { + Random rng = new Random(); + + byte[] sourceBuffer = new byte[6]; + rng.NextBytes(sourceBuffer); + PhysicalAddress source = new PhysicalAddress(sourceBuffer); + + byte[] targetBuffer = new byte[6]; + rng.NextBytes(targetBuffer); + PhysicalAddress target = new PhysicalAddress(targetBuffer); + + byte[] buffer = Properties.Resources.MultipartRegistrationResponseTest; + T45_V4_MultipartRegistrationResponse test = new T45_V4_MultipartRegistrationResponse(source, target, buffer); + Assert.True(test.Valid); + } + + [Fact] + [AllureSuite("Resources")] + [AllureFeature("DOCSIS")] + public void MacManagement_4_45() + { + DocsisEventHandlerImpl docsisEventHandler = new DocsisEventHandlerImpl(); + DocsisEnvironment environment = new DocsisEnvironment(docsisEventHandler); + + byte[] testPayload = Resources.PushMacManagementMessage_Version4_Type45; + + Random rng = new Random(); + byte[] sourceBuffer = new byte[6]; + rng.NextBytes(sourceBuffer); + PhysicalAddress source = new PhysicalAddress(sourceBuffer); + + byte[] targetBuffer = new byte[6]; + rng.NextBytes(targetBuffer); + PhysicalAddress target = new PhysicalAddress(targetBuffer); + + environment.PushMacManagementMessage(testPayload, 4, 45, source, target, testPayload); + } + + [Fact] + [AllureSuite("Resources")] + [AllureFeature("DOCSIS")] + public void InvalidUpstreamChannelDescriptorTest() + { + byte[] testPayload = Resources.UpstreamChannelDescriptorTest; + + Random rng = new Random(); + byte[] sourceBuffer = new byte[6]; + rng.NextBytes(sourceBuffer); + PhysicalAddress source = new PhysicalAddress(sourceBuffer); + + byte[] targetBuffer = new byte[6]; + rng.NextBytes(targetBuffer); + PhysicalAddress target = new PhysicalAddress(targetBuffer); + + UpstreamChannelDescriptor ucd = new UpstreamChannelDescriptor(source, target, testPayload); + Assert.False(ucd.Valid); + } + + [Fact] + [AllureSuite("Resources")] + [AllureFeature("DOCSIS")] + public void TransmitChannelConfigurationObjectTest() + { + byte[] testPayload = Resources.TransmitChannelConfigurationObject; + + CommonTlvEncodingObject.TransmitChannelConfigurationObject child = new CommonTlvEncodingObject.TransmitChannelConfigurationObject(testPayload); + Assert.True(child.Valid); + } + + [Fact] + [AllureSuite("Resources")] + [AllureFeature("DOCSIS")] + public void MultipartRegistrationResponse2() + { + Random rng = new Random(); + + byte[] sourceBuffer = new byte[6]; + rng.NextBytes(sourceBuffer); + PhysicalAddress source = new PhysicalAddress(sourceBuffer); + + byte[] targetBuffer = new byte[6]; + rng.NextBytes(targetBuffer); + PhysicalAddress target = new PhysicalAddress(targetBuffer); + + byte[] buffer = Properties.Resources.MultipartRegistrationResponseTest2; + T45_V4_MultipartRegistrationResponse test = new T45_V4_MultipartRegistrationResponse(source, target, buffer); + Assert.True(test.Valid); + } + + [Fact] + [AllureSuite("Resources")] + [AllureFeature("DOCSIS")] + public void OffsetBreakerTest() + { + + byte[] blob = Resources.ranging_response_test; + Random rng = new Random(); + + byte[] sourceMacBuffer = new byte[6]; + rng.NextBytes(sourceMacBuffer); + PhysicalAddress sourceAddress = new PhysicalAddress(sourceMacBuffer); + + byte[] targetMacBuffer = new byte[6]; + rng.NextBytes(targetMacBuffer); + PhysicalAddress targetAddress = new PhysicalAddress(targetMacBuffer); + + RangingResponse rangingResponse = new RangingResponse(sourceAddress, targetAddress, blob); + Assert.True(rangingResponse.Valid); + } + } +} diff --git a/skyscraper8.Tests/ResourceTests/GsType1SanityTest.cs b/skyscraper8.Tests/ResourceTests/GsType1SanityTest.cs new file mode 100644 index 0000000..d1fd8c4 --- /dev/null +++ b/skyscraper8.Tests/ResourceTests/GsType1SanityTest.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using Allure.Xunit.Attributes; +using skyscraper5.Mpeg2; +using skyscraper8.Tests.Properties; + +namespace skyscraper8.Tests.ResourceTests; + +public class GsType1SanityTest +{ + [Fact] + [AllureSuite("Resources")] + [AllureFeature("MPEG2")] + public void CheckBfbsCrc() + { + byte[] blob = Resources.Frame00001343_TSGS1_MIS000_SYNC001; + MemoryStream ms = new MemoryStream(blob, false); + bool result = DvbCrc32.ValidateCrc(ms, 0, (int)ms.Length); + Assert.True(result); + + blob = Resources.Frame00000008_TSGS1_MIS000_SYNC001; + ms = new MemoryStream(blob, false); + result = DvbCrc32.ValidateCrc(ms, 0, (int)ms.Length); + Assert.True(result); + } + + [Fact] + [AllureSuite("Resources")] + [AllureFeature("MPEG2")] + public void CheckBfbsCrcSpan() + { + byte[] blob = Resources.Frame00000012_TSGS1_MIS000_SYNC001; + ReadOnlySpan span = new ReadOnlySpan(blob); + bool result = DvbCrc32.ValidateCrc(span); + Assert.True(result); + } +} \ No newline at end of file diff --git a/skyscraper8.Tests/ResourceTests/SkyscraperTests.cs b/skyscraper8.Tests/ResourceTests/SkyscraperTests.cs new file mode 100644 index 0000000..53932de --- /dev/null +++ b/skyscraper8.Tests/ResourceTests/SkyscraperTests.cs @@ -0,0 +1,43 @@ +using skyscraper5.Mpeg2; +using skyscraper5.Skyscraper.Scraper; +using skyscraper5.Skyscraper.Scraper.Storage.InMemory; +using skyscraper8.Tests.Properties; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Allure.Xunit.Attributes; +using skyscraper8.Skyscraper.Scraper.Storage; + +namespace skyscraper8.Tests.ResourceTests +{ + public class SkyscraperTests + { + [Fact] + [AllureSuite("Resources")] + [AllureFeature("Skyscraper")] + public void RunTestPatterns() + { + byte[][] buffers = new byte[][] { Resources.test_1packet_01, Resources.test_2packets_02_03, Resources.test_3packets_04_05_06 }; + + InMemoryScraperStorageFactory imssf = new InMemoryScraperStorageFactory(); + + foreach (byte[] buffer in buffers) + { + TsContext mpeg2 = new TsContext(); + DataStorage ds = new InMemoryScraperStorageFactory().CreateDataStorage(); + ObjectStorage os = new NullObjectStorage(); + + SkyscraperContext skyscraper = new SkyscraperContext(mpeg2, ds, os); + MemoryStream ms = new MemoryStream(buffer, false); + + skyscraper.InitalizeFilterChain(); + skyscraper.IngestFromStream(ms); + + ms.Close(); + ms.Dispose(); + } + } + } +} diff --git a/skyscraper8.Tests/RootTests/DocsisTests.cs b/skyscraper8.Tests/RootTests/DocsisTests.cs new file mode 100644 index 0000000..e23705c --- /dev/null +++ b/skyscraper8.Tests/RootTests/DocsisTests.cs @@ -0,0 +1,590 @@ +using Allure.Commons; +using Allure.Xunit.Attributes; +using skyscraper5.Docsis; +using skyscraper5.Docsis.AnnexC; + +namespace skyscraper8.Tests.RootTests; + +public class DocsisTests +{ + [Fact] + [AllureSuite("Root")] + [AllureFeature("DOCSIS")] + void MacManagementMessageTypeAttributeTest() + { + MacManagementMessageTypeAttribute mmmta = new MacManagementMessageTypeAttribute(1, 2); + Console.WriteLine(mmmta.ToString()); + } + + [Fact] + [AllureSuite("Root")] + [AllureFeature("DOCSIS")] + void RcpIdEncodingTest() + { + RcpIdEncoding rie = new RcpIdEncoding(new byte[] { 7, 1, 0 }); + SimplifiedReceiveChannelAssignmentEncoding simplifiedReceiveChannelAssignmentEncoding = rie.SimplifiedReceiveChannelConfiguration; + Assert.NotNull(simplifiedReceiveChannelAssignmentEncoding); + Assert.Throws(() => new RcpIdEncoding(new byte[] { 255, 1, 0 })); + } + + [Fact] + [AllureSuite("Root")] + [AllureFeature("DOCSIS")] + void EthernetLlcPacketClassificationEncodingTest() + { + EthernetLlcPacketClassificationEncoding epce = new EthernetLlcPacketClassificationEncoding(new byte[] { 3, 3, 1, 0, 1 }); + ushort epceEProt = epce.EProt; + Assert.Equal(1, epce.EProt); + Assert.Equal(1, epce.Type); + Assert.Throws(() => new EthernetLlcPacketClassificationEncoding(new byte[] { 255, 1, 0 })); + } + + [Fact] + [AllureSuite("Root")] + [AllureFeature("DOCSIS")] + void SimplifiedReceiveChannelAssignmentEncodingTest() + { + SimplifiedReceiveChannelAssignmentEncoding srcae = + new SimplifiedReceiveChannelAssignmentEncoding(new byte[] { 1, 1, 0, 2, 1, 0, 3, 1, 0 }); + Assert.Equal(0,srcae.DownstreamChannelAssignment[0]); + Assert.Equal(0, srcae.DownstreamProfileAssignment[0]); + Assert.Equal(0, srcae.PrimaryDownstreamChannelAssignment[0]); + Assert.Throws(() => new SimplifiedReceiveChannelAssignmentEncoding(new byte[] { 254,0,1 })); + } + + [Fact] + [AllureSuite("Root")] + [AllureFeature("DOCSIS")] + void TransmitChannelConfigurationObjectTest() + { + CommonTlvEncodingObject.TransmitChannelConfigurationObject tcco = + new CommonTlvEncodingObject.TransmitChannelConfigurationObject( + new byte[] + { + 1, 1, 0, + 2, 1, 0, + 3, 1, 0, + 5, 4, 0, 0, 0, 0, + 6, 2, 0, 0, + 7, 1, 1, + 9, 1, 0, + 10, 1, 0, + 11, 1, 0 + }); + Assert.Equal(0, tcco.TccReferenceId.Value); + Assert.Equal(CommonTlvEncodingObject.TransmitChannelConfigurationObject.UpstreamChannelActionEnum.NoAction, tcco.UpstreamChannelAction.Value); + Assert.Equal(0, tcco.UpstreamChannelId.Value); + Assert.NotNull(tcco.UpstreamChannelDescriptor); + Assert.Equal(0, tcco.RangingSid.Value); + Assert.Equal(InitalizationTechniqueEnum.BroadcastInitialRanging, tcco.InitializationTechnique.Value); + Assert.Equal(0, tcco.DynamicRangeWindow); + Assert.Equal(0, tcco.P16Hi); + Assert.Equal(0, tcco.ListOfIucs[0]); + + Assert.Throws(() => + new CommonTlvEncodingObject.TransmitChannelConfigurationObject(new byte[] { 254, 1, 0 })); + } + + [Fact] + [AllureSuite("Root")] + [AllureFeature("DOCSIS")] + void CommonTlvEncodingObjectTest() + { + MemoryStream ms = new MemoryStream(new byte[] + { + 5, 1, 0, + 47, 1, 0, + 49, 1, 0, + 31, 1, 0, + 27, 1, 0, + 30, 1, 0, + 52, 2, 0, 1 + }); + CommonTlvEncodingObject commonTlv = new CommonTlvEncodingObject(ms); + Assert.NotNull(commonTlv.ModemCapabilitiesEncoding); + Assert.NotNull(commonTlv.ServiceFlowSidClusterAssignment); + Assert.NotNull(commonTlv.RcpId); + Assert.Equal(0, commonTlv.KeySequenceNumber); + Assert.Equal(0, commonTlv.HmacDigest[0]); + Assert.NotNull(commonTlv.AuthorizationHint); + Assert.Equal(new TimeSpan(0, 0, 1), commonTlv.InitializingChannelTimeout); + + ms = new MemoryStream(new byte[] { 254, 1, 0 }); + Assert.Throws(() => new CommonTlvEncodingObject(ms)); + } + + [Fact] + [AllureSuite("Root")] + [AllureFeature("DOCSIS")] + void GeneralPacketClassifierEncodingTest() + { + GeneralPacketClassifierEncoding gpce = new GeneralPacketClassifierEncoding(new byte[] + { + 6, 1, 1, + 5, 1, 0, + 9, 1, 0, + 3, 2, 0, 1, + 1, 1, 0, + 2, 2, 0, 1, + 4, 4, 0, 0, 0, 1, + 7, 1, 0, + 10, 1, 0, + 12, 16, + //IPv6 Packet Classification Encoding + 3, 2, 0, 1, + 4, 4, 127, 0, 0, 1, + 6, 4, 127, 0, 0, 1 + }); + Assert.True(gpce.ClassifierActivationState.Value); + Assert.Equal(0, gpce.RulePriority.Value); + Assert.NotNull(gpce.Ipv4PacketClassification); + Assert.Equal(1, gpce.ServiceFlowReference.Value); + Assert.Equal(0, gpce.ClassifierReference.Value); + Assert.Equal(1, gpce.ClassifierIdentifier.Value); + Assert.Equal((uint)1, gpce.ServiceFlowIdentifier.Value); + Assert.Equal(GeneralPacketClassifierEncoding.DynamicServiceChangeActionEnum.Add, gpce.DynamicServiceChangeAction.Value); + Assert.NotNull(gpce.EthernetLlcPacketClassificationEncodings); + + Assert.Throws(() => new GeneralPacketClassifierEncoding(new byte[] + { + 12, 4, + 255, 1, 0, 0 + })); + + Assert.Throws(() => new GeneralPacketClassifierEncoding(new byte[] + { + 254, 1, 0 + })); + } + + [Fact] + [AllureSuite("Root")] + [AllureFeature("DOCSIS")] + public void Ipv4PacketClassificationEncodingTest() + { + GeneralPacketClassifierEncoding.Ipv4PacketClassificationEncodings ipce = + new GeneralPacketClassifierEncoding.Ipv4PacketClassificationEncodings(new byte[] + { + 3, 4, 127, 0, 0, 1, + 5, 4, 127, 0, 0, 1, + 2, 2, 0, 1, + 4, 4, 255, 255, 255, 0, + 6, 4, 255, 255, 255, 0, + 9, 2, 0, 1, + 10, 2, 0, 1, + 7, 2, 0, 1, + 8, 2, 0, 1 + }); + Assert.NotNull(ipce.Ipv4SourceAddress); + Assert.NotNull(ipce.Ipv4DestinationAddress); + Assert.Equal(1, ipce.IpProtocol.Value); + Assert.NotNull(ipce.Ipv4SourceMask); + Assert.NotNull(ipce.Ipv4DestinationMask); + Assert.Equal(1, ipce.DestinationPortStart.Value); + Assert.Equal(1, ipce.DestinationPortEnd.Value); + Assert.Equal(1, ipce.SourcePortStart.Value); + Assert.Equal(1, ipce.SourcePortEnd.Value); + + Assert.Throws(() => + new GeneralPacketClassifierEncoding.Ipv4PacketClassificationEncodings(new byte[] + { + 255, 1, 0 + })); + } + + [Fact] + [AllureSuite("Root")] + [AllureFeature("DOCSIS")] + public void ServiceFlowSidClusterAssignmentObjectTest() + { + ServiceFlowSidClusterAssignmentObject sfscao = new ServiceFlowSidClusterAssignmentObject(new byte[] + { + 1, 4, 0, 0, 0, 1, + 2, 1, 0, + 3, 1, 0, + }); + Assert.Equal(1u, sfscao.SFID.Value); + Assert.NotNull(sfscao.SidClusterEncoding); + Assert.NotNull(sfscao.SidClusterSwitchoverCriteria); + + Assert.Throws(() => new ServiceFlowSidClusterAssignmentObject(new byte[] + { + 255, 1, 0 + })); + } + + [Fact] + [AllureSuite("Root")] + [AllureFeature("DOCSIS")] + public void SidClusterEncodingObjectTest() + { + ServiceFlowSidClusterAssignmentObject.SidClusterEncodingObject sceo = + new ServiceFlowSidClusterAssignmentObject.SidClusterEncodingObject(new byte[] + { + 1, 1, 1, + 2, 1, 0 + }); + Assert.Equal(1, sceo.SidClusterId.Value); + Assert.NotNull(sceo.SidToChannelMapping); + + Assert.Throws(() => new ServiceFlowSidClusterAssignmentObject.SidClusterEncodingObject(new byte[] + { + 255, 1, 0 + })); + } + + [Fact] + [AllureSuite("Root")] + [AllureFeature("DOCSIS")] + public void SidToChannelMappingObjectTest() + { + ServiceFlowSidClusterAssignmentObject.SidClusterEncodingObject.SidToChannelMappingObject stcmo = + new ServiceFlowSidClusterAssignmentObject.SidClusterEncodingObject.SidToChannelMappingObject(new byte[] + { + 1,1,1, + 2,2,0,1, + 3,1,1 + }); + Assert.Equal(1, stcmo.UpstreamChannelId.Value); + Assert.Equal(1, stcmo.SID.Value); + Assert.Equal(ServiceFlowSidClusterAssignmentObject.SidClusterEncodingObject.SidToChannelMappingObject.ActionEnum.Add,stcmo.Action.Value); + + Assert.Throws(() => + new ServiceFlowSidClusterAssignmentObject.SidClusterEncodingObject.SidToChannelMappingObject(new byte[] + { + 255, 1, 0 + })); + } + + [Fact] + [AllureSuite("Root")] + [AllureFeature("DOCSIS")] + public void Ipv6PacketClassificationEncodingTest() + { + byte[] buffer = new byte[] + { + 12, //Type Ipv6 Packet Classification Encoding + 40, //Length of IPv6 Packet Classification Encoding + + 3,2, 0x08,0x00, //Next Header Type + 4,16, 0xfd,0x58,0x2f,0x40,0xec,0xe9,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01, + 6,16, 0xfd,0x73,0x14,0x63,0x41,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01 + }; + GeneralPacketClassifierEncoding gpce = new GeneralPacketClassifierEncoding(buffer); + Ipv6PacketClassificationEncoding ipce = gpce.Ipv6PacketClassification; + Assert.NotNull(ipce); + Assert.NotNull(ipce.Ipv6DestinationAddress); + Assert.NotNull(ipce.Ipv6SourceAddress); + Assert.Equal(0x0800, ipce.NextHeaderType); + } + + [Fact] + [AllureSuite("Root")] + [AllureFeature("DOCSIS")] + public void SidClusterSwitchoverCriteriaObjectTest() + { + byte[] buffer = new byte[] + { + 1, 1, 1, + 2, 4, 0, 0, 0, 1, + 3, 4, 0, 0, 0, 1, + 4, 2, 0, 1 + }; + ServiceFlowSidClusterAssignmentObject.SidClusterSwitchoverCriteriaObject scsco = + new ServiceFlowSidClusterAssignmentObject.SidClusterSwitchoverCriteriaObject(buffer); + Assert.Equal((byte)1,scsco.MaximumRequestPerSidCluster); + Assert.Equal((uint)1, scsco.MaximumOutstandingBytesPerSidCluster); + Assert.Equal((uint)1, scsco.MaximumTotalBytesRequestedPerSidCluster); + Assert.Equal((ushort)1, scsco.MaximumTimeInTheSidCluster); + + buffer = new byte[] { 254, 1, 0 }; + Assert.Throws(() => + new ServiceFlowSidClusterAssignmentObject.SidClusterSwitchoverCriteriaObject(buffer)); + } + + [Fact] + [AllureSuite("Root")] + [AllureFeature("DOCSIS")] + public void ModemCapabilitiesEncodingTest() + { + byte[] buffer = new byte[] + { + 1, 1, 1, + 2, 1, 0, + 3, 1, 1, + 4, 1, 1, + 6, 1, 1, + 7, 1, 1, + 8, 1, 1, + 10, 1, 1, + 11, 1, 1, + 12, 1, 1, + 15, 1, 1, + 16, 4, 1, 2, 3, 4, + 17, 1, 1, + 18, 7, 1, 0, 0, 0, 0, 0, 0, + 19, 1, 1, + 20, 1, 2, + 21, 1, 255, + 22, 1, 1, + 23, 1, 1, + 24, 1, 2, + 25, 1, 2, + 26, 1, 2, + 27, 1, 2, + 28, 1, 2, + 29, 1, 2, + 30, 1, 3, + 31, 1, 3, + 32, 1, 3, + 33, 1, 2, + 34, 1, 1, + 35, 1, 255, + 36, 1, 3, + 37, 1, 0, + 38, 2, 0, 3, + 39, 1, 1, + 40, 1, 4, + 44, 0, + 46, 1, 1, + 47, 4, 0, 0, 0, 255, + 48, 2, 0, 4, + 49, 1, 4, + 50, 1, 5, + 51, 1, 5, + 52, 2, 1, 2, + 53, 2, 1, 2, + 54, 1, 1, + 55, 1, 1, + 56, 1, 0, + 57, 1, 3, + 58, 1, 5, + 59, 2, 0, 5, + 60, 1, 3, + 76, 1, 7, + }; + + ModemCapabilitiesEncoding mcs = new ModemCapabilitiesEncoding(buffer); + Assert.True(mcs.ConcatenationSupport); + Assert.Equal(new Version(1, 0), mcs.DocsisVersion); + Assert.True(mcs.FragmentationSupport); + Assert.True(mcs.PayloadHeaderSuppressionSupport); + Assert.Equal(ModemCapabilitiesEncoding.PrivacySupportValue.BpiPlusSupport,mcs.PrivacySupport.Value); + Assert.Equal(1, mcs.DownstreamSaidSupport.Value); + Assert.Equal(1, mcs.UpstreamServiceFlowSupport.Value); + Assert.Equal(1, mcs.TransmitPreEqualizerTapsPerModulationInterval.Value); + Assert.Equal(1, mcs.NumberOfTransmitEqualizerTaps.Value); + Assert.True(mcs.DccSupport); + Assert.NotNull(mcs.RangingHoldOffSupport); + Assert.True(mcs.L2VPN); + Assert.NotNull(mcs.ESafeHostCapability); + Assert.True(mcs.DownstreamUnencryptedTrafficFiltering); + Assert.Equal(ModemCapabilitiesEncoding.UpstreamFrequencyRangeSupportEnum.Extended, mcs.UpstreamFrequencyRangeSupport); + Assert.True(mcs._160kspsSymbolRateSupport); + Assert.True(mcs._320kspsSymbolRateSupport); + Assert.True(mcs._640kspsSymbolRateSupport); + Assert.True(mcs._1280kspsSymbolRateSupport); + Assert.True(mcs._2560kspsSymbolRateSupport); + Assert.True(mcs._5120kspsSymbolRateSupport); + Assert.True(mcs.SelectableActiveCodeMode2Support); + Assert.True(mcs.CodeHoppingMode2Support); + Assert.Equal(2,mcs.ScQamMultipleTransmitChannelSupport.Value); + Assert.Equal(2, mcs.TotalSidClusterSupport.Value); + Assert.Equal(2, mcs.SidClustersPerServiceFlowSupport.Value); + Assert.Equal(2, mcs.ScQamMultipleReceiveChannelSupport.Value); + Assert.Equal(3, mcs.TotalDsidSupport.Value); + Assert.Equal(3, mcs.ResequencingDsidSupport.Value); + Assert.Equal(3, mcs.MulticastDsidSupport.Value); + Assert.Equal(ModemCapabilitiesEncoding.MulticastDsidForwardingEnum.SupportPromiscious, mcs.MulticastDsidForwarding.Value); + Assert.True(mcs.FrameControlTypeForwardingCapability); + Assert.True(mcs.DpvPerPathSuppported); + Assert.True(mcs.DpvPerPacketSuppported); + Assert.Equal(3, mcs.UnsolicitedGrantServiceFlowSupport.Value); + Assert.True(mcs.MapAndUcdReceiptSupport); + Assert.Equal(3, mcs.UpstreamDropClassifierSupport); + Assert.True(mcs.Ipv6Support.Value); + Assert.Equal(4, mcs.ExtendedUpstreamTransmitPowerCapability.Value); + Assert.True(mcs.CmStatusAck); + Assert.True(mcs.EnergyManagement1x1Feature); + Assert.True(mcs.DocsisLightSleepMode); + Assert.Equal(4, mcs.ExtendedPacketLengthSupportCapability); + Assert.Equal(4, mcs.OfdmMultipleReceiveChannelSupport.Value); + Assert.Equal(5, mcs.OfdmaMultipleTransmitChannelSupport.Value); + Assert.Equal(5, mcs.DownstreamOfdmProfileSupport.Value); + Assert.NotNull(mcs.DownstreamOfdmChannelSubcarrierQamModulationSupport); + Assert.NotNull(mcs.UpstreamOfdmaChannelSubcarrierQamModulationSupport); + Assert.Equal(108, mcs.DownstreamFrequencyRangeStarting); + Assert.Equal(1218, mcs.DownstreamFrequencyRangeUpTo); + Assert.Equal(42, mcs.UpstreamFrequencyRangeUpTo); + Assert.Equal(ModemCapabilitiesEncoding.DtpMode.MasterOrSlave, mcs.DocsisTimeProtocolMode.Value); + Assert.Equal(ModemCapabilitiesEncoding.DtpPerformanceSupport.Level5, mcs.DocsisTimeProtocolPerformanceSupport.Value); + Assert.Equal(5, mcs.Pmax); + Assert.True(mcs.DownstreamFullDuplex); + Assert.Equal(7, mcs.LowLatencySupport.Value); + + buffer = new byte[] + { + 2, 1, 1, + 54, 1, 2, + 55, 1, 2, + 56, 1, 1, + }; + mcs = new ModemCapabilitiesEncoding(buffer); + Assert.True(mcs._160kspsSymbolRateSupport); + Assert.True(mcs._320kspsSymbolRateSupport); + Assert.True(mcs._640kspsSymbolRateSupport); + Assert.True(mcs._1280kspsSymbolRateSupport); + Assert.True(mcs._2560kspsSymbolRateSupport); + Assert.True(mcs._5120kspsSymbolRateSupport); + + + buffer = new byte[] + { + 2, 1, 2, + 55, 1, 4, + 56, 1, 2, + 60, 1, 1, + }; + mcs = new ModemCapabilitiesEncoding(buffer); + + buffer = new byte[] + { + 2, 1, 3, + 56, 1, 3, + 60, 1, 2, + 61, 1, 1 + }; + mcs = new ModemCapabilitiesEncoding(buffer); + + buffer = new byte[] + { + 2, 1, 4, + 56, 1, 4, + 61, 1, 2 + }; + mcs = new ModemCapabilitiesEncoding(buffer); + Assert.Null(mcs.DpvPerPathSuppported); + Assert.Null(mcs.DpvPerPacketSuppported); + Assert.Null(mcs.EnergyManagement1x1Feature); + Assert.Null(mcs.DocsisLightSleepMode); + + buffer = new byte[] + { + 2, 1, 5, + 61, 1, 4, + 62, 1, 0 + }; + mcs = new ModemCapabilitiesEncoding(buffer); + + buffer = new byte[] + { + 2, 1, 6, + 62, 1, 1 + }; + mcs = new ModemCapabilitiesEncoding(buffer); + + buffer = new byte[] + { + 62, 1, 2 + }; + mcs = new ModemCapabilitiesEncoding(buffer); + + buffer = new byte[] + { + 62, 1, 3 + }; + mcs = new ModemCapabilitiesEncoding(buffer); + + buffer = new byte[] + { + 62, 1, 4 + }; + mcs = new ModemCapabilitiesEncoding(buffer); + + + buffer = new byte[] + { + 255, 1, 1 + }; + Assert.Throws(() => new ModemCapabilitiesEncoding(buffer)); + } + + [Fact] + [AllureSuite("Root")] + [AllureFeature("DOCSIS")] + public void GeneralServiceFlowEncodingTest() + { + byte[] buffer = new byte[] + { + 1, 2, 0, 1, + 2, 2, 0, 1, + 6, 1, 255, + 7, 1, 1, + 8, 4, 0, 0, 0, 1, + 9, 4, 0, 0, 0, 1, + 10, 4, 0, 0, 0, 1, + 11, 2, 0, 1, + 12, 2, 0, 1, + 14, 2, 0, 1, + 15, 1, 7, + 17, 1, 1, + 19, 2, 0, 1, + 20, 4, 0, 0, 0, 2, + 21, 4, 0, 0, 0, 2, + 22, 1, 2, + 23, 1, 2, + 24, 4, 0, 0, 0, 2, + 26, 1, 2, + 32, 4, 0, 0, 0, 3, + 16, 4, 0, 0, 255, 255, + }; + GeneralServiceFlowEncoding gsfe = new GeneralServiceFlowEncoding(buffer); + Assert.Equal((ushort)1, gsfe.ServiceFlowReference); + Assert.Equal((ushort)1, gsfe.ServiceFlowIdentifier); + Assert.True(gsfe.ProvisionedSet); + Assert.True(gsfe.AdmittedSet); + Assert.True(gsfe.ActiveSet); + Assert.Equal((byte)1, gsfe.TrafficPriority); + Assert.Equal((uint)1, gsfe.UpstreamMaximumSustainedTrafficRate); + Assert.Equal((uint)1, gsfe.MaximumTrafficBurst); + Assert.Equal((uint)1, gsfe.MinimumReservedTrafficRate); + Assert.Equal((ushort)1, gsfe.AssumedMinimumReservedRatePacketSize); + Assert.Equal((ushort)1, gsfe.TimeoutForActiveQosParameters); + Assert.Equal(1, gsfe.MaximumConcatenatedBurst); + Assert.Equal(GeneralServiceFlowEncoding.ServiceFlowSchedulingTypeEnum.ProactiveGrantService, gsfe.ServiceFlowSchedulingType); + Assert.Equal(1, gsfe.DownstreamResequencing.Value); + Assert.Equal(1, gsfe.UnsolicitedGrantSize.Value); + Assert.Equal((uint)2, gsfe.NominalGrantInterval.Value); + Assert.Equal((uint)2, gsfe.ToleratedGrantJitter.Value); + Assert.Equal(2, gsfe.GrantsPerInterval.Value); + Assert.NotNull(gsfe.IpTypeOfServiceOverwrite); + Assert.Equal((uint)2, gsfe.CmtsTimestamp.Value); + Assert.Equal(2, gsfe.MultiplierToNumberOfBytesRequested); + Assert.Equal((uint)3, gsfe.ServiceFlowForbiddenAttributeMask); + Assert.True(gsfe.DoNotUseContentionRegions); + Assert.True(gsfe.DoNotUseSegmentHeaders); + Assert.True(gsfe.DropPacketsTooBigForUnsolicitedGrant); + Assert.True(gsfe.DoNotSupressPayloadHeaders); + Assert.True(gsfe.DoNotFragmentData); + Assert.True(gsfe.DoNotConcatenateData); + Assert.True(gsfe.DoNotPiggybackRequests); + Assert.True(gsfe.DoNotUseRequest2ForData); + Assert.True(gsfe.DoNotUseRequest2ForRequests); + Assert.True(gsfe.DoNotUsePriorityRequest); + Assert.True(gsfe.DoNotUseAllCms); + AllureLog.Log(gsfe.ToString()); + + buffer = new byte[] + { + 17, 4, 0, 0, 0, 1 + }; + gsfe = new GeneralServiceFlowEncoding(buffer); + Assert.Equal((uint)1, gsfe.NominalPollingInterval.Value); + + buffer = new byte[] + { + 254, 1, 1 + }; + Assert.Throws(() => new GeneralServiceFlowEncoding(buffer)); + } +} diff --git a/skyscraper8.Tests/RootTests/Mpeg2Tests.cs b/skyscraper8.Tests/RootTests/Mpeg2Tests.cs new file mode 100644 index 0000000..2d1c082 --- /dev/null +++ b/skyscraper8.Tests/RootTests/Mpeg2Tests.cs @@ -0,0 +1,16 @@ +using Allure.Xunit.Attributes; +using skyscraper5.Mpeg2; + +namespace skyscraper8.Tests.RootTests; + +public class Mpeg2Tests +{ + [Fact] + [AllureSuite("Root")] + [AllureFeature("MPEG2")] + void PsiSectionTest() + { + PsiSection section = new PsiSection(); + section.Append(new byte[] { 3 }); + } +} diff --git a/skyscraper8.Tests/UselessCodeCoverageTests.cs b/skyscraper8.Tests/UselessCodeCoverageTests.cs deleted file mode 100644 index 30b5bc2..0000000 --- a/skyscraper8.Tests/UselessCodeCoverageTests.cs +++ /dev/null @@ -1,242 +0,0 @@ -using skyscraper5.Docsis; -using skyscraper5.Docsis.AnnexC; -using skyscraper5.Mpeg2; - -namespace skyscraper8.Tests; - -public class UselessCodeCoverageTests -{ - [Fact] - void PsiSectionTest() - { - PsiSection section = new PsiSection(); - section.Append(new byte[] { 3 }); - } - - [Fact] - void MacManagementMessageTypeAttributeTest() - { - MacManagementMessageTypeAttribute mmmta = new MacManagementMessageTypeAttribute(1, 2); - Console.WriteLine(mmmta.ToString()); - } - - [Fact] - void RcpIdEncodingTest() - { - RcpIdEncoding rie = new RcpIdEncoding(new byte[] { 7, 1, 0 }); - SimplifiedReceiveChannelAssignmentEncoding simplifiedReceiveChannelAssignmentEncoding = rie.SimplifiedReceiveChannelConfiguration; - Assert.NotNull(simplifiedReceiveChannelAssignmentEncoding); - Assert.Throws(() => new RcpIdEncoding(new byte[] { 255, 1, 0 })); - } - - [Fact] - void EthernetLlcPacketClassificationEncodingTest() - { - EthernetLlcPacketClassificationEncoding epce = new EthernetLlcPacketClassificationEncoding(new byte[] { 3, 3, 1, 0, 1 }); - ushort epceEProt = epce.EProt; - Assert.Equal(1, epce.EProt); - Assert.Equal(1, epce.Type); - Assert.Throws(() => new EthernetLlcPacketClassificationEncoding(new byte[] { 255, 1, 0 })); - } - - [Fact] - void SimplifiedReceiveChannelAssignmentEncodingTest() - { - SimplifiedReceiveChannelAssignmentEncoding srcae = - new SimplifiedReceiveChannelAssignmentEncoding(new byte[] { 1, 1, 0, 2, 1, 0, 3, 1, 0 }); - Assert.Equal(0,srcae.DownstreamChannelAssignment[0]); - Assert.Equal(0, srcae.DownstreamProfileAssignment[0]); - Assert.Equal(0, srcae.PrimaryDownstreamChannelAssignment[0]); - Assert.Throws(() => new SimplifiedReceiveChannelAssignmentEncoding(new byte[] { 254,0,1 })); - } - - [Fact] - void TransmitChannelConfigurationObjectTest() - { - CommonTlvEncodingObject.TransmitChannelConfigurationObject tcco = - new CommonTlvEncodingObject.TransmitChannelConfigurationObject( - new byte[] - { - 1, 1, 0, - 2, 1, 0, - 3, 1, 0, - 5, 4, 0, 0, 0, 0, - 6, 2, 0, 0, - 7, 1, 1, - 9, 1, 0, - 10, 1, 0, - 11, 1, 0 - }); - Assert.Equal(0, tcco.TccReferenceId.Value); - Assert.Equal(CommonTlvEncodingObject.TransmitChannelConfigurationObject.UpstreamChannelActionEnum.NoAction, tcco.UpstreamChannelAction.Value); - Assert.Equal(0, tcco.UpstreamChannelId.Value); - Assert.NotNull(tcco.UpstreamChannelDescriptor); - Assert.Equal(0, tcco.RangingSid.Value); - Assert.Equal(InitalizationTechniqueEnum.BroadcastInitialRanging, tcco.InitializationTechnique.Value); - Assert.Equal(0, tcco.DynamicRangeWindow); - Assert.Equal(0, tcco.P16Hi); - Assert.Equal(0, tcco.ListOfIucs[0]); - - Assert.Throws(() => - new CommonTlvEncodingObject.TransmitChannelConfigurationObject(new byte[] { 254, 1, 0 })); - } - - [Fact] - void CommonTlvEncodingObjectTest() - { - MemoryStream ms = new MemoryStream(new byte[] - { - 5, 1, 0, - 47, 1, 0, - 49, 1, 0, - 31, 1, 0, - 27, 1, 0, - 30, 1, 0, - 52, 2, 0, 1 - }); - CommonTlvEncodingObject commonTlv = new CommonTlvEncodingObject(ms); - Assert.NotNull(commonTlv.ModemCapabilitiesEncoding); - Assert.NotNull(commonTlv.ServiceFlowSidClusterAssignment); - Assert.NotNull(commonTlv.RcpId); - Assert.Equal(0, commonTlv.KeySequenceNumber); - Assert.Equal(0, commonTlv.HmacDigest[0]); - Assert.NotNull(commonTlv.AuthorizationHint); - Assert.Equal(new TimeSpan(0, 0, 1), commonTlv.InitializingChannelTimeout); - - ms = new MemoryStream(new byte[] { 254, 1, 0 }); - Assert.Throws(() => new CommonTlvEncodingObject(ms)); - } - - [Fact] - void GeneralPacketClassifierEncodingTest() - { - GeneralPacketClassifierEncoding gpce = new GeneralPacketClassifierEncoding(new byte[] - { - 6, 1, 1, - 5, 1, 0, - 9, 1, 0, - 3, 2, 0, 1, - 1, 1, 0, - 2, 2, 0, 1, - 4, 4, 0, 0, 0, 1, - 7, 1, 0, - 10, 1, 0, - 12, 16, - //IPv6 Packet Classification Encoding - 3, 2, 0, 1, - 4, 4, 127, 0, 0, 1, - 6, 4, 127, 0, 0, 1 - }); - Assert.True(gpce.ClassifierActivationState.Value); - Assert.Equal(0, gpce.RulePriority.Value); - Assert.NotNull(gpce.Ipv4PacketClassification); - Assert.Equal(1, gpce.ServiceFlowReference.Value); - Assert.Equal(0, gpce.ClassifierReference.Value); - Assert.Equal(1, gpce.ClassifierIdentifier.Value); - Assert.Equal((uint)1, gpce.ServiceFlowIdentifier.Value); - Assert.Equal(GeneralPacketClassifierEncoding.DynamicServiceChangeActionEnum.Add, gpce.DynamicServiceChangeAction.Value); - Assert.NotNull(gpce.EthernetLlcPacketClassificationEncodings); - - Assert.Throws(() => new GeneralPacketClassifierEncoding(new byte[] - { - 12, 4, - 255, 1, 0, 0 - })); - - Assert.Throws(() => new GeneralPacketClassifierEncoding(new byte[] - { - 254, 1, 0 - })); - } - - [Fact] - public void Ipv4PacketClassificationEncodingTest() - { - GeneralPacketClassifierEncoding.Ipv4PacketClassificationEncodings ipce = - new GeneralPacketClassifierEncoding.Ipv4PacketClassificationEncodings(new byte[] - { - 3, 4, 127, 0, 0, 1, - 5, 4, 127, 0, 0, 1, - 2, 2, 0, 1, - 4, 4, 255, 255, 255, 0, - 6, 4, 255, 255, 255, 0, - 9, 2, 0, 1, - 10, 2, 0, 1, - 7, 2, 0, 1, - 8, 2, 0, 1 - }); - Assert.NotNull(ipce.Ipv4SourceAddress); - Assert.NotNull(ipce.Ipv4DestinationAddress); - Assert.Equal(1, ipce.IpProtocol.Value); - Assert.NotNull(ipce.Ipv4SourceMask); - Assert.NotNull(ipce.Ipv4DestinationMask); - Assert.Equal(1, ipce.DestinationPortStart.Value); - Assert.Equal(1, ipce.DestinationPortEnd.Value); - Assert.Equal(1, ipce.SourcePortStart.Value); - Assert.Equal(1, ipce.SourcePortEnd.Value); - - Assert.Throws(() => - new GeneralPacketClassifierEncoding.Ipv4PacketClassificationEncodings(new byte[] - { - 255, 1, 0 - })); - } - - [Fact] - public void ServiceFlowSidClusterAssignmentObjectTest() - { - ServiceFlowSidClusterAssignmentObject sfscao = new ServiceFlowSidClusterAssignmentObject(new byte[] - { - 1, 4, 0, 0, 0, 1, - 2, 1, 0, - 3, 1, 0, - }); - Assert.Equal(1u, sfscao.SFID.Value); - Assert.NotNull(sfscao.SidClusterEncoding); - Assert.NotNull(sfscao.SidClusterSwitchoverCriteria); - - Assert.Throws(() => new ServiceFlowSidClusterAssignmentObject(new byte[] - { - 255, 1, 0 - })); - } - - [Fact] - public void SidClusterEncodingObjectTest() - { - ServiceFlowSidClusterAssignmentObject.SidClusterEncodingObject sceo = - new ServiceFlowSidClusterAssignmentObject.SidClusterEncodingObject(new byte[] - { - 1, 1, 1, - 2, 1, 0 - }); - Assert.Equal(1, sceo.SidClusterId.Value); - Assert.NotNull(sceo.SidToChannelMapping); - - Assert.Throws(() => new ServiceFlowSidClusterAssignmentObject.SidClusterEncodingObject(new byte[] - { - 255, 1, 0 - })); - } - - [Fact] - public void SidToChannelMappingObjectTest() - { - ServiceFlowSidClusterAssignmentObject.SidClusterEncodingObject.SidToChannelMappingObject stcmo = - new ServiceFlowSidClusterAssignmentObject.SidClusterEncodingObject.SidToChannelMappingObject(new byte[] - { - 1,1,1, - 2,2,0,1, - 3,1,1 - }); - Assert.Equal(1, stcmo.UpstreamChannelId.Value); - Assert.Equal(1, stcmo.SID.Value); - Assert.Equal(ServiceFlowSidClusterAssignmentObject.SidClusterEncodingObject.SidToChannelMappingObject.ActionEnum.Add,stcmo.Action.Value); - - Assert.Throws(() => - new ServiceFlowSidClusterAssignmentObject.SidClusterEncodingObject.SidToChannelMappingObject(new byte[] - { - 255, 1, 0 - })); - } -} \ No newline at end of file diff --git a/skyscraper8.Tests/skyscraper8.Tests.csproj b/skyscraper8.Tests/skyscraper8.Tests.csproj index f25b1bc..66eebe0 100644 --- a/skyscraper8.Tests/skyscraper8.Tests.csproj +++ b/skyscraper8.Tests/skyscraper8.Tests.csproj @@ -10,6 +10,8 @@ + + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -46,4 +48,17 @@ + + + Always + + + + + + Always + + + + diff --git a/skyscraper8.sln.DotSettings.user b/skyscraper8.sln.DotSettings.user index 99e7b5f..56db608 100644 --- a/skyscraper8.sln.DotSettings.user +++ b/skyscraper8.sln.DotSettings.user @@ -1,4 +1,5 @@  + ForceIncluded ForceIncluded ForceIncluded ForceIncluded @@ -7,15 +8,20 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded + <AssemblyExplorer> + <Assembly Path="/home/schiemas/.dotnet/packs/Microsoft.NETCore.App.Ref/8.0.21/ref/net8.0/System.Windows.dll" /> +</AssemblyExplorer> /home/schiemas/.cache/JetBrains/Rider2025.1/resharper-host/temp/Rider/vAny/CoverageData/_skyscraper8.1808907683/Snapshot/snapshot.utdcvr - <SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from &lt;skyscraper8.Tests&gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> - <Project Location="\home\schiemas\RiderProjects\skyscraper8\skyscraper8.Tests" Presentation="&lt;skyscraper8.Tests&gt;" /> + <SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from &lt;skyscraper8.Tests&gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <Project Location="/home/schiemas/RiderProjects/skyscraper8/skyscraper8.Tests" Presentation="&lt;skyscraper8.Tests&gt;" /> </SessionState> diff --git a/skyscraper8/Docsis/AnnexC/GeneralPacketClassifierEncoding.cs b/skyscraper8/Docsis/AnnexC/GeneralPacketClassifierEncoding.cs index c5b0cc1..3ed42ea 100644 --- a/skyscraper8/Docsis/AnnexC/GeneralPacketClassifierEncoding.cs +++ b/skyscraper8/Docsis/AnnexC/GeneralPacketClassifierEncoding.cs @@ -149,6 +149,6 @@ namespace skyscraper5.Docsis.AnnexC public uint? ServiceFlowIdentifier { get; set; } public EthernetLlcPacketClassificationEncoding EthernetLlcPacketClassificationEncodings { get; } - internal Ipv6PacketClassificationEncoding Ipv6PacketClassification { get; } + public Ipv6PacketClassificationEncoding Ipv6PacketClassification { get; } } } diff --git a/skyscraper8/Docsis/AnnexC/Ipv6PacketClassificationEncoding.cs b/skyscraper8/Docsis/AnnexC/Ipv6PacketClassificationEncoding.cs index fcf5268..43ba846 100644 --- a/skyscraper8/Docsis/AnnexC/Ipv6PacketClassificationEncoding.cs +++ b/skyscraper8/Docsis/AnnexC/Ipv6PacketClassificationEncoding.cs @@ -3,7 +3,7 @@ using System.Net; namespace skyscraper5.Docsis.AnnexC { - internal class Ipv6PacketClassificationEncoding + public class Ipv6PacketClassificationEncoding { public Ipv6PacketClassificationEncoding(byte[] buffer) { diff --git a/skyscraper8/Docsis/AnnexC/ModemCapabilitiesEncoding.cs b/skyscraper8/Docsis/AnnexC/ModemCapabilitiesEncoding.cs index 94777e4..475d96e 100644 --- a/skyscraper8/Docsis/AnnexC/ModemCapabilitiesEncoding.cs +++ b/skyscraper8/Docsis/AnnexC/ModemCapabilitiesEncoding.cs @@ -12,7 +12,7 @@ namespace skyscraper5.Docsis.AnnexC { private readonly bool? ExpandedUnicastSidSpace; private readonly byte? DpvCapability; - private readonly byte EnergyManagementPreference; + private readonly byte? EnergyManagementPreference; private byte? UpstreamScQamSymbolRateSupport; private byte? _512MspsUpstreamTransmitScQamChannelSupport; private byte? _256MspsUpstreamTransmitScQamChannelSupport; @@ -207,7 +207,7 @@ namespace skyscraper5.Docsis.AnnexC DownstreamFrequencyRangeStarting = 108; else if (v[0] == 0x02) DownstreamFrequencyRangeStarting = 258; - else if (v[0] == 0x003) + else if (v[0] == 0x03) DownstreamFullDuplex = true; break; case 61: @@ -235,7 +235,7 @@ namespace skyscraper5.Docsis.AnnexC break; default: //CM-SP-MULPIv4.0-I01-190815.pdf, page 688 - throw new NotFiniteNumberException(String.Format("{0} {1}", nameof(ModemCapabilitiesEncoding), type)); + throw new NotImplementedException(String.Format("{0} {1}", nameof(ModemCapabilitiesEncoding), type)); } } Valid = true; @@ -268,7 +268,7 @@ namespace skyscraper5.Docsis.AnnexC public byte? TransmitPreEqualizerTapsPerModulationInterval { get; } public byte? NumberOfTransmitEqualizerTaps { get; } public bool? DccSupport { get; } - internal RangingHoldOffSupport RangingHoldOffSupport { get; } + public RangingHoldOffSupport RangingHoldOffSupport { get; } public bool? L2VPN { get; } public ESafeHostCapability ESafeHostCapability { get; } public bool? DownstreamUnencryptedTrafficFiltering { get; } @@ -446,5 +446,5 @@ namespace skyscraper5.Docsis.AnnexC Level5 = 5, NoSpecifiedPerformance = 6, } - } + } } diff --git a/skyscraper8/Docsis/AnnexC/RangingHoldOffSupport.cs b/skyscraper8/Docsis/AnnexC/RangingHoldOffSupport.cs index ed361d3..00a792a 100644 --- a/skyscraper8/Docsis/AnnexC/RangingHoldOffSupport.cs +++ b/skyscraper8/Docsis/AnnexC/RangingHoldOffSupport.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace skyscraper8.Docsis.AnnexC { - internal class RangingHoldOffSupport + public class RangingHoldOffSupport { public RangingHoldOffSupport(byte a, byte b, byte c, byte d) { diff --git a/skyscraper8/Skyscraper/Scraper/SkyscraperContext.cs b/skyscraper8/Skyscraper/Scraper/SkyscraperContext.cs index d0a6d11..52f4e55 100644 --- a/skyscraper8/Skyscraper/Scraper/SkyscraperContext.cs +++ b/skyscraper8/Skyscraper/Scraper/SkyscraperContext.cs @@ -3072,6 +3072,10 @@ namespace skyscraper5.Skyscraper.Scraper //Link Layer Discovery Protocol LldpFrame lldpFrame = new LldpFrame(contents); OnLldpFrame(lldpFrame); + return; + case 0x9417: + case 0xf95c: + //Unknown proprietary. return; default: throw new NotImplementedException(String.Format("EtherType: 0x{0:X4}", etherType)); @@ -3155,6 +3159,12 @@ namespace skyscraper5.Skyscraper.Scraper throw new NotImplementedException("LLC/SNAP (2)"); } } + + if (dsap == 0x09 && ssap == 0x01) + { + //Likely an LLC management packet (TEST or XID) + return; + } throw new NotImplementedException("LLC/SNAP"); }