Add attributes to new abstract base class for UdpSocket

This commit is contained in:
Tom Henderson
2008-05-20 07:25:17 -07:00
parent 25de2ff3c4
commit 5b119aa40d
7 changed files with 76 additions and 29 deletions

View File

@@ -67,6 +67,7 @@ main (int argc, char *argv[])
// Set up some default values for the simulation. Use the
Config::SetDefault ("ns3::UdpSocketx::IpTtl", UintegerValue (19));
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));

View File

@@ -38,29 +38,15 @@ namespace ns3 {
static const uint32_t MAX_IPV4_UDP_DATAGRAM_SIZE = 65507;
// Add attributes generic to all UdpSockets to base class UdpSocket
TypeId
UdpSocket::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::UdpSocket")
.SetParent<Socket> ()
.SetParent<UdpSocketx> ()
.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 ("IpTtl",
"socket-specific TTL for unicast IP packets (if non-zero)",
UintegerValue (0),
MakeUintegerAccessor (&UdpSocket::m_ipTtl),
MakeUintegerChecker<uint8_t> ())
.AddAttribute ("IpMulticastTtl",
"socket-specific TTL for multicast IP packets (if non-zero)",
UintegerValue (0),
MakeUintegerAccessor (&UdpSocket::m_ipMulticastTtl),
MakeUintegerChecker<uint8_t> ())
;
return tid;
}
@@ -323,6 +309,7 @@ UdpSocket::DoSendTo (Ptr<Packet> p, Ipv4Address dest, uint16_t port)
// irrespective of what is set in these socket options. So, this tagging
// may end up setting the TTL of a limited broadcast packet to be
// the same as a unicast, but it will be fixed further down the stack
//NS_LOG_UNCOND ("IPttl: " << m_ipTtl);
if (m_ipMulticastTtl != 0 && dest.IsMulticast ())
{
SocketIpTtlTag tag;
@@ -456,6 +443,43 @@ UdpSocket::ForwardUp (Ptr<Packet> packet, Ipv4Address ipv4, uint16_t port)
}
}
void
UdpSocket::SetRcvBufSize (uint32_t size)
{
m_rcvBufSize = size;
}
uint32_t
UdpSocket::GetRcvBufSize (void) const
{
return m_rcvBufSize;
}
void
UdpSocket::SetIpTtl (uint32_t ipTtl)
{
m_ipTtl = ipTtl;
}
uint32_t
UdpSocket::GetIpTtl (void) const
{
return m_ipTtl;
}
void
UdpSocket::SetIpMulticastTtl (uint32_t ipTtl)
{
m_ipMulticastTtl = ipTtl;
}
uint32_t
UdpSocket::GetIpMulticastTtl (void) const
{
return m_ipMulticastTtl;
}
} //namespace ns3
@@ -490,8 +514,9 @@ public:
UdpSocketTest::UdpSocketTest ()
: Test ("UdpSocket") {}
: Test ("UdpSocket")
{
}
void UdpSocketTest::ReceivePacket (Ptr<Socket> socket, Ptr<Packet> packet, const Address &from)
{
@@ -653,7 +678,6 @@ InetSocketAddress (Ipv4Address("255.255.255.255"), 1234)), 123);
return result;
}
static UdpSocketTest gUdpSocketTest;
}; // namespace ns3

View File

@@ -27,6 +27,7 @@
#include "ns3/socket.h"
#include "ns3/ptr.h"
#include "ns3/ipv4-address.h"
#include "ns3/udp-socketx.h"
namespace ns3 {
@@ -35,7 +36,7 @@ class Node;
class Packet;
class UdpL4Protocol;
class UdpSocket : public Socket
class UdpSocket : public UdpSocketx
{
public:
static TypeId GetTypeId (void);
@@ -63,6 +64,14 @@ public:
virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
virtual uint32_t GetRxAvailable (void) const;
// Attributes set through UdpSocket base class
virtual void SetRcvBufSize (uint32_t size);
virtual uint32_t GetRcvBufSize (void) const;
virtual void SetIpTtl (uint32_t ipTtl);
virtual uint32_t GetIpTtl (void) const;
virtual void SetIpMulticastTtl (uint32_t ipTtl);
virtual uint32_t GetIpMulticastTtl (void) const;
private:
friend class UdpSocketFactory;
// invoked by Udp class
@@ -90,10 +99,10 @@ private:
std::queue<Ptr<Packet> > m_deliveryQueue;
uint32_t m_rxAvailable;
// Socket options (UdpSocket attributes)
// Socket attributes
uint32_t m_rcvBufSize;
uint8_t m_ipTtl;
uint8_t m_ipMulticastTtl;
uint32_t m_ipTtl;
uint32_t m_ipMulticastTtl;
};

View File

@@ -30,6 +30,19 @@ NS_LOG_COMPONENT_DEFINE ("Socket");
namespace ns3 {
#if 0
TypeId
Socket::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::Socket")
.SetParent<Object> ()
.AddConstructor<Socket> ()
;
return tid;
}
#endif
Socket::Socket (void)
{
NS_LOG_FUNCTION_NOARGS ();

View File

@@ -49,6 +49,8 @@ class Packet;
class Socket : public Object
{
public:
// static TypeId GetTypeId (void);
Socket (void);
virtual ~Socket (void);

View File

@@ -29,15 +29,11 @@ class Socket;
/**
* \brief API to create UDP socket instances
*
* This abstract class defines the API for UDP sockets.
* This class also can hold the global default variables used to
* initialize newly created sockets, such as values that are
* set through the sysctl or proc interfaces in Linux.
* This abstract class defines the API for UDP socket factory.
* All UDP implementations must provide an implementation of CreateSocket
* below.
*
* \see UdpImpl
* \see UdpSocketFactoryImpl
*/
class UdpSocketFactory : public SocketFactory
{

View File

@@ -25,6 +25,7 @@ def build(bld):
'socket-factory.cc',
'packet-socket-factory.cc',
'packet-socket.cc',
'udp-socketx.cc',
'udp-socket-factory.cc',
'tcp.cc',
'ipv4.cc',
@@ -57,6 +58,7 @@ def build(bld):
'socket.h',
'socket-factory.h',
'packet-socket-factory.h',
'udp-socketx.h',
'udp-socket-factory.h',
'tcp.h',
'ipv4.h',