gem5  v21.1.0.2
ethertap.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-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 
29 /* @file
30  * Interface to connect a simulated ethernet device to the real world
31  */
32 
33 #ifndef __DEV_NET_ETHERTAP_HH__
34 #define __DEV_NET_ETHERTAP_HH__
35 
36 #include <queue>
37 #include <string>
38 
39 #include "base/pollevent.hh"
40 #include "config/have_tuntap.hh"
41 #include "dev/net/etherint.hh"
42 #include "dev/net/etherpkt.hh"
43 
44 #if HAVE_TUNTAP
45 #include "params/EtherTap.hh"
46 
47 #endif
48 
49 #include "params/EtherTapStub.hh"
50 #include "sim/eventq.hh"
51 #include "sim/sim_object.hh"
52 
53 namespace gem5
54 {
55 
56 class TapEvent;
57 class EtherTapInt;
58 
59 class EtherTapBase : public SimObject
60 {
61  public:
62  using Params = EtherTapBaseParams;
63  EtherTapBase(const Params &p);
64  virtual ~EtherTapBase();
65 
66  void serialize(CheckpointOut &cp) const override;
67  void unserialize(CheckpointIn &cp) override;
68 
69  protected:
70  uint8_t *buffer;
71  int buflen;
72 
74 
75 
76  /*
77  * Interface to the real network.
78  */
79  protected:
80  friend class TapEvent;
82  void pollFd(int fd);
83  void stopPolling();
84 
85  // Receive data from the real network.
86  virtual void recvReal(int revent) = 0;
87  // Prepare and send data out to the real network.
88  virtual bool sendReal(const void *data, size_t len) = 0;
89 
90 
91  /*
92  * Interface to the simulated network.
93  */
94  protected:
96 
97  public:
98  Port &getPort(const std::string &if_name,
99  PortID idx=InvalidPortID) override;
100 
101  bool recvSimulated(EthPacketPtr packet);
102  void sendSimulated(void *data, size_t len);
103 
104  protected:
105  std::queue<EthPacketPtr> packetBuffer;
106  void retransmit();
108 };
109 
110 class EtherTapInt : public EtherInt
111 {
112  private:
114  public:
115  EtherTapInt(const std::string &name, EtherTapBase *t) :
116  EtherInt(name), tap(t)
117  { }
118 
119  bool recvPacket(EthPacketPtr pkt) override
120  { return tap->recvSimulated(pkt); }
121  void sendDone() override {}
122 };
123 
124 
125 class TapListener;
126 
127 /*
128  * Interface to connect a simulated ethernet device to the real world. An
129  * external helper program bridges between this object's TCP port and a
130  * source/sink for Ethernet frames. Each frame going in either direction is
131  * prepended with the frame's length in a 32 bit integer in network byte order.
132  */
134 {
135  public:
136  using Params = EtherTapStubParams;
137  EtherTapStub(const Params &p);
138  ~EtherTapStub();
139 
140  void serialize(CheckpointOut &cp) const override;
141  void unserialize(CheckpointIn &cp) override;
142 
143 
144  protected:
145  friend class TapListener;
147 
148  int socket;
149 
150  void attach(int fd);
151  void detach();
152 
153  uint32_t buffer_used;
154  uint32_t frame_len;
155 
156  void recvReal(int revent) override;
157  bool sendReal(const void *data, size_t len) override;
158 };
159 
160 
161 #if HAVE_TUNTAP
162 class EtherTap : public EtherTapBase
163 {
164  public:
165  using Params = EtherTapParams;
166  EtherTap(const Params &p);
167  ~EtherTap();
168 
169 
170  protected:
171  int tap;
172 
173  void recvReal(int revent) override;
174  bool sendReal(const void *data, size_t len) override;
175 };
176 #endif
177 
178 } // namespace gem5
179 
180 #endif // __DEV_NET_ETHERTAP_HH__
gem5::EtherTapInt::sendDone
void sendDone() override
Definition: ethertap.hh:121
gem5::PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:252
gem5::EtherTapBase::getPort
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: ethertap.cc:164
gem5::ArmISA::len
Bitfield< 18, 16 > len
Definition: misc_types.hh:444
gem5::EtherTapStub::sendReal
bool sendReal(const void *data, size_t len) override
Definition: ethertap.cc:393
gem5::EtherTapStub::buffer_used
uint32_t buffer_used
Definition: ethertap.hh:153
data
const char data[]
Definition: circlebuf.test.cc:48
gem5::EtherTapBase::dump
EtherDump * dump
Definition: ethertap.hh:73
gem5::ArmISA::fd
Bitfield< 14, 12 > fd
Definition: types.hh:150
gem5::EtherTapBase::EtherTapBase
EtherTapBase(const Params &p)
Definition: ethertap.cc:95
gem5::EtherTapBase::event
TapEvent * event
Definition: ethertap.hh:81
gem5::EtherTapBase::packetBuffer
std::queue< EthPacketPtr > packetBuffer
Definition: ethertap.hh:105
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::EtherTapBase
Definition: ethertap.hh:59
etherint.hh
gem5::EtherInt::name
const std::string & name() const
Return port name (for DPRINTF).
Definition: etherint.hh:62
gem5::EtherTapStub::frame_len
uint32_t frame_len
Definition: ethertap.hh:154
gem5::EtherTapBase::sendSimulated
void sendSimulated(void *data, size_t len)
Definition: ethertap.cc:188
gem5::EtherInt
Definition: etherint.hh:50
gem5::InvalidPortID
const PortID InvalidPortID
Definition: types.hh:253
gem5::EtherTapInt::recvPacket
bool recvPacket(EthPacketPtr pkt) override
Definition: ethertap.hh:119
gem5::EtherTapBase::buflen
int buflen
Definition: ethertap.hh:71
gem5::EtherTapBase::pollFd
void pollFd(int fd)
Definition: ethertap.cc:147
gem5::EtherTapStub::~EtherTapStub
~EtherTapStub()
Definition: ethertap.cc:298
gem5::EtherTapBase::retransmit
void retransmit()
Definition: ethertap.cc:209
gem5::EtherTapStub::EtherTapStub
EtherTapStub(const Params &p)
Definition: ethertap.cc:289
gem5::EtherTapBase::txEvent
EventFunctionWrapper txEvent
Definition: ethertap.hh:107
gem5::EtherTapInt
Definition: ethertap.hh:110
gem5::EthPacketPtr
std::shared_ptr< EthPacketData > EthPacketPtr
Definition: etherpkt.hh:90
sim_object.hh
gem5::EtherTapBase::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: ethertap.cc:129
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
pollevent.hh
gem5::EtherDump
Definition: etherdump.hh:48
gem5::TapEvent
Definition: ethertap.cc:75
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
gem5::ArmISA::t
Bitfield< 5 > t
Definition: misc_types.hh:70
gem5::EtherTapBase::buffer
uint8_t * buffer
Definition: ethertap.hh:70
gem5::EtherTapStub::recvReal
void recvReal(int revent) override
Definition: ethertap.cc:347
gem5::EventFunctionWrapper
Definition: eventq.hh:1115
gem5::EtherTapBase::~EtherTapBase
virtual ~EtherTapBase()
Definition: ethertap.cc:104
gem5::EtherTapStub::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: ethertap.cc:314
gem5::EtherTapStub::detach
void detach()
Definition: ethertap.cc:338
gem5::Port
Ports are used to interface objects to each other.
Definition: port.hh:61
gem5::EtherTapInt::tap
EtherTapBase * tap
Definition: ethertap.hh:113
gem5::EtherTapStub::attach
void attach(int fd)
Definition: ethertap.cc:325
gem5::EtherTapBase::interface
EtherTapInt * interface
Definition: ethertap.hh:95
gem5::EtherTapStub::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: ethertap.cc:304
gem5::EtherTapBase::stopPolling
void stopPolling()
Definition: ethertap.cc:155
gem5::EtherTapBase::recvReal
virtual void recvReal(int revent)=0
etherpkt.hh
gem5::EtherTapStub::listener
TapListener * listener
Definition: ethertap.hh:146
gem5::CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:66
gem5::EtherTapInt::EtherTapInt
EtherTapInt(const std::string &name, EtherTapBase *t)
Definition: ethertap.hh:115
gem5::EtherTapBase::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: ethertap.cc:112
gem5::EtherTapStub
Definition: ethertap.hh:133
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::EtherTapStub::socket
int socket
Definition: ethertap.hh:148
gem5::EtherTapBase::recvSimulated
bool recvSimulated(EthPacketPtr packet)
Definition: ethertap.cc:172
gem5::EtherTapBase::sendReal
virtual bool sendReal(const void *data, size_t len)=0
gem5::TapListener
Definition: ethertap.cc:228
gem5::EtherTapBase::Params
EtherTapBaseParams Params
Definition: ethertap.hh:62
eventq.hh

Generated on Tue Sep 21 2021 12:25:17 for gem5 by doxygen 1.8.17