From 0f55fefabab3f61b9b774db866f2a12d54b20a5e Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Sat, 10 May 2008 21:27:32 -0700 Subject: [PATCH] API for SocketOptions class --- src/internet-node/tcp-socket.cc | 4 +- src/internet-node/tcp-socket.h | 5 ++- src/internet-node/udp-socket.cc | 13 +++---- src/internet-node/udp-socket.h | 5 ++- src/node/packet-socket.cc | 10 +++-- src/node/packet-socket.h | 5 ++- src/node/socket.cc | 50 ++++++++++++++++++++++++ src/node/socket.h | 69 +++++++++++++++++++-------------- 8 files changed, 111 insertions(+), 50 deletions(-) diff --git a/src/internet-node/tcp-socket.cc b/src/internet-node/tcp-socket.cc index 44b78290a..2df2ba7d7 100644 --- a/src/internet-node/tcp-socket.cc +++ b/src/internet-node/tcp-socket.cc @@ -489,7 +489,7 @@ TcpSocket::SetSndBuf (uint32_t size) // XXX Raj to finish uint32_t -TcpSocket::GetSndBuf (void) +TcpSocket::GetSndBuf (void) const { return 0; } @@ -502,7 +502,7 @@ TcpSocket::SetRcvBuf (uint32_t size) // XXX Raj to finish uint32_t -TcpSocket::GetRcvBuf (void) +TcpSocket::GetRcvBuf (void) const { return 0; } diff --git a/src/internet-node/tcp-socket.h b/src/internet-node/tcp-socket.h index ce8948448..2cf21c547 100644 --- a/src/internet-node/tcp-socket.h +++ b/src/internet-node/tcp-socket.h @@ -74,10 +74,11 @@ public: virtual Ptr Recv (uint32_t maxSize, uint32_t flags); virtual uint32_t GetRxAvailable (void) const; +protected: virtual void SetSndBuf (uint32_t size); - virtual uint32_t GetSndBuf (void); + virtual uint32_t GetSndBuf (void) const; virtual void SetRcvBuf (uint32_t size); - virtual uint32_t GetRcvBuf (void); + virtual uint32_t GetRcvBuf (void) const; private: friend class Tcp; diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index b705033a7..4aa9f0b11 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -338,7 +338,7 @@ uint32_t UdpSocket::GetTxAvailable (void) const { // No finite send buffer is modelled - return 0xffffffff; + return std::numeric_limits::max (); } int @@ -416,27 +416,24 @@ UdpSocket::SetSndBuf (uint32_t size) // return EINVAL since we are not modelling a finite send buffer // Enforcing buffer size should be added if we ever start to model // non-zero processing delay in the UDP/IP stack - m_errno = ERROR_INVAL; + NS_LOG_WARN ("UdpSocket has infinite send buffer"); } uint32_t -UdpSocket::GetSndBuf (void) +UdpSocket::GetSndBuf (void) const { - m_errno = ERROR_NOTERROR; - return 0xffffffff; + return std::numeric_limits::max (); } void UdpSocket::SetRcvBuf (uint32_t size) { - m_errno = ERROR_NOTERROR; m_udp_rmem = size; } uint32_t -UdpSocket::GetRcvBuf (void) +UdpSocket::GetRcvBuf (void) const { - m_errno = ERROR_NOTERROR; return m_udp_rmem; } diff --git a/src/internet-node/udp-socket.h b/src/internet-node/udp-socket.h index 74fc2e26b..8ed3ba67e 100644 --- a/src/internet-node/udp-socket.h +++ b/src/internet-node/udp-socket.h @@ -63,10 +63,11 @@ public: virtual Ptr Recv (uint32_t maxSize, uint32_t flags); virtual uint32_t GetRxAvailable (void) const; +protected: virtual void SetSndBuf (uint32_t size); - virtual uint32_t GetSndBuf (void); + virtual uint32_t GetSndBuf (void) const; virtual void SetRcvBuf (uint32_t size); - virtual uint32_t GetRcvBuf (void); + virtual uint32_t GetRcvBuf (void) const; private: friend class Udp; diff --git a/src/node/packet-socket.cc b/src/node/packet-socket.cc index 7accac512..6212cce78 100644 --- a/src/node/packet-socket.cc +++ b/src/node/packet-socket.cc @@ -349,19 +349,21 @@ void PacketSocket::SetSndBuf (uint32_t size) { } + uint32_t -PacketSocket::GetSndBuf (void) +PacketSocket::GetSndBuf (void) const { -return 0; + return 0; } void PacketSocket::SetRcvBuf (uint32_t size) { } + uint32_t -PacketSocket::GetRcvBuf (void) +PacketSocket::GetRcvBuf (void) const { -return 0; + return 0; } }//namespace ns3 diff --git a/src/node/packet-socket.h b/src/node/packet-socket.h index f9997c679..555485bc2 100644 --- a/src/node/packet-socket.h +++ b/src/node/packet-socket.h @@ -93,10 +93,11 @@ public: virtual Ptr Recv (uint32_t maxSize, uint32_t flags); virtual uint32_t GetRxAvailable (void) const; +protected: virtual void SetSndBuf (uint32_t size); - virtual uint32_t GetSndBuf (void); + virtual uint32_t GetSndBuf (void) const; virtual void SetRcvBuf (uint32_t size); - virtual uint32_t GetRcvBuf (void); + virtual uint32_t GetRcvBuf (void) const; private: void ForwardUp (Ptr device, Ptr packet, diff --git a/src/node/socket.cc b/src/node/socket.cc index 528ea79a9..039b635a2 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -28,6 +28,56 @@ NS_LOG_COMPONENT_DEFINE ("Socket"); namespace ns3 { +TypeId +SocketOptions::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::SocketOptions") + .SetParent () + .AddConstructor () + ; + return tid; +} + +SocketOptions::SocketOptions (void) +{ + NS_LOG_FUNCTION_NOARGS (); +} + +SocketOptions::~SocketOptions (void) +{ + NS_LOG_FUNCTION_NOARGS (); +} + + +void +SocketOptions::SetSndBuf (uint32_t size) +{ +} + +uint32_t +SocketOptions::GetSndBuf (void) const +{ + return 0; +} + +void +SocketOptions::SetRcvBuf (uint32_t size) +{ +} + +uint32_t +SocketOptions::GetRcvBuf (void) const +{ + return 0; +} + +Socket::Socket (void) +{ + NS_LOG_FUNCTION_NOARGS (); + Ptr s = CreateObject (); + AggregateObject (s); +} + Socket::~Socket () { NS_LOG_FUNCTION_NOARGS (); diff --git a/src/node/socket.h b/src/node/socket.h index 921070f77..cde3e3a1d 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -36,6 +36,36 @@ namespace ns3 { class Node; class Packet; +/** + * \brief Support for socket options at the socket level. + * + * A SocketOptions object is aggregated to each Socket. This object + * can be fetched using GetObject() by any user of a Socket. An + * instance of SocketOptions is aggregated to each Socket when the + * Socket is constructed. + * + * This implements the equivalent of getsockopt() and setsockopt() + * function calls to manipulate the options associated with the + * socket at the uppermost ``socket'' level. Socket options that + * exist at a lower level (such as TCP socket options) are manipulated + * using a different aggregated class (TcpSocketOptions). + */ +class SocketOptions : public Object +{ +public: + static TypeId GetTypeId (void); + + SocketOptions (void); + virtual ~SocketOptions (void); + + virtual void SetSndBuf (uint32_t size); + virtual uint32_t GetSndBuf (void) const; + virtual void SetRcvBuf (uint32_t size); + virtual uint32_t GetRcvBuf (void) const; + + // all others +}; + /** * \brief Define a Socket API based on the BSD Socket API. * @@ -48,8 +78,10 @@ class Packet; */ class Socket : public Object { + friend class SocketOptions; public: - virtual ~Socket(); + Socket (void); + virtual ~Socket (void); enum SocketErrno { ERROR_NOTERROR, @@ -286,35 +318,6 @@ public: */ virtual uint32_t GetRxAvailable (void) const = 0; - /** - * \brief ns-3 version of setsockopt (SO_SNDBUF) - * - * The error code value can be checked by calling GetErrno () - */ - virtual void SetSndBuf (uint32_t size) = 0; - /** - * \brief ns-3 version of getsockopt (SO_SNDBUF) - * - * The error code value can be checked by calling GetErrno () - * - * \returns The size in bytes of the send buffer - */ - virtual uint32_t GetSndBuf (void) = 0; - /** - * \brief ns-3 version of setsockopt (SO_RCVBUF) - * - * The error code value can be checked by calling GetErrno () - */ - virtual void SetRcvBuf (uint32_t size) = 0; - /** - * \brief ns-3 version of getsockopt (SO_RCVBUF) - * - * The error code value can be checked by calling GetErrno () - * - * \returns The size in bytes of the receive buffer - */ - virtual uint32_t GetRcvBuf (void) = 0; - protected: void NotifyCloseCompleted (void); void NotifyConnectionSucceeded (void); @@ -337,6 +340,12 @@ protected: Callback, uint32_t> m_dataSent; Callback, uint32_t > m_sendCb; Callback > m_receivedData; + + // Socket options at level socket + virtual void SetSndBuf (uint32_t size) = 0; + virtual uint32_t GetSndBuf (void) const = 0; + virtual void SetRcvBuf (uint32_t size) = 0; + virtual uint32_t GetRcvBuf (void) const = 0; }; /**