port Applications to Attributes

This commit is contained in:
Mathieu Lacage
2008-02-27 00:05:23 +01:00
parent 1ae525bf0e
commit e5e35f6545
35 changed files with 586 additions and 506 deletions

View File

@@ -154,30 +154,36 @@ main (int argc, char *argv[])
// Create the OnOff application to send UDP datagrams of size
// 512 bytes (default) at a rate of 500 Kb/s (default) from n0
NS_LOG_INFO ("Create Applications.");
Ptr<OnOffApplication> ooff = CreateObject<OnOffApplication> (
n0,
InetSocketAddress ("255.255.255.255", port),
"Udp",
ConstantVariable(1),
ConstantVariable(0));
Ptr<OnOffApplication> ooff =
CreateObjectWith<OnOffApplication> (
"Node", n0,
"Remote", Address (InetSocketAddress ("255.255.255.255", port)),
"Protocol", TypeId::LookupByName ("Udp"),
"OnTime", ConstantVariable(1),
"OffTime", ConstantVariable(0));
n0->AddApplication (ooff);
// Start the application
ooff->Start(Seconds(1.0));
ooff->Stop (Seconds(10.0));
// Create an optional packet sink to receive these packets
Ptr<PacketSink> sink = CreateObject<PacketSink> (
n1,
InetSocketAddress (Ipv4Address::GetAny (), port),
"Udp");
Ptr<PacketSink> sink =
CreateObjectWith<PacketSink> (
"Node", n1,
"Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
"Protocol", TypeId::LookupByName ("Udp"));
n1->AddApplication (sink);
// Start the sink
sink->Start (Seconds (1.0));
sink->Stop (Seconds (10.0));
// Create an optional packet sink to receive these packets
sink = CreateObject<PacketSink> (
n2,
InetSocketAddress (Ipv4Address::GetAny (), port),
"Udp");
sink = CreateObjectWith<PacketSink> (
"Node", n2,
"Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
"Protocol", TypeId::LookupByName ("Udp"));
n2->AddApplication (sink);
// Start the sink
sink->Start (Seconds (1.0));
sink->Stop (Seconds (10.0));

View File

@@ -52,6 +52,7 @@
#include "ns3/ipv4-route.h"
#include "ns3/onoff-application.h"
#include "ns3/packet-sink.h"
#include "ns3/uinteger.h"
using namespace ns3;
@@ -281,14 +282,16 @@ main (int argc, char *argv[])
// Configure a multicast packet generator that generates a packet
// every few seconds
Ptr<OnOffApplication> ooff = CreateObject<OnOffApplication> (
n0,
InetSocketAddress (multicastGroup, port),
"Udp",
ConstantVariable(1),
ConstantVariable(0),
DataRate ("255b/s"),
128);
Ptr<OnOffApplication> ooff =
CreateObjectWith<OnOffApplication> (
"Node", n0,
"Remote", Address (InetSocketAddress (multicastGroup, port)),
"Protocol", TypeId::LookupByName ("Udp"),
"OnTime", ConstantVariable(1),
"OffTime", ConstantVariable(0),
"DataRate", MakeDataRate ("255b/s"),
"PacketSize", Uinteger (128));
n0->AddApplication (ooff);
//
// Tell the application when to start and stop.
//
@@ -298,10 +301,12 @@ main (int argc, char *argv[])
// Create an optional packet sink to receive these packets
// If you enable logging on this (above) it will print a log statement
// for every packet received
Ptr<PacketSink> sink = CreateObject<PacketSink> (
n4,
InetSocketAddress (Ipv4Address::GetAny (), port),
"Udp");
Ptr<PacketSink> sink =
CreateObjectWith<PacketSink> (
"Node", n4,
"Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
"Protocol", TypeId::LookupByName ("Udp"));
n4->AddApplication (sink);
// Start the sink
sink->Start (Seconds (1.0));
sink->Stop (Seconds (10.0));

View File

@@ -165,12 +165,15 @@ main (int argc, char *argv[])
//
NS_LOG_INFO ("Create Applications.");
uint16_t port = 9; // Discard port (RFC 863)
Ptr<OnOffApplication> ooff = CreateObject<OnOffApplication> (
n0,
InetSocketAddress ("10.1.1.2", port),
"Udp",
ConstantVariable(1),
ConstantVariable(0));
Ptr<OnOffApplication> ooff =
CreateObjectWith<OnOffApplication> (
"Node", n0,
"Remote", Address (InetSocketAddress ("10.1.1.2", port)),
"Protocol", TypeId::LookupByName ("Udp"),
"OnTime", ConstantVariable(1),
"OffTime", ConstantVariable(0));
n0->AddApplication (ooff);
//
// Tell the application when to start and stop.
//
@@ -179,12 +182,13 @@ main (int argc, char *argv[])
//
// Create a similar flow from n3 to n0, starting at time 1.1 seconds
//
ooff = CreateObject<OnOffApplication> (
n3,
InetSocketAddress ("10.1.1.1", port),
"Udp",
ConstantVariable(1),
ConstantVariable(0));
ooff = CreateObjectWith<OnOffApplication> (
"Node", n3,
"Remote", Address (InetSocketAddress ("10.1.1.1", port)),
"Protocol", TypeId::LookupByName ("Udp"),
"OnTime", ConstantVariable(1),
"OffTime", ConstantVariable(0));
n3->AddApplication (ooff);
ooff->Start(Seconds(1.1));
ooff->Stop (Seconds(10.0));

View File

@@ -136,23 +136,26 @@ main (int argc, char *argv[])
// 210 bytes at a rate of 448 Kb/s
// from n0 to n1
NS_LOG_INFO ("Create Applications.");
Ptr<OnOffApplication> ooff = CreateObject<OnOffApplication> (
n0,
n0ToN1,
"Packet",
ConstantVariable(1),
ConstantVariable(0));
Ptr<OnOffApplication> ooff =
CreateObjectWith<OnOffApplication> (
"Node", n0,
"Remote", Address (n0ToN1),
"Protocol", TypeId::LookupByName ("Packet"),
"OnTime", ConstantVariable(1),
"OffTime", ConstantVariable(0));
n0->AddApplication (ooff);
// Start the application
ooff->Start(Seconds(1.0));
ooff->Stop (Seconds(10.0));
// Create a similar flow from n3 to n0, starting at time 1.1 seconds
ooff = CreateObject<OnOffApplication> (
n3,
n3ToN0,
"Packet",
ConstantVariable(1),
ConstantVariable(0));
ooff = CreateObjectWith<OnOffApplication> (
"Node", n3,
"Remote", Address (n3ToN0),
"Protocol", TypeId::LookupByName ("Packet"),
"OnTime", ConstantVariable(1),
"OffTime", ConstantVariable(0));
n3->AddApplication (ooff);
// Start the application
ooff->Start(Seconds(1.1));
ooff->Stop (Seconds(10.0));

View File

@@ -42,6 +42,7 @@
#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/random-variable.h"
#include "ns3/config.h"
#include "ns3/simulator.h"
#include "ns3/nstime.h"
@@ -65,6 +66,7 @@
#include "ns3/point-to-point-topology.h"
#include "ns3/onoff-application.h"
#include "ns3/global-route-manager.h"
#include "ns3/uinteger.h"
using namespace ns3;
@@ -110,10 +112,8 @@ main (int argc, char *argv[])
// topology code
DefaultValue::Bind ("Queue", "DropTailQueue");
DefaultValue::Bind ("OnOffApplicationPacketSize", "210");
DefaultValue::Bind ("OnOffApplicationDataRate", "448kb/s");
//DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30);
Config::SetDefault ("OnOffApplication::PacketSize", Uinteger (210));
Config::SetDefault ("OnOffApplication::DataRate", MakeDataRate ("448kb/s"));
// Allow the user to override any of the defaults and the above
// Bind ()s at run-time, via command-line arguments
@@ -191,14 +191,16 @@ main (int argc, char *argv[])
// 210 bytes at a rate of 448 Kb/s
NS_LOG_INFO ("Create Applications.");
uint16_t port = 9; // Discard port (RFC 863)
Ptr<OnOffApplication> ooff = CreateObject<OnOffApplication> (
n0,
InetSocketAddress ("10.1.3.2", port),
"Udp",
ConstantVariable (1),
ConstantVariable (0),
DataRate("300bps"),
50);
Ptr<OnOffApplication> ooff =
CreateObjectWith<OnOffApplication> (
"Node", n0,
"Remote", Address (InetSocketAddress ("10.1.3.2", port)),
"Protocol", TypeId::LookupByName ("Udp"),
"OnTime", ConstantVariable (1),
"OffTime", ConstantVariable (0),
"DataRate", MakeDataRate("300bps"),
"PacketSize", Uinteger (50));
n0->AddApplication (ooff);
// Start the application
ooff->Start (Seconds (1.0));
ooff->Stop (Seconds (10.0));

