private static uint GetCounterSize(CounterVersion version) { switch (version) { case CounterVersion.GenericCounter: case CounterVersion.FDDICounter: case CounterVersion.WANCounter: return(GenericCounterSize); case CounterVersion.VlanCounter: return(VlanCounterSize); case CounterVersion.EthernetCounter: return(EthernetCounterSize); case CounterVersion.TokenringCounter: return(TokenringCounterSize); case CounterVersion.VGCounter: return(VGCounterSize); default: System.Diagnostics.Debug.Assert(false); return(0); } }
private void createSampleCounter(CounterVersion version) { System.Random rand = new System.Random(); // generic counters are always set UInt64 v = 100000000; // 100 MB interface speed byte[] bytes = BitConverter.GetBytes(v); Array.Reverse(bytes); v = BitConverter.ToUInt64(bytes, 0); genericCounter.ifSpeed = v; // 100 MB genericCounter.ifStatus = netflow.Netflow.reverseByteOrder((uint)3); // admin & oper status = 1 genericCounter.ifDirection = netflow.Netflow.reverseByteOrder((uint)1); // full duplex genericCounter.ifType = netflow.Netflow.reverseByteOrder((uint)6); genericCounter.ifIndex = netflow.Netflow.reverseByteOrder((uint)1); genericCounter.ifInOctets = Add64BitValues(genericCounter.ifInOctets, options.NextBytes); genericCounter.ifInUcastPkts = Add32BitValues(genericCounter.ifInUcastPkts, options.NextPackets); genericCounter.ifInMulticastPkts = Add32BitValues(genericCounter.ifInMulticastPkts, options.NextPackets); genericCounter.ifInBroadcastPkts = Add32BitValues(genericCounter.ifInBroadcastPkts, options.NextPackets); genericCounter.ifInDiscards = Add32BitValues(genericCounter.ifInDiscards, options.NextPackets); genericCounter.ifInErrors = 0; genericCounter.ifInUnknownProtos = Add32BitValues(genericCounter.ifInUnknownProtos, options.NextPackets); genericCounter.ifOutOctets = Add64BitValues(genericCounter.ifOutOctets, options.NextBytes); genericCounter.ifOutUcastPkts = Add32BitValues(genericCounter.ifOutUcastPkts, options.NextPackets); genericCounter.ifOutMulticastPkts = Add32BitValues(genericCounter.ifOutMulticastPkts, options.NextPackets); genericCounter.ifOutBroadcastPkts = Add32BitValues(genericCounter.ifOutBroadcastPkts, options.NextPackets); genericCounter.ifOutDiscards = Add32BitValues(genericCounter.ifOutDiscards, options.NextPackets); genericCounter.ifOutErrors = 0; genericCounter.ifPromiscuousMode = 0; if (version == CounterVersion.GenericCounter || version == CounterVersion.WANCounter || version == CounterVersion.FDDICounter) { return; } if (version == CounterVersion.EthernetCounter) { ethernetCounter.generic = genericCounter; ethernetCounter.dot3StatsAlignmentErrors = Add32BitValues(ethernetCounter.dot3StatsAlignmentErrors, NextError(rand)); ethernetCounter.dot3StatsCarrierSenseErrors = Add32BitValues(ethernetCounter.dot3StatsCarrierSenseErrors, NextError(rand)); ethernetCounter.dot3StatsDeferredTransmissions = Add32BitValues(ethernetCounter.dot3StatsDeferredTransmissions, NextError(rand)); ethernetCounter.dot3StatsExcessiveCollisions = Add32BitValues(ethernetCounter.dot3StatsExcessiveCollisions, NextError(rand)); ethernetCounter.dot3StatsFCSErrors = Add32BitValues(ethernetCounter.dot3StatsFCSErrors, NextError(rand)); ethernetCounter.dot3StatsFrameTooLongs = Add32BitValues(ethernetCounter.dot3StatsFrameTooLongs, NextError(rand)); ethernetCounter.dot3StatsInternalMacReceiveErrors = Add32BitValues(ethernetCounter.dot3StatsInternalMacReceiveErrors, NextError(rand)); ethernetCounter.dot3StatsInternalMacTransmitErrors = Add32BitValues(ethernetCounter.dot3StatsInternalMacTransmitErrors, NextError(rand)); ethernetCounter.dot3StatsLateCollisions = Add32BitValues(ethernetCounter.dot3StatsLateCollisions, NextError(rand)); ethernetCounter.dot3StatsMultipleCollisionFrames = Add32BitValues(ethernetCounter.dot3StatsMultipleCollisionFrames, NextError(rand)); ethernetCounter.dot3StatsSingleCollisionFrames = Add32BitValues(ethernetCounter.dot3StatsSingleCollisionFrames, NextError(rand)); ethernetCounter.dot3StatsSQETestErrors = Add32BitValues(ethernetCounter.dot3StatsSQETestErrors, NextError(rand)); ethernetCounter.dot3StatsSymbolErrors = Add32BitValues(ethernetCounter.dot3StatsSymbolErrors, NextError(rand)); } else if (version == CounterVersion.VGCounter) { vgCounter.generic = genericCounter; vgCounter.dot12HCInHighPriorityOctets = Add64BitValues(vgCounter.dot12HCInHighPriorityOctets, options.NextBytes); vgCounter.dot12HCInNormPriorityOctets = Add64BitValues(vgCounter.dot12HCInNormPriorityOctets, options.NextBytes); vgCounter.dot12HCOutHighPriorityOctets = Add64BitValues(vgCounter.dot12HCOutHighPriorityOctets, options.NextBytes); vgCounter.dot12InDataErrors = Add32BitValues(vgCounter.dot12InDataErrors, NextError(rand)); vgCounter.dot12InHighPriorityFrames = Add32BitValues(vgCounter.dot12InHighPriorityFrames, options.NextPackets); vgCounter.dot12InHighPriorityOctets = Add64BitValues(vgCounter.dot12InHighPriorityOctets, options.NextBytes); vgCounter.dot12InIPMErrors = Add32BitValues(vgCounter.dot12InIPMErrors, NextError(rand)); vgCounter.dot12InNormPriorityFrames = Add32BitValues(vgCounter.dot12InNormPriorityFrames, options.NextPackets); vgCounter.dot12InNormPriorityOctets = Add64BitValues(vgCounter.dot12InNormPriorityOctets, options.NextBytes); vgCounter.dot12InNullAddressedFrames = Add32BitValues(vgCounter.dot12InNullAddressedFrames, options.NextPackets); vgCounter.dot12InOversizeFrameErrors = Add32BitValues(vgCounter.dot12InOversizeFrameErrors, NextError(rand)); vgCounter.dot12OutHighPriorityFrames = Add32BitValues(vgCounter.dot12OutHighPriorityFrames, options.NextPackets); vgCounter.dot12OutHighPriorityOctets = Add64BitValues(vgCounter.dot12OutHighPriorityOctets, options.NextBytes); vgCounter.dot12TransitionIntoTrainings = Add32BitValues(vgCounter.dot12TransitionIntoTrainings, options.NextPackets); } else if (version == CounterVersion.TokenringCounter) { tokenringCounter.generic = genericCounter; tokenringCounter.dot5StatsAbortTransErrors = Add32BitValues(tokenringCounter.dot5StatsAbortTransErrors, NextError(rand)); tokenringCounter.dot5StatsACErrors = Add32BitValues(tokenringCounter.dot5StatsACErrors, NextError(rand)); tokenringCounter.dot5StatsBurstErrors = Add32BitValues(tokenringCounter.dot5StatsBurstErrors, NextError(rand)); tokenringCounter.dot5StatsFrameCopiedErrors = Add32BitValues(tokenringCounter.dot5StatsFrameCopiedErrors, NextError(rand)); tokenringCounter.dot5StatsFreqErrors = Add32BitValues(tokenringCounter.dot5StatsFreqErrors, NextError(rand)); tokenringCounter.dot5StatsHardErrors = Add32BitValues(tokenringCounter.dot5StatsHardErrors, NextError(rand)); tokenringCounter.dot5StatsInternalErrors = Add32BitValues(tokenringCounter.dot5StatsInternalErrors, NextError(rand)); tokenringCounter.dot5StatsLineErrors = Add32BitValues(tokenringCounter.dot5StatsLineErrors, NextError(rand)); tokenringCounter.dot5StatsLobeWires = Add32BitValues(tokenringCounter.dot5StatsLobeWires, NextError(rand)); tokenringCounter.dot5StatsLostFrameErrors = Add32BitValues(tokenringCounter.dot5StatsLostFrameErrors, NextError(rand)); tokenringCounter.dot5StatsReceiveCongestions = Add32BitValues(tokenringCounter.dot5StatsReceiveCongestions, NextError(rand)); tokenringCounter.dot5StatsRecoverys = Add32BitValues(tokenringCounter.dot5StatsRecoverys, NextError(rand)); tokenringCounter.dot5StatsRemoves = Add32BitValues(tokenringCounter.dot5StatsRemoves, NextError(rand)); tokenringCounter.dot5StatsSignalLoss = Add32BitValues(tokenringCounter.dot5StatsSignalLoss, NextError(rand)); tokenringCounter.dot5StatsSingles = Add32BitValues(tokenringCounter.dot5StatsSingles, NextError(rand)); tokenringCounter.dot5StatsSoftErrors = Add32BitValues(tokenringCounter.dot5StatsSoftErrors, NextError(rand)); tokenringCounter.dot5StatsTokenErrors = Add32BitValues(tokenringCounter.dot5StatsTokenErrors, NextError(rand)); tokenringCounter.dot5StatsTransmitBeacons = Add32BitValues(tokenringCounter.dot5StatsTransmitBeacons, NextError(rand)); } else if (version == CounterVersion.VlanCounter) { vlanCounter.broadcastPkts = Add32BitValues(vlanCounter.broadcastPkts, options.NextPackets); vlanCounter.discards = Add32BitValues(vlanCounter.discards, NextError(rand)); vlanCounter.multicastPkts = Add32BitValues(vlanCounter.multicastPkts, options.NextPackets); vlanCounter.octets = Add64BitValues(vlanCounter.octets, options.NextBytes); vlanCounter.ucastPkts = Add32BitValues(vlanCounter.ucastPkts, options.NextPackets); vlanCounter.vlan_id = netflow.Netflow.reverseByteOrder(1); } }
public override ushort createPacket(ushort samples) { ushort packet_size = 0; ++sequenceNumber; v5Header.sequenceNumber = netflow.Netflow.reverseByteOrder(sequenceNumber); v5Header.numSamples = netflow.Netflow.reverseByteOrder((uint)samples); v5SampleHeader.numRecords = netflow.Netflow.reverseByteOrder((uint)1); v5SampleHeader.sequenceNumber = v5Header.sequenceNumber; v5SampleHeader.sourceId = netflow.Netflow.reverseByteOrder((uint)1); unsafe { fixed(byte *pb = packet) { byte * p = pb; sFlowV5Header *pheader = (sFlowV5Header *)p; *pheader = v5Header; p += sizeof(sFlowV5Header); packet_size += (ushort)(sizeof(sFlowV5Header)); for (int index = 1; index < simVersions.Length; ++index) { if (!simVersions[index]) { continue; } // use generic counters for now // TODO: get the counters type from GUI CounterVersion version = (CounterVersion)index; uint counterSize = GetCounterSize(version); v5SampleHeader.sampleLength = netflow.Netflow.reverseByteOrder((uint)(V5SampleHeaderSize + counterSize)); V5CounterSampleHeader *pCounterSample = (V5CounterSampleHeader *)p; *pCounterSample = v5SampleHeader; packet_size += (ushort)(sizeof(V5CounterSampleHeader)); createSampleCounter(version); Counter_Header header = new Counter_Header(); header.sampleType = netflow.Netflow.reverseByteOrder((uint)version); header.counterLength = netflow.Netflow.reverseByteOrder((uint)counterSize); p += sizeof(V5CounterSampleHeader); Counter_Header *pHeader = (Counter_Header *)p; *pHeader = header; p += sizeof(Counter_Header); packet_size += (ushort)sizeof(Counter_Header); switch (version) { case CounterVersion.GenericCounter: case CounterVersion.WANCounter: case CounterVersion.FDDICounter: Generic_Counter *pGC = (Generic_Counter *)p; *pGC = genericCounter; break; case CounterVersion.EthernetCounter: Ethernet_Counter *pEth = (Ethernet_Counter *)p; *pEth = ethernetCounter; break; case CounterVersion.TokenringCounter: Tokenring_Counter *pToken = (Tokenring_Counter *)p; *pToken = tokenringCounter; break; case CounterVersion.VGCounter: VG_Counter *pVG = (VG_Counter *)p; * pVG = vgCounter; break; case CounterVersion.VlanCounter: Vlan_Counter *pVlan = (Vlan_Counter *)p; *pVlan = vlanCounter; break; } p += counterSize; packet_size += (ushort)counterSize; } } } return(packet_size); }