undo SocketDefaults class; plumb in new UdpSocket option attributes

This commit is contained in:
Tom Henderson
2008-05-16 21:28:07 -07:00
parent 18011ba4eb
commit 0a476b4f04
10 changed files with 45 additions and 214 deletions

View File

@@ -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> node = *i;
Ptr<PacketSocketFactory> factory = CreateObject<PacketSocketFactory> ();
node->AggregateObject (factory);
Ptr<SocketDefaults> sockDefaults = CreateObject<SocketDefaults> ();
node->AggregateObject (sockDefaults);
}
}

View File

@@ -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> node)
Ptr<UdpImpl> udpImpl = CreateObject<UdpImpl> ();
Ptr<TcpImpl> tcpImpl = CreateObject<TcpImpl> ();
Ptr<Ipv4Impl> ipv4Impl = CreateObject<Ipv4Impl> ();
Ptr<SocketDefaults> sockDef = CreateObject<SocketDefaults> ();
udpImpl->SetUdp (udp);
tcpImpl->SetTcp (tcp);
@@ -74,7 +72,6 @@ AddInternetStack (Ptr<Node> node)
node->AggregateObject (udpImpl);
node->AggregateObject (tcpImpl);
node->AggregateObject (ipv4L4Demux);
node->AggregateObject (sockDef);
}
}//namespace ns3

View File

@@ -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 <algorithm>
@@ -188,17 +187,6 @@ TcpSocket::SetNode (Ptr<Node> 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<SocketDefaults> sd = node->GetObject<SocketDefaults> ();
NS_ASSERT (sd != 0);
UintegerValue uiv;
sd->GetAttribute ("DefaultSndBufLimit", uiv);
m_sndBufLimit = uiv.Get();
sd->GetAttribute ("DefaultRcvBufLimit", uiv);
m_rcvBufLimit = uiv.Get();
}
void

View File

@@ -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<UdpSocket> ()
.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<uint32_t> ())
.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<uint8_t> ())
.AddAttribute ("IpMulticastTtl",
"Time-to-live for multicast IP packets",
UintegerValue (64),
MakeUintegerAccessor (&UdpSocket::m_ipMulticastTtl),
MakeUintegerChecker<uint8_t> ())
;
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> node)
{
NS_LOG_FUNCTION_NOARGS ();
// Pull default values for socket options from SocketDefaults
// object that was aggregated to the node
m_node = node;
Ptr<SocketDefaults> sd = node->GetObject<SocketDefaults> ();
NS_ASSERT (sd != 0);
UintegerValue uiv;
sd->GetAttribute ("DefaultRcvBufLimit", uiv);
m_rcvBufLimit = uiv.Get();
}
void
@@ -412,7 +428,7 @@ UdpSocket::ForwardUp (Ptr<Packet> 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> 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

View File

@@ -63,12 +63,6 @@ public:
virtual Ptr<Packet> 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<Ptr<Packet> > 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

View File

@@ -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<PacketSocket> ()
.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<uint32_t> ())
;
return tid;
}
@@ -58,16 +62,6 @@ PacketSocket::SetNode (Ptr<Node> node)
{
NS_LOG_FUNCTION_NOARGS ();
m_node = node;
// Pull default values for socket options from SocketDefaults
// object that was aggregated to the node
Ptr<SocketDefaults> sd = node->GetObject<SocketDefaults> ();
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<NetDevice> device, Ptr<Packet> 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

View File

@@ -96,12 +96,6 @@ public:
virtual Ptr<Packet> 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<NetDevice> device, Ptr<Packet> packet,
uint16_t protocol, const Address &from);
@@ -128,9 +122,9 @@ private:
uint32_t m_rxAvailable;
TracedCallback<Ptr<const Packet> > 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;
};

View File

@@ -30,64 +30,9 @@ NS_LOG_COMPONENT_DEFINE ("Socket");
namespace ns3 {
TypeId
SocketOptions::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::SocketOptions")
.SetParent<Object> ()
.AddConstructor<SocketOptions> ()
;
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<Socket> sock = GetObject<Socket> ();
sock->SetSndBuf (size);
}
uint32_t
SocketOptions::GetSndBuf (void) const
{
NS_LOG_FUNCTION_NOARGS ();
Ptr<Socket> sock = GetObject<Socket> ();
return sock->GetSndBuf ();
}
void
SocketOptions::SetRcvBuf (uint32_t size)
{
NS_LOG_FUNCTION_NOARGS ();
Ptr<Socket> sock = GetObject<Socket> ();
sock->SetRcvBuf (size);
}
uint32_t
SocketOptions::GetRcvBuf (void) const
{
NS_LOG_FUNCTION_NOARGS ();
Ptr<Socket> sock = GetObject<Socket> ();
return sock->GetRcvBuf ();
}
Socket::Socket (void)
{
NS_LOG_FUNCTION_NOARGS ();
Ptr<SocketOptions> s = CreateObject<SocketOptions> ();
AggregateObject (s);
}
Socket::~Socket ()

View File

@@ -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<void, Ptr<Socket>, uint32_t > m_sendCb;
Callback<void, Ptr<Socket> > 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;
};
/**

View File

@@ -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',