View File

@@ -43,6 +43,8 @@
#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/random-variable.h"
#include "ns3/config.h"
#include "ns3/uinteger.h"
#include "ns3/simulator.h"
#include "ns3/nstime.h"
@@ -105,8 +107,8 @@ main (int argc, char *argv[])
// instantiate, when the queue factory is invoked in the topology code
DefaultValue::Bind ("Queue", "DropTailQueue");
DefaultValue::Bind ("OnOffApplicationPacketSize", "210");
DefaultValue::Bind ("OnOffApplicationDataRate", "300b/s");
Config::SetDefault ("OnOffApplication::PacketSize", Uinteger (210));
Config::SetDefault ("OnOffApplication::DataRate", MakeDataRate ("300b/s"));
// The below metric, if set to 3 or higher, will cause packets between
// n1 and n3 to take the 2-hop route through n2
@@ -182,21 +184,25 @@ main (int argc, char *argv[])
uint16_t port = 9; // Discard port (RFC 863)
// Create a flow from n3 to n1, starting at time 1.1 seconds
Ptr<OnOffApplication> ooff = CreateObject<OnOffApplication> (
n3,
InetSocketAddress ("10.1.1.1", port),
"Udp",
ConstantVariable (1),
ConstantVariable (0));
Ptr<OnOffApplication> ooff =
CreateObjectWith<OnOffApplication> (
"Node", n3,
"Remote", Address (InetSocketAddress ("10.1.1.1", port)),
"Protocol", TypeId::LookupByName ("Udp"),
"OnTime", ConstantVariable (1),
"OffTime", ConstantVariable (0));
n3->AddApplication (ooff);
// Start the application
ooff->Start (Seconds (1.1));
ooff->Stop (Seconds (10.0));
// Create a packet sink to receive these packets
Ptr<PacketSink> sink = CreateObject<PacketSink> (
n1,
InetSocketAddress (Ipv4Address::GetAny (), port),
"Udp");
Ptr<PacketSink> sink =
CreateObjectWith<PacketSink> (
"Node", n1,
"Remote", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
"Protocol", TypeId::LookupByName ("Udp"));
n1->AddApplication (sink);
// Start the sink
sink->Start (Seconds (1.1));
sink->Stop (Seconds (10.0));

View File

@@ -43,6 +43,8 @@
#include "ns3/command-line.h"
#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/config.h"
#include "ns3/uinteger.h"
#include "ns3/simulator.h"
#include "ns3/nstime.h"
@@ -79,15 +81,12 @@ main (int argc, char *argv[])
LogComponentEnable ("SimplePointToPointExample", LOG_LEVEL_INFO);
#endif
// Set up some default values for the simulation. Use the Bind()
// technique to tell the system what subclass of ErrorModel to use
DefaultValue::Bind ("ErrorModel", "RateErrorModel");
// Set a few parameters
DefaultValue::Bind ("RateErrorModelErrorRate", "0.01");
DefaultValue::Bind ("RateErrorModelErrorUnit", "EU_PKT");
DefaultValue::Bind ("OnOffApplicationPacketSize", "210");
DefaultValue::Bind ("OnOffApplicationDataRate", "448kb/s");
Config::SetDefault ("RateErrorModel::ErrorRate", Double (0.01));
Config::SetDefault ("RateErrorModel::ErrorUnit", "EU_PKT");
Config::SetDefault ("OnOffApplication::PacketSize", Uinteger (210));
Config::SetDefault ("OnOffApplication::DataRate", MakeDataRate ("448kb/s"));
// Allow the user to override any of the defaults and the above
@@ -143,41 +142,46 @@ main (int argc, char *argv[])
// 210 bytes at a rate of 448 Kb/s
NS_LOG_INFO ("Create Applications.");
uint16_t port = 9; // Discard port (RFC 863)
Ptr<OnOffApplication> ooff = CreateObject<OnOffApplication> (
n0,
InetSocketAddress ("10.1.3.2", port),
"Udp",
ConstantVariable(1),
ConstantVariable(0));
Ptr<OnOffApplication> ooff =
CreateObjectWith<OnOffApplication> (
"Node", n0,
"Remote", Address (InetSocketAddress ("10.1.3.2", port)),
"Protocol", TypeId::LookupByName ("Udp"),
"OnTime", ConstantVariable(1),
"OffTime", ConstantVariable(0));
n0->AddApplication (ooff);
// Start the application
ooff->Start(Seconds(1.0));
ooff->Stop (Seconds(10.0));
// Create an optional packet sink to receive these packets
Ptr<PacketSink> sink = CreateObject<PacketSink> (
n3,
InetSocketAddress (Ipv4Address::GetAny (), port),
"Udp");
Ptr<PacketSink> sink = CreateObjectWith<PacketSink> (
"Node", n3,
"Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
"Protocol", TypeId::LookupByName ("Udp"));
n3->AddApplication (sink);
// Start the sink
sink->Start (Seconds (1.0));
sink->Stop (Seconds (10.0));
// Create a similar flow from n3 to n1, starting at time 1.1 seconds
ooff = CreateObject<OnOffApplication> (
n3,
InetSocketAddress ("10.1.2.1", port),
"Udp",
ConstantVariable(1),
ConstantVariable(0));
ooff = CreateObjectWith<OnOffApplication> (
"Node", n3,
"Remote", Address (InetSocketAddress ("10.1.2.1", port)),
"Protocol", TypeId::LookupByName ("Udp"),
"OnTime", ConstantVariable(1),
"OffTime", ConstantVariable(0));
n3->AddApplication (ooff);
// Start the application
ooff->Start(Seconds(1.1));
ooff->Stop (Seconds(10.0));
// Create a packet sink to receive these packets
sink = CreateObject<PacketSink> (
n1,
InetSocketAddress (Ipv4Address::GetAny (), port),
"Udp");
sink = CreateObjectWith<PacketSink> (
"Node", n1,
"Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
"Protocol", TypeId::LookupByName ("Udp"));
n1->AddApplication (sink);
// Start the sink
sink->Start (Seconds (1.1));
sink->Stop (Seconds (10.0));

View File

