From e855838ed159be98cb5460fca50c663fc91a36da Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Sun, 13 Apr 2008 15:46:17 -0700 Subject: [PATCH 1/8] Align helper API use of Install() --- examples/mixed-wireless.cc | 39 ++++++++++++++------------ examples/simple-point-to-point-olsr.cc | 2 +- examples/wifi-adhoc.cc | 2 +- examples/wifi-ap.cc | 4 +-- samples/main-grid-topology.cc | 2 +- samples/main-random-topology.cc | 2 +- samples/main-random-walk.cc | 2 +- src/helper/internet-stack-helper.cc | 10 +++++++ src/helper/internet-stack-helper.h | 5 +++- src/helper/mobility-helper.cc | 6 ++-- src/helper/mobility-helper.h | 20 ++++++------- src/helper/ns2-mobility-helper.cc | 4 +-- src/helper/ns2-mobility-helper.h | 6 ++-- src/helper/olsr-helper.cc | 16 +++++++---- src/helper/olsr-helper.h | 6 ++-- src/internet-node/internet-stack.cc | 5 ---- 16 files changed, 74 insertions(+), 57 deletions(-) diff --git a/examples/mixed-wireless.cc b/examples/mixed-wireless.cc index cb28e8855..36a506959 100644 --- a/examples/mixed-wireless.cc +++ b/examples/mixed-wireless.cc @@ -166,7 +166,7 @@ main (int argc, char *argv[]) "Bounds", Rectangle (0, 1000, 0, 1000), "Speed", ConstantVariable (2000), "Pause", ConstantVariable (0.2)); - mobility.Layout (backbone); + mobility.Install (backbone); /////////////////////////////////////////////////////////////////////////// // // @@ -178,17 +178,19 @@ main (int argc, char *argv[]) // the "172.16 address space ipAddrs.SetBase ("172.16.0.0", "255.255.255.0"); + for (uint32_t i = 0; i < backboneNodes; ++i) { NS_LOG_INFO ("Configuring local area network for backbone node " << i); // - // Create a container to manage the nodes of the LAN. Pick one of - // the backbone nodes to be part of the LAN and first add it to - // the container. Then create the rest of the nodes we'll need. + // Create a container to manage the nodes of the LAN. We need + // two containers here; one with all of the new nodes, and one + // with all of the nodes including new and existing nodes // - NodeContainer lan; - lan.Add (backbone.Get (i)); - lan.Create (lanNodes - 1); + NodeContainer newLanNodes; + newLanNodes.Create (lanNodes - 1); + // Now, create the container with all nodes on this link + NodeContainer lan (backbone.Get (i), newLanNodes); // // Create the CSMA net devices and install them into the nodes in our // collection. @@ -198,9 +200,9 @@ main (int argc, char *argv[]) csma.SetChannelParameter ("Delay", MilliSeconds (2)); NetDeviceContainer lanDevices = csma.Install (lan); // - // Add the IPv4 protocol stack to the nodes in our container + // Add the IPv4 protocol stack to the new LAN nodes // - internet.Install (lan); + internet.Install (newLanNodes); // // Assign IPv4 addresses to the device drivers (actually to the // associated IPv4 interfaces) we just created. @@ -227,13 +229,14 @@ main (int argc, char *argv[]) { NS_LOG_INFO ("Configuring wireless network for backbone node " << i); // - // Create a container to manage the nodes of the network. Pick one of - // the backbone nodes to be part of the network and first add it to - // the container. Then create the rest of the nodes we'll need. + // Create a container to manage the nodes of the LAN. We need + // two containers here; one with all of the new nodes, and one + // with all of the nodes including new and existing nodes // - NodeContainer infra; - infra.Add (backbone.Get (i)); - infra.Create (infraNodes - 1); + NodeContainer newInfraNodes; + newInfraNodes.Create (infraNodes - 1); + // Now, create the container with all nodes on this link + NodeContainer infra (backbone.Get (i), newInfraNodes); // // Create another ad hoc network and devices // @@ -244,7 +247,7 @@ main (int argc, char *argv[]) // Add the IPv4 protocol stack to the nodes in our container // - internet.Install (infra); + internet.Install (newInfraNodes); // // Assign IPv4 addresses to the device drivers (actually to the associated // IPv4 interfaces) we just created. @@ -272,7 +275,7 @@ main (int argc, char *argv[]) "Bounds", Rectangle (-25, 25, -25, 25), "Speed", ConstantVariable (30), "Pause", ConstantVariable (0.4)); - mobility.Layout (infra); + mobility.Install (infra); } /////////////////////////////////////////////////////////////////////////// // // @@ -282,7 +285,7 @@ main (int argc, char *argv[]) NS_LOG_INFO ("Enabling OLSR routing on all backbone nodes"); OlsrHelper olsr; - olsr.Enable (backbone); + olsr.Install (backbone); /////////////////////////////////////////////////////////////////////////// // // diff --git a/examples/simple-point-to-point-olsr.cc b/examples/simple-point-to-point-olsr.cc index 4c85d605a..da726fa5d 100644 --- a/examples/simple-point-to-point-olsr.cc +++ b/examples/simple-point-to-point-olsr.cc @@ -120,7 +120,7 @@ main (int argc, char *argv[]) // Enable OLSR NS_LOG_INFO ("Enabling OLSR Routing."); OlsrHelper olsr; - olsr.EnableAll (); + olsr.InstallAll (); // Create the OnOff application to send UDP datagrams of size // 210 bytes at a rate of 448 Kb/s diff --git a/examples/wifi-adhoc.cc b/examples/wifi-adhoc.cc index cc5a4e9b3..06ac048b0 100644 --- a/examples/wifi-adhoc.cc +++ b/examples/wifi-adhoc.cc @@ -126,7 +126,7 @@ Experiment::Run (const WifiHelper &wifi) mobility.SetPositionAllocator (positionAlloc); mobility.SetMobilityModel ("ns3::StaticMobilityModel"); - mobility.Layout (c); + mobility.Install (c); PacketSocketAddress socket; socket.SetSingleDevice(devices.Get (0)->GetIfIndex ()); diff --git a/examples/wifi-ap.cc b/examples/wifi-ap.cc index 914439601..db91a1e80 100644 --- a/examples/wifi-ap.cc +++ b/examples/wifi-ap.cc @@ -151,8 +151,8 @@ int main (int argc, char *argv[]) wifi.Install (ap, channel); // mobility. - mobility.Layout (stas); - mobility.Layout (ap); + mobility.Install (stas); + mobility.Install (ap); Simulator::Schedule (Seconds (1.0), &AdvancePosition, ap.Get (0)); diff --git a/samples/main-grid-topology.cc b/samples/main-grid-topology.cc index 9c4a3617e..d1ca99e2b 100644 --- a/samples/main-grid-topology.cc +++ b/samples/main-grid-topology.cc @@ -37,7 +37,7 @@ int main (int argc, char *argv[]) // finalize the setup by attaching to each object // in the input array a position and initializing // this position with the calculated coordinates. - mobility.Layout (nodes); + mobility.Install (nodes); // iterate our nodes and print their position. for (NodeContainer::Iterator j = nodes.Begin (); diff --git a/samples/main-random-topology.cc b/samples/main-random-topology.cc index 022f02c6b..a83b8deef 100644 --- a/samples/main-random-topology.cc +++ b/samples/main-random-topology.cc @@ -31,7 +31,7 @@ int main (int argc, char *argv[]) "Y", String ("100.0"), "Rho", String ("Uniform:0:30")); mobility.SetMobilityModel ("ns3::StaticMobilityModel"); - mobility.Layout (c); + mobility.Install (c); Config::Connect ("/NodeList/*/$ns3::MobilityModelNotifier/CourseChange", MakeCallback (&CourseChange)); diff --git a/samples/main-random-walk.cc b/samples/main-random-walk.cc index 6a536d5fb..d234b8645 100644 --- a/samples/main-random-walk.cc +++ b/samples/main-random-walk.cc @@ -41,7 +41,7 @@ int main (int argc, char *argv[]) "Time", String ("2s"), "Speed", String ("Constant:1.0"), "Bounds", String ("0:200:0:100")); - mobility.LayoutAll (); + mobility.InstallAll (); Config::Connect ("/NodeList/*/$ns3::MobilityModelNotifier/CourseChange", MakeCallback (&CourseChange)); diff --git a/src/helper/internet-stack-helper.cc b/src/helper/internet-stack-helper.cc index b6e3454ee..39728beec 100644 --- a/src/helper/internet-stack-helper.cc +++ b/src/helper/internet-stack-helper.cc @@ -17,6 +17,10 @@ * * Author: Mathieu Lacage */ +#include "ns3/assert.h" +#include "ns3/log.h" +#include "ns3/object.h" +#include "ns3/ipv4.h" #include "internet-stack-helper.h" #include "ns3/internet-stack.h" #include "ns3/packet-socket-factory.h" @@ -33,6 +37,12 @@ InternetStackHelper::Install (NodeContainer c) for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) { Ptr node = *i; + if (node->GetObject () != 0) + { + NS_FATAL_ERROR ("InternetStackHelper::Install(): Aggregating " + "an InternetStack to a node with an existing Ipv4 object"); + return; + } AddInternetStack (node); Ptr factory = CreateObject (); node->AggregateObject (factory); diff --git a/src/helper/internet-stack-helper.h b/src/helper/internet-stack-helper.h index ecee023cf..19ddf1bcb 100644 --- a/src/helper/internet-stack-helper.h +++ b/src/helper/internet-stack-helper.h @@ -37,7 +37,10 @@ public: * \param c the set of nodes * * For each node in the input container, aggregate implementations - * of the ns3::Ipv4, ns3::Udp, and, ns3::Tcp classes. + * of the ns3::Ipv4, ns3::Udp, and, ns3::Tcp classes. The program + * will assert if this method is called on a container with a node + * that already has an Ipv4 object aggregated to it. + * */ void Install (NodeContainer c); diff --git a/src/helper/mobility-helper.cc b/src/helper/mobility-helper.cc index 94ade79c7..3fbe38197 100644 --- a/src/helper/mobility-helper.cc +++ b/src/helper/mobility-helper.cc @@ -122,7 +122,7 @@ MobilityHelper::GetMobilityModelType (void) const } void -MobilityHelper::Layout (NodeContainer c) +MobilityHelper::Install (NodeContainer c) { for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) { @@ -167,9 +167,9 @@ MobilityHelper::Layout (NodeContainer c) } void -MobilityHelper::LayoutAll (void) +MobilityHelper::InstallAll (void) { - Layout (NodeContainer::GetGlobal ()); + Install (NodeContainer::GetGlobal ()); } } // namespace ns3 diff --git a/src/helper/mobility-helper.h b/src/helper/mobility-helper.h index 5a8c07e3d..761b47a13 100644 --- a/src/helper/mobility-helper.h +++ b/src/helper/mobility-helper.h @@ -34,7 +34,7 @@ class MobilityModel; /** * \brief assign positions and mobility models to nodes. * - * MobilityHelper::Layout is the most important method here. + * MobilityHelper::Install is the most important method here. */ class MobilityHelper { @@ -43,14 +43,14 @@ public: ~MobilityHelper (); /** - * After this method is called, every call to MobilityHelper::Layout + * After this method is called, every call to MobilityHelper::Install * will also attach to the new ns3::MobilityModel an ns3::MobilityModelNotifier * which can be used to listen to CourseChange events. */ void EnableNotifier (void); /** * After this method is called, no ns3::MobilityModelNotifier object will - * be associated to any new ns3::MobilityModel created by MobilityHelper::Layout. + * be associated to any new ns3::MobilityModel created by MobilityHelper::Install. * This will make it impossible to listen to "CourseChange" events from these * new ns3::MobilityModel instances. */ @@ -60,7 +60,7 @@ public: * \param allocator allocate initial node positions * * Set the position allocator which will be used to allocate - * the initial position of every node in MobilityModel::Layout. + * the initial position of every node in MobilityModel::Install. */ void SetPositionAllocator (Ptr allocator); @@ -117,7 +117,7 @@ public: * \param n9 the name of the attribute to set in the mobility model. * \param v9 the value of the attribute to set in the mobility model. * - * Calls to MobilityHelper::Layout will create an instance of a matching + * Calls to MobilityHelper::Install will create an instance of a matching * mobility model for each node. */ void SetMobilityModel (std::string type, @@ -136,9 +136,9 @@ public: * * Push an item on the top of the stack of "reference mobility models". * The input item should be a node instance to which a mobility model - * has already been aggregated (usually by a call to Layout). + * has already been aggregated (usually by a call to Install). * - * If this this stack is not empty when MobilityHelper::Layout + * If this this stack is not empty when MobilityHelper::Install * is called, the model from the top of the stack is used * to create a ns3::HierarchicalMobilityModel to make the * newly-created models define their positions relative to that @@ -173,13 +173,13 @@ public: * ns3::MobilityModelNotifier to generate 'CourseChange' events based on the * boolean flag set by MobilityHelper::EnableNotifier and MobilityHelper::DisableNotifier. */ - void Layout (NodeContainer container); + void Install (NodeContainer container); /** - * Perform the work of MobilityHelper::Layout on _all_ nodes which + * Perform the work of MobilityHelper::Install on _all_ nodes which * exist in the simulation. */ - void LayoutAll (void); + void InstallAll (void); private: std::vector > m_mobilityStack; diff --git a/src/helper/ns2-mobility-helper.cc b/src/helper/ns2-mobility-helper.cc index 761dfaae0..736c92581 100644 --- a/src/helper/ns2-mobility-helper.cc +++ b/src/helper/ns2-mobility-helper.cc @@ -154,9 +154,9 @@ Ns2MobilityHelper::LayoutObjectStore (const ObjectStore &store) const } void -Ns2MobilityHelper::Layout (void) const +Ns2MobilityHelper::Install (void) const { - Layout (NodeList::Begin (), NodeList::End ()); + Install (NodeList::Begin (), NodeList::End ()); } } // namespace ns3 diff --git a/src/helper/ns2-mobility-helper.h b/src/helper/ns2-mobility-helper.h index b75a3221a..b112129a1 100644 --- a/src/helper/ns2-mobility-helper.h +++ b/src/helper/ns2-mobility-helper.h @@ -51,7 +51,7 @@ public: * whose nodeId is matches the nodeId of the nodes in the trace * file. */ - void Layout (void) const; + void Install (void) const; /** * \param begin an iterator which points to the start of the input @@ -65,7 +65,7 @@ public: * the index of the object in the input array. */ template - void Layout (T begin, T end) const; + void Install (T begin, T end) const; private: class ObjectStore { @@ -86,7 +86,7 @@ namespace ns3 { template void -Ns2MobilityHelper::Layout (T begin, T end) const +Ns2MobilityHelper::Install (T begin, T end) const { class MyObjectStore : public ObjectStore { diff --git a/src/helper/olsr-helper.cc b/src/helper/olsr-helper.cc index 4032f387c..bc6856312 100644 --- a/src/helper/olsr-helper.cc +++ b/src/helper/olsr-helper.cc @@ -51,26 +51,32 @@ OlsrHelper::SetAgent (std::string tid, } void -OlsrHelper::Enable (NodeContainer container) +OlsrHelper::Install (NodeContainer container) { for (NodeContainer::Iterator i = container.Begin (); i != container.End (); ++i) { Ptr node = *i; - Enable (node); + Install (node); } } void -OlsrHelper::Enable (Ptr node) +OlsrHelper::Install (Ptr node) { + if (node->GetObject () != 0) + { + NS_FATAL_ERROR ("OlsrHelper::Install(): Aggregating " + "an Olsr Agent to a node with an existing Olsr Agent"); + return; + } Ptr agent = m_agentFactory.Create (); agent->SetNode (node); node->AggregateObject (agent); agent->Start (); } void -OlsrHelper::EnableAll (void) +OlsrHelper::InstallAll (void) { - Enable (NodeContainer::GetGlobal ()); + Install (NodeContainer::GetGlobal ()); } } // namespace ns3 diff --git a/src/helper/olsr-helper.h b/src/helper/olsr-helper.h index 4afb6cd9a..599a6245d 100644 --- a/src/helper/olsr-helper.h +++ b/src/helper/olsr-helper.h @@ -41,9 +41,9 @@ public: std::string n6 = "", Attribute v6 = Attribute (), std::string n7 = "", Attribute v7 = Attribute ()); - void Enable (NodeContainer container); - void Enable (Ptr node); - void EnableAll (void); + void Install (NodeContainer container); + void Install (Ptr node); + void InstallAll (void); private: ObjectFactory m_agentFactory; }; diff --git a/src/internet-node/internet-stack.cc b/src/internet-node/internet-stack.cc index cde9ac719..916f436ac 100644 --- a/src/internet-node/internet-stack.cc +++ b/src/internet-node/internet-stack.cc @@ -36,11 +36,6 @@ namespace ns3 { void AddInternetStack (Ptr node) { - // This may be called on a node with a previously added stack - if (node->GetObject ()) - { - return; - } Ptr ipv4 = CreateObject (); Ptr arp = CreateObject (); ipv4->SetNode (node); From 0dab5235c91af36e7e7e0a3d9595b057c8017b32 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 22 Apr 2008 13:54:05 -0700 Subject: [PATCH 2/8] kill unused code --- src/common/buffer.cc | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 6e242e97c..613c79139 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -544,14 +544,6 @@ Buffer Buffer::CreateFragment (uint32_t start, uint32_t length) const { NS_ASSERT (CheckInternalState ()); - uint32_t zeroStart = m_zeroAreaStart - m_start; - uint32_t zeroEnd = zeroStart + m_zeroAreaEnd; - if (m_zeroAreaEnd != 0 && - start + length > zeroStart && - start <= zeroEnd) - { - TransformIntoRealBuffer (); - } Buffer tmp = *this; tmp.RemoveAtStart (start); tmp.RemoveAtEnd (GetSize () - (start + length)); @@ -563,7 +555,7 @@ Buffer Buffer::CreateFullCopy (void) const { NS_ASSERT (CheckInternalState ()); - if (m_zeroAreaEnd != 0) + if (m_zeroAreaEnd - m_zeroAreaStart != 0) { Buffer tmp; tmp.AddAtStart (m_zeroAreaEnd - m_zeroAreaStart); From 815f3721b7d7d6630d5c5f3cce08604f0e58d5a7 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 22 Apr 2008 14:18:33 -0700 Subject: [PATCH 3/8] move Packet::AddAtEnd implementation to the Buffer code. --- src/common/buffer.cc | 13 +++++++++++++ src/common/buffer.h | 2 ++ src/common/packet.cc | 9 +-------- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 613c79139..9859aeda0 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -461,6 +461,19 @@ Buffer::AddAtEnd (uint32_t end) NS_ASSERT (CheckInternalState ()); } +void +Buffer::AddAtEnd (const Buffer &o) +{ + Buffer dst = CreateFullCopy (); + Buffer src = o.CreateFullCopy (); + + dst.AddAtEnd (src.GetSize ()); + Buffer::Iterator destStart = dst.End (); + destStart.Prev (src.GetSize ()); + destStart.Write (src.Begin (), src.End ()); + *this = dst; +} + void Buffer::RemoveAtStart (uint32_t start) { diff --git a/src/common/buffer.h b/src/common/buffer.h index e2b9a0d53..3f8409aff 100644 --- a/src/common/buffer.h +++ b/src/common/buffer.h @@ -410,6 +410,8 @@ public: * pointing to this Buffer. */ void AddAtEnd (uint32_t end); + + void AddAtEnd (const Buffer &o); /** * \param start size to remove * diff --git a/src/common/packet.cc b/src/common/packet.cc index 0ad8fb508..1e980c351 100644 --- a/src/common/packet.cc +++ b/src/common/packet.cc @@ -159,14 +159,7 @@ Packet::RemoveTrailer (Trailer &trailer) void Packet::AddAtEnd (Ptr packet) { - Buffer src = packet->m_buffer.CreateFullCopy (); - Buffer dst = m_buffer.CreateFullCopy (); - - dst.AddAtEnd (src.GetSize ()); - Buffer::Iterator destStart = dst.End (); - destStart.Prev (src.GetSize ()); - destStart.Write (src.Begin (), src.End ()); - m_buffer = dst; + m_buffer.AddAtEnd (packet->m_buffer); /** * XXX: we might need to merge the tag list of the * other packet into the current packet. From 63d6b14d454d1280be59366180eac2ec296c8ad3 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 22 Apr 2008 14:35:42 -0700 Subject: [PATCH 4/8] optimize case where fake payload is fragmented and re-assembled. --- src/common/buffer.cc | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 9859aeda0..4c5efe725 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -464,6 +464,27 @@ Buffer::AddAtEnd (uint32_t end) void Buffer::AddAtEnd (const Buffer &o) { + if (m_end == m_zeroAreaEnd && + o.m_start == o.m_zeroAreaStart && + o.m_zeroAreaEnd - o.m_zeroAreaStart > 0) + { + /** + * This is an optimization which kicks in when + * we attempt to aggregate two buffers which contain + * adjacent zero areas. + */ + uint32_t zeroSize = o.m_zeroAreaEnd - o.m_zeroAreaStart; + m_zeroAreaEnd += zeroSize; + m_end = m_zeroAreaEnd; + uint32_t endData = o.m_end - o.m_zeroAreaEnd; + AddAtEnd (endData); + Buffer::Iterator dst = End (); + dst.Prev (endData); + Buffer::Iterator src = o.End (); + src.Prev (endData); + dst.Write (src, o.End ()); + return; + } Buffer dst = CreateFullCopy (); Buffer src = o.CreateFullCopy (); @@ -1336,6 +1357,21 @@ BufferTest::RunTests (void) NS_TEST_ASSERT (memcmp (inputBuffer.PeekData (), outputBuffer.PeekData (), chunkSize) == 0); } + buffer = Buffer (5); + buffer.AddAtEnd (2); + i = buffer.End (); + i.Prev (2); + i.WriteU8 (0); + i.WriteU8 (0x66); + ENSURE_WRITTEN_BYTES (buffer, 7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66); + Buffer frag0 = buffer.CreateFragment (0, 2); + ENSURE_WRITTEN_BYTES (frag0, 2, 0x00, 0x00); + Buffer frag1 = buffer.CreateFragment (2, 5); + ENSURE_WRITTEN_BYTES (frag1, 5, 0x00, 0x00, 0x00, 0x00, 0x66); + frag0.AddAtEnd (frag1); + ENSURE_WRITTEN_BYTES (buffer, 7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66); + ENSURE_WRITTEN_BYTES (frag0, 7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66); + return result; } From 1f0dd55d8ddef1ebd377410c89a955d53a242de7 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Tue, 22 Apr 2008 21:18:04 -0700 Subject: [PATCH 5/8] EnablePcap()->EnablePcapAll(); EnableAscii()->EnableAsciiAll() --- examples/csma-broadcast.cc | 4 ++-- examples/csma-multicast.cc | 4 ++-- examples/csma-one-subnet.cc | 4 ++-- examples/mixed-global-routing.cc | 8 ++++---- 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 ++-- examples/tcp-large-transfer.cc | 4 ++-- examples/udp-echo.cc | 4 ++-- src/helper/csma-helper.cc | 4 ++-- src/helper/csma-helper.h | 4 ++-- src/helper/internet-stack-helper.cc | 2 +- src/helper/internet-stack-helper.h | 2 +- src/helper/mobility-helper.h | 2 +- src/helper/point-to-point-helper.cc | 4 ++-- src/helper/point-to-point-helper.h | 4 ++-- src/helper/wifi-helper.cc | 4 ++-- src/helper/wifi-helper.h | 4 ++-- tutorial/tutorial-bus-network.cc | 2 +- tutorial/tutorial-csma-echo-ascii-trace.cc | 2 +- tutorial/tutorial-csma-echo-pcap-trace.cc | 2 +- tutorial/tutorial-linear-dumbbell.cc | 8 ++++---- tutorial/tutorial-point-to-point.cc | 2 +- tutorial/tutorial-star-routing.cc | 2 +- tutorial/tutorial-star.cc | 2 +- 27 files changed, 49 insertions(+), 49 deletions(-) diff --git a/examples/csma-broadcast.cc b/examples/csma-broadcast.cc index fdda66c49..e1d5d4698 100644 --- a/examples/csma-broadcast.cc +++ b/examples/csma-broadcast.cc @@ -113,10 +113,10 @@ main (int argc, char *argv[]) // The output files will be named // csma-broadcast.pcap-- // and can be read by the "tcpdump -tt -r" command - CsmaHelper::EnablePcap ("csma-broadcast"); + CsmaHelper::EnablePcapAll ("csma-broadcast"); std::ofstream ascii; ascii.open ("csma-broadcast.tr"); - CsmaHelper::EnableAscii (ascii); + CsmaHelper::EnableAsciiAll (ascii); NS_LOG_INFO ("Run Simulation."); Simulator::Run (); diff --git a/examples/csma-multicast.cc b/examples/csma-multicast.cc index d0a4f4457..1d9e2f94c 100644 --- a/examples/csma-multicast.cc +++ b/examples/csma-multicast.cc @@ -172,14 +172,14 @@ main (int argc, char *argv[]) // std::ofstream ascii; ascii.open ("csma-multicast.tr"); - CsmaHelper::EnableAscii (ascii); + CsmaHelper::EnableAsciiAll (ascii); // Also configure some tcpdump traces; each interface will be traced. // The output files will be named: // csma-multicast.pcap-- // and can be read by the "tcpdump -r" command (use "-tt" option to // display timestamps correctly) - CsmaHelper::EnablePcap ("csma-multicast"); + CsmaHelper::EnablePcapAll ("csma-multicast"); // // Now, do the actual simulation. // diff --git a/examples/csma-one-subnet.cc b/examples/csma-one-subnet.cc index f7db8ea9b..f95effdda 100644 --- a/examples/csma-one-subnet.cc +++ b/examples/csma-one-subnet.cc @@ -128,7 +128,7 @@ main (int argc, char *argv[]) NS_LOG_INFO ("Configure Tracing."); std::ofstream ascii; ascii.open ("csma-one-subnet.tr"); - CsmaHelper::EnableAscii (ascii); + CsmaHelper::EnableAsciiAll (ascii); // // Also configure some tcpdump traces; each interface will be traced. // The output files will be named: @@ -136,7 +136,7 @@ main (int argc, char *argv[]) // and can be read by the "tcpdump -r" command (use "-tt" option to // display timestamps correctly) // - CsmaHelper::EnablePcap ("csma-one-subnet"); + CsmaHelper::EnablePcapAll ("csma-one-subnet"); // // Now, do the actual simulation. // diff --git a/examples/mixed-global-routing.cc b/examples/mixed-global-routing.cc index 2b5153f8b..2c665cb0c 100644 --- a/examples/mixed-global-routing.cc +++ b/examples/mixed-global-routing.cc @@ -125,10 +125,10 @@ main (int argc, char *argv[]) std::ofstream ascii; ascii.open ("mixed-global-routing.tr"); - PointToPointHelper::EnablePcap ("mixed-global-routing"); - PointToPointHelper::EnableAscii (ascii); - CsmaHelper::EnablePcap ("mixed-global-routing"); - CsmaHelper::EnableAscii (ascii); + PointToPointHelper::EnablePcapAll ("mixed-global-routing"); + PointToPointHelper::EnableAsciiAll (ascii); + CsmaHelper::EnablePcapAll ("mixed-global-routing"); + CsmaHelper::EnableAsciiAll (ascii); NS_LOG_INFO ("Run Simulation."); diff --git a/examples/mixed-wireless.cc b/examples/mixed-wireless.cc index 36a506959..eb4b5f357 100644 --- a/examples/mixed-wireless.cc +++ b/examples/mixed-wireless.cc @@ -335,8 +335,8 @@ main (int argc, char *argv[]) // asciiTrace.TraceNetDeviceRx ("/NodeList/11|13/DeviceList/0"); std::ofstream ascii; ascii.open ("mixed-wireless.tr"); - WifiHelper::EnableAscii (ascii); - CsmaHelper::EnableAscii (ascii); + WifiHelper::EnableAsciiAll (ascii); + CsmaHelper::EnableAsciiAll (ascii); // Let's do a pcap trace on the backbone devices WifiHelper::EnablePcap ("mixed-wireless.pcap", backboneDevices); diff --git a/examples/simple-alternate-routing.cc b/examples/simple-alternate-routing.cc index 5d4b5f34c..34e1981cd 100644 --- a/examples/simple-alternate-routing.cc +++ b/examples/simple-alternate-routing.cc @@ -159,8 +159,8 @@ main (int argc, char *argv[]) std::ofstream ascii; ascii.open ("simple-alternate-routing.tr"); - PointToPointHelper::EnablePcap ("simple-alternate-routing"); - PointToPointHelper::EnableAscii (ascii); + PointToPointHelper::EnablePcapAll ("simple-alternate-routing"); + PointToPointHelper::EnableAsciiAll (ascii); NS_LOG_INFO ("Run Simulation."); Simulator::Run (); diff --git a/examples/simple-error-model.cc b/examples/simple-error-model.cc index 249523391..72a9e4638 100644 --- a/examples/simple-error-model.cc +++ b/examples/simple-error-model.cc @@ -173,8 +173,8 @@ main (int argc, char *argv[]) std::ofstream ascii; ascii.open ("simple-error-model.tr"); - PointToPointHelper::EnablePcap ("simple-error-model"); - PointToPointHelper::EnableAscii (ascii); + PointToPointHelper::EnablePcapAll ("simple-error-model"); + PointToPointHelper::EnableAsciiAll (ascii); NS_LOG_INFO ("Run Simulation."); Simulator::Run (); diff --git a/examples/simple-global-routing.cc b/examples/simple-global-routing.cc index 36c91f2f4..19e86c70e 100644 --- a/examples/simple-global-routing.cc +++ b/examples/simple-global-routing.cc @@ -151,8 +151,8 @@ main (int argc, char *argv[]) std::ofstream ascii; ascii.open ("simple-global-routing.tr"); - PointToPointHelper::EnablePcap ("simple-global-routing"); - PointToPointHelper::EnableAscii (ascii); + PointToPointHelper::EnablePcapAll ("simple-global-routing"); + PointToPointHelper::EnableAsciiAll (ascii); NS_LOG_INFO ("Run Simulation."); Simulator::Run (); diff --git a/examples/simple-point-to-point-olsr.cc b/examples/simple-point-to-point-olsr.cc index da726fa5d..de6a63224 100644 --- a/examples/simple-point-to-point-olsr.cc +++ b/examples/simple-point-to-point-olsr.cc @@ -158,8 +158,8 @@ main (int argc, char *argv[]) std::ofstream ascii; ascii.open ("simple-point-to-point-olsr.tr"); - PointToPointHelper::EnablePcap ("simple-point-to-point-olsr"); - PointToPointHelper::EnableAscii (ascii); + PointToPointHelper::EnablePcapAll ("simple-point-to-point-olsr"); + PointToPointHelper::EnableAsciiAll (ascii); Simulator::StopAt (Seconds (30)); diff --git a/examples/tcp-large-transfer.cc b/examples/tcp-large-transfer.cc index 5c7f27e6a..d7982cf75 100644 --- a/examples/tcp-large-transfer.cc +++ b/examples/tcp-large-transfer.cc @@ -188,9 +188,9 @@ int main (int argc, char *argv[]) std::ofstream ascii; ascii.open ("tcp-large-transfer.tr"); - PointToPointHelper::EnableAscii (ascii); + PointToPointHelper::EnableAsciiAll (ascii); - InternetStackHelper::EnablePcap ("tcp-large-transfer"); + InternetStackHelper::EnablePcapAll ("tcp-large-transfer"); Simulator::StopAt (Seconds(1000)); Simulator::Run (); diff --git a/examples/udp-echo.cc b/examples/udp-echo.cc index d568e38c4..0bcaded48 100644 --- a/examples/udp-echo.cc +++ b/examples/udp-echo.cc @@ -128,8 +128,8 @@ main (int argc, char *argv[]) std::ofstream ascii; ascii.open ("udp-echo.tr"); - CsmaHelper::EnablePcap ("udp-echo"); - CsmaHelper::EnableAscii (ascii); + CsmaHelper::EnablePcapAll ("udp-echo"); + CsmaHelper::EnableAsciiAll (ascii); // // Now, do the actual simulation. diff --git a/src/helper/csma-helper.cc b/src/helper/csma-helper.cc index 7efa559ba..c86665589 100644 --- a/src/helper/csma-helper.cc +++ b/src/helper/csma-helper.cc @@ -103,7 +103,7 @@ CsmaHelper::EnablePcap (std::string filename, NodeContainer n) } void -CsmaHelper::EnablePcap (std::string filename) +CsmaHelper::EnablePcapAll (std::string filename) { EnablePcap (filename, NodeContainer::GetGlobal ()); } @@ -150,7 +150,7 @@ CsmaHelper::EnableAscii (std::ostream &os, NodeContainer n) } void -CsmaHelper::EnableAscii (std::ostream &os) +CsmaHelper::EnableAsciiAll (std::ostream &os) { EnableAscii (os, NodeContainer::GetGlobal ()); } diff --git a/src/helper/csma-helper.h b/src/helper/csma-helper.h index e83d98c82..ae4057549 100644 --- a/src/helper/csma-helper.h +++ b/src/helper/csma-helper.h @@ -115,7 +115,7 @@ public: * Enable pcap output on each device which is of the * ns3::CsmaNetDevice type */ - static void EnablePcap (std::string filename); + static void EnablePcapAll (std::string filename); /** * \param os output stream @@ -154,7 +154,7 @@ public: * ns3::CsmaNetDevice type and dump that to the specified * stdc++ output stream. */ - static void EnableAscii (std::ostream &os); + static void EnableAsciiAll (std::ostream &os); /** * \param c a set of nodes diff --git a/src/helper/internet-stack-helper.cc b/src/helper/internet-stack-helper.cc index 39728beec..8285f29d8 100644 --- a/src/helper/internet-stack-helper.cc +++ b/src/helper/internet-stack-helper.cc @@ -50,7 +50,7 @@ InternetStackHelper::Install (NodeContainer c) } void -InternetStackHelper::EnablePcap (std::string filename) +InternetStackHelper::EnablePcapAll (std::string filename) { InternetStackHelper::m_pcapBaseFilename = filename; Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Tx", diff --git a/src/helper/internet-stack-helper.h b/src/helper/internet-stack-helper.h index 19ddf1bcb..9241ee3a0 100644 --- a/src/helper/internet-stack-helper.h +++ b/src/helper/internet-stack-helper.h @@ -50,7 +50,7 @@ public: * Enable pcap output on each protocol instance which is of the * ns3::Ipv4L3Protocol type. Both Tx and Rx events will be logged. */ - static void EnablePcap (std::string filename); + static void EnablePcapAll (std::string filename); private: static void LogRxIp (std::string context, Ptr packet, uint32_t deviceId); diff --git a/src/helper/mobility-helper.h b/src/helper/mobility-helper.h index 761b47a13..c5d442886 100644 --- a/src/helper/mobility-helper.h +++ b/src/helper/mobility-helper.h @@ -171,7 +171,7 @@ public: * position allocator (set through MobilityHelper::SetPositionAllocator). * Optionally, this method will also create and aggregate a * ns3::MobilityModelNotifier to generate 'CourseChange' events based on the - * boolean flag set by MobilityHelper::EnableNotifier and MobilityHelper::DisableNotifier. + * boolean flag set by MobilityHelper::EnableNotifierAll and MobilityHelper::DisableNotifier. */ void Install (NodeContainer container); diff --git a/src/helper/point-to-point-helper.cc b/src/helper/point-to-point-helper.cc index 8f4543325..34689895c 100644 --- a/src/helper/point-to-point-helper.cc +++ b/src/helper/point-to-point-helper.cc @@ -103,7 +103,7 @@ PointToPointHelper::EnablePcap (std::string filename, NodeContainer n) } void -PointToPointHelper::EnablePcap (std::string filename) +PointToPointHelper::EnablePcapAll (std::string filename) { EnablePcap (filename, NodeContainer::GetGlobal ()); } @@ -150,7 +150,7 @@ PointToPointHelper::EnableAscii (std::ostream &os, NodeContainer n) } void -PointToPointHelper::EnableAscii (std::ostream &os) +PointToPointHelper::EnableAsciiAll (std::ostream &os) { EnableAscii (os, NodeContainer::GetGlobal ()); } diff --git a/src/helper/point-to-point-helper.h b/src/helper/point-to-point-helper.h index fd9ee396d..487942692 100644 --- a/src/helper/point-to-point-helper.h +++ b/src/helper/point-to-point-helper.h @@ -114,7 +114,7 @@ public: * Enable pcap output on each device which is of the * ns3::PointToPointNetDevice type */ - static void EnablePcap (std::string filename); + static void EnablePcapAll (std::string filename); /** * \param os output stream @@ -153,7 +153,7 @@ public: * ns3::PointToPointNetDevice type and dump that to the specified * stdc++ output stream. */ - static void EnableAscii (std::ostream &os); + static void EnableAsciiAll (std::ostream &os); /** * \param c a set of nodes diff --git a/src/helper/wifi-helper.cc b/src/helper/wifi-helper.cc index 4176608d1..6fb069d04 100644 --- a/src/helper/wifi-helper.cc +++ b/src/helper/wifi-helper.cc @@ -184,7 +184,7 @@ WifiHelper::EnablePcap (std::string filename, NodeContainer n) } void -WifiHelper::EnablePcap (std::string filename) +WifiHelper::EnablePcapAll (std::string filename) { EnablePcap (filename, NodeContainer::GetGlobal ()); } @@ -225,7 +225,7 @@ WifiHelper::EnableAscii (std::ostream &os, NodeContainer n) } void -WifiHelper::EnableAscii (std::ostream &os) +WifiHelper::EnableAsciiAll (std::ostream &os) { EnableAscii (os, NodeContainer::GetGlobal ()); } diff --git a/src/helper/wifi-helper.h b/src/helper/wifi-helper.h index 261c8fce6..2cc1108c3 100644 --- a/src/helper/wifi-helper.h +++ b/src/helper/wifi-helper.h @@ -176,7 +176,7 @@ public: * Enable pcap output on each device which is of the * ns3::WifiNetDevice type */ - static void EnablePcap (std::string filename); + static void EnablePcapAll (std::string filename); /** * \param os output stream @@ -215,7 +215,7 @@ public: * ns3::WifiNetDevice type and dump that to the specified * stdc++ output stream. */ - static void EnableAscii (std::ostream &os); + static void EnableAsciiAll (std::ostream &os); /** * \param c a set of nodes diff --git a/tutorial/tutorial-bus-network.cc b/tutorial/tutorial-bus-network.cc index 814b58245..246c8d516 100644 --- a/tutorial/tutorial-bus-network.cc +++ b/tutorial/tutorial-bus-network.cc @@ -68,7 +68,7 @@ main (int argc, char *argv[]) std::ofstream ascii; ascii.open ("tutorial.tr"); - CsmaHelper::EnableAscii (ascii); + CsmaHelper::EnableAsciiAll (ascii); Simulator::Run (); Simulator::Destroy (); diff --git a/tutorial/tutorial-csma-echo-ascii-trace.cc b/tutorial/tutorial-csma-echo-ascii-trace.cc index 03606c677..d5efb6c68 100644 --- a/tutorial/tutorial-csma-echo-ascii-trace.cc +++ b/tutorial/tutorial-csma-echo-ascii-trace.cc @@ -65,7 +65,7 @@ main (int argc, char *argv[]) std::ofstream os; os.open ("tutorial.tr"); - CsmaHelper::EnableAscii (os); + CsmaHelper::EnableAsciiAll (os); Simulator::Run (); Simulator::Destroy (); diff --git a/tutorial/tutorial-csma-echo-pcap-trace.cc b/tutorial/tutorial-csma-echo-pcap-trace.cc index 4db6f500c..2e7f87917 100644 --- a/tutorial/tutorial-csma-echo-pcap-trace.cc +++ b/tutorial/tutorial-csma-echo-pcap-trace.cc @@ -61,7 +61,7 @@ main (int argc, char *argv[]) apps.Start (Seconds (1.0)); apps.Stop (Seconds (10.0)); - CsmaHelper::EnablePcap ("tutorial"); + CsmaHelper::EnablePcapAll ("tutorial"); Simulator::Run (); Simulator::Destroy (); diff --git a/tutorial/tutorial-linear-dumbbell.cc b/tutorial/tutorial-linear-dumbbell.cc index c5b56cb66..68c5ab2b8 100644 --- a/tutorial/tutorial-linear-dumbbell.cc +++ b/tutorial/tutorial-linear-dumbbell.cc @@ -137,11 +137,11 @@ main (int argc, char *argv[]) std::ofstream os; os.open ("tutorial.tr"); - PointToPointHelper::EnableAscii (os); - CsmaHelper::EnableAscii (os); + PointToPointHelper::EnableAsciiAll (os); + CsmaHelper::EnableAsciiAll (os); - PointToPointHelper::EnablePcap ("tutorial"); - CsmaHelper::EnablePcap ("tutorial"); + PointToPointHelper::EnablePcapAll ("tutorial"); + CsmaHelper::EnablePcapAll ("tutorial"); Simulator::Run (); Simulator::Destroy (); diff --git a/tutorial/tutorial-point-to-point.cc b/tutorial/tutorial-point-to-point.cc index a71d20052..5c8913cf7 100644 --- a/tutorial/tutorial-point-to-point.cc +++ b/tutorial/tutorial-point-to-point.cc @@ -71,7 +71,7 @@ main (int argc, char *argv[]) std::ofstream ascii; ascii.open ("tutorial.tr"); - PointToPointHelper::EnableAscii (ascii); + PointToPointHelper::EnableAsciiAll (ascii); Simulator::Run (); Simulator::Destroy (); diff --git a/tutorial/tutorial-star-routing.cc b/tutorial/tutorial-star-routing.cc index 71a8582e6..ec7e6ceef 100644 --- a/tutorial/tutorial-star-routing.cc +++ b/tutorial/tutorial-star-routing.cc @@ -101,7 +101,7 @@ main (int argc, char *argv[]) std::ofstream ascii; ascii.open ("tutorial.tr"); - PointToPointHelper::EnableAscii (ascii); + PointToPointHelper::EnableAsciiAll (ascii); Simulator::Run (); Simulator::Destroy (); diff --git a/tutorial/tutorial-star.cc b/tutorial/tutorial-star.cc index 573e78b2c..2f5b5721e 100644 --- a/tutorial/tutorial-star.cc +++ b/tutorial/tutorial-star.cc @@ -98,7 +98,7 @@ main (int argc, char *argv[]) std::ofstream ascii; ascii.open ("tutorial.tr"); - PointToPointHelper::EnableAscii (ascii); + PointToPointHelper::EnableAsciiAll (ascii); Simulator::Run (); Simulator::Destroy (); From 9fd7fbb86cd6b6a95b1a8e36b98e228c429df852 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Tue, 22 Apr 2008 22:08:53 -0700 Subject: [PATCH 6/8] Fix two nits that escaped checkin --- examples/mixed-wireless.cc | 4 ++-- samples/main-random-walk.cc | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/mixed-wireless.cc b/examples/mixed-wireless.cc index 515a1a455..05dbcf0a4 100644 --- a/examples/mixed-wireless.cc +++ b/examples/mixed-wireless.cc @@ -166,7 +166,7 @@ main (int argc, char *argv[]) "Bounds", RectangleValue (Rectangle (0, 1000, 0, 1000)), "Speed", RandomVariableValue (ConstantVariable (2000)), "Pause", RandomVariableValue (ConstantVariable (0.2))); - mobility.Layout (backbone); + mobility.Install (backbone); /////////////////////////////////////////////////////////////////////////// // // @@ -275,7 +275,7 @@ main (int argc, char *argv[]) "Bounds", RectangleValue (Rectangle (-25, 25, -25, 25)), "Speed", RandomVariableValue (ConstantVariable (30)), "Pause", RandomVariableValue (ConstantVariable (0.4))); - mobility.Layout (infra); + mobility.Install (infra); } /////////////////////////////////////////////////////////////////////////// // // diff --git a/samples/main-random-walk.cc b/samples/main-random-walk.cc index 4e951c2d6..1ce1ae0ac 100644 --- a/samples/main-random-walk.cc +++ b/samples/main-random-walk.cc @@ -41,7 +41,7 @@ int main (int argc, char *argv[]) "Time", StringValue ("2s"), "Speed", StringValue ("Constant:1.0"), "Bounds", StringValue ("0:200:0:100")); - mobility.LayoutAll (); + mobility.InstallAll (); Config::Connect ("/NodeList/*/$ns3::MobilityModelNotifier/CourseChange", MakeCallback (&CourseChange)); From 3752943c225251955544743bd9caadce918c1c0c Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Tue, 22 Apr 2008 22:29:16 -0700 Subject: [PATCH 7/8] bug 131 partial fix: split out Send and DataSent callbacks --- src/internet-node/tcp-socket.cc | 9 +++++++++ src/node/socket.cc | 22 ++++++++++++++++++++-- src/node/socket.h | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/internet-node/tcp-socket.cc b/src/internet-node/tcp-socket.cc index ac52efd2d..ef6a40dc2 100644 --- a/src/internet-node/tcp-socket.cc +++ b/src/internet-node/tcp-socket.cc @@ -370,6 +370,9 @@ int TcpSocket::Send (const uint8_t* buf, uint32_t 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 ()); if (!ProcessAction (action)) { return -1; // Failed, return zero @@ -689,6 +692,9 @@ 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 ()); } SendPendingData (); break; @@ -1077,6 +1083,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 ()); if (ack > m_nextTxSequence) { m_nextTxSequence = ack; // If advanced diff --git a/src/node/socket.cc b/src/node/socket.cc index 0bf9e95b4..51eacfe03 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -64,11 +64,19 @@ Socket::SetAcceptCallback ( m_closeRequested = closeRequested; } -void -Socket::SetSendCallback (Callback, uint32_t> dataSent) +bool +Socket::SetDataSentCallback (Callback, uint32_t> dataSent) { NS_LOG_FUNCTION_NOARGS (); m_dataSent = dataSent; + return true; +} + +void +Socket::SetSendCallback (Callback, uint32_t> sendCb) +{ + NS_LOG_FUNCTION_NOARGS (); + m_sendCb = sendCb; } void @@ -202,6 +210,16 @@ Socket::NotifyDataSent (uint32_t size) } } +void +Socket::NotifySend (uint32_t spaceAvailable) +{ + NS_LOG_FUNCTION_NOARGS (); + if (!m_sendCb.IsNull ()) + { + m_sendCb (this, spaceAvailable); + } +} + void Socket::NotifyDataReceived (Ptr p, const Address &from) { diff --git a/src/node/socket.h b/src/node/socket.h index bf5e1c8d4..f7ab43456 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -120,7 +120,36 @@ public: Callback, const Address&> newConnectionCreated, Callback > closeRequested); - void SetSendCallback (Callback, uint32_t> dataSent); + /** + * \brief Notify application when a packet has been sent from transport + * protocol (non-standard socket call) + * \param dataSent Callback for the event that data is sent from the + * underlying transport protocol. This callback is passed a + * pointer to the socket, and the number of bytes sent. + * \returns whether or not this socket supports this callback. Note + * that this is a non-standard socket call. Some socket + * implementations in ns-3 may not support this call, so the + * user should check this return value to confirm that the + * callback is supported. + */ + virtual bool SetDataSentCallback (Callback, uint32_t> dataSent); + /** + * \brief Notify application when space in transmit buffer is added + * + * This callback is intended to notify a + * socket that would have been blocked in a blocking socket model + * that some data has been acked and removed from the transmit + * buffer, and that it can call send again. The semantics for + * reliable stream sockets are that when data is acked and removed + * from the transmit buffer, this callback is invoked. + * + * \param sendCb Callback for the event that the socket transmit buffer + * fill level has decreased. This callback is passed a pointer to + * the socket, and the number of bytes available for writing + * into the buffer (an absolute value). If there is no transmit + * 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. @@ -232,6 +261,7 @@ protected: void NotifyNewConnectionCreated (Ptr socket, const Address &from); void NotifyCloseRequested (void); void NotifyDataSent (uint32_t size); + void NotifySend (uint32_t spaceAvailable); void NotifyDataReceived (Ptr p, const Address &from); Callback > m_closeCompleted; @@ -242,6 +272,7 @@ protected: Callback, const Address &> m_connectionRequest; Callback, const Address&> m_newConnectionCreated; Callback, uint32_t> m_dataSent; + Callback, uint32_t > m_sendCb; Callback, Ptr,const Address&> m_receivedData; }; From b998a05ccecfbf2fbc219969cf8348aa810c8514 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Tue, 22 Apr 2008 22:39:17 -0700 Subject: [PATCH 8/8] A few minor cleanups to socket.h/cc --- src/node/socket.cc | 12 ++++++------ src/node/socket.h | 40 ++++++++++++++++++++-------------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/node/socket.cc b/src/node/socket.cc index 51eacfe03..41f09f879 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -86,6 +86,12 @@ Socket::SetRecvCallback (Callback, Ptr,const Address&> m_receivedData = receivedData; } +int Socket::Listen (uint32_t queueLimit) +{ + return 0; //XXX the base class version does nothing +} + + int Socket::Send (const uint8_t* buf, uint32_t size) { NS_LOG_FUNCTION_NOARGS (); @@ -116,12 +122,6 @@ int Socket::SendTo (const Address &address, const uint8_t* buf, uint32_t size) return SendTo (address,p); } -int Socket::Listen(uint32_t queueLimit) -{ - return 0; //XXX the base class version does nothing -} - - void Socket::NotifyCloseCompleted (void) { diff --git a/src/node/socket.h b/src/node/socket.h index f7ab43456..07a267ee7 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -38,9 +38,11 @@ class Packet; * \brief Define a Socket API based on the BSD Socket API. * * Contrary to the original BSD socket API, this API is asynchronous: - * it does not contain blocking calls. Other than that, it tries to stick - * to the BSD API to make it easier those who know the BSD API to use - * this API. + * 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. */ class Socket : public Object { @@ -94,8 +96,8 @@ public: * Or when I call Close ? */ void SetConnectCallback (Callback > connectionSucceeded, - Callback > connectionFailed, - Callback > halfClose); + Callback > connectionFailed, + Callback > halfClose); /** * \brief Accept connection requests from remote hosts * \param connectionRequest Callback for connection request from peer. @@ -138,10 +140,8 @@ public: * * This callback is intended to notify a * socket that would have been blocked in a blocking socket model - * that some data has been acked and removed from the transmit - * buffer, and that it can call send again. The semantics for - * reliable stream sockets are that when data is acked and removed - * from the transmit buffer, this callback is invoked. + * that space is available in the transmit buffer and that it + * can call Send() again. * * \param sendCb Callback for the event that the socket transmit buffer * fill level has decreased. This callback is passed a pointer to @@ -179,7 +179,7 @@ public: * After the Close call, the socket is no longer valid, and cannot * safely be used for subsequent operations. */ - virtual int Close(void) = 0; + virtual int Close (void) = 0; /** * \returns zero on success, -1 on failure. @@ -201,8 +201,15 @@ public: * \brief Initiate a connection to a remote host * \param address Address of remote. */ - virtual int Connect(const Address &address) = 0; + virtual int Connect (const Address &address) = 0; + /** + * \brief Listen for incoming connections. + * \param queueLimit maximum number of incoming request to queue + * \returns XXX an error code + */ + virtual int Listen (uint32_t queueLimit); + /** * \brief Send data (or dummy data) to the remote host * \param p packet to send @@ -229,14 +236,7 @@ public: * \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; - - /** - * \brief Listen for incoming connections. - * \param queueLimit maximum number of incoming request to queue - * \returns XXX an error code - */ - virtual int Listen(uint32_t queueLimit); + virtual int SendTo (const Address &address,Ptr p) = 0; /** * \brief Send data to a specified peer. @@ -250,7 +250,7 @@ public: * 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 Address &address, const uint8_t* buf, uint32_t size); protected: void NotifyCloseCompleted (void);