2 * Copyright (c) 2015 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 * Authors: Gabor Dozsa
41 * Device module for a full duplex ethernet link for multi gem5 simulations.
44 #include "dev/net/multi_etherlink.hh"
46 #include <arpa/inet.h>
47 #include <sys/socket.h>
55 #include "base/random.hh"
56 #include "base/trace.hh"
57 #include "debug/EthernetData.hh"
58 #include "debug/MultiEthernet.hh"
59 #include "debug/MultiEthernetPkt.hh"
60 #include "dev/net/etherdump.hh"
61 #include "dev/net/etherint.hh"
62 #include "dev/net/etherlink.hh"
63 #include "dev/net/etherobject.hh"
64 #include "dev/net/etherpkt.hh"
65 #include "dev/net/multi_iface.hh"
66 #include "dev/net/tcp_iface.hh"
67 #include "params/EtherLink.hh"
68 #include "sim/core.hh"
69 #include "sim/serialize.hh"
70 #include "sim/system.hh"
74 MultiEtherLink::MultiEtherLink(const Params
*p
)
77 DPRINTF(MultiEthernet
,"MultiEtherLink::MultiEtherLink() "
78 "link delay:%llu\n", p
->delay
);
80 txLink
= new TxLink(name() + ".link0", this, p
->speed
, p
->delay_var
,
82 rxLink
= new RxLink(name() + ".link1", this, p
->delay
, p
->dump
);
84 // create the multi (TCP) interface to talk to the peer gem5 processes.
85 multiIface
= new TCPIface(p
->server_name
, p
->server_port
, p
->multi_rank
,
86 p
->sync_start
, p
->sync_repeat
, this);
88 localIface
= new LocalIface(name() + ".int0", txLink
, rxLink
, multiIface
);
91 MultiEtherLink::~MultiEtherLink()
100 MultiEtherLink::getEthPort(const std::string
&if_name
, int idx
)
102 if (if_name
!= "int0") {
105 panic_if(localIface
->getPeer(), "interface already connected to");
110 void MultiEtherLink::memWriteback()
112 DPRINTF(MultiEthernet
,"MultiEtherLink::memWriteback() called\n");
113 multiIface
->drainDone();
117 MultiEtherLink::serialize(CheckpointOut
&cp
) const
119 multiIface
->serialize("multiIface", cp
);
120 txLink
->serialize("txLink", cp
);
121 rxLink
->serialize("rxLink", cp
);
125 MultiEtherLink::unserialize(CheckpointIn
&cp
)
127 multiIface
->unserialize("multiIface", cp
);
128 txLink
->unserialize("txLink", cp
);
129 rxLink
->unserialize("rxLink", cp
);
133 MultiEtherLink::init()
135 DPRINTF(MultiEthernet
,"MultiEtherLink::init() called\n");
136 multiIface
->initRandom();
140 MultiEtherLink::startup()
142 DPRINTF(MultiEthernet
,"MultiEtherLink::startup() called\n");
143 multiIface
->startPeriodicSync();
147 MultiEtherLink::RxLink::setMultiInt(MultiIface
*m
)
151 // Spawn a new receiver thread that will process messages
152 // coming in from peer gem5 processes.
153 // The receive thread will also schedule a (receive) doneEvent
154 // for each incoming data packet.
155 multiIface
->spawnRecvThread(&doneEvent
, linkDelay
);
159 MultiEtherLink::RxLink::rxDone()
163 // retrieve the packet that triggered the receive done event
164 packet
= multiIface
->packetIn();
169 DPRINTF(MultiEthernetPkt
, "MultiEtherLink::MultiLink::rxDone() "
170 "packet received: len=%d\n", packet
->length
);
171 DDUMP(EthernetData
, packet
->data
, packet
->length
);
173 localIface
->sendPacket(packet
);
179 MultiEtherLink::TxLink::txDone()
187 localIface
->sendDone();
191 MultiEtherLink::TxLink::transmit(EthPacketPtr pkt
)
194 DPRINTF(MultiEthernet
, "packet not sent, link busy\n");
199 Tick delay
= (Tick
)ceil(((double)pkt
->length
* ticksPerByte
) + 1.0);
201 delay
+= random_mt
.random
<Tick
>(0, delayVar
);
203 // send the packet to the peers
205 multiIface
->packetOut(pkt
, delay
);
207 // schedule the send done event
208 parent
->schedule(doneEvent
, curTick() + delay
);
214 MultiEtherLink::Link::serialize(const string
&base
, CheckpointOut
&cp
) const
216 bool packet_exists
= (packet
!= nullptr);
217 paramOut(cp
, base
+ ".packet_exists", packet_exists
);
219 packet
->serialize(base
+ ".packet", cp
);
221 bool event_scheduled
= event
->scheduled();
222 paramOut(cp
, base
+ ".event_scheduled", event_scheduled
);
223 if (event_scheduled
) {
224 Tick event_time
= event
->when();
225 paramOut(cp
, base
+ ".event_time", event_time
);
230 MultiEtherLink::Link::unserialize(const string
&base
, CheckpointIn
&cp
)
233 paramIn(cp
, base
+ ".packet_exists", packet_exists
);
235 packet
= make_shared
<EthPacketData
>(16384);
236 packet
->unserialize(base
+ ".packet", cp
);
239 bool event_scheduled
;
240 paramIn(cp
, base
+ ".event_scheduled", event_scheduled
);
241 if (event_scheduled
) {
243 paramIn(cp
, base
+ ".event_time", event_time
);
244 parent
->schedule(*event
, event_time
);
248 MultiEtherLink::LocalIface::LocalIface(const std::string
&name
,
252 EtherInt(name
), txLink(tx
)
254 tx
->setLocalInt(this);
255 rx
->setLocalInt(this);
261 MultiEtherLinkParams::create()
263 return new MultiEtherLink(this);