@@ -48,6 +48,8 @@
#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/random-variable.h"
#include "ns3/config.h"
#include "ns3/uinteger.h"
#include "ns3/simulator.h"
#include "ns3/nstime.h"
@@ -110,8 +112,8 @@ main (int argc, char *argv[])
// instantiate, when the queue factory is invoked in the topology code
DefaultValue::Bind ("Queue", "DropTailQueue");
DefaultValue::Bind ("OnOffApplicationPacketSize", "210");
DefaultValue::Bind ("OnOffApplicationDataRate", "448kb/s");
Config::SetDefault ("OnOffApplication::PacketSize", Uinteger (210));
Config::SetDefault ("OnOffApplication::DataRate", MakeDataRate ("448kb/s"));
//DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30);
@@ -163,42 +165,45 @@ main (int argc, char *argv[])
// 210 bytes at a rate of 448 Kb/s
NS_LOG_INFO ("Create Applications.");
uint16_t port = 9; // Discard port (RFC 863)
Ptr<OnOffApplication> ooff = CreateObject<OnOffApplication> (
n0,
InetSocketAddress ("10.1.3.2", port),
"Udp",
ConstantVariable (1),
ConstantVariable (0));
Ptr<OnOffApplication> ooff =
CreateObjectWith<OnOffApplication> ("Node", n0,
"Remote", Address (InetSocketAddress ("10.1.3.2", port)),
"Protocol", TypeId::LookupByName ("Udp"),
"OnTime", ConstantVariable (1),
"OffTime", ConstantVariable (0));
n0->AddApplication (ooff);
// Start the application
ooff->Start (Seconds (1.0));
ooff->Stop (Seconds (10.0));
// Create a packet sink to receive these packets
// The last argument "true" disables output from the Receive callback
Ptr<PacketSink> sink = CreateObject<PacketSink> (
n3,
InetSocketAddress (Ipv4Address::GetAny (), port),
"Udp");
Ptr<PacketSink> sink =
CreateObjectWith<PacketSink> ("Node", n3,
"Remote", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
"Protocol", TypeId::LookupByName ("Udp"));
n3->AddApplication (sink);
// Start the sink
sink->Start (Seconds (1.0));
sink->Stop (Seconds (10.0));
// Create a similar flow from n3 to n1, starting at time 1.1 seconds
ooff = CreateObject<OnOffApplication> (
n3,
InetSocketAddress ("10.1.2.1", port),
"Udp",
ConstantVariable (1),
ConstantVariable (0));
ooff = CreateObjectWith<OnOffApplication> (
"Node", n3,
"Remote", Address (InetSocketAddress ("10.1.2.1", port)),
"Protocol", TypeId::LookupByName ("Udp"),
"OnTime", ConstantVariable (1),
"OffTime", ConstantVariable (0));
n3->AddApplication (ooff);
// Start the application
ooff->Start (Seconds (1.1));
ooff->Stop (Seconds (10.0));
// Create a packet sink to receive these packets
sink = CreateObject<PacketSink> (
n1,
InetSocketAddress (Ipv4Address::GetAny (), port),
"Udp");
sink = CreateObjectWith<PacketSink> ("Node", n1,
"Remote", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
"Protocol", TypeId::LookupByName ("Udp"));
n1->AddApplication (sink);
// Start the sink
sink->Start (Seconds (1.1));
sink->Stop (Seconds (10.0));

View File

@@ -43,6 +43,7 @@
#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/random-variable.h"
#include "ns3/config.h"
#include "ns3/simulator.h"
#include "ns3/nstime.h"
@@ -98,16 +99,10 @@ main (int argc, char *argv[])
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
#endif
// Set up some default values for the simulation. Use the Bind()
// technique to tell the system what subclass of Queue to use,
// and what the queue limit is
// Set up some default values for the simulation.
// The below Bind command tells the queue factory which class to
// instantiate, when the queue factory is invoked in the topology code
DefaultValue::Bind ("Queue", "DropTailQueue");
DefaultValue::Bind ("OnOffApplicationPacketSize", "210");
DefaultValue::Bind ("OnOffApplicationDataRate", "448kb/s");
Config::SetDefault ("OnOffApplication::PacketSize", "210");
Config::SetDefault ("OnOffApplication::DataRate", "448kb/s");
//DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30);
@@ -162,38 +157,44 @@ main (int argc, char *argv[])
// 210 bytes at a rate of 448 Kb/s
NS_LOG_INFO ("Create Applications.");
uint16_t port = 9; // Discard port (RFC 863)
Ptr<OnOffApplication> ooff = CreateObject<OnOffApplication> (
n0,
InetSocketAddress ("10.1.3.2", port),
"Udp",
ConstantVariable(1),
ConstantVariable(0));
Ptr<OnOffApplication> ooff =
CreateObjectWith<OnOffApplication> (
"Node", n0,
"Remote", Address (InetSocketAddress ("10.1.3.2", port)),
"Protocol", TypeId::LookupByName ("Udp"),
"OnTime", ConstantVariable(1),
"OffTime", ConstantVariable(0));
n0->AddApplication (ooff);
// Start the application
ooff->Start(Seconds(1.0));
// Create an optional packet sink to receive these packets
Ptr<PacketSink> sink = CreateObject<PacketSink> (
n3,
InetSocketAddress (Ipv4Address::GetAny (), port),
"Udp");
Ptr<PacketSink> sink =
CreateObjectWith<PacketSink> (
"Node", n3,
"Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
"Protocol", TypeId::LookupByName ("Udp"));
n3->AddApplication (sink);
// Start the sink
sink->Start (Seconds (1.0));
// Create a similar flow from n3 to n1, starting at time 1.1 seconds
ooff = CreateObject<OnOffApplication> (
n3,
InetSocketAddress ("10.1.2.1", port),
"Udp",
ConstantVariable(1),
ConstantVariable(0));
ooff = CreateObjectWith<OnOffApplication> (
"Node", n3,
"Remote", Address (InetSocketAddress ("10.1.2.1", port)),
"Protocol", TypeId::LookupByName ("Udp"),
"OnTime", ConstantVariable(1),
"OffTime", ConstantVariable(0));
n3->AddApplication (ooff);
// Start the application
ooff->Start (Seconds(1.1));
// Create a packet sink to receive these packets
sink = CreateObject<PacketSink> (
n1,
InetSocketAddress (Ipv4Address::GetAny (), port),
"Udp");
sink = CreateObjectWith<PacketSink> (
"Node", n1,
"Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
"Protocol", TypeId::LookupByName ("Udp"));
n1->AddApplication (sink);
// Start the sink
sink->Start (Seconds (1.1));

View File

@@ -43,6 +43,7 @@
#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/random-variable.h"
#include "ns3/config.h"
#include "ns3/simulator.h"
#include "ns3/nstime.h"
@@ -75,16 +76,10 @@ main (int argc, char *argv[])
LogComponentEnable ("SimplePointToPointExample", LOG_LEVEL_ALL);
#endif
// Set up some default values for the simulation. Use the Bind()
// technique to tell the system what subclass of Queue to use,
// and what the queue limit is
// Set up some default values for the simulation.
// The below Bind command tells the queue factory which class to
// instantiate, when the queue factory is invoked in the topology code
DefaultValue::Bind ("Queue", "DropTailQueue");
DefaultValue::Bind ("OnOffApplicationPacketSize", "210");
DefaultValue::Bind ("OnOffApplicationDataRate", "448kb/s");
Config::SetDefault ("OnOffApplication::PacketSize", "210");
Config::SetDefault ("OnOffApplication::DataRate", "448kb/s");
// Allow the user to override any of the defaults and the above
// Bind()s at run-time, via command-line arguments
@@ -139,38 +134,44 @@ main (int argc, char *argv[])
// 210 bytes at a rate of 448 Kb/s
NS_LOG_INFO ("Create Applications.");
uint16_t port = 9; // Discard port (RFC 863)
Ptr<OnOffApplication> ooff = CreateObject<OnOffApplication> (
n0,
InetSocketAddress ("10.1.3.2", port),
"Udp",
ConstantVariable(1),
ConstantVariable(0));
Ptr<OnOffApplication> ooff =
CreateObjectWith<OnOffApplication> (
"Node", n0,
"Remote", Address (InetSocketAddress ("10.1.3.2", port)),
"Protocol", TypeId::LookupByName ("Udp"),
"OnTime", ConstantVariable(1),
"OffTime", ConstantVariable(0));
n0->AddApplication (ooff);
// Start the application
ooff->Start (Seconds(1.0));
// Create an optional packet sink to receive these packets
Ptr<PacketSink> sink = CreateObject<PacketSink> (
n3,
InetSocketAddress (Ipv4Address::GetAny (), port),
"Udp");
Ptr<PacketSink> sink =
CreateObjectWith<PacketSink> (
"Node", n3,
"Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
"Protocol", TypeId::LookupByName ("Udp"));
n3->AddApplication (sink);
// Start the sink
sink->Start (Seconds (1.0));
// Create a similar flow from n3 to n1, starting at time 1.1 seconds
ooff = CreateObject<OnOffApplication> (
n3,
InetSocketAddress ("10.1.2.1", port),
"Udp",
ConstantVariable(1),
ConstantVariable(0));
ooff = CreateObjectWith<OnOffApplication> (
"Node", n3,
"Remote", Address (InetSocketAddress ("10.1.2.1", port)),
"Protocol", TypeId::LookupByName ("Udp"),
"OnTime", ConstantVariable(1),
"OffTime", ConstantVariable(0));
n3->AddApplication (ooff);
// Start the application
ooff->Start(Seconds(1.1));
// Create a packet sink to receive these packets
sink = CreateObject<PacketSink> (
n1,
InetSocketAddress (Ipv4Address::GetAny (), port),
"Udp");
sink = CreateObjectWith<PacketSink> (
"Node", n1,
"Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
"Protocol", TypeId::LookupByName ("Udp"));
n1->AddApplication (sink);
// Start the sink
sink->Start (Seconds (1.1));
@@ -178,21 +179,23 @@ main (int argc, char *argv[])
// Create a file transfer from n0 to n3, starting at time 1.2
uint16_t servPort = 500;
ooff = CreateObject<OnOffApplication> (
n0,
InetSocketAddress ("10.1.3.2", servPort),
"Tcp",
ConstantVariable(1),
ConstantVariable(0));
ooff = CreateObjectWith<OnOffApplication> (
"Node", n0,
"Remote", Address (InetSocketAddress ("10.1.3.2", servPort)),
"Protocol", TypeId::LookupByName ("Tcp"),
"OnTime", ConstantVariable(1),
"OffTime", ConstantVariable(0));
n0->AddApplication (ooff);
// Start the application
ooff->Start (Seconds(1.2));
ooff->Stop (Seconds(1.35));
// Create a packet sink to receive these TCP packets
sink = Create<PacketSink> (
n3,
InetSocketAddress (Ipv4Address::GetAny (), servPort),
"Tcp");
sink = CreateObjectWith<PacketSink> (
"Node", n3,
"Local", Address (InetSocketAddress (Ipv4Address::GetAny (), servPort)),
"Protocol", TypeId::LookupByName ("Tcp"));
n3->AddApplication (sink);
sink->Start (Seconds (1.2));
// Here, finish off packet routing configuration

