diff --git a/examples/udp-client-server/udp-client-server.cc b/examples/udp-client-server/udp-client-server.cc index f31b3a62d..1dbc36238 100644 --- a/examples/udp-client-server/udp-client-server.cc +++ b/examples/udp-client-server/udp-client-server.cc @@ -1,5 +1,7 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* + * Copyright (c) 2009 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; @@ -12,6 +14,8 @@ * 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: Mohamed Amine Ismail */ // Network topology @@ -19,9 +23,11 @@ // n0 n1 // | | // ======= -// LAN +// LAN (CSMA) // -// - UDP flows from n0 to n1 +// - UDP flow from n0 to n1 of 320 packets of 1024 bytes at intervals of 50 ms +// - option to use IPv4 or IPv6 addressing +// - option to disable logging statements #include #include "ns3/core-module.h" @@ -36,42 +42,36 @@ NS_LOG_COMPONENT_DEFINE ("UdpClientServerExample"); int main (int argc, char *argv[]) { -// -// Enable logging for UdpClient and -// - LogComponentEnable ("UdpClient", LOG_LEVEL_INFO); - LogComponentEnable ("UdpServer", LOG_LEVEL_INFO); - + // Declare variables used in command-line arguments bool useV6 = false; + bool logging = true; Address serverAddress; CommandLine cmd (__FILE__); cmd.AddValue ("useIpv6", "Use Ipv6", useV6); + cmd.AddValue ("logging", "Enable logging", logging); cmd.Parse (argc, argv); -// -// Explicitly create the nodes required by the topology (shown above). -// - NS_LOG_INFO ("Create nodes."); + if (logging) + { + LogComponentEnable ("UdpClient", LOG_LEVEL_INFO); + LogComponentEnable ("UdpServer", LOG_LEVEL_INFO); + } + + NS_LOG_INFO ("Create nodes in above topology."); NodeContainer n; n.Create (2); InternetStackHelper internet; internet.Install (n); - NS_LOG_INFO ("Create channels."); -// -// Explicitly create the channels required by the topology (shown above). -// + NS_LOG_INFO ("Create channel between the two nodes."); CsmaHelper csma; csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000))); csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2))); csma.SetDeviceAttribute ("Mtu", UintegerValue (1400)); NetDeviceContainer d = csma.Install (n); -// -// We've got the "hardware" in place. Now we need to add IP addresses. -// NS_LOG_INFO ("Assign IP Addresses."); if (useV6 == false) { @@ -88,20 +88,14 @@ main (int argc, char *argv[]) serverAddress = Address(i6.GetAddress (1,1)); } - NS_LOG_INFO ("Create Applications."); -// -// Create one udpServer applications on node one. -// + NS_LOG_INFO ("Create UdpServer application on node 1."); uint16_t port = 4000; UdpServerHelper server (port); ApplicationContainer apps = server.Install (n.Get (1)); apps.Start (Seconds (1.0)); apps.Stop (Seconds (10.0)); -// -// Create one UdpClient application to send UDP datagrams from node zero to -// node one. -// + NS_LOG_INFO ("Create UdpClient application on node 0 to send to node 1."); uint32_t MaxPacketSize = 1024; Time interPacketInterval = Seconds (0.05); uint32_t maxPacketCount = 320; @@ -113,9 +107,6 @@ main (int argc, char *argv[]) apps.Start (Seconds (2.0)); apps.Stop (Seconds (10.0)); -// -// Now, do the actual simulation. -// NS_LOG_INFO ("Run Simulation."); Simulator::Run (); Simulator::Destroy (); diff --git a/examples/udp-client-server/udp-trace-client-server.cc b/examples/udp-client-server/udp-trace-client-server.cc index 9eae5218a..2b6d5574a 100644 --- a/examples/udp-client-server/udp-trace-client-server.cc +++ b/examples/udp-client-server/udp-trace-client-server.cc @@ -1,5 +1,7 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* + * Copyright (c) 2009 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; @@ -12,6 +14,8 @@ * 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: Mohamed Amine Ismail */ // Network topology @@ -19,9 +23,11 @@ // n0 n1 // | | // ======= -// LAN +// LAN (CSMA) // -// - UDP flows from n0 to n1 +// - UDP flow from n0 to n1 of packets drawn from a trace file +// -- option to use IPv4 or IPv6 addressing +// -- option to disable logging statements #include #include "ns3/core-module.h" @@ -36,42 +42,36 @@ NS_LOG_COMPONENT_DEFINE ("UdpTraceClientServerExample"); int main (int argc, char *argv[]) { -// -// Enable logging for UdpClient and -// - LogComponentEnable ("UdpTraceClient", LOG_LEVEL_INFO); - LogComponentEnable ("UdpServer", LOG_LEVEL_INFO); - + // Declare variables used in command-line arguments bool useV6 = false; + bool logging = true; Address serverAddress; CommandLine cmd (__FILE__); cmd.AddValue ("useIpv6", "Use Ipv6", useV6); + cmd.AddValue ("logging", "Enable logging", logging); cmd.Parse (argc, argv); -// -// Explicitly create the nodes required by the topology (shown above). -// - NS_LOG_INFO ("Create nodes."); + if (logging) + { + LogComponentEnable ("UdpClient", LOG_LEVEL_INFO); + LogComponentEnable ("UdpServer", LOG_LEVEL_INFO); + } + + NS_LOG_INFO ("Create nodes in above topology."); NodeContainer n; n.Create (2); InternetStackHelper internet; internet.Install (n); - NS_LOG_INFO ("Create channels."); -// -// Explicitly create the channels required by the topology (shown above). -// + NS_LOG_INFO ("Create channel between the two nodes."); CsmaHelper csma; csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000))); csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2))); csma.SetDeviceAttribute ("Mtu", UintegerValue (1500)); NetDeviceContainer d = csma.Install (n); -// -// We've got the "hardware" in place. Now we need to add IP addresses. -// NS_LOG_INFO ("Assign IP Addresses."); if (useV6 == false) { @@ -88,20 +88,14 @@ main (int argc, char *argv[]) serverAddress = Address(i6.GetAddress (1,1)); } - NS_LOG_INFO ("Create Applications."); -// -// Create one udpServer applications on node one. -// + NS_LOG_INFO ("Create UdpServer application on node 1."); uint16_t port = 4000; UdpServerHelper server (port); ApplicationContainer apps = server.Install (n.Get (1)); apps.Start (Seconds (1.0)); apps.Stop (Seconds (10.0)); -// -// Create one UdpTraceClient application to send UDP datagrams from node zero to -// node one. -// + NS_LOG_INFO ("Create UdpClient application on node 0 to send to node 1."); uint32_t MaxPacketSize = 1472; // Back off 20 (IP) + 8 (UDP) bytes from MTU UdpTraceClientHelper client (serverAddress, port,""); client.SetAttribute ("MaxPacketSize", UintegerValue (MaxPacketSize)); @@ -109,9 +103,6 @@ main (int argc, char *argv[]) apps.Start (Seconds (2.0)); apps.Stop (Seconds (10.0)); -// -// Now, do the actual simulation. -// NS_LOG_INFO ("Run Simulation."); Simulator::Run (); Simulator::Destroy ();