Files
ns-3-dev/examples/udp-client-server/udp-client-server.cc
T
Mitch Watrous 75845a078e Move applications to a single module
--HG--
rename : src/helper/bulk-send-helper.cc => src/applications/helper/bulk-send-helper.cc
rename : src/helper/bulk-send-helper.h => src/applications/helper/bulk-send-helper.h
rename : src/helper/on-off-helper.cc => src/applications/helper/on-off-helper.cc
rename : src/helper/on-off-helper.h => src/applications/helper/on-off-helper.h
rename : src/helper/packet-sink-helper.cc => src/applications/helper/packet-sink-helper.cc
rename : src/helper/packet-sink-helper.h => src/applications/helper/packet-sink-helper.h
rename : src/helper/ping6-helper.cc => src/applications/helper/ping6-helper.cc
rename : src/helper/ping6-helper.h => src/applications/helper/ping6-helper.h
rename : src/helper/udp-client-server-helper.cc => src/applications/helper/udp-client-server-helper.cc
rename : src/helper/udp-client-server-helper.h => src/applications/helper/udp-client-server-helper.h
rename : src/helper/udp-echo-helper.cc => src/applications/helper/udp-echo-helper.cc
rename : src/helper/udp-echo-helper.h => src/applications/helper/udp-echo-helper.h
rename : src/helper/v4ping-helper.cc => src/applications/helper/v4ping-helper.cc
rename : src/helper/v4ping-helper.h => src/applications/helper/v4ping-helper.h
rename : src/applications/bulk-send/bulk-send-application.cc => src/applications/model/bulk-send-application.cc
rename : src/applications/bulk-send/bulk-send-application.h => src/applications/model/bulk-send-application.h
rename : src/applications/onoff/onoff-application.cc => src/applications/model/onoff-application.cc
rename : src/applications/onoff/onoff-application.h => src/applications/model/onoff-application.h
rename : src/applications/udp-client-server/packet-loss-counter.cc => src/applications/model/packet-loss-counter.cc
rename : src/applications/udp-client-server/packet-loss-counter.h => src/applications/model/packet-loss-counter.h
rename : src/applications/packet-sink/packet-sink.cc => src/applications/model/packet-sink.cc
rename : src/applications/packet-sink/packet-sink.h => src/applications/model/packet-sink.h
rename : src/applications/ping6/ping6.cc => src/applications/model/ping6.cc
rename : src/applications/ping6/ping6.h => src/applications/model/ping6.h
rename : src/applications/radvd/radvd-interface.cc => src/applications/model/radvd-interface.cc
rename : src/applications/radvd/radvd-interface.h => src/applications/model/radvd-interface.h
rename : src/applications/radvd/radvd-prefix.cc => src/applications/model/radvd-prefix.cc
rename : src/applications/radvd/radvd-prefix.h => src/applications/model/radvd-prefix.h
rename : src/applications/radvd/radvd.cc => src/applications/model/radvd.cc
rename : src/applications/radvd/radvd.h => src/applications/model/radvd.h
rename : src/applications/udp-client-server/seq-ts-header.cc => src/applications/model/seq-ts-header.cc
rename : src/applications/udp-client-server/seq-ts-header.h => src/applications/model/seq-ts-header.h
rename : src/applications/udp-client-server/udp-client.cc => src/applications/model/udp-client.cc
rename : src/applications/udp-client-server/udp-client.h => src/applications/model/udp-client.h
rename : src/applications/udp-echo/udp-echo-client.cc => src/applications/model/udp-echo-client.cc
rename : src/applications/udp-echo/udp-echo-client.h => src/applications/model/udp-echo-client.h
rename : src/applications/udp-echo/udp-echo-server.cc => src/applications/model/udp-echo-server.cc
rename : src/applications/udp-echo/udp-echo-server.h => src/applications/model/udp-echo-server.h
rename : src/applications/udp-client-server/udp-server.cc => src/applications/model/udp-server.cc
rename : src/applications/udp-client-server/udp-server.h => src/applications/model/udp-server.h
rename : src/applications/udp-client-server/udp-trace-client.cc => src/applications/model/udp-trace-client.cc
rename : src/applications/udp-client-server/udp-trace-client.h => src/applications/model/udp-trace-client.h
rename : src/applications/v4ping/v4ping.cc => src/applications/model/v4ping.cc
rename : src/applications/v4ping/v4ping.h => src/applications/model/v4ping.h
rename : src/applications/udp-client-server/udp-client-server-test.cc => src/applications/test/udp-client-server-test.cc
2011-03-02 13:42:28 -08:00

105 lines
3.0 KiB
C++

/* -*- 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
*/
// Network topology
//
// n0 n1
// | |
// =======
// LAN
//
// - UDP flows from n0 to n1
#include <fstream>
#include "ns3/core-module.h"
#include "ns3/helper-module.h"
#include "ns3/applications-module.h"
using namespace ns3;
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);
//
// Explicitly create the nodes required by the topology (shown above).
//
NS_LOG_INFO ("Create nodes.");
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).
//
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate(5000000)));
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
csma.SetDeviceAttribute ("Mtu", UintegerValue (1400));
NetDeviceContainer d = csma.Install (n);
Ipv4AddressHelper ipv4;
//
// We've got the "hardware" in place. Now we need to add IP addresses.
//
NS_LOG_INFO ("Assign IP Addresses.");
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer i = ipv4.Assign (d);
NS_LOG_INFO ("Create Applications.");
//
// Create one udpServer applications on node one.
//
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.
//
uint32_t MaxPacketSize = 1024;
Time interPacketInterval = Seconds (0.05);
uint32_t maxPacketCount = 320;
UdpClientHelper client (i.GetAddress (1), port);
client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
client.SetAttribute ("Interval", TimeValue (interPacketInterval));
client.SetAttribute ("PacketSize", UintegerValue (MaxPacketSize));
apps = client.Install (n.Get (0));
apps.Start (Seconds (2.0));
apps.Stop (Seconds (10.0));
//
// Now, do the actual simulation.
//
NS_LOG_INFO ("Run Simulation.");
Simulator::Run ();
Simulator::Destroy ();
NS_LOG_INFO ("Done.");
}