etherlink.hh revision 2
1955SN/A/* 2955SN/A * Copyright (c) 2003 The Regents of The University of Michigan 313576Sciro.santilli@arm.com * All rights reserved. 413576Sciro.santilli@arm.com * 513576Sciro.santilli@arm.com * Redistribution and use in source and binary forms, with or without 613576Sciro.santilli@arm.com * modification, are permitted provided that the following conditions are 713576Sciro.santilli@arm.com * met: redistributions of source code must retain the above copyright 813576Sciro.santilli@arm.com * notice, this list of conditions and the following disclaimer; 913576Sciro.santilli@arm.com * redistributions in binary form must reproduce the above copyright 1013576Sciro.santilli@arm.com * notice, this list of conditions and the following disclaimer in the 1113576Sciro.santilli@arm.com * documentation and/or other materials provided with the distribution; 1213576Sciro.santilli@arm.com * neither the name of the copyright holders nor the names of its 1313576Sciro.santilli@arm.com * contributors may be used to endorse or promote products derived from 141762SN/A * this software without specific prior written permission. 15955SN/A * 16955SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17955SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18955SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19955SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20955SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21955SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22955SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23955SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24955SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25955SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26955SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27955SN/A */ 28955SN/A 29955SN/A/* @file 30955SN/A * Device module for modelling a fixed bandwidth full duplex ethernet link 31955SN/A */ 32955SN/A 33955SN/A#ifndef __ETHERLINK_HH__ 34955SN/A#define __ETHERLINK_HH__ 35955SN/A 36955SN/A#include "host.hh" 37955SN/A#include "eventq.hh" 38955SN/A#include "etherint.hh" 392665Ssaidi@eecs.umich.edu#include "etherpkt.hh" 404762Snate@binkert.org#include "sim_object.hh" 41955SN/A 4212563Sgabeblack@google.comclass EtherDump; 4312563Sgabeblack@google.com 445522Snate@binkert.org/* 456143Snate@binkert.org * Model for a fixed bandwidth full duplex ethernet link 4612371Sgabeblack@google.com */ 474762Snate@binkert.orgclass EtherLink : public SimObject 485522Snate@binkert.org{ 49955SN/A protected: 505522Snate@binkert.org class Interface; 5111974Sgabeblack@google.com 52955SN/A /* 535522Snate@binkert.org * Model for a single uni-directional link 544202Sbinkertn@umich.edu */ 555742Snate@binkert.org class Link : public Serializeable { 56955SN/A protected: 574381Sbinkertn@umich.edu Interface *txint; 584381Sbinkertn@umich.edu Interface *rxint; 5912246Sgabeblack@google.com 6012246Sgabeblack@google.com double ticks_per_byte; 618334Snate@binkert.org EtherDump *dump; 62955SN/A 63955SN/A protected: 644202Sbinkertn@umich.edu /* 65955SN/A * Transfer is complete 664382Sbinkertn@umich.edu */ 674382Sbinkertn@umich.edu class DoneEvent : public Event 684382Sbinkertn@umich.edu { 696654Snate@binkert.org protected: 705517Snate@binkert.org Link *link; 718614Sgblack@eecs.umich.edu 727674Snate@binkert.org public: 736143Snate@binkert.org DoneEvent(EventQueue *q, Link *l) 746143Snate@binkert.org : Event(q), link(l) {} 756143Snate@binkert.org virtual void process() { link->txDone(); } 7612302Sgabeblack@google.com virtual const char *description() 7712302Sgabeblack@google.com { return "ethernet link completion"; } 7812302Sgabeblack@google.com }; 7912371Sgabeblack@google.com 8012371Sgabeblack@google.com friend class DoneEvent; 8112371Sgabeblack@google.com DoneEvent event; 8212371Sgabeblack@google.com PacketPtr packet; 8312371Sgabeblack@google.com 8412371Sgabeblack@google.com void txDone(); 8512371Sgabeblack@google.com 8612371Sgabeblack@google.com public: 8712371Sgabeblack@google.com Link(const std::string &name, double rate, EtherDump *dump); 8812371Sgabeblack@google.com ~Link() {} 8912371Sgabeblack@google.com 9012371Sgabeblack@google.com bool busy() const { return (bool)packet; } 9112371Sgabeblack@google.com bool transmit(PacketPtr packet); 9212371Sgabeblack@google.com 9312371Sgabeblack@google.com void setTxInt(Interface *i) { assert(!txint); txint = i; } 9412371Sgabeblack@google.com void setRxInt(Interface *i) { assert(!rxint); rxint = i; } 9512371Sgabeblack@google.com }; 9612371Sgabeblack@google.com 9712371Sgabeblack@google.com /* 9812371Sgabeblack@google.com * Interface at each end of the link 9912371Sgabeblack@google.com */ 10012371Sgabeblack@google.com class Interface : public EtherInt 10112371Sgabeblack@google.com { 10212371Sgabeblack@google.com private: 10312371Sgabeblack@google.com Link *txlink; 10412371Sgabeblack@google.com 10512371Sgabeblack@google.com public: 10612371Sgabeblack@google.com Interface(const std::string &name, Link *txlink, Link *rxlink); 10712371Sgabeblack@google.com bool recvPacket(PacketPtr packet) { return txlink->transmit(packet); } 10812371Sgabeblack@google.com void sendDone() { } 10912371Sgabeblack@google.com }; 11012371Sgabeblack@google.com 11112371Sgabeblack@google.com Link *link1; 11212371Sgabeblack@google.com Link *link2; 11312371Sgabeblack@google.com 11412371Sgabeblack@google.com EtherInt *int1; 11512371Sgabeblack@google.com EtherInt *int2; 11612371Sgabeblack@google.com 11712371Sgabeblack@google.com public: 11812371Sgabeblack@google.com EtherLink(const std::string &name, EtherInt *i1, EtherInt *i2, 11912371Sgabeblack@google.com Tick speed, EtherDump *dump); 12012371Sgabeblack@google.com virtual ~EtherLink(); 12112371Sgabeblack@google.com}; 12212371Sgabeblack@google.com 12312371Sgabeblack@google.com#endif // __ETHERLINK_HH__ 12412371Sgabeblack@google.com