fix bug 234 which changes required methods on helpers to constructor parameters. Update tutorial content to reflect. Change RemoteIpv4 attribute to RemoteAddress.
authorCraig Dowell <craigdo@ee.washington.edu>
Thu, 03 Jul 2008 17:37:32 -0700
changeset 3382 d5f8e5fae1c6
parent 3381 3cdd9d60f7c7
child 3383 f21d3d5926b9
fix bug 234 which changes required methods on helpers to constructor parameters. Update tutorial content to reflect. Change RemoteIpv4 attribute to RemoteAddress.
doc/tutorial/building-topologies.texi
doc/tutorial/conceptual-overview.texi
doc/tutorial/tweaking.texi
examples/first.cc
examples/second.cc
examples/third.cc
examples/udp-echo.cc
src/applications/udp-echo/udp-echo-client.cc
src/helper/udp-echo-helper.cc
src/helper/udp-echo-helper.h
--- a/doc/tutorial/building-topologies.texi	Thu Jul 03 15:44:54 2008 -0700
+++ b/doc/tutorial/building-topologies.texi	Thu Jul 03 17:37:32 2008 -0700
@@ -149,8 +149,8 @@
 
 @verbatim
   PointToPointHelper pointToPoint;
-  pointToPoint.SetDeviceParameter ("DataRate", StringValue ("5Mbps"));
-  pointToPoint.SetChannelParameter ("Delay", StringValue ("2ms"));
+  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
 
   NetDeviceContainer p2pDevices;
   p2pDevices = pointToPoint.Install (p2pNodes);
@@ -227,9 +227,15 @@
 nodes that has a CSMA node and the client on the node having only a 
 point-to-point device.
 
-First, we set up the echo server.
+First, we set up the echo server.  We create a @code{UdpEchoServerHelper} and
+provide a required attribute value to the constructor which is the server port
+number.  Recall that this port can be changed later using the 
+@code{SetAttribute} method if desired, but we require it to be provided to
+the constructor.
 
 @verbatim
+  UdpEchoServerHelper echoServer (9);
+
   ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (nCsma));
   serverApps.Start (Seconds (1.0));
   serverApps.Stop (Seconds (10.0));
@@ -246,16 +252,17 @@
 code.
 
 The client application is set up exactly as we did in the @code{first.cc}
-example script.  We tell the client to send packets to the server we just
-installed on the last of the ``extra'' CSMA nodes.  We install the client on
-the leftmost point-to-point node seen in the topology illustration.
+example script.  Again, we provide required attributes to the 
+@code{UdpEchoClientHelper} in the constructor (in this case the remote address
+and port).  We tell the client to send packets to the server we just installed
+on the last of the ``extra'' CSMA nodes.  We install the client on the 
+leftmost point-to-point node seen in the topology illustration.
 
 @verbatim
-  UdpEchoClientHelper echoClient;
-  echoClient.SetRemote (csmaInterfaces.GetAddress (nCsma), 9);
-  echoClient.SetAppAttribute ("MaxPackets", UintegerValue (1));
-  echoClient.SetAppAttribute ("Interval", TimeValue (Seconds (1.)));
-  echoClient.SetAppAttribute ("PacketSize", UintegerValue (1024));
+  UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 9);
+  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
+  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
+  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
 
   ApplicationContainer clientApps = echoClient.Install (p2pNodes.Get (0));
   clientApps.Start (Seconds (2.0));
@@ -669,8 +676,8 @@
 
 @verbatim
   PointToPointHelper pointToPoint;
-  pointToPoint.SetDeviceParameter ("DataRate", StringValue ("5Mbps"));
-  pointToPoint.SetChannelParameter ("Delay", StringValue ("2ms"));
+  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
 
   NetDeviceContainer p2pDevices;
   p2pDevices = pointToPoint.Install (p2pNodes);
@@ -964,8 +971,7 @@
 start of the file.  We have done this before.
 
 @verbatim
