Merge with ns-3-dev.
This commit is contained in:
104
examples/udp-client-server/udp-client-server.cc
Normal file
104
examples/udp-client-server/udp-client-server.cc
Normal file
@@ -0,0 +1,104 @@
|
||||
/* -*- 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/simulator-module.h"
|
||||
#include "ns3/helper-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.");
|
||||
}
|
||||
100
examples/udp-client-server/udp-trace-client-server.cc
Normal file
100
examples/udp-client-server/udp-trace-client-server.cc
Normal file
@@ -0,0 +1,100 @@
|
||||
/* -*- 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/simulator-module.h"
|
||||
#include "ns3/helper-module.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
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);
|
||||
|
||||
//
|
||||
// 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 UdpTraceClient application to send UDP datagrams from node zero to
|
||||
// node one.
|
||||
//
|
||||
uint32_t MaxPacketSize = 1400;
|
||||
UdpTraceClientHelper client (i.GetAddress (1), port,"");
|
||||
client.SetAttribute ("MaxPacketSize", 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.");
|
||||
}
|
||||
1
examples/udp-client-server/waf
vendored
Normal file
1
examples/udp-client-server/waf
vendored
Normal file
@@ -0,0 +1 @@
|
||||
exec "`dirname "$0"`"/../../waf "$@"
|
||||
8
examples/udp-client-server/wscript
Normal file
8
examples/udp-client-server/wscript
Normal file
@@ -0,0 +1,8 @@
|
||||
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
|
||||
|
||||
def build(bld):
|
||||
obj = bld.create_ns3_program('udp-client-server', ['csma', 'internet-stack'])
|
||||
obj.source = 'udp-client-server.cc'
|
||||
|
||||
obj = bld.create_ns3_program('udp-trace-client-server', ['csma', 'internet-stack'])
|
||||
obj.source = 'udp-trace-client-server.cc'
|
||||
@@ -20,3 +20,4 @@ def build(bld):
|
||||
bld.add_subdirs('tutorial')
|
||||
bld.add_subdirs('udp')
|
||||
bld.add_subdirs('wireless')
|
||||
bld.add_subdirs('udp-client-server')
|
||||
|
||||
Reference in New Issue
Block a user