using System; using System.Collections.Generic; using System.IO; using System.Net.NetworkInformation; using Microsoft.VisualStudio.TestTools.UnitTesting; using skyscraper5.Docsis; using skyscraper5.Docsis.AnnexC; using skyscraper5.Docsis.MacManagement; using skyscraper5.Docsis.MacManagement.BaselinePrivacyKeyManagementMessages; namespace skyscraper8.Tests.RootTests; [TestClass] public class DocsisTests : Feyllure { [TestMethod] public void MacManagementMessageTypeAttributeTest() { MacManagementMessageTypeAttribute mmmta = new MacManagementMessageTypeAttribute(1, 2); Print(mmmta.ToString()); } [TestMethod] public void RcpIdEncodingTest() { RcpIdEncoding rie = new RcpIdEncoding(new byte[] { 7, 1, 0 }); SimplifiedReceiveChannelAssignmentEncoding simplifiedReceiveChannelAssignmentEncoding = rie.SimplifiedReceiveChannelConfiguration; Assert.IsNotNull(simplifiedReceiveChannelAssignmentEncoding); Assert.Throws(() => new RcpIdEncoding(new byte[] { 255, 1, 0 })); } [TestMethod] public void EthernetLlcPacketClassificationEncodingTest() { EthernetLlcPacketClassificationEncoding epce = new EthernetLlcPacketClassificationEncoding(new byte[] { 3, 3, 1, 0, 1 }); ushort epceEProt = epce.EProt; Assert.AreEqual(1, epce.EProt); Assert.AreEqual(1, epce.Type); Assert.Throws(() => new EthernetLlcPacketClassificationEncoding(new byte[] { 255, 1, 0 })); } [TestMethod] public void SimplifiedReceiveChannelAssignmentEncodingTest() { SimplifiedReceiveChannelAssignmentEncoding srcae = new SimplifiedReceiveChannelAssignmentEncoding(new byte[] { 1, 1, 0, 2, 1, 0, 3, 1, 0 }); Assert.AreEqual(0,srcae.DownstreamChannelAssignment[0]); Assert.AreEqual(0, srcae.DownstreamProfileAssignment[0]); Assert.AreEqual(0, srcae.PrimaryDownstreamChannelAssignment[0]); Assert.Throws(() => new SimplifiedReceiveChannelAssignmentEncoding(new byte[] { 254,0,1 })); } [TestMethod] public 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.AreEqual(0, tcco.TccReferenceId.Value); Assert.AreEqual(CommonTlvEncodingObject.TransmitChannelConfigurationObject.UpstreamChannelActionEnum.NoAction, tcco.UpstreamChannelAction.Value); Assert.AreEqual(0, tcco.UpstreamChannelId.Value); Assert.IsNotNull(tcco.UpstreamChannelDescriptor); Assert.AreEqual(0, tcco.RangingSid.Value); Assert.AreEqual(InitalizationTechniqueEnum.BroadcastInitialRanging, tcco.InitializationTechnique.Value); Assert.AreEqual(0, tcco.DynamicRangeWindow); Assert.AreEqual(0, tcco.P16Hi); Assert.AreEqual(0, tcco.ListOfIucs[0]); Assert.Throws(() => new CommonTlvEncodingObject.TransmitChannelConfigurationObject(new byte[] { 254, 1, 0 })); } [TestMethod] public 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.IsNotNull(commonTlv.ModemCapabilitiesEncoding); Assert.IsNotNull(commonTlv.ServiceFlowSidClusterAssignment); Assert.IsNotNull(commonTlv.RcpId); Assert.AreEqual(0, commonTlv.KeySequenceNumber); Assert.AreEqual(0, commonTlv.HmacDigest[0]); Assert.IsNotNull(commonTlv.AuthorizationHint); Assert.AreEqual(new TimeSpan(0, 0, 1), commonTlv.InitializingChannelTimeout); ms = new MemoryStream(new byte[] { 254, 1, 0 }); Assert.Throws(() => new CommonTlvEncodingObject(ms)); } [TestMethod] public 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.IsTrue(gpce.ClassifierActivationState.Value); Assert.AreEqual(0, gpce.RulePriority.Value); Assert.IsNotNull(gpce.Ipv4PacketClassification); Assert.AreEqual(1, gpce.ServiceFlowReference.Value); Assert.AreEqual(0, gpce.ClassifierReference.Value); Assert.AreEqual(1, gpce.ClassifierIdentifier.Value); Assert.AreEqual((uint)1, gpce.ServiceFlowIdentifier.Value); Assert.AreEqual(GeneralPacketClassifierEncoding.DynamicServiceChangeActionEnum.Add, gpce.DynamicServiceChangeAction.Value); Assert.IsNotNull(gpce.EthernetLlcPacketClassificationEncodings); Assert.Throws(() => new GeneralPacketClassifierEncoding(new byte[] { 12, 4, 255, 1, 0, 0 })); Assert.Throws(() => new GeneralPacketClassifierEncoding(new byte[] { 254, 1, 0 })); } [TestMethod] 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.IsNotNull(ipce.Ipv4SourceAddress); Assert.IsNotNull(ipce.Ipv4DestinationAddress); Assert.AreEqual(1, ipce.IpProtocol.Value); Assert.IsNotNull(ipce.Ipv4SourceMask); Assert.IsNotNull(ipce.Ipv4DestinationMask); Assert.AreEqual(1, ipce.DestinationPortStart.Value); Assert.AreEqual(1, ipce.DestinationPortEnd.Value); Assert.AreEqual(1, ipce.SourcePortStart.Value); Assert.AreEqual(1, ipce.SourcePortEnd.Value); Assert.Throws(() => new GeneralPacketClassifierEncoding.Ipv4PacketClassificationEncodings(new byte[] { 255, 1, 0 })); } [TestMethod] public void ServiceFlowSidClusterAssignmentObjectTest() { ServiceFlowSidClusterAssignmentObject sfscao = new ServiceFlowSidClusterAssignmentObject(new byte[] { 1, 4, 0, 0, 0, 1, 2, 1, 0, 3, 1, 0, }); Assert.AreEqual(1u, sfscao.SFID.Value); Assert.IsNotNull(sfscao.SidClusterEncoding); Assert.IsNotNull(sfscao.SidClusterSwitchoverCriteria); Assert.Throws(() => new ServiceFlowSidClusterAssignmentObject(new byte[] { 255, 1, 0 })); } [TestMethod] public void SidClusterEncodingObjectTest() { ServiceFlowSidClusterAssignmentObject.SidClusterEncodingObject sceo = new ServiceFlowSidClusterAssignmentObject.SidClusterEncodingObject(new byte[] { 1, 1, 1, 2, 1, 0 }); Assert.AreEqual(1, sceo.SidClusterId.Value); Assert.IsNotNull(sceo.SidToChannelMapping); Assert.Throws(() => new ServiceFlowSidClusterAssignmentObject.SidClusterEncodingObject(new byte[] { 255, 1, 0 })); } [TestMethod] public void SidToChannelMappingObjectTest() { ServiceFlowSidClusterAssignmentObject.SidClusterEncodingObject.SidToChannelMappingObject stcmo = new ServiceFlowSidClusterAssignmentObject.SidClusterEncodingObject.SidToChannelMappingObject(new byte[] { 1,1,1, 2,2,0,1, 3,1,1 }); Assert.AreEqual(1, stcmo.UpstreamChannelId.Value); Assert.AreEqual(1, stcmo.SID.Value); Assert.AreEqual(ServiceFlowSidClusterAssignmentObject.SidClusterEncodingObject.SidToChannelMappingObject.ActionEnum.Add,stcmo.Action.Value); Assert.Throws(() => new ServiceFlowSidClusterAssignmentObject.SidClusterEncodingObject.SidToChannelMappingObject(new byte[] { 255, 1, 0 })); } [TestMethod] 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.IsNotNull(ipce); Assert.IsNotNull(ipce.Ipv6DestinationAddress); Assert.IsNotNull(ipce.Ipv6SourceAddress); Assert.AreEqual(0x0800, ipce.NextHeaderType); } [TestMethod] 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.AreEqual((byte)1,scsco.MaximumRequestPerSidCluster); Assert.AreEqual((uint)1, scsco.MaximumOutstandingBytesPerSidCluster); Assert.AreEqual((uint)1, scsco.MaximumTotalBytesRequestedPerSidCluster); Assert.AreEqual((ushort)1, scsco.MaximumTimeInTheSidCluster); buffer = new byte[] { 254, 1, 0 }; Assert.Throws(() => new ServiceFlowSidClusterAssignmentObject.SidClusterSwitchoverCriteriaObject(buffer)); } [TestMethod] 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.IsTrue(mcs.ConcatenationSupport); Assert.AreEqual(new Version(1, 0), mcs.DocsisVersion); Assert.IsTrue(mcs.FragmentationSupport); Assert.IsTrue(mcs.PayloadHeaderSuppressionSupport); Assert.AreEqual(ModemCapabilitiesEncoding.PrivacySupportValue.BpiPlusSupport,mcs.PrivacySupport.Value); Assert.AreEqual(1, mcs.DownstreamSaidSupport.Value); Assert.AreEqual(1, mcs.UpstreamServiceFlowSupport.Value); Assert.AreEqual(1, mcs.TransmitPreEqualizerTapsPerModulationInterval.Value); Assert.AreEqual(1, mcs.NumberOfTransmitEqualizerTaps.Value); Assert.IsTrue(mcs.DccSupport); Assert.IsNotNull(mcs.RangingHoldOffSupport); Assert.IsTrue(mcs.L2VPN); Assert.IsNotNull(mcs.ESafeHostCapability); Assert.IsTrue(mcs.DownstreamUnencryptedTrafficFiltering); Assert.AreEqual(ModemCapabilitiesEncoding.UpstreamFrequencyRangeSupportEnum.Extended, mcs.UpstreamFrequencyRangeSupport); Assert.IsTrue(mcs._160kspsSymbolRateSupport); Assert.IsTrue(mcs._320kspsSymbolRateSupport); Assert.IsTrue(mcs._640kspsSymbolRateSupport); Assert.IsTrue(mcs._1280kspsSymbolRateSupport); Assert.IsTrue(mcs._2560kspsSymbolRateSupport); Assert.IsTrue(mcs._5120kspsSymbolRateSupport); Assert.IsTrue(mcs.SelectableActiveCodeMode2Support); Assert.IsTrue(mcs.CodeHoppingMode2Support); Assert.AreEqual(2,mcs.ScQamMultipleTransmitChannelSupport.Value); Assert.AreEqual(2, mcs.TotalSidClusterSupport.Value); Assert.AreEqual(2, mcs.SidClustersPerServiceFlowSupport.Value); Assert.AreEqual(2, mcs.ScQamMultipleReceiveChannelSupport.Value); Assert.AreEqual(3, mcs.TotalDsidSupport.Value); Assert.AreEqual(3, mcs.ResequencingDsidSupport.Value); Assert.AreEqual(3, mcs.MulticastDsidSupport.Value); Assert.AreEqual(ModemCapabilitiesEncoding.MulticastDsidForwardingEnum.SupportPromiscious, mcs.MulticastDsidForwarding.Value); Assert.IsTrue(mcs.FrameControlTypeForwardingCapability); Assert.IsTrue(mcs.DpvPerPathSuppported); Assert.IsTrue(mcs.DpvPerPacketSuppported); Assert.AreEqual(3, mcs.UnsolicitedGrantServiceFlowSupport.Value); Assert.IsTrue(mcs.MapAndUcdReceiptSupport); Assert.AreEqual(3, mcs.UpstreamDropClassifierSupport); Assert.IsTrue(mcs.Ipv6Support.Value); Assert.AreEqual(4, mcs.ExtendedUpstreamTransmitPowerCapability.Value); Assert.IsTrue(mcs.CmStatusAck); Assert.IsTrue(mcs.EnergyManagement1x1Feature); Assert.IsTrue(mcs.DocsisLightSleepMode); Assert.AreEqual(4, mcs.ExtendedPacketLengthSupportCapability); Assert.AreEqual(4, mcs.OfdmMultipleReceiveChannelSupport.Value); Assert.AreEqual(5, mcs.OfdmaMultipleTransmitChannelSupport.Value); Assert.AreEqual(5, mcs.DownstreamOfdmProfileSupport.Value); Assert.IsNotNull(mcs.DownstreamOfdmChannelSubcarrierQamModulationSupport); Assert.IsNotNull(mcs.UpstreamOfdmaChannelSubcarrierQamModulationSupport); Assert.AreEqual(108, mcs.DownstreamFrequencyRangeStarting); Assert.AreEqual(1218, mcs.DownstreamFrequencyRangeUpTo); Assert.AreEqual(42, mcs.UpstreamFrequencyRangeUpTo); Assert.AreEqual(ModemCapabilitiesEncoding.DtpMode.MasterOrSlave, mcs.DocsisTimeProtocolMode.Value); Assert.AreEqual(ModemCapabilitiesEncoding.DtpPerformanceSupport.Level5, mcs.DocsisTimeProtocolPerformanceSupport.Value); Assert.AreEqual(5, mcs.Pmax); Assert.IsTrue(mcs.DownstreamFullDuplex); Assert.AreEqual(7, mcs.LowLatencySupport.Value); buffer = new byte[] { 2, 1, 1, 54, 1, 2, 55, 1, 2, 56, 1, 1, }; mcs = new ModemCapabilitiesEncoding(buffer); Assert.IsTrue(mcs._160kspsSymbolRateSupport); Assert.IsTrue(mcs._320kspsSymbolRateSupport); Assert.IsTrue(mcs._640kspsSymbolRateSupport); Assert.IsTrue(mcs._1280kspsSymbolRateSupport); Assert.IsTrue(mcs._2560kspsSymbolRateSupport); Assert.IsTrue(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.IsNull(mcs.DpvPerPathSuppported); Assert.IsNull(mcs.DpvPerPacketSuppported); Assert.IsNull(mcs.EnergyManagement1x1Feature); Assert.IsNull(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)); } [TestMethod] 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.AreEqual((ushort)1, gsfe.ServiceFlowReference); Assert.AreEqual((ushort)1, gsfe.ServiceFlowIdentifier); Assert.IsTrue(gsfe.ProvisionedSet); Assert.IsTrue(gsfe.AdmittedSet); Assert.IsTrue(gsfe.ActiveSet); Assert.AreEqual((byte)1, gsfe.TrafficPriority); Assert.AreEqual((uint)1, gsfe.UpstreamMaximumSustainedTrafficRate); Assert.AreEqual((uint)1, gsfe.MaximumTrafficBurst); Assert.AreEqual((uint)1, gsfe.MinimumReservedTrafficRate); Assert.AreEqual((ushort)1, gsfe.AssumedMinimumReservedRatePacketSize); Assert.AreEqual((ushort)1, gsfe.TimeoutForActiveQosParameters); Assert.AreEqual(1, gsfe.MaximumConcatenatedBurst); Assert.AreEqual(GeneralServiceFlowEncoding.ServiceFlowSchedulingTypeEnum.ProactiveGrantService, gsfe.ServiceFlowSchedulingType); Assert.AreEqual(1, gsfe.DownstreamResequencing.Value); Assert.AreEqual(1, gsfe.UnsolicitedGrantSize.Value); Assert.AreEqual((uint)2, gsfe.NominalGrantInterval.Value); Assert.AreEqual((uint)2, gsfe.ToleratedGrantJitter.Value); Assert.AreEqual(2, gsfe.GrantsPerInterval.Value); Assert.IsNotNull(gsfe.IpTypeOfServiceOverwrite); Assert.AreEqual((uint)2, gsfe.CmtsTimestamp.Value); Assert.AreEqual(2, gsfe.MultiplierToNumberOfBytesRequested); Assert.AreEqual((uint)3, gsfe.ServiceFlowForbiddenAttributeMask); Assert.IsTrue(gsfe.DoNotUseContentionRegions); Assert.IsTrue(gsfe.DoNotUseSegmentHeaders); Assert.IsTrue(gsfe.DropPacketsTooBigForUnsolicitedGrant); Assert.IsTrue(gsfe.DoNotSupressPayloadHeaders); Assert.IsTrue(gsfe.DoNotFragmentData); Assert.IsTrue(gsfe.DoNotConcatenateData); Assert.IsTrue(gsfe.DoNotPiggybackRequests); Assert.IsTrue(gsfe.DoNotUseRequest2ForData); Assert.IsTrue(gsfe.DoNotUseRequest2ForRequests); Assert.IsTrue(gsfe.DoNotUsePriorityRequest); Assert.IsTrue(gsfe.DoNotUseAllCms); this.Print(gsfe.ToString()); buffer = new byte[] { 17, 4, 0, 0, 0, 1 }; gsfe = new GeneralServiceFlowEncoding(buffer); Assert.AreEqual((uint)1, gsfe.NominalPollingInterval.Value); buffer = new byte[] { 254, 1, 1 }; Assert.Throws(() => new GeneralServiceFlowEncoding(buffer)); } [MacManagementMessageType(0x90,0x01)] class TestableMacManagementMessage : MacManagementMessage { public TestableMacManagementMessage(PhysicalAddress source, PhysicalAddress destination, byte[] buffer) : base(source, destination, buffer) { } } class UntestableMacManagementMessage : MacManagementMessage { public UntestableMacManagementMessage(PhysicalAddress source, PhysicalAddress destination, byte[] buffer) : base(source, destination, buffer) { } } [TestMethod] public void MacManagementMessageTest() { Random rng = new Random(); byte[] srcBuffer = new byte[6]; byte[] dstBuffer = new byte[6]; PhysicalAddress srcAddr = new PhysicalAddress(srcBuffer); PhysicalAddress dstAddr = new PhysicalAddress(dstBuffer); byte[] dataBuffer = new byte[0]; MacManagementMessageTypeAttribute expected = new MacManagementMessageTypeAttribute(0x90, 0x01); TestableMacManagementMessage tmmm = new TestableMacManagementMessage(srcAddr, dstAddr, dataBuffer); Assert.AreEqual(expected, tmmm.MessageType); Assert.AreEqual(srcAddr, tmmm.Source); Assert.AreEqual(dstAddr, tmmm.Destination); Assert.Throws(() => new TestableMacManagementMessage(srcAddr, dstAddr, null)); UntestableMacManagementMessage ummm = new UntestableMacManagementMessage(srcAddr, dstAddr, dataBuffer); Assert.IsNull(ummm.MessageType); } [TestMethod] public void UpstreamChannelDescriptorTests() { byte[] buffer = new byte[] { 1,1,1,1, //header 1,1,1, //modulation rate 2,4,0,0,0,1, //frequency 3,1,1, //preamble pattern 5,1,1, //Burst descriptor 6,1,1, 7,1,1, 15,0, 16,1,3, 23,1,2, 24,2,0,2, 25,5,0,0,0,0,2, 26,1,2, 27,1,2, 28,1,2, 29,4,0,0,0,2, 30,4,0,3,0,3, 32,1,3, 33,3,0,0,3 }; Random rng = new Random(); byte[] srcBuffer = new byte[6]; byte[] dstBuffer = new byte[6]; PhysicalAddress srcAddr = new PhysicalAddress(srcBuffer); PhysicalAddress dstAddr = new PhysicalAddress(dstBuffer); UpstreamChannelDescriptor ucd = new UpstreamChannelDescriptor(srcAddr, dstAddr, buffer); Assert.AreEqual((byte)1, ucd.ModulationRate); Assert.AreEqual(1u, ucd.Frequency.Value); Assert.AreEqual((byte)1, ucd.PreamblePattern[0]); Assert.IsNotEmpty(ucd.BurstDescriptors); Assert.AreEqual((byte)1, ucd.ExtendedPreamblePattern[0]); Assert.IsTrue(ucd.S_CDMAMode.Value); Assert.AreEqual(UpstreamChannelDescriptor.RangingRequiredEnum.ProbingRequired, ucd.RangingRequired); Assert.IsNotNull(ucd.UcdChangeIndicator); Assert.AreNotEqual(2,ucd.OfdmaTimestampSnapshot.Value); Assert.AreEqual(2, ucd.OfdmaTimestampSnapshotDivideBy20.Value); Assert.AreEqual((byte)2, ucd.OfdmaCyclicPrefixSize); Assert.AreEqual((byte)2, ucd.OfdmaRolloffPeriodSize); Assert.AreEqual((byte)2, ucd.SubcarrierSpacing); Assert.AreEqual((uint)2, ucd.CenterFrequencyOfSubcarrier0); Assert.AreEqual((ushort)3, ucd.SubcarrierExclusionBand[0].Item2); Assert.AreEqual(3, ucd.SymbolsInOfdmaFrame.Value); Assert.AreEqual(3u, ucd.RandomizationSeed); buffer = new byte[] { 0, 0, 0, 0, 31,1,1 }; Assert.Throws(() => new UpstreamChannelDescriptor(srcAddr, dstAddr, buffer)); buffer = new byte[] { 3, 3, 42, 101, 7, 1, 3 }; ucd = new UpstreamChannelDescriptor(srcAddr, dstAddr, buffer); Assert.IsNull(ucd.S_CDMAMode); Assert.AreEqual(101,ucd.DownstreamChannelId); Assert.AreEqual(42, ucd.MinislotSize); Assert.AreEqual(3, ucd.ConfigurationChangeCount); Assert.AreEqual(3, ucd.UpstreamChannelID); } [TestMethod] public void BurstDescriptorTests() { byte[] buffer = new byte[] { 1, 1,1,1, 2,1,1, 3,2,0,1, 4,2,0,1, 5,1,1, 6,1,1, 7,2,0,1, 8,1,1, 9,1,1, 10,1,2, 11,1,1, 12,1,1, 13,2,0,1, 14,1,2, 19,2,0,1, 20,2,0,2, 21,2,0x8f,255, 22,2,10,4 }; UpstreamChannelDescriptor.BurstDescriptor bd = new UpstreamChannelDescriptor.BurstDescriptor(buffer); Assert.AreEqual(1, bd.ModulationType.Value); Assert.IsTrue(bd.DifferentialEncoding.Value); Assert.AreEqual(1, bd.PreambleLength.Value); Assert.AreEqual(1, bd.PreambleValueOffset.Value); Assert.AreEqual(1, bd.FecErrorCorrection.Value); Assert.AreEqual(1, bd.FecCodewordInformationBytes.Value); Assert.AreEqual(1, bd.ScramblerSeed.Value); Assert.AreEqual(1, bd.MaximumBurstSize.Value); Assert.AreEqual(1, bd.GuardTimeSize.Value); Assert.AreEqual(UpstreamChannelDescriptor.BurstDescriptor.CodewordLength.Shortened,bd.LastCodewordLength.Value); Assert.IsTrue(bd.Scrambler.Value); Assert.AreEqual(1, bd.RsInterleaverDepth.Value); Assert.AreEqual(1, bd.RsInterleaverBlockSize.Value); Assert.AreEqual(1, bd.SubcarriersInitialRanging.Value); Assert.AreEqual(2, bd.SubcarriersFineRanging.Value); Assert.IsNotEmpty(bd.OfdmaDataProfiles); Assert.AreEqual(255, bd.OfdmaDataProfiles[0].NumberOfMinisolts); Assert.AreEqual(0x0f, bd.OfdmaDataProfiles[0].PilotPatternIndex); Assert.AreEqual(UpstreamChannelDescriptor.OfdmaDataProfile.ModulationOrderIndex._256QAM, bd.OfdmaDataProfiles[0].Modulation); Assert.AreEqual(16.0,bd.OfdmaBroadcastIrStartingPowerLevel.Value); Assert.AreEqual(1.0, bd.OfdmaBroadcastIrStartingPowerLevelIncrease.Value); Assert.AreEqual(UpstreamChannelDescriptor.BurstDescriptor.PreambleTypeEnum.QPSK1,bd.PreambleType.Value); Assert.AreEqual(1, bd.IntervalUsageCode); //TO BE CONTINUED... buffer = new byte[] { 2, 2, 1, 2, 11,1, 2, }; bd = new UpstreamChannelDescriptor.BurstDescriptor(buffer); Assert.IsFalse(bd.DifferentialEncoding.Value); Assert.IsFalse(bd.Scrambler.Value); buffer = new byte[] { 3, 2, 1, 3, 11,1, 3, }; bd = new UpstreamChannelDescriptor.BurstDescriptor(buffer); Assert.IsNull(bd.DifferentialEncoding); Assert.IsNull(bd.Scrambler); buffer = new byte[] { 4, 42, 1, 0 }; Assert.Throws(() => new UpstreamChannelDescriptor.BurstDescriptor(buffer)); } [TestMethod] public void UcdChangeIndicatorBitmaskTest() { UpstreamChannelDescriptor.UcdChangeIndicatorBitmask ucdcib = new UpstreamChannelDescriptor.UcdChangeIndicatorBitmask(0xffff); Assert.IsTrue(ucdcib.ChangeIuc14); Assert.IsTrue(ucdcib.ChangeIuc13); Assert.IsTrue(ucdcib.ChangeIuc12); Assert.IsTrue(ucdcib.ChangeIuc11); Assert.IsTrue(ucdcib.ChangeIuc10); Assert.IsTrue(ucdcib.ChangeIuc9); Assert.IsTrue(ucdcib.ChangeIuc6); Assert.IsTrue(ucdcib.ChangeIuc5); Assert.IsTrue(ucdcib.ChangeOtherParameters); Assert.IsTrue(ucdcib.ChangeUnusedSubcarrierSpecification); Assert.IsTrue(ucdcib.ChangeSubcarrierExclusionBand); Assert.AreEqual(0xffff,ucdcib.GetRawValue()); } [TestMethod] public void MultipartRegistrationResponse() { Random rng = new Random(); byte[] srcBuffer = new byte[6]; byte[] dstBuffer = new byte[6]; PhysicalAddress srcAddr = new PhysicalAddress(srcBuffer); PhysicalAddress dstAddr = new PhysicalAddress(dstBuffer); byte[] payload = new byte[] { 0,1, //SID 1, //Response 1, //Number of Fragments 1, //Fragment Sequence Number 0, //TLV encoded information }; T45_V4_MultipartRegistrationResponse mrr = new T45_V4_MultipartRegistrationResponse(srcAddr, dstAddr, payload); Assert.AreEqual(1, mrr.SID); Assert.AreEqual(1, mrr.Response); Assert.AreEqual(1, mrr.NumberOfFragments); Assert.AreEqual(1, mrr.FragmentSequenceNumber); Assert.IsNotNull(mrr.TlvEncodedInformation); } [TestMethod] public void RangingResponseTest() { Random rng = new Random(); byte[] srcBuffer = new byte[6]; byte[] dstBuffer = new byte[6]; PhysicalAddress srcAddr = new PhysicalAddress(srcBuffer); PhysicalAddress dstAddr = new PhysicalAddress(dstBuffer); byte[] payload = new byte[] { 0,1, //SID 1, //Upstream Channel ID 1,4,0,0,0,1, 2,1,1, 3,2,0,1, 4,1,1, 5,1,3, 6,4,0,0,0,1, 7,1,1, 9,1,1, 11,1,1, 12,3,7,7,3, 13,1,1, 14,1,1, 15,0, 7, 1,1,1,0,1,0,1, 16,0, 7, 1,1,1,0,1,0,1, 17,6, 1,1,1, 2,1,1, 18,3, 2,1,1, 8,1,1, 10,1,1 }; RangingResponse rr = new RangingResponse(srcAddr, dstAddr, payload); Assert.AreEqual(1, rr.SID.Value); Assert.AreEqual(1, rr.UpstreamChannelId.Value); Assert.AreEqual(1u, rr.TimingAdjust.Value); Assert.AreEqual(1, rr.PowerLevelAdjust.Value); Assert.AreEqual(1, rr.OffsetFrequencyAdjust.Value); Assert.AreEqual(1, rr.TxEqualizationData[0]); Assert.AreEqual(RangingResponse.RangingStatusEnum.Success, rr.RangingStatus); Assert.AreEqual(1u, rr.DownstreamFrequencyOverride.Value); Assert.AreEqual(1, rr.UpstreamChannelIdOverride.Value); Assert.AreEqual(1, rr.T4TimeoutMultiplier.Value); Assert.AreEqual(1.0, rr.TransmitEqualizationAdjustForOfdmaChannels.Coefficients[0].Imaginary); Assert.AreEqual(1.0,rr.TransmitEqualizationSetForOfdmaChannels.Coefficients[0].Imaginary); Assert.AreEqual(1, rr.TransmitEqualizationSet[0]); Assert.AreEqual(0.25, rr.DynamicRangeWindowUpperEdge.Value); Assert.IsTrue(rr.CommandPower.Valid); Assert.AreEqual(1, rr.CommandPower.DynamicRangeWindow.Value); Assert.AreEqual(1, rr.CommandPower.TransmitPowerLevels[0]); Assert.AreEqual(1, rr.SCdmaPowerHeadroom.Value); Assert.IsNotNull(rr.FdxCommandedPower); Assert.AreEqual(1, rr.TimingAdjustFractionalPart.Value); Assert.AreEqual(1, rr.SCdmaMaximumScheduledCodes.Value); payload = new byte[] { 0, 1, 1, 3, 1, 0 }; rr = new RangingResponse(srcAddr, dstAddr, payload); Assert.IsFalse(rr.Valid); payload = new byte[] { 0, 1, 1, 1, 1, 0 }; rr = new RangingResponse(srcAddr, dstAddr, payload); Assert.IsFalse(rr.Valid); payload = new byte[] { 0, 1, 1, 12, 3, 7, 1, 1 }; rr = new RangingResponse(srcAddr, dstAddr, payload); Assert.IsFalse(rr.UpstreamChannelAdjustments.Valid); payload = new byte[] { 0, 1, 1, 12, 3, 5, 1, 1 }; Assert.Throws(() => new RangingResponse(srcAddr, dstAddr, payload)); payload = new byte[] { 0, 1, 1, 12, 1,0 }; rr = new RangingResponse(srcAddr, dstAddr, payload); Assert.IsTrue(rr.UpstreamChannelAdjustments.Valid); payload = new byte[] { 0, 1, 1, 3, 4, 0, 0 }; rr = new RangingResponse(srcAddr, dstAddr, payload); Assert.IsFalse(rr.Valid); payload = new byte[] { 0, 1, 1, 0, 1, 1, 3, 0, 4, 1, 1 }; rr = new RangingResponse(srcAddr, dstAddr, payload); Assert.IsFalse(rr.Valid); payload = new byte[] { 0, 1, 1, 6, 3, 0, 0, 0 }; rr = new RangingResponse(srcAddr, dstAddr, payload); Assert.IsFalse(rr.Valid); payload = new byte[] { 0, 1, 1, 17, 1, 1 }; rr = new RangingResponse(srcAddr, dstAddr, payload); Assert.IsFalse(rr.Valid); payload = new byte[] { 0, 1, 1, 18, 1, 1 }; rr = new RangingResponse(srcAddr, dstAddr, payload); Assert.IsFalse(rr.Valid); payload = new byte[] { 0, 1, 1, 42, 1, 1 }; Assert.Throws(() => new RangingResponse(srcAddr, dstAddr, payload)); } [TestMethod] public void CommandPowerObjectTest() { byte[] payload = new byte[] { 0 }; RangingResponse.CommandPowerObject commandPower = new RangingResponse.CommandPowerObject(payload); Assert.IsFalse(commandPower.Valid); payload = new byte[] { 1, 4, 0, 0, 0 }; commandPower = new RangingResponse.CommandPowerObject(payload); Assert.IsFalse(commandPower.Valid); payload = new byte[] { 3, 1, 1 }; commandPower = new RangingResponse.CommandPowerObject(payload); Assert.IsFalse(commandPower.Valid); } [TestMethod] public void PrivacyKeyManagementResponseTest() { NullDocsisEventHandler nullDocsisEventHandler = new NullDocsisEventHandler(); DocsisEnvironment docsisEnvironment = new DocsisEnvironment(nullDocsisEventHandler); Random rng = new Random(); byte[] srcBuffer = new byte[6]; byte[] dstBuffer = new byte[6]; PhysicalAddress srcAddr = new PhysicalAddress(srcBuffer); PhysicalAddress dstAddr = new PhysicalAddress(dstBuffer); byte[] payload = new byte[] { 5, //Code 1, //Identifier 0, 4 + 7 + 4 + 3 + 5 + 5 + 5, //Length (von der darauf folgenden Message) //Hier beginnt die Message (length sind immer zwei bytes) 7, 0, 1, 1, 9, 0, 4, 0, 0, 0, 1, 10, 0, 1, 1, 23, 0, 5 + 5 + 5, //length für den SA descriptor //Hier fängt der SA descriptor an 12, 0, 2, 0, 1, 20, 0, 2, 2, 0, 24, 0, 1, 0, 2, }; docsisEnvironment.PushMacManagementMessage(null, 1, 13, srcAddr, dstAddr, payload); //Falsche Länge der Message payload = new byte[] { 5, //Code 1, //Identifier 0, 2, //Length (von der darauf folgenden Message) //Hier beginnt die Message 0, }; docsisEnvironment.PushMacManagementMessage(null, 1, 13, srcAddr, dstAddr, payload); //Unimplementierter message type payload = new byte[] { 42, //Code 1, //Identifier 0, 1, //Length (von der darauf folgenden Message) //Hier beginnt die Message 0, }; docsisEnvironment.PushMacManagementMessage(null, 1, 13, srcAddr, dstAddr, payload); //Auth Reply NotImplemented payload = new byte[] { 5, 1, 0, 4, 255, 0, 1, 1 }; AssertTargetInvocation(() => docsisEnvironment.PushMacManagementMessage(null, 1, 13, srcAddr, dstAddr, payload)); //Privacy Key Management Response Unimplemented Message Type payload = new byte[] { 10, 1, 0, 3, 255, 255, 255 }; AssertTargetInvocation(() => docsisEnvironment.PushMacManagementMessage(null, 1, 13, srcAddr, dstAddr, payload)); //Sa Descriptor Unimplemented TLV payload = new byte[] { 5, 1, 0, 7, //Länge für darauffolgendes 23, 0, 4, //Länge für darauffolgendes 8, 0, 1, 1 }; AssertTargetInvocation(() => docsisEnvironment.PushMacManagementMessage(null, 1, 13, srcAddr, dstAddr, payload)); payload = new byte[] { 8, //Code 1, //Identifier 0, 4 + 7 + 5 + 1 + 2 + 4 + 7 + 4 + 4, //Length für alles darauf folgende 10, 0, 1, 1, 11, 0, 4, 0, 0, 0, 1, 12, 0, 2, 0, 1, 13, //TEK parameters 0, 4 + 7 + 4 + 4, //Length für alles darauf folgende 8, 0, 1, 1, 9, 0, 4, 0, 0, 0, 1, 10, 0, 1, 1, 15, 0, 1, 1, }; docsisEnvironment.PushMacManagementMessage(null, 1, 13, srcAddr, dstAddr, payload); Queue queue = nullDocsisEventHandler.GetQueue(); while (queue.Count > 0) { PrivacyKeyManagementResponse dequeue = queue.Dequeue() as PrivacyKeyManagementResponse; Assert.AreEqual(1,dequeue.Identifier); switch (dequeue.BpkmMessage) { case AuthReply ar: Assert.AreNotEqual(255,ar.KeySequenceNumber); Assert.AreNotEqual(255u,ar.KeyLifetime); if (ar.SaDescriptor != null) { Assert.AreNotEqual(255, ar.SaDescriptor.SAID); Assert.AreNotEqual(AuthReply.SaDescriptorObject.SaTypeEnum.Dynamic, ar.SaDescriptor.SaType); Assert.AreNotEqual(AuthReply.SaDescriptorObject.DataEncryptionAlgorithmIdentifiers.Cbc128Aes, ar.SaDescriptor.DataEncryptionAlgorithm); Assert.AreEqual(AuthReply.SaDescriptorObject.DataAuthenticationIdentifiers.NoDataAuthentication, ar.SaDescriptor.DataAuthenticationAlgorithm); } if (ar.AuthKey != null) { Assert.IsNotNull(ar.AuthKey); } break; case KeyReply kr: Assert.AreNotEqual(255, kr.KeySequenceNumber.Value); Assert.IsNotNull(kr.HmacDigest); Assert.AreNotEqual(255, kr.SAID.Value); if (kr.TekParameters.Count > 0) { KeyReply.TekParameter krTekParameter = kr.TekParameters[0]; Assert.IsNotNull(krTekParameter.KeyLifetime); Assert.IsNotNull(krTekParameter.CbcIv); Assert.IsNotNull(krTekParameter.TekKeySequenceNumber); Assert.IsNotNull(krTekParameter.TEK); } break; case null: break; default: throw new NotImplementedException(dequeue.BpkmMessage.ToString()); } } } [TestMethod] public void KeyReplyTest() { byte[] payload = new byte[] { 254, 0, 1, 0 }; Assert.Throws(() => new KeyReply(payload)); } [TestMethod] public void TekParameterTest() { byte[] payload = new byte[] { 254, 0, 1, 0 }; Assert.Throws(() => new KeyReply.TekParameter(payload)); payload = new byte[] { 10, 0, 1, 1, 8, 0, 1, 2 }; KeyReply.TekParameter tekParameter = new KeyReply.TekParameter(payload); Print(tekParameter.ToString()); } [TestMethod] public void DynamicServiceAdditionResponseTest() { NullDocsisEventHandler nullDocsisEventHandler = new NullDocsisEventHandler(); DocsisEnvironment docsisEnvironment = new DocsisEnvironment(nullDocsisEventHandler); Random rng = new Random(); byte[] srcBuffer = new byte[6]; byte[] dstBuffer = new byte[6]; PhysicalAddress srcAddr = new PhysicalAddress(srcBuffer); PhysicalAddress dstAddr = new PhysicalAddress(dstBuffer); byte[] payload = new byte[] { 0, 1, //Transaction ID 1, //Confirmation Code }; docsisEnvironment.PushMacManagementMessage(null, 2, 16, srcAddr, dstAddr, payload); } [TestMethod] public void NullDocsisEventHandlerTest() { NullDocsisEventHandler nullDocsisEventHandler = new NullDocsisEventHandler(); Random rng = new Random(); byte[] srcBuffer = new byte[6]; rng.NextBytes(srcBuffer); PhysicalAddress srcAddr = new PhysicalAddress(srcBuffer); nullDocsisEventHandler.OnParticipantDetected(srcAddr); HashSet physicalAddresses = nullDocsisEventHandler.GetParticipants(); Assert.Contains(srcAddr, physicalAddresses); rng.NextBytes(srcBuffer); srcAddr = new PhysicalAddress(srcBuffer); nullDocsisEventHandler.OnCmtsTimestamp(srcAddr, 1); Assert.Contains(srcAddr, physicalAddresses); Assert.AreEqual(1u, nullDocsisEventHandler.GetTiming()); byte[] ucdPayload = new byte[] { 1, 0, 0, 1 }; byte[] dstBuffer = new byte[6]; rng.NextBytes(dstBuffer); PhysicalAddress dstAddr = new PhysicalAddress(dstBuffer); UpstreamChannelDescriptor ucd = new UpstreamChannelDescriptor(srcAddr, dstAddr, ucdPayload); nullDocsisEventHandler.OnUpstreamChannel(ucd); object dequeue = nullDocsisEventHandler.GetQueue().Dequeue(); Assert.AreEqual(ucd, dequeue); } }