/// <summary> /// Initializes a new instance of the ArpEntry class using the specified /// values. /// </summary> /// <param name="ipAddress">The IPv4 address to initialize this entry /// with.</param> /// <param name="macAddress">The MAC-48 address to initialize this entry /// with.</param> /// <exception cref="ArgumentNullException">Thrown if either argument is /// null.</exception> public ArpEntry(IpAddress ipAddress, MacAddress macAddress) { ipAddress.ThrowIfNull("ipAddress"); macAddress.ThrowIfNull("macAddress"); IpAddress = ipAddress; MacAddress = macAddress; ExpiryTime = Simulation.Time + maxAge; }
/// <summary> /// Initializes a new instance of the ArpPacket class creating an ARP /// request message. /// </summary> /// <param name="macAddressSender">The MAC-48 address of the sender.</param> /// <param name="ipAddressSender">The IPv4 address of the sender.</param> /// <param name="ipAddressTarget">The IPv4 address of the target.</param> /// <exception cref="ArgumentNullException">Thrown if any of the arguments /// is null.</exception> public ArpPacket(MacAddress macAddressSender, IpAddress ipAddressSender, IpAddress ipAddressTarget) { macAddressSender.ThrowIfNull("macAddressSender"); ipAddressSender.ThrowIfNull("ipAddressSender"); ipAddressTarget.ThrowIfNull("ipAddressTarget"); IsRequest = true; MacAddressSender = macAddressSender; IpAddressSender = ipAddressSender; IpAddressTarget = ipAddressTarget; // Broadcast to all stations. MacAddressTarget = broadcastAddress; }
/// <summary> /// Initializes a new EthernetFrame instance using the specified values. /// </summary> /// <param name="destination">The physical address of the destination /// host.</param> /// <param name="source">The physical address of the source host.</param> /// <param name="payload">The data transmitted in the frame's payload /// field.</param> /// <param name="type">The type of the encapsulated protocol.</param> /// <exception cref="ArgumentNullException">Thrown if any of the /// arguments is null.</exception> /// <exception cref="ArgumentException">Thrown if the payload parameter /// does not satisfy the Ethernet 802.3 length requirements.</exception> public Frame(MacAddress destination, MacAddress source, byte[] payload, EtherType type) { destination.ThrowIfNull("destination"); source.ThrowIfNull("source"); payload.ThrowIfNull("payload"); if (payload.Length > MaximumPayloadSize) throw new ArgumentException("The frame payload data must " + "not exceed 1500 bytes of data.", nameof(payload)); Destination = destination; Source = source; Payload = payload; Type = type; CheckSequence = Crc32.Compute( new ByteBuilder() .Append(Destination.Bytes) .Append(Source.Bytes) .Append((short)Type) .Append(Payload) .ToArray() ); }
/// <summary> /// Initializes a new instance of the ArpPacket class creating an ARP /// response message. /// </summary> /// <param name="macAddressSender">The MAC-48 address of the sender.</param> /// <param name="ipAddressSender">The IPv4 address of the sender.</param> /// <param name="macAddressTarget">The MAC-48 address of the target.</param> /// <param name="ipAddressTarget">The IPv4 address of the target.</param> /// <exception cref="ArgumentNullException">Thrown if any of the arguments /// is null.</exception> public ArpPacket(MacAddress macAddressSender, IpAddress ipAddressSender, MacAddress macAddressTarget, IpAddress ipAddressTarget) : this(macAddressSender, ipAddressSender, ipAddressTarget) { macAddressTarget.ThrowIfNull("macAddressTarget"); MacAddressTarget = macAddressTarget; IsRequest = false; }
/// <summary> /// Initializes a new instance of the EthernetFrame class using the /// specified values. /// </summary> /// <param name="destination">The physical address of the destination /// host.</param> /// <param name="source">The physical address of the source host.</param> /// <param name="payload">The data transmitted in the frame's payload /// field.</param> /// <param name="checkSequence">The value to set as the frame's /// check sequence.</param> /// <param name="type">The type of the encapsulated protocol.</param> /// <exception cref="ArgumentNullException">Thrown if any of the /// arguments is null.</exception> /// <remarks>This is a private constructor solely used for /// deserialization.</remarks> private Frame(MacAddress destination, MacAddress source, byte[] payload, uint checkSequence, EtherType type) { destination.ThrowIfNull("destination"); source.ThrowIfNull("source"); payload.ThrowIfNull("payload"); Destination = destination; Source = source; Payload = payload; Type = type; CheckSequence = checkSequence; }
/// <summary> /// Wraps the specified data into an Ethernet frame and queues it /// for transmission. /// </summary> /// <param name="destination">The MAC address of the destination /// host.</param> /// <param name="data">The data to transmit as part of the frame's /// payload.</param> /// <param name="type">The type of the data.</param> public override void Output(MacAddress destination, byte[] data, EtherType type = EtherType.IPv4) { destination.ThrowIfNull("destination"); data.ThrowIfNull("data"); // Start emptying the FIFO, if we're not already doing it. if (emptyingFifo == false) Simulation.Callback(0, EmptySendFifo); // Enqueue the data. sendFifo.Enqueue(new Frame(destination, MacAddress, data, type)); }