MEM: Separate queries for snooping and address ranges
[gem5.git] / src / base / inet.hh
index 21ac5c89e6f4e52c31c1775debe1f4644f0e8bff..a957b8a71eefe2b58e54bf66b94fa6b95c5f0bcb 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2002-2005 The Regents of The University of Michigan
+ * Copyright (c) 2010 Advanced Micro Devices, Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -27,6 +28,7 @@
  *
  * Authors: Nathan Binkert
  *          Steve Reinhardt
+ *          Gabe Black
  */
 
 #ifndef __BASE_INET_HH__
@@ -38,9 +40,8 @@
 #include <vector>
 
 #include "base/range.hh"
+#include "base/types.hh"
 #include "dev/etherpkt.hh"
-#include "sim/host.hh"
-
 #include "dnet/os.h"
 #include "dnet/eth.h"
 #include "dnet/ip.h"
@@ -140,11 +141,72 @@ class EthPtr
     EthPacketPtr packet() { return p; }
     bool operator!() const { return !p; }
     operator bool() const { return p; }
+    int off() const { return 0; }
+    int pstart() const { return off() + ((const EthHdr*)p->data)->size(); }
 };
 
 /*
  * IP Stuff
  */
+struct IpAddress
+{
+  protected:
+    uint32_t _ip;
+
+  public:
+    IpAddress() : _ip(0)
+    {}
+    IpAddress(const uint32_t __ip) : _ip(__ip)
+    {}
+
+    uint32_t ip() const { return _ip; }
+
+    std::string string() const;
+};
+
+std::ostream &operator<<(std::ostream &stream, const IpAddress &ia);
+bool operator==(const IpAddress &left, const IpAddress &right);
+
+struct IpNetmask : public IpAddress
+{
+  protected:
+    uint8_t _netmask;
+
+  public:
+    IpNetmask() : IpAddress(), _netmask(0)
+    {}
+    IpNetmask(const uint32_t __ip, const uint8_t __netmask) :
+        IpAddress(__ip), _netmask(__netmask)
+    {}
+
+    uint8_t netmask() const { return _netmask; }
+
+    std::string string() const;
+};
+
+std::ostream &operator<<(std::ostream &stream, const IpNetmask &in);
+bool operator==(const IpNetmask &left, const IpNetmask &right);
+
+struct IpWithPort : public IpAddress
+{
+  protected:
+    uint16_t _port;
+
+  public:
+    IpWithPort() : IpAddress(), _port(0)
+    {}
+    IpWithPort(const uint32_t __ip, const uint16_t __port) :
+        IpAddress(__ip), _port(__port)
+    {}
+
+    uint8_t port() const { return _port; }
+
+    std::string string() const;
+};
+
+std::ostream &operator<<(std::ostream &stream, const IpWithPort &iwp);
+bool operator==(const IpWithPort &left, const IpWithPort &right);
+
 struct IpOpt;
 struct IpHdr : public ip_hdr
 {
@@ -216,6 +278,8 @@ class IpPtr
     EthPacketPtr packet() { return p; }
     bool operator!() const { return !p; }
     operator bool() const { return p; }
+    int off() const { return sizeof(eth_hdr); }
+    int pstart() const { return off() + get()->size(); }
 };
 
 uint16_t cksum(const IpPtr &ptr);
