etherbus.hh revision 8229
112866Sgabeblack@google.com/* 212866Sgabeblack@google.com * Copyright (c) 2002-2005 The Regents of The University of Michigan 312866Sgabeblack@google.com * All rights reserved. 412866Sgabeblack@google.com * 512866Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 612866Sgabeblack@google.com * modification, are permitted provided that the following conditions are 712866Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 812866Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 912866Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1012866Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1112866Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1212866Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1312866Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1412866Sgabeblack@google.com * this software without specific prior written permission. 1512866Sgabeblack@google.com * 1612866Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712866Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812866Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912866Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012866Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112866Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212866Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312866Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412866Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512866Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612866Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712866Sgabeblack@google.com * 2812866Sgabeblack@google.com * Authors: Nathan Binkert 2912866Sgabeblack@google.com */ 3012866Sgabeblack@google.com 3112866Sgabeblack@google.com/* @file 3212866Sgabeblack@google.com * Device module for modelling an ethernet hub 3312866Sgabeblack@google.com */ 3412866Sgabeblack@google.com 3512866Sgabeblack@google.com#ifndef __ETHERBUS_H__ 3612866Sgabeblack@google.com#define __ETHERBUS_H__ 3712866Sgabeblack@google.com 3812866Sgabeblack@google.com#include "dev/etherobject.hh" 3912866Sgabeblack@google.com#include "dev/etherpkt.hh" 4012866Sgabeblack@google.com#include "params/EtherBus.hh" 4112866Sgabeblack@google.com#include "sim/eventq.hh" 4212866Sgabeblack@google.com#include "sim/sim_object.hh" 4312866Sgabeblack@google.com 4412866Sgabeblack@google.comclass EtherDump; 4512866Sgabeblack@google.comclass EtherInt; 4612866Sgabeblack@google.comclass EtherBus : public EtherObject 4712866Sgabeblack@google.com{ 4812866Sgabeblack@google.com protected: 4912866Sgabeblack@google.com typedef std::list<EtherInt *> devlist_t; 5012866Sgabeblack@google.com devlist_t devlist; 5112866Sgabeblack@google.com double ticksPerByte; 5212866Sgabeblack@google.com bool loopback; 5312866Sgabeblack@google.com 5412866Sgabeblack@google.com protected: 5512866Sgabeblack@google.com class DoneEvent : public Event 5612866Sgabeblack@google.com { 5712866Sgabeblack@google.com protected: 5812866Sgabeblack@google.com EtherBus *bus; 5912866Sgabeblack@google.com 6012866Sgabeblack@google.com public: 6112866Sgabeblack@google.com DoneEvent(EtherBus *b) : bus(b) {} 6212866Sgabeblack@google.com virtual void process() { bus->txDone(); } 6312866Sgabeblack@google.com virtual const char *description() const 6412866Sgabeblack@google.com { return "ethernet bus completion"; } 6512866Sgabeblack@google.com }; 6612866Sgabeblack@google.com 6712866Sgabeblack@google.com DoneEvent event; 6812866Sgabeblack@google.com EthPacketPtr packet; 6912866Sgabeblack@google.com EtherInt *sender; 7012866Sgabeblack@google.com EtherDump *dump; 7112866Sgabeblack@google.com 7212866Sgabeblack@google.com public: 7312866Sgabeblack@google.com typedef EtherBusParams Params; 7412866Sgabeblack@google.com EtherBus(const Params *p); 7512866Sgabeblack@google.com virtual ~EtherBus() {} 7612866Sgabeblack@google.com 7712866Sgabeblack@google.com const Params * 7812866Sgabeblack@google.com params() const 7912866Sgabeblack@google.com { 8012866Sgabeblack@google.com return dynamic_cast<const Params *>(_params); 8112866Sgabeblack@google.com } 8212866Sgabeblack@google.com 8312866Sgabeblack@google.com void txDone(); 8412866Sgabeblack@google.com void reg(EtherInt *dev); 8512866Sgabeblack@google.com bool busy() const { return (bool)packet; } 8612866Sgabeblack@google.com bool send(EtherInt *sender, EthPacketPtr &packet); 8712866Sgabeblack@google.com virtual EtherInt *getEthPort(const std::string &if_name, int idx); 8812866Sgabeblack@google.com}; 8912866Sgabeblack@google.com 9012866Sgabeblack@google.com#endif // __ETHERBUS_H__ 9112866Sgabeblack@google.com