View File

@@ -196,10 +196,12 @@ int main (int argc, char *argv[])
localSocket->Bind ();
// Create a packet sink to receive these packets
Ptr<PacketSink> sink = Create<PacketSink> (
n2,
InetSocketAddress (Ipv4Address::GetAny (), servPort),
"Tcp");
Ptr<PacketSink> sink =
CreateObjectWith<PacketSink> (
"Node", n2,
"Local", Address (InetSocketAddress (Ipv4Address::GetAny (), servPort)),
"Protocol", TypeId::LookupByName ("Tcp"));
n2->AddApplication (sink);
sink->Start (Seconds (0.0));
sink->Stop (Seconds (10000.0));

View File

@@ -196,10 +196,12 @@ int main (int argc, char *argv[])
localSocket->Bind ();
// Create a packet sink to receive these packets
Ptr<PacketSink> sink = Create<PacketSink> (
n2,
InetSocketAddress (Ipv4Address::GetAny (), servPort),
"Tcp");
Ptr<PacketSink> sink =
CreateObjectWith<PacketSink> (
"Node", n2,
"Local", Address (InetSocketAddress (Ipv4Address::GetAny (), servPort)),
"Protocol", TypeId::LookupByName ("Tcp"));
n2->AddApplication (sink);
sink->Start (Seconds (0.0));
sink->Stop (Seconds (100.0));

View File

@@ -178,10 +178,12 @@ int main (int argc, char *argv[])
localSocket->Bind ();
// Create a packet sink to receive these packets
Ptr<PacketSink> sink = Create<PacketSink> (
n2,
InetSocketAddress (Ipv4Address::GetAny (), servPort),
"Tcp");
Ptr<PacketSink> sink =
CreateObjectWith<PacketSink> (
"Node", n2,
"Local", Address (InetSocketAddress (Ipv4Address::GetAny (), servPort)),
"Protocol", TypeId::LookupByName ("Tcp"));
n2->AddApplication (sink);
sink->Start (Seconds (0.0));
sink->Stop (Seconds (100.0));

View File

@@ -188,10 +188,12 @@ int main (int argc, char *argv[])
localSocket->Bind ();
// Create a packet sink to receive these packets
Ptr<PacketSink> sink = Create<PacketSink> (
n2,
InetSocketAddress (Ipv4Address::GetAny (), servPort),
"Tcp");
Ptr<PacketSink> sink =
CreateObjectWith<PacketSink> (
"Node", n2,
"Local", Address (InetSocketAddress (Ipv4Address::GetAny (), servPort)),
"Protocol", TypeId::LookupByName ("Tcp"));
n2->AddApplication (sink);
sink->Start (Seconds (0.0));
sink->Stop (Seconds (100.0));

View File

