Clock: Move the clock and related functions to ClockedObject
[gem5.git] / src / base / inet.cc
index b8da12a99f86e0a5764cce28386251623207950b..7d7eb3f5abdcb854683df88e587f7d0373727881 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
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * Authors: Nathan Binkert
+ *          Gabe Black
  */
 
+#include <cstddef>
+#include <cstdio>
 #include <sstream>
 #include <string>
 
 #include "base/cprintf.hh"
-#include "sim/host.hh"
 #include "base/inet.hh"
+#include "base/types.hh"
 
 using namespace std;
 namespace Net {
@@ -116,6 +120,73 @@ operator<<(ostream &stream, const EthAddr &ea)
     return stream;
 }
 
+string
+IpAddress::string() const
+{
+    stringstream stream;
+    stream << *this;
+    return stream.str();
+}
+
+bool
+operator==(const IpAddress &left, const IpAddress &right)
+{
+    return left.ip() == right.ip();
+}
+
+ostream &
+operator<<(ostream &stream, const IpAddress &ia)
+{
+    uint32_t ip = ia.ip();
+    ccprintf(stream, "%x.%x.%x.%x",
+            (uint8_t)(ip >> 24), (uint8_t)(ip >> 16),
+            (uint8_t)(ip >> 8),  (uint8_t)(ip >> 0));
+    return stream;
+}
+
+string
+IpNetmask::string() const
+{
+    stringstream stream;
+    stream << *this;
+    return stream.str();
+}
+
+bool
+operator==(const IpNetmask &left, const IpNetmask &right)
+{
+    return (left.ip() == right.ip()) &&
+        (left.netmask() == right.netmask());
+}
+
+ostream &
+operator<<(ostream &stream, const IpNetmask &in)
+{
+    ccprintf(stream, "%s/%d", (const IpAddress &)in, in.netmask());
+    return stream;
+}
+
+string
+IpWithPort::string() const
+{
+    stringstream stream;
+    stream << *this;
+    return stream.str();
+}
+
+bool
+operator==(const IpWithPort &left, const IpWithPort &right)
+{
+    return (left.ip() == right.ip()) && (left.port() == right.port());
+}
+
+ostream &
+operator<<(ostream &stream, const IpWithPort &iwp)
+{
+    ccprintf(stream, "%s:%d", (const IpAddress &)iwp, iwp.port());
+    return stream;
+}
+
 uint16_t
 cksum(const IpPtr &ptr)
 {
@@ -206,4 +277,25 @@ TcpOpt::sack(vector<SackRange> &vec) const
     return false;
 }
 
-/* namespace Net */ }
+int 
+hsplit(const EthPacketPtr &ptr)
+{
+    int split_point = 0;
+
+    IpPtr ip(ptr);
+    if (ip) {
+        split_point = ip.pstart();
+
+        TcpPtr tcp(ip);
+        if (tcp)
+            split_point = tcp.pstart();
+
+        UdpPtr udp(ip);
+        if (udp)
+            split_point = udp.pstart();
+    }
+    return split_point;
+}
+
+
+} // namespace Net