dist_etherlink.hh revision 11290
110923SN/A/* 210923SN/A * Copyright (c) 2015 ARM Limited 310923SN/A * All rights reserved 410923SN/A * 510923SN/A * The license below extends only to copyright in the software and shall 610923SN/A * not be construed as granting a license to any other intellectual 710923SN/A * property including but not limited to intellectual property relating 810923SN/A * to a hardware implementation of the functionality of the software 910923SN/A * licensed hereunder. You may use the software subject to the license 1010923SN/A * terms below provided that you ensure that this notice is replicated 1110923SN/A * unmodified and in its entirety in all distributions of the software, 1210923SN/A * modified or unmodified, in source code or in binary form. 1310923SN/A * 1410923SN/A * Redistribution and use in source and binary forms, with or without 1510923SN/A * modification, are permitted provided that the following conditions are 1610923SN/A * met: redistributions of source code must retain the above copyright 1710923SN/A * notice, this list of conditions and the following disclaimer; 1810923SN/A * redistributions in binary form must reproduce the above copyright 1910923SN/A * notice, this list of conditions and the following disclaimer in the 2010923SN/A * documentation and/or other materials provided with the distribution; 2110923SN/A * neither the name of the copyright holders nor the names of its 2210923SN/A * contributors may be used to endorse or promote products derived from 2310923SN/A * this software without specific prior written permission. 2410923SN/A * 2510923SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2610923SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2710923SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2810923SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2910923SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3010923SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3110923SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3210923SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3310923SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3410923SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3510923SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3610923SN/A * 3710923SN/A * Authors: Gabor Dozsa 3810923SN/A */ 3910923SN/A 4010923SN/A/* @file 4111290Sgabor.dozsa@arm.com * Device module for a full duplex ethernet link for dist gem5 simulations. 4210923SN/A * 4311290Sgabor.dozsa@arm.com * See comments in dev/net/dist_iface.hh for a generic description of dist 4410923SN/A * gem5 simulations. 4510923SN/A * 4610923SN/A * This class is meant to be a drop in replacement for the EtherLink class for 4711290Sgabor.dozsa@arm.com * dist gem5 runs. 4810923SN/A * 4910923SN/A */ 5011290Sgabor.dozsa@arm.com#ifndef __DEV_DIST_ETHERLINK_HH__ 5111290Sgabor.dozsa@arm.com#define __DEV_DIST_ETHERLINK_HH__ 5210923SN/A 5310923SN/A#include <iostream> 5410923SN/A 5511263SN/A#include "dev/net/etherlink.hh" 5611290Sgabor.dozsa@arm.com#include "params/DistEtherLink.hh" 5710923SN/A 5811290Sgabor.dozsa@arm.comclass DistIface; 5910923SN/Aclass EthPacketData; 6010923SN/A 6110923SN/A/** 6210923SN/A * Model for a fixed bandwidth full duplex ethernet link. 6310923SN/A */ 6411290Sgabor.dozsa@arm.comclass DistEtherLink : public EtherObject 6510923SN/A{ 6610923SN/A protected: 6710923SN/A class LocalIface; 6810923SN/A 6910923SN/A /** 7010923SN/A * Model base class for a single uni-directional link. 7110923SN/A * 7210923SN/A * The link will encapsulate and transfer Ethernet packets to/from 7310923SN/A * the message server. 7410923SN/A */ 7511290Sgabor.dozsa@arm.com class Link : public Serializable 7610923SN/A { 7710923SN/A protected: 7810923SN/A std::string objName; 7911290Sgabor.dozsa@arm.com DistEtherLink *parent; 8010923SN/A LocalIface *localIface; 8110923SN/A EtherDump *dump; 8211290Sgabor.dozsa@arm.com DistIface *distIface; 8310923SN/A Event *event; 8410923SN/A EthPacketPtr packet; 8510923SN/A 8610923SN/A public: 8711290Sgabor.dozsa@arm.com Link(const std::string &name, DistEtherLink *p, 8810923SN/A EtherDump *d, Event *e) : 8910923SN/A objName(name), parent(p), localIface(nullptr), dump(d), 9011290Sgabor.dozsa@arm.com distIface(nullptr), event(e) {} 9110923SN/A 9210923SN/A ~Link() {} 9310923SN/A 9410923SN/A const std::string name() const { return objName; } 9510923SN/A bool busy() const { return (bool)packet; } 9610923SN/A void setLocalInt(LocalIface *i) { assert(!localIface); localIface=i; } 9710923SN/A 9811290Sgabor.dozsa@arm.com void serialize(CheckpointOut &cp) const override; 9911290Sgabor.dozsa@arm.com void unserialize(CheckpointIn &cp) override; 10010923SN/A }; 10110923SN/A 10210923SN/A /** 10310923SN/A * Model for a send link. 10410923SN/A */ 10510923SN/A class TxLink : public Link 10610923SN/A { 10710923SN/A protected: 10810923SN/A /** 10910923SN/A * Per byte send delay 11010923SN/A */ 11110923SN/A double ticksPerByte; 11210923SN/A /** 11310923SN/A * Random component of the send delay 11410923SN/A */ 11510923SN/A Tick delayVar; 11610923SN/A 11710923SN/A /** 11810923SN/A * Send done callback. Called from doneEvent. 11910923SN/A */ 12010923SN/A void txDone(); 12110923SN/A typedef EventWrapper<TxLink, &TxLink::txDone> DoneEvent; 12210923SN/A friend void DoneEvent::process(); 12310923SN/A DoneEvent doneEvent; 12410923SN/A 12510923SN/A public: 12611290Sgabor.dozsa@arm.com TxLink(const std::string &name, DistEtherLink *p, 12710923SN/A double invBW, Tick delay_var, EtherDump *d) : 12810923SN/A Link(name, p, d, &doneEvent), ticksPerByte(invBW), 12910923SN/A delayVar(delay_var), doneEvent(this) {} 13010923SN/A ~TxLink() {} 13110923SN/A 13210923SN/A /** 13311290Sgabor.dozsa@arm.com * Register the dist interface to be used to talk to the 13410923SN/A * peer gem5 processes. 13510923SN/A */ 13611290Sgabor.dozsa@arm.com void setDistInt(DistIface *m) { assert(!distIface); distIface=m; } 13710923SN/A 13810923SN/A /** 13910923SN/A * Initiate sending of a packet via this link. 14010923SN/A * 14110923SN/A * @param packet Ethernet packet to send 14210923SN/A */ 14310923SN/A bool transmit(EthPacketPtr packet); 14410923SN/A }; 14510923SN/A 14610923SN/A /** 14710923SN/A * Model for a receive link. 14810923SN/A */ 14910923SN/A class RxLink : public Link 15010923SN/A { 15110923SN/A protected: 15210923SN/A 15310923SN/A /** 15410923SN/A * Transmission delay for the simulated Ethernet link. 15510923SN/A */ 15610923SN/A Tick linkDelay; 15710923SN/A 15810923SN/A /** 15910923SN/A * Receive done callback method. Called from doneEvent. 16010923SN/A */ 16111290Sgabor.dozsa@arm.com void rxDone(); 16210923SN/A typedef EventWrapper<RxLink, &RxLink::rxDone> DoneEvent; 16310923SN/A friend void DoneEvent::process(); 16411290Sgabor.dozsa@arm.com DoneEvent _doneEvent; 16510923SN/A 16610923SN/A public: 16710923SN/A 16811290Sgabor.dozsa@arm.com RxLink(const std::string &name, DistEtherLink *p, 16910923SN/A Tick delay, EtherDump *d) : 17011290Sgabor.dozsa@arm.com Link(name, p, d, &_doneEvent), 17111290Sgabor.dozsa@arm.com linkDelay(delay), _doneEvent(this) {} 17210923SN/A ~RxLink() {} 17310923SN/A 17410923SN/A /** 17511290Sgabor.dozsa@arm.com * Register our dist interface to talk to the peer gem5 processes. 17610923SN/A */ 17711290Sgabor.dozsa@arm.com void setDistInt(DistIface *m); 17811290Sgabor.dozsa@arm.com /** 17911290Sgabor.dozsa@arm.com * Done events will be scheduled by DistIface (so we need the accessor) 18011290Sgabor.dozsa@arm.com */ 18111290Sgabor.dozsa@arm.com const DoneEvent *doneEvent() const { return &_doneEvent; } 18210923SN/A }; 18310923SN/A 18410923SN/A /** 18510923SN/A * Interface to the local simulated system 18610923SN/A */ 18710923SN/A class LocalIface : public EtherInt 18810923SN/A { 18910923SN/A private: 19010923SN/A TxLink *txLink; 19110923SN/A 19210923SN/A public: 19310923SN/A LocalIface(const std::string &name, TxLink *tx, RxLink *rx, 19411290Sgabor.dozsa@arm.com DistIface *m); 19510923SN/A 19610923SN/A bool recvPacket(EthPacketPtr pkt) { return txLink->transmit(pkt); } 19710923SN/A void sendDone() { peer->sendDone(); } 19810923SN/A bool isBusy() { return txLink->busy(); } 19910923SN/A }; 20010923SN/A 20110923SN/A 20210923SN/A protected: 20310923SN/A /** 20410923SN/A * Interface to talk to the peer gem5 processes. 20510923SN/A */ 20611290Sgabor.dozsa@arm.com DistIface *distIface; 20710923SN/A /** 20810923SN/A * Send link 20910923SN/A */ 21010923SN/A TxLink *txLink; 21110923SN/A /** 21210923SN/A * Receive link 21310923SN/A */ 21410923SN/A RxLink *rxLink; 21510923SN/A LocalIface *localIface; 21610923SN/A 21711290Sgabor.dozsa@arm.com Tick linkDelay; 21811290Sgabor.dozsa@arm.com 21910923SN/A public: 22011290Sgabor.dozsa@arm.com typedef DistEtherLinkParams Params; 22111290Sgabor.dozsa@arm.com DistEtherLink(const Params *p); 22211290Sgabor.dozsa@arm.com ~DistEtherLink(); 22310923SN/A 22410923SN/A const Params * 22510923SN/A params() const 22610923SN/A { 22710923SN/A return dynamic_cast<const Params *>(_params); 22810923SN/A } 22910923SN/A 23010923SN/A virtual EtherInt *getEthPort(const std::string &if_name, 23111168SN/A int idx) override; 23210923SN/A 23311290Sgabor.dozsa@arm.com virtual void init() override; 23411290Sgabor.dozsa@arm.com virtual void startup() override; 23510923SN/A 23611168SN/A void serialize(CheckpointOut &cp) const override; 23711168SN/A void unserialize(CheckpointIn &cp) override; 23810923SN/A}; 23910923SN/A 24011290Sgabor.dozsa@arm.com#endif // __DEV_DIST_ETHERLINK_HH__ 241