@@ -47,6 +47,7 @@
#include "ns3/ipv4-route.h"
#include "ns3/udp-echo-client.h"
#include "ns3/udp-echo-server.h"
#include "ns3/uinteger.h"
using namespace ns3;
@@ -167,7 +168,9 @@ main (int argc, char *argv[])
//
uint16_t port = 9; // well-known echo port number
Ptr<UdpEchoServer> server = CreateObject<UdpEchoServer> (n1, port);
Ptr<UdpEchoServer> server = CreateObjectWith<UdpEchoServer> ("Node", n1,
"Port", Uinteger (port));
n1->AddApplication (server);
//
// Create a UdpEchoClient application to send UDP datagrams from node zero to
// node one.
@@ -176,8 +179,14 @@ main (int argc, char *argv[])
uint32_t maxPacketCount = 1;
Time interPacketInterval = Seconds (1.);
Ptr<UdpEchoClient> client = CreateObject<UdpEchoClient> (n0, "10.1.1.2", port,
maxPacketCount, interPacketInterval, packetSize);
Ptr<UdpEchoClient> client =
CreateObjectWith<UdpEchoClient> ("Node", n0,
"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.
//

View File

@@ -33,6 +33,7 @@
#include "ns3/socket-factory.h"
#include "ns3/command-line.h"
#include "ns3/gnuplot.h"
#include "ns3/uinteger.h"
#include <iostream>
@@ -122,12 +123,15 @@ RunOneExperiment (void)
destination.SetProtocol (1);
destination.SetSingleDevice (0);
destination.SetPhysicalAddress (Mac48Address ("00:00:00:00:00:02"));
Ptr<Application> app = CreateObject<OnOffApplication> (a, destination,
"Packet",
ConstantVariable (250),
ConstantVariable (0),
DataRate (60000000),
2000);
Ptr<Application> app =
CreateObjectWith<OnOffApplication> ("Node", a,
"Remote", Address (destination),
"Protocol", TypeId::LookupByName ("Packet"),
"OnTime", ConstantVariable (250),
"OffTime", ConstantVariable (0),
"DataRate", DataRate (60000000),
"PacketSize", Uinteger (2000));
a->AddApplication (app);
app->Start (Seconds (0.5));
app->Stop (Seconds (250.0));

View File

@@ -172,10 +172,13 @@ int main (int argc, char *argv[])
destination.SetProtocol (1);
destination.SetSingleDevice (0);
destination.SetPhysicalAddress (Mac48Address ("00:00:00:00:00:03"));
Ptr<Application> app = CreateObject<OnOffApplication> (b, destination,
"Packet",
ConstantVariable (42),
ConstantVariable (0));
Ptr<Application> app =
CreateObjectWith<OnOffApplication> ("Node", b,
"Remote", Address (destination),
"Protocol", TypeId::LookupByName ("Packet"),
"OnTime", ConstantVariable (42),
"OffTime", ConstantVariable (0));
b->AddApplication (app);
app->Start (Seconds (0.5));
app->Stop (Seconds (43.0));

View File

@@ -31,10 +31,11 @@
#include "ns3/socket.h"
#include "ns3/simulator.h"
#include "ns3/socket-factory.h"
#include "ns3/default-value.h"
#include "ns3/packet.h"
#include "ns3/composite-trace-resolver.h"
#include "ns3/uinteger.h"
#include "ns3/trace-source-accessor.h"
#include "onoff-application.h"
#include "ns3/udp.h"
NS_LOG_COMPONENT_DEFINE ("OnOffApplication");
@@ -42,63 +43,54 @@ using namespace std;
namespace ns3 {
// Defaults for rate/size
static DataRateDefaultValue g_defaultRate ("OnOffApplicationDataRate",
"The data rate in on state for OnOffApplication",
MakeDataRate ("500kb/s"));
static NumericDefaultValue<uint32_t> g_defaultSize ("OnOffApplicationPacketSize",
"The size of packets sent in on state for OnOffApplication",
512, 1);
// Constructors
NS_OBJECT_ENSURE_REGISTERED (OnOffApplication);
OnOffApplication::OnOffApplication(Ptr<Node> n,
const Address &remote,
std::string tid,
const RandomVariable& ontime,
const RandomVariable& offtime)
: Application(n),
m_cbrRate (g_defaultRate.GetValue ())
TypeId
OnOffApplication::GetTypeId (void)
{
Construct (n, remote, tid,
ontime, offtime,
g_defaultSize.GetValue ());
static TypeId tid = TypeId ("OnOffApplication")
.SetParent<Application> ()
.AddConstructor<OnOffApplication> ()
.AddAttribute ("DataRate", "The data rate in on state.",
MakeDataRate ("500kb/s"),
MakeDataRateAccessor (&OnOffApplication::m_cbrRate),
MakeDataRateChecker ())
.AddAttribute ("PacketSize", "The size of packets sent in on state",
Uinteger (512),
MakeUintegerAccessor (&OnOffApplication::m_pktSize),
MakeUintegerChecker<uint32_t> (1))
.AddAttribute ("Remote", "The address of the destination",
Address (),
MakeAddressAccessor (&OnOffApplication::m_peer),
MakeAddressChecker ())
.AddAttribute ("OnTime", "A RandomVariable used to pick the duration of the 'On' state.",
ConstantVariable (1.0),
MakeRandomVariableAccessor (&OnOffApplication::m_onTime),
MakeRandomVariableChecker ())
.AddAttribute ("OffTime", "A RandomVariable used to pick the duration of the 'Off' state.",
ConstantVariable (1.0),
MakeRandomVariableAccessor (&OnOffApplication::m_offTime),
MakeRandomVariableChecker ())
.AddAttribute ("Protocol", "The type of protocol to use.",
Udp::GetTypeId (),
MakeTypeIdAccessor (&OnOffApplication::m_tid),
MakeTypeIdChecker ())
.AddTraceSource ("Tx", "A new packet is created and is sent",
MakeTraceSourceAccessor (&OnOffApplication::m_txTrace))
;
return tid;
}
OnOffApplication::OnOffApplication(Ptr<Node> n,
const Address &remote,
std::string tid,
const RandomVariable& ontime,
const RandomVariable& offtime,
DataRate rate,
uint32_t size)
: Application(n),
m_cbrRate (rate)
OnOffApplication::OnOffApplication ()
{
NS_LOG_FUNCTION;
Construct (n, remote, tid, ontime, offtime, size);
}
void
OnOffApplication::Construct (Ptr<Node> n,
const Address &remote,
std::string tid,
const RandomVariable& onTime,
const RandomVariable& offTime,
uint32_t size)
{
NS_LOG_FUNCTION;
m_socket = 0;
m_peer = remote;
m_connected = false;
m_onTime = onTime;
m_offTime = offTime;
m_pktSize = size;
m_residualBits = 0;
m_lastStartTime = Seconds (0);
m_maxBytes = 0;
m_totBytes = 0;
m_tid = tid;
}
OnOffApplication::~OnOffApplication()
@@ -114,21 +106,6 @@ OnOffApplication::SetMaxBytes(uint32_t maxBytes)
m_maxBytes = maxBytes;
}
void
OnOffApplication::SetDefaultRate (const DataRate &rate)
{
NS_LOG_FUNCTION;
NS_LOG_PARAMS (&rate);
g_defaultRate.SetValue (rate);
}
void
OnOffApplication::SetDefaultSize (uint32_t size)
{
NS_LOG_FUNCTION;
NS_LOG_PARAMS (size);
g_defaultSize.SetValue (size);
}
void
OnOffApplication::DoDispose (void)
@@ -148,8 +125,7 @@ void OnOffApplication::StartApplication() // Called at time specified by Start
// Create the socket if not already
if (!m_socket)
{
TypeId tid = TypeId::LookupByName (m_tid);
Ptr<SocketFactory> socketFactory = GetNode ()->GetObject<SocketFactory> (tid);
Ptr<SocketFactory> socketFactory = GetNode ()->GetObject<SocketFactory> (m_tid);
m_socket = socketFactory->CreateSocket ();
m_socket->Bind ();
m_socket->Connect (m_peer);
@@ -258,17 +234,4 @@ void OnOffApplication::ConnectionFailed(Ptr<Socket>)
cout << "OnOffApplication, Connection Failed" << endl;
}
Ptr<TraceResolver>
OnOffApplication::GetTraceResolver (void) const
{
Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
resolver->AddSource ("tx",
TraceDoc ("A new packet is created and is sent",
"Ptr<const Packet>",
"The newly-created packet."),
m_txTrace);
resolver->SetParentResolver (Application::GetTraceResolver ());
return resolver;
}
} // Namespace ns3

View File

