2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
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.
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.
28 * Authors: Nathan Binkert
32 * Device module for modelling an ethernet hub
40 #include "base/trace.hh"
41 #include "debug/Ethernet.hh"
42 #include "debug/EthernetData.hh"
43 #include "dev/etherbus.hh"
44 #include "dev/etherdump.hh"
45 #include "dev/etherint.hh"
46 #include "dev/etherpkt.hh"
47 #include "params/EtherBus.hh"
48 #include "sim/core.hh"
52 EtherBus::EtherBus(const Params
*p
)
53 : EtherObject(p
), ticksPerByte(p
->speed
), loopback(p
->loopback
),
54 event(this), sender(0), dump(p
->dump
)
61 devlist_t::iterator i
= devlist
.begin();
62 devlist_t::iterator end
= devlist
.end();
64 DPRINTF(Ethernet
, "ethernet packet received: length=%d\n", packet
->length
);
65 DDUMP(EthernetData
, packet
->data
, packet
->length
);
68 if (loopback
|| *i
!= sender
)
69 (*i
)->sendPacket(packet
);
83 EtherBus::getEthPort(const std::string
&if_name
, int idx
)
85 panic("Etherbus doesn't work\n");
89 EtherBus::send(EtherInt
*sndr
, EthPacketPtr
&pkt
)
92 DPRINTF(Ethernet
, "ethernet packet not sent, bus busy\n", curTick());
96 DPRINTF(Ethernet
, "ethernet packet sent: length=%d\n", pkt
->length
);
97 DDUMP(EthernetData
, pkt
->data
, pkt
->length
);
101 int delay
= (int)ceil(((double)pkt
->length
* ticksPerByte
) + 1.0);
102 DPRINTF(Ethernet
, "scheduling packet: delay=%d, (rate=%f)\n",
103 delay
, ticksPerByte
);
104 schedule(event
, curTick() + delay
);
110 EtherBusParams::create()
112 return new EtherBus(this);