etherlink.hh revision 2
12030SN/A/* 22030SN/A * Copyright (c) 2003 The Regents of The University of Michigan 32054SN/A * All rights reserved. 42054SN/A * 52054SN/A * Redistribution and use in source and binary forms, with or without 62054SN/A * modification, are permitted provided that the following conditions are 72054SN/A * met: redistributions of source code must retain the above copyright 82054SN/A * notice, this list of conditions and the following disclaimer; 92054SN/A * redistributions in binary form must reproduce the above copyright 102054SN/A * notice, this list of conditions and the following disclaimer in the 112054SN/A * documentation and/or other materials provided with the distribution; 122054SN/A * neither the name of the copyright holders nor the names of its 132054SN/A * contributors may be used to endorse or promote products derived from 142054SN/A * this software without specific prior written permission. 152054SN/A * 162054SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172054SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182054SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192054SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202054SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212054SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222054SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232054SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242054SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252054SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262054SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272054SN/A */ 282665Ssaidi@eecs.umich.edu 293377Sgblack@eecs.umich.edu/* @file 302030SN/A * Device module for modelling a fixed bandwidth full duplex ethernet link 312649Ssaidi@eecs.umich.edu */ 322649Ssaidi@eecs.umich.edu 332649Ssaidi@eecs.umich.edu#ifndef __ETHERLINK_HH__ 342649Ssaidi@eecs.umich.edu#define __ETHERLINK_HH__ 352649Ssaidi@eecs.umich.edu 362649Ssaidi@eecs.umich.edu#include "host.hh" 377741Sgblack@eecs.umich.edu#include "eventq.hh" 382504SN/A#include "etherint.hh" 392030SN/A#include "etherpkt.hh" 402030SN/A#include "sim_object.hh" 412030SN/A 422030SN/Aclass EtherDump; 432030SN/A 442030SN/A/* 452030SN/A * Model for a fixed bandwidth full duplex ethernet link 462030SN/A */ 472030SN/Aclass EtherLink : public SimObject 487741Sgblack@eecs.umich.edu{ 492504SN/A protected: 502030SN/A class Interface; 517741Sgblack@eecs.umich.edu 522504SN/A /* 532030SN/A * Model for a single uni-directional link 547741Sgblack@eecs.umich.edu */ 552504SN/A class Link : public Serializeable { 562030SN/A protected: 577741Sgblack@eecs.umich.edu Interface *txint; 583388Sgblack@eecs.umich.edu Interface *rxint; 592030SN/A 607741Sgblack@eecs.umich.edu double ticks_per_byte; 612504SN/A EtherDump *dump; 62 63 protected: 64 /* 65 * Transfer is complete 66 */ 67 class DoneEvent : public Event 68 { 69 protected: 70 Link *link; 71 72 public: 73 DoneEvent(EventQueue *q, Link *l) 74 : Event(q), link(l) {} 75 virtual void process() { link->txDone(); } 76 virtual const char *description() 77 { return "ethernet link completion"; } 78 }; 79 80 friend class DoneEvent; 81 DoneEvent event; 82 PacketPtr packet; 83 84 void txDone(); 85 86 public: 87 Link(const std::string &name, double rate, EtherDump *dump); 88 ~Link() {} 89 90 bool busy() const { return (bool)packet; } 91 bool transmit(PacketPtr packet); 92 93 void setTxInt(Interface *i) { assert(!txint); txint = i; } 94 void setRxInt(Interface *i) { assert(!rxint); rxint = i; } 95 }; 96 97 /* 98 * Interface at each end of the link 99 */ 100 class Interface : public EtherInt 101 { 102 private: 103 Link *txlink; 104 105 public: 106 Interface(const std::string &name, Link *txlink, Link *rxlink); 107 bool recvPacket(PacketPtr packet) { return txlink->transmit(packet); } 108 void sendDone() { } 109 }; 110 111 Link *link1; 112 Link *link2; 113 114 EtherInt *int1; 115 EtherInt *int2; 116 117 public: 118 EtherLink(const std::string &name, EtherInt *i1, EtherInt *i2, 119 Tick speed, EtherDump *dump); 120 virtual ~EtherLink(); 121}; 122 123#endif // __ETHERLINK_HH__ 124