summaryrefslogtreecommitdiff
path: root/src/dev/net/ethertap.hh
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2017-06-03 05:03:18 -0700
committerGabe Black <gabeblack@google.com>2017-06-03 15:23:46 +0000
commit2ce045341b73166cad2ef95b37c87d8d4c590d80 (patch)
treeeb46ce8c910cd04d39477da459915802105c5729 /src/dev/net/ethertap.hh
parentf9ad4066d71748829c11868b5b92ba092ee9513b (diff)
downloadgem5-2ce045341b73166cad2ef95b37c87d8d4c590d80.tar.xz
dev: Refactor the EtherTapStub to make room for using tap.
A lot of the implementation of EtherTapStub can be shared with a version which uses a tap device directly. This change factors out those parts to accommodate that. Change-Id: I9c2e31f1be139ca73859a83f05457cef90101006 Reviewed-on: https://gem5-review.googlesource.com/3645 Reviewed-by: Nathan Binkert <nate@binkert.org> Maintainer: Nathan Binkert <nate@binkert.org>
Diffstat (limited to 'src/dev/net/ethertap.hh')
-rw-r--r--src/dev/net/ethertap.hh130
1 files changed, 85 insertions, 45 deletions
diff --git a/src/dev/net/ethertap.hh b/src/dev/net/ethertap.hh
index b4af6979e..718af1808 100644
--- a/src/dev/net/ethertap.hh
+++ b/src/dev/net/ethertap.hh
@@ -47,65 +47,107 @@
#include "sim/sim_object.hh"
class TapEvent;
-class TapListener;
class EtherTapInt;
-/*
- * Interface to connect a simulated ethernet device to the real world. An
- * external helper program bridges between this object's TCP port and a
- * source/sink for Ethernet frames. Each frame going in either direction is
- * prepended with the frame's length in a 32 bit integer in network byte order.
- */
-class EtherTapStub : public EtherObject
+class EtherTapBase : public EtherObject
{
- protected:
- friend class TapEvent;
- TapEvent *event;
+ public:
+ typedef EtherTapBaseParams Params;
+ EtherTapBase(const Params *p);
+ virtual ~EtherTapBase();
+
+ const Params *
+ params() const
+ {
+ return dynamic_cast<const Params *>(_params);
+ }
+
+ void serialize(CheckpointOut &cp) const override;
+ void unserialize(CheckpointIn &cp) override;
protected:
- friend class TapListener;
- TapListener *listener;
- int socket;
- char *buffer;
+ uint8_t *buffer;
int buflen;
- uint32_t buffer_offset;
- uint32_t data_len;
EtherDump *dump;
- void attach(int fd);
- void detach();
+ /*
+ * Interface to the real network.
+ */
protected:
- std::string device;
- std::queue<EthPacketPtr> packetBuffer;
- EtherTapInt *interface;
+ friend class TapEvent;
+ TapEvent *event;
+ void pollFd(int fd);
+ void stopPolling();
+
+ // Receive data from the real network.
+ virtual void recvReal(int revent) = 0;
+ // Prepare and send data out to the real network.
+ virtual bool sendReal(const void *data, size_t len) = 0;
- void process(int revent);
- void enqueue(EthPacketData *packet);
- void retransmit();
/*
+ * Interface to the simulated network.
*/
+ protected:
+ EtherTapInt *interface;
+
+ public:
+ EtherInt *getEthPort(const std::string &if_name, int idx) override;
+
+ bool recvSimulated(EthPacketPtr packet);
+ void sendSimulated(void *data, size_t len);
+
+ protected:
+ std::queue<EthPacketPtr> packetBuffer;
+ void retransmit();
+
class TxEvent : public Event
{
protected:
- EtherTapStub *tap;
+ EtherTapBase *tap;
public:
- TxEvent(EtherTapStub *_tap) : tap(_tap) {}
+ TxEvent(EtherTapBase *_tap) : tap(_tap) {}
void process() { tap->retransmit(); }
virtual const char *description() const
- { return "EtherTapStub retransmit"; }
+ { return "EtherTapBase retransmit"; }
};
friend class TxEvent;
TxEvent txEvent;
+};
+class EtherTapInt : public EtherInt
+{
+ private:
+ EtherTapBase *tap;
+ public:
+ EtherTapInt(const std::string &name, EtherTapBase *t) :
+ EtherInt(name), tap(t)
+ { }
+
+ bool recvPacket(EthPacketPtr pkt) override
+ { return tap->recvSimulated(pkt); }
+ void sendDone() override {}
+};
+
+
+class TapListener;
+
+/*
+ * Interface to connect a simulated ethernet device to the real world. An
+ * external helper program bridges between this object's TCP port and a
+ * source/sink for Ethernet frames. Each frame going in either direction is
+ * prepended with the frame's length in a 32 bit integer in network byte order.
+ */
+class EtherTapStub : public EtherTapBase
+{
public:
typedef EtherTapStubParams Params;
EtherTapStub(const Params *p);
- virtual ~EtherTapStub();
+ ~EtherTapStub();
const Params *
params() const
@@ -113,26 +155,24 @@ class EtherTapStub : public EtherObject
return dynamic_cast<const Params *>(_params);
}
- EtherInt *getEthPort(const std::string &if_name, int idx) override;
-
- virtual bool recvPacket(EthPacketPtr packet);
- virtual void sendDone();
-
void serialize(CheckpointOut &cp) const override;
void unserialize(CheckpointIn &cp) override;
-};
-class EtherTapInt : public EtherInt
-{
- private:
- EtherTapStub *tap;
- public:
- EtherTapInt(const std::string &name, EtherTapStub *t)
- : EtherInt(name), tap(t)
- { }
- virtual bool recvPacket(EthPacketPtr pkt) { return tap->recvPacket(pkt); }
- virtual void sendDone() { tap->sendDone(); }
+ protected:
+ friend class TapListener;
+ TapListener *listener;
+
+ int socket;
+
+ void attach(int fd);
+ void detach();
+
+ uint32_t buffer_used;
+ uint32_t frame_len;
+
+ void recvReal(int revent) override;
+ bool sendReal(const void *data, size_t len) override;
};