dev-arm: Move GICv3 (Re)Ditributor address in Realview.py
[gem5.git] / src / dev / net / ethertap.hh
index b4af6979e91fb8975cd9ecb372ad052532551a8c..5f59a390cda3d64a823134729defc0366c9dec7f 100644 (file)
 #include <string>
 
 #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. 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 SimObject
 {
-  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.
      */
-    class TxEvent : public Event
-    {
-      protected:
-        EtherTapStub *tap;
+  protected:
+    EtherTapInt *interface;
+
+  public:
+    Port &getPort(const std::string &if_name,
+                  PortID idx=InvalidPortID) override;
+
+    bool recvSimulated(EthPacketPtr packet);
+    void sendSimulated(void *data, size_t len);
+
+  protected:
+    std::queue<EthPacketPtr> packetBuffer;
+    void retransmit();
+    EventFunctionWrapper 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 {}
+};
 
-      public:
-        TxEvent(EtherTapStub *_tap) : tap(_tap) {}
-        void process() { tap->retransmit(); }
-        virtual const char *description() const
-            { return "EtherTapStub retransmit"; }
-    };
 
-    friend class TxEvent;
-    TxEvent txEvent;
+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,27 +148,49 @@ 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;
+
+
+  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:
-    EtherTapStub *tap;
   public:
-    EtherTapInt(const std::string &name, EtherTapStub *t)
-            : EtherInt(name), tap(t)
-    { }
+    typedef EtherTapParams Params;
+    EtherTap(const Params *p);
+    ~EtherTap();
+
+    const Params *
+    params() const
+    {
+        return dynamic_cast<const Params *>(_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__