-  UdpEchoServerHelper echoServer;
-  echoServer.SetPort (9);
+  UdpEchoServerHelper echoServer (9);
 
   ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (nCsma));
   serverApps.Start (Seconds (1.0));
@@ -976,11 +982,10 @@
 the server on the CSMA network.  We have also seen similar operations before.
 
 @verbatim
-  UdpEchoClientHelper echoClient;
-  echoClient.SetRemote (csmaInterfaces.GetAddress (nCsma), 9);
-  echoClient.SetAppAttribute ("MaxPackets", UintegerValue (1));
-  echoClient.SetAppAttribute ("Interval", TimeValue (Seconds (1.)));
-  echoClient.SetAppAttribute ("PacketSize", UintegerValue (1024));
+  UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 9);
+  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
+  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
+  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
 
   ApplicationContainer clientApps =
     echoClient.Install (wifiStaNodes.Get (nWifi - 1));
--- a/doc/tutorial/conceptual-overview.texi	Thu Jul 03 15:44:54 2008 -0700
+++ b/doc/tutorial/conceptual-overview.texi	Thu Jul 03 17:37:32 2008 -0700
@@ -420,8 +420,8 @@
 
 @verbatim
     PointToPointHelper pointToPoint;
-    pointToPoint.SetDeviceParameter ("DataRate", StringValue ("5Mbps"));
-    pointToPoint.SetChannelParameter ("Delay", StringValue ("2ms"));
+    pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+    pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
 @end verbatim
 
 The first line 
@@ -434,7 +434,7 @@
 high-level perspective the next line,
 
 @verbatim
-    pointToPoint.SetDeviceParameter ("DataRate", StringValue ("5Mbps"));
+    pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
 @end verbatim
 
 tells the @code{PointToPointHelper} object to use the value ``5mbps''
@@ -455,7 +455,7 @@
 final line,
 
 @verbatim
-    pointToPoint.SetChannelParameter ("Delay", StringValue ("2ms"));
+    pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
 @end verbatim
 
 tells the @code{PointToPointHelper} to use the value ``2ms'' (two milliseconds)
@@ -565,8 +565,7 @@
 created.
 
 @verbatim
-    UdpEchoServerHelper echoServer;
-    echoServer.SetPort (9);
+    UdpEchoServerHelper echoServer (9);
 
     ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
     serverApps.Start (Seconds (1.0));
@@ -575,10 +574,14 @@
 
 The first line of code in the above snippet declares the 
 @code{UdpEchoServerHelper}.  As usual, this isn't the application itself, it
-is an object used to help us create the actual applications.  The second line
-that has the @code{SetPort} call, is used to tell the helper to assign the
-value nine to the ``Port'' attribute when creating 
-@code{UdpEchoServerApplication} objects.
+is an object used to help us create the actual applications.  One of our 
+conventions is place required attributes in the helper constructor.  In this
+case, the helper can't do anything useful unless it is provided with a port
+number that the client also knows about.  Rather than just picking one and
+hoping it all works out, we require the port number as a parameter to the 
+constructor.  The constructor, in turn, simply does a @code{SetAttribute}
+with the passed value.  You can, if desired, set the ``Port'' attribute to
+another value later.
 
 Similar to many other helper objects, the @code{UdpEchoServerHelper} object 
 has an @code{Install} method.  It is the execution of this method that actually
--- a/doc/tutorial/tweaking.texi	Thu Jul 03 15:44:54 2008 -0700
+++ b/doc/tutorial/tweaking.texi	Thu Jul 03 17:37:32 2008 -0700
@@ -462,8 +462,8 @@
 
 @verbatim
     PointToPointHelper pointToPoint;
-    pointToPoint.SetDeviceParameter ("DataRate", StringValue ("5Mbps"));
-    pointToPoint.SetChannelParameter ("Delay", StringValue ("2ms"));
+    pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+    pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
 @end verbatim
 
 and mentioned that @code{DataRate} was actually an @code{Attribute} of the 
