gem5  v20.1.0.0
etherbus.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2005 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 an ethernet hub
31  */
32 #include "dev/net/etherbus.hh"
33 
34 #include <cmath>
35 #include <deque>
36 #include <string>
37 #include <vector>
38 
39 #include "base/logging.hh"
40 #include "base/trace.hh"
41 #include "debug/Ethernet.hh"
42 #include "debug/EthernetData.hh"
43 #include "dev/net/etherdump.hh"
44 #include "dev/net/etherint.hh"
45 #include "dev/net/etherpkt.hh"
46 #include "params/EtherBus.hh"
47 #include "sim/core.hh"
48 
49 using namespace std;
50 
52  : SimObject(p), ticksPerByte(p->speed), loopback(p->loopback),
53  event([this]{ txDone(); }, "ethernet bus completion"),
54  sender(0), dump(p->dump)
55 {
56 }
57 
58 void
60 {
61  devlist_t::iterator i = devlist.begin();
62  devlist_t::iterator end = devlist.end();
63 
64  DPRINTF(Ethernet, "ethernet packet received: length=%d\n", packet->length);
65  DDUMP(EthernetData, packet->data, packet->length);
66 
67  while (i != end) {
68  if (loopback || *i != sender)
69  (*i)->sendPacket(packet);
70  ++i;
71  }
72 
73  sender->sendDone();
74 
75  if (dump)
76  dump->dump(packet);
77 
78  sender = 0;
79  packet = 0;
80 }
81 
82 Port &
83 EtherBus::getPort(const std::string &if_name, PortID idx)
84 {
85  panic("Etherbus doesn't work\n");
86 }
87 
88 bool
90 {
91  if (busy()) {
92  DPRINTF(Ethernet, "ethernet packet not sent, bus busy\n", curTick());
93  return false;
94  }
95 
96  DPRINTF(Ethernet, "ethernet packet sent: length=%d\n", pkt->length);
97  DDUMP(EthernetData, pkt->data, pkt->length);
98 
99  packet = pkt;
100  sender = sndr;
101  int delay = (int)ceil(((double)pkt->simLength * ticksPerByte) + 1.0);
102  DPRINTF(Ethernet, "scheduling packet: delay=%d, (rate=%f)\n",
103  delay, ticksPerByte);
104  schedule(event, curTick() + delay);
105 
106  return true;
107 }
108 
109 EtherBus *
110 EtherBusParams::create()
111 {
112  return new EtherBus(this);
113 }
EtherInt::sendDone
virtual void sendDone()=0
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
EtherBus::loopback
bool loopback
Definition: etherbus.hh:49
EtherInt
Definition: etherint.hh:47
etherint.hh
etherdump.hh
PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
EtherBus::ticksPerByte
double ticksPerByte
Definition: etherbus.hh:48
EtherBus::event
EventFunctionWrapper event
Definition: etherbus.hh:52
EtherBus::getPort
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: etherbus.cc:83
EtherBus::txDone
void txDone()
Definition: etherbus.cc:59
EventManager::schedule
void schedule(Event &event, Tick when)
Definition: eventq.hh:1005
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
MipsISA::event
Bitfield< 10, 5 > event
Definition: pra_constants.hh:297
Port
Ports are used to interface objects to each other.
Definition: port.hh:56
EtherBus
Definition: etherbus.hh:43
EtherBus::Params
EtherBusParams Params
Definition: etherbus.hh:58
core.hh
EtherBus::sender
EtherInt * sender
Definition: etherbus.hh:54
DDUMP
#define DDUMP(x, data, count)
DPRINTF is a debugging trace facility that allows one to selectively enable tracing statements.
Definition: trace.hh:233
EthPacketPtr
std::shared_ptr< EthPacketData > EthPacketPtr
Definition: etherpkt.hh:87
EtherBus::EtherBus
EtherBus(const Params *p)
Definition: etherbus.cc:51
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
Stats::dump
void dump()
Dump all statistics data to the registered outputs.
Definition: statistics.cc:560
EtherBus::dump
EtherDump * dump
Definition: etherbus.hh:55
EtherBus::busy
bool busy() const
Definition: etherbus.hh:70
logging.hh
EtherBus::packet
EthPacketPtr packet
Definition: etherbus.hh:53
etherpkt.hh
trace.hh
EtherBus::devlist
devlist_t devlist
Definition: etherbus.hh:47
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
EtherBus::send
bool send(EtherInt *sender, EthPacketPtr &packet)
Definition: etherbus.cc:89
EtherDump::dump
void dump(EthPacketPtr &pkt)
Definition: etherdump.hh:57
etherbus.hh
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
curTick
Tick curTick()
The current simulated tick.
Definition: core.hh:45
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:92

Generated on Wed Sep 30 2020 14:02:11 for gem5 by doxygen 1.8.17