From f9ad4066d71748829c11868b5b92ba092ee9513b Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Sat, 3 Jun 2017 00:45:09 -0700 Subject: dev: Rename EtherTap to be EtherTapStub. The EtherTap object is going to be reworked so that it connects to a tap device directly, but it's worthwhile to still be able to use the m5tap utility (util/tap) to send/receive packets on systems which don't support tap but do support the pcap API. It can also be used to replay ethernet frames, to capture the ethernet frames coming from gem5 for analysis, to programmatically consume and/or generate the frames, or even to forward them to/from a remote system. Change-Id: Ic7bd763d86cd913ac373dd10a8d6d1fc6b35f95a Reviewed-on: https://gem5-review.googlesource.com/3644 Reviewed-by: Nathan Binkert Maintainer: Nathan Binkert --- src/dev/net/Ethernet.py | 8 ++++---- src/dev/net/ethertap.cc | 48 ++++++++++++++++++++++++------------------------ src/dev/net/ethertap.hh | 25 ++++++++++++++----------- 3 files changed, 42 insertions(+), 39 deletions(-) diff --git a/src/dev/net/Ethernet.py b/src/dev/net/Ethernet.py index da1e5720d..1f8e75200 100644 --- a/src/dev/net/Ethernet.py +++ b/src/dev/net/Ethernet.py @@ -95,13 +95,13 @@ class EtherSwitch(EtherObject): delay_var = Param.Latency('0ns', "packet transmit delay variability") time_to_live = Param.Latency('10ms', "time to live of MAC address maping") -class EtherTap(EtherObject): - type = 'EtherTap' +class EtherTapStub(EtherObject): + type = 'EtherTapStub' cxx_header = "dev/net/ethertap.hh" bufsz = Param.Int(10000, "tap buffer size") dump = Param.EtherDump(NULL, "dump object") - port = Param.UInt16(3500, "tap port") - tap = SlavePort("Ethernet interface") + port = Param.UInt16(3500, "Port helper should send packets to") + tap = SlavePort("Ethernet interface to gem5's network") class EtherDump(SimObject): type = 'EtherDump' diff --git a/src/dev/net/ethertap.cc b/src/dev/net/ethertap.cc index e09b7a318..e7b928972 100644 --- a/src/dev/net/ethertap.cc +++ b/src/dev/net/ethertap.cc @@ -80,11 +80,11 @@ class TapListener protected: ListenSocket listener; - EtherTap *tap; + EtherTapStub *tap; int port; public: - TapListener(EtherTap *t, int p) + TapListener(EtherTapStub *t, int p) : event(NULL), tap(t), port(p) {} ~TapListener() { if (event) delete event; } @@ -126,20 +126,20 @@ TapListener::accept() class TapEvent : public PollEvent { protected: - EtherTap *tap; + EtherTapStub *tap; public: - TapEvent(EtherTap *_tap, int fd, int e) + TapEvent(EtherTapStub *_tap, int fd, int e) : PollEvent(fd, e), tap(_tap) {} virtual void process(int revent) { tap->process(revent); } }; -EtherTap::EtherTap(const Params *p) +EtherTapStub::EtherTapStub(const Params *p) : EtherObject(p), event(NULL), socket(-1), buflen(p->bufsz), dump(p->dump), interface(NULL), txEvent(this) { if (ListenSocket::allDisabled()) - fatal("All listeners are disabled! EtherTap can't work!"); + fatal("All listeners are disabled! EtherTapStub can't work!"); buffer = new char[buflen]; listener = new TapListener(this, p->port); @@ -147,7 +147,7 @@ EtherTap::EtherTap(const Params *p) interface = new EtherTapInt(name() + ".interface", this); } -EtherTap::~EtherTap() +EtherTapStub::~EtherTapStub() { if (event) delete event; @@ -159,7 +159,7 @@ EtherTap::~EtherTap() } void -EtherTap::attach(int fd) +EtherTapStub::attach(int fd) { if (socket != -1) close(fd); @@ -167,15 +167,15 @@ EtherTap::attach(int fd) buffer_offset = 0; data_len = 0; socket = fd; - DPRINTF(Ethernet, "EtherTap attached\n"); + DPRINTF(Ethernet, "EtherTapStub attached\n"); event = new TapEvent(this, socket, POLLIN|POLLERR); pollQueue.schedule(event); } void -EtherTap::detach() +EtherTapStub::detach() { - DPRINTF(Ethernet, "EtherTap detached\n"); + DPRINTF(Ethernet, "EtherTapStub detached\n"); delete event; event = 0; close(socket); @@ -183,12 +183,12 @@ EtherTap::detach() } bool -EtherTap::recvPacket(EthPacketPtr packet) +EtherTapStub::recvPacket(EthPacketPtr packet) { if (dump) dump->dump(packet); - DPRINTF(Ethernet, "EtherTap output len=%d\n", packet->length); + DPRINTF(Ethernet, "EtherTapStub output len=%d\n", packet->length); DDUMP(EthernetData, packet->data, packet->length); uint32_t len = htonl(packet->length); ssize_t ret = write(socket, &len, sizeof(len)); @@ -204,11 +204,11 @@ EtherTap::recvPacket(EthPacketPtr packet) } void -EtherTap::sendDone() +EtherTapStub::sendDone() {} void -EtherTap::process(int revent) +EtherTapStub::process(int revent) { if (revent & POLLERR) { detach(); @@ -250,7 +250,7 @@ EtherTap::process(int revent) } else data_len = 0; - DPRINTF(Ethernet, "EtherTap input len=%d\n", packet->length); + DPRINTF(Ethernet, "EtherTapStub input len=%d\n", packet->length); DDUMP(EthernetData, packet->data, packet->length); if (!interface->sendPacket(packet)) { DPRINTF(Ethernet, "bus busy...buffer for retransmission\n"); @@ -264,7 +264,7 @@ EtherTap::process(int revent) } void -EtherTap::retransmit() +EtherTapStub::retransmit() { if (packetBuffer.empty()) return; @@ -273,7 +273,7 @@ EtherTap::retransmit() if (interface->sendPacket(packet)) { if (dump) dump->dump(packet); - DPRINTF(Ethernet, "EtherTap retransmit\n"); + DPRINTF(Ethernet, "EtherTapStub retransmit\n"); packetBuffer.front() = NULL; packetBuffer.pop(); } @@ -283,7 +283,7 @@ EtherTap::retransmit() } EtherInt* -EtherTap::getEthPort(const std::string &if_name, int idx) +EtherTapStub::getEthPort(const std::string &if_name, int idx) { if (if_name == "tap") { if (interface->getPeer()) @@ -297,7 +297,7 @@ EtherTap::getEthPort(const std::string &if_name, int idx) //===================================================================== void -EtherTap::serialize(CheckpointOut &cp) const +EtherTapStub::serialize(CheckpointOut &cp) const { SERIALIZE_SCALAR(socket); SERIALIZE_SCALAR(buflen); @@ -318,7 +318,7 @@ EtherTap::serialize(CheckpointOut &cp) const } void -EtherTap::unserialize(CheckpointIn &cp) +EtherTapStub::unserialize(CheckpointIn &cp) { UNSERIALIZE_SCALAR(socket); UNSERIALIZE_SCALAR(buflen); @@ -342,8 +342,8 @@ EtherTap::unserialize(CheckpointIn &cp) //===================================================================== -EtherTap * -EtherTapParams::create() +EtherTapStub * +EtherTapStubParams::create() { - return new EtherTap(this); + return new EtherTapStub(this); } diff --git a/src/dev/net/ethertap.hh b/src/dev/net/ethertap.hh index b27b80f84..b4af6979e 100644 --- a/src/dev/net/ethertap.hh +++ b/src/dev/net/ethertap.hh @@ -42,7 +42,7 @@ #include "dev/net/etherint.hh" #include "dev/net/etherobject.hh" #include "dev/net/etherpkt.hh" -#include "params/EtherTap.hh" +#include "params/EtherTapStub.hh" #include "sim/eventq.hh" #include "sim/sim_object.hh" @@ -51,9 +51,12 @@ class TapListener; class EtherTapInt; /* - * Interface to connect a simulated ethernet device to the real world + * 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 EtherTap : public EtherObject +class EtherTapStub : public EtherObject { protected: friend class TapEvent; @@ -87,22 +90,22 @@ class EtherTap : public EtherObject class TxEvent : public Event { protected: - EtherTap *tap; + EtherTapStub *tap; public: - TxEvent(EtherTap *_tap) : tap(_tap) {} + TxEvent(EtherTapStub *_tap) : tap(_tap) {} void process() { tap->retransmit(); } virtual const char *description() const - { return "EtherTap retransmit"; } + { return "EtherTapStub retransmit"; } }; friend class TxEvent; TxEvent txEvent; public: - typedef EtherTapParams Params; - EtherTap(const Params *p); - virtual ~EtherTap(); + typedef EtherTapStubParams Params; + EtherTapStub(const Params *p); + virtual ~EtherTapStub(); const Params * params() const @@ -122,9 +125,9 @@ class EtherTap : public EtherObject class EtherTapInt : public EtherInt { private: - EtherTap *tap; + EtherTapStub *tap; public: - EtherTapInt(const std::string &name, EtherTap *t) + EtherTapInt(const std::string &name, EtherTapStub *t) : EtherInt(name), tap(t) { } -- cgit v1.2.3