@@ -486,10 +486,10 @@
 @end verbatim
 
 This is the default value that will be used when a @code{PointToPointNetDevice}
-is created in the system.  We overrode this default with the ``parameter''
+is created in the system.  We overrode this default with the attribute
 setting in the @code{PointToPointHelper} above.  Let's use the default values 
 for the point-to-point devices and channels by deleting the 
-@code{SetDeviceParameter} call and the @code{SetChannelParameter} call from 
+@code{SetDeviceAttribute} call and the @code{SetChannelAttribute} call from 
 the @code{first.cc} we have in the scratch directory.
 
 Your script should now just declare the @code{PointToPointHelper} and not do 
--- a/examples/first.cc	Thu Jul 03 15:44:54 2008 -0700
+++ b/examples/first.cc	Thu Jul 03 17:37:32 2008 -0700
@@ -33,8 +33,8 @@
   nodes.Create (2);
 
   PointToPointHelper pointToPoint;
-  pointToPoint.SetDeviceParameter ("DataRate", StringValue ("5Mbps"));
-  pointToPoint.SetChannelParameter ("Delay", StringValue ("2ms"));
+  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
 
   NetDeviceContainer devices;
   devices = pointToPoint.Install (nodes);
@@ -47,18 +47,16 @@
 
   Ipv4InterfaceContainer interfaces = address.Assign (devices);
 
-  UdpEchoServerHelper echoServer;
-  echoServer.SetPort (9);
+  UdpEchoServerHelper echoServer (9);
 
   ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
   serverApps.Start (Seconds (1.0));
   serverApps.Stop (Seconds (10.0));
 
-  UdpEchoClientHelper echoClient;
-  echoClient.SetRemote (interfaces.GetAddress (1), 9);
-  echoClient.SetAppAttribute ("MaxPackets", UintegerValue (1));
-  echoClient.SetAppAttribute ("Interval", TimeValue (Seconds (1.)));
-  echoClient.SetAppAttribute ("PacketSize", UintegerValue (1024));
+  UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
+  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
+  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
+  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
 
   ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
   clientApps.Start (Seconds (2.0));
--- a/examples/second.cc	Thu Jul 03 15:44:54 2008 -0700
+++ b/examples/second.cc	Thu Jul 03 17:37:32 2008 -0700
@@ -52,8 +52,8 @@
   csmaNodes.Create (nCsma);
 
   PointToPointHelper pointToPoint;
-  pointToPoint.SetDeviceParameter ("DataRate", StringValue ("5Mbps"));
-  pointToPoint.SetChannelParameter ("Delay", StringValue ("2ms"));
+  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
 
   NetDeviceContainer p2pDevices;
   p2pDevices = pointToPoint.Install (p2pNodes);
@@ -76,18 +76,16 @@
   Ipv4InterfaceContainer csmaInterfaces;
   csmaInterfaces = address.Assign (csmaDevices);
 
-  UdpEchoServerHelper echoServer;
-  echoServer.SetPort (9);
+  UdpEchoServerHelper echoServer (9);
 
   ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (nCsma));
   serverApps.Start (Seconds (1.0));
   serverApps.Stop (Seconds (10.0));
 
-  UdpEchoClientHelper echoClient;
-  echoClient.SetRemote (csmaInterfaces.GetAddress (nCsma), 9);
-  echoClient.SetAppAttribute ("MaxPackets", UintegerValue (1));
-  echoClient.SetAppAttribute ("Interval", TimeValue (Seconds (1.)));
-  echoClient.SetAppAttribute ("PacketSize", UintegerValue (1024));
+  UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 9);
+  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
+  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
+  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
 
   ApplicationContainer clientApps = echoClient.Install (p2pNodes.Get (0));
   clientApps.Start (Seconds (2.0));
