diff -r e4f63f1d502d -r 7365362b1198 src/dev/Ethernet.py --- a/src/dev/Ethernet.py Sun Jun 21 20:52:13 2015 +0100 +++ b/src/dev/Ethernet.py Tue Jun 23 15:08:07 2015 -0500 @@ -59,6 +59,8 @@ bufsz = Param.Int(10000, "tap buffer size") dump = Param.EtherDump(NULL, "dump object") port = Param.UInt16(3500, "tap port") + tap = MasterPort("EtherTap interface") + poll_rate = Param.UInt64(1000000, "check fd for incomming pkts in this rate") class EtherDump(SimObject): type = 'EtherDump' diff -r e4f63f1d502d -r 7365362b1198 src/dev/ethertap.hh --- a/src/dev/ethertap.hh Sun Jun 21 20:52:13 2015 +0100 +++ b/src/dev/ethertap.hh Tue Jun 23 15:08:07 2015 -0500 @@ -46,7 +46,6 @@ #include "sim/eventq.hh" #include "sim/sim_object.hh" -class TapEvent; class TapListener; class EtherTapInt; @@ -56,10 +55,6 @@ class EtherTap : public EtherObject { protected: - friend class TapEvent; - TapEvent *event; - - protected: friend class TapListener; TapListener *listener; int socket; @@ -77,8 +72,9 @@ std::string device; std::queue packetBuffer; EtherTapInt *interface; + uint64_t pollRate; - void process(int revent); + void process(); void enqueue(EthPacketData *packet); void retransmit(); @@ -98,6 +94,7 @@ friend class TxEvent; TxEvent txEvent; + EventWrapper tapInEvent; public: typedef EtherTapParams Params; diff -r e4f63f1d502d -r 7365362b1198 src/dev/ethertap.cc --- a/src/dev/ethertap.cc Sun Jun 21 20:52:13 2015 +0100 +++ b/src/dev/ethertap.cc Tue Jun 23 15:08:07 2015 -0500 @@ -51,6 +51,17 @@ #include "dev/etherint.hh" #include "dev/etherpkt.hh" #include "dev/ethertap.hh" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include using namespace std; @@ -121,20 +132,9 @@ /** */ -class TapEvent : public PollEvent -{ - protected: - EtherTap *tap; - - public: - TapEvent(EtherTap *_tap, int fd, int e) - : PollEvent(fd, e), tap(_tap) {} - virtual void process(int revent) { tap->process(revent); } -}; - EtherTap::EtherTap(const Params *p) - : EtherObject(p), event(NULL), socket(-1), buflen(p->bufsz), dump(p->dump), - interface(NULL), txEvent(this) + : EtherObject(p), socket(-1), buflen(p->bufsz), dump(p->dump), + interface(NULL), pollRate(p->poll_rate), txEvent(this), tapInEvent(this) { if (ListenSocket::allDisabled()) fatal("All listeners are disabled! EtherTap can't work!"); @@ -147,8 +147,6 @@ EtherTap::~EtherTap() { - if (event) - delete event; if (buffer) delete [] buffer; @@ -166,16 +164,16 @@ data_len = 0; socket = fd; DPRINTF(Ethernet, "EtherTap attached\n"); - event = new TapEvent(this, socket, POLLIN|POLLERR); - pollQueue.schedule(event); + int nonBlocking = 1; + fcntl( socket, F_SETFL, O_NONBLOCK, nonBlocking ); + if (!tapInEvent.scheduled()) + schedule(tapInEvent, curTick() + pollRate); } void EtherTap::detach() { DPRINTF(Ethernet, "EtherTap detached\n"); - delete event; - event = 0; close(socket); socket = -1; } @@ -206,21 +204,14 @@ {} void -EtherTap::process(int revent) +EtherTap::process() { - if (revent & POLLERR) { - detach(); - return; - } - char *data = buffer + sizeof(uint32_t); - if (!(revent & POLLIN)) - return; if (buffer_offset < data_len + sizeof(uint32_t)) { int len = read(socket, buffer + buffer_offset, buflen - buffer_offset); - if (len == 0) { - detach(); + if (len <= 0) { + schedule(tapInEvent, curTick() + pollRate); return; } @@ -258,6 +249,7 @@ dump->dump(packet); } } + schedule(tapInEvent, curTick() + pollRate); } void @@ -303,38 +295,19 @@ SERIALIZE_SCALAR(buffer_offset); SERIALIZE_SCALAR(data_len); - bool tapevent_present = false; - if (event) { - tapevent_present = true; - SERIALIZE_SCALAR(tapevent_present); - event->serialize(os); - } - else { - SERIALIZE_SCALAR(tapevent_present); - } } void EtherTap::unserialize(Checkpoint *cp, const std::string §ion) { - UNSERIALIZE_SCALAR(socket); UNSERIALIZE_SCALAR(buflen); uint8_t *buffer = (uint8_t *)this->buffer; UNSERIALIZE_ARRAY(buffer, buflen); UNSERIALIZE_SCALAR(buffer_offset); UNSERIALIZE_SCALAR(data_len); - - bool tapevent_present; - UNSERIALIZE_SCALAR(tapevent_present); - if (tapevent_present) { - event = new TapEvent(this, socket, POLLIN|POLLERR); - - event->unserialize(cp,section); - - if (event->queued()) { - pollQueue.schedule(event); - } - } + if (tapInEvent.scheduled()) + deschedule(tapInEvent); + schedule(tapInEvent, curTick() + 1000); } //=====================================================================