X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fdev%2Fnet%2Fethertap.hh;h=5f59a390cda3d64a823134729defc0366c9dec7f;hb=40018b14a608b066a52c4baf86b4160820402c9c;hp=b27b80f84617363e67e71c9ab17365e163d97e78;hpb=23c961a0fd97251ee7c760bc2ff2a011a417ad9b;p=gem5.git diff --git a/src/dev/net/ethertap.hh b/src/dev/net/ethertap.hh index b27b80f84..5f59a390c 100644 --- a/src/dev/net/ethertap.hh +++ b/src/dev/net/ethertap.hh @@ -39,70 +39,108 @@ #include #include "base/pollevent.hh" +#include "config/use_tuntap.hh" #include "dev/net/etherint.hh" -#include "dev/net/etherobject.hh" #include "dev/net/etherpkt.hh" + +#if USE_TUNTAP #include "params/EtherTap.hh" + +#endif + +#include "params/EtherTapStub.hh" #include "sim/eventq.hh" #include "sim/sim_object.hh" class TapEvent; -class TapListener; class EtherTapInt; -/* - * Interface to connect a simulated ethernet device to the real world - */ -class EtherTap : public EtherObject +class EtherTapBase : public SimObject { - protected: - friend class TapEvent; - TapEvent *event; + public: + typedef EtherTapBaseParams Params; + EtherTapBase(const Params *p); + virtual ~EtherTapBase(); + + const Params * + params() const + { + return dynamic_cast(_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 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. */ - class TxEvent : public Event - { - protected: - EtherTap *tap; + protected: + EtherTapInt *interface; - public: - TxEvent(EtherTap *_tap) : tap(_tap) {} - void process() { tap->retransmit(); } - virtual const char *description() const - { return "EtherTap retransmit"; } - }; + public: + Port &getPort(const std::string &if_name, + PortID idx=InvalidPortID) override; - friend class TxEvent; - TxEvent txEvent; + bool recvSimulated(EthPacketPtr packet); + void sendSimulated(void *data, size_t len); + protected: + std::queue packetBuffer; + void retransmit(); + EventFunctionWrapper txEvent; +}; + +class EtherTapInt : public EtherInt +{ + private: + EtherTapBase *tap; public: - typedef EtherTapParams Params; - EtherTap(const Params *p); - virtual ~EtherTap(); + 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); + ~EtherTapStub(); const Params * params() const @@ -110,27 +148,49 @@ class EtherTap : public EtherObject return dynamic_cast(_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; + + + 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; }; -class EtherTapInt : public EtherInt + +#if USE_TUNTAP +class EtherTap : public EtherTapBase { - private: - EtherTap *tap; public: - EtherTapInt(const std::string &name, EtherTap *t) - : EtherInt(name), tap(t) - { } + typedef EtherTapParams Params; + EtherTap(const Params *p); + ~EtherTap(); + + const Params * + params() const + { + return dynamic_cast(_params); + } + + + protected: + int tap; - virtual bool recvPacket(EthPacketPtr pkt) { return tap->recvPacket(pkt); } - virtual void sendDone() { tap->sendDone(); } + void recvReal(int revent) override; + bool sendReal(const void *data, size_t len) override; }; +#endif #endif // __DEV_NET_ETHERTAP_HH__