etherlink.hh revision 4419
12810SN/A/*
212728Snikos.nikoleris@arm.com * Copyright (c) 2002-2005 The Regents of The University of Michigan
39796Sprakash.ramrakhyani@arm.com * All rights reserved.
49796Sprakash.ramrakhyani@arm.com *
59796Sprakash.ramrakhyani@arm.com * Redistribution and use in source and binary forms, with or without
69796Sprakash.ramrakhyani@arm.com * modification, are permitted provided that the following conditions are
79796Sprakash.ramrakhyani@arm.com * met: redistributions of source code must retain the above copyright
89796Sprakash.ramrakhyani@arm.com * notice, this list of conditions and the following disclaimer;
99796Sprakash.ramrakhyani@arm.com * redistributions in binary form must reproduce the above copyright
109796Sprakash.ramrakhyani@arm.com * notice, this list of conditions and the following disclaimer in the
119796Sprakash.ramrakhyani@arm.com * documentation and/or other materials provided with the distribution;
129796Sprakash.ramrakhyani@arm.com * neither the name of the copyright holders nor the names of its
139796Sprakash.ramrakhyani@arm.com * contributors may be used to endorse or promote products derived from
142810SN/A * this software without specific prior written permission.
152810SN/A *
162810SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172810SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182810SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192810SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202810SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212810SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222810SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232810SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242810SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252810SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262810SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272810SN/A *
282810SN/A * Authors: Nathan Binkert
292810SN/A */
302810SN/A
312810SN/A/* @file
322810SN/A * Device module for modelling a fixed bandwidth full duplex ethernet link
332810SN/A */
342810SN/A
352810SN/A#ifndef __DEV_ETHERLINK_HH__
362810SN/A#define __DEV_ETHERLINK_HH__
372810SN/A
382810SN/A#include "dev/etherint.hh"
392810SN/A#include "dev/etherpkt.hh"
402810SN/A#include "sim/eventq.hh"
412810SN/A#include "sim/host.hh"
422810SN/A#include "sim/sim_object.hh"
432810SN/A
442810SN/Aclass EtherDump;
452810SN/Aclass Checkpoint;
462810SN/A/*
472810SN/A * Model for a fixed bandwidth full duplex ethernet link
482810SN/A */
4911486Snikos.nikoleris@arm.comclass EtherLink : public SimObject
5011486Snikos.nikoleris@arm.com{
5112727Snikos.nikoleris@arm.com  protected:
5212727Snikos.nikoleris@arm.com    class Interface;
5312727Snikos.nikoleris@arm.com
545338Sstever@gmail.com    friend class LinkDelayEvent;
5512727Snikos.nikoleris@arm.com     /*
5612727Snikos.nikoleris@arm.com      * Model for a single uni-directional link
5712727Snikos.nikoleris@arm.com      */
582810SN/A    class Link
5912727Snikos.nikoleris@arm.com    {
602810SN/A      protected:
619796Sprakash.ramrakhyani@arm.com        std::string objName;
6211893Snikos.nikoleris@arm.com
6311893Snikos.nikoleris@arm.com        EtherLink *parent;
6411722Ssophiane.senni@gmail.com        int number;
6511722Ssophiane.senni@gmail.com
6611722Ssophiane.senni@gmail.com        Interface *txint;
6711722Ssophiane.senni@gmail.com        Interface *rxint;
6812513Sodanrc@yahoo.com.br
6912513Sodanrc@yahoo.com.br        double ticksPerByte;
7012629Sodanrc@yahoo.com.br        Tick linkDelay;
7112629Sodanrc@yahoo.com.br        Tick delayVar;
729796Sprakash.ramrakhyani@arm.com        EtherDump *dump;
739796Sprakash.ramrakhyani@arm.com
749796Sprakash.ramrakhyani@arm.com      protected:
752810SN/A        /*
762810SN/A         * Transfer is complete
772810SN/A         */
7810360Sandreas.hansson@arm.com        EthPacketPtr packet;
792810SN/A        void txDone();
802810SN/A        typedef EventWrapper<Link, &Link::txDone> DoneEvent;
812810SN/A        friend void DoneEvent::process();
822810SN/A        DoneEvent doneEvent;
8312636Sodanrc@yahoo.com.br
8412636Sodanrc@yahoo.com.br        friend class LinkDelayEvent;
8512722Snikos.nikoleris@arm.com        void txComplete(EthPacketPtr packet);
8612722Snikos.nikoleris@arm.com
8712636Sodanrc@yahoo.com.br      public:
8812636Sodanrc@yahoo.com.br        Link(const std::string &name, EtherLink *p, int num,
8912636Sodanrc@yahoo.com.br             double rate, Tick delay, Tick delay_var, EtherDump *dump);
9012636Sodanrc@yahoo.com.br        ~Link() {}
9112636Sodanrc@yahoo.com.br
9212636Sodanrc@yahoo.com.br        const std::string name() const { return objName; }
9312636Sodanrc@yahoo.com.br
9412636Sodanrc@yahoo.com.br        bool busy() const { return (bool)packet; }
9512636Sodanrc@yahoo.com.br        bool transmit(EthPacketPtr packet);
9612636Sodanrc@yahoo.com.br
9712636Sodanrc@yahoo.com.br        void setTxInt(Interface *i) { assert(!txint); txint = i; }
9812691Sodanrc@yahoo.com.br        void setRxInt(Interface *i) { assert(!rxint); rxint = i; }
9912691Sodanrc@yahoo.com.br
10012691Sodanrc@yahoo.com.br        void serialize(const std::string &base, std::ostream &os);
10112636Sodanrc@yahoo.com.br        void unserialize(const std::string &base, Checkpoint *cp,
10212703Snikos.nikoleris@arm.com                                 const std::string &section);
10312703Snikos.nikoleris@arm.com    };
10412703Snikos.nikoleris@arm.com
10512703Snikos.nikoleris@arm.com    /*
10612703Snikos.nikoleris@arm.com     * Interface at each end of the link
10712703Snikos.nikoleris@arm.com     */
10812636Sodanrc@yahoo.com.br    class Interface : public EtherInt
10912636Sodanrc@yahoo.com.br    {
11012636Sodanrc@yahoo.com.br      private:
11112636Sodanrc@yahoo.com.br        Link *txlink;
11212636Sodanrc@yahoo.com.br
11312636Sodanrc@yahoo.com.br      public:
11412728Snikos.nikoleris@arm.com        Interface(const std::string &name, Link *txlink, Link *rxlink);
11512728Snikos.nikoleris@arm.com        bool recvPacket(EthPacketPtr packet) { return txlink->transmit(packet); }
11612728Snikos.nikoleris@arm.com        void sendDone() { peer->sendDone(); }
11712728Snikos.nikoleris@arm.com        bool isBusy() { return txlink->busy(); }
11812728Snikos.nikoleris@arm.com    };
11912728Snikos.nikoleris@arm.com
12012728Snikos.nikoleris@arm.com    Link *link[2];
12112728Snikos.nikoleris@arm.com    EtherInt *interface[2];
12212728Snikos.nikoleris@arm.com
12312728Snikos.nikoleris@arm.com  public:
12412728Snikos.nikoleris@arm.com    EtherLink(const std::string &name, EtherInt *peer0, EtherInt *peer1,
12512728Snikos.nikoleris@arm.com              double rate, Tick delay, Tick delayVar, EtherDump *dump);
12612728Snikos.nikoleris@arm.com    virtual ~EtherLink();
12712728Snikos.nikoleris@arm.com
12812728Snikos.nikoleris@arm.com    virtual void serialize(std::ostream &os);
12912728Snikos.nikoleris@arm.com    virtual void unserialize(Checkpoint *cp, const std::string &section);
13012728Snikos.nikoleris@arm.com
13112728Snikos.nikoleris@arm.com};
13212728Snikos.nikoleris@arm.com
13312728Snikos.nikoleris@arm.com#endif // __ETHERLINK_HH__
13412728Snikos.nikoleris@arm.com