gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Authors: Nathan Binkert
29  */
30 
31 /* @file
32  * Device module for modelling an ethernet hub
33  */
34 #include "dev/net/etherbus.hh"
35 
36 #include <cmath>
37 #include <deque>
38 #include <string>
39 #include <vector>
40 
41 #include "base/logging.hh"
42 #include "base/trace.hh"
43 #include "debug/Ethernet.hh"
44 #include "debug/EthernetData.hh"
45 #include "dev/net/etherdump.hh"
46 #include "dev/net/etherint.hh"
47 #include "dev/net/etherpkt.hh"
48 #include "params/EtherBus.hh"
49 #include "sim/core.hh"
50 
51 using namespace std;
52 
54  : SimObject(p), ticksPerByte(p->speed), loopback(p->loopback),
55  event([this]{ txDone(); }, "ethernet bus completion"),
56  sender(0), dump(p->dump)
57 {
58 }
59 
60 void
62 {
63  devlist_t::iterator i = devlist.begin();
64  devlist_t::iterator end = devlist.end();
65 
66  DPRINTF(Ethernet, "ethernet packet received: length=%d\n", packet->length);
67  DDUMP(EthernetData, packet->data, packet->length);
68 
69  while (i != end) {
70  if (loopback || *i != sender)
71  (*i)->sendPacket(packet);
72  ++i;
73  }
74 
75  sender->sendDone();
76 
77  if (dump)
78  dump->dump(packet);
79 
80  sender = 0;
81  packet = 0;
82 }
83 
84 Port &
85 EtherBus::getPort(const std::string &if_name, PortID idx)
86 {
87  panic("Etherbus doesn't work\n");
88 }
89 
90 bool
92 {
93  if (busy()) {
94  DPRINTF(Ethernet, "ethernet packet not sent, bus busy\n", curTick());
95  return false;
96  }
97 
98  DPRINTF(Ethernet, "ethernet packet sent: length=%d\n", pkt->length);
99  DDUMP(EthernetData, pkt->data, pkt->length);
100 
101  packet = pkt;
102  sender = sndr;
103  int delay = (int)ceil(((double)pkt->simLength * ticksPerByte) + 1.0);
104  DPRINTF(Ethernet, "scheduling packet: delay=%d, (rate=%f)\n",
105  delay, ticksPerByte);
106  schedule(event, curTick() + delay);
107 
108  return true;
109 }
110 
111 EtherBus *
112 EtherBusParams::create()
113 {
114  return new EtherBus(this);
115 }
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
#define DPRINTF(x,...)
Definition: trace.hh:229
Ports are used to interface objects to each other.
Definition: port.hh:60
EventFunctionWrapper event
Definition: etherbus.hh:54
Bitfield< 7 > i
void txDone()
Definition: etherbus.cc:61
#define DDUMP(x, data, count)
Definition: trace.hh:228
EtherBus(const Params *p)
Definition: etherbus.cc:53
bool busy() const
Definition: etherbus.hh:72
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:586
EthPacketPtr packet
Definition: etherbus.hh:55
devlist_t devlist
Definition: etherbus.hh:49
bool send(EtherInt *sender, EthPacketPtr &packet)
Definition: etherbus.cc:91
Tick curTick()
The current simulated tick.
Definition: core.hh:47
void dump(EthPacketPtr &pkt)
Definition: etherdump.hh:59
std::shared_ptr< EthPacketData > EthPacketPtr
Definition: etherpkt.hh:90
bool loopback
Definition: etherbus.hh:51
Bitfield< 10, 5 > event
EtherDump * dump
Definition: etherbus.hh:57
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: etherbus.cc:85
EtherBusParams Params
Definition: etherbus.hh:60
double ticksPerByte
Definition: etherbus.hh:50
virtual void sendDone()=0
void schedule(Event &event, Tick when)
Definition: eventq.hh:744
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
EtherInt * sender
Definition: etherbus.hh:56
Bitfield< 0 > p
Abstract superclass for simulation objects.
Definition: sim_object.hh:96

Generated on Fri Feb 28 2020 16:27:00 for gem5 by doxygen 1.8.13