2 * Copyright (c) 2003-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 * Interface to connect a simulated ethernet device to the real world
35 #ifndef __DEV_NET_ETHERTAP_HH__
36 #define __DEV_NET_ETHERTAP_HH__
41 #include "base/pollevent.hh"
42 #include "config/use_tuntap.hh"
43 #include "dev/net/etherint.hh"
44 #include "dev/net/etherobject.hh"
45 #include "dev/net/etherpkt.hh"
48 #include "params/EtherTap.hh"
52 #include "params/EtherTapStub.hh"
53 #include "sim/eventq.hh"
54 #include "sim/sim_object.hh"
59 class EtherTapBase : public SimObject, public EtherObject
62 typedef EtherTapBaseParams Params;
63 EtherTapBase(const Params *p);
64 virtual ~EtherTapBase();
69 return dynamic_cast<const Params *>(_params);
72 void serialize(CheckpointOut &cp) const override;
73 void unserialize(CheckpointIn &cp) override;
83 * Interface to the real network.
86 friend class TapEvent;
91 // Receive data from the real network.
92 virtual void recvReal(int revent) = 0;
93 // Prepare and send data out to the real network.
94 virtual bool sendReal(const void *data, size_t len) = 0;
98 * Interface to the simulated network.
101 EtherTapInt *interface;
104 EtherInt *getEthPort(const std::string &if_name, int idx) override;
106 bool recvSimulated(EthPacketPtr packet);
107 void sendSimulated(void *data, size_t len);
110 std::queue<EthPacketPtr> packetBuffer;
112 EventFunctionWrapper txEvent;
115 class EtherTapInt : public EtherInt
120 EtherTapInt(const std::string &name, EtherTapBase *t) :
121 EtherInt(name), tap(t)
124 bool recvPacket(EthPacketPtr pkt) override
125 { return tap->recvSimulated(pkt); }
126 void sendDone() override {}
133 * Interface to connect a simulated ethernet device to the real world. An
134 * external helper program bridges between this object's TCP port and a
135 * source/sink for Ethernet frames. Each frame going in either direction is
136 * prepended with the frame's length in a 32 bit integer in network byte order.
138 class EtherTapStub : public EtherTapBase
141 typedef EtherTapStubParams Params;
142 EtherTapStub(const Params *p);
148 return dynamic_cast<const Params *>(_params);
151 void serialize(CheckpointOut &cp) const override;
152 void unserialize(CheckpointIn &cp) override;
156 friend class TapListener;
157 TapListener *listener;
164 uint32_t buffer_used;
167 void recvReal(int revent) override;
168 bool sendReal(const void *data, size_t len) override;
173 class EtherTap : public EtherTapBase
176 typedef EtherTapParams Params;
177 EtherTap(const Params *p);
183 return dynamic_cast<const Params *>(_params);
190 void recvReal(int revent) override;
191 bool sendReal(const void *data, size_t len) override;
196 #endif // __DEV_NET_ETHERTAP_HH__