dist_etherlink.hh (13766:4ecebdee8da4) dist_etherlink.hh (13784:1941dc118243)
1/*
2 * Copyright (c) 2015 ARM Limited
3 * All rights reserved
4 *
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.
13 *
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.
24 *
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.
36 *
37 * Authors: Gabor Dozsa
38 */
39
40/* @file
41 * Device module for a full duplex ethernet link for dist gem5 simulations.
42 *
43 * See comments in dev/net/dist_iface.hh for a generic description of dist
44 * gem5 simulations.
45 *
46 * This class is meant to be a drop in replacement for the EtherLink class for
47 * dist gem5 runs.
48 *
49 */
50#ifndef __DEV_DIST_ETHERLINK_HH__
51#define __DEV_DIST_ETHERLINK_HH__
52
53#include <iostream>
54
55#include "dev/net/etherlink.hh"
1/*
2 * Copyright (c) 2015 ARM Limited
3 * All rights reserved
4 *
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.
13 *
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.
24 *
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.
36 *
37 * Authors: Gabor Dozsa
38 */
39
40/* @file
41 * Device module for a full duplex ethernet link for dist gem5 simulations.
42 *
43 * See comments in dev/net/dist_iface.hh for a generic description of dist
44 * gem5 simulations.
45 *
46 * This class is meant to be a drop in replacement for the EtherLink class for
47 * dist gem5 runs.
48 *
49 */
50#ifndef __DEV_DIST_ETHERLINK_HH__
51#define __DEV_DIST_ETHERLINK_HH__
52
53#include <iostream>
54
55#include "dev/net/etherlink.hh"
56#include "dev/net/etherobject.hh"
57#include "params/DistEtherLink.hh"
58
59class DistIface;
60class EthPacketData;
61
62/**
63 * Model for a fixed bandwidth full duplex ethernet link.
64 */
56#include "params/DistEtherLink.hh"
57
58class DistIface;
59class EthPacketData;
60
61/**
62 * Model for a fixed bandwidth full duplex ethernet link.
63 */
65class DistEtherLink : public SimObject, public EtherObject
64class DistEtherLink : public SimObject
66{
67 protected:
68 class LocalIface;
69
70 /**
71 * Model base class for a single uni-directional link.
72 *
73 * The link will encapsulate and transfer Ethernet packets to/from
74 * the message server.
75 */
76 class Link : public Serializable
77 {
78 protected:
79 std::string objName;
80 DistEtherLink *parent;
81 LocalIface *localIface;
82 EtherDump *dump;
83 DistIface *distIface;
84 Event *event;
85 EthPacketPtr packet;
86
87 public:
88 Link(const std::string &name, DistEtherLink *p,
89 EtherDump *d, Event *e) :
90 objName(name), parent(p), localIface(nullptr), dump(d),
91 distIface(nullptr), event(e) {}
92
93 ~Link() {}
94
95 const std::string name() const { return objName; }
96 bool busy() const { return (bool)packet; }
97 void setLocalInt(LocalIface *i) { assert(!localIface); localIface=i; }
98
99 void serialize(CheckpointOut &cp) const override;
100 void unserialize(CheckpointIn &cp) override;
101 };
102
103 /**
104 * Model for a send link.
105 */
106 class TxLink : public Link
107 {
108 protected:
109 /**
110 * Per byte send delay
111 */
112 double ticksPerByte;
113 /**
114 * Random component of the send delay
115 */
116 Tick delayVar;
117
118 /**
119 * Send done callback. Called from doneEvent.
120 */
121 void txDone();
122 EventFunctionWrapper doneEvent;
123
124 public:
125 TxLink(const std::string &name, DistEtherLink *p,
126 double invBW, Tick delay_var, EtherDump *d) :
127 Link(name, p, d, &doneEvent), ticksPerByte(invBW),
128 delayVar(delay_var), doneEvent([this]{ txDone(); }, name) {}
129 ~TxLink() {}
130
131 /**
132 * Register the dist interface to be used to talk to the
133 * peer gem5 processes.
134 */
135 void setDistInt(DistIface *m) { assert(!distIface); distIface=m; }
136
137 /**
138 * Initiate sending of a packet via this link.
139 *
140 * @param packet Ethernet packet to send
141 */
142 bool transmit(EthPacketPtr packet);
143 };
144
145 /**
146 * Model for a receive link.
147 */
148 class RxLink : public Link
149 {
150 protected:
151
152 /**
153 * Transmission delay for the simulated Ethernet link.
154 */
155 Tick linkDelay;
156
157 /**
158 * Receive done callback method. Called from doneEvent.
159 */
160 void rxDone();
161 EventFunctionWrapper _doneEvent;
162
163 public:
164
165 RxLink(const std::string &name, DistEtherLink *p,
166 Tick delay, EtherDump *d) :
167 Link(name, p, d, &_doneEvent), linkDelay(delay),
168 _doneEvent([this]{ rxDone(); }, name) {}
169 ~RxLink() {}
170
171 /**
172 * Register our dist interface to talk to the peer gem5 processes.
173 */
174 void setDistInt(DistIface *m);
175 /**
176 * Done events will be scheduled by DistIface (so we need the accessor)
177 */
178 const EventFunctionWrapper *doneEvent() const { return &_doneEvent; }
179 };
180
181 /**
182 * Interface to the local simulated system
183 */
184 class LocalIface : public EtherInt
185 {
186 private:
187 TxLink *txLink;
188
189 public:
190 LocalIface(const std::string &name, TxLink *tx, RxLink *rx,
191 DistIface *m);
192
193 bool recvPacket(EthPacketPtr pkt) { return txLink->transmit(pkt); }
194 void sendDone() { peer->sendDone(); }
195 bool isBusy() { return txLink->busy(); }
196 };
197
198
199 protected:
200 /**
201 * Interface to talk to the peer gem5 processes.
202 */
203 DistIface *distIface;
204 /**
205 * Send link
206 */
207 TxLink *txLink;
208 /**
209 * Receive link
210 */
211 RxLink *rxLink;
212 LocalIface *localIface;
213
214 Tick linkDelay;
215
216 public:
217 typedef DistEtherLinkParams Params;
218 DistEtherLink(const Params *p);
219 ~DistEtherLink();
220
221 const Params *
222 params() const
223 {
224 return dynamic_cast<const Params *>(_params);
225 }
226
65{
66 protected:
67 class LocalIface;
68
69 /**
70 * Model base class for a single uni-directional link.
71 *
72 * The link will encapsulate and transfer Ethernet packets to/from
73 * the message server.
74 */
75 class Link : public Serializable
76 {
77 protected:
78 std::string objName;
79 DistEtherLink *parent;
80 LocalIface *localIface;
81 EtherDump *dump;
82 DistIface *distIface;
83 Event *event;
84 EthPacketPtr packet;
85
86 public:
87 Link(const std::string &name, DistEtherLink *p,
88 EtherDump *d, Event *e) :
89 objName(name), parent(p), localIface(nullptr), dump(d),
90 distIface(nullptr), event(e) {}
91
92 ~Link() {}
93
94 const std::string name() const { return objName; }
95 bool busy() const { return (bool)packet; }
96 void setLocalInt(LocalIface *i) { assert(!localIface); localIface=i; }
97
98 void serialize(CheckpointOut &cp) const override;
99 void unserialize(CheckpointIn &cp) override;
100 };
101
102 /**
103 * Model for a send link.
104 */
105 class TxLink : public Link
106 {
107 protected:
108 /**
109 * Per byte send delay
110 */
111 double ticksPerByte;
112 /**
113 * Random component of the send delay
114 */
115 Tick delayVar;
116
117 /**
118 * Send done callback. Called from doneEvent.
119 */
120 void txDone();
121 EventFunctionWrapper doneEvent;
122
123 public:
124 TxLink(const std::string &name, DistEtherLink *p,
125 double invBW, Tick delay_var, EtherDump *d) :
126 Link(name, p, d, &doneEvent), ticksPerByte(invBW),
127 delayVar(delay_var), doneEvent([this]{ txDone(); }, name) {}
128 ~TxLink() {}
129
130 /**
131 * Register the dist interface to be used to talk to the
132 * peer gem5 processes.
133 */
134 void setDistInt(DistIface *m) { assert(!distIface); distIface=m; }
135
136 /**
137 * Initiate sending of a packet via this link.
138 *
139 * @param packet Ethernet packet to send
140 */
141 bool transmit(EthPacketPtr packet);
142 };
143
144 /**
145 * Model for a receive link.
146 */
147 class RxLink : public Link
148 {
149 protected:
150
151 /**
152 * Transmission delay for the simulated Ethernet link.
153 */
154 Tick linkDelay;
155
156 /**
157 * Receive done callback method. Called from doneEvent.
158 */
159 void rxDone();
160 EventFunctionWrapper _doneEvent;
161
162 public:
163
164 RxLink(const std::string &name, DistEtherLink *p,
165 Tick delay, EtherDump *d) :
166 Link(name, p, d, &_doneEvent), linkDelay(delay),
167 _doneEvent([this]{ rxDone(); }, name) {}
168 ~RxLink() {}
169
170 /**
171 * Register our dist interface to talk to the peer gem5 processes.
172 */
173 void setDistInt(DistIface *m);
174 /**
175 * Done events will be scheduled by DistIface (so we need the accessor)
176 */
177 const EventFunctionWrapper *doneEvent() const { return &_doneEvent; }
178 };
179
180 /**
181 * Interface to the local simulated system
182 */
183 class LocalIface : public EtherInt
184 {
185 private:
186 TxLink *txLink;
187
188 public:
189 LocalIface(const std::string &name, TxLink *tx, RxLink *rx,
190 DistIface *m);
191
192 bool recvPacket(EthPacketPtr pkt) { return txLink->transmit(pkt); }
193 void sendDone() { peer->sendDone(); }
194 bool isBusy() { return txLink->busy(); }
195 };
196
197
198 protected:
199 /**
200 * Interface to talk to the peer gem5 processes.
201 */
202 DistIface *distIface;
203 /**
204 * Send link
205 */
206 TxLink *txLink;
207 /**
208 * Receive link
209 */
210 RxLink *rxLink;
211 LocalIface *localIface;
212
213 Tick linkDelay;
214
215 public:
216 typedef DistEtherLinkParams Params;
217 DistEtherLink(const Params *p);
218 ~DistEtherLink();
219
220 const Params *
221 params() const
222 {
223 return dynamic_cast<const Params *>(_params);
224 }
225
227 EtherInt *getEthPort(const std::string &if_name, int idx) override;
226 Port &getPort(const std::string &if_name,
227 PortID idx=InvalidPortID) override;
228
229 virtual void init() override;
230 virtual void startup() override;
231
232 void serialize(CheckpointOut &cp) const override;
233 void unserialize(CheckpointIn &cp) override;
234};
235
236#endif // __DEV_DIST_ETHERLINK_HH__
228
229 virtual void init() override;
230 virtual void startup() override;
231
232 void serialize(CheckpointOut &cp) const override;
233 void unserialize(CheckpointIn &cp) override;
234};
235
236#endif // __DEV_DIST_ETHERLINK_HH__