Exemple #1
0
        /// <summary>
        /// Invoked on behalf of PHY whenever new data has been received.
        /// </summary>
        /// <param name="data">The data that was received.</param>
        void OnDataReceived(byte[] data)
        {
            data.ThrowIfNull("data");
            var frame = Frame.Deserialize(data);

            WriteMac("Received an Ethernet frame.");
            // Compute checksum and compare to the one contained in the frame.
            var fcs = Frame.ComputeCheckSequence(frame);

            if (fcs != frame.CheckSequence)
            {
                WriteMac("Detected a bad frame check sequence, discarding.");
                return;
            }
            // Drop our own frames.
            if (frame.Source == MacAddress)
            {
                return;
            }
            // Examine the frame and see if it's for us; If not, discard it.
            if (frame.Destination != MacAddress &&
                frame.Destination != broadcastAddress)
            {
                WriteMac("Recipient mismatch, discarding.");
                return;
            }
            //Extract the payload and hand it up to the Network layer.
            InterruptReason = Lan.Interrupt.DataReceived;
            Interrupt.RaiseEvent(this,
                                 new DataReceivedEventArgs(frame.Payload, frame.Type));
        }
Exemple #2
0
        /// <summary>
        /// Invoked on behalf of PHY whenever new data has been received.
        /// </summary>
        /// <param name="connector"></param>
        /// <param name="data">The data that was received.</param>
        void OnDataReceived(Connector connector, byte[] data)
        {
            data.ThrowIfNull("data");
            WriteMac("Received an Ethernet frame.");
            waitTime[connector] = Simulation.Time + interframeGapTime(connector);
            var frame = Frame.Deserialize(data);
            // Compute checksum and compare to the one contained in the frame.
            var fcs = Frame.ComputeCheckSequence(frame);

            if (fcs != frame.CheckSequence)
            {
                WriteMac("Detected a bad frame check sequence, discarding.");
                return;
            }
            // Remember the port through which the frame came in.
            forwardTable[frame.Source] = connector;
            // If we know the destination and it's on the same port as the
            // source, discard the frame.
            if (forwardTable.ContainsKey(frame.Destination))
            {
                if (forwardTable[frame.Source] == forwardTable[frame.Destination])
                {
                    return;
                }
            }
            // Start emptying the FIFO, if we're not already doing it.
            if (emptyingFifos == false)
            {
                Simulation.Callback(0, EmptyFifos);
            }
            // Enqueue the data.
            inputFifo[connector].Enqueue(frame);
        }