diff --git a/src/helper/packet-socket-helper.cc b/src/helper/packet-socket-helper.cc index ad744bfb1..dd8d2b3fe 100644 --- a/src/helper/packet-socket-helper.cc +++ b/src/helper/packet-socket-helper.cc @@ -1,6 +1,5 @@ #include "packet-socket-helper.h" #include "ns3/packet-socket-factory.h" -#include "ns3/socket-defaults.h" namespace ns3 { @@ -12,8 +11,6 @@ PacketSocketHelper::Install (NodeContainer c) Ptr node = *i; Ptr factory = CreateObject (); node->AggregateObject (factory); - Ptr sockDefaults = CreateObject (); - node->AggregateObject (sockDefaults); } } diff --git a/src/internet-node/internet-stack.cc b/src/internet-node/internet-stack.cc index f4d7c66a4..916f436ac 100644 --- a/src/internet-node/internet-stack.cc +++ b/src/internet-node/internet-stack.cc @@ -21,7 +21,6 @@ #include "ns3/net-device.h" #include "ns3/callback.h" #include "ns3/node.h" -#include "ns3/socket-defaults.h" #include "ipv4-l4-demux.h" #include "udp-l4-protocol.h" @@ -62,7 +61,6 @@ AddInternetStack (Ptr node) Ptr udpImpl = CreateObject (); Ptr tcpImpl = CreateObject (); Ptr ipv4Impl = CreateObject (); - Ptr sockDef = CreateObject (); udpImpl->SetUdp (udp); tcpImpl->SetTcp (tcp); @@ -74,7 +72,6 @@ AddInternetStack (Ptr node) node->AggregateObject (udpImpl); node->AggregateObject (tcpImpl); node->AggregateObject (ipv4L4Demux); - node->AggregateObject (sockDef); } }//namespace ns3 diff --git a/src/internet-node/tcp-socket.cc b/src/internet-node/tcp-socket.cc index 5f8e0d195..3e2a7bc2a 100644 --- a/src/internet-node/tcp-socket.cc +++ b/src/internet-node/tcp-socket.cc @@ -32,7 +32,6 @@ #include "ns3/simulator.h" #include "ns3/packet.h" #include "ns3/uinteger.h" -#include "ns3/socket-defaults.h" #include "ns3/trace-source-accessor.h" #include @@ -188,17 +187,6 @@ TcpSocket::SetNode (Ptr node) m_cnCount = t->GetDefaultConnCount (); m_delAckTimout = Seconds(t->GetDefaultDelAckTimeout ()); m_delAckMaxCount = t->GetDefaultDelAckCount (); - - // Pull default values for socket options from SocketDefaults - // object that was aggregated to the node - Ptr sd = node->GetObject (); - NS_ASSERT (sd != 0); - UintegerValue uiv; - sd->GetAttribute ("DefaultSndBufLimit", uiv); - m_sndBufLimit = uiv.Get(); - sd->GetAttribute ("DefaultRcvBufLimit", uiv); - m_rcvBufLimit = uiv.Get(); - } void diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index c7c87900e..2f6e232b6 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -25,9 +25,9 @@ #include "ns3/ipv4.h" #include "ns3/ipv4.h" #include "ns3/udp.h" -#include "ns3/socket-defaults.h" #include "ns3/trace-source-accessor.h" #include "ns3/uinteger.h" +#include "ns3/boolean.h" #include "udp-socket.h" #include "udp-l4-protocol.h" #include "ipv4-end-point.h" @@ -47,6 +47,31 @@ UdpSocket::GetTypeId (void) .AddConstructor () .AddTraceSource ("Drop", "Drop UDP packet due to receive buffer overflow", MakeTraceSourceAccessor (&UdpSocket::m_dropTrace)) + .AddAttribute ("RcvBufSize", + "UdpSocket maximum receive buffer size (bytes)", + UintegerValue (0xffffffffl), + MakeUintegerAccessor (&UdpSocket::m_rcvBufSize), + MakeUintegerChecker ()) + .AddAttribute ("DontRoute", + "Bypass normal routing; destination must be local", + BooleanValue (false), + MakeBooleanAccessor (&UdpSocket::m_dontRoute), + MakeBooleanChecker ()) + .AddAttribute ("AcceptConn", + "Whether a socket is enabled for listening (read-only)", + BooleanValue (false), + MakeBooleanAccessor (&UdpSocket::m_acceptConn), + MakeBooleanChecker ()) + .AddAttribute ("IpTtl", + "Time-to-live for unicast IP packets", + UintegerValue (64), + MakeUintegerAccessor (&UdpSocket::m_ipTtl), + MakeUintegerChecker ()) + .AddAttribute ("IpMulticastTtl", + "Time-to-live for multicast IP packets", + UintegerValue (64), + MakeUintegerAccessor (&UdpSocket::m_ipMulticastTtl), + MakeUintegerChecker ()) ; return tid; } @@ -59,9 +84,7 @@ UdpSocket::UdpSocket () m_shutdownSend (false), m_shutdownRecv (false), m_connected (false), - m_rxAvailable (0), - m_sndBufLimit (0), - m_rcvBufLimit (0) + m_rxAvailable (0) { NS_LOG_FUNCTION_NOARGS (); } @@ -93,14 +116,7 @@ void UdpSocket::SetNode (Ptr node) { NS_LOG_FUNCTION_NOARGS (); - // Pull default values for socket options from SocketDefaults - // object that was aggregated to the node m_node = node; - Ptr sd = node->GetObject (); - NS_ASSERT (sd != 0); - UintegerValue uiv; - sd->GetAttribute ("DefaultRcvBufLimit", uiv); - m_rcvBufLimit = uiv.Get(); } void @@ -412,7 +428,7 @@ UdpSocket::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) { return; } - if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufLimit) + if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize) { Address address = InetSocketAddress (ipv4, port); SocketRxAddressTag tag; @@ -434,39 +450,6 @@ UdpSocket::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) } } -void -UdpSocket::SetSndBuf (uint32_t size) -{ - NS_LOG_FUNCTION_NOARGS (); - // 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 - NS_LOG_WARN ("UdpSocket has infinite send buffer"); - m_sndBufLimit = size; -} - -uint32_t -UdpSocket::GetSndBuf (void) const -{ - NS_LOG_FUNCTION_NOARGS (); - return m_sndBufLimit; -} - -void -UdpSocket::SetRcvBuf (uint32_t size) -{ - NS_LOG_FUNCTION_NOARGS (); - m_rcvBufLimit = size; -} - -uint32_t -UdpSocket::GetRcvBuf (void) const -{ - NS_LOG_FUNCTION_NOARGS (); - return m_rcvBufLimit; -} - - } //namespace ns3 diff --git a/src/internet-node/udp-socket.h b/src/internet-node/udp-socket.h index 71e55f232..be545a02a 100644 --- a/src/internet-node/udp-socket.h +++ b/src/internet-node/udp-socket.h @@ -63,12 +63,6 @@ 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) const; - virtual void SetRcvBuf (uint32_t size); - virtual uint32_t GetRcvBuf (void) const; - private: friend class Udp; // invoked by Udp class @@ -96,8 +90,13 @@ private: std::queue > m_deliveryQueue; uint32_t m_rxAvailable; - uint32_t m_sndBufLimit; - uint32_t m_rcvBufLimit; + // Socket options (UdpSocket attributes) + uint32_t m_rcvBufSize; + bool m_dontRoute; + bool m_acceptConn; + uint8_t m_ipTtl; + uint8_t m_ipMulticastTtl; + }; }//namespace ns3 diff --git a/src/node/packet-socket.cc b/src/node/packet-socket.cc index 8ebe8748a..58949a331 100644 --- a/src/node/packet-socket.cc +++ b/src/node/packet-socket.cc @@ -25,7 +25,6 @@ #include "ns3/node.h" #include "ns3/packet.h" #include "ns3/uinteger.h" -#include "ns3/socket-defaults.h" #include "ns3/trace-source-accessor.h" NS_LOG_COMPONENT_DEFINE ("PacketSocket"); @@ -40,6 +39,11 @@ PacketSocket::GetTypeId (void) .AddConstructor () .AddTraceSource ("Drop", "Drop packet due to receive buffer overflow", MakeTraceSourceAccessor (&PacketSocket::m_dropTrace)) + .AddAttribute ("RcvBufSize", + "PacketSocket maximum receive buffer size (bytes)", + UintegerValue (0xffffffffl), + MakeUintegerAccessor (&PacketSocket::m_rcvBufSize), + MakeUintegerChecker ()) ; return tid; } @@ -58,16 +62,6 @@ PacketSocket::SetNode (Ptr node) { NS_LOG_FUNCTION_NOARGS (); m_node = node; - // Pull default values for socket options from SocketDefaults - // object that was aggregated to the node - Ptr sd = node->GetObject (); - NS_ASSERT (sd != 0); - UintegerValue uiv; - sd->GetAttribute ("DefaultSndBufLimit", uiv); - m_sndBufLimit = uiv.Get(); - sd->GetAttribute ("DefaultRcvBufLimit", uiv); - m_rcvBufLimit = uiv.Get(); - } PacketSocket::~PacketSocket () @@ -340,7 +334,7 @@ PacketSocket::ForwardUp (Ptr device, Ptr packet, address.SetSingleDevice (device->GetIfIndex ()); address.SetProtocol (protocol); - if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufLimit) + if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize) { SocketRxAddressTag tag; tag.SetAddress (address); @@ -392,32 +386,4 @@ PacketSocket::GetRxAvailable (void) const return m_rxAvailable; } -void -PacketSocket::SetSndBuf (uint32_t size) -{ - NS_LOG_FUNCTION_NOARGS (); - NS_LOG_WARN ("PacketSocket send buffer limit not enforced"); - m_sndBufLimit = size; -} - -uint32_t -PacketSocket::GetSndBuf (void) const -{ - NS_LOG_FUNCTION_NOARGS (); - return m_sndBufLimit; -} -void -PacketSocket::SetRcvBuf (uint32_t size) -{ - NS_LOG_FUNCTION_NOARGS (); - m_rcvBufLimit = size; -} - -uint32_t -PacketSocket::GetRcvBuf (void) const -{ - NS_LOG_FUNCTION_NOARGS (); - return m_rcvBufLimit; -} - }//namespace ns3 diff --git a/src/node/packet-socket.h b/src/node/packet-socket.h index f34c90051..680168f1e 100644 --- a/src/node/packet-socket.h +++ b/src/node/packet-socket.h @@ -96,12 +96,6 @@ 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) const; - virtual void SetRcvBuf (uint32_t size); - virtual uint32_t GetRcvBuf (void) const; - private: void ForwardUp (Ptr device, Ptr packet, uint16_t protocol, const Address &from); @@ -128,9 +122,9 @@ private: uint32_t m_rxAvailable; TracedCallback > m_dropTrace; - - uint32_t m_sndBufLimit; // Max send buffer size - uint32_t m_rcvBufLimit; // Max receive buffer size + + // Socket options (attributes) + uint32_t m_rcvBufSize; }; diff --git a/src/node/socket.cc b/src/node/socket.cc index 9fe458e08..f00625885 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -30,64 +30,9 @@ 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) -{ - NS_LOG_FUNCTION_NOARGS (); - Ptr sock = GetObject (); - sock->SetSndBuf (size); -} - -uint32_t -SocketOptions::GetSndBuf (void) const -{ - NS_LOG_FUNCTION_NOARGS (); - Ptr sock = GetObject (); - return sock->GetSndBuf (); -} - -void -SocketOptions::SetRcvBuf (uint32_t size) -{ - NS_LOG_FUNCTION_NOARGS (); - Ptr sock = GetObject (); - sock->SetRcvBuf (size); -} - -uint32_t -SocketOptions::GetRcvBuf (void) const -{ - NS_LOG_FUNCTION_NOARGS (); - Ptr sock = GetObject (); - return sock->GetRcvBuf (); -} - Socket::Socket (void) { NS_LOG_FUNCTION_NOARGS (); - Ptr s = CreateObject (); - AggregateObject (s); } Socket::~Socket () diff --git a/src/node/socket.h b/src/node/socket.h index c78970af6..847113e84 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -36,40 +36,10 @@ 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. * - * Contrary to the original BSD socket API, this API is asynchronous: + * In contrast to the original BSD socket API, this API is asynchronous: * it does not contain blocking calls. It also uses class ns3::Packet * as a fancy byte buffer, allowing data to be passed across the API * using an ns3::Packet instead of a raw data pointer. Other than that, @@ -78,7 +48,6 @@ public: */ class Socket : public Object { - friend class SocketOptions; public: Socket (void); virtual ~Socket (void); @@ -387,11 +356,6 @@ protected: 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; }; /** diff --git a/src/node/wscript b/src/node/wscript index 747537254..770b1edb9 100644 --- a/src/node/wscript +++ b/src/node/wscript @@ -23,7 +23,6 @@ def build(bld): 'node-list.cc', 'socket.cc', 'socket-factory.cc', - 'socket-defaults.cc', 'packet-socket-factory.cc', 'packet-socket.cc', 'udp.cc', @@ -57,7 +56,6 @@ def build(bld): 'node-list.h', 'socket.h', 'socket-factory.h', - 'socket-defaults.h', 'packet-socket-factory.h', 'udp.h', 'tcp.h',