dist_etherlink.hh revision 11263
1955SN/A/*
2955SN/A * Copyright (c) 2015 ARM Limited
35871Snate@binkert.org * All rights reserved
41762SN/A *
5955SN/A * The license below extends only to copyright in the software and shall
6955SN/A * not be construed as granting a license to any other intellectual
7955SN/A * property including but not limited to intellectual property relating
8955SN/A * to a hardware implementation of the functionality of the software
9955SN/A * licensed hereunder.  You may use the software subject to the license
10955SN/A * terms below provided that you ensure that this notice is replicated
11955SN/A * unmodified and in its entirety in all distributions of the software,
12955SN/A * modified or unmodified, in source code or in binary form.
13955SN/A *
14955SN/A * Redistribution and use in source and binary forms, with or without
15955SN/A * modification, are permitted provided that the following conditions are
16955SN/A * met: redistributions of source code must retain the above copyright
17955SN/A * notice, this list of conditions and the following disclaimer;
18955SN/A * redistributions in binary form must reproduce the above copyright
19955SN/A * notice, this list of conditions and the following disclaimer in the
20955SN/A * documentation and/or other materials provided with the distribution;
21955SN/A * neither the name of the copyright holders nor the names of its
22955SN/A * contributors may be used to endorse or promote products derived from
23955SN/A * this software without specific prior written permission.
24955SN/A *
25955SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26955SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27955SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28955SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
292665Ssaidi@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
302665Ssaidi@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
315863Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32955SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33955SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34955SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35955SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36955SN/A *
372632Sstever@eecs.umich.edu * Authors: Gabor Dozsa
382632Sstever@eecs.umich.edu */
392632Sstever@eecs.umich.edu
402632Sstever@eecs.umich.edu/* @file
41955SN/A * Device module for a full duplex ethernet link for multi gem5 simulations.
422632Sstever@eecs.umich.edu *
432632Sstever@eecs.umich.edu * See comments in dev/multi_iface.hh for a generic description of multi
442761Sstever@eecs.umich.edu * gem5 simulations.
452632Sstever@eecs.umich.edu *
462632Sstever@eecs.umich.edu * This class is meant to be a drop in replacement for the EtherLink class for
472632Sstever@eecs.umich.edu * multi gem5 runs.
482761Sstever@eecs.umich.edu *
492761Sstever@eecs.umich.edu */
502761Sstever@eecs.umich.edu#ifndef __DEV_NET_MULTIETHERLINK_HH__
512632Sstever@eecs.umich.edu#define __DEV_NET_MULTIETHERLINK_HH__
522632Sstever@eecs.umich.edu
532761Sstever@eecs.umich.edu#include <iostream>
542761Sstever@eecs.umich.edu
552761Sstever@eecs.umich.edu#include "dev/net/etherlink.hh"
562761Sstever@eecs.umich.edu#include "params/MultiEtherLink.hh"
572761Sstever@eecs.umich.edu
582632Sstever@eecs.umich.educlass MultiIface;
592632Sstever@eecs.umich.educlass EthPacketData;
602632Sstever@eecs.umich.edu
612632Sstever@eecs.umich.edu/**
622632Sstever@eecs.umich.edu * Model for a fixed bandwidth full duplex ethernet link.
632632Sstever@eecs.umich.edu */
642632Sstever@eecs.umich.educlass MultiEtherLink : public EtherObject
65955SN/A{
66955SN/A  protected:
67955SN/A    class LocalIface;
685863Snate@binkert.org
695863Snate@binkert.org    /**
705863Snate@binkert.org     * Model base class for a single uni-directional link.
715863Snate@binkert.org     *
725863Snate@binkert.org     * The link will encapsulate and transfer Ethernet packets to/from
735863Snate@binkert.org     * the message server.
745863Snate@binkert.org     */
755863Snate@binkert.org    class Link
765863Snate@binkert.org    {
775863Snate@binkert.org      protected:
785863Snate@binkert.org        std::string objName;
795863Snate@binkert.org        MultiEtherLink *parent;
805863Snate@binkert.org        LocalIface *localIface;
815863Snate@binkert.org        EtherDump *dump;
825863Snate@binkert.org        MultiIface *multiIface;
835863Snate@binkert.org        Event *event;
845863Snate@binkert.org        EthPacketPtr packet;
855863Snate@binkert.org
865863Snate@binkert.org      public:
875863Snate@binkert.org        Link(const std::string &name, MultiEtherLink *p,
885863Snate@binkert.org             EtherDump *d, Event *e) :
895863Snate@binkert.org            objName(name), parent(p), localIface(nullptr), dump(d),
905863Snate@binkert.org            multiIface(nullptr), event(e) {}
915863Snate@binkert.org
925863Snate@binkert.org        ~Link() {}
935863Snate@binkert.org
945863Snate@binkert.org        const std::string name() const { return objName; }
955863Snate@binkert.org        bool busy() const { return (bool)packet; }
965863Snate@binkert.org        void setLocalInt(LocalIface *i) { assert(!localIface); localIface=i; }
975863Snate@binkert.org
985863Snate@binkert.org        void serialize(const std::string &base, CheckpointOut &cp) const;
996654Snate@binkert.org        void unserialize(const std::string &base, CheckpointIn &cp);
100955SN/A    };
1015396Ssaidi@eecs.umich.edu
1025863Snate@binkert.org    /**
1035863Snate@binkert.org     * Model for a send link.
1044202Sbinkertn@umich.edu     */
1055863Snate@binkert.org    class TxLink : public Link
1065863Snate@binkert.org    {
1075863Snate@binkert.org      protected:
1085863Snate@binkert.org        /**
109955SN/A         * Per byte send delay
1106654Snate@binkert.org         */
1115273Sstever@gmail.com        double ticksPerByte;
1125871Snate@binkert.org        /**
1135273Sstever@gmail.com         * Random component of the send delay
1146655Snate@binkert.org         */
1156655Snate@binkert.org        Tick delayVar;
1166655Snate@binkert.org
1176655Snate@binkert.org        /**
1186655Snate@binkert.org         * Send done callback. Called from doneEvent.
1196655Snate@binkert.org         */
1205871Snate@binkert.org        void txDone();
1216654Snate@binkert.org        typedef EventWrapper<TxLink, &TxLink::txDone> DoneEvent;
1225396Ssaidi@eecs.umich.edu        friend void DoneEvent::process();
1235871Snate@binkert.org        DoneEvent doneEvent;
1245871Snate@binkert.org
1256121Snate@binkert.org      public:
1265871Snate@binkert.org        TxLink(const std::string &name, MultiEtherLink *p,
1275871Snate@binkert.org               double invBW, Tick delay_var, EtherDump *d) :
1286003Snate@binkert.org            Link(name, p, d, &doneEvent), ticksPerByte(invBW),
1296655Snate@binkert.org            delayVar(delay_var), doneEvent(this) {}
130955SN/A        ~TxLink() {}
1315871Snate@binkert.org
1325871Snate@binkert.org        /**
1335871Snate@binkert.org         * Register the multi interface to be used to talk to the
1345871Snate@binkert.org         * peer gem5 processes.
135955SN/A         */
1366121Snate@binkert.org        void setMultiInt(MultiIface *m) { assert(!multiIface); multiIface=m; }
1376121Snate@binkert.org
1386121Snate@binkert.org        /**
1391533SN/A         * Initiate sending of a packet via this link.
1406655Snate@binkert.org         *
1416655Snate@binkert.org         * @param packet Ethernet packet to send
1426655Snate@binkert.org         */
1436655Snate@binkert.org        bool transmit(EthPacketPtr packet);
1445871Snate@binkert.org    };
1455871Snate@binkert.org
1465863Snate@binkert.org    /**
1475871Snate@binkert.org     * Model for a receive link.
1485871Snate@binkert.org     */
1495871Snate@binkert.org    class RxLink : public Link
1505871Snate@binkert.org    {
1515871Snate@binkert.org      protected:
1525863Snate@binkert.org
1536121Snate@binkert.org        /**
1545863Snate@binkert.org         * Transmission delay for the simulated Ethernet link.
1555871Snate@binkert.org         */
1564678Snate@binkert.org        Tick linkDelay;
1574678Snate@binkert.org
1584678Snate@binkert.org        /**
1594678Snate@binkert.org         * Receive done callback method. Called from doneEvent.
1604678Snate@binkert.org         */
1614678Snate@binkert.org        void rxDone() ;
1624678Snate@binkert.org        typedef EventWrapper<RxLink, &RxLink::rxDone> DoneEvent;
1634678Snate@binkert.org        friend void DoneEvent::process();
1644678Snate@binkert.org        DoneEvent doneEvent;
1654678Snate@binkert.org
1664678Snate@binkert.org      public:
1674678Snate@binkert.org
1687807Snate@binkert.org        RxLink(const std::string &name, MultiEtherLink *p,
1696121Snate@binkert.org               Tick delay, EtherDump *d) :
1704678Snate@binkert.org            Link(name, p, d, &doneEvent),
1715871Snate@binkert.org            linkDelay(delay), doneEvent(this) {}
1725871Snate@binkert.org        ~RxLink() {}
1735871Snate@binkert.org
1745871Snate@binkert.org        /**
1755871Snate@binkert.org         * Register our multi interface to talk to the peer gem5 processes.
1765871Snate@binkert.org         */
1775871Snate@binkert.org        void setMultiInt(MultiIface *m);
1785871Snate@binkert.org    };
1795871Snate@binkert.org
1805871Snate@binkert.org    /**
1815871Snate@binkert.org     * Interface to the local simulated system
1825871Snate@binkert.org     */
1835871Snate@binkert.org    class LocalIface : public EtherInt
1845990Ssaidi@eecs.umich.edu    {
1855871Snate@binkert.org      private:
1865871Snate@binkert.org        TxLink *txLink;
1875871Snate@binkert.org
1884678Snate@binkert.org      public:
1896654Snate@binkert.org        LocalIface(const std::string &name, TxLink *tx, RxLink *rx,
1905871Snate@binkert.org                   MultiIface *m);
1915871Snate@binkert.org
1925871Snate@binkert.org        bool recvPacket(EthPacketPtr pkt) { return txLink->transmit(pkt); }
1935871Snate@binkert.org        void sendDone() { peer->sendDone(); }
1945871Snate@binkert.org        bool isBusy() { return txLink->busy(); }
1955871Snate@binkert.org    };
1965871Snate@binkert.org
1975871Snate@binkert.org
1985871Snate@binkert.org  protected:
1994678Snate@binkert.org    /**
2005871Snate@binkert.org     * Interface to talk to the peer gem5 processes.
2014678Snate@binkert.org     */
2025871Snate@binkert.org    MultiIface *multiIface;
2035871Snate@binkert.org    /**
2045871Snate@binkert.org     * Send link
2055871Snate@binkert.org     */
2065871Snate@binkert.org    TxLink *txLink;
2075871Snate@binkert.org    /**
2085871Snate@binkert.org     * Receive link
2095871Snate@binkert.org     */
2105871Snate@binkert.org    RxLink *rxLink;
2116121Snate@binkert.org    LocalIface *localIface;
2126121Snate@binkert.org
2135863Snate@binkert.org  public:
214955SN/A    typedef MultiEtherLinkParams Params;
215955SN/A    MultiEtherLink(const Params *p);
2162632Sstever@eecs.umich.edu    ~MultiEtherLink();
2172632Sstever@eecs.umich.edu
218955SN/A    const Params *
219955SN/A    params() const
220955SN/A    {
221955SN/A        return dynamic_cast<const Params *>(_params);
2225863Snate@binkert.org    }
223955SN/A
2242632Sstever@eecs.umich.edu    virtual EtherInt *getEthPort(const std::string &if_name,
2252632Sstever@eecs.umich.edu                                 int idx) override;
2262632Sstever@eecs.umich.edu
2272632Sstever@eecs.umich.edu    void memWriteback() override;
2282632Sstever@eecs.umich.edu    void init() override;
2292632Sstever@eecs.umich.edu    void startup() override;
2302632Sstever@eecs.umich.edu
2312632Sstever@eecs.umich.edu    void serialize(CheckpointOut &cp) const override;
2322632Sstever@eecs.umich.edu    void unserialize(CheckpointIn &cp) override;
2332632Sstever@eecs.umich.edu};
2342632Sstever@eecs.umich.edu
2352632Sstever@eecs.umich.edu#endif // __DEV_NET_MULTIETHERLINK_HH__
2362632Sstever@eecs.umich.edu