@@ -279,9 +343,9 @@ class TcpPtr
 {
   protected:
     EthPacketPtr p;
-    int off;
+    int _off;
 
-    void set(const EthPacketPtr &ptr, int offset) { p = ptr; off = offset; }
+    void set(const EthPacketPtr &ptr, int offset) { p = ptr; _off = offset; }
     void set(const IpPtr &ptr)
     {
         if (ptr && ptr->proto() == IP_PROTO_TCP)
@@ -291,25 +355,27 @@ class TcpPtr
     }
 
   public:
-    TcpPtr() : p(0), off(0) {}
-    TcpPtr(const IpPtr &ptr) : p(0), off(0) { set(ptr); }
-    TcpPtr(const TcpPtr &ptr) : p(ptr.p), off(ptr.off) {}
+    TcpPtr() : p(0), _off(0) {}
+    TcpPtr(const IpPtr &ptr) : p(0), _off(0) { set(ptr); }
+    TcpPtr(const TcpPtr &ptr) : p(ptr.p), _off(ptr._off) {}
 
-    TcpHdr *get() { return (TcpHdr *)(p->data + off); }
+    TcpHdr *get() { return (TcpHdr *)(p->data + _off); }
     TcpHdr *operator->() { return get(); }
     TcpHdr &operator*() { return *get(); }
 
-    const TcpHdr *get() const { return (const TcpHdr *)(p->data + off); }
+    const TcpHdr *get() const { return (const TcpHdr *)(p->data + _off); }
     const TcpHdr *operator->() const { return get(); }
     const TcpHdr &operator*() const { return *get(); }
 
     const TcpPtr &operator=(const IpPtr &i) { set(i); return *this; }
-    const TcpPtr &operator=(const TcpPtr &t) { set(t.p, t.off); return *this; }
+    const TcpPtr &operator=(const TcpPtr &t) { set(t.p, t._off); return *this; }
 
     const EthPacketPtr packet() const { return p; }
     EthPacketPtr packet() { return p; }
     bool operator!() const { return !p; }
     operator bool() const { return p; }
+    int off() const { return _off; }
+    int pstart() const { return off() + get()->size(); }
 };
 
 uint16_t cksum(const TcpPtr &ptr);
@@ -366,9 +432,9 @@ class UdpPtr
 {
   protected:
     EthPacketPtr p;
-    int off;
+    int _off;
 
-    void set(const EthPacketPtr &ptr, int offset) { p = ptr; off = offset; }
+    void set(const EthPacketPtr &ptr, int offset) { p = ptr; _off = offset; }
     void set(const IpPtr &ptr)
     {
         if (ptr && ptr->proto() == IP_PROTO_UDP)
@@ -378,29 +444,33 @@ class UdpPtr
     }
 
   public:
-    UdpPtr() : p(0), off(0) {}
-    UdpPtr(const IpPtr &ptr) : p(0), off(0) { set(ptr); }
-    UdpPtr(const UdpPtr &ptr) : p(ptr.p), off(ptr.off) {}
+    UdpPtr() : p(0), _off(0) {}
+    UdpPtr(const IpPtr &ptr) : p(0), _off(0) { set(ptr); }
+    UdpPtr(const UdpPtr &ptr) : p(ptr.p), _off(ptr._off) {}
 
-    UdpHdr *get() { return (UdpHdr *)(p->data + off); }
+    UdpHdr *get() { return (UdpHdr *)(p->data + _off); }
     UdpHdr *operator->() { return get(); }
     UdpHdr &operator*() { return *get(); }
 
-    const UdpHdr *get() const { return (const UdpHdr *)(p->data + off); }
+    const UdpHdr *get() const { return (const UdpHdr *)(p->data + _off); }
     const UdpHdr *operator->() const { return get(); }
     const UdpHdr &operator*() const { return *get(); }
 
     const UdpPtr &operator=(const IpPtr &i) { set(i); return *this; }
-    const UdpPtr &operator=(const UdpPtr &t) { set(t.p, t.off); return *this; }
+    const UdpPtr &operator=(const UdpPtr &t) { set(t.p, t._off); return *this; }
 
     const EthPacketPtr packet() const { return p; }
     EthPacketPtr packet() { return p; }
     bool operator!() const { return !p; }
     operator bool() const { return p; }
+    int off() const { return _off; }
+    int pstart() const { return off() + get()->size(); }
 };
 
 uint16_t cksum(const UdpPtr &ptr);
 
-/* namespace Net */ }
+int hsplit(const EthPacketPtr &ptr);
+
+} // namespace Net
 
 #endif // __BASE_INET_HH__