--- a/examples/third.cc	Thu Jul 03 15:44:54 2008 -0700
+++ b/examples/third.cc	Thu Jul 03 17:37:32 2008 -0700
@@ -54,8 +54,8 @@
   p2pNodes.Create (2);
 
   PointToPointHelper pointToPoint;
-  pointToPoint.SetDeviceParameter ("DataRate", StringValue ("5Mbps"));
-  pointToPoint.SetChannelParameter ("Delay", StringValue ("2ms"));
+  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
 
   NetDeviceContainer p2pDevices;
   p2pDevices = pointToPoint.Install (p2pNodes);
@@ -141,18 +141,16 @@
   address.Assign (staDevices);
   address.Assign (apDevices);
 
-  UdpEchoServerHelper echoServer;
-  echoServer.SetPort (9);
+  UdpEchoServerHelper echoServer (9);
 
   ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (nCsma));
   serverApps.Start (Seconds (1.0));
   serverApps.Stop (Seconds (10.0));
 
-  UdpEchoClientHelper echoClient;
-  echoClient.SetRemote (csmaInterfaces.GetAddress (nCsma), 9);
-  echoClient.SetAppAttribute ("MaxPackets", UintegerValue (1));
-  echoClient.SetAppAttribute ("Interval", TimeValue (Seconds (1.)));
-  echoClient.SetAppAttribute ("PacketSize", UintegerValue (1024));
+  UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 9);
+  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
+  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
+  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
 
   ApplicationContainer clientApps = 
     echoClient.Install (wifiStaNodes.Get (nWifi - 1));
--- a/examples/udp-echo.cc	Thu Jul 03 15:44:54 2008 -0700
+++ b/examples/udp-echo.cc	Thu Jul 03 17:37:32 2008 -0700
@@ -104,8 +104,7 @@
 // Create a UdpEchoServer application on node one.
 //
   uint16_t port = 9;  // well-known echo port number
-  UdpEchoServerHelper server;
-  server.SetPort (port);
+  UdpEchoServerHelper server (port);
   ApplicationContainer apps = server.Install (n.Get(1));
   apps.Start (Seconds (1.0));
   apps.Stop (Seconds (10.0));
@@ -117,11 +116,10 @@
   uint32_t packetSize = 1024;
   uint32_t maxPacketCount = 1;
   Time interPacketInterval = Seconds (1.);
-  UdpEchoClientHelper client;
-  client.SetRemote (i.GetAddress (1), port);
-  client.SetAppAttribute ("MaxPackets", UintegerValue (maxPacketCount));
-  client.SetAppAttribute ("Interval", TimeValue (interPacketInterval));
-  client.SetAppAttribute ("PacketSize", UintegerValue (packetSize));
+  UdpEchoClientHelper client (i.GetAddress (1), port);
+  client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
+  client.SetAttribute ("Interval", TimeValue (interPacketInterval));
+  client.SetAttribute ("PacketSize", UintegerValue (packetSize));
   apps = client.Install (n.Get (0));
   apps.Start (Seconds (2.0));
   apps.Stop (Seconds (10.0));
--- a/src/applications/udp-echo/udp-echo-client.cc	Thu Jul 03 15:44:54 2008 -0700
+++ b/src/applications/udp-echo/udp-echo-client.cc	Thu Jul 03 17:37:32 2008 -0700
@@ -47,8 +47,8 @@
                    TimeValue (Seconds (1.0)),
                    MakeTimeAccessor (&UdpEchoClient::m_interval),
                    MakeTimeChecker ())
