etherlink.hh revision 265
14120Sgblack@eecs.umich.edu/* 24120Sgblack@eecs.umich.edu * Copyright (c) 2003 The Regents of The University of Michigan 34120Sgblack@eecs.umich.edu * All rights reserved. 44120Sgblack@eecs.umich.edu * 54120Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 64120Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 74120Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 84120Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 94120Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 104120Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 114120Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 124120Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 134120Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 144120Sgblack@eecs.umich.edu * this software without specific prior written permission. 154120Sgblack@eecs.umich.edu * 164120Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 174120Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 184120Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 194120Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 204120Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 214120Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 224120Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 234120Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 244120Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 254120Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 264120Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 274120Sgblack@eecs.umich.edu */ 284120Sgblack@eecs.umich.edu 294120Sgblack@eecs.umich.edu/* @file 304120Sgblack@eecs.umich.edu * Device module for modelling a fixed bandwidth full duplex ethernet link 314120Sgblack@eecs.umich.edu */ 324120Sgblack@eecs.umich.edu 334120Sgblack@eecs.umich.edu#ifndef __ETHERLINK_HH__ 344120Sgblack@eecs.umich.edu#define __ETHERLINK_HH__ 354120Sgblack@eecs.umich.edu 364120Sgblack@eecs.umich.edu#include "sim/host.hh" 374120Sgblack@eecs.umich.edu#include "sim/eventq.hh" 384120Sgblack@eecs.umich.edu#include "dev/etherint.hh" 394120Sgblack@eecs.umich.edu#include "dev/etherpkt.hh" 404120Sgblack@eecs.umich.edu#include "sim/sim_object.hh" 414120Sgblack@eecs.umich.edu 424120Sgblack@eecs.umich.educlass EtherDump; 434120Sgblack@eecs.umich.edu 444120Sgblack@eecs.umich.edu/* 454120Sgblack@eecs.umich.edu * Model for a fixed bandwidth full duplex ethernet link 464120Sgblack@eecs.umich.edu */ 474120Sgblack@eecs.umich.educlass EtherLink : public SimObject 484120Sgblack@eecs.umich.edu{ 494120Sgblack@eecs.umich.edu protected: 504120Sgblack@eecs.umich.edu class Interface; 514120Sgblack@eecs.umich.edu 524120Sgblack@eecs.umich.edu /* 534120Sgblack@eecs.umich.edu * Model for a single uni-directional link 544120Sgblack@eecs.umich.edu */ 554120Sgblack@eecs.umich.edu class Link : public Serializeable { 564120Sgblack@eecs.umich.edu protected: 574120Sgblack@eecs.umich.edu std::string objName; 584120Sgblack@eecs.umich.edu 594120Sgblack@eecs.umich.edu Interface *txint; 604120Sgblack@eecs.umich.edu Interface *rxint; 614120Sgblack@eecs.umich.edu 624120Sgblack@eecs.umich.edu double ticks_per_byte; 634120Sgblack@eecs.umich.edu EtherDump *dump; 644120Sgblack@eecs.umich.edu 654120Sgblack@eecs.umich.edu protected: 664120Sgblack@eecs.umich.edu /* 674120Sgblack@eecs.umich.edu * 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 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 101 /* 102 * Interface at each end of the link 103 */ 104 class Interface : public EtherInt 105 { 106 private: 107 Link *txlink; 108 109 public: 110 Interface(const std::string &name, Link *txlink, Link *rxlink); 111 bool recvPacket(PacketPtr packet) { return txlink->transmit(packet); } 112 void sendDone() { } 113 }; 114 115 Link *link1; 116 Link *link2; 117 118 EtherInt *int1; 119 EtherInt *int2; 120 121 public: 122 EtherLink(const std::string &name, EtherInt *i1, EtherInt *i2, 123 Tick speed, EtherDump *dump); 124 virtual ~EtherLink(); 125}; 126 127#endif // __ETHERLINK_HH__ 128