--- a/examples/udp-echo.cc Thu Mar 27 12:20:14 2008 -0700
+++ b/examples/udp-echo.cc Thu Mar 27 12:20:26 2008 -0700
@@ -25,28 +25,11 @@
// - DropTail queues
// - Tracing of queues and packet receptions to file "udp-echo.tr"
-#include "ns3/command-line.h"
-#include "ns3/ptr.h"
-#include "ns3/log.h"
-#include "ns3/simulator.h"
-#include "ns3/nstime.h"
-#include "ns3/data-rate.h"
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/helper-module.h"
#include "ns3/ascii-trace.h"
#include "ns3/pcap-trace.h"
-#include "ns3/internet-node.h"
-#include "ns3/csma-channel.h"
-#include "ns3/csma-net-device.h"
-#include "ns3/csma-topology.h"
-#include "ns3/csma-ipv4-topology.h"
-#include "ns3/mac48-address.h"
-#include "ns3/ipv4-address.h"
-#include "ns3/inet-socket-address.h"
-#include "ns3/ipv4.h"
-#include "ns3/socket.h"
-#include "ns3/ipv4-route.h"
-#include "ns3/udp-echo-client.h"
-#include "ns3/udp-echo-server.h"
-#include "ns3/uinteger.h"
using namespace ns3;
@@ -94,75 +77,40 @@
// Explicitly create the nodes required by the topology (shown above).
//
NS_LOG_INFO ("Create nodes.");
- Ptr<Node> n0 = CreateObject<InternetNode> ();
- Ptr<Node> n1 = CreateObject<InternetNode> ();
- Ptr<Node> n2 = CreateObject<InternetNode> ();
- Ptr<Node> n3 = CreateObject<InternetNode> ();
+ NodeContainer n;
+ n.Create (4);
+
+ InternetStackHelper internet;
+ internet.Build (n);
NS_LOG_INFO ("Create channels.");
//
// Explicitly create the channels required by the topology (shown above).
//
- Ptr<CsmaChannel> lan = CsmaTopology::CreateCsmaChannel(
- DataRate(5000000), MilliSeconds(2));
+ CsmaHelper csma;
+ csma.SetChannelParameter ("BitRate", DataRate(5000000));
+ csma.SetChannelParameter ("Delay", MilliSeconds (2));
+ NetDeviceContainer d = csma.Build (n);
- NS_LOG_INFO ("Build Topology.");
-//
-// Now fill out the topology by creating the net devices required to connect
-// the nodes to the channels and hooking them up. AddIpv4CsmaNetDevice will
-// create a net device, add a MAC address (in memory of the pink flamingo) and
-// connect the net device to a nodes and also to a channel. the
-// AddIpv4CsmaNetDevice method returns a net device index for the net device
-// created on the node. Interpret nd0 as the net device we created for node
-// zero.
-//
- uint32_t nd0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, lan,
- Mac48Address("08:00:2e:00:00:00"));
-
- uint32_t nd1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, lan,
- Mac48Address("08:00:2e:00:00:01"));
-
- uint32_t nd2 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan,
- Mac48Address("08:00:2e:00:00:02"));
-
- uint32_t nd3 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan,
- Mac48Address("08:00:2e:00:00:03"));
+ Ipv4AddressHelper ipv4;
//
// We've got the "hardware" in place. Now we need to add IP addresses.
//
NS_LOG_INFO ("Assign IP Addresses.");
-//
-// XXX BUGBUG
-// Need a better way to get the interface index. The point-to-point topology
-// as implemented can't return the index since it creates interfaces on both
-// sides (i.e., it does AddIpv4Addresses, not AddIpv4Address). We need a
-// method on Ipv4 to find the interface index corresponding to a given ipv4
-// address.
-//
-// Assign IP addresses to the net devices and associated interfaces
-// on the lan. The AddIpv4Address method returns an Ipv4 interface index
-// which we do not need here.
-//
- CsmaIpv4Topology::AddIpv4Address (n0, nd0, Ipv4Address("10.1.1.1"),
- Ipv4Mask("255.255.255.0"));
-
- CsmaIpv4Topology::AddIpv4Address (n1, nd1, Ipv4Address("10.1.1.2"),
- Ipv4Mask("255.255.255.0"));
-
- CsmaIpv4Topology::AddIpv4Address (n2, nd2, Ipv4Address("10.1.1.3"),
- Ipv4Mask("255.255.255.0"));
-
- CsmaIpv4Topology::AddIpv4Address (n3, nd3, Ipv4Address("10.1.1.4"),
- Ipv4Mask("255.255.255.0"));
+ ipv4.SetBase ("10.1.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer i = ipv4.Allocate (d);
NS_LOG_INFO ("Create Applications.");
//
// Create a UdpEchoServer application on node one.
//
uint16_t port = 9; // well-known echo port number
+ UdpEchoServerHelper server;
+ server.SetPort (port);
+ ApplicationContainer apps = server.Build (n.Get(1));
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
- Ptr<UdpEchoServer> server = CreateObject<UdpEchoServer> ("Port", Uinteger (port));
- n1->AddApplication (server);
//
// Create a UdpEchoClient application to send UDP datagrams from node zero to
// node one.
@@ -170,22 +118,15 @@
uint32_t packetSize = 1024;
uint32_t maxPacketCount = 1;
Time interPacketInterval = Seconds (1.);
+ UdpEchoClientHelper client;
+ client.SetRemote (i.GetAddress (1), port);
+ client.SetAppAttribute ("MaxPackets", Uinteger (maxPacketCount));
+ client.SetAppAttribute ("Interval", interPacketInterval);
+ client.SetAppAttribute ("PacketSize", Uinteger (packetSize));
+ apps = client.Build (n.Get (0));
+ apps.Start (Seconds (2.0));
+ apps.Stop (Seconds (10.0));
- Ptr<UdpEchoClient> client =
- CreateObject<UdpEchoClient> ("RemoteIpv4", Ipv4Address ("10.1.1.2"),
- "RemotePort", Uinteger (port),
- "MaxPackets", Uinteger (maxPacketCount),
- "Interval", interPacketInterval,
- "PacketSize", Uinteger (packetSize));
- n0->AddApplication (client);
-//
-// Tell the applications when to start and stop.
-//
- server->Start(Seconds(1.));
- client->Start(Seconds(2.));
-
- server->Stop (Seconds(10.));
- client->Stop (Seconds(10.));
//
// Configure tracing of all enqueue, dequeue, and NetDevice receive events.
// Trace output will be sent to the file "udp-echo.tr"
--- a/src/helper/wscript Thu Mar 27 12:20:14 2008 -0700
+++ b/src/helper/wscript Thu Mar 27 12:20:26 2008 -0700
@@ -18,6 +18,7 @@
'packet-sink-helper.cc',
'packet-socket-helper.cc',
'ipv4-interface-container.cc',
+ 'udp-echo-helper.cc',
]
headers = bld.create_obj('ns3header')
@@ -38,4 +39,5 @@
'packet-sink-helper.h',
'packet-socket-helper.h',
'ipv4-interface-container.h',
+ 'udp-echo-helper.h',
]