gem5  v22.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/cur_tick.hh"
48 
49 namespace gem5
50 {
51 
53  : SimObject(p), ticksPerByte(p.speed), loopback(p.loopback),
54  event([this]{ txDone(); }, "ethernet bus completion"),
55  sender(0), dump(p.dump)
56 {
57 }
58 
59 void
61 {
62  devlist_t::iterator i = devlist.begin();
63  devlist_t::iterator end = devlist.end();
64 
65  DPRINTF(Ethernet, "ethernet packet received: length=%d\n", packet->length);
66  DDUMP(EthernetData, packet->data, packet->length);
67 
68  while (i != end) {
69  if (loopback || *i != sender)
70  (*i)->sendPacket(packet);
71  ++i;
72  }
73 
74  sender->sendDone();
75 
76  if (dump)
77  dump->dump(packet);
78 
79  sender = 0;
80  packet = 0;
81 }
82 
83 Port &
84 EtherBus::getPort(const std::string &if_name, PortID idx)
85 {
86  panic("Etherbus doesn't work\n");
87 }
88 
89 bool
91 {
92  if (busy()) {
93  DPRINTF(Ethernet, "ethernet packet not sent, bus busy\n", curTick());
94  return false;
95  }
96 
97  DPRINTF(Ethernet, "ethernet packet sent: length=%d\n", pkt->length);
98  DDUMP(EthernetData, pkt->data, pkt->length);
99 
100  packet = pkt;
101  sender = sndr;
102  int delay = (int)ceil(((double)pkt->simLength * ticksPerByte) + 1.0);
103  DPRINTF(Ethernet, "scheduling packet: delay=%d, (rate=%f)\n",
104  delay, ticksPerByte);
105  schedule(event, curTick() + delay);
106 
107  return true;
108 }
109 
110 } // namespace gem5
#define DDUMP(x, data, count)
DPRINTF is a debugging trace facility that allows one to selectively enable tracing statements.
Definition: trace.hh:180
#define DPRINTF(x,...)
Definition: trace.hh:186
EventFunctionWrapper event
Definition: etherbus.hh:55
EthPacketPtr packet
Definition: etherbus.hh:56
EtherInt * sender
Definition: etherbus.hh:57
EtherDump * dump
Definition: etherbus.hh:58
double ticksPerByte
Definition: etherbus.hh:51
EtherBus(const Params &p)
Definition: etherbus.cc:52
EtherBusParams Params
Definition: etherbus.hh:61
bool send(EtherInt *sender, EthPacketPtr &packet)
Definition: etherbus.cc:90
void txDone()
Definition: etherbus.cc:60
bool busy() const
Definition: etherbus.hh:67
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: etherbus.cc:84
devlist_t devlist
Definition: etherbus.hh:50
void dump(EthPacketPtr &pkt)
Definition: etherdump.hh:60
virtual void sendDone()=0
Ports are used to interface objects to each other.
Definition: port.hh:62
Abstract superclass for simulation objects.
Definition: sim_object.hh:148
void schedule(Event &event, Tick when)
Definition: eventq.hh:1019
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 10, 5 > event
Bitfield< 54 > p
Definition: pagetable.hh:70
void dump()
Dump all statistics data to the registered outputs.
Definition: statistics.cc:301
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:245
std::shared_ptr< EthPacketData > EthPacketPtr
Definition: etherpkt.hh:90

Generated on Wed Dec 21 2022 10:22:34 for gem5 by doxygen 1.9.1