etherlink.hh revision 558
1/* 2 * Copyright (c) 2003 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29/* @file 30 * Device module for modelling a fixed bandwidth full duplex ethernet link 31 */ 32 33#ifndef __ETHERLINK_HH__ 34#define __ETHERLINK_HH__ 35 36#include "sim/host.hh" 37#include "sim/eventq.hh" 38#include "dev/etherint.hh" 39#include "dev/etherpkt.hh" 40#include "sim/sim_object.hh" 41 42class EtherDump; 43 44/* 45 * Model for a fixed bandwidth full duplex ethernet link 46 */ 47class EtherLink : public SimObject 48{ 49 protected: 50 class Interface; 51 52 /* 53 * Model for a single uni-directional link 54 */ 55 class Link : public Serializable { 56 protected: 57 std::string objName; 58 59 Interface *txint; 60 Interface *rxint; 61 62 double ticks_per_byte; 63 EtherDump *dump; 64 65 protected: 66 /* 67 * Transfer is complete 68 */ 69 class DoneEvent : public Event 70 { 71 protected: 72 Link *link; 73 74 public: 75 DoneEvent(EventQueue *q, Link *l) 76 : Event(q), link(l) {} 77 virtual void process() { link->txDone(); } 78 virtual const char *description() 79 { return "ethernet link completion"; } 80 }; 81 82 friend class DoneEvent; 83 DoneEvent event; 84 PacketPtr packet; 85 86 void txDone(); 87 88 public: 89 Link(const std::string &name, double rate, EtherDump *dump); 90 ~Link() {} 91 92 virtual const std::string name() const { return objName; } 93 94 bool busy() const { return (bool)packet; } 95 bool transmit(PacketPtr &packet); 96 97 void setTxInt(Interface *i) { assert(!txint); txint = i; } 98 void setRxInt(Interface *i) { assert(!rxint); rxint = i; } 99 100 virtual void serialize(std::ostream &os); 101 virtual void unserialize(Checkpoint *cp, const std::string §ion); 102 }; 103 104 /* 105 * Interface at each end of the link 106 */ 107 class Interface : public EtherInt 108 { 109 private: 110 Link *txlink; 111 112 public: 113 Interface(const std::string &name, Link *txlink, Link *rxlink); 114 bool recvPacket(PacketPtr &packet) { return txlink->transmit(packet); } 115 void sendDone() { } 116 }; 117 118 Link *link1; 119 Link *link2; 120 121 EtherInt *int1; 122 EtherInt *int2; 123 124 public: 125 EtherLink(const std::string &name, EtherInt *i1, EtherInt *i2, 126 Tick speed, EtherDump *dump); 127 virtual ~EtherLink(); 128 129 virtual void serialize(std::ostream &os); 130 virtual void unserialize(Checkpoint *cp, const std::string §ion); 131 132}; 133 134#endif // __ETHERLINK_HH__ 135