-    .AddAttribute ("RemoteIpv4", 
-                   "The Ipv4Address of the outbound packets",
+    .AddAttribute ("RemoteAddress", 
+                   "The destination Ipv4Address of the outbound packets",
                    Ipv4AddressValue (),
                    MakeIpv4AddressAccessor (&UdpEchoClient::m_peerAddress),
                    MakeIpv4AddressChecker ())
--- a/src/helper/udp-echo-helper.cc	Thu Jul 03 15:44:54 2008 -0700
+++ b/src/helper/udp-echo-helper.cc	Thu Jul 03 17:37:32 2008 -0700
@@ -24,15 +24,21 @@
 
 namespace ns3 {
 
-UdpEchoServerHelper::UdpEchoServerHelper ()
-  : m_port (9)
-{}
+UdpEchoServerHelper::UdpEchoServerHelper (uint16_t port)
+{
+  m_factory.SetTypeId (UdpEchoServer::GetTypeId ());
+  SetAttribute ("Port", UintegerValue(port));
+}
 
 void 
-UdpEchoServerHelper::SetPort (uint16_t port)
+UdpEchoServerHelper::SetAttribute (
+  std::string name, 
+  const AttributeValue &value)
 {
-  m_port = port;
+  m_factory.Set (name, value);
 }
+
+
 ApplicationContainer 
 UdpEchoServerHelper::Install (NodeContainer c)
 {
@@ -40,25 +46,24 @@
   for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
     {
       Ptr<Node> node = *i;
-      Ptr<UdpEchoServer> server = CreateObject<UdpEchoServer> ("Port", UintegerValue (m_port));
+      Ptr<UdpEchoServer> server = m_factory.Create<UdpEchoServer> ();
       node->AddApplication (server);
       apps.Add (server);
     }
   return apps;
 }
 
-UdpEchoClientHelper::UdpEchoClientHelper ()
+UdpEchoClientHelper::UdpEchoClientHelper (Ipv4Address address, uint16_t port)
 {
   m_factory.SetTypeId (UdpEchoClient::GetTypeId ());
+  SetAttribute ("RemoteAddress", Ipv4AddressValue (address));
+  SetAttribute ("RemotePort", UintegerValue (port));
 }
+
 void 
-UdpEchoClientHelper::SetRemote (Ipv4Address ip, uint16_t port)
-{
-  m_remoteIp = ip;
-  m_remotePort = port;
-}
-void 
-UdpEchoClientHelper::SetAppAttribute (std::string name, const AttributeValue &value)
+UdpEchoClientHelper::SetAttribute (
+  std::string name, 
+  const AttributeValue &value)
 {
   m_factory.Set (name, value);
 }
@@ -71,13 +76,10 @@
     {
       Ptr<Node> node = *i;
       Ptr<UdpEchoClient> client = m_factory.Create<UdpEchoClient> ();
-      client->SetRemote (m_remoteIp, m_remotePort);
       node->AddApplication (client);
       apps.Add (client);
     }
   return apps;  
 }
 
-
-
 } // namespace ns3
--- a/src/helper/udp-echo-helper.h	Thu Jul 03 15:44:54 2008 -0700
+++ b/src/helper/udp-echo-helper.h	Thu Jul 03 17:37:32 2008 -0700
@@ -31,25 +31,25 @@
 class UdpEchoServerHelper
 {
 public:
-  UdpEchoServerHelper ();
-  void SetPort (uint16_t port);
+  UdpEchoServerHelper (uint16_t port);
+
+  void SetAttribute (std::string name, const AttributeValue &value);
   ApplicationContainer Install (NodeContainer c);
-private:
-  uint16_t m_port;
+
+ private:
+  ObjectFactory m_factory;
 };
 
 class UdpEchoClientHelper
 {
 public:
-  UdpEchoClientHelper ();
+  UdpEchoClientHelper (Ipv4Address ip, uint16_t port);
 
-  void SetRemote (Ipv4Address ip, uint16_t port);
-  void SetAppAttribute (std::string name, const AttributeValue &value);
+  void SetAttribute (std::string name, const AttributeValue &value);
   ApplicationContainer Install (NodeContainer c);
+
  private:
   ObjectFactory m_factory;
-  Ipv4Address m_remoteIp;
-  uint16_t m_remotePort;
 };