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 dist gem5 simulations.
44 #include "dev/net/dist_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/DistEthernet.hh"
58 #include "debug/DistEthernetPkt.hh"
59 #include "debug/EthernetData.hh"
60 #include "dev/net/dist_iface.hh"
61 #include "dev/net/etherdump.hh"
62 #include "dev/net/etherint.hh"
63 #include "dev/net/etherlink.hh"
64 #include "dev/net/etherobject.hh"
65 #include "dev/net/etherpkt.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 DistEtherLink::DistEtherLink(const Params
*p
)
75 : EtherObject(p
), linkDelay(p
->delay
)
77 DPRINTF(DistEthernet
,"DistEtherLink::DistEtherLink() "
78 "link delay:%llu ticksPerByte:%f\n", p
->delay
, p
->speed
);
80 txLink
= new TxLink(name() + ".link0", this, p
->speed
, p
->delay_var
,
82 rxLink
= new RxLink(name() + ".link1", this, p
->delay
, p
->dump
);
85 if (p
->sync_repeat
!= 0) {
86 if (p
->sync_repeat
!= p
->delay
)
87 warn("DistEtherLink(): sync_repeat is %lu and linkdelay is %lu",
88 p
->sync_repeat
, p
->delay
);
89 sync_repeat
= p
->sync_repeat
;
91 sync_repeat
= p
->delay
;
94 // create the dist (TCP) interface to talk to the peer gem5 processes.
95 distIface
= new TCPIface(p
->server_name
, p
->server_port
,
96 p
->dist_rank
, p
->dist_size
,
97 p
->sync_start
, sync_repeat
, this,
98 p
->dist_sync_on_pseudo_op
, p
->is_switch
,
101 localIface
= new LocalIface(name() + ".int0", txLink
, rxLink
, distIface
);
104 DistEtherLink::~DistEtherLink()
113 DistEtherLink::getEthPort(const std::string
&if_name
, int idx
)
115 if (if_name
!= "int0") {
118 panic_if(localIface
->getPeer(), "interface already connected to");
124 DistEtherLink::serialize(CheckpointOut
&cp
) const
126 distIface
->serializeSection(cp
, "distIface");
127 txLink
->serializeSection(cp
, "txLink");
128 rxLink
->serializeSection(cp
, "rxLink");
132 DistEtherLink::unserialize(CheckpointIn
&cp
)
134 distIface
->unserializeSection(cp
, "distIface");
135 txLink
->unserializeSection(cp
, "txLink");
136 rxLink
->unserializeSection(cp
, "rxLink");
140 DistEtherLink::init()
142 DPRINTF(DistEthernet
,"DistEtherLink::init() called\n");
143 distIface
->init(rxLink
->doneEvent(), linkDelay
);
147 DistEtherLink::startup()
149 DPRINTF(DistEthernet
,"DistEtherLink::startup() called\n");
150 distIface
->startup();
154 DistEtherLink::RxLink::setDistInt(DistIface
*m
)
161 DistEtherLink::RxLink::rxDone()
165 // retrieve the packet that triggered the receive done event
166 packet
= distIface
->packetIn();
171 DPRINTF(DistEthernetPkt
, "DistEtherLink::DistLink::rxDone() "
172 "packet received: len=%d\n", packet
->length
);
173 DDUMP(EthernetData
, packet
->data
, packet
->length
);
175 localIface
->sendPacket(packet
);
181 DistEtherLink::TxLink::txDone()
189 localIface
->sendDone();
193 DistEtherLink::TxLink::transmit(EthPacketPtr pkt
)
196 DPRINTF(DistEthernet
, "packet not sent, link busy\n");
201 Tick delay
= (Tick
)ceil(((double)pkt
->simLength
* ticksPerByte
) + 1.0);
203 delay
+= random_mt
.random
<Tick
>(0, delayVar
);
205 // send the packet to the peers
207 distIface
->packetOut(pkt
, delay
);
209 // schedule the send done event
210 parent
->schedule(doneEvent
, curTick() + delay
);
216 DistEtherLink::Link::serialize(CheckpointOut
&cp
) const
218 bool packet_exists
= (packet
!= nullptr);
219 SERIALIZE_SCALAR(packet_exists
);
221 packet
->serialize("packet", cp
);
223 bool event_scheduled
= event
->scheduled();
224 SERIALIZE_SCALAR(event_scheduled
);
225 if (event_scheduled
) {
226 Tick event_time
= event
->when();
227 SERIALIZE_SCALAR(event_time
);
232 DistEtherLink::Link::unserialize(CheckpointIn
&cp
)
235 UNSERIALIZE_SCALAR(packet_exists
);
237 packet
= make_shared
<EthPacketData
>();
238 packet
->unserialize("packet", cp
);
241 bool event_scheduled
;
242 UNSERIALIZE_SCALAR(event_scheduled
);
243 if (event_scheduled
) {
245 UNSERIALIZE_SCALAR(event_time
);
246 parent
->schedule(*event
, event_time
);
250 DistEtherLink::LocalIface::LocalIface(const std::string
&name
,
254 EtherInt(name
), txLink(tx
)
256 tx
->setLocalInt(this);
257 rx
->setLocalInt(this);
263 DistEtherLinkParams::create()
265 return new DistEtherLink(this);