@@ -29,8 +29,8 @@
#include "ns3/event-id.h"
#include "ns3/ptr.h"
#include "ns3/data-rate.h"
#include "ns3/callback-trace-source.h"
#include "ns3/random-variable.h"
#include "ns3/traced-callback.h"
namespace ns3 {
@@ -52,56 +52,14 @@ class Socket;
class OnOffApplication : public Application
{
public:
/**
* \param n node associated to this application
* \param remote remote ip address
* \param tid
* \param ontime on time random variable
* \param offtime off time random variable
*/
OnOffApplication(Ptr<Node> n,
const Address &remote,
std::string tid,
const RandomVariable& ontime,
const RandomVariable& offtime);
static TypeId GetTypeId (void);
/**
* \param n node associated to this application
* \param remote remote ip address
* \param tid
* \param ontime on time random variable
* \param offtime off time random variable
* \param rate data rate when on
* \param size size of packets when sending data.
*/
OnOffApplication(Ptr<Node> n,
const Address &remote,
std::string tid,
const RandomVariable& ontime,
const RandomVariable& offtime,
DataRate rate,
uint32_t size);
OnOffApplication ();
virtual ~OnOffApplication();
void SetMaxBytes(uint32_t maxBytes);
/**
* \param r the data rate
*
* Set the data rate to use for every OnOffApplication for which
* the user does not specify an explicit data rate.
*/
static void SetDefaultRate(const DataRate & r);
/**
* \param size the packet size
*
* Set the packet size to use for every OnOffApplication for
* which the user does not specify an explicit packet size.
*/
static void SetDefaultSize (uint32_t size);
protected:
virtual void DoDispose (void);
private:
@@ -125,8 +83,8 @@ private:
Ptr<Socket> m_socket; // Associated socket
Address m_peer; // Peer address
bool m_connected; // True if connected
RandomVariable m_onTime; // rng for On Time
RandomVariable m_offTime; // rng for Off Time
RandomVariable m_onTime; // rng for On Time
RandomVariable m_offTime; // rng for Off Time
DataRate m_cbrRate; // Rate that data is generated
uint32_t m_pktSize; // Size of packets
uint32_t m_residualBits; // Number of generated, but not sent, bits
@@ -136,11 +94,10 @@ private:
EventId m_startStopEvent; // Event id for next start or stop event
EventId m_sendEvent; // Eventid of pending "send packet" event
bool m_sending; // True if currently in sending state
std::string m_tid;
CallbackTraceSource<Ptr<const Packet> > m_txTrace;
TypeId m_tid;
TracedCallback<Ptr<const Packet> > m_txTrace;
private:
virtual Ptr<TraceResolver> GetTraceResolver (void) const;
void ScheduleNextTx();
void ScheduleStartEvent();
void ScheduleStopEvent();

View File

@@ -25,7 +25,8 @@
#include "ns3/simulator.h"
#include "ns3/socket-factory.h"
#include "ns3/packet.h"
#include "ns3/composite-trace-resolver.h"
#include "ns3/trace-source-accessor.h"
#include "ns3/udp.h"
#include "packet-sink.h"
using namespace std;
@@ -33,25 +34,30 @@ using namespace std;
namespace ns3 {
NS_LOG_COMPONENT_DEFINE ("PacketSinkApplication");
NS_OBJECT_ENSURE_REGISTERED (PacketSink);
// Constructors
PacketSink::PacketSink (Ptr<Node> n,
const Address &local,
std::string tid)
: Application(n)
TypeId
PacketSink::GetTypeId (void)
{
Construct (n, local, tid);
static TypeId tid = TypeId ("PacketSink")
.SetParent<Application> ()
.AddAttribute ("Local", "The Address on which to Bind the rx socket.",
Address (),
MakeAddressAccessor (&PacketSink::m_local),
MakeAddressChecker ())
.AddAttribute ("Protocol", "The type id of the protocol to use for the rx socket.",
Udp::GetTypeId (),
MakeTypeIdAccessor (&PacketSink::m_tid),
MakeTypeIdChecker ())
.AddTraceSource ("Rx", "A packet has been received",
MakeTraceSourceAccessor (&PacketSink::m_rxTrace))
;
return tid;
}
void
PacketSink::Construct (Ptr<Node> n,
const Address &local,
std::string tid)
PacketSink::PacketSink ()
{
m_socket = 0;
m_local = local;
m_tid = tid;
}
PacketSink::~PacketSink()
@@ -73,9 +79,8 @@ void PacketSink::StartApplication() // Called at time specified by Start
// Create the socket if not already
if (!m_socket)
{
TypeId tid = TypeId::LookupByName (m_tid);
Ptr<SocketFactory> socketFactory =
GetNode ()->GetObject<SocketFactory> (tid);
GetNode ()->GetObject<SocketFactory> (m_tid);
m_socket = socketFactory->CreateSocket ();
m_socket->Bind (m_local);
m_socket->Listen (0);
@@ -116,19 +121,4 @@ void PacketSink::CloseConnection (Ptr<Socket> socket)
socket->Close ();
}
Ptr<TraceResolver>
PacketSink::GetTraceResolver (void) const
{
Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
resolver->AddSource ("rx",
TraceDoc ("A new packet has been received",
"Ptr<const Packet>",
"The newly-received packet.",
"const Address &",
"The source address of the received packet."),
m_rxTrace);
resolver->SetParentResolver (Application::GetTraceResolver ());
return resolver;
}
} // Namespace ns3

View File

@@ -24,7 +24,7 @@
#include "ns3/application.h"
#include "ns3/event-id.h"
#include "ns3/ptr.h"
#include "ns3/callback-trace-source.h"
#include "ns3/traced-callback.h"
#include "ns3/address.h"
namespace ns3 {
@@ -53,14 +53,13 @@ class Packet;
class PacketSink : public Application
{
public:
static TypeId GetTypeId (void);
/**
* \param n node associated to this application
* \param local local address to bind to
* \param tid string to identify transport protocol of interest
*/
PacketSink (Ptr<Node> n,
const Address &local,
std::string tid);
PacketSink ();
virtual ~PacketSink ();
@@ -70,20 +69,14 @@ private:
// inherited from Application base class.
virtual void StartApplication (void); // Called at time specified by Start
virtual void StopApplication (void); // Called at time specified by Stop
// inherited from Object base class.
virtual Ptr<TraceResolver> GetTraceResolver (void) const;
void Construct (Ptr<Node> n,
const Address &local,
std::string tid);
virtual void Receive (Ptr<Socket> socket, Ptr<Packet> packet, const Address& from);
virtual void CloseConnection (Ptr<Socket> socket);
Ptr<Socket> m_socket; // Associated socket
Address m_local; // Local address to bind to
std::string m_tid; // Protocol name (e.g., "Udp")
CallbackTraceSource<Ptr<const Packet>, const Address &> m_rxTrace;
TypeId m_tid; // Protocol TypeId
TracedCallback<Ptr<const Packet>, const Address &> m_rxTrace;
};

View File

@@ -23,27 +23,50 @@
#include "ns3/simulator.h"
#include "ns3/socket-factory.h"
#include "ns3/packet.h"
#include "ns3/uinteger.h"
#include "udp-echo-client.h"
namespace ns3 {
NS_LOG_COMPONENT_DEFINE ("UdpEchoClientApplication");
NS_OBJECT_ENSURE_REGISTERED (UdpEchoClient);
UdpEchoClient::UdpEchoClient (
Ptr<Node> n,
Ipv4Address serverAddress,
uint16_t serverPort,
uint32_t count,
Time interval,
uint32_t size)
:
Application(n)
TypeId
UdpEchoClient::GetTypeId (void)
{
static TypeId tid = TypeId ("UdpEchoClient")
.SetParent<Application> ()
.AddConstructor<UdpEchoClient> ()
.AddAttribute ("MaxPackets", "XXX",
Uinteger (100),
MakeUintegerAccessor (&UdpEchoClient::m_count),
MakeUintegerChecker<uint32_t> ())
.AddAttribute ("Interval", "XXX",
Seconds (1.0),
MakeTimeAccessor (&UdpEchoClient::m_interval),
MakeTimeChecker ())
.AddAttribute ("RemoteIpv4", "XXX",
Ipv4Address (),
MakeIpv4AddressAccessor (&UdpEchoClient::m_peerAddress),
MakeIpv4AddressChecker ())
.AddAttribute ("RemotePort", "XXX",
Uinteger (0),
MakeUintegerAccessor (&UdpEchoClient::m_peerPort),
MakeUintegerChecker<uint16_t> ())
.AddAttribute ("PacketSize", "Size of packets generated",
Uinteger (100),
MakeUintegerAccessor (&UdpEchoClient::m_size),
MakeUintegerChecker<uint32_t> ())
;
return tid;
}
UdpEchoClient::UdpEchoClient ()
{
NS_LOG_FUNCTION;
NS_LOG_PARAMS (this << n << serverAddress << serverPort << count
<< interval << size);
Construct (n, serverAddress, serverPort, count, interval, size);
m_sent = 0;
m_socket = 0;
m_sendEvent = EventId ();
}
UdpEchoClient::~UdpEchoClient()
@@ -51,32 +74,6 @@ UdpEchoClient::~UdpEchoClient()
NS_LOG_FUNCTION;
}
void
UdpEchoClient::Construct (
Ptr<Node> n,
Ipv4Address serverAddress,
uint16_t serverPort,
uint32_t count,
Time interval,
uint32_t size)
{
NS_LOG_FUNCTION;
NS_LOG_PARAMS (this << n << serverAddress << serverPort
<< count << interval << size);
m_node = n;
m_serverAddress = serverAddress;
m_serverPort = serverPort;
m_count = count;
m_interval = interval;
m_size = size;
m_sent = 0;
m_socket = 0;
m_peer = InetSocketAddress (serverAddress, serverPort);
m_sendEvent = EventId ();
}
void
UdpEchoClient::DoDispose (void)
{
@@ -96,7 +93,7 @@ UdpEchoClient::StartApplication (void)
GetNode ()->GetObject<SocketFactory> (tid);
m_socket = socketFactory->CreateSocket ();
m_socket->Bind ();
m_socket->Connect (m_peer);
m_socket->Connect (InetSocketAddress (m_peerAddress, m_peerPort));
}
m_socket->SetRecvCallback(MakeCallback(&UdpEchoClient::Receive, this));
@@ -136,7 +133,7 @@ UdpEchoClient::Send (void)
m_socket->Send (p);
++m_sent;
NS_LOG_INFO ("Sent " << m_size << " bytes to " << m_serverAddress);
NS_LOG_INFO ("Sent " << m_size << " bytes to " << m_peerAddress);
if (m_sent < m_count)
{

View File

@@ -32,8 +32,9 @@ class Packet;
class UdpEchoClient : public Application
{
public:
UdpEchoClient (Ptr<Node> n, Ipv4Address serverAddr, uint16_t serverPort,
uint32_t count, Time interval, uint32_t size);
static TypeId GetTypeId (void);
UdpEchoClient ();
virtual ~UdpEchoClient ();
@@ -41,8 +42,6 @@ protected:
virtual void DoDispose (void);
private:
void Construct (Ptr<Node> n, Ipv4Address serverAddr, uint16_t serverPort,
uint32_t count, Time interval, uint32_t size);
virtual void StartApplication (void);
virtual void StopApplication (void);
@@ -52,16 +51,14 @@ private:
void Receive(Ptr<Socket> socket, Ptr<Packet> packet, const Address &from);
Ptr<Node> m_node;
Ipv4Address m_serverAddress;
uint16_t m_serverPort;
uint32_t m_count;
Time m_interval;
uint32_t m_size;
uint32_t m_sent;
Ptr<Socket> m_socket;
Address m_peer;
Ipv4Address m_peerAddress;
uint16_t m_peerPort;
EventId m_sendEvent;
};

View File

@@ -24,23 +24,32 @@
#include "ns3/simulator.h"
#include "ns3/socket-factory.h"
#include "ns3/packet.h"
#include "ns3/uinteger.h"
#include "udp-echo-server.h"
namespace ns3 {
NS_LOG_COMPONENT_DEFINE ("UdpEchoServerApplication");
NS_OBJECT_ENSURE_REGISTERED (UdpEchoServer);
UdpEchoServer::UdpEchoServer (
Ptr<Node> n,
uint16_t port)
:
Application(n)
TypeId
UdpEchoServer::GetTypeId (void)
{
static TypeId tid = TypeId ("UdpEchoServer")
.SetParent<Application> ()
.AddConstructor<UdpEchoServer> ()
.AddAttribute ("Port", "Client Port",
Uinteger (0),
MakeUintegerAccessor (&UdpEchoServer::m_port),
MakeUintegerChecker<uint16_t> ())
;
return tid;
}
UdpEchoServer::UdpEchoServer ()
{
NS_LOG_FUNCTION;
NS_LOG_PARAMS (this << n << port);
Construct (n, port);
}
UdpEchoServer::~UdpEchoServer()
@@ -48,21 +57,6 @@ UdpEchoServer::~UdpEchoServer()
NS_LOG_FUNCTION;
}
void
UdpEchoServer::Construct (
Ptr<Node> n,
uint16_t port)
{
NS_LOG_FUNCTION;
NS_LOG_PARAMS (this << n << port);
m_node = n;
m_port = port;
m_socket = 0;
m_local = InetSocketAddress (Ipv4Address::GetAny (), port);
}
void
UdpEchoServer::DoDispose (void)
{
@@ -81,7 +75,8 @@ UdpEchoServer::StartApplication (void)
Ptr<SocketFactory> socketFactory =
GetNode ()->GetObject<SocketFactory> (tid);
m_socket = socketFactory->CreateSocket ();
m_socket->Bind (m_local);
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), m_port);
m_socket->Bind (local);
}
m_socket->SetRecvCallback(MakeCallback(&UdpEchoServer::Receive, this));

View File

@@ -32,23 +32,21 @@ class Packet;
class UdpEchoServer : public Application
{
public:
UdpEchoServer (Ptr<Node> n, uint16_t clientPort);
static TypeId GetTypeId (void);
UdpEchoServer ();
virtual ~UdpEchoServer ();
protected:
virtual void DoDispose (void);
private:
void Construct (Ptr<Node> n, uint16_t clientPort);
virtual void StartApplication (void);
virtual void StopApplication (void);
void Receive(Ptr<Socket> socket, Ptr<Packet> packet, const Address &from);
Ptr<Node> m_node;
uint16_t m_port;
Ptr<Socket> m_socket;
Address m_local;
};

View File

@@ -31,14 +31,26 @@ using namespace std;
namespace ns3 {
NS_OBJECT_ENSURE_REGISTERED (Application);
// Application Methods
// \brief Application Constructor
Application::Application(Ptr<Node> n)
: m_node (n)
TypeId
Application::GetTypeId (void)
{
m_node->AddApplication (this);
static TypeId tid = TypeId ("Application")
.SetParent<Object> ()
.AddAttribute ("Node", "The on which this application resides",
Ptr<Node> (0),
MakePtrAccessor (&Application::m_node),
MakePtrChecker<Node> ())
;
return tid;
}
// \brief Application Constructor
Application::Application()
{}
// \brief Application Destructor
Application::~Application()

View File

@@ -52,7 +52,8 @@ class RandomVariable;
class Application : public Object
{
public:
Application(Ptr<Node>);
static TypeId GetTypeId (void);
Application();
virtual ~Application();
/**

View File

@@ -21,6 +21,8 @@
#include "ns3/simulator.h"
#include "ns3/nstime.h"
#include "ns3/ascii-trace.h"
#include "ns3/inet-socket-address.h"
#include "ns3/uinteger.h"
#include "ipv4-bus-network.h"
@@ -41,11 +43,19 @@ main (int argc, char *argv[])
uint32_t port = 7;
Ptr<Node> n0 = bus.GetNode (0);
Ptr<UdpEchoClient> client = CreateObject<UdpEchoClient> (n0, "10.1.0.1",
port, 1, Seconds(1.), 1024);
Ptr<UdpEchoClient> client =
CreateObjectWith<UdpEchoClient> ("Node", n0,
"RemoteIpv4", Ipv4Address ("10.1.0.1"),
"RemotePort", Uinteger (port),
"MaxPackets", Uinteger (1),
"Interval", Seconds(1.),
"PacketSize", Uinteger (1024));
n0->AddApplication (client);
Ptr<Node> n1 = bus.GetNode (1);
Ptr<UdpEchoServer> server = CreateObject<UdpEchoServer> (n1, port);
Ptr<UdpEchoServer> server =
CreateObjectWith<UdpEchoServer> ("Node", n1, "Port", Uinteger (port));
n1->AddApplication (server);
server->Start(Seconds(1.));
client->Start(Seconds(2.));

View File

@@ -27,6 +27,8 @@
#include "ns3/simulator.h"
#include "ns3/nstime.h"
#include "ns3/ascii-trace.h"
#include "ns3/inet-socket-address.h"
#include "ns3/uinteger.h"
NS_LOG_COMPONENT_DEFINE ("UdpEchoSimulation");
@@ -66,10 +68,19 @@ main (int argc, char *argv[])
uint16_t port = 7;
Ptr<UdpEchoClient> client = CreateObject<UdpEchoClient> (n0, "10.1.1.2",
port, 1, Seconds(1.), 1024);
Ptr<UdpEchoClient> client =
CreateObjectWith<UdpEchoClient> ("Node", n0,
"RemoteIpv4", Ipv4Address ("10.1.1.2"),
"RemotePort", Uinteger (port),
"MaxPackets", Uinteger (1),
"Interval", Seconds(1.),
"PacketSize", Uinteger (1024));
n0->AddApplication (client);
Ptr<UdpEchoServer> server = CreateObject<UdpEchoServer> (n1, port);
Ptr<UdpEchoServer> server =
CreateObjectWith<UdpEchoServer> ("Node", n1,
"Port", Uinteger (port));
n1->AddApplication (server);
server->Start(Seconds(1.));
client->Start(Seconds(2.));

View File

@@ -28,6 +28,8 @@
#include "ns3/nstime.h"
#include "ns3/ascii-trace.h"
#include "ns3/pcap-trace.h"
#include "ns3/inet-socket-address.h"
#include "ns3/uinteger.h"
NS_LOG_COMPONENT_DEFINE ("UdpEchoSimulation");
@@ -67,10 +69,19 @@ main (int argc, char *argv[])
uint16_t port = 7;
Ptr<UdpEchoClient> client = CreateObject<UdpEchoClient> (n0, "10.1.1.2",
port, 1, Seconds(1.), 1024);
Ptr<UdpEchoClient> client =
CreateObjectWith<UdpEchoClient> ("Node", n0,
"RemoteIpv4", Ipv4Address ("10.1.1.2"),
"RemotePort", Uinteger (port),
"MaxPackets", Uinteger (1),
"Interval", Seconds(1.),
"PacketSize", Uinteger (1024));
n0->AddApplication (client);
Ptr<UdpEchoServer> server = CreateObject<UdpEchoServer> (n1, port);
Ptr<UdpEchoServer> server =
CreateObjectWith<UdpEchoServer> ("Node", n1,
"Port", Uinteger (port));
n1->AddApplication (server);
server->Start(Seconds(1.));
client->Start(Seconds(2.));

View File

@@ -26,6 +26,8 @@
#include "ns3/udp-echo-server.h"
#include "ns3/simulator.h"
#include "ns3/nstime.h"
#include "ns3/uinteger.h"
#include "ns3/inet-socket-address.h"
NS_LOG_COMPONENT_DEFINE ("UdpEchoSimulation");
@@ -65,10 +67,19 @@ main (int argc, char *argv[])
uint16_t port = 7;
Ptr<UdpEchoClient> client = CreateObject<UdpEchoClient> (n0, "10.1.1.2",
port, 1, Seconds(1.), 1024);
Ptr<UdpEchoClient> client =
CreateObjectWith<UdpEchoClient> ("Node", n0,
"RemoteIpv4", Ipv4Address ("10.1.1.2"),
"RemotePort", Uinteger (port),
"MaxPackets", Uinteger (1),
"Interval", Seconds(1.),
"PacketSize", Uinteger (1024));
n0->AddApplication (client);
Ptr<UdpEchoServer> server = CreateObject<UdpEchoServer> (n1, port);
Ptr<UdpEchoServer> server =
CreateObjectWith<UdpEchoServer> ("Node", n1,
"Port", Uinteger (port));
n1->AddApplication (server);
server->Start(Seconds(1.));
client->Start(Seconds(2.));

View File

@@ -32,6 +32,8 @@
#include "ns3/ascii-trace.h"
#include "ns3/pcap-trace.h"
#include "ns3/global-route-manager.h"
#include "ns3/inet-socket-address.h"
#include "ns3/uinteger.h"
NS_LOG_COMPONENT_DEFINE ("DumbbellSimulation");
@@ -124,19 +126,55 @@ main (int argc, char *argv[])
//
uint16_t port = 7;
Ptr<UdpEchoClient> client0 = CreateObject<UdpEchoClient> (n0, "10.1.2.1",
port, 100, Seconds(.01), 1024);
Ptr<UdpEchoClient> client1 = CreateObject<UdpEchoClient> (n1, "10.1.2.2",
port, 100, Seconds(.01), 1024);
Ptr<UdpEchoClient> client2 = CreateObject<UdpEchoClient> (n2, "10.1.2.3",
port, 100, Seconds(.01), 1024);
Ptr<UdpEchoClient> client3 = CreateObject<UdpEchoClient> (n3, "10.1.2.4",
port, 100, Seconds(.01), 1024);
Ptr<UdpEchoClient> client0 =
CreateObjectWith<UdpEchoClient> (
"Node", n0,
"RemoteIpv4", Ipv4Address ("10.1.2.1"),
"RemotePort", Uinteger (port),
"MaxPackets", Uinteger (100),
"Interval", Seconds (0.01),
"PacketSize", Uinteger (1024));
n0->AddApplication (client0);
Ptr<UdpEchoClient> client1 =
CreateObjectWith<UdpEchoClient> (
"Node", n1,
"RemoteIpv4", Ipv4Address ("10.1.2.2"),
"RemotePort", Uinteger (port),
"MaxPackets", Uinteger (100),
"Interval", Seconds (0.01),
"PacketSize", Uinteger (1024));
n1->AddApplication (client1);
Ptr<UdpEchoClient> client2 =
CreateObjectWith<UdpEchoClient> (
"Node", n2,
"RemoteIpv4", Ipv4Address ("10.1.2.3"),
"RemotePort", Uinteger (port),
"MaxPackets", Uinteger (100),
"Interval", Seconds (0.01),
"PacketSize", Uinteger (1024));
n2->AddApplication (client2);
Ptr<UdpEchoClient> client3 =
CreateObjectWith<UdpEchoClient> (
"Node", n3,
"RemoteIpv4", Ipv4Address ("10.1.2.4"),
"RemotePort", Uinteger (port),
"MaxPackets", Uinteger (100),
"Interval", Seconds (0.01),
"PacketSize", Uinteger (1024));
n3->AddApplication (client3);
Ptr<UdpEchoServer> server4 = CreateObject<UdpEchoServer> (n4, port);
Ptr<UdpEchoServer> server5 = CreateObject<UdpEchoServer> (n5, port);
Ptr<UdpEchoServer> server6 = CreateObject<UdpEchoServer> (n6, port);
Ptr<UdpEchoServer> server7 = CreateObject<UdpEchoServer> (n7, port);
Ptr<UdpEchoServer> server4 =
CreateObjectWith<UdpEchoServer> ("Node", n4, "Port", Uinteger (port));
n4->AddApplication (server4);
Ptr<UdpEchoServer> server5 =
CreateObjectWith<UdpEchoServer> ("Node", n5, "Port", Uinteger (port));
n5->AddApplication (server5);
Ptr<UdpEchoServer> server6 =
CreateObjectWith<UdpEchoServer> ("Node", n6, "Port", Uinteger (port));
n6->AddApplication (server6);
Ptr<UdpEchoServer> server7 =
CreateObjectWith<UdpEchoServer> ("Node", n7, "Port", Uinteger (port));
n7->AddApplication (server7);
server4->Start(Seconds(1.));
server5->Start(Seconds(1.));

View File

@@ -28,6 +28,8 @@
#include "ns3/ascii-trace.h"
#include "ns3/pcap-trace.h"
#include "ns3/global-route-manager.h"
#include "ns3/inet-socket-address.h"
#include "ns3/uinteger.h"
NS_LOG_COMPONENT_DEFINE ("PointToPointSimulation");
@@ -58,10 +60,19 @@ main (int argc, char *argv[])
uint16_t port = 7;
Ptr<UdpEchoClient> client = CreateObject<UdpEchoClient> (n0, "10.1.1.2",
port, 1, Seconds(1.), 1024);
Ptr<UdpEchoClient> client =
CreateObjectWith<UdpEchoClient> ("Node", n0,
"RemoteIpv4", Ipv4Address ("10.1.1.2"),
"RemotePort", Uinteger (port),
"MaxPackets", Uinteger (1),
"Interval", Seconds(1.),
"PacketSize", Uinteger (1024));
n0->AddApplication (client);
Ptr<UdpEchoServer> server = CreateObject<UdpEchoServer> (n1, port);
Ptr<UdpEchoServer> server =
CreateObjectWith<UdpEchoServer> ("Node", n1,
"Port", Uinteger (port));
n1->AddApplication (server);
server->Start(Seconds(1.));
client->Start(Seconds(2.));

View File

@@ -27,6 +27,8 @@
#include "ns3/ascii-trace.h"
#include "ns3/pcap-trace.h"
#include "ns3/global-route-manager.h"
#include "ns3/inet-socket-address.h"
#include "ns3/uinteger.h"
#include "point-to-point-ipv4-topology.h"
@@ -145,10 +147,19 @@ main (int argc, char *argv[])
uint16_t port = 7;
Ptr<UdpEchoClient> client = CreateObject<UdpEchoClient> (n4, "10.1.1.2",
port, 1, Seconds(1.), 1024);
Ptr<UdpEchoClient> client =
CreateObjectWith<UdpEchoClient> ("Node", n4,
"RemoteIpv4", Ipv4Address ("10.1.1.2"),
"RemotePort", Uinteger (port),
"MaxPackets", Uinteger (1),
"Interval", Seconds(1.),
"PacketSize", Uinteger (1024));
n0->AddApplication (client);
Ptr<UdpEchoServer> server = CreateObject<UdpEchoServer> (n1, port);
Ptr<UdpEchoServer> server =
CreateObjectWith<UdpEchoServer> ("Node", n1,
"Port", Uinteger (port));
n1->AddApplication (server);
server->Start(Seconds(1.));
client->Start(Seconds(2.));

View File

@@ -27,6 +27,8 @@
#include "ns3/ascii-trace.h"
#include "ns3/pcap-trace.h"
#include "ns3/global-route-manager.h"
#include "ns3/inet-socket-address.h"
#include "ns3/uinteger.h"
#include "point-to-point-ipv4-topology.h"
@@ -145,10 +147,19 @@ main (int argc, char *argv[])
uint16_t port = 7;
Ptr<UdpEchoClient> client = CreateObject<UdpEchoClient> (n0, "10.1.1.2",
port, 1, Seconds(1.), 1024);
Ptr<UdpEchoClient> client =
CreateObjectWith<UdpEchoClient> ("Node", n0,
"RemoteIpv4", Ipv4Address ("10.1.1.2"),
"RemotePort", Uinteger (port),
"MaxPackets", Uinteger (1),
"Interval", Seconds(1.),
"PacketSize", Uinteger (1024));
n0->AddApplication (client);
Ptr<UdpEchoServer> server = CreateObject<UdpEchoServer> (n1, port);
Ptr<UdpEchoServer> server =
CreateObjectWith<UdpEchoServer> ("Node", n1,
"Port", Uinteger (port));
n1->AddApplication (server);
server->Start(Seconds(1.));
client->Start(Seconds(2.));