From d7a038431f9ef418c3462f5947f1285539708656 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Thu, 24 Apr 2008 08:18:01 -0700 Subject: [PATCH 01/45] Plumb in socket receive pull model, in parallel to existing Receive framework --- src/applications/packet-sink/packet-sink.cc | 23 +++++++++++++++++++++ src/applications/packet-sink/packet-sink.h | 2 ++ src/internet-node/tcp-socket.cc | 8 +++++++ src/internet-node/tcp-socket.h | 5 +++++ src/internet-node/udp-socket.cc | 8 +++++++ src/internet-node/udp-socket.h | 5 ++++- src/node/packet-socket.cc | 8 +++++++ src/node/packet-socket.h | 5 +++++ src/node/socket.cc | 16 ++++++++++++++ src/node/socket.h | 11 +++++++++- 10 files changed, 89 insertions(+), 2 deletions(-) diff --git a/src/applications/packet-sink/packet-sink.cc b/src/applications/packet-sink/packet-sink.cc index 6b768978b..e090f40ac 100644 --- a/src/applications/packet-sink/packet-sink.cc +++ b/src/applications/packet-sink/packet-sink.cc @@ -88,6 +88,7 @@ void PacketSink::StartApplication() // Called at time specified by Start } m_socket->SetRecvCallback (MakeCallback(&PacketSink::Receive, this)); + m_socket->SetRecv_Callback (MakeCallback(&PacketSink::HandleRead, this)); m_socket->SetAcceptCallback ( MakeNullCallback, const Address &> (), MakeNullCallback, const Address&> (), @@ -103,6 +104,28 @@ void PacketSink::StopApplication() // Called at time specified by Stop } } +void PacketSink::HandleRead (Ptr socket) +{ + Ptr packet; + uint32_t maxSize = std::numeric_limits::max(); + uint32_t flags = 0; // no flags + while (packet = socket->Recv (maxSize, flags)) + { + NS_LOG_INFO ("Received " << packet->GetSize()); +#if 0 + // this code waits until we pass address as a Packet tag + if (InetSocketAddress::IsMatchingType (from)) + { + address = InetSocketAddress::ConvertFrom (from); + NS_LOG_INFO ("Received " << packet->GetSize() << " bytes from " << + address.GetIpv4() << " [" << address << "]---'" << + packet->PeekData() << "'"); + } + m_rxTrace (packet, from); +#endif + } +} + // This LOG output inspired by the application on Joseph Kopena's wiki void PacketSink::Receive(Ptr socket, Ptr packet, const Address &from) diff --git a/src/applications/packet-sink/packet-sink.h b/src/applications/packet-sink/packet-sink.h index 70f190ab0..576784dda 100644 --- a/src/applications/packet-sink/packet-sink.h +++ b/src/applications/packet-sink/packet-sink.h @@ -66,6 +66,8 @@ private: virtual void StopApplication (void); // Called at time specified by Stop virtual void Receive (Ptr socket, Ptr packet, const Address& from); + virtual void HandleRead (Ptr socket); + virtual void CloseConnection (Ptr socket); Ptr m_socket; // Associated socket diff --git a/src/internet-node/tcp-socket.cc b/src/internet-node/tcp-socket.cc index ef6a40dc2..e88693979 100644 --- a/src/internet-node/tcp-socket.cc +++ b/src/internet-node/tcp-socket.cc @@ -442,6 +442,14 @@ TcpSocket::Listen (uint32_t q) return 0; } +Ptr +TcpSocket::Recv (uint32_t maxSize, uint32_t flags) +{ + Ptr p = m_deliveryQueue.front (); + m_deliveryQueue.pop (); + return p; +} + void TcpSocket::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) { diff --git a/src/internet-node/tcp-socket.h b/src/internet-node/tcp-socket.h index 7499e2a3e..6bf63082f 100644 --- a/src/internet-node/tcp-socket.h +++ b/src/internet-node/tcp-socket.h @@ -21,6 +21,7 @@ #define TCP_SOCKET_H #include +#include #include "ns3/callback.h" #include "ns3/traced-value.h" #include "ns3/socket.h" @@ -69,6 +70,8 @@ public: virtual int SendTo(const Address &address, Ptr p); virtual int Listen(uint32_t queueLimit); + virtual Ptr Recv (uint32_t maxSize, uint32_t flags); + private: friend class Tcp; // invoked by Tcp class @@ -170,6 +173,8 @@ private: Time m_cnTimeout; uint32_t m_cnCount; + // Temporary queue for delivering data to application + std::queue > m_deliveryQueue; }; }//namespace ns3 diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index 951a8c73f..00ba74e9a 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -513,6 +513,14 @@ UdpSocketTest::RunTests (void) return result; } +Ptr +UdpSocket::Recv (uint32_t maxSize, uint32_t flags) +{ + Ptr p = m_deliveryQueue.front (); + m_deliveryQueue.pop (); + return p; +} + static UdpSocketTest gUdpSocketTest; diff --git a/src/internet-node/udp-socket.h b/src/internet-node/udp-socket.h index 0b662926e..d976e1ad3 100644 --- a/src/internet-node/udp-socket.h +++ b/src/internet-node/udp-socket.h @@ -21,6 +21,7 @@ #define UDP_SOCKET_H #include +#include #include "ns3/callback.h" #include "ns3/socket.h" #include "ns3/ptr.h" @@ -56,7 +57,7 @@ public: virtual int Send (Ptr p); virtual int SendTo(const Address &address,Ptr p); -private: + virtual Ptr Recv (uint32_t maxSize, uint32_t flags); private: friend class Udp; @@ -79,6 +80,8 @@ private: bool m_shutdownSend; bool m_shutdownRecv; bool m_connected; + + std::queue > m_deliveryQueue; }; }//namespace ns3 diff --git a/src/node/packet-socket.cc b/src/node/packet-socket.cc index 7d3578475..fa045e3b0 100644 --- a/src/node/packet-socket.cc +++ b/src/node/packet-socket.cc @@ -305,4 +305,12 @@ PacketSocket::ForwardUp (Ptr device, Ptr packet, NotifyDataReceived (packet, address); } +Ptr +PacketSocket::Recv (uint32_t maxSize, uint32_t flags) +{ + Ptr p = m_deliveryQueue.front (); + m_deliveryQueue.pop (); + return p; +} + }//namespace ns3 diff --git a/src/node/packet-socket.h b/src/node/packet-socket.h index d94ef7030..b5282aaab 100644 --- a/src/node/packet-socket.h +++ b/src/node/packet-socket.h @@ -22,6 +22,7 @@ #define PACKET_SOCKET_H #include +#include #include "ns3/callback.h" #include "ns3/ptr.h" #include "ns3/socket.h" @@ -87,6 +88,8 @@ public: virtual int Send (Ptr p); virtual int SendTo(const Address &address,Ptr p); + virtual Ptr Recv (uint32_t maxSize, uint32_t flags); + private: void ForwardUp (Ptr device, Ptr packet, @@ -109,6 +112,8 @@ private: bool m_isSingleDevice; uint32_t m_device; Address m_destAddr; /// Default destination address + + std::queue > m_deliveryQueue; }; }//namespace ns3 diff --git a/src/node/socket.cc b/src/node/socket.cc index 41f09f879..86d5d2ec8 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -86,6 +86,13 @@ Socket::SetRecvCallback (Callback, Ptr,const Address&> m_receivedData = receivedData; } +void +Socket::SetRecv_Callback (Callback > receivedData) +{ + NS_LOG_FUNCTION_NOARGS (); + m_receivedData_ = receivedData; +} + int Socket::Listen (uint32_t queueLimit) { return 0; //XXX the base class version does nothing @@ -230,4 +237,13 @@ Socket::NotifyDataReceived (Ptr p, const Address &from) } } +void +Socket::NotifyDataRecv (void) +{ + NS_LOG_FUNCTION_NOARGS (); + if (!m_receivedData_.IsNull ()) + { + m_receivedData_ (this); + } +} }//namespace ns3 diff --git a/src/node/socket.h b/src/node/socket.h index 07a267ee7..8340ae665 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -157,7 +157,12 @@ public: */ void SetRecvCallback (Callback, Ptr, const Address&> receivedData); - + /** + * \brief Receive data + * \param receivedData Invoked whenever new data is received. + * + */ + void SetRecv_Callback (Callback >); /** * \param address the address to try to allocate * \returns 0 on success, -1 on failure. @@ -252,6 +257,8 @@ public: */ int SendTo (const Address &address, const uint8_t* buf, uint32_t size); + virtual Ptr Recv (uint32_t maxSize, uint32_t flags) = 0; + protected: void NotifyCloseCompleted (void); void NotifyConnectionSucceeded (void); @@ -263,6 +270,7 @@ protected: void NotifyDataSent (uint32_t size); void NotifySend (uint32_t spaceAvailable); void NotifyDataReceived (Ptr p, const Address &from); + void NotifyDataRecv (void); Callback > m_closeCompleted; Callback > m_connectionSucceeded; @@ -274,6 +282,7 @@ protected: Callback, uint32_t> m_dataSent; Callback, uint32_t > m_sendCb; Callback, Ptr,const Address&> m_receivedData; + Callback > m_receivedData_; }; } //namespace ns3 From 288d193daaf34aa078c2cb3d59cfd02b9ae4c731 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Fri, 25 Apr 2008 14:29:28 -0700 Subject: [PATCH 02/45] Cut over UDP applications to use the new receive API --- src/applications/udp-echo/udp-echo-client.cc | 25 +++++++- src/applications/udp-echo/udp-echo-client.h | 1 + src/applications/udp-echo/udp-echo-server.cc | 28 ++++++++- src/applications/udp-echo/udp-echo-server.h | 1 + src/common/tags.h | 2 +- src/internet-node/tcp-socket.cc | 13 +++- src/internet-node/udp-socket.cc | 65 +++++++++++++++++--- src/node/packet-socket.cc | 19 +++++- src/node/socket.cc | 49 +++++++++++++++ src/node/socket.h | 30 +++++++++ src/routing/olsr/olsr-agent-impl.cc | 16 +++-- src/routing/olsr/olsr-agent-impl.h | 4 +- 12 files changed, 230 insertions(+), 23 deletions(-) diff --git a/src/applications/udp-echo/udp-echo-client.cc b/src/applications/udp-echo/udp-echo-client.cc index 6d122d872..458beb105 100644 --- a/src/applications/udp-echo/udp-echo-client.cc +++ b/src/applications/udp-echo/udp-echo-client.cc @@ -103,7 +103,7 @@ UdpEchoClient::StartApplication (void) m_socket->Connect (InetSocketAddress (m_peerAddress, m_peerPort)); } - m_socket->SetRecvCallback(MakeCallback(&UdpEchoClient::Receive, this)); + m_socket->SetRecv_Callback(MakeCallback(&UdpEchoClient::HandleRead, this)); ScheduleTransmit (Seconds(0.)); } @@ -148,6 +148,29 @@ UdpEchoClient::Send (void) } } +void +UdpEchoClient::HandleRead (Ptr socket) +{ + NS_LOG_FUNCTION (this << socket); + Ptr packet; + uint32_t maxSize = std::numeric_limits::max(); + uint32_t flags = 0; // no flags + while (packet = socket->Recv (maxSize, flags)) + { + SocketRxAddressTag tag; + bool found = packet->PeekTag (tag); + NS_ASSERT (found); + Address from = tag.GetAddress (); + packet->RemoveTag (tag); + if (InetSocketAddress::IsMatchingType (from)) + { + InetSocketAddress address = InetSocketAddress::ConvertFrom (from); + NS_LOG_INFO ("Received " << packet->GetSize() << " bytes from " << + address.GetIpv4()); + } + } +} + void UdpEchoClient::Receive( Ptr socket, diff --git a/src/applications/udp-echo/udp-echo-client.h b/src/applications/udp-echo/udp-echo-client.h index 9a924edc2..848bdd211 100644 --- a/src/applications/udp-echo/udp-echo-client.h +++ b/src/applications/udp-echo/udp-echo-client.h @@ -57,6 +57,7 @@ private: void Send (void); void Receive(Ptr socket, Ptr packet, const Address &from); + void HandleRead (Ptr socket); uint32_t m_count; Time m_interval; diff --git a/src/applications/udp-echo/udp-echo-server.cc b/src/applications/udp-echo/udp-echo-server.cc index 3535c3ffc..f0129b160 100644 --- a/src/applications/udp-echo/udp-echo-server.cc +++ b/src/applications/udp-echo/udp-echo-server.cc @@ -79,7 +79,8 @@ UdpEchoServer::StartApplication (void) m_socket->Bind (local); } - m_socket->SetRecvCallback(MakeCallback(&UdpEchoServer::Receive, this)); + //m_socket->SetRecvCallback(MakeCallback(&UdpEchoServer::Receive, this)); + m_socket->SetRecv_Callback(MakeCallback(&UdpEchoServer::HandleRead, this)); } void @@ -94,6 +95,31 @@ UdpEchoServer::StopApplication () } } +void +UdpEchoServer::HandleRead (Ptr socket) +{ + Ptr packet; + uint32_t maxSize = std::numeric_limits::max(); + uint32_t flags = 0; // no flags + while (packet = socket->Recv (maxSize, flags)) + { + SocketRxAddressTag tag; + bool found = packet->PeekTag (tag); + NS_ASSERT (found); + Address from = tag.GetAddress (); + packet->RemoveTag (tag); + if (InetSocketAddress::IsMatchingType (from)) + { + InetSocketAddress address = InetSocketAddress::ConvertFrom (from); + NS_LOG_INFO ("Received " << packet->GetSize() << " bytes from " << + address.GetIpv4()); + + NS_LOG_LOGIC ("Echoing packet"); + socket->SendTo (from, packet); + } + } +} + void UdpEchoServer::Receive( Ptr socket, diff --git a/src/applications/udp-echo/udp-echo-server.h b/src/applications/udp-echo/udp-echo-server.h index e0f55b4cd..6b42ec2fc 100644 --- a/src/applications/udp-echo/udp-echo-server.h +++ b/src/applications/udp-echo/udp-echo-server.h @@ -50,6 +50,7 @@ private: virtual void StopApplication (void); void Receive(Ptr socket, Ptr packet, const Address &from); + void HandleRead (Ptr socket); uint16_t m_port; Ptr m_socket; diff --git a/src/common/tags.h b/src/common/tags.h index a88b6a6e0..d8ca513b5 100644 --- a/src/common/tags.h +++ b/src/common/tags.h @@ -33,7 +33,7 @@ namespace ns3 { * The maximum size (in bytes) of a Tag is stored * in this constant. */ -#define TAGS_MAX_SIZE 16 +#define TAGS_MAX_SIZE 32 class Tags { public: diff --git a/src/internet-node/tcp-socket.cc b/src/internet-node/tcp-socket.cc index e88693979..34f0476f3 100644 --- a/src/internet-node/tcp-socket.cc +++ b/src/internet-node/tcp-socket.cc @@ -445,8 +445,19 @@ TcpSocket::Listen (uint32_t q) Ptr TcpSocket::Recv (uint32_t maxSize, uint32_t flags) { + if (m_deliveryQueue.empty() ) + { + return 0; + } Ptr p = m_deliveryQueue.front (); - m_deliveryQueue.pop (); + if (p->GetSize() <= maxSize) + { + m_deliveryQueue.pop (); + } + else + { + p = 0; + } return p; } diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index 00ba74e9a..7a1976639 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -325,6 +325,25 @@ UdpSocket::SendTo(const Address &address, Ptr p) return DoSendTo (p, ipv4, port); } +Ptr +UdpSocket::Recv (uint32_t maxSize, uint32_t flags) +{ + if (m_deliveryQueue.empty() ) + { + return 0; + } + Ptr p = m_deliveryQueue.front (); + if (p->GetSize() <= maxSize) + { + m_deliveryQueue.pop (); + } + else + { + p = 0; + } + return p; +} + void UdpSocket::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) { @@ -334,9 +353,12 @@ UdpSocket::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) { return; } - Address address = InetSocketAddress (ipv4, port); - NotifyDataReceived (packet, address); + SocketRxAddressTag tag; + tag.SetAddress (address); + packet->AddTag (tag); + m_deliveryQueue.push (packet); + NotifyDataRecv (); } } //namespace ns3 @@ -367,6 +389,8 @@ public: void ReceivePacket (Ptr socket, Ptr packet, const Address &from); void ReceivePacket2 (Ptr socket, Ptr packet, const Address &from); + void ReceivePkt (Ptr socket); + void ReceivePkt2 (Ptr socket); }; @@ -384,6 +408,16 @@ void UdpSocketTest::ReceivePacket2 (Ptr socket, Ptr packet, cons m_receivedPacket2 = packet; } +void UdpSocketTest::ReceivePkt (Ptr socket) +{ + m_receivedPacket = socket->Recv (std::numeric_limits::max(), 0); +} + +void UdpSocketTest::ReceivePkt2 (Ptr socket) +{ + m_receivedPacket2 = socket->Recv (std::numeric_limits::max(), 0); +} + bool UdpSocketTest::RunTests (void) { @@ -457,10 +491,18 @@ UdpSocketTest::RunTests (void) Ptr rxSocketFactory = rxNode->GetObject (); Ptr rxSocket = rxSocketFactory->CreateSocket (); NS_TEST_ASSERT_EQUAL (rxSocket->Bind (InetSocketAddress (Ipv4Address ("10.0.0.1"), 1234)), 0); +#ifdef OLDSEMANTICS rxSocket->SetRecvCallback (MakeCallback (&UdpSocketTest::ReceivePacket, this)); +#else + rxSocket->SetRecv_Callback (MakeCallback (&UdpSocketTest::ReceivePkt, this)); +#endif Ptr rxSocket2 = rxSocketFactory->CreateSocket (); +#ifdef OLDSEMANTICS rxSocket2->SetRecvCallback (MakeCallback (&UdpSocketTest::ReceivePacket2, this)); +#else + rxSocket2->SetRecv_Callback (MakeCallback (&UdpSocketTest::ReceivePkt2, this)); +#endif NS_TEST_ASSERT_EQUAL (rxSocket2->Bind (InetSocketAddress (Ipv4Address ("10.0.1.1"), 1234)), 0); Ptr txSocketFactory = txNode->GetObject (); @@ -477,6 +519,8 @@ UdpSocketTest::RunTests (void) NS_TEST_ASSERT_EQUAL (m_receivedPacket->GetSize (), 123); NS_TEST_ASSERT_EQUAL (m_receivedPacket2->GetSize (), 0); // second interface should receive it + m_receivedPacket->RemoveAllTags (); + m_receivedPacket2->RemoveAllTags (); // Simple broadcast test @@ -489,6 +533,8 @@ UdpSocketTest::RunTests (void) // second socket should not receive it (it is bound specifically to the second interface's address NS_TEST_ASSERT_EQUAL (m_receivedPacket2->GetSize (), 0); + m_receivedPacket->RemoveAllTags (); + m_receivedPacket2->RemoveAllTags (); // Broadcast test with multiple receiving sockets @@ -497,7 +543,11 @@ UdpSocketTest::RunTests (void) // the socket address matches. rxSocket2->Dispose (); rxSocket2 = rxSocketFactory->CreateSocket (); +#ifdef OLDSEMANTICS rxSocket2->SetRecvCallback (MakeCallback (&UdpSocketTest::ReceivePacket2, this)); +#else + rxSocket2->SetRecv_Callback (MakeCallback (&UdpSocketTest::ReceivePkt2, this)); +#endif NS_TEST_ASSERT_EQUAL (rxSocket2->Bind (InetSocketAddress (Ipv4Address ("0.0.0.0"), 1234)), 0); m_receivedPacket = Create (); @@ -508,19 +558,14 @@ UdpSocketTest::RunTests (void) NS_TEST_ASSERT_EQUAL (m_receivedPacket->GetSize (), 123); NS_TEST_ASSERT_EQUAL (m_receivedPacket2->GetSize (), 123); + m_receivedPacket->RemoveAllTags (); + m_receivedPacket2->RemoveAllTags (); + Simulator::Destroy (); return result; } -Ptr -UdpSocket::Recv (uint32_t maxSize, uint32_t flags) -{ - Ptr p = m_deliveryQueue.front (); - m_deliveryQueue.pop (); - return p; -} - static UdpSocketTest gUdpSocketTest; diff --git a/src/node/packet-socket.cc b/src/node/packet-socket.cc index fa045e3b0..ad2041333 100644 --- a/src/node/packet-socket.cc +++ b/src/node/packet-socket.cc @@ -301,15 +301,30 @@ PacketSocket::ForwardUp (Ptr device, Ptr packet, address.SetSingleDevice (device->GetIfIndex ()); address.SetProtocol (protocol); + SocketRxAddressTag tag; + tag.SetAddress (address); + packet->AddTag (tag); + m_deliveryQueue.push (packet); NS_LOG_LOGIC ("UID is " << packet->GetUid() << " PacketSocket " << this); - NotifyDataReceived (packet, address); + NotifyDataRecv (); } Ptr PacketSocket::Recv (uint32_t maxSize, uint32_t flags) { + if (m_deliveryQueue.empty() ) + { + return 0; + } Ptr p = m_deliveryQueue.front (); - m_deliveryQueue.pop (); + if (p->GetSize() <= maxSize) + { + m_deliveryQueue.pop (); + } + else + { + p = 0; + } return p; } diff --git a/src/node/socket.cc b/src/node/socket.cc index 86d5d2ec8..071449a31 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -246,4 +246,53 @@ Socket::NotifyDataRecv (void) m_receivedData_ (this); } } + +SocketRxAddressTag::SocketRxAddressTag () +{ +} + +uint32_t +SocketRxAddressTag::GetUid (void) +{ + static uint32_t uid = ns3::Tag::AllocateUid ("SocketRxAddressTag.ns3"); + return uid; +} + +void +SocketRxAddressTag::Print (std::ostream &os) const +{ + os << "address="<< m_address; +} + +uint32_t +SocketRxAddressTag::GetSerializedSize (void) const +{ + return 0; +} + +void +SocketRxAddressTag::Serialize (Buffer::Iterator i) const +{ + // for local use in stack only +} + +uint32_t +SocketRxAddressTag::Deserialize (Buffer::Iterator i) +{ + // for local use in stack only + return 0; +} + +void +SocketRxAddressTag::SetAddress (Address addr) +{ + m_address = addr; +} + +Address +SocketRxAddressTag::GetAddress (void) const +{ + return m_address; +} + }//namespace ns3 diff --git a/src/node/socket.h b/src/node/socket.h index 8340ae665..f60233738 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -25,12 +25,14 @@ #include "ns3/callback.h" #include "ns3/ptr.h" +#include "ns3/tag.h" #include "ns3/object.h" #include "address.h" #include namespace ns3 { + class Node; class Packet; @@ -257,6 +259,14 @@ public: */ int SendTo (const Address &address, const uint8_t* buf, uint32_t size); + /** + * \brief Read a single packet from the socket + * \param maxSize reader will accept packet up to maxSize + * \param flags Socket recv flags + * \returns Ptr of the next in-sequence packet. Returns + * 0 if the socket cannot return a next in-sequence packet conforming + * to the maxSize and flags. + */ virtual Ptr Recv (uint32_t maxSize, uint32_t flags) = 0; protected: @@ -285,6 +295,26 @@ protected: Callback > m_receivedData_; }; +/** + * \brief This class implements a tag that carries the source address + * of a packet across the receiving socket interface. + */ +class SocketRxAddressTag : public Tag +{ +public: + SocketRxAddressTag (); + static uint32_t GetUid (void); + void Print (std::ostream &os) const; + uint32_t GetSerializedSize (void) const; + void Serialize (Buffer::Iterator i) const; + uint32_t Deserialize (Buffer::Iterator i); + + void SetAddress (Address addr); + Address GetAddress (void) const; +private: + Address m_address; +}; + } //namespace ns3 #endif /* SOCKET_H */ diff --git a/src/routing/olsr/olsr-agent-impl.cc b/src/routing/olsr/olsr-agent-impl.cc index 5c27a7d6b..f0bebc2e8 100644 --- a/src/routing/olsr/olsr-agent-impl.cc +++ b/src/routing/olsr/olsr-agent-impl.cc @@ -282,7 +282,7 @@ void AgentImpl::Start () // Create a socket to listen only on this interface Ptr socket = socketFactory->CreateSocket (); - socket->SetRecvCallback (MakeCallback (&AgentImpl::RecvOlsr, this)); + socket->SetRecv_Callback (MakeCallback (&AgentImpl::RecvOlsr, this)); if (socket->Bind (InetSocketAddress (addr, OLSR_PORT_NUMBER))) { NS_FATAL_ERROR ("Failed to bind() OLSR receive socket"); @@ -307,10 +307,18 @@ void AgentImpl::SetMainInterface (uint32_t interface) // // \brief Processes an incoming %OLSR packet following RFC 3626 specification. void -AgentImpl::RecvOlsr (Ptr socket, - Ptr receivedPacket, - const Address &sourceAddress) +AgentImpl::RecvOlsr (Ptr socket) { + Ptr receivedPacket; + uint32_t maxSize = std::numeric_limits::max(); + uint32_t flags = 0; // no flags + receivedPacket = socket->Recv (maxSize, flags); + + SocketRxAddressTag tag; + bool found = receivedPacket->PeekTag (tag); + NS_ASSERT (found); + Address sourceAddress = tag.GetAddress (); + InetSocketAddress inetSourceAddr = InetSocketAddress::ConvertFrom (sourceAddress); Ipv4Address senderIfaceAddr = inetSourceAddr.GetIpv4 (); Ipv4Address receiverIfaceAddr = m_socketAddresses[socket]; diff --git a/src/routing/olsr/olsr-agent-impl.h b/src/routing/olsr/olsr-agent-impl.h index 6c4f4b68a..01e486d35 100644 --- a/src/routing/olsr/olsr-agent-impl.h +++ b/src/routing/olsr/olsr-agent-impl.h @@ -98,9 +98,7 @@ protected: /// Increments message sequence number and returns the new value. inline uint16_t GetMessageSequenceNumber (); - void RecvOlsr (Ptr socket, - Ptr receivedPacket, - const Address &sourceAddress); + void RecvOlsr (Ptr socket); void MprComputation (); void RoutingTableComputation (); From 075851985f671ba2c28c0cb9c33d4aa171705662 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Mon, 28 Apr 2008 21:33:15 -0700 Subject: [PATCH 03/45] Move tcp socket to receive pull model --- src/internet-node/tcp-socket.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/internet-node/tcp-socket.cc b/src/internet-node/tcp-socket.cc index 34f0476f3..b117d2082 100644 --- a/src/internet-node/tcp-socket.cc +++ b/src/internet-node/tcp-socket.cc @@ -975,7 +975,11 @@ void TcpSocket::NewRx (Ptr p, m_nextRxSequence += s; // Advance next expected sequence //bytesReceived += s; // Statistics NS_LOG_LOGIC("Case 1, advanced nrxs to " << m_nextRxSequence ); - NotifyDataReceived (p, fromAddress); + SocketRxAddressTag tag; + tag.SetAddress (fromAddress); + p->AddTag (tag); + m_deliveryQueue.push (p); + NotifyDataRecv (); if (m_closeNotified) { NS_LOG_LOGIC ("Tcp " << this << " HuH? Got data after closeNotif"); @@ -1027,7 +1031,11 @@ void TcpSocket::NewRx (Ptr p, } s1 = p1->GetSize (); } - NotifyDataReceived (p1, fromAddress); + SocketRxAddressTag tag; + tag.SetAddress (fromAddress); + p1->AddTag (tag); + m_deliveryQueue.push (p1); + NotifyDataRecv (); NS_LOG_LOGIC ("TcpSocket " << this << " adv rxseq1 by " << s1 ); m_nextRxSequence += s1; // Note data received From c6f7bb2d3e9f7cedeaf32c8aa81c73e40234986a Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Mon, 28 Apr 2008 21:45:55 -0700 Subject: [PATCH 04/45] remove previous socket receive methods --- examples/wifi-adhoc.cc | 14 ++++++++++---- samples/main-simple.cc | 12 +++++++++--- src/applications/packet-sink/packet-sink.cc | 4 +--- src/applications/udp-echo/udp-echo-client.cc | 3 +-- src/applications/udp-echo/udp-echo-server.cc | 4 +--- src/node/socket.cc | 17 ----------------- src/node/socket.h | 9 --------- 7 files changed, 22 insertions(+), 41 deletions(-) diff --git a/examples/wifi-adhoc.cc b/examples/wifi-adhoc.cc index 0244d8160..35dc1852c 100644 --- a/examples/wifi-adhoc.cc +++ b/examples/wifi-adhoc.cc @@ -38,7 +38,7 @@ public: Experiment (std::string name); GnuplotDataset Run (const WifiHelper &wifi); private: - void ReceivePacket (Ptr socket, Ptr packet, const Address &address); + void ReceivePacket (Ptr socket); void SetPosition (Ptr node, Vector position); Vector GetPosition (Ptr node); void AdvancePosition (Ptr node); @@ -90,9 +90,15 @@ Experiment::AdvancePosition (Ptr node) } void -Experiment::ReceivePacket (Ptr socket, Ptr packet, const Address &address) +Experiment::ReceivePacket (Ptr socket) { - m_bytesTotal += packet->GetSize (); + Ptr packet; + uint32_t maxSize = std::numeric_limits::max(); + uint32_t flags = 0; // no flags + while (packet = socket->Recv (maxSize, flags)) + { + m_bytesTotal += packet->GetSize (); + } } Ptr @@ -102,7 +108,7 @@ Experiment::SetupPacketReceive (Ptr node) Ptr socketFactory = node->GetObject (tid); Ptr sink = socketFactory->CreateSocket (); sink->Bind (); - sink->SetRecvCallback (MakeCallback (&Experiment::ReceivePacket, this)); + sink->SetRecv_Callback (MakeCallback (&Experiment::ReceivePacket, this)); return sink; } diff --git a/samples/main-simple.cc b/samples/main-simple.cc index 2bb339c45..0afc07f4c 100644 --- a/samples/main-simple.cc +++ b/samples/main-simple.cc @@ -23,15 +23,21 @@ GenerateTraffic (Ptr socket, uint32_t size) } static void -SocketPrinter (Ptr socket, Ptr packet, const Address &from) +SocketPrinter (Ptr socket) { - std::cout << "at=" << Simulator::Now ().GetSeconds () << "s, rx bytes=" << packet->GetSize () << std::endl; + Ptr packet; + uint32_t maxSize = std::numeric_limits::max(); + uint32_t flags = 0; // no flags + while (packet = socket->Recv (maxSize, flags)) + { + std::cout << "at=" << Simulator::Now ().GetSeconds () << "s, rx bytes=" << packet->GetSize () << std::endl; + } } static void PrintTraffic (Ptr socket) { - socket->SetRecvCallback (MakeCallback (&SocketPrinter)); + socket->SetRecv_Callback (MakeCallback (&SocketPrinter)); } void diff --git a/src/applications/packet-sink/packet-sink.cc b/src/applications/packet-sink/packet-sink.cc index e090f40ac..b200a4879 100644 --- a/src/applications/packet-sink/packet-sink.cc +++ b/src/applications/packet-sink/packet-sink.cc @@ -87,7 +87,6 @@ void PacketSink::StartApplication() // Called at time specified by Start m_socket->Listen (0); } - m_socket->SetRecvCallback (MakeCallback(&PacketSink::Receive, this)); m_socket->SetRecv_Callback (MakeCallback(&PacketSink::HandleRead, this)); m_socket->SetAcceptCallback ( MakeNullCallback, const Address &> (), @@ -99,8 +98,7 @@ void PacketSink::StopApplication() // Called at time specified by Stop { if (m_socket) { - m_socket->SetRecvCallback (MakeNullCallback, - Ptr, const Address &> ()); + m_socket->SetRecv_Callback (MakeNullCallback > ()); } } diff --git a/src/applications/udp-echo/udp-echo-client.cc b/src/applications/udp-echo/udp-echo-client.cc index 458beb105..86122177f 100644 --- a/src/applications/udp-echo/udp-echo-client.cc +++ b/src/applications/udp-echo/udp-echo-client.cc @@ -115,8 +115,7 @@ UdpEchoClient::StopApplication () if (!m_socket) { - m_socket->SetRecvCallback(MakeNullCallback, Ptr, - const Address &> ()); + m_socket->SetRecv_Callback(MakeNullCallback > ()); } Simulator::Cancel(m_sendEvent); diff --git a/src/applications/udp-echo/udp-echo-server.cc b/src/applications/udp-echo/udp-echo-server.cc index f0129b160..fda6ad08e 100644 --- a/src/applications/udp-echo/udp-echo-server.cc +++ b/src/applications/udp-echo/udp-echo-server.cc @@ -79,7 +79,6 @@ UdpEchoServer::StartApplication (void) m_socket->Bind (local); } - //m_socket->SetRecvCallback(MakeCallback(&UdpEchoServer::Receive, this)); m_socket->SetRecv_Callback(MakeCallback(&UdpEchoServer::HandleRead, this)); } @@ -90,8 +89,7 @@ UdpEchoServer::StopApplication () if (!m_socket) { - m_socket->SetRecvCallback(MakeNullCallback, - Ptr, const Address &> ()); + m_socket->SetRecv_Callback(MakeNullCallback > ()); } } diff --git a/src/node/socket.cc b/src/node/socket.cc index 071449a31..00c17b9ae 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -79,13 +79,6 @@ Socket::SetSendCallback (Callback, uint32_t> sendCb) m_sendCb = sendCb; } -void -Socket::SetRecvCallback (Callback, Ptr,const Address&> receivedData) -{ - NS_LOG_FUNCTION_NOARGS (); - m_receivedData = receivedData; -} - void Socket::SetRecv_Callback (Callback > receivedData) { @@ -227,16 +220,6 @@ Socket::NotifySend (uint32_t spaceAvailable) } } -void -Socket::NotifyDataReceived (Ptr p, const Address &from) -{ - NS_LOG_FUNCTION_NOARGS (); - if (!m_receivedData.IsNull ()) - { - m_receivedData (this, p, from); - } -} - void Socket::NotifyDataRecv (void) { diff --git a/src/node/socket.h b/src/node/socket.h index f60233738..f7300a9b6 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -152,13 +152,6 @@ public: * buffer limit, a maximum-sized integer is always returned. */ void SetSendCallback (Callback, uint32_t> sendCb); - /** - * \brief Receive data - * \param receivedData Invoked whenever new data is received. - * - */ - void SetRecvCallback (Callback, Ptr, - const Address&> receivedData); /** * \brief Receive data * \param receivedData Invoked whenever new data is received. @@ -279,7 +272,6 @@ protected: void NotifyCloseRequested (void); void NotifyDataSent (uint32_t size); void NotifySend (uint32_t spaceAvailable); - void NotifyDataReceived (Ptr p, const Address &from); void NotifyDataRecv (void); Callback > m_closeCompleted; @@ -291,7 +283,6 @@ protected: Callback, const Address&> m_newConnectionCreated; Callback, uint32_t> m_dataSent; Callback, uint32_t > m_sendCb; - Callback, Ptr,const Address&> m_receivedData; Callback > m_receivedData_; }; From af58cc302631189e20842e3bdde4874bdce2a812 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Mon, 28 Apr 2008 21:54:48 -0700 Subject: [PATCH 05/45] remove more dead code --- src/applications/packet-sink/packet-sink.cc | 25 +++++--------------- src/applications/packet-sink/packet-sink.h | 1 - src/applications/udp-echo/udp-echo-client.cc | 17 ------------- src/applications/udp-echo/udp-echo-client.h | 1 - src/applications/udp-echo/udp-echo-server.cc | 19 --------------- src/applications/udp-echo/udp-echo-server.h | 1 - 6 files changed, 6 insertions(+), 58 deletions(-) diff --git a/src/applications/packet-sink/packet-sink.cc b/src/applications/packet-sink/packet-sink.cc index b200a4879..2ed2b1882 100644 --- a/src/applications/packet-sink/packet-sink.cc +++ b/src/applications/packet-sink/packet-sink.cc @@ -109,35 +109,22 @@ void PacketSink::HandleRead (Ptr socket) uint32_t flags = 0; // no flags while (packet = socket->Recv (maxSize, flags)) { - NS_LOG_INFO ("Received " << packet->GetSize()); -#if 0 - // this code waits until we pass address as a Packet tag + SocketRxAddressTag tag; + bool found = packet->PeekTag (tag); + NS_ASSERT (found); + Address from = tag.GetAddress (); + packet->RemoveTag (tag); if (InetSocketAddress::IsMatchingType (from)) { - address = InetSocketAddress::ConvertFrom (from); + InetSocketAddress address = InetSocketAddress::ConvertFrom (from); NS_LOG_INFO ("Received " << packet->GetSize() << " bytes from " << address.GetIpv4() << " [" << address << "]---'" << packet->PeekData() << "'"); } m_rxTrace (packet, from); -#endif } } -// This LOG output inspired by the application on Joseph Kopena's wiki -void PacketSink::Receive(Ptr socket, Ptr packet, - const Address &from) -{ - if (InetSocketAddress::IsMatchingType (from)) - { - InetSocketAddress address = InetSocketAddress::ConvertFrom (from); - NS_LOG_INFO ("Received " << packet->GetSize() << " bytes from " << - address.GetIpv4() << " [" << address << "]---'" << - packet->PeekData() << "'"); - } - m_rxTrace (packet, from); -} - void PacketSink::CloseConnection (Ptr socket) { socket->Close (); diff --git a/src/applications/packet-sink/packet-sink.h b/src/applications/packet-sink/packet-sink.h index 576784dda..638309aad 100644 --- a/src/applications/packet-sink/packet-sink.h +++ b/src/applications/packet-sink/packet-sink.h @@ -65,7 +65,6 @@ private: virtual void StartApplication (void); // Called at time specified by Start virtual void StopApplication (void); // Called at time specified by Stop - virtual void Receive (Ptr socket, Ptr packet, const Address& from); virtual void HandleRead (Ptr socket); virtual void CloseConnection (Ptr socket); diff --git a/src/applications/udp-echo/udp-echo-client.cc b/src/applications/udp-echo/udp-echo-client.cc index 86122177f..382fbac82 100644 --- a/src/applications/udp-echo/udp-echo-client.cc +++ b/src/applications/udp-echo/udp-echo-client.cc @@ -170,21 +170,4 @@ UdpEchoClient::HandleRead (Ptr socket) } } -void -UdpEchoClient::Receive( - Ptr socket, - Ptr packet, - const Address &from) -{ - NS_LOG_FUNCTION (this << socket << packet << from); - - if (InetSocketAddress::IsMatchingType (from)) - { - InetSocketAddress address = InetSocketAddress::ConvertFrom (from); - NS_LOG_INFO ("Received " << packet->GetSize() << " bytes from " << - address.GetIpv4()); - } -} - - } // Namespace ns3 diff --git a/src/applications/udp-echo/udp-echo-client.h b/src/applications/udp-echo/udp-echo-client.h index 848bdd211..bfb1c3fcf 100644 --- a/src/applications/udp-echo/udp-echo-client.h +++ b/src/applications/udp-echo/udp-echo-client.h @@ -56,7 +56,6 @@ private: void ScheduleTransmit (Time dt); void Send (void); - void Receive(Ptr socket, Ptr packet, const Address &from); void HandleRead (Ptr socket); uint32_t m_count; diff --git a/src/applications/udp-echo/udp-echo-server.cc b/src/applications/udp-echo/udp-echo-server.cc index fda6ad08e..c22b03af3 100644 --- a/src/applications/udp-echo/udp-echo-server.cc +++ b/src/applications/udp-echo/udp-echo-server.cc @@ -118,23 +118,4 @@ UdpEchoServer::HandleRead (Ptr socket) } } -void -UdpEchoServer::Receive( - Ptr socket, - Ptr packet, - const Address &from) -{ - NS_LOG_FUNCTION (this << socket << packet << from); - - if (InetSocketAddress::IsMatchingType (from)) - { - InetSocketAddress address = InetSocketAddress::ConvertFrom (from); - NS_LOG_INFO ("Received " << packet->GetSize() << " bytes from " << - address.GetIpv4()); - - NS_LOG_LOGIC ("Echoing packet"); - socket->SendTo (from, packet); - } -} - } // Namespace ns3 diff --git a/src/applications/udp-echo/udp-echo-server.h b/src/applications/udp-echo/udp-echo-server.h index 6b42ec2fc..4e2b09fce 100644 --- a/src/applications/udp-echo/udp-echo-server.h +++ b/src/applications/udp-echo/udp-echo-server.h @@ -49,7 +49,6 @@ private: virtual void StartApplication (void); virtual void StopApplication (void); - void Receive(Ptr socket, Ptr packet, const Address &from); void HandleRead (Ptr socket); uint16_t m_port; From f8a2add6271be6a7b5ae8523280dc677cd8e6877 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Fri, 2 May 2008 09:21:01 -0700 Subject: [PATCH 06/45] more cleanup --- examples/wifi-adhoc.cc | 2 +- samples/main-simple.cc | 2 +- src/applications/packet-sink/packet-sink.cc | 4 ++-- src/applications/udp-echo/udp-echo-client.cc | 4 ++-- src/applications/udp-echo/udp-echo-server.cc | 4 ++-- src/internet-node/udp-socket.cc | 18 +++--------------- src/node/socket.cc | 8 ++++---- src/node/socket.h | 10 ++++++---- src/routing/olsr/olsr-agent-impl.cc | 2 +- 9 files changed, 22 insertions(+), 32 deletions(-) diff --git a/examples/wifi-adhoc.cc b/examples/wifi-adhoc.cc index 35dc1852c..ee2d8d32a 100644 --- a/examples/wifi-adhoc.cc +++ b/examples/wifi-adhoc.cc @@ -108,7 +108,7 @@ Experiment::SetupPacketReceive (Ptr node) Ptr socketFactory = node->GetObject (tid); Ptr sink = socketFactory->CreateSocket (); sink->Bind (); - sink->SetRecv_Callback (MakeCallback (&Experiment::ReceivePacket, this)); + sink->SetRecvCallback (MakeCallback (&Experiment::ReceivePacket, this)); return sink; } diff --git a/samples/main-simple.cc b/samples/main-simple.cc index 0afc07f4c..eddf69b32 100644 --- a/samples/main-simple.cc +++ b/samples/main-simple.cc @@ -37,7 +37,7 @@ SocketPrinter (Ptr socket) static void PrintTraffic (Ptr socket) { - socket->SetRecv_Callback (MakeCallback (&SocketPrinter)); + socket->SetRecvCallback (MakeCallback (&SocketPrinter)); } void diff --git a/src/applications/packet-sink/packet-sink.cc b/src/applications/packet-sink/packet-sink.cc index 2ed2b1882..d55fdf720 100644 --- a/src/applications/packet-sink/packet-sink.cc +++ b/src/applications/packet-sink/packet-sink.cc @@ -87,7 +87,7 @@ void PacketSink::StartApplication() // Called at time specified by Start m_socket->Listen (0); } - m_socket->SetRecv_Callback (MakeCallback(&PacketSink::HandleRead, this)); + m_socket->SetRecvCallback (MakeCallback(&PacketSink::HandleRead, this)); m_socket->SetAcceptCallback ( MakeNullCallback, const Address &> (), MakeNullCallback, const Address&> (), @@ -98,7 +98,7 @@ void PacketSink::StopApplication() // Called at time specified by Stop { if (m_socket) { - m_socket->SetRecv_Callback (MakeNullCallback > ()); + m_socket->SetRecvCallback (MakeNullCallback > ()); } } diff --git a/src/applications/udp-echo/udp-echo-client.cc b/src/applications/udp-echo/udp-echo-client.cc index 382fbac82..a68b600e4 100644 --- a/src/applications/udp-echo/udp-echo-client.cc +++ b/src/applications/udp-echo/udp-echo-client.cc @@ -103,7 +103,7 @@ UdpEchoClient::StartApplication (void) m_socket->Connect (InetSocketAddress (m_peerAddress, m_peerPort)); } - m_socket->SetRecv_Callback(MakeCallback(&UdpEchoClient::HandleRead, this)); + m_socket->SetRecvCallback(MakeCallback(&UdpEchoClient::HandleRead, this)); ScheduleTransmit (Seconds(0.)); } @@ -115,7 +115,7 @@ UdpEchoClient::StopApplication () if (!m_socket) { - m_socket->SetRecv_Callback(MakeNullCallback > ()); + m_socket->SetRecvCallback(MakeNullCallback > ()); } Simulator::Cancel(m_sendEvent); diff --git a/src/applications/udp-echo/udp-echo-server.cc b/src/applications/udp-echo/udp-echo-server.cc index c22b03af3..4472d02b1 100644 --- a/src/applications/udp-echo/udp-echo-server.cc +++ b/src/applications/udp-echo/udp-echo-server.cc @@ -79,7 +79,7 @@ UdpEchoServer::StartApplication (void) m_socket->Bind (local); } - m_socket->SetRecv_Callback(MakeCallback(&UdpEchoServer::HandleRead, this)); + m_socket->SetRecvCallback(MakeCallback(&UdpEchoServer::HandleRead, this)); } void @@ -89,7 +89,7 @@ UdpEchoServer::StopApplication () if (!m_socket) { - m_socket->SetRecv_Callback(MakeNullCallback > ()); + m_socket->SetRecvCallback(MakeNullCallback > ()); } } diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index 7a1976639..cae73b0c7 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -491,18 +491,10 @@ UdpSocketTest::RunTests (void) Ptr rxSocketFactory = rxNode->GetObject (); Ptr rxSocket = rxSocketFactory->CreateSocket (); NS_TEST_ASSERT_EQUAL (rxSocket->Bind (InetSocketAddress (Ipv4Address ("10.0.0.1"), 1234)), 0); -#ifdef OLDSEMANTICS - rxSocket->SetRecvCallback (MakeCallback (&UdpSocketTest::ReceivePacket, this)); -#else - rxSocket->SetRecv_Callback (MakeCallback (&UdpSocketTest::ReceivePkt, this)); -#endif + rxSocket->SetRecvCallback (MakeCallback (&UdpSocketTest::ReceivePkt, this)); Ptr rxSocket2 = rxSocketFactory->CreateSocket (); -#ifdef OLDSEMANTICS - rxSocket2->SetRecvCallback (MakeCallback (&UdpSocketTest::ReceivePacket2, this)); -#else - rxSocket2->SetRecv_Callback (MakeCallback (&UdpSocketTest::ReceivePkt2, this)); -#endif + rxSocket2->SetRecvCallback (MakeCallback (&UdpSocketTest::ReceivePkt2, this)); NS_TEST_ASSERT_EQUAL (rxSocket2->Bind (InetSocketAddress (Ipv4Address ("10.0.1.1"), 1234)), 0); Ptr txSocketFactory = txNode->GetObject (); @@ -543,11 +535,7 @@ UdpSocketTest::RunTests (void) // the socket address matches. rxSocket2->Dispose (); rxSocket2 = rxSocketFactory->CreateSocket (); -#ifdef OLDSEMANTICS - rxSocket2->SetRecvCallback (MakeCallback (&UdpSocketTest::ReceivePacket2, this)); -#else - rxSocket2->SetRecv_Callback (MakeCallback (&UdpSocketTest::ReceivePkt2, this)); -#endif + rxSocket2->SetRecvCallback (MakeCallback (&UdpSocketTest::ReceivePkt2, this)); NS_TEST_ASSERT_EQUAL (rxSocket2->Bind (InetSocketAddress (Ipv4Address ("0.0.0.0"), 1234)), 0); m_receivedPacket = Create (); diff --git a/src/node/socket.cc b/src/node/socket.cc index 00c17b9ae..ad2747094 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -80,10 +80,10 @@ Socket::SetSendCallback (Callback, uint32_t> sendCb) } void -Socket::SetRecv_Callback (Callback > receivedData) +Socket::SetRecvCallback (Callback > receivedData) { NS_LOG_FUNCTION_NOARGS (); - m_receivedData_ = receivedData; + m_receivedData = receivedData; } int Socket::Listen (uint32_t queueLimit) @@ -224,9 +224,9 @@ void Socket::NotifyDataRecv (void) { NS_LOG_FUNCTION_NOARGS (); - if (!m_receivedData_.IsNull ()) + if (!m_receivedData.IsNull ()) { - m_receivedData_ (this); + m_receivedData (this); } } diff --git a/src/node/socket.h b/src/node/socket.h index f7300a9b6..b2b943432 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -153,11 +153,13 @@ public: */ void SetSendCallback (Callback, uint32_t> sendCb); /** - * \brief Receive data - * \param receivedData Invoked whenever new data is received. + * \brief Notify application when new data is available to be read. * + * This callback is intended to notify a socket that would + * have been blocked in a blocking socket model that data + * is available to be read. */ - void SetRecv_Callback (Callback >); + void SetRecvCallback (Callback >); /** * \param address the address to try to allocate * \returns 0 on success, -1 on failure. @@ -283,7 +285,7 @@ protected: Callback, const Address&> m_newConnectionCreated; Callback, uint32_t> m_dataSent; Callback, uint32_t > m_sendCb; - Callback > m_receivedData_; + Callback > m_receivedData; }; /** diff --git a/src/routing/olsr/olsr-agent-impl.cc b/src/routing/olsr/olsr-agent-impl.cc index f0bebc2e8..1db5c5e2a 100644 --- a/src/routing/olsr/olsr-agent-impl.cc +++ b/src/routing/olsr/olsr-agent-impl.cc @@ -282,7 +282,7 @@ void AgentImpl::Start () // Create a socket to listen only on this interface Ptr socket = socketFactory->CreateSocket (); - socket->SetRecv_Callback (MakeCallback (&AgentImpl::RecvOlsr, this)); + socket->SetRecvCallback (MakeCallback (&AgentImpl::RecvOlsr, this)); if (socket->Bind (InetSocketAddress (addr, OLSR_PORT_NUMBER))) { NS_FATAL_ERROR ("Failed to bind() OLSR receive socket"); From bfe0533aa374da2ad7249a972a143de91f308b61 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Fri, 2 May 2008 09:38:18 -0700 Subject: [PATCH 07/45] overloaded Recv() method suggested by Gustavo --- examples/wifi-adhoc.cc | 4 +--- samples/main-simple.cc | 4 +--- src/applications/packet-sink/packet-sink.cc | 4 +--- src/applications/udp-echo/udp-echo-client.cc | 4 +--- src/applications/udp-echo/udp-echo-server.cc | 4 +--- src/node/socket.cc | 6 ++++++ src/node/socket.h | 10 ++++++++++ src/routing/olsr/olsr-agent-impl.cc | 4 +--- 8 files changed, 22 insertions(+), 18 deletions(-) diff --git a/examples/wifi-adhoc.cc b/examples/wifi-adhoc.cc index ee2d8d32a..3bc51ed50 100644 --- a/examples/wifi-adhoc.cc +++ b/examples/wifi-adhoc.cc @@ -93,9 +93,7 @@ void Experiment::ReceivePacket (Ptr socket) { Ptr packet; - uint32_t maxSize = std::numeric_limits::max(); - uint32_t flags = 0; // no flags - while (packet = socket->Recv (maxSize, flags)) + while (packet = socket->Recv ()) { m_bytesTotal += packet->GetSize (); } diff --git a/samples/main-simple.cc b/samples/main-simple.cc index eddf69b32..d8878be4b 100644 --- a/samples/main-simple.cc +++ b/samples/main-simple.cc @@ -26,9 +26,7 @@ static void SocketPrinter (Ptr socket) { Ptr packet; - uint32_t maxSize = std::numeric_limits::max(); - uint32_t flags = 0; // no flags - while (packet = socket->Recv (maxSize, flags)) + while (packet = socket->Recv ()) { std::cout << "at=" << Simulator::Now ().GetSeconds () << "s, rx bytes=" << packet->GetSize () << std::endl; } diff --git a/src/applications/packet-sink/packet-sink.cc b/src/applications/packet-sink/packet-sink.cc index d55fdf720..c35c8e4d7 100644 --- a/src/applications/packet-sink/packet-sink.cc +++ b/src/applications/packet-sink/packet-sink.cc @@ -105,9 +105,7 @@ void PacketSink::StopApplication() // Called at time specified by Stop void PacketSink::HandleRead (Ptr socket) { Ptr packet; - uint32_t maxSize = std::numeric_limits::max(); - uint32_t flags = 0; // no flags - while (packet = socket->Recv (maxSize, flags)) + while (packet = socket->Recv ()) { SocketRxAddressTag tag; bool found = packet->PeekTag (tag); diff --git a/src/applications/udp-echo/udp-echo-client.cc b/src/applications/udp-echo/udp-echo-client.cc index a68b600e4..b452c3d86 100644 --- a/src/applications/udp-echo/udp-echo-client.cc +++ b/src/applications/udp-echo/udp-echo-client.cc @@ -152,9 +152,7 @@ UdpEchoClient::HandleRead (Ptr socket) { NS_LOG_FUNCTION (this << socket); Ptr packet; - uint32_t maxSize = std::numeric_limits::max(); - uint32_t flags = 0; // no flags - while (packet = socket->Recv (maxSize, flags)) + while (packet = socket->Recv ()) { SocketRxAddressTag tag; bool found = packet->PeekTag (tag); diff --git a/src/applications/udp-echo/udp-echo-server.cc b/src/applications/udp-echo/udp-echo-server.cc index 4472d02b1..bfbfde1b4 100644 --- a/src/applications/udp-echo/udp-echo-server.cc +++ b/src/applications/udp-echo/udp-echo-server.cc @@ -97,9 +97,7 @@ void UdpEchoServer::HandleRead (Ptr socket) { Ptr packet; - uint32_t maxSize = std::numeric_limits::max(); - uint32_t flags = 0; // no flags - while (packet = socket->Recv (maxSize, flags)) + while (packet = socket->Recv ()) { SocketRxAddressTag tag; bool found = packet->PeekTag (tag); diff --git a/src/node/socket.cc b/src/node/socket.cc index ad2747094..528ea79a9 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -107,6 +107,12 @@ int Socket::Send (const uint8_t* buf, uint32_t size) return Send (p); } +Ptr +Socket::Recv (void) +{ + return Recv (std::numeric_limits::max(), 0); +} + int Socket::SendTo (const Address &address, const uint8_t* buf, uint32_t size) { NS_LOG_FUNCTION_NOARGS (); diff --git a/src/node/socket.h b/src/node/socket.h index b2b943432..62d512280 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -263,6 +263,16 @@ public: * to the maxSize and flags. */ virtual Ptr Recv (uint32_t maxSize, uint32_t flags) = 0; + /** + * \brief Read a single packet from the socket + * + * Overloaded version of Recv(maxSize, flags) with maxSize + * implicitly set to maximum sized integer, and flags set to zero. + * + * \returns Ptr of the next in-sequence packet. Returns + * 0 if the socket cannot return a next in-sequence packet. + */ + Ptr Recv (void); protected: void NotifyCloseCompleted (void); diff --git a/src/routing/olsr/olsr-agent-impl.cc b/src/routing/olsr/olsr-agent-impl.cc index 1db5c5e2a..3031982f5 100644 --- a/src/routing/olsr/olsr-agent-impl.cc +++ b/src/routing/olsr/olsr-agent-impl.cc @@ -310,9 +310,7 @@ void AgentImpl::RecvOlsr (Ptr socket) { Ptr receivedPacket; - uint32_t maxSize = std::numeric_limits::max(); - uint32_t flags = 0; // no flags - receivedPacket = socket->Recv (maxSize, flags); + receivedPacket = socket->Recv (); SocketRxAddressTag tag; bool found = receivedPacket->PeekTag (tag); From daddd90d0770937b4d91493e481df2b3e75c30dc Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Fri, 2 May 2008 10:55:07 -0700 Subject: [PATCH 08/45] Implement GetRxAvailable () --- src/internet-node/tcp-socket.cc | 19 ++++++++++++++++--- src/internet-node/tcp-socket.h | 2 ++ src/internet-node/udp-socket.cc | 19 +++++++++++++++++-- src/internet-node/udp-socket.h | 2 ++ src/node/packet-socket.cc | 14 ++++++++++++-- src/node/packet-socket.h | 3 +++ src/node/socket.h | 8 +++++++- 7 files changed, 59 insertions(+), 8 deletions(-) diff --git a/src/internet-node/tcp-socket.cc b/src/internet-node/tcp-socket.cc index b117d2082..ea3eb9058 100644 --- a/src/internet-node/tcp-socket.cc +++ b/src/internet-node/tcp-socket.cc @@ -78,7 +78,8 @@ TcpSocket::GetTypeId () m_nextRxSequence (0), m_pendingData (0), m_rtt (0), - m_lastMeasuredRtt (Seconds(0.0)) + m_lastMeasuredRtt (Seconds(0.0)), + m_rxAvailable (0) { NS_LOG_FUNCTION (this); @@ -122,7 +123,8 @@ TcpSocket::TcpSocket(const TcpSocket& sock) m_rtt (0), m_lastMeasuredRtt (Seconds(0.0)), m_cnTimeout (sock.m_cnTimeout), - m_cnCount (sock.m_cnCount) + m_cnCount (sock.m_cnCount), + m_rxAvailable (0) { NS_LOG_FUNCTION_NOARGS (); NS_LOG_LOGIC("Invoked the copy constructor"); @@ -450,9 +452,10 @@ TcpSocket::Recv (uint32_t maxSize, uint32_t flags) return 0; } Ptr p = m_deliveryQueue.front (); - if (p->GetSize() <= maxSize) + if (p->GetSize () <= maxSize) { m_deliveryQueue.pop (); + m_rxAvailable -= p->GetSize (); } else { @@ -461,6 +464,14 @@ TcpSocket::Recv (uint32_t maxSize, uint32_t flags) return p; } +uint32_t +TcpSocket::GetRxAvailable (void) const +{ + // We separately maintain this state to avoid walking the queue + // every time this might be called + return m_rxAvailable; +} + void TcpSocket::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) { @@ -979,6 +990,7 @@ void TcpSocket::NewRx (Ptr p, tag.SetAddress (fromAddress); p->AddTag (tag); m_deliveryQueue.push (p); + m_rxAvailable += p->GetSize (); NotifyDataRecv (); if (m_closeNotified) { @@ -1035,6 +1047,7 @@ void TcpSocket::NewRx (Ptr p, tag.SetAddress (fromAddress); p1->AddTag (tag); m_deliveryQueue.push (p1); + m_rxAvailable += p->GetSize (); NotifyDataRecv (); NS_LOG_LOGIC ("TcpSocket " << this << " adv rxseq1 by " << s1 ); diff --git a/src/internet-node/tcp-socket.h b/src/internet-node/tcp-socket.h index 6bf63082f..c7600e3f5 100644 --- a/src/internet-node/tcp-socket.h +++ b/src/internet-node/tcp-socket.h @@ -71,6 +71,7 @@ public: virtual int Listen(uint32_t queueLimit); virtual Ptr Recv (uint32_t maxSize, uint32_t flags); + virtual uint32_t GetRxAvailable (void) const; private: friend class Tcp; @@ -175,6 +176,7 @@ private: // Temporary queue for delivering data to application std::queue > m_deliveryQueue; + uint32_t m_rxAvailable; }; }//namespace ns3 diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index cae73b0c7..5960a929b 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -40,7 +40,8 @@ UdpSocket::UdpSocket () m_errno (ERROR_NOTERROR), m_shutdownSend (false), m_shutdownRecv (false), - m_connected (false) + m_connected (false), + m_rxAvailable (0) { NS_LOG_FUNCTION_NOARGS (); } @@ -333,9 +334,10 @@ UdpSocket::Recv (uint32_t maxSize, uint32_t flags) return 0; } Ptr p = m_deliveryQueue.front (); - if (p->GetSize() <= maxSize) + if (p->GetSize () <= maxSize) { m_deliveryQueue.pop (); + m_rxAvailable -= p->GetSize (); } else { @@ -344,6 +346,14 @@ UdpSocket::Recv (uint32_t maxSize, uint32_t flags) return p; } +uint32_t +UdpSocket::GetRxAvailable (void) const +{ + // We separately maintain this state to avoid walking the queue + // every time this might be called + return m_rxAvailable; +} + void UdpSocket::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) { @@ -358,6 +368,7 @@ UdpSocket::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) tag.SetAddress (address); packet->AddTag (tag); m_deliveryQueue.push (packet); + m_rxAvailable += packet->GetSize (); NotifyDataRecv (); } @@ -410,12 +421,16 @@ void UdpSocketTest::ReceivePacket2 (Ptr socket, Ptr packet, cons void UdpSocketTest::ReceivePkt (Ptr socket) { + uint32_t availableData = socket->GetRxAvailable (); m_receivedPacket = socket->Recv (std::numeric_limits::max(), 0); + NS_ASSERT (availableData == m_receivedPacket->GetSize ()); } void UdpSocketTest::ReceivePkt2 (Ptr socket) { + uint32_t availableData = socket->GetRxAvailable (); m_receivedPacket2 = socket->Recv (std::numeric_limits::max(), 0); + NS_ASSERT (availableData == m_receivedPacket2->GetSize ()); } bool diff --git a/src/internet-node/udp-socket.h b/src/internet-node/udp-socket.h index d976e1ad3..e5a425ddc 100644 --- a/src/internet-node/udp-socket.h +++ b/src/internet-node/udp-socket.h @@ -58,6 +58,7 @@ public: virtual int SendTo(const Address &address,Ptr p); virtual Ptr Recv (uint32_t maxSize, uint32_t flags); + virtual uint32_t GetRxAvailable (void) const; private: friend class Udp; @@ -82,6 +83,7 @@ private: bool m_connected; std::queue > m_deliveryQueue; + uint32_t m_rxAvailable; }; }//namespace ns3 diff --git a/src/node/packet-socket.cc b/src/node/packet-socket.cc index ad2041333..9600666e2 100644 --- a/src/node/packet-socket.cc +++ b/src/node/packet-socket.cc @@ -29,7 +29,7 @@ NS_LOG_COMPONENT_DEFINE ("PacketSocket"); namespace ns3 { -PacketSocket::PacketSocket () +PacketSocket::PacketSocket () : m_rxAvailable (0) { NS_LOG_FUNCTION_NOARGS (); m_state = STATE_OPEN; @@ -305,6 +305,7 @@ PacketSocket::ForwardUp (Ptr device, Ptr packet, tag.SetAddress (address); packet->AddTag (tag); m_deliveryQueue.push (packet); + m_rxAvailable += packet->GetSize (); NS_LOG_LOGIC ("UID is " << packet->GetUid() << " PacketSocket " << this); NotifyDataRecv (); } @@ -317,9 +318,10 @@ PacketSocket::Recv (uint32_t maxSize, uint32_t flags) return 0; } Ptr p = m_deliveryQueue.front (); - if (p->GetSize() <= maxSize) + if (p->GetSize () <= maxSize) { m_deliveryQueue.pop (); + m_rxAvailable -= p->GetSize (); } else { @@ -328,4 +330,12 @@ PacketSocket::Recv (uint32_t maxSize, uint32_t flags) return p; } +uint32_t +PacketSocket::GetRxAvailable (void) const +{ + // We separately maintain this state to avoid walking the queue + // every time this might be called + return m_rxAvailable; +} + }//namespace ns3 diff --git a/src/node/packet-socket.h b/src/node/packet-socket.h index b5282aaab..a2a60403f 100644 --- a/src/node/packet-socket.h +++ b/src/node/packet-socket.h @@ -89,6 +89,7 @@ public: virtual int SendTo(const Address &address,Ptr p); virtual Ptr Recv (uint32_t maxSize, uint32_t flags); + virtual uint32_t GetRxAvailable (void) const; private: @@ -114,6 +115,8 @@ private: Address m_destAddr; /// Default destination address std::queue > m_deliveryQueue; + uint32_t m_rxAvailable; + }; }//namespace ns3 diff --git a/src/node/socket.h b/src/node/socket.h index 62d512280..e9a11b51a 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -273,7 +273,13 @@ public: * 0 if the socket cannot return a next in-sequence packet. */ Ptr Recv (void); - + /** + * Return number of bytes which can be returned from one or + * multiple calls to Recv. + * Must be possible to call this method from the Recv callback. + */ + virtual uint32_t GetRxAvailable (void) const = 0; + protected: void NotifyCloseCompleted (void); void NotifyConnectionSucceeded (void); From 08511f30c51f9352b91750b25ce8124bec3c907d Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Sat, 3 May 2008 11:11:24 -0700 Subject: [PATCH 09/45] Add GetTxBuffer; add some socket options; make limited UDP receive buffer functional --- src/internet-node/tcp-socket.cc | 35 +++++++++++++ src/internet-node/tcp-socket.h | 6 +++ src/internet-node/udp-socket.cc | 87 +++++++++++++++++++++++++++++---- src/internet-node/udp-socket.h | 12 +++++ src/node/packet-socket.cc | 26 ++++++++++ src/node/packet-socket.h | 6 +++ src/node/socket.h | 35 +++++++++++++ src/node/udp.cc | 15 +++++- src/node/udp.h | 4 ++ 9 files changed, 216 insertions(+), 10 deletions(-) diff --git a/src/internet-node/tcp-socket.cc b/src/internet-node/tcp-socket.cc index ea3eb9058..44b78290a 100644 --- a/src/internet-node/tcp-socket.cc +++ b/src/internet-node/tcp-socket.cc @@ -435,6 +435,14 @@ TcpSocket::SendTo (const Address &address, Ptr p) } } +// XXX Raj to make this functional +uint32_t +TcpSocket::GetTxAvailable (void) const +{ + // No finite send buffer is modelled + return 0xffffffff; +} + int TcpSocket::Listen (uint32_t q) { @@ -472,6 +480,33 @@ TcpSocket::GetRxAvailable (void) const return m_rxAvailable; } +// XXX Raj to finish +void +TcpSocket::SetSndBuf (uint32_t size) +{ + +} + +// XXX Raj to finish +uint32_t +TcpSocket::GetSndBuf (void) +{ + return 0; +} + +// XXX Raj to finish +void +TcpSocket::SetRcvBuf (uint32_t size) +{ +} + +// XXX Raj to finish +uint32_t +TcpSocket::GetRcvBuf (void) +{ + return 0; +} + void TcpSocket::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) { diff --git a/src/internet-node/tcp-socket.h b/src/internet-node/tcp-socket.h index c7600e3f5..ce8948448 100644 --- a/src/internet-node/tcp-socket.h +++ b/src/internet-node/tcp-socket.h @@ -68,11 +68,17 @@ public: virtual int Send (Ptr p); virtual int Send (const uint8_t* buf, uint32_t size); virtual int SendTo(const Address &address, Ptr p); + virtual uint32_t GetTxAvailable (void) const; virtual int Listen(uint32_t queueLimit); virtual Ptr Recv (uint32_t maxSize, uint32_t flags); virtual uint32_t GetRxAvailable (void) const; + virtual void SetSndBuf (uint32_t size); + virtual uint32_t GetSndBuf (void); + virtual void SetRcvBuf (uint32_t size); + virtual uint32_t GetRcvBuf (void); + private: friend class Tcp; // invoked by Tcp class diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index 5960a929b..b705033a7 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -28,11 +28,25 @@ #include "ipv4-end-point.h" #include "ipv4-l4-demux.h" #include "ns3/ipv4.h" +#include "ns3/udp.h" +#include "ns3/trace-source-accessor.h" NS_LOG_COMPONENT_DEFINE ("UdpSocket"); namespace ns3 { +TypeId +UdpSocket::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::UdpSocket") + .SetParent () + .AddConstructor () + .AddTraceSource ("Drop", "Drop UDP packet due to receive buffer overflow", + MakeTraceSourceAccessor (&UdpSocket::m_dropTrace)) + ; + return tid; +} + UdpSocket::UdpSocket () : m_endPoint (0), m_node (0), @@ -41,7 +55,8 @@ UdpSocket::UdpSocket () m_shutdownSend (false), m_shutdownRecv (false), m_connected (false), - m_rxAvailable (0) + m_rxAvailable (0), + m_udp_rmem (0) { NS_LOG_FUNCTION_NOARGS (); } @@ -73,6 +88,9 @@ void UdpSocket::SetNode (Ptr node) { m_node = node; + Ptr u = node->GetObject (); + m_udp_rmem =u->GetDefaultRxBuffer (); + } void UdpSocket::SetUdp (Ptr udp) @@ -316,8 +334,15 @@ UdpSocket::DoSendTo (Ptr p, Ipv4Address dest, uint16_t port) return 0; } +uint32_t +UdpSocket::GetTxAvailable (void) const +{ + // No finite send buffer is modelled + return 0xffffffff; +} + int -UdpSocket::SendTo(const Address &address, Ptr p) +UdpSocket::SendTo (const Address &address, Ptr p) { NS_LOG_FUNCTION (this << address << p); InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); @@ -363,15 +388,59 @@ UdpSocket::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) { return; } - Address address = InetSocketAddress (ipv4, port); - SocketRxAddressTag tag; - tag.SetAddress (address); - packet->AddTag (tag); - m_deliveryQueue.push (packet); - m_rxAvailable += packet->GetSize (); - NotifyDataRecv (); + if ((m_rxAvailable + packet->GetSize ()) <= m_udp_rmem) + { + Address address = InetSocketAddress (ipv4, port); + SocketRxAddressTag tag; + tag.SetAddress (address); + packet->AddTag (tag); + m_deliveryQueue.push (packet); + m_rxAvailable += packet->GetSize (); + NotifyDataRecv (); + } + else + { + // In general, this case should not occur unless the + // receiving application reads data from this socket slowly + // in comparison to the arrival rate + // + // drop and trace packet + NS_LOG_WARN ("No receive buffer space available. Drop."); + m_dropTrace (packet); + } } +void +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; +} + +uint32_t +UdpSocket::GetSndBuf (void) +{ + m_errno = ERROR_NOTERROR; + return 0xffffffff; +} + +void +UdpSocket::SetRcvBuf (uint32_t size) +{ + m_errno = ERROR_NOTERROR; + m_udp_rmem = size; +} + +uint32_t +UdpSocket::GetRcvBuf (void) +{ + m_errno = ERROR_NOTERROR; + return m_udp_rmem; +} + + } //namespace ns3 diff --git a/src/internet-node/udp-socket.h b/src/internet-node/udp-socket.h index e5a425ddc..74fc2e26b 100644 --- a/src/internet-node/udp-socket.h +++ b/src/internet-node/udp-socket.h @@ -23,6 +23,7 @@ #include #include #include "ns3/callback.h" +#include "ns3/traced-callback.h" #include "ns3/socket.h" #include "ns3/ptr.h" #include "ns3/ipv4-address.h" @@ -37,6 +38,7 @@ class UdpL4Protocol; class UdpSocket : public Socket { public: + static TypeId GetTypeId (void); /** * Create an unbound udp socket. */ @@ -56,10 +58,16 @@ public: virtual int Connect(const Address &address); virtual int Send (Ptr p); virtual int SendTo(const Address &address,Ptr p); + virtual uint32_t GetTxAvailable (void) const; virtual Ptr Recv (uint32_t maxSize, uint32_t flags); virtual uint32_t GetRxAvailable (void) const; + virtual void SetSndBuf (uint32_t size); + virtual uint32_t GetSndBuf (void); + virtual void SetRcvBuf (uint32_t size); + virtual uint32_t GetRcvBuf (void); + private: friend class Udp; // invoked by Udp class @@ -77,6 +85,8 @@ private: uint16_t m_defaultPort; Callback,uint32_t,const Address &> m_dummyRxCallback; Callback,uint8_t const*,uint32_t,const Address &> m_rxCallback; + TracedCallback > m_dropTrace; + enum SocketErrno m_errno; bool m_shutdownSend; bool m_shutdownRecv; @@ -84,6 +94,8 @@ private: std::queue > m_deliveryQueue; uint32_t m_rxAvailable; + + uint32_t m_udp_rmem; }; }//namespace ns3 diff --git a/src/node/packet-socket.cc b/src/node/packet-socket.cc index 9600666e2..7accac512 100644 --- a/src/node/packet-socket.cc +++ b/src/node/packet-socket.cc @@ -214,6 +214,13 @@ PacketSocket::Send (Ptr p) return SendTo (m_destAddr, p); } +uint32_t +PacketSocket::GetTxAvailable (void) const +{ + // No finite send buffer is modelled + return 0xffffffff; +} + int PacketSocket::SendTo(const Address &address, Ptr p) { @@ -338,4 +345,23 @@ PacketSocket::GetRxAvailable (void) const return m_rxAvailable; } +void +PacketSocket::SetSndBuf (uint32_t size) +{ +} +uint32_t +PacketSocket::GetSndBuf (void) +{ +return 0; +} +void +PacketSocket::SetRcvBuf (uint32_t size) +{ +} +uint32_t +PacketSocket::GetRcvBuf (void) +{ +return 0; +} + }//namespace ns3 diff --git a/src/node/packet-socket.h b/src/node/packet-socket.h index a2a60403f..f9997c679 100644 --- a/src/node/packet-socket.h +++ b/src/node/packet-socket.h @@ -86,11 +86,17 @@ public: virtual int ShutdownRecv (void); virtual int Connect(const Address &address); virtual int Send (Ptr p); + virtual uint32_t GetTxAvailable (void) const; + virtual int SendTo(const Address &address,Ptr p); virtual Ptr Recv (uint32_t maxSize, uint32_t flags); virtual uint32_t GetRxAvailable (void) const; + virtual void SetSndBuf (uint32_t size); + virtual uint32_t GetSndBuf (void); + virtual void SetRcvBuf (uint32_t size); + virtual uint32_t GetRcvBuf (void); private: void ForwardUp (Ptr device, Ptr packet, diff --git a/src/node/socket.h b/src/node/socket.h index e9a11b51a..921070f77 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -220,6 +220,12 @@ public: */ virtual int Send (Ptr p) = 0; + /** + * returns the number of bytes which can be sent in a single call + * to Send. + */ + virtual uint32_t GetTxAvailable (void) const = 0; + /** * \brief Send data (or dummy data) to the remote host * \param buf A pointer to a raw byte buffer of some data to send. If this @@ -280,6 +286,35 @@ 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); diff --git a/src/node/udp.cc b/src/node/udp.cc index 989dd95f8..28046152d 100644 --- a/src/node/udp.cc +++ b/src/node/udp.cc @@ -18,6 +18,7 @@ * Author: Mathieu Lacage */ #include "udp.h" +#include "ns3/uinteger.h" namespace ns3 { @@ -26,11 +27,23 @@ NS_OBJECT_ENSURE_REGISTERED (Udp); TypeId Udp::GetTypeId (void) { static TypeId tid = TypeId ("ns3::Udp") - .SetParent (); + .SetParent () + .AddAttribute ("DefaultRxBufferSize", + "Default UDP maximum receive buffer size (bytes)", + UintegerValue (0xffffffffl), + MakeUintegerAccessor (&Udp::m_defaultRxBuffer), + MakeUintegerChecker ()) + ; return tid; } Udp::Udp () {} +uint32_t +Udp::GetDefaultRxBuffer (void) const +{ + return m_defaultRxBuffer; +} + } // namespace ns3 diff --git a/src/node/udp.h b/src/node/udp.h index a539eb94a..addcb583d 100644 --- a/src/node/udp.h +++ b/src/node/udp.h @@ -53,6 +53,10 @@ public: * implementations.. */ virtual Ptr CreateSocket (void) = 0; + + uint32_t GetDefaultRxBuffer (void) const; +private: + uint32_t m_defaultRxBuffer; }; } // namespace ns3 From 7089f682d6d31049191ea503d3c87b4c61328bc3 Mon Sep 17 00:00:00 2001 From: Raj Bhattacharjea Date: Thu, 8 May 2008 15:31:44 -0400 Subject: [PATCH 10/45] Finite send buffer first cut --- src/internet-node/tcp-socket.cc | 34 ++++++++++++++++++++++----------- src/internet-node/tcp-socket.h | 9 +++++++-- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/internet-node/tcp-socket.cc b/src/internet-node/tcp-socket.cc index 44b78290a..02a339e22 100644 --- a/src/internet-node/tcp-socket.cc +++ b/src/internet-node/tcp-socket.cc @@ -79,7 +79,8 @@ TcpSocket::GetTypeId () m_pendingData (0), m_rtt (0), m_lastMeasuredRtt (Seconds(0.0)), - m_rxAvailable (0) + m_rxAvailable (0), //XXX zero? + m_maxTxBuffer (65536) //interpret 0 as no limit, //XXX hook into default values { NS_LOG_FUNCTION (this); @@ -124,7 +125,8 @@ TcpSocket::TcpSocket(const TcpSocket& sock) m_lastMeasuredRtt (Seconds(0.0)), m_cnTimeout (sock.m_cnTimeout), m_cnCount (sock.m_cnCount), - m_rxAvailable (0) + m_rxAvailable (0), + m_maxTxBuffer (0) //interpret 0 as no limit, //XXX hook into default values { NS_LOG_FUNCTION_NOARGS (); NS_LOG_LOGIC("Invoked the copy constructor"); @@ -361,20 +363,19 @@ int TcpSocket::Send (const uint8_t* buf, uint32_t size) NS_LOG_FUNCTION (this << buf << size); if (m_state == ESTABLISHED || m_state == SYN_SENT || m_state == CLOSE_WAIT) { // Ok to buffer some data to send + size = std::min(size, GetTxAvailable() ); //only buffer what can fit if (!m_pendingData) - { - m_pendingData = new PendingData (); // Create if non-existent - m_firstPendingSequence = m_nextTxSequence; // Note seq of first - } + { + m_pendingData = new PendingData (); // Create if non-existent + m_firstPendingSequence = m_nextTxSequence; // Note seq of first + } //PendingData::Add always copies the data buffer, never modifies m_pendingData->Add (size,buf); NS_LOG_DEBUG("TcpSock::Send, pdsize " << m_pendingData->Size() << " state " << m_state); Actions_t action = ProcessEvent (APP_SEND); NS_LOG_DEBUG(" action " << action); - // We do not model any limit to the buffer, so report that the - // maximum is available - NotifySend (std::numeric_limits::max ()); + NotifySend (GetTxAvailable ()); if (!ProcessAction (action)) { return -1; // Failed, return zero @@ -439,8 +440,19 @@ TcpSocket::SendTo (const Address &address, Ptr p) uint32_t TcpSocket::GetTxAvailable (void) const { - // No finite send buffer is modelled - return 0xffffffff; + if (m_maxTxBuffer == 0) //interpret this as infinite buffer + { + return std::numeric_limits::max (); + } + if (m_pendingData != 0) + { + NS_ASSERT (m_maxTxBuffer >= m_pendingData->Size()); //else a logical error + return m_maxTxBuffer-m_pendingData->Size(); + } + else + { + return m_maxTxBuffer; + } } int diff --git a/src/internet-node/tcp-socket.h b/src/internet-node/tcp-socket.h index ce8948448..88e22d970 100644 --- a/src/internet-node/tcp-socket.h +++ b/src/internet-node/tcp-socket.h @@ -160,7 +160,9 @@ private: SequenceNumber m_nextRxSequence; //history data + //this is the incoming data buffer which sorts out of sequence data UnAckData_t m_bufferedData; + //this is kind of the tx buffer PendingData* m_pendingData; SequenceNumber m_firstPendingSequence; @@ -182,9 +184,12 @@ private: // Temporary queue for delivering data to application std::queue > m_deliveryQueue; - uint32_t m_rxAvailable; + uint32_t m_rxAvailable; + + // buffer limit for the outgoing queue + uint32_t m_maxTxBuffer; }; }//namespace ns3 -#endif /* UDP_SOCKET_H */ +#endif /* TCP_SOCKET_H */ From 53841f6170c62a2e76e4c7b20fe5dac2fc71ce24 Mon Sep 17 00:00:00 2001 From: Raj Bhattacharjea Date: Thu, 8 May 2008 16:17:16 -0400 Subject: [PATCH 11/45] NotifySend ONLY when data is acked --- src/internet-node/tcp-socket.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/internet-node/tcp-socket.cc b/src/internet-node/tcp-socket.cc index 02a339e22..b1635c052 100644 --- a/src/internet-node/tcp-socket.cc +++ b/src/internet-node/tcp-socket.cc @@ -375,7 +375,7 @@ int TcpSocket::Send (const uint8_t* buf, uint32_t size) " state " << m_state); Actions_t action = ProcessEvent (APP_SEND); NS_LOG_DEBUG(" action " << action); - NotifySend (GetTxAvailable ()); + //NotifySend (GetTxAvailable ()); //XXX not here, do this when data acked if (!ProcessAction (action)) { return -1; // Failed, return zero @@ -446,8 +446,10 @@ TcpSocket::GetTxAvailable (void) const } if (m_pendingData != 0) { - NS_ASSERT (m_maxTxBuffer >= m_pendingData->Size()); //else a logical error - return m_maxTxBuffer-m_pendingData->Size(); + uint32_t unAckedDataSize = + m_pendingData->SizeFromSeq (m_firstPendingSequence, m_highestRxAck); + NS_ASSERT (m_maxTxBuffer >= unAckedDataSize); //else a logical error + return m_maxTxBuffer-unAckedDataSize; } else { @@ -769,9 +771,7 @@ bool TcpSocket::ProcessPacketAction (Actions_t a, Ptr p, if (tcpHeader.GetAckNumber () > m_highestRxAck) { m_highestRxAck = tcpHeader.GetAckNumber (); - // We do not model any limit to the buffer, so report that the - // maximum is available - NotifySend (std::numeric_limits::max ()); + //NotifySend (GetTxAvailable() ); //XXX do when data gets acked } SendPendingData (); break; @@ -1170,9 +1170,9 @@ void TcpSocket::CommonNewAck (SequenceNumber ack, bool skipTimer) NS_LOG_LOGIC ("TCP " << this << " NewAck " << ack << " numberAck " << (ack - m_highestRxAck)); // Number bytes ack'ed m_highestRxAck = ack; // Note the highest recieved Ack - // We do not model any limit to the buffer, so report that the - // maximum is available - NotifySend (std::numeric_limits::max ()); + //m_highestRxAck advancing means some data was acked, and the size of free + //space in the buffer has increased + NotifySend (GetTxAvailable ()); if (ack > m_nextTxSequence) { m_nextTxSequence = ack; // If advanced From 0f55fefabab3f61b9b774db866f2a12d54b20a5e Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Sat, 10 May 2008 21:27:32 -0700 Subject: [PATCH 12/45] 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; }; /** From ee62b6d04e0b7b0ee88b7edca9180f817d175798 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Sun, 11 May 2008 20:59:08 -0700 Subject: [PATCH 13/45] Enable receive buffer limit for packet socket --- src/node/packet-socket.cc | 54 ++++++++++++++++++++++++++++++++------- src/node/packet-socket.h | 8 ++++++ 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/src/node/packet-socket.cc b/src/node/packet-socket.cc index 6212cce78..a0d2668a9 100644 --- a/src/node/packet-socket.cc +++ b/src/node/packet-socket.cc @@ -24,11 +24,24 @@ #include "ns3/log.h" #include "ns3/node.h" #include "ns3/packet.h" +#include "ns3/trace-source-accessor.h" NS_LOG_COMPONENT_DEFINE ("PacketSocket"); namespace ns3 { +TypeId +PacketSocket::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::PacketSocket") + .SetParent () + .AddConstructor () + .AddTraceSource ("Drop", "Drop packet due to receive buffer overflow", + MakeTraceSourceAccessor (&PacketSocket::m_dropTrace)) + ; + return tid; +} + PacketSocket::PacketSocket () : m_rxAvailable (0) { NS_LOG_FUNCTION_NOARGS (); @@ -41,6 +54,7 @@ PacketSocket::PacketSocket () : m_rxAvailable (0) void PacketSocket::SetNode (Ptr node) { + NS_LOG_FUNCTION_NOARGS (); m_node = node; } @@ -308,18 +322,32 @@ PacketSocket::ForwardUp (Ptr device, Ptr packet, address.SetSingleDevice (device->GetIfIndex ()); address.SetProtocol (protocol); - SocketRxAddressTag tag; - tag.SetAddress (address); - packet->AddTag (tag); - m_deliveryQueue.push (packet); - m_rxAvailable += packet->GetSize (); - NS_LOG_LOGIC ("UID is " << packet->GetUid() << " PacketSocket " << this); - NotifyDataRecv (); + if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufLimit) + { + SocketRxAddressTag tag; + tag.SetAddress (address); + packet->AddTag (tag); + m_deliveryQueue.push (packet); + m_rxAvailable += packet->GetSize (); + NS_LOG_LOGIC ("UID is " << packet->GetUid() << " PacketSocket " << this); + NotifyDataRecv (); + } + else + { + // In general, this case should not occur unless the + // receiving application reads data from this socket slowly + // in comparison to the arrival rate + // + // drop and trace packet + NS_LOG_WARN ("No receive buffer space available. Drop."); + m_dropTrace (packet); + } } Ptr PacketSocket::Recv (uint32_t maxSize, uint32_t flags) { + NS_LOG_FUNCTION_NOARGS (); if (m_deliveryQueue.empty() ) { return 0; @@ -340,6 +368,7 @@ PacketSocket::Recv (uint32_t maxSize, uint32_t flags) uint32_t PacketSocket::GetRxAvailable (void) const { + NS_LOG_FUNCTION_NOARGS (); // We separately maintain this state to avoid walking the queue // every time this might be called return m_rxAvailable; @@ -348,22 +377,29 @@ PacketSocket::GetRxAvailable (void) const 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 { - return 0; + 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 { - return 0; + NS_LOG_FUNCTION_NOARGS (); + return m_rcvBufLimit; } }//namespace ns3 diff --git a/src/node/packet-socket.h b/src/node/packet-socket.h index 555485bc2..2e70a67fa 100644 --- a/src/node/packet-socket.h +++ b/src/node/packet-socket.h @@ -24,6 +24,7 @@ #include #include #include "ns3/callback.h" +#include "ns3/traced-callback.h" #include "ns3/ptr.h" #include "ns3/socket.h" @@ -72,6 +73,8 @@ class PacketSocketAddress; class PacketSocket : public Socket { public: + static TypeId GetTypeId (void); + PacketSocket (); virtual ~PacketSocket (); @@ -123,6 +126,11 @@ private: std::queue > m_deliveryQueue; uint32_t m_rxAvailable; + + TracedCallback > m_dropTrace; + + uint32_t m_sndBufLimit; // Max send buffer size + uint32_t m_rcvBufLimit; // Max receive buffer size }; From 6ec88588f122edc42f266d07bfa16ae3570b6985 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Sun, 11 May 2008 21:55:00 -0700 Subject: [PATCH 14/45] tweak UdpSocket buffer limit behavior --- src/internet-node/udp-socket.cc | 23 +++++++++++++++++------ src/internet-node/udp-socket.h | 3 ++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index 4aa9f0b11..8305b17ba 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -56,7 +56,8 @@ UdpSocket::UdpSocket () m_shutdownRecv (false), m_connected (false), m_rxAvailable (0), - m_udp_rmem (0) + m_sndBufLimit (0), + m_rcvBufLimit (0) { NS_LOG_FUNCTION_NOARGS (); } @@ -87,14 +88,16 @@ UdpSocket::~UdpSocket () void UdpSocket::SetNode (Ptr node) { + NS_LOG_FUNCTION_NOARGS (); m_node = node; Ptr u = node->GetObject (); - m_udp_rmem =u->GetDefaultRxBuffer (); + m_rcvBufLimit =u->GetDefaultRxBuffer (); } void UdpSocket::SetUdp (Ptr udp) { + NS_LOG_FUNCTION_NOARGS (); m_udp = udp; } @@ -337,6 +340,7 @@ UdpSocket::DoSendTo (Ptr p, Ipv4Address dest, uint16_t port) uint32_t UdpSocket::GetTxAvailable (void) const { + NS_LOG_FUNCTION_NOARGS (); // No finite send buffer is modelled return std::numeric_limits::max (); } @@ -354,6 +358,7 @@ UdpSocket::SendTo (const Address &address, Ptr p) Ptr UdpSocket::Recv (uint32_t maxSize, uint32_t flags) { + NS_LOG_FUNCTION_NOARGS (); if (m_deliveryQueue.empty() ) { return 0; @@ -374,6 +379,7 @@ UdpSocket::Recv (uint32_t maxSize, uint32_t flags) uint32_t UdpSocket::GetRxAvailable (void) const { + NS_LOG_FUNCTION_NOARGS (); // We separately maintain this state to avoid walking the queue // every time this might be called return m_rxAvailable; @@ -388,7 +394,7 @@ UdpSocket::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) { return; } - if ((m_rxAvailable + packet->GetSize ()) <= m_udp_rmem) + if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufLimit) { Address address = InetSocketAddress (ipv4, port); SocketRxAddressTag tag; @@ -413,28 +419,33 @@ 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 { - return std::numeric_limits::max (); + NS_LOG_FUNCTION_NOARGS (); + return m_sndBufLimit; } void UdpSocket::SetRcvBuf (uint32_t size) { - m_udp_rmem = size; + NS_LOG_FUNCTION_NOARGS (); + m_rcvBufLimit = size; } uint32_t UdpSocket::GetRcvBuf (void) const { - return m_udp_rmem; + NS_LOG_FUNCTION_NOARGS (); + return m_rcvBufLimit; } diff --git a/src/internet-node/udp-socket.h b/src/internet-node/udp-socket.h index 8ed3ba67e..aa21a8e7f 100644 --- a/src/internet-node/udp-socket.h +++ b/src/internet-node/udp-socket.h @@ -96,7 +96,8 @@ private: std::queue > m_deliveryQueue; uint32_t m_rxAvailable; - uint32_t m_udp_rmem; + uint32_t m_sndBufLimit; + uint32_t m_rcvBufLimit; }; }//namespace ns3 From 3ebec1046ca5daa0ca36d4a4da1e1a508664d457 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Sun, 11 May 2008 22:12:16 -0700 Subject: [PATCH 15/45] Some tcp socket cleanup for buffer limits --- src/internet-node/tcp-socket.cc | 47 +++++++++++++++++---------------- src/internet-node/tcp-socket.h | 4 +-- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/internet-node/tcp-socket.cc b/src/internet-node/tcp-socket.cc index 63b33bafb..8127d8f87 100644 --- a/src/internet-node/tcp-socket.cc +++ b/src/internet-node/tcp-socket.cc @@ -79,8 +79,9 @@ TcpSocket::GetTypeId () m_pendingData (0), m_rtt (0), m_lastMeasuredRtt (Seconds(0.0)), - m_rxAvailable (0), //XXX zero? - m_maxTxBuffer (65536) //interpret 0 as no limit, //XXX hook into default values + m_rxAvailable (0), + m_sndBufLimit (0xffffffff), + m_rcvBufLimit (0xffffffff) { NS_LOG_FUNCTION (this); @@ -126,7 +127,8 @@ TcpSocket::TcpSocket(const TcpSocket& sock) m_cnTimeout (sock.m_cnTimeout), m_cnCount (sock.m_cnCount), m_rxAvailable (0), - m_maxTxBuffer (0) //interpret 0 as no limit, //XXX hook into default values + m_sndBufLimit (0xffffffff), + m_rcvBufLimit (0xffffffff) { NS_LOG_FUNCTION_NOARGS (); NS_LOG_LOGIC("Invoked the copy constructor"); @@ -436,25 +438,21 @@ TcpSocket::SendTo (const Address &address, Ptr p) } } -// XXX Raj to make this functional uint32_t TcpSocket::GetTxAvailable (void) const { - if (m_maxTxBuffer == 0) //interpret this as infinite buffer - { - return std::numeric_limits::max (); - } + NS_LOG_FUNCTION_NOARGS (); if (m_pendingData != 0) - { - uint32_t unAckedDataSize = + { + uint32_t unAckedDataSize = m_pendingData->SizeFromSeq (m_firstPendingSequence, m_highestRxAck); - NS_ASSERT (m_maxTxBuffer >= unAckedDataSize); //else a logical error - return m_maxTxBuffer-unAckedDataSize; - } + NS_ASSERT (m_sndBufLimit >= unAckedDataSize); //else a logical error + return m_sndBufLimit-unAckedDataSize; + } else - { - return m_maxTxBuffer; - } + { + return m_sndBufLimit; + } } int @@ -469,6 +467,7 @@ TcpSocket::Listen (uint32_t q) Ptr TcpSocket::Recv (uint32_t maxSize, uint32_t flags) { + NS_LOG_FUNCTION_NOARGS (); if (m_deliveryQueue.empty() ) { return 0; @@ -489,36 +488,38 @@ TcpSocket::Recv (uint32_t maxSize, uint32_t flags) uint32_t TcpSocket::GetRxAvailable (void) const { + NS_LOG_FUNCTION_NOARGS (); // We separately maintain this state to avoid walking the queue // every time this might be called return m_rxAvailable; } -// XXX Raj to finish void TcpSocket::SetSndBuf (uint32_t size) { - + NS_LOG_FUNCTION_NOARGS (); + m_sndBufLimit = size; } -// XXX Raj to finish uint32_t TcpSocket::GetSndBuf (void) const { - return 0; + NS_LOG_FUNCTION_NOARGS (); + return m_sndBufLimit; } -// XXX Raj to finish void TcpSocket::SetRcvBuf (uint32_t size) { + NS_LOG_FUNCTION_NOARGS (); + m_rcvBufLimit = size; } -// XXX Raj to finish uint32_t TcpSocket::GetRcvBuf (void) const { - return 0; + NS_LOG_FUNCTION_NOARGS (); + return m_rcvBufLimit; } void diff --git a/src/internet-node/tcp-socket.h b/src/internet-node/tcp-socket.h index f68e19884..dbaedc835 100644 --- a/src/internet-node/tcp-socket.h +++ b/src/internet-node/tcp-socket.h @@ -187,8 +187,8 @@ private: std::queue > m_deliveryQueue; uint32_t m_rxAvailable; - // buffer limit for the outgoing queue - uint32_t m_maxTxBuffer; + uint32_t m_sndBufLimit; // buffer limit for the outgoing queue + uint32_t m_rcvBufLimit; // maximum receive socket buffer size }; }//namespace ns3 From a042d0bbefba84b2f64b0bf3ec6687819e5f8c75 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Mon, 12 May 2008 06:39:00 -0700 Subject: [PATCH 16/45] Move API for socket factory to a Socket::CreateSocket () factory method --- examples/tcp-large-transfer.cc | 5 ++--- examples/wifi-adhoc.cc | 7 +++---- examples/wifi-ap.cc | 2 +- samples/main-simple.cc | 6 ++---- src/applications/onoff/onoff-application.cc | 3 +-- src/applications/packet-sink/packet-sink.cc | 4 +--- src/applications/udp-echo/udp-echo-client.cc | 4 +--- src/applications/udp-echo/udp-echo-server.cc | 4 +--- src/node/socket.cc | 12 ++++++++++++ src/node/socket.h | 11 +++++++++++ src/routing/olsr/olsr-agent-impl.cc | 7 +++---- 11 files changed, 38 insertions(+), 27 deletions(-) diff --git a/examples/tcp-large-transfer.cc b/examples/tcp-large-transfer.cc index 641de0537..ee7d831b0 100644 --- a/examples/tcp-large-transfer.cc +++ b/examples/tcp-large-transfer.cc @@ -176,9 +176,8 @@ int main (int argc, char *argv[]) apps.Start (Seconds (0.0)); // and generate traffic to remote sink. - Ptr socketFactory = - c0.Get (0)->GetObject (); - Ptr localSocket = socketFactory->CreateSocket (); + //TypeId tid = TypeId::LookupByName ("ns3::Tcp"); + Ptr localSocket = Socket::CreateSocket (c0.Get (0), Tcp::GetTypeId ()); localSocket->Bind (); Simulator::ScheduleNow (&StartFlow, localSocket, nBytes, ipInterfs.GetAddress (1), servPort); diff --git a/examples/wifi-adhoc.cc b/examples/wifi-adhoc.cc index 3bc51ed50..1759f3643 100644 --- a/examples/wifi-adhoc.cc +++ b/examples/wifi-adhoc.cc @@ -102,9 +102,8 @@ Experiment::ReceivePacket (Ptr socket) Ptr Experiment::SetupPacketReceive (Ptr node) { - TypeId tid = TypeId::LookupByName ("ns3::PacketSocketFactory"); - Ptr socketFactory = node->GetObject (tid); - Ptr sink = socketFactory->CreateSocket (); + TypeId tid = TypeId::LookupByName ("ns3::PacketSocket"); + Ptr sink = Socket::CreateSocket (node, tid); sink->Bind (); sink->SetRecvCallback (MakeCallback (&Experiment::ReceivePacket, this)); return sink; @@ -137,7 +136,7 @@ Experiment::Run (const WifiHelper &wifi) socket.SetPhysicalAddress (devices.Get (1)->GetAddress ()); socket.SetProtocol (1); - OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket)); + OnOffHelper onoff ("ns3::PacketSocket", Address (socket)); onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (250))); onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); onoff.SetAttribute ("DataRate", DataRateValue (DataRate (60000000))); diff --git a/examples/wifi-ap.cc b/examples/wifi-ap.cc index 7c2c266fa..ecc82eaca 100644 --- a/examples/wifi-ap.cc +++ b/examples/wifi-ap.cc @@ -162,7 +162,7 @@ int main (int argc, char *argv[]) socket.SetPhysicalAddress (staDevs.Get (1)->GetAddress ()); socket.SetProtocol (1); - OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket)); + OnOffHelper onoff ("ns3::PacketSocket", Address (socket)); onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (42))); onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); diff --git a/samples/main-simple.cc b/samples/main-simple.cc index d8878be4b..719406f27 100644 --- a/samples/main-simple.cc +++ b/samples/main-simple.cc @@ -49,13 +49,11 @@ RunSimulation (void) TypeId tid = TypeId::LookupByName ("ns3::Udp"); - Ptr socketFactory = c.Get (0)->GetObject (tid); - - Ptr sink = socketFactory->CreateSocket (); + Ptr sink = Socket::CreateSocket (c.Get (0), tid); InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80); sink->Bind (local); - Ptr source = socketFactory->CreateSocket (); + Ptr source = Socket::CreateSocket (c.Get (0), tid); InetSocketAddress remote = InetSocketAddress (Ipv4Address::GetLoopback (), 80); source->Connect (remote); diff --git a/src/applications/onoff/onoff-application.cc b/src/applications/onoff/onoff-application.cc index 311c30519..271304715 100644 --- a/src/applications/onoff/onoff-application.cc +++ b/src/applications/onoff/onoff-application.cc @@ -130,8 +130,7 @@ void OnOffApplication::StartApplication() // Called at time specified by Start // Create the socket if not already if (!m_socket) { - Ptr socketFactory = GetNode ()->GetObject (m_tid); - m_socket = socketFactory->CreateSocket (); + m_socket = Socket::CreateSocket (GetNode(), m_tid); m_socket->Bind (); m_socket->Connect (m_peer); } diff --git a/src/applications/packet-sink/packet-sink.cc b/src/applications/packet-sink/packet-sink.cc index c35c8e4d7..d4478dc32 100644 --- a/src/applications/packet-sink/packet-sink.cc +++ b/src/applications/packet-sink/packet-sink.cc @@ -80,9 +80,7 @@ void PacketSink::StartApplication() // Called at time specified by Start // Create the socket if not already if (!m_socket) { - Ptr socketFactory = - GetNode ()->GetObject (m_tid); - m_socket = socketFactory->CreateSocket (); + m_socket = Socket::CreateSocket (GetNode(), m_tid); m_socket->Bind (m_local); m_socket->Listen (0); } diff --git a/src/applications/udp-echo/udp-echo-client.cc b/src/applications/udp-echo/udp-echo-client.cc index b452c3d86..3241b49c5 100644 --- a/src/applications/udp-echo/udp-echo-client.cc +++ b/src/applications/udp-echo/udp-echo-client.cc @@ -96,9 +96,7 @@ UdpEchoClient::StartApplication (void) if (!m_socket) { TypeId tid = TypeId::LookupByName ("ns3::Udp"); - Ptr socketFactory = - GetNode ()->GetObject (tid); - m_socket = socketFactory->CreateSocket (); + m_socket = Socket::CreateSocket (GetNode(), tid); m_socket->Bind (); m_socket->Connect (InetSocketAddress (m_peerAddress, m_peerPort)); } diff --git a/src/applications/udp-echo/udp-echo-server.cc b/src/applications/udp-echo/udp-echo-server.cc index bfbfde1b4..badd4ec92 100644 --- a/src/applications/udp-echo/udp-echo-server.cc +++ b/src/applications/udp-echo/udp-echo-server.cc @@ -72,9 +72,7 @@ UdpEchoServer::StartApplication (void) if (!m_socket) { TypeId tid = TypeId::LookupByName ("ns3::Udp"); - Ptr socketFactory = - GetNode ()->GetObject (tid); - m_socket = socketFactory->CreateSocket (); + m_socket = Socket::CreateSocket (GetNode(), tid); InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), m_port); m_socket->Bind (local); } diff --git a/src/node/socket.cc b/src/node/socket.cc index 039b635a2..07e44be6d 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -22,7 +22,9 @@ #include "ns3/log.h" #include "ns3/packet.h" +#include "node.h" #include "socket.h" +#include "socket-factory.h" NS_LOG_COMPONENT_DEFINE ("Socket"); @@ -83,6 +85,16 @@ Socket::~Socket () NS_LOG_FUNCTION_NOARGS (); } +Ptr +Socket::CreateSocket (Ptr node, TypeId tid) +{ + Ptr s; + Ptr socketFactory = node->GetObject (tid); + s = socketFactory->CreateSocket (); + NS_ASSERT (s != 0); + return s; +} + void Socket::SetCloseCallback (Callback > closeCompleted) { diff --git a/src/node/socket.h b/src/node/socket.h index cde3e3a1d..9f106dc75 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -98,6 +98,17 @@ public: SOCKET_ERRNO_LAST }; + /** + * This method wraps the creation of sockets that is performed + * by a socket factory on a given node based on a TypeId. + * + * \return A smart pointer to a newly created socket. + * + * \param node The node on which to create the socket + * \param tid The TypeId of the socket to create + */ + static Ptr CreateSocket (Ptr node, TypeId tid); + /** * \return the errno associated to the last call which failed in this * socket. Each socket's errno is initialized to zero diff --git a/src/routing/olsr/olsr-agent-impl.cc b/src/routing/olsr/olsr-agent-impl.cc index 3031982f5..19257306a 100644 --- a/src/routing/olsr/olsr-agent-impl.cc +++ b/src/routing/olsr/olsr-agent-impl.cc @@ -258,9 +258,7 @@ void AgentImpl::Start () // Add OLSR as routing protocol, with slightly higher priority than // static routing. m_ipv4->AddRoutingProtocol (m_routingTable, 10); - - Ptr socketFactory = GetObject (Udp::GetTypeId ()); - + Ipv4Address loopback ("127.0.0.1"); for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++) { @@ -281,7 +279,8 @@ void AgentImpl::Start () } // Create a socket to listen only on this interface - Ptr socket = socketFactory->CreateSocket (); + Ptr socket = Socket::CreateSocket (GetObject (), + Udp::GetTypeId()); socket->SetRecvCallback (MakeCallback (&AgentImpl::RecvOlsr, this)); if (socket->Bind (InetSocketAddress (addr, OLSR_PORT_NUMBER))) { From 6be343530f19c49913a62cd5dec49a219047167d Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Mon, 12 May 2008 23:02:23 -0700 Subject: [PATCH 17/45] Add SocketDefaults to store socket option attributes --- src/helper/packet-socket-helper.cc | 3 +++ src/internet-node/internet-stack.cc | 3 +++ src/internet-node/tcp-socket.cc | 13 +++++++++++++ src/internet-node/udp-socket.cc | 17 ++++++++++++----- src/node/packet-socket.cc | 12 ++++++++++++ src/node/socket.cc | 14 ++++++++++++-- src/node/udp.cc | 14 -------------- src/node/udp.h | 5 ----- src/node/wscript | 2 ++ 9 files changed, 57 insertions(+), 26 deletions(-) diff --git a/src/helper/packet-socket-helper.cc b/src/helper/packet-socket-helper.cc index dd8d2b3fe..ad744bfb1 100644 --- a/src/helper/packet-socket-helper.cc +++ b/src/helper/packet-socket-helper.cc @@ -1,5 +1,6 @@ #include "packet-socket-helper.h" #include "ns3/packet-socket-factory.h" +#include "ns3/socket-defaults.h" namespace ns3 { @@ -11,6 +12,8 @@ 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 916f436ac..f4d7c66a4 100644 --- a/src/internet-node/internet-stack.cc +++ b/src/internet-node/internet-stack.cc @@ -21,6 +21,7 @@ #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" @@ -61,6 +62,7 @@ AddInternetStack (Ptr node) Ptr udpImpl = CreateObject (); Ptr tcpImpl = CreateObject (); Ptr ipv4Impl = CreateObject (); + Ptr sockDef = CreateObject (); udpImpl->SetUdp (udp); tcpImpl->SetTcp (tcp); @@ -72,6 +74,7 @@ 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 8127d8f87..9055c9f61 100644 --- a/src/internet-node/tcp-socket.cc +++ b/src/internet-node/tcp-socket.cc @@ -31,6 +31,8 @@ #include "tcp-typedefs.h" #include "ns3/simulator.h" #include "ns3/packet.h" +#include "ns3/uinteger.h" +#include "ns3/socket-defaults.h" #include "ns3/trace-source-accessor.h" #include @@ -185,6 +187,17 @@ 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 8305b17ba..9f1764b1c 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -23,13 +23,15 @@ #include "ns3/inet-socket-address.h" #include "ns3/ipv4-route.h" #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 "udp-socket.h" #include "udp-l4-protocol.h" #include "ipv4-end-point.h" #include "ipv4-l4-demux.h" -#include "ns3/ipv4.h" -#include "ns3/udp.h" -#include "ns3/trace-source-accessor.h" NS_LOG_COMPONENT_DEFINE ("UdpSocket"); @@ -89,9 +91,14 @@ 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 u = node->GetObject (); - m_rcvBufLimit =u->GetDefaultRxBuffer (); + Ptr sd = node->GetObject (); + NS_ASSERT (sd != 0); + UintegerValue uiv; + sd->GetAttribute ("DefaultRcvBufLimit", uiv); + m_rcvBufLimit = uiv.Get(); } void diff --git a/src/node/packet-socket.cc b/src/node/packet-socket.cc index a0d2668a9..4067410c1 100644 --- a/src/node/packet-socket.cc +++ b/src/node/packet-socket.cc @@ -24,6 +24,8 @@ #include "ns3/log.h" #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"); @@ -56,6 +58,16 @@ 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 () diff --git a/src/node/socket.cc b/src/node/socket.cc index 07e44be6d..69a6d4d98 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -54,23 +54,33 @@ SocketOptions::~SocketOptions (void) void SocketOptions::SetSndBuf (uint32_t size) { + NS_LOG_FUNCTION_NOARGS (); + Ptr sock = GetObject (); + sock->SetSndBuf (size); } uint32_t SocketOptions::GetSndBuf (void) const { - return 0; + 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 { - return 0; + NS_LOG_FUNCTION_NOARGS (); + Ptr sock = GetObject (); + return sock->GetRcvBuf (); } Socket::Socket (void) diff --git a/src/node/udp.cc b/src/node/udp.cc index 28046152d..14311a2bb 100644 --- a/src/node/udp.cc +++ b/src/node/udp.cc @@ -28,22 +28,8 @@ TypeId Udp::GetTypeId (void) { static TypeId tid = TypeId ("ns3::Udp") .SetParent () - .AddAttribute ("DefaultRxBufferSize", - "Default UDP maximum receive buffer size (bytes)", - UintegerValue (0xffffffffl), - MakeUintegerAccessor (&Udp::m_defaultRxBuffer), - MakeUintegerChecker ()) ; return tid; } -Udp::Udp () -{} - -uint32_t -Udp::GetDefaultRxBuffer (void) const -{ - return m_defaultRxBuffer; -} - } // namespace ns3 diff --git a/src/node/udp.h b/src/node/udp.h index addcb583d..be6b0149d 100644 --- a/src/node/udp.h +++ b/src/node/udp.h @@ -44,8 +44,6 @@ class Udp : public SocketFactory public: static TypeId GetTypeId (void); - Udp (); - /** * \return smart pointer to Socket * @@ -54,9 +52,6 @@ public: */ virtual Ptr CreateSocket (void) = 0; - uint32_t GetDefaultRxBuffer (void) const; -private: - uint32_t m_defaultRxBuffer; }; } // namespace ns3 diff --git a/src/node/wscript b/src/node/wscript index 770b1edb9..747537254 100644 --- a/src/node/wscript +++ b/src/node/wscript @@ -23,6 +23,7 @@ def build(bld): 'node-list.cc', 'socket.cc', 'socket-factory.cc', + 'socket-defaults.cc', 'packet-socket-factory.cc', 'packet-socket.cc', 'udp.cc', @@ -56,6 +57,7 @@ def build(bld): 'node-list.h', 'socket.h', 'socket-factory.h', + 'socket-defaults.h', 'packet-socket-factory.h', 'udp.h', 'tcp.h', From 9eb007fd261a2983148c7968f70511272e8e1a0e Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Mon, 12 May 2008 23:02:44 -0700 Subject: [PATCH 18/45] Add SocketDefaults to store socket option attributes (missing files) --- src/node/socket-defaults.cc | 42 +++++++++++++++++++++++++++++++++++++ src/node/socket-defaults.h | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 src/node/socket-defaults.cc create mode 100644 src/node/socket-defaults.h diff --git a/src/node/socket-defaults.cc b/src/node/socket-defaults.cc new file mode 100644 index 000000000..20c97b980 --- /dev/null +++ b/src/node/socket-defaults.cc @@ -0,0 +1,42 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +#include "socket-defaults.h" +#include "ns3/uinteger.h" + +namespace ns3 { + +NS_OBJECT_ENSURE_REGISTERED (SocketDefaults); + +TypeId SocketDefaults::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::SocketDefaults") + .SetParent () + .AddAttribute ("DefaultSndBufLimit", + "Default maximum receive buffer size (bytes)", + UintegerValue (0xffffffffl), + MakeUintegerAccessor (&SocketDefaults::m_defaultSndBufLimit), + MakeUintegerChecker ()) + .AddAttribute ("DefaultRcvBufLimit", + "Default maximum receive buffer size (bytes)", + UintegerValue (0xffffffffl), + MakeUintegerAccessor (&SocketDefaults::m_defaultRcvBufLimit), + MakeUintegerChecker ()) + ; + return tid; +} + +} // namespace ns3 diff --git a/src/node/socket-defaults.h b/src/node/socket-defaults.h new file mode 100644 index 000000000..e6eb290fb --- /dev/null +++ b/src/node/socket-defaults.h @@ -0,0 +1,42 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef SOCKET_DEFAULTS_H +#define SOCKET_DEFAULTS_H + +#include "ns3/object.h" + +namespace ns3 { + +/** + * \brief Object to hold socket option defaults + * + * This class can be aggregated to a Node and can be used to store + * socket defaults for a Node. + * + */ +class SocketDefaults : public Object +{ +public: + static TypeId GetTypeId (void); + +private: + uint32_t m_defaultSndBufLimit; + uint32_t m_defaultRcvBufLimit; +}; + +} // namespace ns3 + +#endif /* SOCKET_DEFAULTS_H */ From 2e116e5f74716910bf78d0d71f2b1823a473b7a0 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Tue, 13 May 2008 06:57:57 -0700 Subject: [PATCH 19/45] Fix semantics of NotifySend() for Tcp --- src/internet-node/tcp-socket.cc | 27 ++++++++++++++++++++------- src/internet-node/tcp-socket.h | 1 + 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/internet-node/tcp-socket.cc b/src/internet-node/tcp-socket.cc index 9055c9f61..e73e36c05 100644 --- a/src/internet-node/tcp-socket.cc +++ b/src/internet-node/tcp-socket.cc @@ -83,7 +83,8 @@ TcpSocket::GetTypeId () m_lastMeasuredRtt (Seconds(0.0)), m_rxAvailable (0), m_sndBufLimit (0xffffffff), - m_rcvBufLimit (0xffffffff) + m_rcvBufLimit (0xffffffff), + m_wouldBlock (false) { NS_LOG_FUNCTION (this); @@ -378,7 +379,11 @@ int TcpSocket::Send (const uint8_t* buf, uint32_t size) NS_LOG_FUNCTION (this << buf << size); if (m_state == ESTABLISHED || m_state == SYN_SENT || m_state == CLOSE_WAIT) { // Ok to buffer some data to send - size = std::min(size, GetTxAvailable() ); //only buffer what can fit + if (size > GetTxAvailable ()) + { + size = std::min(size, GetTxAvailable() ); //only buffer what can fit + m_wouldBlock = true; + } if (!m_pendingData) { m_pendingData = new PendingData (); // Create if non-existent @@ -390,7 +395,6 @@ int TcpSocket::Send (const uint8_t* buf, uint32_t size) " state " << m_state); Actions_t action = ProcessEvent (APP_SEND); NS_LOG_DEBUG(" action " << action); - //NotifySend (GetTxAvailable ()); //XXX not here, do this when data acked if (!ProcessAction (action)) { return -1; // Failed, return zero @@ -785,7 +789,12 @@ bool TcpSocket::ProcessPacketAction (Actions_t a, Ptr p, if (tcpHeader.GetAckNumber () > m_highestRxAck) { m_highestRxAck = tcpHeader.GetAckNumber (); - //NotifySend (GetTxAvailable() ); //XXX do when data gets acked + // Data freed from the send buffer; notify any blocked sender + if (m_wouldBlock) + { + NotifySend (GetTxAvailable ()); + m_wouldBlock = false; + } } SendPendingData (); break; @@ -1184,9 +1193,13 @@ void TcpSocket::CommonNewAck (SequenceNumber ack, bool skipTimer) NS_LOG_LOGIC ("TCP " << this << " NewAck " << ack << " numberAck " << (ack - m_highestRxAck)); // Number bytes ack'ed m_highestRxAck = ack; // Note the highest recieved Ack - //m_highestRxAck advancing means some data was acked, and the size of free - //space in the buffer has increased - NotifySend (GetTxAvailable ()); + if (m_wouldBlock) + { + // m_highestRxAck advancing means some data was acked, and the size + // of free space in the buffer has increased + NotifySend (GetTxAvailable ()); + m_wouldBlock = false; + } if (ack > m_nextTxSequence) { m_nextTxSequence = ack; // If advanced diff --git a/src/internet-node/tcp-socket.h b/src/internet-node/tcp-socket.h index dbaedc835..6e4d3c4a4 100644 --- a/src/internet-node/tcp-socket.h +++ b/src/internet-node/tcp-socket.h @@ -189,6 +189,7 @@ private: uint32_t m_sndBufLimit; // buffer limit for the outgoing queue uint32_t m_rcvBufLimit; // maximum receive socket buffer size + bool m_wouldBlock; // set to true whenever socket would block on send() }; }//namespace ns3 From b00892cae7a9d20e190ce2ad78f8030646f965b5 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Tue, 13 May 2008 07:22:03 -0700 Subject: [PATCH 20/45] swap SendTo parameters --- src/applications/udp-echo/udp-echo-server.cc | 2 +- src/internet-node/tcp-socket.cc | 2 +- src/internet-node/tcp-socket.h | 2 +- src/internet-node/udp-socket.cc | 14 +++++++------- src/internet-node/udp-socket.h | 2 +- src/node/packet-socket.cc | 4 ++-- src/node/packet-socket.h | 2 +- src/node/socket.cc | 4 ++-- src/node/socket.h | 8 ++++---- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/applications/udp-echo/udp-echo-server.cc b/src/applications/udp-echo/udp-echo-server.cc index badd4ec92..ea305616c 100644 --- a/src/applications/udp-echo/udp-echo-server.cc +++ b/src/applications/udp-echo/udp-echo-server.cc @@ -109,7 +109,7 @@ UdpEchoServer::HandleRead (Ptr socket) address.GetIpv4()); NS_LOG_LOGIC ("Echoing packet"); - socket->SendTo (from, packet); + socket->SendTo (packet, from); } } } diff --git a/src/internet-node/tcp-socket.cc b/src/internet-node/tcp-socket.cc index e73e36c05..a350476e0 100644 --- a/src/internet-node/tcp-socket.cc +++ b/src/internet-node/tcp-socket.cc @@ -441,7 +441,7 @@ int TcpSocket::DoSendTo (Ptr p, Ipv4Address ipv4, uint16_t port) } int -TcpSocket::SendTo (const Address &address, Ptr p) +TcpSocket::SendTo (Ptr p, const Address &address) { NS_LOG_FUNCTION (this << address << p); if (!m_connected) diff --git a/src/internet-node/tcp-socket.h b/src/internet-node/tcp-socket.h index 6e4d3c4a4..023d3029d 100644 --- a/src/internet-node/tcp-socket.h +++ b/src/internet-node/tcp-socket.h @@ -67,7 +67,7 @@ public: virtual int Connect(const Address &address); virtual int Send (Ptr p); virtual int Send (const uint8_t* buf, uint32_t size); - virtual int SendTo(const Address &address, Ptr p); + virtual int SendTo(Ptr p, const Address &address); virtual uint32_t GetTxAvailable (void) const; virtual int Listen(uint32_t queueLimit); diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index 9f1764b1c..5670aa8fc 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -353,7 +353,7 @@ UdpSocket::GetTxAvailable (void) const } int -UdpSocket::SendTo (const Address &address, Ptr p) +UdpSocket::SendTo (Ptr p, const Address &address) { NS_LOG_FUNCTION (this << address << p); InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); @@ -604,8 +604,8 @@ UdpSocketTest::RunTests (void) // Unicast test m_receivedPacket = Create (); m_receivedPacket2 = Create (); - NS_TEST_ASSERT_EQUAL (txSocket->SendTo (InetSocketAddress (Ipv4Address("10.0.0.1"), 1234), - Create (123)), 123); + NS_TEST_ASSERT_EQUAL (txSocket->SendTo ( Create (123), + InetSocketAddress (Ipv4Address("10.0.0.1"), 1234)), 123); Simulator::Run (); NS_TEST_ASSERT_EQUAL (m_receivedPacket->GetSize (), 123); NS_TEST_ASSERT_EQUAL (m_receivedPacket2->GetSize (), 0); // second interface should receive it @@ -617,8 +617,8 @@ UdpSocketTest::RunTests (void) m_receivedPacket = Create (); m_receivedPacket2 = Create (); - NS_TEST_ASSERT_EQUAL (txSocket->SendTo (InetSocketAddress (Ipv4Address("255.255.255.255"), 1234), - Create (123)), 123); + NS_TEST_ASSERT_EQUAL (txSocket->SendTo ( Create (123), + InetSocketAddress (Ipv4Address("255.255.255.255"), 1234)), 123); Simulator::Run (); NS_TEST_ASSERT_EQUAL (m_receivedPacket->GetSize (), 123); // second socket should not receive it (it is bound specifically to the second interface's address @@ -639,8 +639,8 @@ UdpSocketTest::RunTests (void) m_receivedPacket = Create (); m_receivedPacket2 = Create (); - NS_TEST_ASSERT_EQUAL (txSocket->SendTo (InetSocketAddress (Ipv4Address("255.255.255.255"), 1234), - Create (123)), 123); + NS_TEST_ASSERT_EQUAL (txSocket->SendTo (Create (123), +InetSocketAddress (Ipv4Address("255.255.255.255"), 1234)), 123); Simulator::Run (); NS_TEST_ASSERT_EQUAL (m_receivedPacket->GetSize (), 123); NS_TEST_ASSERT_EQUAL (m_receivedPacket2->GetSize (), 123); diff --git a/src/internet-node/udp-socket.h b/src/internet-node/udp-socket.h index aa21a8e7f..71e55f232 100644 --- a/src/internet-node/udp-socket.h +++ b/src/internet-node/udp-socket.h @@ -57,7 +57,7 @@ public: virtual int ShutdownRecv (void); virtual int Connect(const Address &address); virtual int Send (Ptr p); - virtual int SendTo(const Address &address,Ptr p); + virtual int SendTo (Ptr p, const Address &address); virtual uint32_t GetTxAvailable (void) const; virtual Ptr Recv (uint32_t maxSize, uint32_t flags); diff --git a/src/node/packet-socket.cc b/src/node/packet-socket.cc index 4067410c1..09f7ce099 100644 --- a/src/node/packet-socket.cc +++ b/src/node/packet-socket.cc @@ -237,7 +237,7 @@ PacketSocket::Send (Ptr p) m_errno = ERROR_NOTCONN; return -1; } - return SendTo (m_destAddr, p); + return SendTo (p, m_destAddr); } uint32_t @@ -248,7 +248,7 @@ PacketSocket::GetTxAvailable (void) const } int -PacketSocket::SendTo(const Address &address, Ptr p) +PacketSocket::SendTo(Ptr p, const Address &address) { NS_LOG_FUNCTION_NOARGS (); PacketSocketAddress ad; diff --git a/src/node/packet-socket.h b/src/node/packet-socket.h index 2e70a67fa..f34c90051 100644 --- a/src/node/packet-socket.h +++ b/src/node/packet-socket.h @@ -91,7 +91,7 @@ public: virtual int Send (Ptr p); virtual uint32_t GetTxAvailable (void) const; - virtual int SendTo(const Address &address,Ptr p); + virtual int SendTo(Ptr p, const Address &address); virtual Ptr Recv (uint32_t maxSize, uint32_t flags); virtual uint32_t GetRxAvailable (void) const; diff --git a/src/node/socket.cc b/src/node/socket.cc index 69a6d4d98..9fe458e08 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -185,7 +185,7 @@ Socket::Recv (void) return Recv (std::numeric_limits::max(), 0); } -int Socket::SendTo (const Address &address, const uint8_t* buf, uint32_t size) +int Socket::SendTo (const uint8_t* buf, uint32_t size, const Address &address) { NS_LOG_FUNCTION_NOARGS (); Ptr p; @@ -197,7 +197,7 @@ int Socket::SendTo (const Address &address, const uint8_t* buf, uint32_t size) { p = Create (size); } - return SendTo (address,p); + return SendTo (p, address); } void diff --git a/src/node/socket.h b/src/node/socket.h index 9f106dc75..0d879e74d 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -282,26 +282,26 @@ public: /** * \brief Send data to a specified peer. - * \param address IP Address of remote host * \param p packet to send + * \param address IP Address of remote host * \returns -1 in case of error or the number of bytes copied in the * internal buffer and accepted for transmission. */ - virtual int SendTo (const Address &address,Ptr p) = 0; + virtual int SendTo (Ptr p, const Address &address) = 0; /** * \brief Send data to a specified peer. - * \param address IP Address of remote host * \param buf A pointer to a raw byte buffer of some data to send. If this * is 0, we send dummy data whose size is specified by the third parameter * \param size the number of bytes to copy from the buffer + * \param address IP Address of remote host * \returns -1 in case of error or the number of bytes copied in the * internal buffer and accepted for transmission. * * This is provided so as to have an API which is closer in appearance * to that of real network or BSD sockets. */ - int SendTo (const Address &address, const uint8_t* buf, uint32_t size); + int SendTo (const uint8_t* buf, uint32_t size, const Address &address); /** * \brief Read a single packet from the socket From 18011ba4eb073407f2ef044caafaba81d1edf3fd Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Thu, 15 May 2008 23:06:58 -0700 Subject: [PATCH 21/45] improve send semantics, documentation --- src/internet-node/tcp-socket.cc | 5 ++-- src/internet-node/udp-socket.cc | 15 ++++++++++-- src/node/packet-socket.cc | 10 ++++++-- src/node/socket.h | 43 ++++++++++++++++++++++++++++++--- 4 files changed, 63 insertions(+), 10 deletions(-) diff --git a/src/internet-node/tcp-socket.cc b/src/internet-node/tcp-socket.cc index a350476e0..5f8e0d195 100644 --- a/src/internet-node/tcp-socket.cc +++ b/src/internet-node/tcp-socket.cc @@ -378,11 +378,12 @@ int TcpSocket::Send (const uint8_t* buf, uint32_t size) { NS_LOG_FUNCTION (this << buf << size); if (m_state == ESTABLISHED || m_state == SYN_SENT || m_state == CLOSE_WAIT) - { // Ok to buffer some data to send + { if (size > GetTxAvailable ()) { - size = std::min(size, GetTxAvailable() ); //only buffer what can fit m_wouldBlock = true; + m_errno = ERROR_MSGSIZE; + return -1; } if (!m_pendingData) { diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index 5670aa8fc..c7c87900e 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -37,6 +37,8 @@ NS_LOG_COMPONENT_DEFINE ("UdpSocket"); namespace ns3 { +static const uint32_t MAX_IPV4_UDP_DATAGRAM_SIZE = 65507; + TypeId UdpSocket::GetTypeId (void) { @@ -302,6 +304,12 @@ UdpSocket::DoSendTo (Ptr p, Ipv4Address dest, uint16_t port) return -1; } + if (p->GetSize () > GetTxAvailable () ) + { + m_errno = ERROR_MSGSIZE; + return -1; + } + uint32_t localIfIndex; Ptr ipv4 = m_node->GetObject (); @@ -344,12 +352,15 @@ UdpSocket::DoSendTo (Ptr p, Ipv4Address dest, uint16_t port) return 0; } +// XXX maximum message size for UDP broadcast is limited by MTU +// size of underlying link; we are not checking that now. uint32_t UdpSocket::GetTxAvailable (void) const { NS_LOG_FUNCTION_NOARGS (); - // No finite send buffer is modelled - return std::numeric_limits::max (); + // No finite send buffer is modelled, but we must respect + // the maximum size of an IP datagram (65535 bytes - headers). + return MAX_IPV4_UDP_DATAGRAM_SIZE; } int diff --git a/src/node/packet-socket.cc b/src/node/packet-socket.cc index d04ef5dc2..8ebe8748a 100644 --- a/src/node/packet-socket.cc +++ b/src/node/packet-socket.cc @@ -240,11 +240,12 @@ PacketSocket::Send (Ptr p) return SendTo (p, m_destAddr); } +// XXX must limit it to interface MTU uint32_t PacketSocket::GetTxAvailable (void) const { - // No finite send buffer is modelled - return 0xffffffff; + // Use 65536 for now + return 0xffff; } int @@ -277,6 +278,11 @@ PacketSocket::SendTo(Ptr p, const Address &address) m_errno = ERROR_AFNOSUPPORT; return -1; } + if (p->GetSize () > GetTxAvailable ()) + { + m_errno = ERROR_MSGSIZE; + return -1; + } ad = PacketSocketAddress::ConvertFrom (address); bool error = false; diff --git a/src/node/socket.h b/src/node/socket.h index 0d879e74d..c78970af6 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -257,15 +257,50 @@ public: /** * \brief Send data (or dummy data) to the remote host - * \param p packet to send - * \returns -1 in case of error or the number of bytes copied in the - * internal buffer and accepted for transmission. + * + * This function matches closely in semantics to the send() function + * call in the standard C library (libc): + * ssize_t send (int s, const void *msg, size_t len, int flags); + * except that the function call is asynchronous. + * + * In a typical blocking sockets model, this call would block upon + * lack of space to hold the message to be sent. In ns-3 at this + * API, the call returns immediately in such a case, but the callback + * registered with SetSendCallback() is invoked when the socket + * has space (when it conceptually unblocks); this is an asynchronous + * I/O model for send(). + * + * This variant of Send() uses class ns3::Packet to encapsulate + * data, rather than providing a raw pointer and length field. + * This allows an ns-3 application to attach tags if desired (such + * as a flow ID) and may allow the simulator to avoid some data + * copies. Despite the appearance of sending Packets on a stream + * socket, just think of it as a fancy byte buffer with streaming + * semantics. + * + * If either the message buffer within the Packet is too long to pass + * atomically through the underlying protocol (for datagram sockets), + * or the message buffer cannot entirely fit in the transmit buffer + * (for stream sockets), -1 is returned and SocketErrno is set + * to ERROR_MSGSIZE. If the packet does not fit, the caller can + * split the Packet (based on information obtained from + * GetTxAvailable) and reattempt to send the data. + * + * \param p ns3::Packet to send + * \returns the number of bytes accepted for transmission if no error + * occurs, and -1 otherwise. */ virtual int Send (Ptr p) = 0; /** - * returns the number of bytes which can be sent in a single call + * \brief Returns the number of bytes which can be sent in a single call * to Send. + * + * For datagram sockets, this returns the number of bytes that + * can be passed atomically through the underlying protocol. + * + * For stream sockets, this returns the available space in bytes + * left in the transmit buffer. */ virtual uint32_t GetTxAvailable (void) const = 0; From 0a476b4f049f94e954e6da28ecb61e6e21c2fe75 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Fri, 16 May 2008 21:28:07 -0700 Subject: [PATCH 22/45] undo SocketDefaults class; plumb in new UdpSocket option attributes --- src/helper/packet-socket-helper.cc | 3 -- src/internet-node/internet-stack.cc | 3 -- src/internet-node/tcp-socket.cc | 12 ----- src/internet-node/udp-socket.cc | 73 +++++++++++------------------ src/internet-node/udp-socket.h | 15 +++--- src/node/packet-socket.cc | 46 +++--------------- src/node/packet-socket.h | 12 ++--- src/node/socket.cc | 55 ---------------------- src/node/socket.h | 38 +-------------- src/node/wscript | 2 - 10 files changed, 45 insertions(+), 214 deletions(-) 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', From 67d54a7f8a1a87961748bdde14868d84115e994e Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Sat, 17 May 2008 11:15:02 -0700 Subject: [PATCH 23/45] Implement IPTTL socket option for UDP --- src/internet-node/ipv4-l3-protocol.cc | 30 +++++++++++++++++ src/internet-node/udp-socket.cc | 41 +++++++++++++---------- src/internet-node/udp-socket.h | 2 -- src/node/socket.cc | 48 +++++++++++++++++++++++++++ src/node/socket.h | 20 +++++++++++ 5 files changed, 122 insertions(+), 19 deletions(-) diff --git a/src/internet-node/ipv4-l3-protocol.cc b/src/internet-node/ipv4-l3-protocol.cc index 9188a358e..7be8959c9 100644 --- a/src/internet-node/ipv4-l3-protocol.cc +++ b/src/internet-node/ipv4-l3-protocol.cc @@ -24,6 +24,7 @@ #include "ns3/ipv4-address.h" #include "ns3/ipv4-route.h" #include "ns3/node.h" +#include "ns3/socket.h" #include "ns3/net-device.h" #include "ns3/uinteger.h" #include "ns3/trace-source-accessor.h" @@ -486,6 +487,35 @@ Ipv4L3Protocol::Send (Ptr packet, m_identification ++; + // Set TTL to 1 if it is a broadcast packet of any type. Otherwise, + // possibly override the default TTL if the packet is tagged + SocketIpTtlTag tag; + bool found = packet->PeekTag (tag); + uint8_t socketTtl = tag.GetTtl (); + packet->RemoveTag (tag); + + if (destination.IsBroadcast ()) + { + ipHeader.SetTtl (1); + } + else if (found) + { + ipHeader.SetTtl (socketTtl); + } + else + { + uint32_t ifaceIndex = 0; + for (Ipv4InterfaceList::iterator ifaceIter = m_interfaces.begin (); + ifaceIter != m_interfaces.end (); ifaceIter++, ifaceIndex++) + { + Ptr outInterface = *ifaceIter; + if (destination.IsSubnetDirectedBroadcast ( + outInterface->GetNetworkMask ())) + { + ipHeader.SetTtl (1); + } + } + } if (destination.IsBroadcast ()) { uint32_t ifaceIndex = 0; diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index 2f6e232b6..d2689dfbb 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -52,24 +52,14 @@ UdpSocket::GetTypeId (void) 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), + "socket-specific TTL for unicast IP packets (if non-zero)", + UintegerValue (0), MakeUintegerAccessor (&UdpSocket::m_ipTtl), MakeUintegerChecker ()) .AddAttribute ("IpMulticastTtl", - "Time-to-live for multicast IP packets", - UintegerValue (64), + "socket-specific TTL for multicast IP packets (if non-zero)", + UintegerValue (0), MakeUintegerAccessor (&UdpSocket::m_ipMulticastTtl), MakeUintegerChecker ()) ; @@ -232,7 +222,6 @@ int UdpSocket::Connect(const Address & address) { NS_LOG_FUNCTION (this << address); - Ipv4Route routeToDest; InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); m_defaultAddress = transport.GetIpv4 (); m_defaultPort = transport.GetPort (); @@ -303,8 +292,6 @@ UdpSocket::DoSendTo (Ptr p, Ipv4Address dest, uint16_t port) { NS_LOG_FUNCTION (this << p << dest << port); - Ipv4Route routeToDest; - if (m_endPoint == 0) { if (Bind () == -1) @@ -329,6 +316,26 @@ UdpSocket::DoSendTo (Ptr p, Ipv4Address dest, uint16_t port) uint32_t localIfIndex; Ptr ipv4 = m_node->GetObject (); + // Locally override the IP TTL for this socket + // We cannot directly modify the TTL at this stage, so we set a Packet tag + // The destination can be either multicast, unicast/anycast, or + // either all-hosts broadcast or limited (subnet-directed) broadcast. + // For the latter two broadcast types, the TTL will later be set to one + // 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 + if (m_ipMulticastTtl != 0 && dest.IsMulticast ()) + { + SocketIpTtlTag tag; + tag.SetTtl (m_ipMulticastTtl); + p->AddTag (tag); + } + else if (m_ipTtl != 0 && !dest.IsMulticast () && !dest.IsBroadcast ()) + { + SocketIpTtlTag tag; + tag.SetTtl (m_ipTtl); + p->AddTag (tag); + } // // If dest is sent to the limited broadcast address (all ones), // convert it to send a copy of the packet out of every interface diff --git a/src/internet-node/udp-socket.h b/src/internet-node/udp-socket.h index be545a02a..812d5f552 100644 --- a/src/internet-node/udp-socket.h +++ b/src/internet-node/udp-socket.h @@ -92,8 +92,6 @@ private: // Socket options (UdpSocket attributes) uint32_t m_rcvBufSize; - bool m_dontRoute; - bool m_acceptConn; uint8_t m_ipTtl; uint8_t m_ipMulticastTtl; diff --git a/src/node/socket.cc b/src/node/socket.cc index f00625885..8b066edd7 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -301,4 +301,52 @@ SocketRxAddressTag::GetAddress (void) const return m_address; } +SocketIpTtlTag::SocketIpTtlTag () +{ +} + +uint32_t +SocketIpTtlTag::GetUid (void) +{ + static uint32_t uid = ns3::Tag::AllocateUid ("SocketIpTtlTag.ns3"); + return uid; +} + +void +SocketIpTtlTag::Print (std::ostream &os) const +{ + os << "ttl="<< m_ttl; +} + +uint32_t +SocketIpTtlTag::GetSerializedSize (void) const +{ + return 0; +} + +void +SocketIpTtlTag::Serialize (Buffer::Iterator i) const +{ + // for local use in stack only +} + +uint32_t +SocketIpTtlTag::Deserialize (Buffer::Iterator i) +{ + // for local use in stack only + return 0; +} + +void +SocketIpTtlTag::SetTtl (uint8_t ttl) +{ + m_ttl = ttl; +} + +uint8_t +SocketIpTtlTag::GetTtl (void) const +{ + return m_ttl; +} + }//namespace ns3 diff --git a/src/node/socket.h b/src/node/socket.h index 847113e84..1ea91aebc 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -378,6 +378,26 @@ private: Address m_address; }; +/** + * \brief This class implements a tag that carries the socket-specific + * TTL of a packet to the IP layer + */ +class SocketIpTtlTag : public Tag +{ +public: + SocketIpTtlTag (); + static uint32_t GetUid (void); + void Print (std::ostream &os) const; + uint32_t GetSerializedSize (void) const; + void Serialize (Buffer::Iterator i) const; + uint32_t Deserialize (Buffer::Iterator i); + + void SetTtl (uint8_t ttl); + uint8_t GetTtl (void) const; +private: + uint8_t m_ttl; +}; + } //namespace ns3 #endif /* SOCKET_H */ From 4c4ef85a9349b0071b19c49c829d85a0f956bbf6 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Sat, 17 May 2008 12:08:20 -0700 Subject: [PATCH 24/45] s/ns3::Udp/ns3::UdpSocketFactory --- examples/csma-broadcast.cc | 4 ++-- examples/csma-multicast.cc | 4 ++-- examples/csma-one-subnet.cc | 4 ++-- examples/mixed-global-routing.cc | 2 +- examples/mixed-wireless.cc | 4 ++-- examples/simple-alternate-routing.cc | 4 ++-- examples/simple-error-model.cc | 4 ++-- examples/simple-global-routing.cc | 4 ++-- examples/simple-point-to-point-olsr.cc | 4 ++-- samples/main-simple.cc | 2 +- src/applications/onoff/onoff-application.cc | 4 ++-- src/applications/packet-sink/packet-sink.cc | 4 ++-- src/applications/udp-echo/udp-echo-client.cc | 2 +- src/applications/udp-echo/udp-echo-server.cc | 2 +- src/core/type-id.cc | 2 +- src/helper/packet-sink-helper.cc | 2 +- src/internet-node/udp-impl.cc | 2 +- src/internet-node/udp-impl.h | 4 ++-- src/internet-node/udp-socket.cc | 9 ++++----- src/internet-node/udp-socket.h | 2 +- src/node/{udp.cc => udp-socket-factory.cc} | 8 ++++---- src/node/{udp.h => udp-socket-factory.h} | 8 ++++---- src/node/wscript | 4 ++-- src/routing/olsr/olsr-agent-impl.cc | 4 ++-- utils/print-introspected-doxygen.cc | 2 +- 25 files changed, 47 insertions(+), 48 deletions(-) rename src/node/{udp.cc => udp-socket-factory.cc} (84%) rename src/node/{udp.h => udp-socket-factory.h} (91%) diff --git a/examples/csma-broadcast.cc b/examples/csma-broadcast.cc index 9585bf06d..7928b3a82 100644 --- a/examples/csma-broadcast.cc +++ b/examples/csma-broadcast.cc @@ -93,7 +93,7 @@ main (int argc, char *argv[]) // Create the OnOff application to send UDP datagrams of size // 512 bytes (default) at a rate of 500 Kb/s (default) from n0 NS_LOG_INFO ("Create Applications."); - OnOffHelper onoff ("ns3::Udp", + OnOffHelper onoff ("ns3::UdpSocketFactory", Address (InetSocketAddress (Ipv4Address ("255.255.255.255"), port))); onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); @@ -104,7 +104,7 @@ main (int argc, char *argv[]) app.Stop (Seconds (10.0)); // Create an optional packet sink to receive these packets - PacketSinkHelper sink ("ns3::Udp", + PacketSinkHelper sink ("ns3::UdpSocketFactory", Address (InetSocketAddress (Ipv4Address::GetAny (), port))); sink.Install (c0.Get (1)); sink.Install (c1.Get (1)); diff --git a/examples/csma-multicast.cc b/examples/csma-multicast.cc index 870494809..6a07a3c6b 100644 --- a/examples/csma-multicast.cc +++ b/examples/csma-multicast.cc @@ -140,7 +140,7 @@ main (int argc, char *argv[]) // Configure a multicast packet generator that generates a packet // every few seconds - OnOffHelper onoff ("ns3::Udp", + OnOffHelper onoff ("ns3::UdpSocketFactory", Address (InetSocketAddress (multicastGroup, multicastPort))); onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); @@ -156,7 +156,7 @@ main (int argc, char *argv[]) srcC.Stop (Seconds(10.)); // Create an optional packet sink to receive these packets - PacketSinkHelper sink ("ns3::Udp", + PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny(), multicastPort)); ApplicationContainer sinkC = sink.Install (c1.Get (2)); // Node n4 diff --git a/examples/csma-one-subnet.cc b/examples/csma-one-subnet.cc index d75df160c..f90a6ad43 100644 --- a/examples/csma-one-subnet.cc +++ b/examples/csma-one-subnet.cc @@ -95,7 +95,7 @@ main (int argc, char *argv[]) NS_LOG_INFO ("Create Applications."); uint16_t port = 9; // Discard port (RFC 863) - OnOffHelper onoff ("ns3::Udp", + OnOffHelper onoff ("ns3::UdpSocketFactory", Address (InetSocketAddress (Ipv4Address ("10.1.1.2"), port))); onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); @@ -106,7 +106,7 @@ main (int argc, char *argv[]) app.Stop (Seconds (10.0)); // Create an optional packet sink to receive these packets - PacketSinkHelper sink ("ns3::Udp", + PacketSinkHelper sink ("ns3::UdpSocketFactory", Address (InetSocketAddress (Ipv4Address::GetAny (), port))); sink.Install (c.Get (1)); diff --git a/examples/mixed-global-routing.cc b/examples/mixed-global-routing.cc index 764c7e3a5..f003571bf 100644 --- a/examples/mixed-global-routing.cc +++ b/examples/mixed-global-routing.cc @@ -112,7 +112,7 @@ main (int argc, char *argv[]) // 210 bytes at a rate of 448 Kb/s NS_LOG_INFO ("Create Applications."); uint16_t port = 9; // Discard port (RFC 863) - OnOffHelper onoff ("ns3::Udp", + OnOffHelper onoff ("ns3::UdpSocketFactory", InetSocketAddress (i5i6.GetAddress (1), port)); onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); diff --git a/examples/mixed-wireless.cc b/examples/mixed-wireless.cc index baf9a2836..2e74f18c0 100644 --- a/examples/mixed-wireless.cc +++ b/examples/mixed-wireless.cc @@ -305,7 +305,7 @@ main (int argc, char *argv[]) Ptr appSink = NodeList::GetNode (13); Ipv4Address remoteAddr = Ipv4Address ("172.16.0.5"); - OnOffHelper onoff ("ns3::Udp", + OnOffHelper onoff ("ns3::UdpSocketFactory", Address (InetSocketAddress (remoteAddr, port))); onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); @@ -314,7 +314,7 @@ main (int argc, char *argv[]) apps.Stop (Seconds (20.0)); // Create a packet sink to receive these packets - PacketSinkHelper sink ("ns3::Udp", + PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port)); apps = sink.Install (appSink); apps.Start (Seconds (3.0)); diff --git a/examples/simple-alternate-routing.cc b/examples/simple-alternate-routing.cc index dd83323c8..0cdc687b0 100644 --- a/examples/simple-alternate-routing.cc +++ b/examples/simple-alternate-routing.cc @@ -141,7 +141,7 @@ main (int argc, char *argv[]) uint16_t port = 9; // Discard port (RFC 863) // Create a flow from n3 to n1, starting at time 1.1 seconds - OnOffHelper onoff ("ns3::Udp", + OnOffHelper onoff ("ns3::UdpSocketFactory", Address (InetSocketAddress (i1i2.GetAddress (0), port))); onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); @@ -151,7 +151,7 @@ main (int argc, char *argv[]) apps.Start (Seconds (10.0)); // Create a packet sink to receive these packets - PacketSinkHelper sink ("ns3::Udp", + PacketSinkHelper sink ("ns3::UdpSocketFactory", Address (InetSocketAddress (Ipv4Address::GetAny (), port))); apps = sink.Install (c.Get (1)); apps.Start (Seconds (1.1)); diff --git a/examples/simple-error-model.cc b/examples/simple-error-model.cc index 617666d12..1c08f3f04 100644 --- a/examples/simple-error-model.cc +++ b/examples/simple-error-model.cc @@ -122,7 +122,7 @@ main (int argc, char *argv[]) NS_LOG_INFO ("Create Applications."); uint16_t port = 9; // Discard port (RFC 863) - OnOffHelper onoff ("ns3::Udp", + OnOffHelper onoff ("ns3::UdpSocketFactory", Address (InetSocketAddress (i3i2.GetAddress (1), port))); onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable(1))); onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable(0))); @@ -132,7 +132,7 @@ main (int argc, char *argv[]) apps.Stop (Seconds(10.0)); // Create an optional packet sink to receive these packets - PacketSinkHelper sink ("ns3::Udp", + PacketSinkHelper sink ("ns3::UdpSocketFactory", Address (InetSocketAddress (Ipv4Address::GetAny (), port))); apps = sink.Install (c.Get (3)); apps.Start (Seconds (1.0)); diff --git a/examples/simple-global-routing.cc b/examples/simple-global-routing.cc index aa33d090b..e6a7b4eef 100644 --- a/examples/simple-global-routing.cc +++ b/examples/simple-global-routing.cc @@ -122,7 +122,7 @@ main (int argc, char *argv[]) // 210 bytes at a rate of 448 Kb/s NS_LOG_INFO ("Create Applications."); uint16_t port = 9; // Discard port (RFC 863) - OnOffHelper onoff ("ns3::Udp", + OnOffHelper onoff ("ns3::UdpSocketFactory", Address (InetSocketAddress (i3i2.GetAddress (0), port))); onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); @@ -131,7 +131,7 @@ main (int argc, char *argv[]) apps.Stop (Seconds (10.0)); // Create a packet sink to receive these packets - PacketSinkHelper sink ("ns3::Udp", + PacketSinkHelper sink ("ns3::UdpSocketFactory", Address (InetSocketAddress (Ipv4Address::GetAny (), port))); apps = sink.Install (c.Get (3)); apps.Start (Seconds (1.0)); diff --git a/examples/simple-point-to-point-olsr.cc b/examples/simple-point-to-point-olsr.cc index 8c78030a6..bd7b39487 100644 --- a/examples/simple-point-to-point-olsr.cc +++ b/examples/simple-point-to-point-olsr.cc @@ -127,7 +127,7 @@ main (int argc, char *argv[]) NS_LOG_INFO ("Create Applications."); uint16_t port = 9; // Discard port (RFC 863) - OnOffHelper onoff ("ns3::Udp", + OnOffHelper onoff ("ns3::UdpSocketFactory", InetSocketAddress (i34.GetAddress (1), port)); onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); @@ -137,7 +137,7 @@ main (int argc, char *argv[]) apps.Stop (Seconds (10.0)); // Create a packet sink to receive these packets - PacketSinkHelper sink ("ns3::Udp", + PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port)); apps = sink.Install (c.Get (3)); diff --git a/samples/main-simple.cc b/samples/main-simple.cc index 719406f27..92c6e5c36 100644 --- a/samples/main-simple.cc +++ b/samples/main-simple.cc @@ -48,7 +48,7 @@ RunSimulation (void) internet.Install (c); - TypeId tid = TypeId::LookupByName ("ns3::Udp"); + TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); Ptr sink = Socket::CreateSocket (c.Get (0), tid); InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80); sink->Bind (local); diff --git a/src/applications/onoff/onoff-application.cc b/src/applications/onoff/onoff-application.cc index 271304715..c4f84277a 100644 --- a/src/applications/onoff/onoff-application.cc +++ b/src/applications/onoff/onoff-application.cc @@ -35,7 +35,7 @@ #include "ns3/uinteger.h" #include "ns3/trace-source-accessor.h" #include "onoff-application.h" -#include "ns3/udp.h" +#include "ns3/udp-socket-factory.h" NS_LOG_COMPONENT_DEFINE ("OnOffApplication"); @@ -79,7 +79,7 @@ OnOffApplication::GetTypeId (void) MakeUintegerAccessor (&OnOffApplication::m_maxBytes), MakeUintegerChecker ()) .AddAttribute ("Protocol", "The type of protocol to use.", - TypeIdValue (Udp::GetTypeId ()), + TypeIdValue (UdpSocketFactory::GetTypeId ()), MakeTypeIdAccessor (&OnOffApplication::m_tid), MakeTypeIdChecker ()) .AddTraceSource ("Tx", "A new packet is created and is sent", diff --git a/src/applications/packet-sink/packet-sink.cc b/src/applications/packet-sink/packet-sink.cc index d4478dc32..d71de1495 100644 --- a/src/applications/packet-sink/packet-sink.cc +++ b/src/applications/packet-sink/packet-sink.cc @@ -26,7 +26,7 @@ #include "ns3/socket-factory.h" #include "ns3/packet.h" #include "ns3/trace-source-accessor.h" -#include "ns3/udp.h" +#include "ns3/udp-socket-factory.h" #include "packet-sink.h" using namespace std; @@ -47,7 +47,7 @@ PacketSink::GetTypeId (void) MakeAddressAccessor (&PacketSink::m_local), MakeAddressChecker ()) .AddAttribute ("Protocol", "The type id of the protocol to use for the rx socket.", - TypeIdValue (Udp::GetTypeId ()), + TypeIdValue (UdpSocketFactory::GetTypeId ()), MakeTypeIdAccessor (&PacketSink::m_tid), MakeTypeIdChecker ()) .AddTraceSource ("Rx", "A packet has been received", diff --git a/src/applications/udp-echo/udp-echo-client.cc b/src/applications/udp-echo/udp-echo-client.cc index 3241b49c5..6276a5ec7 100644 --- a/src/applications/udp-echo/udp-echo-client.cc +++ b/src/applications/udp-echo/udp-echo-client.cc @@ -95,7 +95,7 @@ UdpEchoClient::StartApplication (void) if (!m_socket) { - TypeId tid = TypeId::LookupByName ("ns3::Udp"); + TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); m_socket = Socket::CreateSocket (GetNode(), tid); m_socket->Bind (); m_socket->Connect (InetSocketAddress (m_peerAddress, m_peerPort)); diff --git a/src/applications/udp-echo/udp-echo-server.cc b/src/applications/udp-echo/udp-echo-server.cc index ea305616c..51b7904bd 100644 --- a/src/applications/udp-echo/udp-echo-server.cc +++ b/src/applications/udp-echo/udp-echo-server.cc @@ -71,7 +71,7 @@ UdpEchoServer::StartApplication (void) if (!m_socket) { - TypeId tid = TypeId::LookupByName ("ns3::Udp"); + TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); m_socket = Socket::CreateSocket (GetNode(), tid); InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), m_port); m_socket->Bind (local); diff --git a/src/core/type-id.cc b/src/core/type-id.cc index 6234cb628..1c12a843d 100644 --- a/src/core/type-id.cc +++ b/src/core/type-id.cc @@ -386,7 +386,7 @@ TypeId TypeId::LookupByName (std::string name) { uint16_t uid = Singleton::Get ()->GetUid (name); - NS_ASSERT (uid != 0); + NS_ASSERT_MSG (uid != 0, "Assert in TypeId::LookupByName: " << name << " not found"); return TypeId (uid); } bool diff --git a/src/helper/packet-sink-helper.cc b/src/helper/packet-sink-helper.cc index 45f1d17a6..e7cc76f72 100644 --- a/src/helper/packet-sink-helper.cc +++ b/src/helper/packet-sink-helper.cc @@ -41,7 +41,7 @@ PacketSinkHelper::SetAttribute (std::string name, const AttributeValue &value) void PacketSinkHelper::SetUdpLocal (Ipv4Address ip, uint16_t port) { - m_factory.Set ("Protocol", String ("ns3::Udp")); + m_factory.Set ("Protocol", String ("ns3::UdpSocketFactory")); m_factory.Set ("Local", Address (InetSocketAddress (ip, port))); } void diff --git a/src/internet-node/udp-impl.cc b/src/internet-node/udp-impl.cc index 9de5259e5..86114bb4a 100644 --- a/src/internet-node/udp-impl.cc +++ b/src/internet-node/udp-impl.cc @@ -48,7 +48,7 @@ void UdpImpl::DoDispose (void) { m_udp = 0; - Udp::DoDispose (); + UdpSocketFactory::DoDispose (); } } // namespace ns3 diff --git a/src/internet-node/udp-impl.h b/src/internet-node/udp-impl.h index 114edfdbb..defbdbb02 100644 --- a/src/internet-node/udp-impl.h +++ b/src/internet-node/udp-impl.h @@ -20,7 +20,7 @@ #ifndef UDP_IMPL_H #define UDP_IMPL_H -#include "ns3/udp.h" +#include "ns3/udp-socket-factory.h" #include "ns3/ptr.h" namespace ns3 { @@ -36,7 +36,7 @@ class UdpL4Protocol; * also hold global variables used to initialize newly created sockets, * such as values that are set through the sysctl or proc interfaces in Linux. */ -class UdpImpl : public Udp +class UdpImpl : public UdpSocketFactory { public: UdpImpl (); diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index d2689dfbb..86d37d2da 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -23,8 +23,7 @@ #include "ns3/inet-socket-address.h" #include "ns3/ipv4-route.h" #include "ns3/ipv4.h" -#include "ns3/ipv4.h" -#include "ns3/udp.h" +#include "ns3/udp-socket-factory.h" #include "ns3/trace-source-accessor.h" #include "ns3/uinteger.h" #include "ns3/boolean.h" @@ -464,7 +463,7 @@ UdpSocket::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) #include "ns3/test.h" #include "ns3/socket-factory.h" -#include "ns3/udp.h" +#include "ns3/udp-socket-factory.h" #include "ns3/simulator.h" #include "ns3/simple-channel.h" #include "ns3/simple-net-device.h" @@ -588,7 +587,7 @@ UdpSocketTest::RunTests (void) // Create the UDP sockets - Ptr rxSocketFactory = rxNode->GetObject (); + Ptr rxSocketFactory = rxNode->GetObject (); Ptr rxSocket = rxSocketFactory->CreateSocket (); NS_TEST_ASSERT_EQUAL (rxSocket->Bind (InetSocketAddress (Ipv4Address ("10.0.0.1"), 1234)), 0); rxSocket->SetRecvCallback (MakeCallback (&UdpSocketTest::ReceivePkt, this)); @@ -597,7 +596,7 @@ UdpSocketTest::RunTests (void) rxSocket2->SetRecvCallback (MakeCallback (&UdpSocketTest::ReceivePkt2, this)); NS_TEST_ASSERT_EQUAL (rxSocket2->Bind (InetSocketAddress (Ipv4Address ("10.0.1.1"), 1234)), 0); - Ptr txSocketFactory = txNode->GetObject (); + Ptr txSocketFactory = txNode->GetObject (); Ptr txSocket = txSocketFactory->CreateSocket (); // ------ Now the tests ------------ diff --git a/src/internet-node/udp-socket.h b/src/internet-node/udp-socket.h index 812d5f552..4683d8f2e 100644 --- a/src/internet-node/udp-socket.h +++ b/src/internet-node/udp-socket.h @@ -64,7 +64,7 @@ public: virtual uint32_t GetRxAvailable (void) const; private: - friend class Udp; + friend class UdpSocketFactory; // invoked by Udp class int FinishBind (void); void ForwardUp (Ptr p, Ipv4Address ipv4, uint16_t port); diff --git a/src/node/udp.cc b/src/node/udp-socket-factory.cc similarity index 84% rename from src/node/udp.cc rename to src/node/udp-socket-factory.cc index 14311a2bb..d95b0068a 100644 --- a/src/node/udp.cc +++ b/src/node/udp-socket-factory.cc @@ -17,16 +17,16 @@ * * Author: Mathieu Lacage */ -#include "udp.h" +#include "udp-socket-factory.h" #include "ns3/uinteger.h" namespace ns3 { -NS_OBJECT_ENSURE_REGISTERED (Udp); +NS_OBJECT_ENSURE_REGISTERED (UdpSocketFactory); -TypeId Udp::GetTypeId (void) +TypeId UdpSocketFactory::GetTypeId (void) { - static TypeId tid = TypeId ("ns3::Udp") + static TypeId tid = TypeId ("ns3::UdpSocketFactory") .SetParent () ; return tid; diff --git a/src/node/udp.h b/src/node/udp-socket-factory.h similarity index 91% rename from src/node/udp.h rename to src/node/udp-socket-factory.h index be6b0149d..3fac525ce 100644 --- a/src/node/udp.h +++ b/src/node/udp-socket-factory.h @@ -17,8 +17,8 @@ * * Author: Mathieu Lacage */ -#ifndef UDP_H -#define UDP_H +#ifndef UDP_SOCKET_FACTORY_H +#define UDP_SOCKET_FACTORY_H #include "socket-factory.h" @@ -39,7 +39,7 @@ class Socket; * * \see UdpImpl */ -class Udp : public SocketFactory +class UdpSocketFactory : public SocketFactory { public: static TypeId GetTypeId (void); @@ -56,4 +56,4 @@ public: } // namespace ns3 -#endif /* UDP_H */ +#endif /* UDP_SOCKET_FACTORY_H */ diff --git a/src/node/wscript b/src/node/wscript index 770b1edb9..1a80b33d6 100644 --- a/src/node/wscript +++ b/src/node/wscript @@ -25,7 +25,7 @@ def build(bld): 'socket-factory.cc', 'packet-socket-factory.cc', 'packet-socket.cc', - 'udp.cc', + 'udp-socket-factory.cc', 'tcp.cc', 'ipv4.cc', 'application.cc', @@ -57,7 +57,7 @@ def build(bld): 'socket.h', 'socket-factory.h', 'packet-socket-factory.h', - 'udp.h', + 'udp-socket-factory.h', 'tcp.h', 'ipv4.h', 'application.h', diff --git a/src/routing/olsr/olsr-agent-impl.cc b/src/routing/olsr/olsr-agent-impl.cc index 19257306a..929a2b446 100644 --- a/src/routing/olsr/olsr-agent-impl.cc +++ b/src/routing/olsr/olsr-agent-impl.cc @@ -31,7 +31,7 @@ #include "olsr-agent-impl.h" #include "ns3/socket-factory.h" -#include "ns3/udp.h" +#include "ns3/udp-socket-factory.h" #include "ns3/simulator.h" #include "ns3/log.h" #include "ns3/random-variable.h" @@ -280,7 +280,7 @@ void AgentImpl::Start () // Create a socket to listen only on this interface Ptr socket = Socket::CreateSocket (GetObject (), - Udp::GetTypeId()); + UdpSocketFactory::GetTypeId()); socket->SetRecvCallback (MakeCallback (&AgentImpl::RecvOlsr, this)); if (socket->Bind (InetSocketAddress (addr, OLSR_PORT_NUMBER))) { diff --git a/utils/print-introspected-doxygen.cc b/utils/print-introspected-doxygen.cc index e76629571..c714d5ee7 100644 --- a/utils/print-introspected-doxygen.cc +++ b/utils/print-introspected-doxygen.cc @@ -237,7 +237,7 @@ int main (int argc, char *argv[]) StaticInformation info; info.RecordAggregationInfo ("ns3::Node", "ns3::Tcp"); - info.RecordAggregationInfo ("ns3::Node", "ns3::Udp"); + info.RecordAggregationInfo ("ns3::Node", "ns3::UdpSocketFactory"); info.RecordAggregationInfo ("ns3::Node", "ns3::PacketSocketFactory"); info.RecordAggregationInfo ("ns3::Node", "ns3::olsr::Agent"); info.RecordAggregationInfo ("ns3::Node", "ns3::MobilityModel"); From 25de2ff3c47700153a9f2455c9ebbb9c695ec152 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Sat, 17 May 2008 22:02:09 -0700 Subject: [PATCH 25/45] s/UdpImpl/UdpSocketFactoryImpl --- examples/csma-broadcast.cc | 1 + src/internet-node/internet-stack.cc | 8 ++++---- ...udp-impl.cc => udp-socket-factory-impl.cc} | 12 +++++------ .../{udp-impl.h => udp-socket-factory-impl.h} | 20 +++++++++---------- src/internet-node/wscript | 2 +- 5 files changed, 21 insertions(+), 22 deletions(-) rename src/internet-node/{udp-impl.cc => udp-socket-factory-impl.cc} (80%) rename src/internet-node/{udp-impl.h => udp-socket-factory-impl.h} (72%) diff --git a/examples/csma-broadcast.cc b/examples/csma-broadcast.cc index 7928b3a82..0e5c2f5fb 100644 --- a/examples/csma-broadcast.cc +++ b/examples/csma-broadcast.cc @@ -49,6 +49,7 @@ main (int argc, char *argv[]) #if 0 LogComponentEnable ("CsmaBroadcastExample", LOG_LEVEL_INFO); #endif + LogComponentEnable ("CsmaBroadcastExample", LOG_PREFIX_TIME); // // Make the random number generators generate reproducible results. diff --git a/src/internet-node/internet-stack.cc b/src/internet-node/internet-stack.cc index 916f436ac..8aaab0509 100644 --- a/src/internet-node/internet-stack.cc +++ b/src/internet-node/internet-stack.cc @@ -27,7 +27,7 @@ #include "tcp-l4-protocol.h" #include "ipv4-l3-protocol.h" #include "arp-l3-protocol.h" -#include "udp-impl.h" +#include "udp-socket-factory-impl.h" #include "tcp-impl.h" #include "ipv4-impl.h" @@ -58,18 +58,18 @@ AddInternetStack (Ptr node) ipv4L4Demux->Insert (udp); ipv4L4Demux->Insert (tcp); - Ptr udpImpl = CreateObject (); + Ptr udpFactory = CreateObject (); Ptr tcpImpl = CreateObject (); Ptr ipv4Impl = CreateObject (); - udpImpl->SetUdp (udp); + udpFactory->SetUdp (udp); tcpImpl->SetTcp (tcp); ipv4Impl->SetIpv4 (ipv4); node->AggregateObject (ipv4); node->AggregateObject (arp); node->AggregateObject (ipv4Impl); - node->AggregateObject (udpImpl); + node->AggregateObject (udpFactory); node->AggregateObject (tcpImpl); node->AggregateObject (ipv4L4Demux); } diff --git a/src/internet-node/udp-impl.cc b/src/internet-node/udp-socket-factory-impl.cc similarity index 80% rename from src/internet-node/udp-impl.cc rename to src/internet-node/udp-socket-factory-impl.cc index 86114bb4a..3fd63d6cd 100644 --- a/src/internet-node/udp-impl.cc +++ b/src/internet-node/udp-socket-factory-impl.cc @@ -17,35 +17,35 @@ * * Author: Mathieu Lacage */ -#include "udp-impl.h" +#include "udp-socket-factory-impl.h" #include "udp-l4-protocol.h" #include "ns3/socket.h" #include "ns3/assert.h" namespace ns3 { -UdpImpl::UdpImpl () +UdpSocketFactoryImpl::UdpSocketFactoryImpl () : m_udp (0) {} -UdpImpl::~UdpImpl () +UdpSocketFactoryImpl::~UdpSocketFactoryImpl () { NS_ASSERT (m_udp == 0); } void -UdpImpl::SetUdp (Ptr udp) +UdpSocketFactoryImpl::SetUdp (Ptr udp) { m_udp = udp; } Ptr -UdpImpl::CreateSocket (void) +UdpSocketFactoryImpl::CreateSocket (void) { return m_udp->CreateSocket (); } void -UdpImpl::DoDispose (void) +UdpSocketFactoryImpl::DoDispose (void) { m_udp = 0; UdpSocketFactory::DoDispose (); diff --git a/src/internet-node/udp-impl.h b/src/internet-node/udp-socket-factory-impl.h similarity index 72% rename from src/internet-node/udp-impl.h rename to src/internet-node/udp-socket-factory-impl.h index defbdbb02..b4366fc31 100644 --- a/src/internet-node/udp-impl.h +++ b/src/internet-node/udp-socket-factory-impl.h @@ -17,8 +17,8 @@ * * Author: Mathieu Lacage */ -#ifndef UDP_IMPL_H -#define UDP_IMPL_H +#ifndef UDP_SOCKET_FACTORY_IMPL_H +#define UDP_SOCKET_FACTORY_IMPL_H #include "ns3/udp-socket-factory.h" #include "ns3/ptr.h" @@ -31,21 +31,19 @@ class UdpL4Protocol; * \brief Object to create UDP socket instances * \internal * - * This class implements the API for UDP sockets. - * It is a socket factory (deriving from class SocketFactory) and can - * also hold global variables used to initialize newly created sockets, - * such as values that are set through the sysctl or proc interfaces in Linux. + * This class implements the API for creating UDP sockets. + * It is a socket factory (deriving from class SocketFactory). */ -class UdpImpl : public UdpSocketFactory +class UdpSocketFactoryImpl : public UdpSocketFactory { public: - UdpImpl (); - virtual ~UdpImpl (); + UdpSocketFactoryImpl (); + virtual ~UdpSocketFactoryImpl (); void SetUdp (Ptr udp); /** - * \brief Implements a method to create a UdpImpl-based socket and return + * \brief Implements a method to create a Udp-based socket and return * a base class smart pointer to the socket. * \internal * @@ -61,4 +59,4 @@ private: } // namespace ns3 -#endif /* UDP_IMPL_H */ +#endif /* UDP_SOCKET_FACTORY_IMPL_H */ diff --git a/src/internet-node/wscript b/src/internet-node/wscript index 2d03561ff..abd8f471c 100644 --- a/src/internet-node/wscript +++ b/src/internet-node/wscript @@ -28,7 +28,7 @@ def build(bld): 'ipv4-impl.cc', 'ascii-trace.cc', 'pcap-trace.cc', - 'udp-impl.cc', + 'udp-socket-factory-impl.cc', 'tcp-impl.cc', 'pending-data.cc', 'sequence-number.cc', From 5b119aa40d05ef5ca1141e5f021101899126f352 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Tue, 20 May 2008 07:25:17 -0700 Subject: [PATCH 26/45] 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', From 2a14b1c40861a731144adbb3f30878138c361a50 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Tue, 20 May 2008 07:27:16 -0700 Subject: [PATCH 27/45] remove spurious test line --- examples/simple-point-to-point-olsr.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/simple-point-to-point-olsr.cc b/examples/simple-point-to-point-olsr.cc index cd52a0477..bd7b39487 100644 --- a/examples/simple-point-to-point-olsr.cc +++ b/examples/simple-point-to-point-olsr.cc @@ -67,7 +67,6 @@ 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")); From 935532822bc59aab7a6778d0820b3e8747d93531 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Tue, 20 May 2008 10:16:03 -0700 Subject: [PATCH 28/45] Move UdpSocket to UdpSocketImpl --- .../{udp-socket.cc => udp-socket-impl.cc} | 0 .../{udp-socket.h => udp-socket-impl.h} | 0 src/node/udp-socketx.cc | 70 ++++++++++++++++ src/node/udp-socketx.h | 79 +++++++++++++++++++ 4 files changed, 149 insertions(+) rename src/internet-node/{udp-socket.cc => udp-socket-impl.cc} (100%) rename src/internet-node/{udp-socket.h => udp-socket-impl.h} (100%) create mode 100644 src/node/udp-socketx.cc create mode 100644 src/node/udp-socketx.h diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket-impl.cc similarity index 100% rename from src/internet-node/udp-socket.cc rename to src/internet-node/udp-socket-impl.cc diff --git a/src/internet-node/udp-socket.h b/src/internet-node/udp-socket-impl.h similarity index 100% rename from src/internet-node/udp-socket.h rename to src/internet-node/udp-socket-impl.h diff --git a/src/node/udp-socketx.cc b/src/node/udp-socketx.cc new file mode 100644 index 000000000..3e7c0fd3f --- /dev/null +++ b/src/node/udp-socketx.cc @@ -0,0 +1,70 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Mathieu Lacage + */ + +#include "ns3/object.h" +#include "ns3/log.h" +#include "ns3/uinteger.h" +#include "ns3/trace-source-accessor.h" +#include "udp-socketx.h" + +NS_LOG_COMPONENT_DEFINE ("UdpSocketx"); + +namespace ns3 { + +NS_OBJECT_ENSURE_REGISTERED (UdpSocketx); + +TypeId +UdpSocketx::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::UdpSocketx") + .SetParent () + .AddAttribute ("RcvBufSize", + "UdpSocket maximum receive buffer size (bytes)", + UintegerValue (0xffffffffl), + MakeUintegerAccessor (&UdpSocketx::GetRcvBufSize, + &UdpSocketx::SetRcvBufSize), + MakeUintegerChecker ()) + .AddAttribute ("IpTtl", + "socket-specific TTL for unicast IP packets (if non-zero)", + UintegerValue (0), + MakeUintegerAccessor (&UdpSocketx::GetIpTtl, + &UdpSocketx::SetIpTtl), + MakeUintegerChecker ()) + .AddAttribute ("IpMulticastTtl", + "socket-specific TTL for multicast IP packets (if non-zero)", + UintegerValue (0), + MakeUintegerAccessor (&UdpSocketx::GetIpMulticastTtl, + &UdpSocketx::SetIpMulticastTtl), + MakeUintegerChecker ()) + ; + return tid; +} + +UdpSocketx::UdpSocketx () +{ + NS_LOG_FUNCTION_NOARGS (); +} + +UdpSocketx::~UdpSocketx () +{ + NS_LOG_FUNCTION_NOARGS (); +} + +}; // namespace ns3 diff --git a/src/node/udp-socketx.h b/src/node/udp-socketx.h new file mode 100644 index 000000000..3731ee7e8 --- /dev/null +++ b/src/node/udp-socketx.h @@ -0,0 +1,79 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2006 Georgia Tech Research Corporation + * 2007 INRIA + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: George F. Riley + * Mathieu Lacage + */ + +#ifndef __UDP_SOCKETX_H__ +#define __UDP_SOCKETX_H__ + +#include "socket.h" +#include "ns3/traced-callback.h" +#include "ns3/callback.h" +#include "ns3/ptr.h" +#include "ns3/object.h" + +namespace ns3 { + +class Node; +class Packet; + +/** + * \brief (abstract) base class of all UdpSockets + * + * This class exists solely for hosting UdpSocket attributes that can + * be reused across different implementations. + */ +class UdpSocketx : public Socket +{ +public: + static TypeId GetTypeId (void); + + UdpSocketx (void); + virtual ~UdpSocketx (void); + + virtual enum Socket::SocketErrno GetErrno (void) const = 0; + virtual Ptr GetNode (void) const = 0; + virtual int Bind () = 0; + virtual int Close (void) = 0; + virtual int ShutdownSend (void) = 0; + virtual int ShutdownRecv (void) = 0; + virtual int Connect (const Address &address) = 0; + virtual int Send (Ptr p) = 0; + virtual uint32_t GetTxAvailable (void) const = 0; + virtual int SendTo (Ptr p, const Address &address) = 0; + virtual Ptr Recv (uint32_t maxSize, uint32_t flags) = 0; + virtual uint32_t GetRxAvailable (void) const = 0; + +public: + // Indirect the attribute setting and getting through private virtual methods + virtual void SetRcvBufSize (uint32_t size) = 0; + virtual uint32_t GetRcvBufSize (void) const = 0; + virtual void SetIpTtl (uint32_t ipTtl) = 0; + virtual uint32_t GetIpTtl (void) const = 0; + virtual void SetIpMulticastTtl (uint32_t ipTtl) = 0; + virtual uint32_t GetIpMulticastTtl (void) const = 0; + +}; + +} //namespace ns3 + +#endif /* UDP_SOCKET_H */ + + From ad374c8d874bbb54e57ca2cc17b0950e924f5c93 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Tue, 20 May 2008 10:30:40 -0700 Subject: [PATCH 29/45] rename UdpSocket to UdpSocketImpl --- src/internet-node/udp-l4-protocol.cc | 4 +- src/internet-node/udp-socket-impl.cc | 102 ++++++++++----------- src/internet-node/udp-socket-impl.h | 14 +-- src/internet-node/wscript | 2 +- src/node/{udp-socketx.cc => udp-socket.cc} | 26 +++--- src/node/{udp-socketx.h => udp-socket.h} | 10 +- src/node/wscript | 4 +- 7 files changed, 81 insertions(+), 81 deletions(-) rename src/node/{udp-socketx.cc => udp-socket.cc} (72%) rename src/node/{udp-socketx.h => udp-socket.h} (94%) diff --git a/src/internet-node/udp-l4-protocol.cc b/src/internet-node/udp-l4-protocol.cc index 424908712..f3b85e15e 100644 --- a/src/internet-node/udp-l4-protocol.cc +++ b/src/internet-node/udp-l4-protocol.cc @@ -28,7 +28,7 @@ #include "ipv4-end-point-demux.h" #include "ipv4-end-point.h" #include "ipv4-l3-protocol.h" -#include "udp-socket.h" +#include "udp-socket-impl.h" NS_LOG_COMPONENT_DEFINE ("UdpL4Protocol"); @@ -95,7 +95,7 @@ Ptr UdpL4Protocol::CreateSocket (void) { NS_LOG_FUNCTION_NOARGS (); - Ptr socket = CreateObject (); + Ptr socket = CreateObject (); socket->SetNode (m_node); socket->SetUdp (this); return socket; diff --git a/src/internet-node/udp-socket-impl.cc b/src/internet-node/udp-socket-impl.cc index a7513e27f..9f326246e 100644 --- a/src/internet-node/udp-socket-impl.cc +++ b/src/internet-node/udp-socket-impl.cc @@ -27,12 +27,12 @@ #include "ns3/trace-source-accessor.h" #include "ns3/uinteger.h" #include "ns3/boolean.h" -#include "udp-socket.h" +#include "udp-socket-impl.h" #include "udp-l4-protocol.h" #include "ipv4-end-point.h" #include "ipv4-l4-demux.h" -NS_LOG_COMPONENT_DEFINE ("UdpSocket"); +NS_LOG_COMPONENT_DEFINE ("UdpSocketImpl"); namespace ns3 { @@ -40,18 +40,18 @@ static const uint32_t MAX_IPV4_UDP_DATAGRAM_SIZE = 65507; // Add attributes generic to all UdpSockets to base class UdpSocket TypeId -UdpSocket::GetTypeId (void) +UdpSocketImpl::GetTypeId (void) { - static TypeId tid = TypeId ("ns3::UdpSocket") - .SetParent () - .AddConstructor () + static TypeId tid = TypeId ("ns3::UdpSocketImpl") + .SetParent () + .AddConstructor () .AddTraceSource ("Drop", "Drop UDP packet due to receive buffer overflow", - MakeTraceSourceAccessor (&UdpSocket::m_dropTrace)) + MakeTraceSourceAccessor (&UdpSocketImpl::m_dropTrace)) ; return tid; } -UdpSocket::UdpSocket () +UdpSocketImpl::UdpSocketImpl () : m_endPoint (0), m_node (0), m_udp (0), @@ -64,7 +64,7 @@ UdpSocket::UdpSocket () NS_LOG_FUNCTION_NOARGS (); } -UdpSocket::~UdpSocket () +UdpSocketImpl::~UdpSocketImpl () { NS_LOG_FUNCTION_NOARGS (); @@ -88,14 +88,14 @@ UdpSocket::~UdpSocket () } void -UdpSocket::SetNode (Ptr node) +UdpSocketImpl::SetNode (Ptr node) { NS_LOG_FUNCTION_NOARGS (); m_node = node; } void -UdpSocket::SetUdp (Ptr udp) +UdpSocketImpl::SetUdp (Ptr udp) { NS_LOG_FUNCTION_NOARGS (); m_udp = udp; @@ -103,21 +103,21 @@ UdpSocket::SetUdp (Ptr udp) enum Socket::SocketErrno -UdpSocket::GetErrno (void) const +UdpSocketImpl::GetErrno (void) const { NS_LOG_FUNCTION_NOARGS (); return m_errno; } Ptr -UdpSocket::GetNode (void) const +UdpSocketImpl::GetNode (void) const { NS_LOG_FUNCTION_NOARGS (); return m_node; } void -UdpSocket::Destroy (void) +UdpSocketImpl::Destroy (void) { NS_LOG_FUNCTION_NOARGS (); m_node = 0; @@ -126,20 +126,20 @@ UdpSocket::Destroy (void) } int -UdpSocket::FinishBind (void) +UdpSocketImpl::FinishBind (void) { NS_LOG_FUNCTION_NOARGS (); if (m_endPoint == 0) { return -1; } - m_endPoint->SetRxCallback (MakeCallback (&UdpSocket::ForwardUp, this)); - m_endPoint->SetDestroyCallback (MakeCallback (&UdpSocket::Destroy, this)); + m_endPoint->SetRxCallback (MakeCallback (&UdpSocketImpl::ForwardUp, this)); + m_endPoint->SetDestroyCallback (MakeCallback (&UdpSocketImpl::Destroy, this)); return 0; } int -UdpSocket::Bind (void) +UdpSocketImpl::Bind (void) { NS_LOG_FUNCTION_NOARGS (); m_endPoint = m_udp->Allocate (); @@ -147,7 +147,7 @@ UdpSocket::Bind (void) } int -UdpSocket::Bind (const Address &address) +UdpSocketImpl::Bind (const Address &address) { NS_LOG_FUNCTION (this << address); @@ -180,7 +180,7 @@ UdpSocket::Bind (const Address &address) } int -UdpSocket::ShutdownSend (void) +UdpSocketImpl::ShutdownSend (void) { NS_LOG_FUNCTION_NOARGS (); m_shutdownSend = true; @@ -188,7 +188,7 @@ UdpSocket::ShutdownSend (void) } int -UdpSocket::ShutdownRecv (void) +UdpSocketImpl::ShutdownRecv (void) { NS_LOG_FUNCTION_NOARGS (); m_shutdownRecv = false; @@ -196,7 +196,7 @@ UdpSocket::ShutdownRecv (void) } int -UdpSocket::Close(void) +UdpSocketImpl::Close(void) { NS_LOG_FUNCTION_NOARGS (); NotifyCloseCompleted (); @@ -204,7 +204,7 @@ UdpSocket::Close(void) } int -UdpSocket::Connect(const Address & address) +UdpSocketImpl::Connect(const Address & address) { NS_LOG_FUNCTION (this << address); InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); @@ -217,7 +217,7 @@ UdpSocket::Connect(const Address & address) } int -UdpSocket::Send (Ptr p) +UdpSocketImpl::Send (Ptr p) { NS_LOG_FUNCTION (this << p); @@ -230,7 +230,7 @@ UdpSocket::Send (Ptr p) } int -UdpSocket::DoSend (Ptr p) +UdpSocketImpl::DoSend (Ptr p) { NS_LOG_FUNCTION_NOARGS (); if (m_endPoint == 0) @@ -252,7 +252,7 @@ UdpSocket::DoSend (Ptr p) } int -UdpSocket::DoSendTo (Ptr p, const Address &address) +UdpSocketImpl::DoSendTo (Ptr p, const Address &address) { NS_LOG_FUNCTION (this << p << address); @@ -273,7 +273,7 @@ UdpSocket::DoSendTo (Ptr p, const Address &address) } int -UdpSocket::DoSendTo (Ptr p, Ipv4Address dest, uint16_t port) +UdpSocketImpl::DoSendTo (Ptr p, Ipv4Address dest, uint16_t port) { NS_LOG_FUNCTION (this << p << dest << port); @@ -364,7 +364,7 @@ UdpSocket::DoSendTo (Ptr p, Ipv4Address dest, uint16_t port) // XXX maximum message size for UDP broadcast is limited by MTU // size of underlying link; we are not checking that now. uint32_t -UdpSocket::GetTxAvailable (void) const +UdpSocketImpl::GetTxAvailable (void) const { NS_LOG_FUNCTION_NOARGS (); // No finite send buffer is modelled, but we must respect @@ -373,7 +373,7 @@ UdpSocket::GetTxAvailable (void) const } int -UdpSocket::SendTo (Ptr p, const Address &address) +UdpSocketImpl::SendTo (Ptr p, const Address &address) { NS_LOG_FUNCTION (this << address << p); InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); @@ -383,7 +383,7 @@ UdpSocket::SendTo (Ptr p, const Address &address) } Ptr -UdpSocket::Recv (uint32_t maxSize, uint32_t flags) +UdpSocketImpl::Recv (uint32_t maxSize, uint32_t flags) { NS_LOG_FUNCTION_NOARGS (); if (m_deliveryQueue.empty() ) @@ -404,7 +404,7 @@ UdpSocket::Recv (uint32_t maxSize, uint32_t flags) } uint32_t -UdpSocket::GetRxAvailable (void) const +UdpSocketImpl::GetRxAvailable (void) const { NS_LOG_FUNCTION_NOARGS (); // We separately maintain this state to avoid walking the queue @@ -413,7 +413,7 @@ UdpSocket::GetRxAvailable (void) const } void -UdpSocket::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) +UdpSocketImpl::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) { NS_LOG_FUNCTION (this << packet << ipv4 << port); @@ -445,37 +445,37 @@ UdpSocket::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) void -UdpSocket::SetRcvBufSize (uint32_t size) +UdpSocketImpl::SetRcvBufSize (uint32_t size) { m_rcvBufSize = size; } uint32_t -UdpSocket::GetRcvBufSize (void) const +UdpSocketImpl::GetRcvBufSize (void) const { return m_rcvBufSize; } void -UdpSocket::SetIpTtl (uint32_t ipTtl) +UdpSocketImpl::SetIpTtl (uint32_t ipTtl) { m_ipTtl = ipTtl; } uint32_t -UdpSocket::GetIpTtl (void) const +UdpSocketImpl::GetIpTtl (void) const { return m_ipTtl; } void -UdpSocket::SetIpMulticastTtl (uint32_t ipTtl) +UdpSocketImpl::SetIpMulticastTtl (uint32_t ipTtl) { m_ipMulticastTtl = ipTtl; } uint32_t -UdpSocket::GetIpMulticastTtl (void) const +UdpSocketImpl::GetIpMulticastTtl (void) const { return m_ipMulticastTtl; } @@ -497,14 +497,14 @@ UdpSocket::GetIpMulticastTtl (void) const namespace ns3 { -class UdpSocketTest: public Test +class UdpSocketImplTest: public Test { Ptr m_receivedPacket; Ptr m_receivedPacket2; public: virtual bool RunTests (void); - UdpSocketTest (); + UdpSocketImplTest (); void ReceivePacket (Ptr socket, Ptr packet, const Address &from); void ReceivePacket2 (Ptr socket, Ptr packet, const Address &from); @@ -513,29 +513,29 @@ public: }; -UdpSocketTest::UdpSocketTest () - : Test ("UdpSocket") +UdpSocketImplTest::UdpSocketImplTest () + : Test ("UdpSocketImpl") { } -void UdpSocketTest::ReceivePacket (Ptr socket, Ptr packet, const Address &from) +void UdpSocketImplTest::ReceivePacket (Ptr socket, Ptr packet, const Address &from) { m_receivedPacket = packet; } -void UdpSocketTest::ReceivePacket2 (Ptr socket, Ptr packet, const Address &from) +void UdpSocketImplTest::ReceivePacket2 (Ptr socket, Ptr packet, const Address &from) { m_receivedPacket2 = packet; } -void UdpSocketTest::ReceivePkt (Ptr socket) +void UdpSocketImplTest::ReceivePkt (Ptr socket) { uint32_t availableData = socket->GetRxAvailable (); m_receivedPacket = socket->Recv (std::numeric_limits::max(), 0); NS_ASSERT (availableData == m_receivedPacket->GetSize ()); } -void UdpSocketTest::ReceivePkt2 (Ptr socket) +void UdpSocketImplTest::ReceivePkt2 (Ptr socket) { uint32_t availableData = socket->GetRxAvailable (); m_receivedPacket2 = socket->Recv (std::numeric_limits::max(), 0); @@ -543,7 +543,7 @@ void UdpSocketTest::ReceivePkt2 (Ptr socket) } bool -UdpSocketTest::RunTests (void) +UdpSocketImplTest::RunTests (void) { bool result = true; @@ -615,10 +615,10 @@ UdpSocketTest::RunTests (void) Ptr rxSocketFactory = rxNode->GetObject (); Ptr rxSocket = rxSocketFactory->CreateSocket (); NS_TEST_ASSERT_EQUAL (rxSocket->Bind (InetSocketAddress (Ipv4Address ("10.0.0.1"), 1234)), 0); - rxSocket->SetRecvCallback (MakeCallback (&UdpSocketTest::ReceivePkt, this)); + rxSocket->SetRecvCallback (MakeCallback (&UdpSocketImplTest::ReceivePkt, this)); Ptr rxSocket2 = rxSocketFactory->CreateSocket (); - rxSocket2->SetRecvCallback (MakeCallback (&UdpSocketTest::ReceivePkt2, this)); + rxSocket2->SetRecvCallback (MakeCallback (&UdpSocketImplTest::ReceivePkt2, this)); NS_TEST_ASSERT_EQUAL (rxSocket2->Bind (InetSocketAddress (Ipv4Address ("10.0.1.1"), 1234)), 0); Ptr txSocketFactory = txNode->GetObject (); @@ -659,7 +659,7 @@ UdpSocketTest::RunTests (void) // the socket address matches. rxSocket2->Dispose (); rxSocket2 = rxSocketFactory->CreateSocket (); - rxSocket2->SetRecvCallback (MakeCallback (&UdpSocketTest::ReceivePkt2, this)); + rxSocket2->SetRecvCallback (MakeCallback (&UdpSocketImplTest::ReceivePkt2, this)); NS_TEST_ASSERT_EQUAL (rxSocket2->Bind (InetSocketAddress (Ipv4Address ("0.0.0.0"), 1234)), 0); m_receivedPacket = Create (); @@ -678,7 +678,7 @@ InetSocketAddress (Ipv4Address("255.255.255.255"), 1234)), 123); return result; } -static UdpSocketTest gUdpSocketTest; +static UdpSocketImplTest gUdpSocketImplTest; }; // namespace ns3 diff --git a/src/internet-node/udp-socket-impl.h b/src/internet-node/udp-socket-impl.h index 97f24f95a..71bded586 100644 --- a/src/internet-node/udp-socket-impl.h +++ b/src/internet-node/udp-socket-impl.h @@ -17,8 +17,8 @@ * * Author: Mathieu Lacage */ -#ifndef UDP_SOCKET_H -#define UDP_SOCKET_H +#ifndef UDP_SOCKET_IMPL_H +#define UDP_SOCKET_IMPL_H #include #include @@ -27,7 +27,7 @@ #include "ns3/socket.h" #include "ns3/ptr.h" #include "ns3/ipv4-address.h" -#include "ns3/udp-socketx.h" +#include "ns3/udp-socket.h" namespace ns3 { @@ -36,15 +36,15 @@ class Node; class Packet; class UdpL4Protocol; -class UdpSocket : public UdpSocketx +class UdpSocketImpl : public UdpSocket { public: static TypeId GetTypeId (void); /** * Create an unbound udp socket. */ - UdpSocket (); - virtual ~UdpSocket (); + UdpSocketImpl (); + virtual ~UdpSocketImpl (); void SetNode (Ptr node); void SetUdp (Ptr udp); @@ -108,4 +108,4 @@ private: }//namespace ns3 -#endif /* UDP_SOCKET_H */ +#endif /* UDP_SOCKET_IMPL_H */ diff --git a/src/internet-node/wscript b/src/internet-node/wscript index abd8f471c..7b05bdaf0 100644 --- a/src/internet-node/wscript +++ b/src/internet-node/wscript @@ -22,7 +22,7 @@ def build(bld): 'arp-ipv4-interface.cc', 'arp-l3-protocol.cc', 'ipv4-loopback-interface.cc', - 'udp-socket.cc', + 'udp-socket-impl.cc', 'tcp-socket.cc', 'ipv4-end-point-demux.cc', 'ipv4-impl.cc', diff --git a/src/node/udp-socketx.cc b/src/node/udp-socket.cc similarity index 72% rename from src/node/udp-socketx.cc rename to src/node/udp-socket.cc index 3e7c0fd3f..8fc5ea8b1 100644 --- a/src/node/udp-socketx.cc +++ b/src/node/udp-socket.cc @@ -22,47 +22,47 @@ #include "ns3/log.h" #include "ns3/uinteger.h" #include "ns3/trace-source-accessor.h" -#include "udp-socketx.h" +#include "udp-socket.h" -NS_LOG_COMPONENT_DEFINE ("UdpSocketx"); +NS_LOG_COMPONENT_DEFINE ("UdpSocket"); namespace ns3 { -NS_OBJECT_ENSURE_REGISTERED (UdpSocketx); +NS_OBJECT_ENSURE_REGISTERED (UdpSocket); TypeId -UdpSocketx::GetTypeId (void) +UdpSocket::GetTypeId (void) { - static TypeId tid = TypeId ("ns3::UdpSocketx") + static TypeId tid = TypeId ("ns3::UdpSocket") .SetParent () .AddAttribute ("RcvBufSize", "UdpSocket maximum receive buffer size (bytes)", UintegerValue (0xffffffffl), - MakeUintegerAccessor (&UdpSocketx::GetRcvBufSize, - &UdpSocketx::SetRcvBufSize), + MakeUintegerAccessor (&UdpSocket::GetRcvBufSize, + &UdpSocket::SetRcvBufSize), MakeUintegerChecker ()) .AddAttribute ("IpTtl", "socket-specific TTL for unicast IP packets (if non-zero)", UintegerValue (0), - MakeUintegerAccessor (&UdpSocketx::GetIpTtl, - &UdpSocketx::SetIpTtl), + MakeUintegerAccessor (&UdpSocket::GetIpTtl, + &UdpSocket::SetIpTtl), MakeUintegerChecker ()) .AddAttribute ("IpMulticastTtl", "socket-specific TTL for multicast IP packets (if non-zero)", UintegerValue (0), - MakeUintegerAccessor (&UdpSocketx::GetIpMulticastTtl, - &UdpSocketx::SetIpMulticastTtl), + MakeUintegerAccessor (&UdpSocket::GetIpMulticastTtl, + &UdpSocket::SetIpMulticastTtl), MakeUintegerChecker ()) ; return tid; } -UdpSocketx::UdpSocketx () +UdpSocket::UdpSocket () { NS_LOG_FUNCTION_NOARGS (); } -UdpSocketx::~UdpSocketx () +UdpSocket::~UdpSocket () { NS_LOG_FUNCTION_NOARGS (); } diff --git a/src/node/udp-socketx.h b/src/node/udp-socket.h similarity index 94% rename from src/node/udp-socketx.h rename to src/node/udp-socket.h index 3731ee7e8..5f20fd7c0 100644 --- a/src/node/udp-socketx.h +++ b/src/node/udp-socket.h @@ -20,8 +20,8 @@ * Mathieu Lacage */ -#ifndef __UDP_SOCKETX_H__ -#define __UDP_SOCKETX_H__ +#ifndef __UDP_SOCKET_H__ +#define __UDP_SOCKET_H__ #include "socket.h" #include "ns3/traced-callback.h" @@ -40,13 +40,13 @@ class Packet; * This class exists solely for hosting UdpSocket attributes that can * be reused across different implementations. */ -class UdpSocketx : public Socket +class UdpSocket : public Socket { public: static TypeId GetTypeId (void); - UdpSocketx (void); - virtual ~UdpSocketx (void); + UdpSocket (void); + virtual ~UdpSocket (void); virtual enum Socket::SocketErrno GetErrno (void) const = 0; virtual Ptr GetNode (void) const = 0; diff --git a/src/node/wscript b/src/node/wscript index c1238b8b9..3f35ca216 100644 --- a/src/node/wscript +++ b/src/node/wscript @@ -25,7 +25,7 @@ def build(bld): 'socket-factory.cc', 'packet-socket-factory.cc', 'packet-socket.cc', - 'udp-socketx.cc', + 'udp-socket.cc', 'udp-socket-factory.cc', 'tcp.cc', 'ipv4.cc', @@ -58,7 +58,7 @@ def build(bld): 'socket.h', 'socket-factory.h', 'packet-socket-factory.h', - 'udp-socketx.h', + 'udp-socket.h', 'udp-socket-factory.h', 'tcp.h', 'ipv4.h', From e6bd2a7a6aa36f0ae90a16208b588427dc4e0058 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Tue, 20 May 2008 11:52:25 -0700 Subject: [PATCH 30/45] change TcpSocket to TcpSocketImpl --- src/internet-node/tcp-header.cc | 2 +- src/internet-node/tcp-impl.h | 2 +- src/internet-node/tcp-l4-protocol.cc | 4 +- src/internet-node/tcp-l4-protocol.h | 6 +- .../{tcp-socket.cc => tcp-socket-impl.cc} | 244 +++++++++--------- .../{tcp-socket.h => tcp-socket-impl.h} | 16 +- src/internet-node/wscript | 2 +- 7 files changed, 138 insertions(+), 138 deletions(-) rename src/internet-node/{tcp-socket.cc => tcp-socket-impl.cc} (83%) rename src/internet-node/{tcp-socket.h => tcp-socket-impl.h} (96%) diff --git a/src/internet-node/tcp-header.cc b/src/internet-node/tcp-header.cc index f5c485999..c0f476220 100644 --- a/src/internet-node/tcp-header.cc +++ b/src/internet-node/tcp-header.cc @@ -20,7 +20,7 @@ #include #include -#include "tcp-socket.h" +#include "tcp-socket-impl.h" #include "tcp-header.h" #include "ns3/buffer.h" diff --git a/src/internet-node/tcp-impl.h b/src/internet-node/tcp-impl.h index 9990c7721..1b69a1d13 100644 --- a/src/internet-node/tcp-impl.h +++ b/src/internet-node/tcp-impl.h @@ -37,7 +37,7 @@ class TcpL4Protocol; * * Georgia Tech Network Simulator (GTNetS). * - * Most of the logic is in class ns3::TcpSocket. + * Most of the logic is in class ns3::TcpSocketImpl. */ class TcpImpl : public Tcp { diff --git a/src/internet-node/tcp-l4-protocol.cc b/src/internet-node/tcp-l4-protocol.cc index 653575db0..2898b09f4 100644 --- a/src/internet-node/tcp-l4-protocol.cc +++ b/src/internet-node/tcp-l4-protocol.cc @@ -30,7 +30,7 @@ #include "ipv4-end-point-demux.h" #include "ipv4-end-point.h" #include "ipv4-l3-protocol.h" -#include "tcp-socket.h" +#include "tcp-socket-impl.h" #include "tcp-typedefs.h" @@ -379,7 +379,7 @@ TcpL4Protocol::CreateSocket (void) { NS_LOG_FUNCTION_NOARGS (); Ptr rtt = m_rttFactory.Create (); - Ptr socket = CreateObject (); + Ptr socket = CreateObject (); socket->SetNode (m_node); socket->SetTcp (this); socket->SetRtt (rtt); diff --git a/src/internet-node/tcp-l4-protocol.h b/src/internet-node/tcp-l4-protocol.h index e832a69a2..b08eabeba 100644 --- a/src/internet-node/tcp-l4-protocol.h +++ b/src/internet-node/tcp-l4-protocol.h @@ -59,7 +59,7 @@ public: virtual int GetVersion (void) const; /** - * \return A smart Socket pointer to a TcpSocket, allocated by this instance + * \return A smart Socket pointer to a TcpSocketImpl, allocated by this instance * of the TCP protocol */ Ptr CreateSocket (void); @@ -73,7 +73,7 @@ public: void DeAllocate (Ipv4EndPoint *endPoint); -// // called by TcpSocket. +// // called by TcpSocketImpl. // bool Connect (const Ipv4Address& saddr, const Ipv4Address& daddr, // uint16_t sport, uint16_t dport); @@ -107,7 +107,7 @@ private: Ipv4EndPointDemux *m_endPoints; ObjectFactory m_rttFactory; private: - friend class TcpSocket; + friend class TcpSocketImpl; void SendPacket (Ptr, TcpHeader, Ipv4Address, Ipv4Address); static ObjectFactory GetDefaultRttEstimatorFactory (void); diff --git a/src/internet-node/tcp-socket.cc b/src/internet-node/tcp-socket-impl.cc similarity index 83% rename from src/internet-node/tcp-socket.cc rename to src/internet-node/tcp-socket-impl.cc index 3e2a7bc2a..12686e376 100644 --- a/src/internet-node/tcp-socket.cc +++ b/src/internet-node/tcp-socket-impl.cc @@ -23,7 +23,7 @@ #include "ns3/inet-socket-address.h" #include "ns3/log.h" #include "ns3/ipv4.h" -#include "tcp-socket.h" +#include "tcp-socket-impl.h" #include "tcp-l4-protocol.h" #include "ipv4-end-point.h" #include "ipv4-l4-demux.h" @@ -36,27 +36,27 @@ #include -NS_LOG_COMPONENT_DEFINE ("TcpSocket"); +NS_LOG_COMPONENT_DEFINE ("TcpSocketImpl"); using namespace std; namespace ns3 { -NS_OBJECT_ENSURE_REGISTERED (TcpSocket); +NS_OBJECT_ENSURE_REGISTERED (TcpSocketImpl); TypeId -TcpSocket::GetTypeId () +TcpSocketImpl::GetTypeId () { - static TypeId tid = TypeId("ns3::TcpSocket") + static TypeId tid = TypeId("ns3::TcpSocketImpl") .SetParent () .AddTraceSource ("CongestionWindow", "The TCP connection's congestion window", - MakeTraceSourceAccessor (&TcpSocket::m_cWnd)) + MakeTraceSourceAccessor (&TcpSocketImpl::m_cWnd)) ; return tid; } - TcpSocket::TcpSocket () + TcpSocketImpl::TcpSocketImpl () : m_skipRetxResched (false), m_dupAckCount (0), m_delAckCount (0), @@ -89,7 +89,7 @@ TcpSocket::GetTypeId () } -TcpSocket::TcpSocket(const TcpSocket& sock) +TcpSocketImpl::TcpSocketImpl(const TcpSocketImpl& sock) : Socket(sock), //copy the base class callbacks m_skipRetxResched (sock.m_skipRetxResched), m_dupAckCount (sock.m_dupAckCount), @@ -148,7 +148,7 @@ TcpSocket::TcpSocket(const TcpSocket& sock) //too; this is in SYN_ACK_TX } -TcpSocket::~TcpSocket () +TcpSocketImpl::~TcpSocketImpl () { NS_LOG_FUNCTION(this); m_node = 0; @@ -173,7 +173,7 @@ TcpSocket::~TcpSocket () } void -TcpSocket::SetNode (Ptr node) +TcpSocketImpl::SetNode (Ptr node) { m_node = node; Ptr t = node->GetObject (); @@ -190,33 +190,33 @@ TcpSocket::SetNode (Ptr node) } void -TcpSocket::SetTcp (Ptr tcp) +TcpSocketImpl::SetTcp (Ptr tcp) { m_tcp = tcp; } void -TcpSocket::SetRtt (Ptr rtt) +TcpSocketImpl::SetRtt (Ptr rtt) { m_rtt = rtt; } enum Socket::SocketErrno -TcpSocket::GetErrno (void) const +TcpSocketImpl::GetErrno (void) const { NS_LOG_FUNCTION_NOARGS (); return m_errno; } Ptr -TcpSocket::GetNode (void) const +TcpSocketImpl::GetNode (void) const { NS_LOG_FUNCTION_NOARGS (); return m_node; } void -TcpSocket::Destroy (void) +TcpSocketImpl::Destroy (void) { NS_LOG_FUNCTION_NOARGS (); m_node = 0; @@ -225,29 +225,29 @@ TcpSocket::Destroy (void) m_retxEvent.Cancel (); } int -TcpSocket::FinishBind (void) +TcpSocketImpl::FinishBind (void) { NS_LOG_FUNCTION_NOARGS (); if (m_endPoint == 0) { return -1; } - m_endPoint->SetRxCallback (MakeCallback (&TcpSocket::ForwardUp, Ptr(this))); - m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocket::Destroy, Ptr(this))); + m_endPoint->SetRxCallback (MakeCallback (&TcpSocketImpl::ForwardUp, Ptr(this))); + m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocketImpl::Destroy, Ptr(this))); m_localAddress = m_endPoint->GetLocalAddress (); m_localPort = m_endPoint->GetLocalPort (); return 0; } int -TcpSocket::Bind (void) +TcpSocketImpl::Bind (void) { NS_LOG_FUNCTION_NOARGS (); m_endPoint = m_tcp->Allocate (); return FinishBind (); } int -TcpSocket::Bind (const Address &address) +TcpSocketImpl::Bind (const Address &address) { NS_LOG_FUNCTION (this<Allocate (); - NS_LOG_LOGIC ("TcpSocket "<Allocate (port); - NS_LOG_LOGIC ("TcpSocket "<Allocate (ipv4); - NS_LOG_LOGIC ("TcpSocket "<Allocate (ipv4, port); - NS_LOG_LOGIC ("TcpSocket "< p) //p here is just data, no headers +TcpSocketImpl::Send (const Ptr p) //p here is just data, no headers { // TCP Does not deal with packets from app, just data return Send(p->PeekData(), p->GetSize()); } -int TcpSocket::Send (const uint8_t* buf, uint32_t size) +int TcpSocketImpl::Send (const uint8_t* buf, uint32_t size) { NS_LOG_FUNCTION (this << buf << size); if (m_state == ESTABLISHED || m_state == SYN_SENT || m_state == CLOSE_WAIT) @@ -397,7 +397,7 @@ int TcpSocket::Send (const uint8_t* buf, uint32_t size) } } -int TcpSocket::DoSendTo (Ptr p, const Address &address) +int TcpSocketImpl::DoSendTo (Ptr p, const Address &address) { NS_LOG_FUNCTION (this << p << address); InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); @@ -406,7 +406,7 @@ int TcpSocket::DoSendTo (Ptr p, const Address &address) return DoSendTo (p, ipv4, port); } -int TcpSocket::DoSendTo (Ptr p, Ipv4Address ipv4, uint16_t port) +int TcpSocketImpl::DoSendTo (Ptr p, Ipv4Address ipv4, uint16_t port) { NS_LOG_FUNCTION (this << p << ipv4 << port); if (m_endPoint == 0) @@ -430,7 +430,7 @@ int TcpSocket::DoSendTo (Ptr p, Ipv4Address ipv4, uint16_t port) } int -TcpSocket::SendTo (Ptr p, const Address &address) +TcpSocketImpl::SendTo (Ptr p, const Address &address) { NS_LOG_FUNCTION (this << address << p); if (!m_connected) @@ -445,7 +445,7 @@ TcpSocket::SendTo (Ptr p, const Address &address) } uint32_t -TcpSocket::GetTxAvailable (void) const +TcpSocketImpl::GetTxAvailable (void) const { NS_LOG_FUNCTION_NOARGS (); if (m_pendingData != 0) @@ -462,7 +462,7 @@ TcpSocket::GetTxAvailable (void) const } int -TcpSocket::Listen (uint32_t q) +TcpSocketImpl::Listen (uint32_t q) { NS_LOG_FUNCTION (this << q); Actions_t action = ProcessEvent (APP_LISTEN); @@ -471,7 +471,7 @@ TcpSocket::Listen (uint32_t q) } Ptr -TcpSocket::Recv (uint32_t maxSize, uint32_t flags) +TcpSocketImpl::Recv (uint32_t maxSize, uint32_t flags) { NS_LOG_FUNCTION_NOARGS (); if (m_deliveryQueue.empty() ) @@ -492,7 +492,7 @@ TcpSocket::Recv (uint32_t maxSize, uint32_t flags) } uint32_t -TcpSocket::GetRxAvailable (void) const +TcpSocketImpl::GetRxAvailable (void) const { NS_LOG_FUNCTION_NOARGS (); // We separately maintain this state to avoid walking the queue @@ -501,35 +501,35 @@ TcpSocket::GetRxAvailable (void) const } void -TcpSocket::SetSndBuf (uint32_t size) +TcpSocketImpl::SetSndBuf (uint32_t size) { NS_LOG_FUNCTION_NOARGS (); m_sndBufLimit = size; } uint32_t -TcpSocket::GetSndBuf (void) const +TcpSocketImpl::GetSndBuf (void) const { NS_LOG_FUNCTION_NOARGS (); return m_sndBufLimit; } void -TcpSocket::SetRcvBuf (uint32_t size) +TcpSocketImpl::SetRcvBuf (uint32_t size) { NS_LOG_FUNCTION_NOARGS (); m_rcvBufLimit = size; } uint32_t -TcpSocket::GetRcvBuf (void) const +TcpSocketImpl::GetRcvBuf (void) const { NS_LOG_FUNCTION_NOARGS (); return m_rcvBufLimit; } void -TcpSocket::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) +TcpSocketImpl::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) { NS_LOG_DEBUG("Socket " << this << " got forward up" << " dport " << m_endPoint->GetLocalPort() << @@ -563,26 +563,26 @@ TcpSocket::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) ProcessPacketAction (action, packet, tcpHeader, address); } -Actions_t TcpSocket::ProcessEvent (Events_t e) +Actions_t TcpSocketImpl::ProcessEvent (Events_t e) { NS_LOG_FUNCTION (this << e); States_t saveState = m_state; - NS_LOG_LOGIC ("TcpSocket " << this << " processing event " << e); + NS_LOG_LOGIC ("TcpSocketImpl " << this << " processing event " << e); // simulation singleton is a way to get a single global static instance of a // class intended to be a singleton; see simulation-singleton.h SA stateAction = SimulationSingleton::Get ()->Lookup (m_state,e); // debug if (stateAction.action == RST_TX) { - NS_LOG_LOGIC ("TcpSocket " << this << " sending RST from state " + NS_LOG_LOGIC ("TcpSocketImpl " << this << " sending RST from state " << saveState << " event " << e); } bool needCloseNotify = (stateAction.state == CLOSED && m_state != CLOSED && e != TIMEOUT); m_state = stateAction.state; - NS_LOG_LOGIC ("TcpSocket " << this << " moved from state " << saveState + NS_LOG_LOGIC ("TcpSocketImpl " << this << " moved from state " << saveState << " to state " <SetPeer (m_remoteAddress, m_remotePort); - NS_LOG_LOGIC ("TcpSocket " << this << " Connected!"); + NS_LOG_LOGIC ("TcpSocketImpl " << this << " Connected!"); } if (needCloseNotify && !m_closeNotified) { - NS_LOG_LOGIC ("TcpSocket " << this << " transition to CLOSED from " + NS_LOG_LOGIC ("TcpSocketImpl " << this << " transition to CLOSED from " << m_state << " event " << e << " closeNot " << m_closeNotified << " action " << stateAction.action); NotifyCloseCompleted (); m_closeNotified = true; - NS_LOG_LOGIC ("TcpSocket " << this << " calling Closed from PE" + NS_LOG_LOGIC ("TcpSocketImpl " << this << " calling Closed from PE" << " origState " << saveState << " event " << e); - NS_LOG_LOGIC ("TcpSocket " << this << " transition to CLOSED from " + NS_LOG_LOGIC ("TcpSocketImpl " << this << " transition to CLOSED from " << m_state << " event " << e << " set CloseNotif "); } return stateAction.action; } -void TcpSocket::SendEmptyPacket (uint8_t flags) +void TcpSocketImpl::SendEmptyPacket (uint8_t flags) { NS_LOG_FUNCTION (this << flags); Ptr p = Create (); @@ -640,17 +640,17 @@ void TcpSocket::SendEmptyPacket (uint8_t flags) NS_LOG_LOGIC ("Schedule retransmission timeout at time " << Simulator::Now ().GetSeconds () << " to expire at time " << (Simulator::Now () + rto).GetSeconds ()); - m_retxEvent = Simulator::Schedule (rto, &TcpSocket::ReTxTimeout, this); + m_retxEvent = Simulator::Schedule (rto, &TcpSocketImpl::ReTxTimeout, this); } } -bool TcpSocket::ProcessAction (Actions_t a) +bool TcpSocketImpl::ProcessAction (Actions_t a) { // These actions do not require a packet or any TCP Headers NS_LOG_FUNCTION (this << a); switch (a) { case NO_ACT: - NS_LOG_LOGIC ("TcpSocket " << this <<" Action: NO_ACT"); + NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action: NO_ACT"); break; case ACK_TX: SendEmptyPacket (TcpHeader::ACK); @@ -659,11 +659,11 @@ bool TcpSocket::ProcessAction (Actions_t a) NS_ASSERT (false); // This should be processed in ProcessPacketAction break; case RST_TX: - NS_LOG_LOGIC ("TcpSocket " << this <<" Action RST_TX"); + NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action RST_TX"); SendEmptyPacket (TcpHeader::RST); break; case SYN_TX: - NS_LOG_LOGIC ("TcpSocket " << this <<" Action SYN_TX"); + NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SYN_TX"); // TCP SYN Flag consumes one byte // is the above correct? we're SENDING a syn, not acking back -- Raj // commented out for now @@ -671,17 +671,17 @@ bool TcpSocket::ProcessAction (Actions_t a) SendEmptyPacket (TcpHeader::SYN); break; case SYN_ACK_TX: - NS_LOG_LOGIC ("TcpSocket " << this <<" Action SYN_ACK_TX"); + NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SYN_ACK_TX"); // TCP SYN Flag consumes one byte ++m_nextRxSequence; SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK); break; case FIN_TX: - NS_LOG_LOGIC ("TcpSocket " << this <<" Action FIN_TX"); + NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action FIN_TX"); SendEmptyPacket (TcpHeader::FIN); break; case FIN_ACK_TX: - NS_LOG_LOGIC ("TcpSocket " << this <<" Action FIN_ACK_TX"); + NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action FIN_ACK_TX"); SendEmptyPacket (TcpHeader::FIN | TcpHeader::ACK); break; case NEW_ACK: @@ -691,36 +691,36 @@ bool TcpSocket::ProcessAction (Actions_t a) NS_ASSERT (false); // This should be processed in ProcessPacketAction break; case RETX: - NS_LOG_LOGIC ("TcpSocket " << this <<" Action RETX"); + NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action RETX"); break; case TX_DATA: - NS_LOG_LOGIC ("TcpSocket " << this <<" Action TX_DATA"); + NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action TX_DATA"); SendPendingData (); break; case PEER_CLOSE: NS_ASSERT (false); // This should be processed in ProcessPacketAction - NS_LOG_LOGIC ("TcpSocket " << this <<" Action PEER_CLOSE"); + NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action PEER_CLOSE"); break; case APP_CLOSED: - NS_LOG_LOGIC ("TcpSocket " << this <<" Action APP_CLOSED"); + NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action APP_CLOSED"); break; case CANCEL_TM: - NS_LOG_LOGIC ("TcpSocket " << this <<" Action CANCEL_TM"); + NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action CANCEL_TM"); break; case APP_NOTIFY: - NS_LOG_LOGIC ("TcpSocket " << this <<" Action APP_NOTIFY"); + NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action APP_NOTIFY"); break; case SERV_NOTIFY: NS_ASSERT (false); // This should be processed in ProcessPacketAction break; case LAST_ACTION: - NS_LOG_LOGIC ("TcpSocket " << this <<" Action LAST_ACTION"); + NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action LAST_ACTION"); break; } return true; } -bool TcpSocket::ProcessPacketAction (Actions_t a, Ptr p, +bool TcpSocketImpl::ProcessPacketAction (Actions_t a, Ptr p, const TcpHeader& tcpHeader, const Address& fromAddress) { @@ -730,24 +730,24 @@ bool TcpSocket::ProcessPacketAction (Actions_t a, Ptr p, switch (a) { case SYN_ACK_TX: - NS_LOG_LOGIC ("TcpSocket " << this <<" Action SYN_ACK_TX"); + NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SYN_ACK_TX"); // m_remotePort = InetSocketAddress::ConvertFrom (fromAddress).GetPort (); // m_remoteAddress = InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (); // if (ipv4->GetIfIndexForDestination (m_remoteAddress, localIfIndex)) // { // m_localAddress = ipv4->GetAddress (localIfIndex); // } - if (m_state == LISTEN) //this means we should fork a new TcpSocket + if (m_state == LISTEN) //this means we should fork a new TcpSocketImpl { NS_LOG_DEBUG("In SYN_ACK_TX, m_state is LISTEN, this " << this); //notify the server that we got a SYN // If server refuses connection do nothing if (!NotifyConnectionRequest(fromAddress)) return true; // Clone the socket - Ptr newSock = Copy (); - NS_LOG_LOGIC ("Cloned a TcpSocket " << newSock); + Ptr newSock = Copy (); + NS_LOG_LOGIC ("Cloned a TcpSocketImpl " << newSock); //this listening socket should do nothing more - Simulator::ScheduleNow (&TcpSocket::CompleteFork, newSock, + Simulator::ScheduleNow (&TcpSocketImpl::CompleteFork, newSock, p, tcpHeader,fromAddress); return true; } @@ -766,12 +766,12 @@ bool TcpSocket::ProcessPacketAction (Actions_t a, Ptr p, SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK); break; case ACK_TX_1: - NS_LOG_LOGIC ("TcpSocket " << this <<" Action ACK_TX_1"); + NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action ACK_TX_1"); // TCP SYN consumes one byte m_nextRxSequence = tcpHeader.GetSequenceNumber() + SequenceNumber(1); m_nextTxSequence = tcpHeader.GetAckNumber (); m_firstPendingSequence = m_nextTxSequence; //bug 166 - NS_LOG_DEBUG ("TcpSocket " << this << " ACK_TX_1" << + NS_LOG_DEBUG ("TcpSocketImpl " << this << " ACK_TX_1" << " nextRxSeq " << m_nextRxSequence); SendEmptyPacket (TcpHeader::ACK); m_rxWindowSize = tcpHeader.GetWindowSize (); @@ -788,7 +788,7 @@ bool TcpSocket::ProcessPacketAction (Actions_t a, Ptr p, SendPendingData (); break; case NEW_ACK: - NS_LOG_LOGIC ("TcpSocket " << this <<" Action NEW_ACK_TX"); + NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action NEW_ACK_TX"); if (tcpHeader.GetAckNumber () < m_highestRxAck) //old ack, do nothing { break; @@ -806,7 +806,7 @@ bool TcpSocket::ProcessPacketAction (Actions_t a, Ptr p, NewAck (tcpHeader.GetAckNumber ()); break; case NEW_SEQ_RX: - NS_LOG_LOGIC ("TcpSocket " << this <<" Action NEW_SEQ_RX"); + NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action NEW_SEQ_RX"); NewRx (p, tcpHeader, fromAddress); // Process new data received break; case PEER_CLOSE: @@ -817,7 +817,7 @@ bool TcpSocket::ProcessPacketAction (Actions_t a, Ptr p, if (tcpHeader.GetSequenceNumber () != m_nextRxSequence) { // process close later m_pendingClose = true; - NS_LOG_LOGIC ("TcpSocket " << this << " setting pendingClose" + NS_LOG_LOGIC ("TcpSocketImpl " << this << " setting pendingClose" << " rxseq " << tcpHeader.GetSequenceNumber () << " nextRxSeq " << m_nextRxSequence); NewRx (p, tcpHeader, fromAddress); @@ -830,7 +830,7 @@ bool TcpSocket::ProcessPacketAction (Actions_t a, Ptr p, NewRx (p, tcpHeader, fromAddress); } States_t saveState = m_state; // Used to see if app responds - NS_LOG_LOGIC ("TcpSocket " << this + NS_LOG_LOGIC ("TcpSocketImpl " << this << " peer close, state " << m_state); if (!m_closeRequestNotified) { @@ -839,7 +839,7 @@ bool TcpSocket::ProcessPacketAction (Actions_t a, Ptr p, NotifyCloseRequested(); m_closeRequestNotified = true; } - NS_LOG_LOGIC ("TcpSocket " << this + NS_LOG_LOGIC ("TcpSocketImpl " << this << " peer close, state after " << m_state); if (m_state == saveState) { // Need to ack, the application will close later @@ -848,15 +848,15 @@ bool TcpSocket::ProcessPacketAction (Actions_t a, Ptr p, } if (m_state == LAST_ACK) { - NS_LOG_LOGIC ("TcpSocket " << this << " scheduling LATO1"); + NS_LOG_LOGIC ("TcpSocketImpl " << this << " scheduling LATO1"); m_lastAckEvent = Simulator::Schedule (m_rtt->RetransmitTimeout (), - &TcpSocket::LastAckTimeout,this); + &TcpSocketImpl::LastAckTimeout,this); } break; } case SERV_NOTIFY: - NS_LOG_LOGIC ("TcpSocket " << this <<" Action SERV_NOTIFY"); - NS_LOG_LOGIC ("TcpSocket " << this << " Connected!"); + NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SERV_NOTIFY"); + NS_LOG_LOGIC ("TcpSocketImpl " << this << " Connected!"); NotifyNewConnectionCreated (this, fromAddress); m_connected = true; // ! This is bogus; fix when we clone the tcp m_endPoint->SetPeer (m_remoteAddress, m_remotePort); @@ -869,7 +869,7 @@ bool TcpSocket::ProcessPacketAction (Actions_t a, Ptr p, return true; } -void TcpSocket::CompleteFork(Ptr p, const TcpHeader& h, const Address& fromAddress) +void TcpSocketImpl::CompleteFork(Ptr p, const TcpHeader& h, const Address& fromAddress) { // Get port and address from peer (connecting host) m_remotePort = InetSocketAddress::ConvertFrom (fromAddress).GetPort (); @@ -881,19 +881,19 @@ void TcpSocket::CompleteFork(Ptr p, const TcpHeader& h, const Address& f //the cloned socket with be in listen state, so manually change state m_state = SYN_RCVD; //equivalent to FinishBind - m_endPoint->SetRxCallback (MakeCallback (&TcpSocket::ForwardUp, Ptr(this))); - m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocket::Destroy, Ptr(this))); + m_endPoint->SetRxCallback (MakeCallback (&TcpSocketImpl::ForwardUp, Ptr(this))); + m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocketImpl::Destroy, Ptr(this))); ProcessPacketAction(SYN_ACK_TX, p, h, fromAddress); } -void TcpSocket::ConnectionSucceeded() +void TcpSocketImpl::ConnectionSucceeded() { // We would preferred to have scheduled an event directly to // NotifyConnectionSucceeded, but (sigh) these are protected // and we can get the address of it :( NotifyConnectionSucceeded(); } -bool TcpSocket::SendPendingData (bool withAck) +bool TcpSocketImpl::SendPendingData (bool withAck) { NS_LOG_FUNCTION (this << withAck); NS_LOG_LOGIC ("ENTERING SendPendingData"); @@ -905,7 +905,7 @@ bool TcpSocket::SendPendingData (bool withAck) while (m_pendingData->SizeFromSeq (m_firstPendingSequence, m_nextTxSequence)) { uint32_t w = AvailableWindow ();// Get available window size - NS_LOG_LOGIC ("TcpSocket " << this << " SendPendingData" + NS_LOG_LOGIC ("TcpSocketImpl " << this << " SendPendingData" << " w " << w << " rxwin " << m_rxWindowSize << " cWnd " << m_cWnd @@ -922,7 +922,7 @@ bool TcpSocket::SendPendingData (bool withAck) uint32_t s = std::min (w, m_segmentSize); // Send no more than window Ptr p = m_pendingData->CopyFromSeq (s, m_firstPendingSequence, m_nextTxSequence); - NS_LOG_LOGIC("TcpSocket " << this << " sendPendingData" + NS_LOG_LOGIC("TcpSocketImpl " << this << " sendPendingData" << " txseq " << m_nextTxSequence << " s " << s << " datasize " << p->GetSize() ); @@ -960,7 +960,7 @@ bool TcpSocket::SendPendingData (bool withAck) NS_LOG_LOGIC ("Schedule retransmission timeout at time " << Simulator::Now ().GetSeconds () << " to expire at time " << (Simulator::Now () + rto).GetSeconds () ); - m_retxEvent = Simulator::Schedule (rto,&TcpSocket::ReTxTimeout,this); + m_retxEvent = Simulator::Schedule (rto,&TcpSocketImpl::ReTxTimeout,this); } NS_LOG_LOGIC ("About to send a packet with flags: " << flags); m_tcp->SendPacket (p, header, @@ -968,7 +968,7 @@ bool TcpSocket::SendPendingData (bool withAck) m_remoteAddress); m_rtt->SentSeq(m_nextTxSequence, sz); // notify the RTT // Notify the application - Simulator::ScheduleNow(&TcpSocket::NotifyDataSent, this, p->GetSize ()); + Simulator::ScheduleNow(&TcpSocketImpl::NotifyDataSent, this, p->GetSize ()); nPacketsSent++; // Count sent this loop m_nextTxSequence += sz; // Advance next tx sequence // Note the high water mark @@ -979,26 +979,26 @@ bool TcpSocket::SendPendingData (bool withAck) return (nPacketsSent>0); } -uint32_t TcpSocket::UnAckDataCount () +uint32_t TcpSocketImpl::UnAckDataCount () { NS_LOG_FUNCTION_NOARGS (); return m_nextTxSequence - m_highestRxAck; } -uint32_t TcpSocket::BytesInFlight () +uint32_t TcpSocketImpl::BytesInFlight () { NS_LOG_FUNCTION_NOARGS (); return m_highTxMark - m_highestRxAck; } -uint32_t TcpSocket::Window () +uint32_t TcpSocketImpl::Window () { NS_LOG_FUNCTION_NOARGS (); - NS_LOG_LOGIC ("TcpSocket::Window() "< p, +void TcpSocketImpl::NewRx (Ptr p, const TcpHeader& tcpHeader, const Address& fromAddress) { NS_LOG_FUNCTION (this << p << "tcpHeader " << fromAddress); - NS_LOG_LOGIC ("TcpSocket " << this << " NewRx," + NS_LOG_LOGIC ("TcpSocketImpl " << this << " NewRx," << " seq " << tcpHeader.GetSequenceNumber() << " ack " << tcpHeader.GetAckNumber() << " p.size is " << p->GetSize () ); - NS_LOG_DEBUG ("TcpSocket " << this << + NS_LOG_DEBUG ("TcpSocketImpl " << this << " NewRx," << " seq " << tcpHeader.GetSequenceNumber() << " ack " << tcpHeader.GetAckNumber() << @@ -1055,7 +1055,7 @@ void TcpSocket::NewRx (Ptr p, { NS_LOG_LOGIC ("Tcp " << this << " HuH? Got data after closeNotif"); } - NS_LOG_LOGIC ("TcpSocket " << this << " adv rxseq by " << s); + NS_LOG_LOGIC ("TcpSocketImpl " << this << " adv rxseq by " << s); // Look for buffered data UnAckData_t::iterator i; // Note that the bufferedData list DOES contain the tcp header @@ -1109,11 +1109,11 @@ void TcpSocket::NewRx (Ptr p, m_rxAvailable += p->GetSize (); NotifyDataRecv (); - NS_LOG_LOGIC ("TcpSocket " << this << " adv rxseq1 by " << s1 ); + NS_LOG_LOGIC ("TcpSocketImpl " << this << " adv rxseq1 by " << s1 ); m_nextRxSequence += s1; // Note data received m_bufferedData.erase (i); // Remove from list if (flags & TcpHeader::FIN) - NS_LOG_LOGIC("TcpSocket " << this + NS_LOG_LOGIC("TcpSocketImpl " << this << " found FIN in buffered"); } @@ -1153,17 +1153,17 @@ void TcpSocket::NewRx (Ptr p, } else { - m_delAckEvent = Simulator::Schedule (m_delAckTimout, &TcpSocket::DelAckTimeout, this); + m_delAckEvent = Simulator::Schedule (m_delAckTimout, &TcpSocketImpl::DelAckTimeout, this); } } -void TcpSocket::DelAckTimeout () +void TcpSocketImpl::DelAckTimeout () { m_delAckCount = 0; SendEmptyPacket (TcpHeader::ACK); } -void TcpSocket::CommonNewAck (SequenceNumber ack, bool skipTimer) +void TcpSocketImpl::CommonNewAck (SequenceNumber ack, bool skipTimer) { // CommonNewAck is called only for "New" (non-duplicate) acks // and MUST be called by any subclass, from the NewAck function // Always cancel any pending re-tx timer on new acknowledgement @@ -1177,7 +1177,7 @@ void TcpSocket::CommonNewAck (SequenceNumber ack, bool skipTimer) NS_LOG_LOGIC ("Schedule retransmission timeout at time " << Simulator::Now ().GetSeconds () << " to expire at time " << (Simulator::Now () + rto).GetSeconds ()); - m_retxEvent = Simulator::Schedule (rto, &TcpSocket::ReTxTimeout, this); + m_retxEvent = Simulator::Schedule (rto, &TcpSocketImpl::ReTxTimeout, this); } NS_LOG_LOGIC ("TCP " << this << " NewAck " << ack << " numberAck " << (ack - m_highestRxAck)); // Number bytes ack'ed @@ -1209,23 +1209,23 @@ void TcpSocket::CommonNewAck (SequenceNumber ack, bool skipTimer) SendPendingData(); } -Ptr TcpSocket::Copy () +Ptr TcpSocketImpl::Copy () { - return CopyObject (this); + return CopyObject (this); } -void TcpSocket::NewAck (SequenceNumber seq) +void TcpSocketImpl::NewAck (SequenceNumber seq) { // New acknowledgement up to sequence number "seq" // Adjust congestion window in response to new ack's received NS_LOG_FUNCTION (this << seq); - NS_LOG_LOGIC ("TcpSocket " << this << " NewAck " + NS_LOG_LOGIC ("TcpSocketImpl " << this << " NewAck " << " seq " << seq << " cWnd " << m_cWnd << " ssThresh " << m_ssThresh); if (m_cWnd < m_ssThresh) { // Slow start mode, add one segSize to cWnd m_cWnd += m_segmentSize; - NS_LOG_LOGIC ("TcpSocket " << this << " NewCWnd SlowStart, cWnd " << m_cWnd + NS_LOG_LOGIC ("TcpSocketImpl " << this << " NewCWnd SlowStart, cWnd " << m_cWnd << " sst " << m_ssThresh); } else @@ -1242,17 +1242,17 @@ void TcpSocket::NewAck (SequenceNumber seq) CommonNewAck (seq, false); // Complete newAck processing } -void TcpSocket::DupAck (const TcpHeader& t, uint32_t count) +void TcpSocketImpl::DupAck (const TcpHeader& t, uint32_t count) { NS_LOG_FUNCTION (this << "t " << count); - NS_LOG_LOGIC ("TcpSocket " << this << " DupAck " << t.GetAckNumber () + NS_LOG_LOGIC ("TcpSocketImpl " << this << " DupAck " << t.GetAckNumber () << ", count " << count << ", time " << Simulator::Now ()); if (count == 3) { // Count of three indicates triple duplicate ack m_ssThresh = Window () / 2; // Per RFC2581 m_ssThresh = std::max (m_ssThresh, 2 * m_segmentSize); - NS_LOG_LOGIC("TcpSocket " << this << "Tahoe TDA, time " << Simulator::Now () + NS_LOG_LOGIC("TcpSocketImpl " << this << "Tahoe TDA, time " << Simulator::Now () << " seq " << t.GetAckNumber () << " in flight " << BytesInFlight () << " new ssthresh " << m_ssThresh); @@ -1264,7 +1264,7 @@ void TcpSocket::DupAck (const TcpHeader& t, uint32_t count) } } -void TcpSocket::ReTxTimeout () +void TcpSocketImpl::ReTxTimeout () { // Retransmit timeout NS_LOG_FUNCTION (this); m_ssThresh = Window () / 2; // Per RFC2581 @@ -1277,7 +1277,7 @@ void TcpSocket::ReTxTimeout () Retransmit (); // Retransmit the packet } -void TcpSocket::LastAckTimeout () +void TcpSocketImpl::LastAckTimeout () { m_lastAckEvent.Cancel (); if (m_state == LAST_ACK) @@ -1291,7 +1291,7 @@ void TcpSocket::LastAckTimeout () } } -void TcpSocket::Retransmit () +void TcpSocketImpl::Retransmit () { NS_LOG_FUNCTION (this); uint8_t flags = TcpHeader::NONE; @@ -1328,14 +1328,14 @@ void TcpSocket::Retransmit () flags = flags | TcpHeader::FIN; } - NS_LOG_LOGIC ("TcpSocket " << this << " retxing seq " << m_highestRxAck); + NS_LOG_LOGIC ("TcpSocketImpl " << this << " retxing seq " << m_highestRxAck); if (m_retxEvent.IsExpired () ) { Time rto = m_rtt->RetransmitTimeout (); NS_LOG_LOGIC ("Schedule retransmission timeout at time " << Simulator::Now ().GetSeconds () << " to expire at time " << (Simulator::Now () + rto).GetSeconds ()); - m_retxEvent = Simulator::Schedule (rto,&TcpSocket::ReTxTimeout,this); + m_retxEvent = Simulator::Schedule (rto,&TcpSocketImpl::ReTxTimeout,this); } m_rtt->SentSeq (m_highestRxAck,p->GetSize ()); // And send the packet diff --git a/src/internet-node/tcp-socket.h b/src/internet-node/tcp-socket-impl.h similarity index 96% rename from src/internet-node/tcp-socket.h rename to src/internet-node/tcp-socket-impl.h index 023d3029d..e2f9d75f6 100644 --- a/src/internet-node/tcp-socket.h +++ b/src/internet-node/tcp-socket-impl.h @@ -17,8 +17,8 @@ * * Author: Raj Bhattacharjea */ -#ifndef TCP_SOCKET_H -#define TCP_SOCKET_H +#ifndef TCP_SOCKET_IMPL_H +#define TCP_SOCKET_IMPL_H #include #include @@ -42,16 +42,16 @@ class Packet; class TcpL4Protocol; class TcpHeader; -class TcpSocket : public Socket +class TcpSocketImpl : public Socket { public: static TypeId GetTypeId (void); /** * Create an unbound tcp socket. */ - TcpSocket (); - TcpSocket (const TcpSocket& sock); - virtual ~TcpSocket (); + TcpSocketImpl (); + TcpSocketImpl (const TcpSocketImpl& sock); + virtual ~TcpSocketImpl (); void SetNode (Ptr node); void SetTcp (Ptr tcp); @@ -110,7 +110,7 @@ private: // Manage data tx/rx void NewRx (Ptr, const TcpHeader&, const Address&); // XXX This should be virtual and overridden - Ptr Copy (); + Ptr Copy (); void NewAck (SequenceNumber seq); // XXX This should be virtual and overridden void DupAck (const TcpHeader& t, uint32_t count); @@ -194,4 +194,4 @@ private: }//namespace ns3 -#endif /* TCP_SOCKET_H */ +#endif /* TCP_SOCKET_IMPL_H */ diff --git a/src/internet-node/wscript b/src/internet-node/wscript index 7b05bdaf0..26c5d6a64 100644 --- a/src/internet-node/wscript +++ b/src/internet-node/wscript @@ -23,7 +23,7 @@ def build(bld): 'arp-l3-protocol.cc', 'ipv4-loopback-interface.cc', 'udp-socket-impl.cc', - 'tcp-socket.cc', + 'tcp-socket-impl.cc', 'ipv4-end-point-demux.cc', 'ipv4-impl.cc', 'ascii-trace.cc', From 8dc24604163de88a1e671cf31be73677402de14b Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Tue, 20 May 2008 12:16:55 -0700 Subject: [PATCH 31/45] move Tcp to TcpSocketFactory --- examples/tcp-large-transfer.cc | 6 +-- src/helper/packet-sink-helper.cc | 2 +- src/internet-node/tcp-header.h | 2 +- src/internet-node/tcp-impl.cc | 2 +- src/internet-node/tcp-impl.h | 4 +- src/internet-node/tcp-socket-impl.cc | 2 +- src/node/{tcp.cc => tcp-socket-factory.cc} | 48 +++++++++++----------- src/node/{tcp.h => tcp-socket-factory.h} | 13 +++--- src/node/wscript | 4 +- utils/print-introspected-doxygen.cc | 2 +- 10 files changed, 43 insertions(+), 42 deletions(-) rename src/node/{tcp.cc => tcp-socket-factory.cc} (70%) rename src/node/{tcp.h => tcp-socket-factory.h} (89%) diff --git a/examples/tcp-large-transfer.cc b/examples/tcp-large-transfer.cc index ee7d831b0..610ad0714 100644 --- a/examples/tcp-large-transfer.cc +++ b/examples/tcp-large-transfer.cc @@ -169,15 +169,15 @@ int main (int argc, char *argv[]) uint16_t servPort = 50000; // Create a packet sink to receive these packets - PacketSinkHelper sink ("ns3::Tcp", + PacketSinkHelper sink ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), servPort)); ApplicationContainer apps = sink.Install (c1.Get (1)); apps.Start (Seconds (0.0)); // and generate traffic to remote sink. - //TypeId tid = TypeId::LookupByName ("ns3::Tcp"); - Ptr localSocket = Socket::CreateSocket (c0.Get (0), Tcp::GetTypeId ()); + //TypeId tid = TypeId::LookupByName ("ns3::TcpSocketFactory"); + Ptr localSocket = Socket::CreateSocket (c0.Get (0), TcpSocketFactory::GetTypeId ()); localSocket->Bind (); Simulator::ScheduleNow (&StartFlow, localSocket, nBytes, ipInterfs.GetAddress (1), servPort); diff --git a/src/helper/packet-sink-helper.cc b/src/helper/packet-sink-helper.cc index e7cc76f72..ef2704114 100644 --- a/src/helper/packet-sink-helper.cc +++ b/src/helper/packet-sink-helper.cc @@ -47,7 +47,7 @@ PacketSinkHelper::SetUdpLocal (Ipv4Address ip, uint16_t port) void PacketSinkHelper::SetTcpLocal (Ipv4Address ip, uint16_t port) { - m_factory.Set ("Protocol", String ("ns3::Tcp")); + m_factory.Set ("Protocol", String ("ns3::TcpSocketFactory")); m_factory.Set ("Local", Address (InetSocketAddress (ip, port))); } #endif diff --git a/src/internet-node/tcp-header.h b/src/internet-node/tcp-header.h index 3181b03be..e676287f6 100644 --- a/src/internet-node/tcp-header.h +++ b/src/internet-node/tcp-header.h @@ -24,7 +24,7 @@ #include #include "ns3/header.h" #include "ns3/buffer.h" -#include "ns3/tcp.h" +#include "ns3/tcp-socket-factory.h" #include "ns3/ipv4-address.h" #include "ns3/sequence-number.h" diff --git a/src/internet-node/tcp-impl.cc b/src/internet-node/tcp-impl.cc index 5a1ad3954..dc6d69f17 100644 --- a/src/internet-node/tcp-impl.cc +++ b/src/internet-node/tcp-impl.cc @@ -48,7 +48,7 @@ void TcpImpl::DoDispose (void) { m_tcp = 0; - Tcp::DoDispose (); + TcpSocketFactory::DoDispose (); } } // namespace ns3 diff --git a/src/internet-node/tcp-impl.h b/src/internet-node/tcp-impl.h index 1b69a1d13..647dd6372 100644 --- a/src/internet-node/tcp-impl.h +++ b/src/internet-node/tcp-impl.h @@ -20,7 +20,7 @@ #ifndef TCP_IMPL_H #define TCP_IMPL_H -#include "ns3/tcp.h" +#include "ns3/tcp-socket-factory.h" #include "ns3/ptr.h" namespace ns3 { @@ -39,7 +39,7 @@ class TcpL4Protocol; * * Most of the logic is in class ns3::TcpSocketImpl. */ -class TcpImpl : public Tcp +class TcpImpl : public TcpSocketFactory { public: TcpImpl (); diff --git a/src/internet-node/tcp-socket-impl.cc b/src/internet-node/tcp-socket-impl.cc index 12686e376..5edc19109 100644 --- a/src/internet-node/tcp-socket-impl.cc +++ b/src/internet-node/tcp-socket-impl.cc @@ -176,7 +176,7 @@ void TcpSocketImpl::SetNode (Ptr node) { m_node = node; - Ptr t = node->GetObject (); + Ptr t = node->GetObject (); m_segmentSize = t->GetDefaultSegSize (); m_rxWindowSize = t->GetDefaultAdvWin (); m_advertisedWindowSize = t->GetDefaultAdvWin (); diff --git a/src/node/tcp.cc b/src/node/tcp-socket-factory.cc similarity index 70% rename from src/node/tcp.cc rename to src/node/tcp-socket-factory.cc index 77e02362f..40d1caa66 100644 --- a/src/node/tcp.cc +++ b/src/node/tcp-socket-factory.cc @@ -17,122 +17,122 @@ * * Author: Raj Bhattacharjea */ -#include "tcp.h" +#include "tcp-socket-factory.h" #include "ns3/uinteger.h" #include "ns3/double.h" namespace ns3 { -NS_OBJECT_ENSURE_REGISTERED (Tcp); +NS_OBJECT_ENSURE_REGISTERED (TcpSocketFactory); TypeId -Tcp::GetTypeId (void) +TcpSocketFactory::GetTypeId (void) { - static TypeId tid = TypeId ("ns3::Tcp") + static TypeId tid = TypeId ("ns3::TcpSocketFactory") .SetParent () .AddAttribute ("DefaultSegmentSize", "Default TCP maximum segment size in bytes (may be adjusted based on MTU discovery)", UintegerValue (536), - MakeUintegerAccessor (&Tcp::m_defaultSegSize), + MakeUintegerAccessor (&TcpSocketFactory::m_defaultSegSize), MakeUintegerChecker ()) .AddAttribute ("DefaultAdvertisedWindowSize", "Default TCP advertised window size (bytes)", UintegerValue (0xffff), - MakeUintegerAccessor (&Tcp::m_defaultAdvWin), + MakeUintegerAccessor (&TcpSocketFactory::m_defaultAdvWin), MakeUintegerChecker ()) .AddAttribute ("DefaultSlowStartThreshold", "Default TCP slow start threshold (bytes)", UintegerValue (0xffff), - MakeUintegerAccessor (&Tcp::m_defaultSsThresh), + MakeUintegerAccessor (&TcpSocketFactory::m_defaultSsThresh), MakeUintegerChecker ()) .AddAttribute ("DefaultTxBufferSize", "Default TCP maximum transmit buffer size (bytes)", UintegerValue (0xffffffffl), - MakeUintegerAccessor (&Tcp::m_defaultTxBuffer), + MakeUintegerAccessor (&TcpSocketFactory::m_defaultTxBuffer), MakeUintegerChecker ()) .AddAttribute ("DefaultRxBufferSize", "Default TCP maximum receive buffer size (bytes)", UintegerValue (0xffffffffl), - MakeUintegerAccessor (&Tcp::m_defaultRxBuffer), + MakeUintegerAccessor (&TcpSocketFactory::m_defaultRxBuffer), MakeUintegerChecker ()) .AddAttribute ("DefaultInitialCongestionWindowSize", "Default TCP initial congestion window size (segments)", UintegerValue (1), - MakeUintegerAccessor (&Tcp::m_defaultInitialCwnd), + MakeUintegerAccessor (&TcpSocketFactory::m_defaultInitialCwnd), MakeUintegerChecker ()) .AddAttribute ("DefaultConnTimeout", "Default TCP retransmission timeout when opening connection (seconds)", UintegerValue (3), - MakeUintegerAccessor (&Tcp::m_defaultConnTimeout), + MakeUintegerAccessor (&TcpSocketFactory::m_defaultConnTimeout), MakeUintegerChecker ()) .AddAttribute ("DefaultConnCount", "Default number of connection attempts (SYN retransmissions) before returning failure", UintegerValue (6), - MakeUintegerAccessor (&Tcp::m_defaultConnCount), + MakeUintegerAccessor (&TcpSocketFactory::m_defaultConnCount), MakeUintegerChecker ()) .AddAttribute ("DefaultDelAckTimeout", "Default timeout value for TCP delayed acks, in seconds", DoubleValue (0.2), - MakeDoubleAccessor (&Tcp::m_defaultDelAckTimeout), + MakeDoubleAccessor (&TcpSocketFactory::m_defaultDelAckTimeout), MakeDoubleChecker ()) .AddAttribute ("DefaultDelAckCount", "Default number of packets to wait before sending a TCP ack", UintegerValue (2), - MakeUintegerAccessor (&Tcp::m_defaultDelAckCount), + MakeUintegerAccessor (&TcpSocketFactory::m_defaultDelAckCount), MakeUintegerChecker ()) ; return tid; } uint32_t -Tcp::GetDefaultSegSize (void) const +TcpSocketFactory::GetDefaultSegSize (void) const { return m_defaultSegSize; } uint32_t -Tcp::GetDefaultAdvWin (void) const +TcpSocketFactory::GetDefaultAdvWin (void) const { return m_defaultAdvWin; } uint32_t -Tcp::GetDefaultSsThresh (void) const +TcpSocketFactory::GetDefaultSsThresh (void) const { return m_defaultSsThresh; } uint32_t -Tcp::GetDefaultTxBuffer (void) const +TcpSocketFactory::GetDefaultTxBuffer (void) const { return m_defaultTxBuffer; } uint32_t -Tcp::GetDefaultRxBuffer (void) const +TcpSocketFactory::GetDefaultRxBuffer (void) const { return m_defaultRxBuffer; } uint32_t -Tcp::GetDefaultInitialCwnd (void) const +TcpSocketFactory::GetDefaultInitialCwnd (void) const { return m_defaultInitialCwnd; } uint32_t -Tcp::GetDefaultConnTimeout (void) const +TcpSocketFactory::GetDefaultConnTimeout (void) const { return m_defaultConnTimeout; } uint32_t -Tcp::GetDefaultConnCount (void) const +TcpSocketFactory::GetDefaultConnCount (void) const { return m_defaultConnCount; } double -Tcp::GetDefaultDelAckTimeout (void) const +TcpSocketFactory::GetDefaultDelAckTimeout (void) const { return m_defaultDelAckTimeout; } uint32_t -Tcp::GetDefaultDelAckCount (void) const +TcpSocketFactory::GetDefaultDelAckCount (void) const { return m_defaultDelAckCount; } diff --git a/src/node/tcp.h b/src/node/tcp-socket-factory.h similarity index 89% rename from src/node/tcp.h rename to src/node/tcp-socket-factory.h index 91923cb62..9d98eafff 100644 --- a/src/node/tcp.h +++ b/src/node/tcp-socket-factory.h @@ -17,8 +17,8 @@ * * Author: Raj Bhattacharjea */ -#ifndef TCP_H -#define TCP_H +#ifndef TCP_SOCKET_FACTORY_H +#define TCP_SOCKET_FACTORY_H #include "socket-factory.h" @@ -34,13 +34,14 @@ class Socket; * initialize newly created sockets, such as values that are * set through the sysctl or proc interfaces in Linux. - * All TCP implementations must provide an implementation of CreateSocket + * All TCP socket factory implementations must provide an implementation + * of CreateSocket * below, and should make use of the default values configured below. * - * \see TcpImpl + * \see TcpSocketFactoryImpl * */ -class Tcp : public SocketFactory +class TcpSocketFactory : public SocketFactory { public: static TypeId GetTypeId (void); @@ -74,4 +75,4 @@ private: } // namespace ns3 -#endif /* TCP_H */ +#endif /* TCP_SOCKET_FACTORY_H */ diff --git a/src/node/wscript b/src/node/wscript index 3f35ca216..6d0974263 100644 --- a/src/node/wscript +++ b/src/node/wscript @@ -27,7 +27,7 @@ def build(bld): 'packet-socket.cc', 'udp-socket.cc', 'udp-socket-factory.cc', - 'tcp.cc', + 'tcp-socket-factory.cc', 'ipv4.cc', 'application.cc', 'simple-channel.cc', @@ -60,7 +60,7 @@ def build(bld): 'packet-socket-factory.h', 'udp-socket.h', 'udp-socket-factory.h', - 'tcp.h', + 'tcp-socket-factory.h', 'ipv4.h', 'application.h', 'simple-channel.h', diff --git a/utils/print-introspected-doxygen.cc b/utils/print-introspected-doxygen.cc index c714d5ee7..24f8b944f 100644 --- a/utils/print-introspected-doxygen.cc +++ b/utils/print-introspected-doxygen.cc @@ -236,7 +236,7 @@ int main (int argc, char *argv[]) NodeContainer c; c.Create (1); StaticInformation info; - info.RecordAggregationInfo ("ns3::Node", "ns3::Tcp"); + info.RecordAggregationInfo ("ns3::Node", "ns3::TcpSocketFactory"); info.RecordAggregationInfo ("ns3::Node", "ns3::UdpSocketFactory"); info.RecordAggregationInfo ("ns3::Node", "ns3::PacketSocketFactory"); info.RecordAggregationInfo ("ns3::Node", "ns3::olsr::Agent"); From c21d79a87b6fab8ef438973d3b03e30ac95a794f Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Tue, 20 May 2008 12:27:30 -0700 Subject: [PATCH 32/45] change TcpImpl to TcpSocketFactoryImpl --- src/internet-node/internet-stack.cc | 8 ++++---- .../{tcp-impl.cc => tcp-socket-factory-impl.cc} | 12 ++++++------ .../{tcp-impl.h => tcp-socket-factory-impl.h} | 12 ++++++------ src/internet-node/wscript | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) rename src/internet-node/{tcp-impl.cc => tcp-socket-factory-impl.cc} (80%) rename src/internet-node/{tcp-impl.h => tcp-socket-factory-impl.h} (86%) diff --git a/src/internet-node/internet-stack.cc b/src/internet-node/internet-stack.cc index 8aaab0509..5b8f3bfd1 100644 --- a/src/internet-node/internet-stack.cc +++ b/src/internet-node/internet-stack.cc @@ -28,7 +28,7 @@ #include "ipv4-l3-protocol.h" #include "arp-l3-protocol.h" #include "udp-socket-factory-impl.h" -#include "tcp-impl.h" +#include "tcp-socket-factory-impl.h" #include "ipv4-impl.h" namespace ns3 { @@ -59,18 +59,18 @@ AddInternetStack (Ptr node) ipv4L4Demux->Insert (tcp); Ptr udpFactory = CreateObject (); - Ptr tcpImpl = CreateObject (); + Ptr tcpFactory = CreateObject (); Ptr ipv4Impl = CreateObject (); udpFactory->SetUdp (udp); - tcpImpl->SetTcp (tcp); + tcpFactory->SetTcp (tcp); ipv4Impl->SetIpv4 (ipv4); node->AggregateObject (ipv4); node->AggregateObject (arp); node->AggregateObject (ipv4Impl); node->AggregateObject (udpFactory); - node->AggregateObject (tcpImpl); + node->AggregateObject (tcpFactory); node->AggregateObject (ipv4L4Demux); } diff --git a/src/internet-node/tcp-impl.cc b/src/internet-node/tcp-socket-factory-impl.cc similarity index 80% rename from src/internet-node/tcp-impl.cc rename to src/internet-node/tcp-socket-factory-impl.cc index dc6d69f17..ef806adf4 100644 --- a/src/internet-node/tcp-impl.cc +++ b/src/internet-node/tcp-socket-factory-impl.cc @@ -17,35 +17,35 @@ * * Author: Raj Bhattacharjea */ -#include "tcp-impl.h" +#include "tcp-socket-factory-impl.h" #include "tcp-l4-protocol.h" #include "ns3/socket.h" #include "ns3/assert.h" namespace ns3 { -TcpImpl::TcpImpl () +TcpSocketFactoryImpl::TcpSocketFactoryImpl () : m_tcp (0) {} -TcpImpl::~TcpImpl () +TcpSocketFactoryImpl::~TcpSocketFactoryImpl () { NS_ASSERT (m_tcp == 0); } void -TcpImpl::SetTcp (Ptr tcp) +TcpSocketFactoryImpl::SetTcp (Ptr tcp) { m_tcp = tcp; } Ptr -TcpImpl::CreateSocket (void) +TcpSocketFactoryImpl::CreateSocket (void) { return m_tcp->CreateSocket (); } void -TcpImpl::DoDispose (void) +TcpSocketFactoryImpl::DoDispose (void) { m_tcp = 0; TcpSocketFactory::DoDispose (); diff --git a/src/internet-node/tcp-impl.h b/src/internet-node/tcp-socket-factory-impl.h similarity index 86% rename from src/internet-node/tcp-impl.h rename to src/internet-node/tcp-socket-factory-impl.h index 647dd6372..38bf123a2 100644 --- a/src/internet-node/tcp-impl.h +++ b/src/internet-node/tcp-socket-factory-impl.h @@ -17,8 +17,8 @@ * * Author: Raj Bhattacharjea */ -#ifndef TCP_IMPL_H -#define TCP_IMPL_H +#ifndef TCP_SOCKET_FACTORY_IMPL_H +#define TCP_SOCKET_FACTORY_IMPL_H #include "ns3/tcp-socket-factory.h" #include "ns3/ptr.h" @@ -39,11 +39,11 @@ class TcpL4Protocol; * * Most of the logic is in class ns3::TcpSocketImpl. */ -class TcpImpl : public TcpSocketFactory +class TcpSocketFactoryImpl : public TcpSocketFactory { public: - TcpImpl (); - virtual ~TcpImpl (); + TcpSocketFactoryImpl (); + virtual ~TcpSocketFactoryImpl (); void SetTcp (Ptr tcp); @@ -57,4 +57,4 @@ private: } // namespace ns3 -#endif /* TCP_IMPL_H */ +#endif /* TCP_SOCKET_FACTORY_IMPL_H */ diff --git a/src/internet-node/wscript b/src/internet-node/wscript index 26c5d6a64..20f69c7b2 100644 --- a/src/internet-node/wscript +++ b/src/internet-node/wscript @@ -29,7 +29,7 @@ def build(bld): 'ascii-trace.cc', 'pcap-trace.cc', 'udp-socket-factory-impl.cc', - 'tcp-impl.cc', + 'tcp-socket-factory-impl.cc', 'pending-data.cc', 'sequence-number.cc', 'rtt-estimator.cc', From 49d5404bfcc494140e29380a689a23e2008d36ed Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Tue, 20 May 2008 12:36:05 -0700 Subject: [PATCH 33/45] Add abstract base class TcpSocket --- src/internet-node/tcp-socket-impl.cc | 2 +- src/internet-node/tcp-socket-impl.h | 4 ++-- src/node/wscript | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/internet-node/tcp-socket-impl.cc b/src/internet-node/tcp-socket-impl.cc index 5edc19109..26ad2dc0a 100644 --- a/src/internet-node/tcp-socket-impl.cc +++ b/src/internet-node/tcp-socket-impl.cc @@ -90,7 +90,7 @@ TcpSocketImpl::GetTypeId () } TcpSocketImpl::TcpSocketImpl(const TcpSocketImpl& sock) - : Socket(sock), //copy the base class callbacks + : TcpSocket(sock), //copy the base class callbacks m_skipRetxResched (sock.m_skipRetxResched), m_dupAckCount (sock.m_dupAckCount), m_delAckCount (0), diff --git a/src/internet-node/tcp-socket-impl.h b/src/internet-node/tcp-socket-impl.h index e2f9d75f6..0171f2e6d 100644 --- a/src/internet-node/tcp-socket-impl.h +++ b/src/internet-node/tcp-socket-impl.h @@ -24,7 +24,7 @@ #include #include "ns3/callback.h" #include "ns3/traced-value.h" -#include "ns3/socket.h" +#include "ns3/tcp-socket.h" #include "ns3/ptr.h" #include "ns3/ipv4-address.h" #include "ns3/event-id.h" @@ -42,7 +42,7 @@ class Packet; class TcpL4Protocol; class TcpHeader; -class TcpSocketImpl : public Socket +class TcpSocketImpl : public TcpSocket { public: static TypeId GetTypeId (void); diff --git a/src/node/wscript b/src/node/wscript index 6d0974263..2f91f1e2a 100644 --- a/src/node/wscript +++ b/src/node/wscript @@ -27,6 +27,7 @@ def build(bld): 'packet-socket.cc', 'udp-socket.cc', 'udp-socket-factory.cc', + 'tcp-socket.cc', 'tcp-socket-factory.cc', 'ipv4.cc', 'application.cc', @@ -60,6 +61,7 @@ def build(bld): 'packet-socket-factory.h', 'udp-socket.h', 'udp-socket-factory.h', + 'tcp-socket.h', 'tcp-socket-factory.h', 'ipv4.h', 'application.h', From ef99300effe286f17f82d781cd5b19187b60f6e2 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Tue, 20 May 2008 12:55:23 -0700 Subject: [PATCH 34/45] Add missing files --- src/node/tcp-socket.cc | 72 +++++++++++++++++++++++++++++++++++++ src/node/tcp-socket.h | 81 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 src/node/tcp-socket.cc create mode 100644 src/node/tcp-socket.h diff --git a/src/node/tcp-socket.cc b/src/node/tcp-socket.cc new file mode 100644 index 000000000..3d3a83d67 --- /dev/null +++ b/src/node/tcp-socket.cc @@ -0,0 +1,72 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Mathieu Lacage + */ + +#include "ns3/object.h" +#include "ns3/log.h" +#include "ns3/uinteger.h" +#include "ns3/trace-source-accessor.h" +#include "tcp-socket.h" + +NS_LOG_COMPONENT_DEFINE ("TcpSocket"); + +namespace ns3 { + +NS_OBJECT_ENSURE_REGISTERED (TcpSocket); + +TypeId +TcpSocket::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::TcpSocket") + .SetParent () +#if 0 + .AddAttribute ("RcvBufSize", + "TcpSocket maximum receive buffer size (bytes)", + UintegerValue (0xffffffffl), + MakeUintegerAccessor (&TcpSocket::GetRcvBufSize, + &TcpSocket::SetRcvBufSize), + MakeUintegerChecker ()) + .AddAttribute ("IpTtl", + "socket-specific TTL for unicast IP packets (if non-zero)", + UintegerValue (0), + MakeUintegerAccessor (&TcpSocket::GetIpTtl, + &TcpSocket::SetIpTtl), + MakeUintegerChecker ()) + .AddAttribute ("IpMulticastTtl", + "socket-specific TTL for multicast IP packets (if non-zero)", + UintegerValue (0), + MakeUintegerAccessor (&TcpSocket::GetIpMulticastTtl, + &TcpSocket::SetIpMulticastTtl), + MakeUintegerChecker ()) +#endif + ; + return tid; +} + +TcpSocket::TcpSocket () +{ + NS_LOG_FUNCTION_NOARGS (); +} + +TcpSocket::~TcpSocket () +{ + NS_LOG_FUNCTION_NOARGS (); +} + +}; // namespace ns3 diff --git a/src/node/tcp-socket.h b/src/node/tcp-socket.h new file mode 100644 index 000000000..bc48ebf93 --- /dev/null +++ b/src/node/tcp-socket.h @@ -0,0 +1,81 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2006 Georgia Tech Research Corporation + * 2007 INRIA + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: George F. Riley + * Mathieu Lacage + */ + +#ifndef __TCP_SOCKET_H__ +#define __TCP_SOCKET_H__ + +#include "socket.h" +#include "ns3/traced-callback.h" +#include "ns3/callback.h" +#include "ns3/ptr.h" +#include "ns3/object.h" + +namespace ns3 { + +class Node; +class Packet; + +/** + * \brief (abstract) base class of all TcpSockets + * + * This class exists solely for hosting TcpSocket attributes that can + * be reused across different implementations. + */ +class TcpSocket : public Socket +{ +public: + static TypeId GetTypeId (void); + + TcpSocket (void); + virtual ~TcpSocket (void); + + virtual enum Socket::SocketErrno GetErrno (void) const = 0; + virtual Ptr GetNode (void) const = 0; + virtual int Bind () = 0; + virtual int Close (void) = 0; + virtual int ShutdownSend (void) = 0; + virtual int ShutdownRecv (void) = 0; + virtual int Connect (const Address &address) = 0; + virtual int Send (Ptr p) = 0; + virtual uint32_t GetTxAvailable (void) const = 0; + virtual int SendTo (Ptr p, const Address &address) = 0; + virtual Ptr Recv (uint32_t maxSize, uint32_t flags) = 0; + virtual uint32_t GetRxAvailable (void) const = 0; + +public: +#if 0 + // Indirect the attribute setting and getting through private virtual methods + virtual void SetRcvBufSize (uint32_t size) = 0; + virtual uint32_t GetRcvBufSize (void) const = 0; + virtual void SetIpTtl (uint32_t ipTtl) = 0; + virtual uint32_t GetIpTtl (void) const = 0; + virtual void SetIpMulticastTtl (uint32_t ipTtl) = 0; + virtual uint32_t GetIpMulticastTtl (void) const = 0; +#endif + +}; + +} //namespace ns3 + +#endif /* TCP_SOCKET_H */ + + From 72d054a8675305dd5106ec0bfc15b60e8747d2d0 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Wed, 21 May 2008 00:38:49 -0700 Subject: [PATCH 35/45] Move Tcp attributes from factory to TcpSocket --- src/internet-node/tcp-socket-impl.cc | 181 +++++++++++++++++++-------- src/internet-node/tcp-socket-impl.h | 36 ++++-- src/internet-node/udp-socket-impl.h | 2 +- src/node/tcp-socket-factory.cc | 105 +--------------- src/node/tcp-socket-factory.h | 23 ---- src/node/tcp-socket.cc | 66 ++++++++-- src/node/tcp-socket.h | 27 ++-- src/node/udp-socket.h | 2 +- 8 files changed, 234 insertions(+), 208 deletions(-) diff --git a/src/internet-node/tcp-socket-impl.cc b/src/internet-node/tcp-socket-impl.cc index 26ad2dc0a..57c0e0d09 100644 --- a/src/internet-node/tcp-socket-impl.cc +++ b/src/internet-node/tcp-socket-impl.cc @@ -48,7 +48,7 @@ TypeId TcpSocketImpl::GetTypeId () { static TypeId tid = TypeId("ns3::TcpSocketImpl") - .SetParent () + .SetParent () .AddTraceSource ("CongestionWindow", "The TCP connection's congestion window", MakeTraceSourceAccessor (&TcpSocketImpl::m_cWnd)) @@ -81,12 +81,9 @@ TcpSocketImpl::GetTypeId () m_rtt (0), m_lastMeasuredRtt (Seconds(0.0)), m_rxAvailable (0), - m_sndBufLimit (0xffffffff), - m_rcvBufLimit (0xffffffff), m_wouldBlock (false) { NS_LOG_FUNCTION (this); - } TcpSocketImpl::TcpSocketImpl(const TcpSocketImpl& sock) @@ -95,7 +92,7 @@ TcpSocketImpl::TcpSocketImpl(const TcpSocketImpl& sock) m_dupAckCount (sock.m_dupAckCount), m_delAckCount (0), m_delAckMaxCount (sock.m_delAckMaxCount), - m_delAckTimout (sock.m_delAckTimout), + m_delAckTimeout (sock.m_delAckTimeout), m_endPoint (0), m_node (sock.m_node), m_tcp (sock.m_tcp), @@ -128,9 +125,7 @@ TcpSocketImpl::TcpSocketImpl(const TcpSocketImpl& sock) m_lastMeasuredRtt (Seconds(0.0)), m_cnTimeout (sock.m_cnTimeout), m_cnCount (sock.m_cnCount), - m_rxAvailable (0), - m_sndBufLimit (0xffffffff), - m_rcvBufLimit (0xffffffff) + m_rxAvailable (0) { NS_LOG_FUNCTION_NOARGS (); NS_LOG_LOGIC("Invoked the copy constructor"); @@ -176,17 +171,9 @@ void TcpSocketImpl::SetNode (Ptr node) { m_node = node; - Ptr t = node->GetObject (); - m_segmentSize = t->GetDefaultSegSize (); - m_rxWindowSize = t->GetDefaultAdvWin (); - m_advertisedWindowSize = t->GetDefaultAdvWin (); - m_cWnd = t->GetDefaultInitialCwnd () * m_segmentSize; - m_ssThresh = t->GetDefaultSsThresh (); - m_initialCWnd = t->GetDefaultInitialCwnd (); - m_cnTimeout = Seconds (t->GetDefaultConnTimeout ()); - m_cnCount = t->GetDefaultConnCount (); - m_delAckTimout = Seconds(t->GetDefaultDelAckTimeout ()); - m_delAckMaxCount = t->GetDefaultDelAckCount (); + // Initialize some variables + m_cWnd = m_initialCWnd * m_segmentSize; + m_rxWindowSize = m_advertisedWindowSize; } void @@ -452,12 +439,12 @@ TcpSocketImpl::GetTxAvailable (void) const { uint32_t unAckedDataSize = m_pendingData->SizeFromSeq (m_firstPendingSequence, m_highestRxAck); - NS_ASSERT (m_sndBufLimit >= unAckedDataSize); //else a logical error - return m_sndBufLimit-unAckedDataSize; + NS_ASSERT (m_sndBufSize >= unAckedDataSize); //else a logical error + return m_sndBufSize-unAckedDataSize; } else { - return m_sndBufLimit; + return m_sndBufSize; } } @@ -500,34 +487,6 @@ TcpSocketImpl::GetRxAvailable (void) const return m_rxAvailable; } -void -TcpSocketImpl::SetSndBuf (uint32_t size) -{ - NS_LOG_FUNCTION_NOARGS (); - m_sndBufLimit = size; -} - -uint32_t -TcpSocketImpl::GetSndBuf (void) const -{ - NS_LOG_FUNCTION_NOARGS (); - return m_sndBufLimit; -} - -void -TcpSocketImpl::SetRcvBuf (uint32_t size) -{ - NS_LOG_FUNCTION_NOARGS (); - m_rcvBufLimit = size; -} - -uint32_t -TcpSocketImpl::GetRcvBuf (void) const -{ - NS_LOG_FUNCTION_NOARGS (); - return m_rcvBufLimit; -} - void TcpSocketImpl::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) { @@ -1153,7 +1112,7 @@ void TcpSocketImpl::NewRx (Ptr p, } else { - m_delAckEvent = Simulator::Schedule (m_delAckTimout, &TcpSocketImpl::DelAckTimeout, this); + m_delAckEvent = Simulator::Schedule (m_delAckTimeout, &TcpSocketImpl::DelAckTimeout, this); } } @@ -1351,4 +1310,124 @@ void TcpSocketImpl::Retransmit () m_remoteAddress); } +void +TcpSocketImpl::SetSndBufSize (uint32_t size) +{ + m_sndBufSize = size; +} + +uint32_t +TcpSocketImpl::GetSndBufSize (void) const +{ + return m_sndBufSize; +} + +void +TcpSocketImpl::SetRcvBufSize (uint32_t size) +{ + m_rcvBufSize = size; +} + +uint32_t +TcpSocketImpl::GetRcvBufSize (void) const +{ + return m_rcvBufSize; +} + +void +TcpSocketImpl::SetSegSize (uint32_t size) +{ + m_segmentSize = size; +} + +uint32_t +TcpSocketImpl::GetSegSize (void) const +{ + return m_segmentSize; +} + +void +TcpSocketImpl::SetAdvWin (uint32_t window) +{ + m_advertisedWindowSize = window; +} + +uint32_t +TcpSocketImpl::GetAdvWin (void) const +{ + return m_advertisedWindowSize; +} + +void +TcpSocketImpl::SetSSThresh (uint32_t threshold) +{ + m_ssThresh = threshold; +} + +uint32_t +TcpSocketImpl::GetSSThresh (void) const +{ + return m_ssThresh; +} + +void +TcpSocketImpl::SetInitialCwnd (uint32_t cwnd) +{ + m_initialCWnd = cwnd; +} + +uint32_t +TcpSocketImpl::GetInitialCwnd (void) const +{ + return m_initialCWnd; +} + +void +TcpSocketImpl::SetConnTimeout (Time timeout) +{ + m_cnTimeout = timeout; +} + +Time +TcpSocketImpl::GetConnTimeout (void) const +{ + return m_cnTimeout; +} + +void +TcpSocketImpl::SetConnCount (uint32_t count) +{ + m_cnCount = count; +} + +uint32_t +TcpSocketImpl::GetConnCount (void) const +{ + return m_cnCount; +} + +void +TcpSocketImpl::SetDelAckTimeout (Time timeout) +{ + m_delAckTimeout = timeout; +} + +Time +TcpSocketImpl::GetDelAckTimeout (void) const +{ + return m_delAckTimeout; +} + +void +TcpSocketImpl::SetDelAckMaxCount (uint32_t count) +{ + m_delAckMaxCount = count; +} + +uint32_t +TcpSocketImpl::GetDelAckMaxCount (void) const +{ + return m_delAckMaxCount; +} + }//namespace ns3 diff --git a/src/internet-node/tcp-socket-impl.h b/src/internet-node/tcp-socket-impl.h index 0171f2e6d..7adc8669e 100644 --- a/src/internet-node/tcp-socket-impl.h +++ b/src/internet-node/tcp-socket-impl.h @@ -74,12 +74,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 Tcp; // invoked by Tcp class @@ -120,6 +114,28 @@ private: void Retransmit (); void CommonNewAck (SequenceNumber seq, bool skipTimer = false); + // attribute related + virtual void SetSndBufSize (uint32_t size); + virtual uint32_t GetSndBufSize (void) const; + virtual void SetRcvBufSize (uint32_t size); + virtual uint32_t GetRcvBufSize (void) const; + virtual void SetSegSize (uint32_t size); + virtual uint32_t GetSegSize (void) const; + virtual void SetAdvWin (uint32_t window); + virtual uint32_t GetAdvWin (void) const; + virtual void SetSSThresh (uint32_t threshold); + virtual uint32_t GetSSThresh (void) const; + virtual void SetInitialCwnd (uint32_t cwnd); + virtual uint32_t GetInitialCwnd (void) const; + virtual void SetConnTimeout (Time timeout); + virtual Time GetConnTimeout (void) const; + virtual void SetConnCount (uint32_t count); + virtual uint32_t GetConnCount (void) const; + virtual void SetDelAckTimeout (Time timeout); + virtual Time GetDelAckTimeout (void) const; + virtual void SetDelAckMaxCount (uint32_t count); + virtual uint32_t GetDelAckMaxCount (void) const; + bool m_skipRetxResched; uint32_t m_dupAckCount; EventId m_retxEvent; @@ -128,7 +144,7 @@ private: EventId m_delAckEvent; uint32_t m_delAckCount; uint32_t m_delAckMaxCount; - Time m_delAckTimout; + Time m_delAckTimeout; Ipv4EndPoint *m_endPoint; Ptr m_node; @@ -187,9 +203,11 @@ private: std::queue > m_deliveryQueue; uint32_t m_rxAvailable; - uint32_t m_sndBufLimit; // buffer limit for the outgoing queue - uint32_t m_rcvBufLimit; // maximum receive socket buffer size bool m_wouldBlock; // set to true whenever socket would block on send() + + // Attributes + uint32_t m_rcvBufSize; // maximum receive socket buffer size + uint32_t m_sndBufSize; // buffer limit for the outgoing queue }; }//namespace ns3 diff --git a/src/internet-node/udp-socket-impl.h b/src/internet-node/udp-socket-impl.h index 71bded586..42047a5d0 100644 --- a/src/internet-node/udp-socket-impl.h +++ b/src/internet-node/udp-socket-impl.h @@ -64,6 +64,7 @@ public: virtual Ptr Recv (uint32_t maxSize, uint32_t flags); virtual uint32_t GetRxAvailable (void) const; +private: // Attributes set through UdpSocket base class virtual void SetRcvBufSize (uint32_t size); virtual uint32_t GetRcvBufSize (void) const; @@ -72,7 +73,6 @@ public: virtual void SetIpMulticastTtl (uint32_t ipTtl); virtual uint32_t GetIpMulticastTtl (void) const; -private: friend class UdpSocketFactory; // invoked by Udp class int FinishBind (void); diff --git a/src/node/tcp-socket-factory.cc b/src/node/tcp-socket-factory.cc index 40d1caa66..ca1ae25b8 100644 --- a/src/node/tcp-socket-factory.cc +++ b/src/node/tcp-socket-factory.cc @@ -30,111 +30,8 @@ TcpSocketFactory::GetTypeId (void) { static TypeId tid = TypeId ("ns3::TcpSocketFactory") .SetParent () - .AddAttribute ("DefaultSegmentSize", - "Default TCP maximum segment size in bytes (may be adjusted based on MTU discovery)", - UintegerValue (536), - MakeUintegerAccessor (&TcpSocketFactory::m_defaultSegSize), - MakeUintegerChecker ()) - .AddAttribute ("DefaultAdvertisedWindowSize", - "Default TCP advertised window size (bytes)", - UintegerValue (0xffff), - MakeUintegerAccessor (&TcpSocketFactory::m_defaultAdvWin), - MakeUintegerChecker ()) - .AddAttribute ("DefaultSlowStartThreshold", - "Default TCP slow start threshold (bytes)", - UintegerValue (0xffff), - MakeUintegerAccessor (&TcpSocketFactory::m_defaultSsThresh), - MakeUintegerChecker ()) - .AddAttribute ("DefaultTxBufferSize", - "Default TCP maximum transmit buffer size (bytes)", - UintegerValue (0xffffffffl), - MakeUintegerAccessor (&TcpSocketFactory::m_defaultTxBuffer), - MakeUintegerChecker ()) - .AddAttribute ("DefaultRxBufferSize", - "Default TCP maximum receive buffer size (bytes)", - UintegerValue (0xffffffffl), - MakeUintegerAccessor (&TcpSocketFactory::m_defaultRxBuffer), - MakeUintegerChecker ()) - .AddAttribute ("DefaultInitialCongestionWindowSize", - "Default TCP initial congestion window size (segments)", - UintegerValue (1), - MakeUintegerAccessor (&TcpSocketFactory::m_defaultInitialCwnd), - MakeUintegerChecker ()) - .AddAttribute ("DefaultConnTimeout", - "Default TCP retransmission timeout when opening connection (seconds)", - UintegerValue (3), - MakeUintegerAccessor (&TcpSocketFactory::m_defaultConnTimeout), - MakeUintegerChecker ()) - .AddAttribute ("DefaultConnCount", - "Default number of connection attempts (SYN retransmissions) before returning failure", - UintegerValue (6), - MakeUintegerAccessor (&TcpSocketFactory::m_defaultConnCount), - MakeUintegerChecker ()) - .AddAttribute ("DefaultDelAckTimeout", - "Default timeout value for TCP delayed acks, in seconds", - DoubleValue (0.2), - MakeDoubleAccessor (&TcpSocketFactory::m_defaultDelAckTimeout), - MakeDoubleChecker ()) - .AddAttribute ("DefaultDelAckCount", - "Default number of packets to wait before sending a TCP ack", - UintegerValue (2), - MakeUintegerAccessor (&TcpSocketFactory::m_defaultDelAckCount), - MakeUintegerChecker ()) - ; + ; return tid; } -uint32_t -TcpSocketFactory::GetDefaultSegSize (void) const -{ - return m_defaultSegSize; -} -uint32_t -TcpSocketFactory::GetDefaultAdvWin (void) const -{ - return m_defaultAdvWin; -} -uint32_t -TcpSocketFactory::GetDefaultSsThresh (void) const -{ - return m_defaultSsThresh; -} -uint32_t -TcpSocketFactory::GetDefaultTxBuffer (void) const -{ - return m_defaultTxBuffer; -} -uint32_t -TcpSocketFactory::GetDefaultRxBuffer (void) const -{ - return m_defaultRxBuffer; -} -uint32_t -TcpSocketFactory::GetDefaultInitialCwnd (void) const -{ - return m_defaultInitialCwnd; -} -uint32_t -TcpSocketFactory::GetDefaultConnTimeout (void) const -{ - return m_defaultConnTimeout; -} -uint32_t -TcpSocketFactory::GetDefaultConnCount (void) const -{ - return m_defaultConnCount; -} - -double -TcpSocketFactory::GetDefaultDelAckTimeout (void) const -{ - return m_defaultDelAckTimeout; -} - -uint32_t -TcpSocketFactory::GetDefaultDelAckCount (void) const -{ - return m_defaultDelAckCount; -} - } // namespace ns3 diff --git a/src/node/tcp-socket-factory.h b/src/node/tcp-socket-factory.h index 9d98eafff..35909cb54 100644 --- a/src/node/tcp-socket-factory.h +++ b/src/node/tcp-socket-factory.h @@ -48,29 +48,6 @@ public: virtual Ptr CreateSocket (void) = 0; - uint32_t GetDefaultSegSize (void) const; - uint32_t GetDefaultAdvWin (void) const; - uint32_t GetDefaultSsThresh (void) const; - uint32_t GetDefaultTxBuffer (void) const; - uint32_t GetDefaultRxBuffer (void) const; - uint32_t GetDefaultInitialCwnd (void) const; - uint32_t GetDefaultConnTimeout (void) const; - uint32_t GetDefaultConnCount (void) const; - double GetDefaultDelAckTimeout (void) const; - uint32_t GetDefaultDelAckCount (void) const; - -private: - uint32_t m_defaultSegSize; - uint32_t m_defaultAdvWin; - uint32_t m_defaultSsThresh; - uint32_t m_defaultTxBuffer; - uint32_t m_defaultRxBuffer; - uint32_t m_defaultInitialCwnd; - uint32_t m_defaultConnTimeout; - uint32_t m_defaultConnCount; - double m_defaultDelAckTimeout; - uint32_t m_defaultDelAckCount; - }; } // namespace ns3 diff --git a/src/node/tcp-socket.cc b/src/node/tcp-socket.cc index 3d3a83d67..1dd3d4057 100644 --- a/src/node/tcp-socket.cc +++ b/src/node/tcp-socket.cc @@ -21,7 +21,9 @@ #include "ns3/object.h" #include "ns3/log.h" #include "ns3/uinteger.h" +#include "ns3/double.h" #include "ns3/trace-source-accessor.h" +#include "ns3/nstime.h" #include "tcp-socket.h" NS_LOG_COMPONENT_DEFINE ("TcpSocket"); @@ -35,26 +37,66 @@ TcpSocket::GetTypeId (void) { static TypeId tid = TypeId ("ns3::TcpSocket") .SetParent () -#if 0 + .AddAttribute ("SndBufSize", + "TcpSocket maximum transmit buffer size (bytes)", + UintegerValue (0xffffffffl), + MakeUintegerAccessor (&TcpSocket::GetSndBufSize, + &TcpSocket::SetSndBufSize), + MakeUintegerChecker ()) .AddAttribute ("RcvBufSize", "TcpSocket maximum receive buffer size (bytes)", UintegerValue (0xffffffffl), MakeUintegerAccessor (&TcpSocket::GetRcvBufSize, &TcpSocket::SetRcvBufSize), MakeUintegerChecker ()) - .AddAttribute ("IpTtl", - "socket-specific TTL for unicast IP packets (if non-zero)", - UintegerValue (0), - MakeUintegerAccessor (&TcpSocket::GetIpTtl, - &TcpSocket::SetIpTtl), + .AddAttribute ("SegmentSize", + "TCP maximum segment size in bytes (may be adjusted based on MTU discovery)", + UintegerValue (536), + MakeUintegerAccessor (&TcpSocket::GetSegSize, + &TcpSocket::SetSegSize), MakeUintegerChecker ()) - .AddAttribute ("IpMulticastTtl", - "socket-specific TTL for multicast IP packets (if non-zero)", - UintegerValue (0), - MakeUintegerAccessor (&TcpSocket::GetIpMulticastTtl, - &TcpSocket::SetIpMulticastTtl), + .AddAttribute ("AdvertisedWindowSize", + "TCP advertised window size (bytes)", + UintegerValue (0xffff), + MakeUintegerAccessor (&TcpSocket::GetAdvWin, + &TcpSocket::SetAdvWin), + MakeUintegerChecker ()) + .AddAttribute ("SlowStartThreshold", + "TCP slow start threshold (bytes)", + UintegerValue (0xffff), + MakeUintegerAccessor (&TcpSocket::GetSSThresh, + &TcpSocket::SetSSThresh), + MakeUintegerChecker ()) + .AddAttribute ("InitialCwnd", + "TCP initial congestion window size (segments)", + UintegerValue (1), + MakeUintegerAccessor (&TcpSocket::GetInitialCwnd, + &TcpSocket::SetInitialCwnd), + MakeUintegerChecker ()) + .AddAttribute ("ConnTimeout", + "TCP retransmission timeout when opening connection (seconds)", + TimeValue (Seconds (3)), + MakeTimeAccessor (&TcpSocket::GetConnTimeout, + &TcpSocket::SetConnTimeout), + MakeTimeChecker ()) + .AddAttribute ("ConnCount", + "Number of connection attempts (SYN retransmissions) before returning failure", + UintegerValue (6), + MakeUintegerAccessor (&TcpSocket::GetConnCount, + &TcpSocket::SetConnCount), + MakeUintegerChecker ()) + .AddAttribute ("DelAckTimeout", + "Timeout value for TCP delayed acks, in seconds", + TimeValue (Seconds (0.2)), + MakeTimeAccessor (&TcpSocket::GetDelAckTimeout, + &TcpSocket::SetDelAckTimeout), + MakeTimeChecker ()) + .AddAttribute ("DelAckCount", + "Number of packets to wait before sending a TCP ack", + UintegerValue (2), + MakeUintegerAccessor (&TcpSocket::GetDelAckMaxCount, + &TcpSocket::SetDelAckMaxCount), MakeUintegerChecker ()) -#endif ; return tid; } diff --git a/src/node/tcp-socket.h b/src/node/tcp-socket.h index bc48ebf93..9092474f4 100644 --- a/src/node/tcp-socket.h +++ b/src/node/tcp-socket.h @@ -28,6 +28,7 @@ #include "ns3/callback.h" #include "ns3/ptr.h" #include "ns3/object.h" +#include "ns3/nstime.h" namespace ns3 { @@ -61,16 +62,28 @@ public: virtual Ptr Recv (uint32_t maxSize, uint32_t flags) = 0; virtual uint32_t GetRxAvailable (void) const = 0; -public: -#if 0 +private: // Indirect the attribute setting and getting through private virtual methods + virtual void SetSndBufSize (uint32_t size) = 0; + virtual uint32_t GetSndBufSize (void) const = 0; virtual void SetRcvBufSize (uint32_t size) = 0; virtual uint32_t GetRcvBufSize (void) const = 0; - virtual void SetIpTtl (uint32_t ipTtl) = 0; - virtual uint32_t GetIpTtl (void) const = 0; - virtual void SetIpMulticastTtl (uint32_t ipTtl) = 0; - virtual uint32_t GetIpMulticastTtl (void) const = 0; -#endif + virtual void SetSegSize (uint32_t size) = 0; + virtual uint32_t GetSegSize (void) const = 0; + virtual void SetAdvWin (uint32_t window) = 0; + virtual uint32_t GetAdvWin (void) const = 0; + virtual void SetSSThresh (uint32_t threshold) = 0; + virtual uint32_t GetSSThresh (void) const = 0; + virtual void SetInitialCwnd (uint32_t count) = 0; + virtual uint32_t GetInitialCwnd (void) const = 0; + virtual void SetConnTimeout (Time timeout) = 0; + virtual Time GetConnTimeout (void) const = 0; + virtual void SetConnCount (uint32_t count) = 0; + virtual uint32_t GetConnCount (void) const = 0; + virtual void SetDelAckTimeout (Time timeout) = 0; + virtual Time GetDelAckTimeout (void) const = 0; + virtual void SetDelAckMaxCount (uint32_t count) = 0; + virtual uint32_t GetDelAckMaxCount (void) const = 0; }; diff --git a/src/node/udp-socket.h b/src/node/udp-socket.h index 5f20fd7c0..1c81916c2 100644 --- a/src/node/udp-socket.h +++ b/src/node/udp-socket.h @@ -61,7 +61,7 @@ public: virtual Ptr Recv (uint32_t maxSize, uint32_t flags) = 0; virtual uint32_t GetRxAvailable (void) const = 0; -public: +private: // Indirect the attribute setting and getting through private virtual methods virtual void SetRcvBufSize (uint32_t size) = 0; virtual uint32_t GetRcvBufSize (void) const = 0; From 5f94a4cf59829a17a486460ddeee43c83cc61e7d Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Wed, 21 May 2008 22:40:18 -0700 Subject: [PATCH 36/45] merge with ns-3-dev --- src/applications/packet-sink/packet-sink.cc | 4 +- src/applications/udp-echo/udp-echo-client.cc | 4 +- src/applications/udp-echo/udp-echo-server.cc | 4 +- src/internet-node/ipv4-l3-protocol.cc | 7 +- src/node/socket.cc | 143 +++++++++---------- src/node/socket.h | 26 ++-- src/routing/olsr/olsr-agent-impl.cc | 2 +- 7 files changed, 90 insertions(+), 100 deletions(-) diff --git a/src/applications/packet-sink/packet-sink.cc b/src/applications/packet-sink/packet-sink.cc index d71de1495..3f4a9f27e 100644 --- a/src/applications/packet-sink/packet-sink.cc +++ b/src/applications/packet-sink/packet-sink.cc @@ -106,10 +106,10 @@ void PacketSink::HandleRead (Ptr socket) while (packet = socket->Recv ()) { SocketRxAddressTag tag; - bool found = packet->PeekTag (tag); + bool found = packet->FindFirstMatchingTag (tag); NS_ASSERT (found); Address from = tag.GetAddress (); - packet->RemoveTag (tag); + // XXX packet->RemoveTag (tag); if (InetSocketAddress::IsMatchingType (from)) { InetSocketAddress address = InetSocketAddress::ConvertFrom (from); diff --git a/src/applications/udp-echo/udp-echo-client.cc b/src/applications/udp-echo/udp-echo-client.cc index 0d2713fca..787e2dcf7 100644 --- a/src/applications/udp-echo/udp-echo-client.cc +++ b/src/applications/udp-echo/udp-echo-client.cc @@ -153,10 +153,10 @@ UdpEchoClient::HandleRead (Ptr socket) while (packet = socket->Recv ()) { SocketRxAddressTag tag; - bool found = packet->PeekTag (tag); + bool found = packet->FindFirstMatchingTag (tag); NS_ASSERT (found); Address from = tag.GetAddress (); - packet->RemoveTag (tag); + // XXX packet->RemoveTag (tag); if (InetSocketAddress::IsMatchingType (from)) { InetSocketAddress address = InetSocketAddress::ConvertFrom (from); diff --git a/src/applications/udp-echo/udp-echo-server.cc b/src/applications/udp-echo/udp-echo-server.cc index 135b2800a..e2dab0bf8 100644 --- a/src/applications/udp-echo/udp-echo-server.cc +++ b/src/applications/udp-echo/udp-echo-server.cc @@ -98,10 +98,10 @@ UdpEchoServer::HandleRead (Ptr socket) while (packet = socket->Recv ()) { SocketRxAddressTag tag; - bool found = packet->PeekTag (tag); + bool found = packet->FindFirstMatchingTag (tag); NS_ASSERT (found); Address from = tag.GetAddress (); - packet->RemoveTag (tag); + // XXX packet->RemoveTag (tag); if (InetSocketAddress::IsMatchingType (from)) { InetSocketAddress address = InetSocketAddress::ConvertFrom (from); diff --git a/src/internet-node/ipv4-l3-protocol.cc b/src/internet-node/ipv4-l3-protocol.cc index 7be8959c9..f314be856 100644 --- a/src/internet-node/ipv4-l3-protocol.cc +++ b/src/internet-node/ipv4-l3-protocol.cc @@ -490,9 +490,7 @@ Ipv4L3Protocol::Send (Ptr packet, // Set TTL to 1 if it is a broadcast packet of any type. Otherwise, // possibly override the default TTL if the packet is tagged SocketIpTtlTag tag; - bool found = packet->PeekTag (tag); - uint8_t socketTtl = tag.GetTtl (); - packet->RemoveTag (tag); + bool found = packet->FindFirstMatchingTag (tag); if (destination.IsBroadcast ()) { @@ -500,7 +498,8 @@ Ipv4L3Protocol::Send (Ptr packet, } else if (found) { - ipHeader.SetTtl (socketTtl); + ipHeader.SetTtl (tag.GetTtl ()); + // XXX remove tag here? } else { diff --git a/src/node/socket.cc b/src/node/socket.cc index 566154b47..07ebaf401 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -30,19 +30,6 @@ 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 (); @@ -266,42 +253,14 @@ Socket::NotifyDataRecv (void) } } +/*************************************************************** + * Socket Tags + ***************************************************************/ + SocketRxAddressTag::SocketRxAddressTag () { } -uint32_t -SocketRxAddressTag::GetUid (void) -{ - static uint32_t uid = ns3::Tag::AllocateUid ("SocketRxAddressTag.ns3"); - return uid; -} - -void -SocketRxAddressTag::Print (std::ostream &os) const -{ - os << "address="<< m_address; -} - -uint32_t -SocketRxAddressTag::GetSerializedSize (void) const -{ - return 0; -} - -void -SocketRxAddressTag::Serialize (Buffer::Iterator i) const -{ - // for local use in stack only -} - -uint32_t -SocketRxAddressTag::Deserialize (Buffer::Iterator i) -{ - // for local use in stack only - return 0; -} - void SocketRxAddressTag::SetAddress (Address addr) { @@ -314,42 +273,41 @@ SocketRxAddressTag::GetAddress (void) const return m_address; } + +TypeId +SocketRxAddressTag::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::SocketRxAddressTag") + .SetParent () + .AddConstructor () + ; + return tid; +} +TypeId +SocketRxAddressTag::GetInstanceTypeId (void) const +{ + return GetTypeId (); +} +uint32_t +SocketRxAddressTag::GetSerializedSize (void) const +{ + return 0; +} +void +SocketRxAddressTag::Serialize (TagBuffer i) const +{ + // for local use in stack only +} +void +SocketRxAddressTag::Deserialize (TagBuffer i) +{ + // for local use in stack only +} + SocketIpTtlTag::SocketIpTtlTag () { } -uint32_t -SocketIpTtlTag::GetUid (void) -{ - static uint32_t uid = ns3::Tag::AllocateUid ("SocketIpTtlTag.ns3"); - return uid; -} - -void -SocketIpTtlTag::Print (std::ostream &os) const -{ - os << "ttl="<< m_ttl; -} - -uint32_t -SocketIpTtlTag::GetSerializedSize (void) const -{ - return 0; -} - -void -SocketIpTtlTag::Serialize (Buffer::Iterator i) const -{ - // for local use in stack only -} - -uint32_t -SocketIpTtlTag::Deserialize (Buffer::Iterator i) -{ - // for local use in stack only - return 0; -} - void SocketIpTtlTag::SetTtl (uint8_t ttl) { @@ -362,4 +320,35 @@ SocketIpTtlTag::GetTtl (void) const return m_ttl; } + +TypeId +SocketIpTtlTag::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::SocketIpTtlTag") + .SetParent () + .AddConstructor () + ; + return tid; +} +TypeId +SocketIpTtlTag::GetInstanceTypeId (void) const +{ + return GetTypeId (); +} +uint32_t +SocketIpTtlTag::GetSerializedSize (void) const +{ + return 0; +} +void +SocketIpTtlTag::Serialize (TagBuffer i) const +{ + // for local use in stack only +} +void +SocketIpTtlTag::Deserialize (TagBuffer i) +{ + // for local use in stack only +} + }//namespace ns3 diff --git a/src/node/socket.h b/src/node/socket.h index a500f3152..d0705762f 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -368,14 +368,15 @@ class SocketRxAddressTag : public Tag { public: SocketRxAddressTag (); - static uint32_t GetUid (void); - void Print (std::ostream &os) const; - uint32_t GetSerializedSize (void) const; - void Serialize (Buffer::Iterator i) const; - uint32_t Deserialize (Buffer::Iterator i); - void SetAddress (Address addr); Address GetAddress (void) const; + + static TypeId GetTypeId (void); + virtual TypeId GetInstanceTypeId (void) const; + virtual uint32_t GetSerializedSize (void) const; + virtual void Serialize (TagBuffer i) const; + virtual void Deserialize (TagBuffer i); + private: Address m_address; }; @@ -388,14 +389,15 @@ class SocketIpTtlTag : public Tag { public: SocketIpTtlTag (); - static uint32_t GetUid (void); - void Print (std::ostream &os) const; - uint32_t GetSerializedSize (void) const; - void Serialize (Buffer::Iterator i) const; - uint32_t Deserialize (Buffer::Iterator i); - void SetTtl (uint8_t ttl); uint8_t GetTtl (void) const; + + static TypeId GetTypeId (void); + virtual TypeId GetInstanceTypeId (void) const; + virtual uint32_t GetSerializedSize (void) const; + virtual void Serialize (TagBuffer i) const; + virtual void Deserialize (TagBuffer i); + private: uint8_t m_ttl; }; diff --git a/src/routing/olsr/olsr-agent-impl.cc b/src/routing/olsr/olsr-agent-impl.cc index 929a2b446..56d4e8c76 100644 --- a/src/routing/olsr/olsr-agent-impl.cc +++ b/src/routing/olsr/olsr-agent-impl.cc @@ -312,7 +312,7 @@ AgentImpl::RecvOlsr (Ptr socket) receivedPacket = socket->Recv (); SocketRxAddressTag tag; - bool found = receivedPacket->PeekTag (tag); + bool found = receivedPacket->FindFirstMatchingTag (tag); NS_ASSERT (found); Address sourceAddress = tag.GetAddress (); From ca7b76ef27281af14b2203d3db1632c9b99d2a0a Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Sun, 25 May 2008 08:04:57 -0700 Subject: [PATCH 37/45] Add tag serialize methods; add serialize routines to Address --- src/node/address.cc | 24 ++++++++++++++++++++++++ src/node/address.h | 21 +++++++++++++++++++++ src/node/socket.cc | 40 ++++++++++++++++++++++++++++------------ 3 files changed, 73 insertions(+), 12 deletions(-) diff --git a/src/node/address.cc b/src/node/address.cc index 3db5f1c8d..fb49bf8ce 100644 --- a/src/node/address.cc +++ b/src/node/address.cc @@ -107,6 +107,30 @@ Address::Register (void) return type; } +uint32_t +Address::GetSerializedSize (void) const +{ + return 1 + 1 + m_len; +} + +void +Address::Serialize (uint8_t* buf, uint32_t len) const +{ + NS_ASSERT (len >= static_cast (m_len + 2)); + buf[0] = m_type; + buf[1] = m_len; + for (uint8_t i = 0; i < m_len; i++) + { + buf[i+2] = m_data[i]; + } +} + +Address +Address::Deserialize (const uint8_t* buf) +{ + return Address (buf[0], buf + 2, buf[1]); +} + ATTRIBUTE_HELPER_CPP (Address); diff --git a/src/node/address.h b/src/node/address.h index e5b6c82e3..cf0d0d847 100644 --- a/src/node/address.h +++ b/src/node/address.h @@ -153,6 +153,27 @@ public: * \returns a new type id. */ static uint8_t Register (void); + /** + * Get the number of bytes needed to serialize the underlying Address + * Typically, this is GetLength () + 2 + * + * \returns the number of bytes required for an Address in serialized form + */ + uint32_t GetSerializedSize (void) const; + /** + * Serialize this address in host byte order to a byte buffer + * + * \param buf output buffer that gets written with this Address + * \param len length of output buffer + */ + void Serialize (uint8_t* buf, uint32_t len) const; + /** + * \param buf buffer to read address from + * \returns an Address + * + * The input address buffer is expected to be in host byte order format. + */ + static Address Deserialize (const uint8_t* buf); ATTRIBUTE_HELPER_HEADER_1 (Address); private: diff --git a/src/node/socket.cc b/src/node/socket.cc index 07ebaf401..768fdd170 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -288,20 +288,35 @@ SocketRxAddressTag::GetInstanceTypeId (void) const { return GetTypeId (); } -uint32_t +uint32_t SocketRxAddressTag::GetSerializedSize (void) const -{ - return 0; +{ + return m_address.GetSerializedSize (); } -void +void SocketRxAddressTag::Serialize (TagBuffer i) const -{ - // for local use in stack only +{ + uint8_t len = m_address.GetSerializedSize (); + uint8_t* buffer = new uint8_t[len]; + memset (buffer, 0, len); + m_address.Serialize (buffer, len); + i.Write (buffer, len); + delete [] buffer; } -void +void SocketRxAddressTag::Deserialize (TagBuffer i) -{ - // for local use in stack only +{ + uint8_t type = i.ReadU8 (); + uint8_t len = i.ReadU8 (); + // Len is the length of the address starting from buffer[2] + NS_ASSERT (len >= 2); + uint8_t* buffer = new uint8_t[len]; + memset (buffer, 0, len); + buffer[0] = type; + buffer[1] = len; + i.Read (buffer+2, len); // ReadU8 consumes a byte + m_address = Address::Deserialize (buffer); + delete [] buffer; } SocketIpTtlTag::SocketIpTtlTag () @@ -335,20 +350,21 @@ SocketIpTtlTag::GetInstanceTypeId (void) const { return GetTypeId (); } + uint32_t SocketIpTtlTag::GetSerializedSize (void) const { - return 0; + return 1; } void SocketIpTtlTag::Serialize (TagBuffer i) const { - // for local use in stack only + i.WriteU8 (m_ttl); } void SocketIpTtlTag::Deserialize (TagBuffer i) { - // for local use in stack only + m_ttl = i.ReadU8 (); } }//namespace ns3 From c2a543f5684e3a7070aa307b6b5664cc30fe2ee4 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Mon, 26 May 2008 11:07:41 -0700 Subject: [PATCH 38/45] Tutorial material for sockets --- doc/tutorial/Makefile | 2 +- doc/tutorial/figures/sockets-overview.dia | Bin 0 -> 2222 bytes doc/tutorial/sockets.texi | 243 ++++++++++++++++++++++ doc/tutorial/tutorial.texi | 4 +- 4 files changed, 247 insertions(+), 2 deletions(-) create mode 100644 doc/tutorial/figures/sockets-overview.dia create mode 100644 doc/tutorial/sockets.texi diff --git a/doc/tutorial/Makefile b/doc/tutorial/Makefile index b229ba74c..f0b2f4f8f 100644 --- a/doc/tutorial/Makefile +++ b/doc/tutorial/Makefile @@ -7,7 +7,7 @@ CONVERT = convert CSS = --css-include=tutorial.css SPLIT = --split section -DIA_SOURCES = buffer.dia pp.dia dumbbell.dia star.dia +DIA_SOURCES = buffer.dia pp.dia dumbbell.dia star.dia sockets-overview.dia TGIF_SOURCES = packet.obj helpers.obj DIA_EPS = ${DIA_SOURCES:.dia=.eps} diff --git a/doc/tutorial/figures/sockets-overview.dia b/doc/tutorial/figures/sockets-overview.dia new file mode 100644 index 0000000000000000000000000000000000000000..af9e583101c90073ef2605e47f9e0ae23a91af05 GIT binary patch literal 2222 zcmV;f2vPSRiwFP!000001MOYkZ{s!+e)nG?cwe@Fmli4Uht^Gsb`Qlp9NGfiJ_oYJ z*t(S^LsB;DKHT4aL&~XRTS^>Jbd!Px659&Hk3$V-z9EOy_dk4FXWmy?R%wx6jWP1a zp3E0TlIF{+@gJXm{vgIbT#vp_()c6%EX#Q9!GGkH`gS#5)%E7%bb5b(kFsqQ*F}l4 z^bS>W`oB2K;wcoGj;}|a_qc*2u48p=cQvl-GM(Sm(#zwuyc*Br#g}DS+~vu*DYYxN zD6*pTzQ)eAhH-cVS;wTSGfR>UCT$)BF?%`X*~Sf*?T%fzF_jhyF+e=68vP_ew2kt?Mj#}>1q+Z>8v(#Np?ORK=e@&}&p2@b>r+GbC z_1j^pKfXKKdhh?;P#c=sI^9DeB$f2#?qPYCCbD`)%?`_S)U?_an?Bd;$K}rLnC8-v zv(^wJPXEgk%Oqapdl;EJ;5qtPu=E?i-MxTm22bt8Ttf(ZsBZNA5#S??E%d!`F-PQ*jq~<3IFgFnt>iF z=9$Xb2k6j1J;7pq-wX)c|1w|8_PZ(byY;Ro&qQf8KV2qty0;!@n3JE1Z!OjYn_3f& zf=OW4m~cd>!kA%>z>a`D>1#)1Cf7HMqRdZ2jKM_G7@CTliuD%_@lkj%u80BF$w)p1 z69|XV<5xehYE|6dv;>~dv+5z#x5FC}Q~ec6xk40L)L+r)ub{ICegT+x{a)~wB9YG9 z+4gp)%IBP2e{1n`R@^UEaan6~QLfWG&RR@HU}`cVL@96-Zqw%hhJu)33LiLl3y!f( zpJyo3IZltFsB?G?@AMFZF7p`|7z;*2-qYr0X)d1=%t!dha9{&4HE8e3Q#;>1lwSgI zn`YS=5QlTee=ARTs;{)SI0oo2MBOt%uhj=T|7$(kBw$?`;(kE?VF4$$;DfugD@!*w ztD;Q*1a$(B`_yrBr52G#KI&j3S#HgCQme1(YBlnq=?^fzQ+hT+RfZ>YrOp9mHV#2e?X$!Qke( z7b+`|P^-BYp~ldrLVXJQfh~$Wzma*OTmLedIuy0P;Gi0d&2bajl7wxCrec856sztM z)+fFJgsZ3&;;IQyB@$4}5viG6XC;vx<&asO@(xjOm_x=~JnG_6H|6aZ*pb~6K+ZA3 z%tfFs0_{aAB4biP5D^z(6-2LV?|4Ns`*HzhVJw`Z7LHmtYT>BG+e_7p9Jg@X!iZa7 z^UbrN^7r=1MX342j$AO!G%i3cjD>UL!jTI{E*!adYve*Ln>%vh$VJbkb8Nhgo~oUo zpoZ8YsQ`>Xp{P7LLT3+<)UBR78`!FWZu#8i@;N30oaCdn@DQ7UNPq&)m`dXfC}lGR z$-)p~1TY(+?Zxy{0b3K_7&OQKTNcy1LX$kXiOaIM@8+b07*>6g$$a^AI6_S!o(*{D zu_=Aj?MRU9s z+~(?pK|K7$TY+LI4~)lNUFfADZ~xa8sFO+uVt2+nJPC$g7a`moCTwcp9tUGiXM`b6 zXf(kvP{|uOd97G{k@YBDZ!)PIyUrZ1M(-tBBJcC3-zK9!{`K3$E93j`938Yx2Rl^O zQ9`SZjt*dHLSKa1=TN(e*t>OT;sY&Iu$%}rgF;B(3Ei_@U5AjZiI!9q1OvzeM-bmW zLG1F-#(NhCQ3oJJD75OHiJp1UdaDjb-C+vhCSaV$ZB;?%ZmpUP;~flGg;5h``{Wjl zLQ%+o)HB37dPE}o+kj!rl_;poIG zrxRgg=qQS?qZ5u!y!hFa#v43{kHW^o6RS+(0VmK;YF2r}K2=K`{0$`;cuj6WDyz|Z z>}_P}Rn2t;Hd5d7B9Sib;4-;P?TYIX4{RnLkYE6N6R4yBb>E`M<}-0IeTZG)ZKl+P zsPthKyo9!Q%5+NEzA;=EW$GEqp-V*gr*1JLq4`r`L%sFO?o(l5bTF>=_eAhMix7md wL7+65Q{VP(%oYh-3+d*(hNF#}?^(Q+<@Kof0zb<#USE&?4|CyAxYdgQ0OMp;RR910 literal 0 HcmV?d00001 diff --git a/doc/tutorial/sockets.texi b/doc/tutorial/sockets.texi new file mode 100644 index 000000000..0c17cde02 --- /dev/null +++ b/doc/tutorial/sockets.texi @@ -0,0 +1,243 @@ +@node Sockets APIs +@chapter Sockets APIs + +The @uref{http://en.wikipedia.org/wiki/Berkeley_sockets,,sockets API} +is a long-standing API used by user-space applications to access +network services in the kernel. A ``socket'' is an abstraction, like +a Unix file handle, that allows applications to connect to other +Internet hosts and exchange reliable byte streams and unreliable +datagrams, among other services. + +ns-3 provides two types of sockets APIs, and it is important to +understand the differences between them. The first is a @emph{native} +ns-3 API, while the second uses the services of the native API to +provide a @uref{http://en.wikipedia.org/wiki/POSIX,,POSIX-like} +API as part of an overall application process. Both APIs strive +to be close to the typical sockets API that application writers +on Unix systems are accustomed to, but the POSIX variant is much +closer to a real system's sockets API. + +@section ns-3 sockets API + +The native sockets API for ns-3 provides an interface to various +types of transport protocols (TCP, UDP) as well as to packet sockets +and, in the future, Netlink-like sockets. However, users are cautioned +to understand that the semantics are @strong{not} the exact same as +one finds in a real system (for an API which is very much aligned +to real systems, see the next section). + +@code{class ns3::Socket} is defined in @code{src/node/socket.cc,h}. +Readers will note that many public member functions are aligned +with real sockets function calls, and all other things being equal, +we have tried to align with a Posix sockets API. However, note that: + +@itemize @bullet +@item ns-3 applications handle a smart pointer to a Socket object, not +a file descriptor; +@item there is no notion of synchronous API or a ``blocking'' API; +in fact, the model for interaction between application and socket is +one of asynchronous I/O, which is not typically found in real systems +(more on this below); +@item the C-style socket address structures are not used; +@item the API is not a complete sockets API, such as supporting +all socket options or all function variants; +@item many calls use @code{ns3::Packet} class to transfer data +between application and socket. This may seem a little funny to +people to pass ``Packets'' across a stream socket API, but think +of these packets as just fancy byte buffers at this level (more +on this also below). +@end itemize + +@subsection Basic operation and calls + +@float Figure,fig:sockets-overview +@caption{Implementation overview of native sockets API} +@image{figures/sockets-overview, 10cm} +@end float + +@subsubsection Creating sockets + +An application that wants to use sockets must first create one. +On real systems, this is accomplished by calling socket(): +@verbatim + int + socket(int domain, int type, int protocol); +@end verbatim +which creates a socket in the system and returns an integer descriptor. + +In ns-3, we have no equivalent of a system call at the lower layers, +so we adopt the following model. There are certain @emph{factory} +objects that can create sockets. Each factory is capable of creating +one type of socket, and if sockets of a particular type are able to +be created on a given node, then a factory that can create such sockets +must be aggregated to the Node. +@verbatim + static Ptr CreateSocket (Ptr node, TypeId tid); +@end verbatim +Examples of TypeIds to pass to this method are @code{TcpSocketFactory}, +@code{PacketSocketFactory}, and @code{UdpSocketFactory}. + +This method returns a smart pointer to a Socket object. Here is an +example: +@verbatim + Ptr n0; + // Do some stuff to build up the Node's internet stack + Ptr localSocket = Socket::CreateSocket (n0, TcpSocketFactory::GetTypeId ()); +@end verbatim + +In some ns-3 code, sockets will not be explicitly created by user's +main programs, if an ns-3 application does it. For instance, for +@code{class ns3::OnOffApplication}, the function @code{StartApplication()} +performs the socket creation, and the application holds the socket +pointer. + +@subsubsection Using sockets + +Below is a typical sequence of socket calls for a TCP client in a +real implementation: +@itemize @bullet +@item @code{sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);} +@item @code{bind(sock, ...);} +@item @code{connect(sock, ...);} +@item @code{send(sock, ...);} +@item @code{recv(sock, ...);} +@item @code{close(sock);} +@end itemize + +There are analogs to all of these calls in ns-3, but we will focus on +two aspects here. First, most usage of sockets in real systems +requires a way to manage I/O between the application and kernel. +These models include @emph{blocking sockets}, @emph{signal-based I/O}, +and @emph{non-blocking sockets} with polling. In ns-3, we make use +of the callback mechanisms to support a fourth mode, which is +analogous to POSIX @emph{asynchronous I/O}. + +In this model, on the sending side, if the @code{send()} call were to +fail because of insufficient buffers, the application suspends the +sending of more data until a function registered at the +@code{SetSendCallback()} callback is invoked. An application can +also ask the socket how much space is available by calling +@code{GetTxAvailable ()}. A typical sequence of events for +sending data (ignoring connection setup) might be: + +@itemize @bullet +@item @code{SetSendCallback (MakeCallback(&HandleSendCallback));} +@item @code{Send ();} +@item @code{Send ();} +@item ... +@item @code{// Send fails because buffer is full} +@item (wait until HandleSendCallback() is called) +@item (HandleSendCallback() is called by socket, since space now available) +@item @code{Send (); // Start sending again} +@end itemize + +Similarly, on the receive side, the socket user does not block on +a call to @code{recv()}. Instead, the application sets a callback +with @code{SetRecvCallback ()} in which the socket will notify the +application when (and how much) there is data to be read, and +the application then calls @code{Recv()} to read the data until +no more can be read. + +@subsection Packet vs. buffer variants + +There are two basic variants of @code{Send()} and @code{Recv()} supported: +@verbatim + virtual int Send (Ptr p) = 0; + int Send (const uint8_t* buf, uint32_t size); + + Ptr Recv (void); + int Recv (uint8_t* buf, uint32_t size); +@end verbatim + +The non-Packet variants are left for legacy API reasons. When calling +the raw buffer variant of @code{Send()}, the buffer is immediately +written into a Packet and the @code{Send (Ptr p)} is invoked. + +Users may find it semantically odd to pass a Packet to a stream socket +such as TCP. However, do not let the name bother you; think of +@code{ns3::Packet} to be a fancy byte buffer. There are a few reasons why +the Packet variants are more likely to be preferred in ns-3: + +@itemize @bullet +@item Users can use the Tags facility of packets to, for example, encode +a flow ID or other helper data. +@item Users can exploit the copy-on-write implementation to avoid +memory copies (on the receive side, the conversion back to a +@code{uint8_t* buf} may sometimes incur an additional copy). +@item Use of Packet is more aligned with the rest of the ns-3 API +@end itemize + +@subsection Sending dummy data + +Sometimes, users want the simulator to just pretend that there is an +actual data payload in the packet (e.g. to calculate transmission delay) +but do not want to actually produce or consume the data. This is +straightforward to support in ns-3; have applications call +@code{Create (size);} instead of @code{Create (buffer, size);}. +Similarly, passing in a zero to the pointer argument in the raw buffer +variants has the same effect. Note that, if some subsequent code tries +to read the Packet data buffer, the fake buffer will be converted to +a real (zero'ed) buffer on the spot, and the efficiency will be lost there. + +@subsection Socket options + +@emph{to be completed} + +@subsection Socket errno + +@emph{to be completed} + +@subsection Example programs + +@emph{to be completed} + +@section POSIX-like sockets API + +@emph{this capability is under development and is scheduled for +inclusion in August 2008 timeframe; see the repository +http://code.nsnam.org/mathieu/ns-3-simu for details} + +The below is excerpted from Mathieu's post to ns-developers list +on April 4, 2008. + +"To summarize, the goal is that the full posix/socket API is defined in +src/process/simu.h: each posix type and function is re-defined there +with a simu_ or SIMU_ prefix to avoid ugly name clashes and collisions +(feel free to come up with a better prefix). + +Each process is created with a call to ProcessManager::Create and is +attached to that ProcessManager instance. So, if the ProcessManager +(which is aggregated to a Node in src/helper/process-helper.cc) is +killed when the simulation ends, the system will automatically reclaim +all the resources of each process associated to each manager. The same +happens when an application "exits" from its main function. + +The example application defines two posix "processes": the function +ClientProgram creates a udp socket on the localhost port 2000 and the +function ServerProgram creates a udp socket on the localhost port 2000. +The code does not work right now because I did not get the details of +simu_read right yet but, I do plan to make this work at some point. + +I really think that this approach is worthwhile for many reasons, a few +of which are outlined below: +@itemize @bullet +@item makes porting real world application code _much_ easier + +@item makes write applications for new users much easier because they can +read the bsd socket api reference and documentation and write code +directly. + +@item can be used to write applications which work in both simulation and +in the real world at the same time. To do this, all you have to do is +write your application to use the simu_ API, and, then, you can chose at +compile-time which implementation of that API you want to use: you can +pick one implementation which forwards all calls to the system BSD +socket API or another one which forwards all calls to the attached +ProcessManager. Arguably, I did not implement the version which forwards +to system BSD sockets but, that should be pretty trivial. +@end itemize + +So, anyway, comments about the overall API would be welcome. Students +interested in the gsoc project for real-world code integration should +consider looking at this also." + diff --git a/doc/tutorial/tutorial.texi b/doc/tutorial/tutorial.texi index 1af725da1..64185d03c 100644 --- a/doc/tutorial/tutorial.texi +++ b/doc/tutorial/tutorial.texi @@ -95,9 +95,10 @@ Part 4: Creating New or Revised Topologies * Other-network-topologies:: Part 5: Key ns-3 objects and systems * ns-3 Packets:: -Part 6: Extending ns-3 * ns-3 Callbacks:: +* Sockets APIs:: * ns-3 routing overview:: +Part 6: Extending ns-3 * Nonlinear-Thinking:: * Summary:: * Object-Model:: @@ -115,6 +116,7 @@ Part 6: Extending ns-3 @include helpers.texi @include packets.texi @include callbacks.texi +@include sockets.texi @c @include output.texi @include routing.texi @c @include other.texi From 791e9ae4645c2094ca296e192bafc53468cc3e04 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Mon, 26 May 2008 11:22:42 -0700 Subject: [PATCH 39/45] Receive raw buffer variant --- src/node/socket.cc | 8 ++++++++ src/node/socket.h | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/node/socket.cc b/src/node/socket.cc index 768fdd170..18a15b0e9 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -130,6 +130,14 @@ Socket::Recv (void) return Recv (std::numeric_limits::max(), 0); } +int +Socket::Recv (uint8_t* buf, uint32_t size, uint32_t flags) +{ + Ptr p = Recv (size, flags); // read up to "size" bytes + memcpy (buf, p->PeekData (), p->GetSize()); + return p->GetSize (); +} + int Socket::SendTo (const uint8_t* buf, uint32_t size, const Address &address) { NS_LOG_FUNCTION_NOARGS (); diff --git a/src/node/socket.h b/src/node/socket.h index d0705762f..b0f53e8eb 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -328,6 +328,19 @@ public: * 0 if the socket cannot return a next in-sequence packet. */ Ptr Recv (void); + /** + * \brief Recv data (or dummy data) from the remote host + * \param buf A pointer to a raw byte buffer to write the data to. + * If the underlying packet was carring null (fake) data, this buffer + * will be zeroed up to the length specified by the return value. + * \param size Number of bytes (at most) to copy to buf + * \param flags any flags to pass to the socket + * \returns number of bytes copied into buf + * + * This is provided so as to have an API which is closer in appearance + * to that of real network or BSD sockets. + */ + int Recv (uint8_t* buf, uint32_t size, uint32_t flags); /** * Return number of bytes which can be returned from one or * multiple calls to Recv. From 9a94ef7a2d46440138fdead6ae4f65e3bba2a59f Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Mon, 26 May 2008 11:48:18 -0700 Subject: [PATCH 40/45] some doxygen cleanup --- src/node/socket.h | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/node/socket.h b/src/node/socket.h index b0f53e8eb..367c09de9 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -37,19 +37,28 @@ class Node; class Packet; /** - * \brief Define a Socket API based on the BSD Socket API. + * \ingroup node + * \defgroup socket Socket + * \brief A low-level Socket API based loosely on the BSD Socket API. * - * 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, - * it tries to stick to the BSD API to make it easier for those who know - * the BSD API to use this API. + * A few things to keep in mind about this type of socket: + * - it uses ns-3 API constructs such as class ns3::Address instead of + * C-style structs + * - in contrast to the original BSD socket API, this API is asynchronous: + * it does not contain blocking calls. Sending and receiving operations + * must make use of the callbacks provided. + * - It also uses class ns3::Packet as a fancy byte buffer, allowing + * data to be passed across the API using an ns-3 Packet instead of + * a raw data pointer. + * - Not all of the full POSIX sockets API is supported + * + * Other than that, it tries to stick to the BSD API to make it + * easier for those who know the BSD API to use this API. + * More details are provided in the ns-3 tutorial. */ class Socket : public Object { public: -// static TypeId GetTypeId (void); Socket (void); virtual ~Socket (void); From 0d86d03be00ab3bda608b3335553abb1fe9e7c6c Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 26 May 2008 20:44:19 -0700 Subject: [PATCH 41/45] kill ATTRIBUTE_HELPER_HEADER_1 --- src/common/data-rate.h | 1 - src/core/attribute-helper.h | 12 +----------- src/core/object-factory.h | 1 - src/core/type-id.h | 1 - src/devices/wifi/ssid.h | 1 - src/devices/wifi/wifi-mode.h | 1 - src/mobility/rectangle.h | 2 -- src/mobility/vector.h | 2 -- src/node/address.h | 1 - src/node/ipv4-address.h | 2 -- src/node/mac48-address.h | 1 - 11 files changed, 1 insertion(+), 24 deletions(-) diff --git a/src/common/data-rate.h b/src/common/data-rate.h index 90a81ace8..9cad5d413 100644 --- a/src/common/data-rate.h +++ b/src/common/data-rate.h @@ -80,7 +80,6 @@ public: */ uint64_t GetBitRate() const; - ATTRIBUTE_HELPER_HEADER_1 (DataRate); private: uint64_t m_bps; static uint64_t Parse(const std::string); diff --git a/src/core/attribute-helper.h b/src/core/attribute-helper.h index 1b31326b0..2757145fc 100644 --- a/src/core/attribute-helper.h +++ b/src/core/attribute-helper.h @@ -83,8 +83,7 @@ MakeSimpleAttributeChecker (std::string name, std::string underlying) * * The simple macros are implemented in terms of the complex * macros and should generally be prefered over the complex macros: - * - \ref ATTRIBUTE_HELPER_HEADER_1, - * - \ref ATTRIBUTE_HELPER_HEADER_2, and, + * - \ref ATTRIBUTE_HELPER_HEADER, and, * - \ref ATTRIBUTE_HELPER_CPP, */ @@ -232,15 +231,6 @@ MakeSimpleAttributeChecker (std::string name, std::string underlying) #define ATTRIBUTE_CONVERTER_IMPLEMENT(type) -/** - * \ingroup AttributeHelper - * \param type the name of the class - * - * This macro should be invoked from a public section of the class - * declaration. - */ -#define ATTRIBUTE_HELPER_HEADER_1(type) - /** * \ingroup AttributeHelper * \param type the name of the class diff --git a/src/core/object-factory.h b/src/core/object-factory.h index ccfdc4177..4161af14b 100644 --- a/src/core/object-factory.h +++ b/src/core/object-factory.h @@ -77,7 +77,6 @@ public: template Ptr Create (void) const; - ATTRIBUTE_HELPER_HEADER_1 (ObjectFactory); private: friend std::ostream & operator << (std::ostream &os, const ObjectFactory &factory); friend std::istream & operator >> (std::istream &is, ObjectFactory &factory); diff --git a/src/core/type-id.h b/src/core/type-id.h index 713f8cb5a..09555a4ea 100644 --- a/src/core/type-id.h +++ b/src/core/type-id.h @@ -354,7 +354,6 @@ public: TypeId (); ~TypeId (); - ATTRIBUTE_HELPER_HEADER_1 (TypeId); private: friend class AttributeList; friend bool operator == (TypeId a, TypeId b); diff --git a/src/devices/wifi/ssid.h b/src/devices/wifi/ssid.h index 0feed168b..9da9900b6 100644 --- a/src/devices/wifi/ssid.h +++ b/src/devices/wifi/ssid.h @@ -49,7 +49,6 @@ public: Buffer::Iterator Serialize (Buffer::Iterator i) const; Buffer::Iterator Deserialize (Buffer::Iterator i); - ATTRIBUTE_HELPER_HEADER_1 (Ssid); private: uint8_t m_ssid[33]; uint8_t m_length; diff --git a/src/devices/wifi/wifi-mode.h b/src/devices/wifi/wifi-mode.h index 9b15a203e..507240485 100644 --- a/src/devices/wifi/wifi-mode.h +++ b/src/devices/wifi/wifi-mode.h @@ -107,7 +107,6 @@ class WifiMode */ WifiMode (); - ATTRIBUTE_HELPER_HEADER_1 (WifiMode); private: friend class WifiModeFactory; WifiMode (uint32_t uid); diff --git a/src/mobility/rectangle.h b/src/mobility/rectangle.h index 3777ee1a6..b60708052 100644 --- a/src/mobility/rectangle.h +++ b/src/mobility/rectangle.h @@ -61,8 +61,6 @@ public: double xMax; double yMin; double yMax; - - ATTRIBUTE_HELPER_HEADER_1 (Rectangle); }; std::ostream &operator << (std::ostream &os, const Rectangle &rectangle); diff --git a/src/mobility/vector.h b/src/mobility/vector.h index 3517f7d36..30bed8dc0 100644 --- a/src/mobility/vector.h +++ b/src/mobility/vector.h @@ -57,8 +57,6 @@ public: * z coordinate of vector vector */ double z; - - ATTRIBUTE_HELPER_HEADER_1 (Vector); }; double CalculateDistance (const Vector &a, const Vector &b); diff --git a/src/node/address.h b/src/node/address.h index e5b6c82e3..b49c14bac 100644 --- a/src/node/address.h +++ b/src/node/address.h @@ -154,7 +154,6 @@ public: */ static uint8_t Register (void); - ATTRIBUTE_HELPER_HEADER_1 (Address); private: friend bool operator == (const Address &a, const Address &b); friend bool operator < (const Address &a, const Address &b); diff --git a/src/node/ipv4-address.h b/src/node/ipv4-address.h index fc2dc7fe7..c88910966 100644 --- a/src/node/ipv4-address.h +++ b/src/node/ipv4-address.h @@ -142,7 +142,6 @@ public: static Ipv4Address GetBroadcast (void); static Ipv4Address GetLoopback (void); - ATTRIBUTE_HELPER_HEADER_1 (Ipv4Address); private: Address ConvertTo (void) const; static uint8_t GetType (void); @@ -180,7 +179,6 @@ public: static Ipv4Mask GetLoopback (void); static Ipv4Mask GetZero (void); - ATTRIBUTE_HELPER_HEADER_1 (Ipv4Mask); private: uint32_t m_mask; }; diff --git a/src/node/mac48-address.h b/src/node/mac48-address.h index 6227e2e1b..e1f42e071 100644 --- a/src/node/mac48-address.h +++ b/src/node/mac48-address.h @@ -96,7 +96,6 @@ public: */ static Mac48Address GetBroadcast (void); - ATTRIBUTE_HELPER_HEADER_1 (Mac48Address); private: /** * \returns a new Address instance From b91e3b0e4c40ae93a62aa8e23cbf6da2aeea111d Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 26 May 2008 20:48:54 -0700 Subject: [PATCH 42/45] ATTRIBUTE_HELPER_HEADER_2 -> ATTRIBUTE_HELPER_HEADER --- src/common/data-rate.h | 2 +- src/core/attribute-helper.h | 2 +- src/core/attribute-test.cc | 2 +- src/core/object-factory.h | 2 +- src/core/type-id.h | 2 +- src/devices/wifi/ssid.h | 2 +- src/devices/wifi/wifi-mode.h | 2 +- src/mobility/rectangle.h | 2 +- src/mobility/vector.h | 2 +- src/node/address.h | 2 +- src/node/ipv4-address.h | 4 ++-- src/node/mac48-address.h | 2 +- 12 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/common/data-rate.h b/src/common/data-rate.h index 9cad5d413..3ebdbeaab 100644 --- a/src/common/data-rate.h +++ b/src/common/data-rate.h @@ -93,7 +93,7 @@ std::istream &operator >> (std::istream &is, DataRate &rate); * \brief hold objects of type ns3::DataRate */ -ATTRIBUTE_HELPER_HEADER_2 (DataRate); +ATTRIBUTE_HELPER_HEADER (DataRate); /** * \param lhs diff --git a/src/core/attribute-helper.h b/src/core/attribute-helper.h index 2757145fc..7e86578a5 100644 --- a/src/core/attribute-helper.h +++ b/src/core/attribute-helper.h @@ -238,7 +238,7 @@ MakeSimpleAttributeChecker (std::string name, std::string underlying) * This macro should be invoked outside of the class * declaration in its public header. */ -#define ATTRIBUTE_HELPER_HEADER_2(type) \ +#define ATTRIBUTE_HELPER_HEADER(type) \ ATTRIBUTE_VALUE_DEFINE (type); \ ATTRIBUTE_ACCESSOR_DEFINE (type); \ ATTRIBUTE_CHECKER_DEFINE (type); diff --git a/src/core/attribute-test.cc b/src/core/attribute-test.cc index e1c694a3d..64eee0837 100644 --- a/src/core/attribute-test.cc +++ b/src/core/attribute-test.cc @@ -53,7 +53,7 @@ std::istream & operator >> (std::istream &is, ValueClassTest &v) { return is; } -ATTRIBUTE_HELPER_HEADER_2 (ValueClassTest); +ATTRIBUTE_HELPER_HEADER (ValueClassTest); ATTRIBUTE_HELPER_CPP (ValueClassTest); class AttributeTest : public Test diff --git a/src/core/object-factory.h b/src/core/object-factory.h index 4161af14b..01f9341ed 100644 --- a/src/core/object-factory.h +++ b/src/core/object-factory.h @@ -93,7 +93,7 @@ std::istream & operator >> (std::istream &is, ObjectFactory &factory); * \brief hold objects of type ns3::ObjectFactory */ -ATTRIBUTE_HELPER_HEADER_2 (ObjectFactory); +ATTRIBUTE_HELPER_HEADER (ObjectFactory); } // namespace ns3 diff --git a/src/core/type-id.h b/src/core/type-id.h index 09555a4ea..48455f06f 100644 --- a/src/core/type-id.h +++ b/src/core/type-id.h @@ -387,7 +387,7 @@ bool operator < (TypeId a, TypeId b); */ -ATTRIBUTE_HELPER_HEADER_2 (TypeId); +ATTRIBUTE_HELPER_HEADER (TypeId); } // namespace ns3 diff --git a/src/devices/wifi/ssid.h b/src/devices/wifi/ssid.h index 9da9900b6..dc47e0787 100644 --- a/src/devices/wifi/ssid.h +++ b/src/devices/wifi/ssid.h @@ -62,7 +62,7 @@ std::istream &operator >> (std::istream &is, Ssid &ssid); * \brief hold objects of type ns3::Ssid */ -ATTRIBUTE_HELPER_HEADER_2 (Ssid); +ATTRIBUTE_HELPER_HEADER (Ssid); } // namespace ns3 diff --git a/src/devices/wifi/wifi-mode.h b/src/devices/wifi/wifi-mode.h index 507240485..24ea1163d 100644 --- a/src/devices/wifi/wifi-mode.h +++ b/src/devices/wifi/wifi-mode.h @@ -122,7 +122,7 @@ std::istream & operator >> (std::istream &is, WifiMode &mode); * \brief hold objects of type ns3::WifiMode */ -ATTRIBUTE_HELPER_HEADER_2 (WifiMode); +ATTRIBUTE_HELPER_HEADER (WifiMode); /** * \brief create WifiMode class instances and keep track of them. diff --git a/src/mobility/rectangle.h b/src/mobility/rectangle.h index b60708052..d49d5365b 100644 --- a/src/mobility/rectangle.h +++ b/src/mobility/rectangle.h @@ -71,7 +71,7 @@ std::istream &operator >> (std::istream &is, Rectangle &rectangle); * \brief hold objects of type ns3::Rectangle */ -ATTRIBUTE_HELPER_HEADER_2 (Rectangle); +ATTRIBUTE_HELPER_HEADER (Rectangle); } // namespace ns3 diff --git a/src/mobility/vector.h b/src/mobility/vector.h index 30bed8dc0..4bf1716d3 100644 --- a/src/mobility/vector.h +++ b/src/mobility/vector.h @@ -66,7 +66,7 @@ double CalculateDistance (const Vector &a, const Vector &b); * \brief hold objects of type ns3::Vector */ -ATTRIBUTE_HELPER_HEADER_2 (Vector); +ATTRIBUTE_HELPER_HEADER (Vector); std::ostream &operator << (std::ostream &os, const Vector &vector); std::istream &operator >> (std::istream &is, Vector &vector); diff --git a/src/node/address.h b/src/node/address.h index b49c14bac..0efa67134 100644 --- a/src/node/address.h +++ b/src/node/address.h @@ -170,7 +170,7 @@ private: * \brief hold objects of type ns3::Address */ -ATTRIBUTE_HELPER_HEADER_2 (Address); +ATTRIBUTE_HELPER_HEADER (Address); bool operator == (const Address &a, const Address &b); bool operator != (const Address &a, const Address &b); diff --git a/src/node/ipv4-address.h b/src/node/ipv4-address.h index c88910966..62999fc03 100644 --- a/src/node/ipv4-address.h +++ b/src/node/ipv4-address.h @@ -192,8 +192,8 @@ private: * \brief hold objects of type ns3::Ipv4Mask */ -ATTRIBUTE_HELPER_HEADER_2 (Ipv4Address); -ATTRIBUTE_HELPER_HEADER_2 (Ipv4Mask); +ATTRIBUTE_HELPER_HEADER (Ipv4Address); +ATTRIBUTE_HELPER_HEADER (Ipv4Mask); std::ostream& operator<< (std::ostream& os, Ipv4Address const& address); std::ostream& operator<< (std::ostream& os, Ipv4Mask const& mask); diff --git a/src/node/mac48-address.h b/src/node/mac48-address.h index e1f42e071..75c356a8e 100644 --- a/src/node/mac48-address.h +++ b/src/node/mac48-address.h @@ -116,7 +116,7 @@ private: * \brief hold objects of type ns3::Mac48Address */ -ATTRIBUTE_HELPER_HEADER_2 (Mac48Address); +ATTRIBUTE_HELPER_HEADER (Mac48Address); bool operator == (const Mac48Address &a, const Mac48Address &b); bool operator != (const Mac48Address &a, const Mac48Address &b); From c352b35d3f0b147841c60730d1cf92df326eb173 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 26 May 2008 21:00:25 -0700 Subject: [PATCH 43/45] add NS_LOG_APPEND_CONTEXT --- src/core/log.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/core/log.h b/src/core/log.h index fd87ace1a..554d16815 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -69,7 +69,7 @@ #define NS_LOG_COMPONENT_DEFINE(name) \ static ns3::LogComponent g_log = ns3::LogComponent (name) -#define APPEND_TIME_PREFIX \ +#define NS_LOG_APPEND_TIME_PREFIX \ if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) \ { \ LogTimePrinter printer = LogGetTimePrinter (); \ @@ -80,13 +80,17 @@ } \ } -#define APPEND_FUNC_PREFIX \ +#define NS_LOG_APPEND_FUNC_PREFIX \ if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) \ { \ std::clog << g_log.Name () << ":" << \ __FUNCTION__ << "(): "; \ } \ +#ifndef NS_LOG_APPEND_CONTEXT +#define NS_LOG_APPEND_CONTEXT +#endif /* NS_LOG_APPEND_CONTEXT */ + /** * \ingroup logging @@ -107,8 +111,9 @@ { \ if (g_log.IsEnabled (level)) \ { \ - APPEND_TIME_PREFIX; \ - APPEND_FUNC_PREFIX; \ + NS_LOG_APPEND_TIME_PREFIX; \ + NS_LOG_APPEND_CONTEXT; \ + NS_LOG_APPEND_FUNC_PREFIX; \ std::clog << msg << std::endl; \ } \ } \ @@ -160,7 +165,8 @@ { \ if (g_log.IsEnabled (ns3::LOG_FUNCTION)) \ { \ - APPEND_TIME_PREFIX; \ + NS_LOG_APPEND_TIME_PREFIX; \ + NS_LOG_APPEND_CONTEXT; \ std::clog << g_log.Name () << ":" \ << __FUNCTION__ << "()" << std::endl; \ } \ @@ -189,7 +195,8 @@ { \ if (g_log.IsEnabled (ns3::LOG_FUNCTION)) \ { \ - APPEND_TIME_PREFIX; \ + NS_LOG_APPEND_TIME_PREFIX; \ + NS_LOG_APPEND_CONTEXT; \ std::clog << g_log.Name () << ":" \ << __FUNCTION__ << "("; \ ParameterLogger (std::clog) << parameters; \ From f79ac9e37328ecc7ffeb26546ad4f677d32f59ec Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 26 May 2008 21:03:59 -0700 Subject: [PATCH 44/45] fix optimized build --- src/contrib/gtk-config-store.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/contrib/gtk-config-store.cc b/src/contrib/gtk-config-store.cc index 025d47d3e..966900a03 100644 --- a/src/contrib/gtk-config-store.cc +++ b/src/contrib/gtk-config-store.cc @@ -304,7 +304,7 @@ cell_tooltip_callback (GtkWidget *widget, } break; case ModelNode::NODE_ATTRIBUTE: { - uint32_t attrIndex; + uint32_t attrIndex = 0; TypeId tid; for (tid = node->object->GetInstanceTypeId (); tid.HasParent (); tid = tid.GetParent ()) { From 4182edbc93ac18e7cbf19320919aec506abcefad Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Tue, 27 May 2008 06:03:48 -0700 Subject: [PATCH 45/45] fix optimized build --- src/applications/packet-sink/packet-sink.cc | 3 ++- src/applications/udp-echo/udp-echo-client.cc | 3 ++- src/applications/udp-echo/udp-echo-server.cc | 3 ++- src/internet-node/udp-socket-impl.cc | 6 ++++-- src/routing/olsr/olsr-agent-impl.cc | 3 ++- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/applications/packet-sink/packet-sink.cc b/src/applications/packet-sink/packet-sink.cc index 3f4a9f27e..d73ca1f03 100644 --- a/src/applications/packet-sink/packet-sink.cc +++ b/src/applications/packet-sink/packet-sink.cc @@ -106,7 +106,8 @@ void PacketSink::HandleRead (Ptr socket) while (packet = socket->Recv ()) { SocketRxAddressTag tag; - bool found = packet->FindFirstMatchingTag (tag); + bool found; + found = packet->FindFirstMatchingTag (tag); NS_ASSERT (found); Address from = tag.GetAddress (); // XXX packet->RemoveTag (tag); diff --git a/src/applications/udp-echo/udp-echo-client.cc b/src/applications/udp-echo/udp-echo-client.cc index 787e2dcf7..7dd68701c 100644 --- a/src/applications/udp-echo/udp-echo-client.cc +++ b/src/applications/udp-echo/udp-echo-client.cc @@ -153,7 +153,8 @@ UdpEchoClient::HandleRead (Ptr socket) while (packet = socket->Recv ()) { SocketRxAddressTag tag; - bool found = packet->FindFirstMatchingTag (tag); + bool found; + found = packet->FindFirstMatchingTag (tag); NS_ASSERT (found); Address from = tag.GetAddress (); // XXX packet->RemoveTag (tag); diff --git a/src/applications/udp-echo/udp-echo-server.cc b/src/applications/udp-echo/udp-echo-server.cc index e2dab0bf8..3851a88b7 100644 --- a/src/applications/udp-echo/udp-echo-server.cc +++ b/src/applications/udp-echo/udp-echo-server.cc @@ -98,7 +98,8 @@ UdpEchoServer::HandleRead (Ptr socket) while (packet = socket->Recv ()) { SocketRxAddressTag tag; - bool found = packet->FindFirstMatchingTag (tag); + bool found; + found = packet->FindFirstMatchingTag (tag); NS_ASSERT (found); Address from = tag.GetAddress (); // XXX packet->RemoveTag (tag); diff --git a/src/internet-node/udp-socket-impl.cc b/src/internet-node/udp-socket-impl.cc index 9f326246e..ae9e1f732 100644 --- a/src/internet-node/udp-socket-impl.cc +++ b/src/internet-node/udp-socket-impl.cc @@ -530,14 +530,16 @@ void UdpSocketImplTest::ReceivePacket2 (Ptr socket, Ptr packet, void UdpSocketImplTest::ReceivePkt (Ptr socket) { - uint32_t availableData = socket->GetRxAvailable (); + uint32_t availableData; + availableData = socket->GetRxAvailable (); m_receivedPacket = socket->Recv (std::numeric_limits::max(), 0); NS_ASSERT (availableData == m_receivedPacket->GetSize ()); } void UdpSocketImplTest::ReceivePkt2 (Ptr socket) { - uint32_t availableData = socket->GetRxAvailable (); + uint32_t availableData; + availableData = socket->GetRxAvailable (); m_receivedPacket2 = socket->Recv (std::numeric_limits::max(), 0); NS_ASSERT (availableData == m_receivedPacket2->GetSize ()); } diff --git a/src/routing/olsr/olsr-agent-impl.cc b/src/routing/olsr/olsr-agent-impl.cc index 56d4e8c76..2d240e897 100644 --- a/src/routing/olsr/olsr-agent-impl.cc +++ b/src/routing/olsr/olsr-agent-impl.cc @@ -312,7 +312,8 @@ AgentImpl::RecvOlsr (Ptr socket) receivedPacket = socket->Recv (); SocketRxAddressTag tag; - bool found = receivedPacket->FindFirstMatchingTag (tag); + bool found; + found = receivedPacket->FindFirstMatchingTag (tag); NS_ASSERT (found); Address sourceAddress = tag.GetAddress ();