From 5b119aa40d05ef5ca1141e5f021101899126f352 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Tue, 20 May 2008 07:25:17 -0700 Subject: [PATCH] Add attributes to new abstract base class for UdpSocket --- examples/simple-point-to-point-olsr.cc | 1 + src/internet-node/udp-socket.cc | 62 ++++++++++++++++++-------- src/internet-node/udp-socket.h | 17 +++++-- src/node/socket.cc | 13 ++++++ src/node/socket.h | 2 + src/node/udp-socket-factory.h | 8 +--- src/node/wscript | 2 + 7 files changed, 76 insertions(+), 29 deletions(-) diff --git a/examples/simple-point-to-point-olsr.cc b/examples/simple-point-to-point-olsr.cc index bd7b39487..cd52a0477 100644 --- a/examples/simple-point-to-point-olsr.cc +++ b/examples/simple-point-to-point-olsr.cc @@ -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")); diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index 86d37d2da..a7513e27f 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -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 () + .SetParent () .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 ("IpTtl", - "socket-specific TTL for unicast IP packets (if non-zero)", - UintegerValue (0), - MakeUintegerAccessor (&UdpSocket::m_ipTtl), - MakeUintegerChecker ()) - .AddAttribute ("IpMulticastTtl", - "socket-specific TTL for multicast IP packets (if non-zero)", - UintegerValue (0), - MakeUintegerAccessor (&UdpSocket::m_ipMulticastTtl), - MakeUintegerChecker ()) ; return tid; } @@ -323,6 +309,7 @@ UdpSocket::DoSendTo (Ptr 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, 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, Ptr packet, const Address &from) { @@ -653,7 +678,6 @@ InetSocketAddress (Ipv4Address("255.255.255.255"), 1234)), 123); return result; } - static UdpSocketTest gUdpSocketTest; }; // namespace ns3 diff --git a/src/internet-node/udp-socket.h b/src/internet-node/udp-socket.h index 4683d8f2e..97f24f95a 100644 --- a/src/internet-node/udp-socket.h +++ b/src/internet-node/udp-socket.h @@ -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 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 > 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; }; diff --git a/src/node/socket.cc b/src/node/socket.cc index 8b066edd7..566154b47 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -30,6 +30,19 @@ NS_LOG_COMPONENT_DEFINE ("Socket"); namespace ns3 { +#if 0 +TypeId +Socket::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::Socket") + .SetParent () + .AddConstructor () + ; + return tid; +} + +#endif + Socket::Socket (void) { NS_LOG_FUNCTION_NOARGS (); diff --git a/src/node/socket.h b/src/node/socket.h index 1ea91aebc..a500f3152 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -49,6 +49,8 @@ class Packet; class Socket : public Object { public: +// static TypeId GetTypeId (void); + Socket (void); virtual ~Socket (void); diff --git a/src/node/udp-socket-factory.h b/src/node/udp-socket-factory.h index 3fac525ce..32789c35a 100644 --- a/src/node/udp-socket-factory.h +++ b/src/node/udp-socket-factory.h @@ -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 { diff --git a/src/node/wscript b/src/node/wscript index 1a80b33d6..c1238b8b9 100644 --- a/src/node/wscript +++ b/src/node/wscript @@ -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',