diff --git a/examples/csma-broadcast.cc b/examples/csma-broadcast.cc index 8592d9f5d..c67a09604 100644 --- a/examples/csma-broadcast.cc +++ b/examples/csma-broadcast.cc @@ -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 ooff = CreateObject ( - n0, - InetSocketAddress ("255.255.255.255", port), - "Udp", - ConstantVariable(1), - ConstantVariable(0)); + Ptr ooff = + CreateObjectWith ( + "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 sink = CreateObject ( - n1, - InetSocketAddress (Ipv4Address::GetAny (), port), - "Udp"); + Ptr sink = + CreateObjectWith ( + "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 ( - n2, - InetSocketAddress (Ipv4Address::GetAny (), port), - "Udp"); + sink = CreateObjectWith ( + "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)); diff --git a/examples/csma-multicast.cc b/examples/csma-multicast.cc index a8b5e5fcd..94bed3f03 100644 --- a/examples/csma-multicast.cc +++ b/examples/csma-multicast.cc @@ -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 ooff = CreateObject ( - n0, - InetSocketAddress (multicastGroup, port), - "Udp", - ConstantVariable(1), - ConstantVariable(0), - DataRate ("255b/s"), - 128); + Ptr ooff = + CreateObjectWith ( + "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 sink = CreateObject ( - n4, - InetSocketAddress (Ipv4Address::GetAny (), port), - "Udp"); + Ptr sink = + CreateObjectWith ( + "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)); diff --git a/examples/csma-one-subnet.cc b/examples/csma-one-subnet.cc index bb2cf5a2f..7f5702127 100644 --- a/examples/csma-one-subnet.cc +++ b/examples/csma-one-subnet.cc @@ -165,12 +165,15 @@ main (int argc, char *argv[]) // NS_LOG_INFO ("Create Applications."); uint16_t port = 9; // Discard port (RFC 863) - Ptr ooff = CreateObject ( - n0, - InetSocketAddress ("10.1.1.2", port), - "Udp", - ConstantVariable(1), - ConstantVariable(0)); + Ptr ooff = + CreateObjectWith ( + "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 ( - n3, - InetSocketAddress ("10.1.1.1", port), - "Udp", - ConstantVariable(1), - ConstantVariable(0)); + ooff = CreateObjectWith ( + "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)); diff --git a/examples/csma-packet-socket.cc b/examples/csma-packet-socket.cc index 45a8f4dcb..56b2bf7a7 100644 --- a/examples/csma-packet-socket.cc +++ b/examples/csma-packet-socket.cc @@ -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 ooff = CreateObject ( - n0, - n0ToN1, - "Packet", - ConstantVariable(1), - ConstantVariable(0)); + Ptr ooff = + CreateObjectWith ( + "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 ( - n3, - n3ToN0, - "Packet", - ConstantVariable(1), - ConstantVariable(0)); + ooff = CreateObjectWith ( + "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)); diff --git a/examples/mixed-global-routing.cc b/examples/mixed-global-routing.cc index e2d39b30d..308114737 100644 --- a/examples/mixed-global-routing.cc +++ b/examples/mixed-global-routing.cc @@ -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 ooff = CreateObject ( - n0, - InetSocketAddress ("10.1.3.2", port), - "Udp", - ConstantVariable (1), - ConstantVariable (0), - DataRate("300bps"), - 50); + Ptr ooff = + CreateObjectWith ( + "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)); diff --git a/examples/simple-alternate-routing.cc b/examples/simple-alternate-routing.cc index e8da2c244..1e5c1ec74 100644 --- a/examples/simple-alternate-routing.cc +++ b/examples/simple-alternate-routing.cc @@ -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 ooff = CreateObject ( - n3, - InetSocketAddress ("10.1.1.1", port), - "Udp", - ConstantVariable (1), - ConstantVariable (0)); + Ptr ooff = + CreateObjectWith ( + "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 sink = CreateObject ( - n1, - InetSocketAddress (Ipv4Address::GetAny (), port), - "Udp"); + Ptr sink = + CreateObjectWith ( + "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)); diff --git a/examples/simple-error-model.cc b/examples/simple-error-model.cc index a3c451140..0689b6974 100644 --- a/examples/simple-error-model.cc +++ b/examples/simple-error-model.cc @@ -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 ooff = CreateObject ( - n0, - InetSocketAddress ("10.1.3.2", port), - "Udp", - ConstantVariable(1), - ConstantVariable(0)); + Ptr ooff = + CreateObjectWith ( + "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 sink = CreateObject ( - n3, - InetSocketAddress (Ipv4Address::GetAny (), port), - "Udp"); + Ptr sink = CreateObjectWith ( + "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 ( - n3, - InetSocketAddress ("10.1.2.1", port), - "Udp", - ConstantVariable(1), - ConstantVariable(0)); + ooff = CreateObjectWith ( + "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 ( - n1, - InetSocketAddress (Ipv4Address::GetAny (), port), - "Udp"); + sink = CreateObjectWith ( + "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)); diff --git a/examples/simple-global-routing.cc b/examples/simple-global-routing.cc index 70f5931b8..416b14117 100644 --- a/examples/simple-global-routing.cc +++ b/examples/simple-global-routing.cc @@ -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 ooff = CreateObject ( - n0, - InetSocketAddress ("10.1.3.2", port), - "Udp", - ConstantVariable (1), - ConstantVariable (0)); + Ptr ooff = + CreateObjectWith ("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 sink = CreateObject ( - n3, - InetSocketAddress (Ipv4Address::GetAny (), port), - "Udp"); + Ptr sink = + CreateObjectWith ("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 ( - n3, - InetSocketAddress ("10.1.2.1", port), - "Udp", - ConstantVariable (1), - ConstantVariable (0)); + ooff = CreateObjectWith ( + "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 ( - n1, - InetSocketAddress (Ipv4Address::GetAny (), port), - "Udp"); + sink = CreateObjectWith ("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)); diff --git a/examples/simple-point-to-point-olsr.cc b/examples/simple-point-to-point-olsr.cc index 5d63ecfa3..9c6f853b6 100644 --- a/examples/simple-point-to-point-olsr.cc +++ b/examples/simple-point-to-point-olsr.cc @@ -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 ooff = CreateObject ( - n0, - InetSocketAddress ("10.1.3.2", port), - "Udp", - ConstantVariable(1), - ConstantVariable(0)); + Ptr ooff = + CreateObjectWith ( + "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 sink = CreateObject ( - n3, - InetSocketAddress (Ipv4Address::GetAny (), port), - "Udp"); + Ptr sink = + CreateObjectWith ( + "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 ( - n3, - InetSocketAddress ("10.1.2.1", port), - "Udp", - ConstantVariable(1), - ConstantVariable(0)); + ooff = CreateObjectWith ( + "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 ( - n1, - InetSocketAddress (Ipv4Address::GetAny (), port), - "Udp"); + sink = CreateObjectWith ( + "Node", n1, + "Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)), + "Protocol", TypeId::LookupByName ("Udp")); + n1->AddApplication (sink); // Start the sink sink->Start (Seconds (1.1)); diff --git a/examples/simple-point-to-point.cc b/examples/simple-point-to-point.cc index c1e708692..51b210030 100644 --- a/examples/simple-point-to-point.cc +++ b/examples/simple-point-to-point.cc @@ -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 ooff = CreateObject ( - n0, - InetSocketAddress ("10.1.3.2", port), - "Udp", - ConstantVariable(1), - ConstantVariable(0)); + Ptr ooff = + CreateObjectWith ( + "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 sink = CreateObject ( - n3, - InetSocketAddress (Ipv4Address::GetAny (), port), - "Udp"); + Ptr sink = + CreateObjectWith ( + "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 ( - n3, - InetSocketAddress ("10.1.2.1", port), - "Udp", - ConstantVariable(1), - ConstantVariable(0)); + ooff = CreateObjectWith ( + "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 ( - n1, - InetSocketAddress (Ipv4Address::GetAny (), port), - "Udp"); + sink = CreateObjectWith ( + "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 ( - n0, - InetSocketAddress ("10.1.3.2", servPort), - "Tcp", - ConstantVariable(1), - ConstantVariable(0)); + ooff = CreateObjectWith ( + "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 ( - n3, - InetSocketAddress (Ipv4Address::GetAny (), servPort), - "Tcp"); + sink = CreateObjectWith ( + "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 diff --git a/examples/tcp-large-transfer-errors.cc b/examples/tcp-large-transfer-errors.cc index c7a355778..11d2383b0 100644 --- a/examples/tcp-large-transfer-errors.cc +++ b/examples/tcp-large-transfer-errors.cc @@ -196,10 +196,12 @@ int main (int argc, char *argv[]) localSocket->Bind (); // Create a packet sink to receive these packets - Ptr sink = Create ( - n2, - InetSocketAddress (Ipv4Address::GetAny (), servPort), - "Tcp"); + Ptr sink = + CreateObjectWith ( + "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)); diff --git a/examples/tcp-large-transfer.cc b/examples/tcp-large-transfer.cc index e2c7487be..68e91fd17 100644 --- a/examples/tcp-large-transfer.cc +++ b/examples/tcp-large-transfer.cc @@ -196,10 +196,12 @@ int main (int argc, char *argv[]) localSocket->Bind (); // Create a packet sink to receive these packets - Ptr sink = Create ( - n2, - InetSocketAddress (Ipv4Address::GetAny (), servPort), - "Tcp"); + Ptr sink = + CreateObjectWith ( + "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)); diff --git a/examples/tcp-small-transfer-oneloss.cc b/examples/tcp-small-transfer-oneloss.cc index ea015e3ec..dbccea562 100644 --- a/examples/tcp-small-transfer-oneloss.cc +++ b/examples/tcp-small-transfer-oneloss.cc @@ -178,10 +178,12 @@ int main (int argc, char *argv[]) localSocket->Bind (); // Create a packet sink to receive these packets - Ptr sink = Create ( - n2, - InetSocketAddress (Ipv4Address::GetAny (), servPort), - "Tcp"); + Ptr sink = + CreateObjectWith ( + "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)); diff --git a/examples/tcp-small-transfer.cc b/examples/tcp-small-transfer.cc index 303a9a3bb..902ad5278 100644 --- a/examples/tcp-small-transfer.cc +++ b/examples/tcp-small-transfer.cc @@ -188,10 +188,12 @@ int main (int argc, char *argv[]) localSocket->Bind (); // Create a packet sink to receive these packets - Ptr sink = Create ( - n2, - InetSocketAddress (Ipv4Address::GetAny (), servPort), - "Tcp"); + Ptr sink = + CreateObjectWith ( + "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)); diff --git a/examples/udp-echo.cc b/examples/udp-echo.cc index 295ab5a99..b7ceddb2f 100644 --- a/examples/udp-echo.cc +++ b/examples/udp-echo.cc @@ -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 server = CreateObject (n1, port); + Ptr server = CreateObjectWith ("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 client = CreateObject (n0, "10.1.1.2", port, - maxPacketCount, interPacketInterval, packetSize); + Ptr client = + CreateObjectWith ("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. // diff --git a/samples/main-adhoc-wifi.cc b/samples/main-adhoc-wifi.cc index 2f8dfcafd..010e1bccb 100644 --- a/samples/main-adhoc-wifi.cc +++ b/samples/main-adhoc-wifi.cc @@ -33,6 +33,7 @@ #include "ns3/socket-factory.h" #include "ns3/command-line.h" #include "ns3/gnuplot.h" +#include "ns3/uinteger.h" #include @@ -122,12 +123,15 @@ RunOneExperiment (void) destination.SetProtocol (1); destination.SetSingleDevice (0); destination.SetPhysicalAddress (Mac48Address ("00:00:00:00:00:02")); - Ptr app = CreateObject (a, destination, - "Packet", - ConstantVariable (250), - ConstantVariable (0), - DataRate (60000000), - 2000); + Ptr app = + CreateObjectWith ("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)); diff --git a/samples/main-ap-wifi.cc b/samples/main-ap-wifi.cc index 49ae1e139..6caa28beb 100644 --- a/samples/main-ap-wifi.cc +++ b/samples/main-ap-wifi.cc @@ -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 app = CreateObject (b, destination, - "Packet", - ConstantVariable (42), - ConstantVariable (0)); + Ptr app = + CreateObjectWith ("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)); diff --git a/src/applications/onoff/onoff-application.cc b/src/applications/onoff/onoff-application.cc index 04a2ea336..1eabaa96a 100644 --- a/src/applications/onoff/onoff-application.cc +++ b/src/applications/onoff/onoff-application.cc @@ -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 g_defaultSize ("OnOffApplicationPacketSize", - "The size of packets sent in on state for OnOffApplication", - 512, 1); -// Constructors +NS_OBJECT_ENSURE_REGISTERED (OnOffApplication); -OnOffApplication::OnOffApplication(Ptr 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 () + .AddConstructor () + .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 (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 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 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 = GetNode ()->GetObject (tid); + Ptr socketFactory = GetNode ()->GetObject (m_tid); m_socket = socketFactory->CreateSocket (); m_socket->Bind (); m_socket->Connect (m_peer); @@ -258,17 +234,4 @@ void OnOffApplication::ConnectionFailed(Ptr) cout << "OnOffApplication, Connection Failed" << endl; } -Ptr -OnOffApplication::GetTraceResolver (void) const -{ - Ptr resolver = Create (); - resolver->AddSource ("tx", - TraceDoc ("A new packet is created and is sent", - "Ptr", - "The newly-created packet."), - m_txTrace); - resolver->SetParentResolver (Application::GetTraceResolver ()); - return resolver; -} - } // Namespace ns3 diff --git a/src/applications/onoff/onoff-application.h b/src/applications/onoff/onoff-application.h index 89a792cc5..c908a212a 100644 --- a/src/applications/onoff/onoff-application.h +++ b/src/applications/onoff/onoff-application.h @@ -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 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 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 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 > m_txTrace; + TypeId m_tid; + TracedCallback > m_txTrace; private: - virtual Ptr GetTraceResolver (void) const; void ScheduleNextTx(); void ScheduleStartEvent(); void ScheduleStopEvent(); diff --git a/src/applications/packet-sink/packet-sink.cc b/src/applications/packet-sink/packet-sink.cc index c97bd8596..d1f583e60 100644 --- a/src/applications/packet-sink/packet-sink.cc +++ b/src/applications/packet-sink/packet-sink.cc @@ -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 n, - const Address &local, - std::string tid) - : Application(n) +TypeId +PacketSink::GetTypeId (void) { - Construct (n, local, tid); + static TypeId tid = TypeId ("PacketSink") + .SetParent () + .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 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 = - GetNode ()->GetObject (tid); + GetNode ()->GetObject (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->Close (); } -Ptr -PacketSink::GetTraceResolver (void) const -{ - Ptr resolver = Create (); - resolver->AddSource ("rx", - TraceDoc ("A new packet has been received", - "Ptr", - "The newly-received packet.", - "const Address &", - "The source address of the received packet."), - m_rxTrace); - resolver->SetParentResolver (Application::GetTraceResolver ()); - return resolver; -} - } // Namespace ns3 diff --git a/src/applications/packet-sink/packet-sink.h b/src/applications/packet-sink/packet-sink.h index 844effcba..e1d412b57 100644 --- a/src/applications/packet-sink/packet-sink.h +++ b/src/applications/packet-sink/packet-sink.h @@ -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 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 GetTraceResolver (void) const; - - void Construct (Ptr n, - const Address &local, - std::string tid); virtual void Receive (Ptr socket, Ptr packet, const Address& from); virtual void CloseConnection (Ptr socket); Ptr m_socket; // Associated socket Address m_local; // Local address to bind to - std::string m_tid; // Protocol name (e.g., "Udp") - CallbackTraceSource, const Address &> m_rxTrace; + TypeId m_tid; // Protocol TypeId + TracedCallback, const Address &> m_rxTrace; }; diff --git a/src/applications/udp-echo/udp-echo-client.cc b/src/applications/udp-echo/udp-echo-client.cc index 80496f7ae..d60386967 100644 --- a/src/applications/udp-echo/udp-echo-client.cc +++ b/src/applications/udp-echo/udp-echo-client.cc @@ -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 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 () + .AddConstructor () + .AddAttribute ("MaxPackets", "XXX", + Uinteger (100), + MakeUintegerAccessor (&UdpEchoClient::m_count), + MakeUintegerChecker ()) + .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 ()) + .AddAttribute ("PacketSize", "Size of packets generated", + Uinteger (100), + MakeUintegerAccessor (&UdpEchoClient::m_size), + MakeUintegerChecker ()) + ; + 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 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 (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) { diff --git a/src/applications/udp-echo/udp-echo-client.h b/src/applications/udp-echo/udp-echo-client.h index dba160a3a..b1bbef823 100644 --- a/src/applications/udp-echo/udp-echo-client.h +++ b/src/applications/udp-echo/udp-echo-client.h @@ -32,8 +32,9 @@ class Packet; class UdpEchoClient : public Application { public: - UdpEchoClient (Ptr 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 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, Ptr packet, const Address &from); - Ptr 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 m_socket; - Address m_peer; + Ipv4Address m_peerAddress; + uint16_t m_peerPort; EventId m_sendEvent; }; diff --git a/src/applications/udp-echo/udp-echo-server.cc b/src/applications/udp-echo/udp-echo-server.cc index 4af808897..10797c529 100644 --- a/src/applications/udp-echo/udp-echo-server.cc +++ b/src/applications/udp-echo/udp-echo-server.cc @@ -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 n, - uint16_t port) -: - Application(n) +TypeId +UdpEchoServer::GetTypeId (void) +{ + static TypeId tid = TypeId ("UdpEchoServer") + .SetParent () + .AddConstructor () + .AddAttribute ("Port", "Client Port", + Uinteger (0), + MakeUintegerAccessor (&UdpEchoServer::m_port), + MakeUintegerChecker ()) + ; + 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 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 = GetNode ()->GetObject (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)); diff --git a/src/applications/udp-echo/udp-echo-server.h b/src/applications/udp-echo/udp-echo-server.h index 82dbf7126..f8bccabfb 100644 --- a/src/applications/udp-echo/udp-echo-server.h +++ b/src/applications/udp-echo/udp-echo-server.h @@ -32,23 +32,21 @@ class Packet; class UdpEchoServer : public Application { public: - UdpEchoServer (Ptr n, uint16_t clientPort); + static TypeId GetTypeId (void); + UdpEchoServer (); virtual ~UdpEchoServer (); protected: virtual void DoDispose (void); private: - void Construct (Ptr n, uint16_t clientPort); virtual void StartApplication (void); virtual void StopApplication (void); void Receive(Ptr socket, Ptr packet, const Address &from); - Ptr m_node; uint16_t m_port; - Ptr m_socket; Address m_local; }; diff --git a/src/node/application.cc b/src/node/application.cc index 73d8b47ed..669e45bdb 100644 --- a/src/node/application.cc +++ b/src/node/application.cc @@ -31,14 +31,26 @@ using namespace std; namespace ns3 { +NS_OBJECT_ENSURE_REGISTERED (Application); + // Application Methods -// \brief Application Constructor -Application::Application(Ptr n) - : m_node (n) +TypeId +Application::GetTypeId (void) { - m_node->AddApplication (this); + static TypeId tid = TypeId ("Application") + .SetParent () + .AddAttribute ("Node", "The on which this application resides", + Ptr (0), + MakePtrAccessor (&Application::m_node), + MakePtrChecker ()) + ; + return tid; } + +// \brief Application Constructor +Application::Application() +{} // \brief Application Destructor Application::~Application() diff --git a/src/node/application.h b/src/node/application.h index f761467fe..6ef9ee246 100644 --- a/src/node/application.h +++ b/src/node/application.h @@ -52,7 +52,8 @@ class RandomVariable; class Application : public Object { public: - Application(Ptr); + static TypeId GetTypeId (void); + Application(); virtual ~Application(); /** diff --git a/tutorial/tutorial-bus-network.cc b/tutorial/tutorial-bus-network.cc index f61af0376..8c2579c36 100644 --- a/tutorial/tutorial-bus-network.cc +++ b/tutorial/tutorial-bus-network.cc @@ -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 n0 = bus.GetNode (0); - Ptr client = CreateObject (n0, "10.1.0.1", - port, 1, Seconds(1.), 1024); + Ptr client = + CreateObjectWith ("Node", n0, + "RemoteIpv4", Ipv4Address ("10.1.0.1"), + "RemotePort", Uinteger (port), + "MaxPackets", Uinteger (1), + "Interval", Seconds(1.), + "PacketSize", Uinteger (1024)); + n0->AddApplication (client); Ptr n1 = bus.GetNode (1); - Ptr server = CreateObject (n1, port); + Ptr server = + CreateObjectWith ("Node", n1, "Port", Uinteger (port)); + n1->AddApplication (server); server->Start(Seconds(1.)); client->Start(Seconds(2.)); diff --git a/tutorial/tutorial-csma-echo-ascii-trace.cc b/tutorial/tutorial-csma-echo-ascii-trace.cc index f7b6256ce..c8b048c90 100644 --- a/tutorial/tutorial-csma-echo-ascii-trace.cc +++ b/tutorial/tutorial-csma-echo-ascii-trace.cc @@ -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 client = CreateObject (n0, "10.1.1.2", - port, 1, Seconds(1.), 1024); + Ptr client = + CreateObjectWith ("Node", n0, + "RemoteIpv4", Ipv4Address ("10.1.1.2"), + "RemotePort", Uinteger (port), + "MaxPackets", Uinteger (1), + "Interval", Seconds(1.), + "PacketSize", Uinteger (1024)); + n0->AddApplication (client); - Ptr server = CreateObject (n1, port); + Ptr server = + CreateObjectWith ("Node", n1, + "Port", Uinteger (port)); + n1->AddApplication (server); server->Start(Seconds(1.)); client->Start(Seconds(2.)); diff --git a/tutorial/tutorial-csma-echo-pcap-trace.cc b/tutorial/tutorial-csma-echo-pcap-trace.cc index ad657e577..310db8794 100644 --- a/tutorial/tutorial-csma-echo-pcap-trace.cc +++ b/tutorial/tutorial-csma-echo-pcap-trace.cc @@ -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 client = CreateObject (n0, "10.1.1.2", - port, 1, Seconds(1.), 1024); + Ptr client = + CreateObjectWith ("Node", n0, + "RemoteIpv4", Ipv4Address ("10.1.1.2"), + "RemotePort", Uinteger (port), + "MaxPackets", Uinteger (1), + "Interval", Seconds(1.), + "PacketSize", Uinteger (1024)); + n0->AddApplication (client); - Ptr server = CreateObject (n1, port); + Ptr server = + CreateObjectWith ("Node", n1, + "Port", Uinteger (port)); + n1->AddApplication (server); server->Start(Seconds(1.)); client->Start(Seconds(2.)); diff --git a/tutorial/tutorial-csma-echo.cc b/tutorial/tutorial-csma-echo.cc index 000e96734..ccf9e8cb0 100644 --- a/tutorial/tutorial-csma-echo.cc +++ b/tutorial/tutorial-csma-echo.cc @@ -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 client = CreateObject (n0, "10.1.1.2", - port, 1, Seconds(1.), 1024); + Ptr client = + CreateObjectWith ("Node", n0, + "RemoteIpv4", Ipv4Address ("10.1.1.2"), + "RemotePort", Uinteger (port), + "MaxPackets", Uinteger (1), + "Interval", Seconds(1.), + "PacketSize", Uinteger (1024)); + n0->AddApplication (client); - Ptr server = CreateObject (n1, port); + Ptr server = + CreateObjectWith ("Node", n1, + "Port", Uinteger (port)); + n1->AddApplication (server); server->Start(Seconds(1.)); client->Start(Seconds(2.)); diff --git a/tutorial/tutorial-linear-dumbbell.cc b/tutorial/tutorial-linear-dumbbell.cc index c88df894e..847664d31 100644 --- a/tutorial/tutorial-linear-dumbbell.cc +++ b/tutorial/tutorial-linear-dumbbell.cc @@ -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 client0 = CreateObject (n0, "10.1.2.1", - port, 100, Seconds(.01), 1024); - Ptr client1 = CreateObject (n1, "10.1.2.2", - port, 100, Seconds(.01), 1024); - Ptr client2 = CreateObject (n2, "10.1.2.3", - port, 100, Seconds(.01), 1024); - Ptr client3 = CreateObject (n3, "10.1.2.4", - port, 100, Seconds(.01), 1024); + Ptr client0 = + CreateObjectWith ( + "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 client1 = + CreateObjectWith ( + "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 client2 = + CreateObjectWith ( + "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 client3 = + CreateObjectWith ( + "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 server4 = CreateObject (n4, port); - Ptr server5 = CreateObject (n5, port); - Ptr server6 = CreateObject (n6, port); - Ptr server7 = CreateObject (n7, port); + Ptr server4 = + CreateObjectWith ("Node", n4, "Port", Uinteger (port)); + n4->AddApplication (server4); + Ptr server5 = + CreateObjectWith ("Node", n5, "Port", Uinteger (port)); + n5->AddApplication (server5); + Ptr server6 = + CreateObjectWith ("Node", n6, "Port", Uinteger (port)); + n6->AddApplication (server6); + Ptr server7 = + CreateObjectWith ("Node", n7, "Port", Uinteger (port)); + n7->AddApplication (server7); server4->Start(Seconds(1.)); server5->Start(Seconds(1.)); diff --git a/tutorial/tutorial-point-to-point.cc b/tutorial/tutorial-point-to-point.cc index 088ac796b..a94c9f8bf 100644 --- a/tutorial/tutorial-point-to-point.cc +++ b/tutorial/tutorial-point-to-point.cc @@ -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 client = CreateObject (n0, "10.1.1.2", - port, 1, Seconds(1.), 1024); + Ptr client = + CreateObjectWith ("Node", n0, + "RemoteIpv4", Ipv4Address ("10.1.1.2"), + "RemotePort", Uinteger (port), + "MaxPackets", Uinteger (1), + "Interval", Seconds(1.), + "PacketSize", Uinteger (1024)); + n0->AddApplication (client); - Ptr server = CreateObject (n1, port); + Ptr server = + CreateObjectWith ("Node", n1, + "Port", Uinteger (port)); + n1->AddApplication (server); server->Start(Seconds(1.)); client->Start(Seconds(2.)); diff --git a/tutorial/tutorial-star-routing.cc b/tutorial/tutorial-star-routing.cc index 8e9a6e828..381d3a7eb 100644 --- a/tutorial/tutorial-star-routing.cc +++ b/tutorial/tutorial-star-routing.cc @@ -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 client = CreateObject (n4, "10.1.1.2", - port, 1, Seconds(1.), 1024); + Ptr client = + CreateObjectWith ("Node", n4, + "RemoteIpv4", Ipv4Address ("10.1.1.2"), + "RemotePort", Uinteger (port), + "MaxPackets", Uinteger (1), + "Interval", Seconds(1.), + "PacketSize", Uinteger (1024)); + n0->AddApplication (client); - Ptr server = CreateObject (n1, port); + Ptr server = + CreateObjectWith ("Node", n1, + "Port", Uinteger (port)); + n1->AddApplication (server); server->Start(Seconds(1.)); client->Start(Seconds(2.)); diff --git a/tutorial/tutorial-star.cc b/tutorial/tutorial-star.cc index c2261afe9..443506b41 100644 --- a/tutorial/tutorial-star.cc +++ b/tutorial/tutorial-star.cc @@ -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 client = CreateObject (n0, "10.1.1.2", - port, 1, Seconds(1.), 1024); + Ptr client = + CreateObjectWith ("Node", n0, + "RemoteIpv4", Ipv4Address ("10.1.1.2"), + "RemotePort", Uinteger (port), + "MaxPackets", Uinteger (1), + "Interval", Seconds(1.), + "PacketSize", Uinteger (1024)); + n0->AddApplication (client); - Ptr server = CreateObject (n1, port); + Ptr server = + CreateObjectWith ("Node", n1, + "Port", Uinteger (port)); + n1->AddApplication (server); server->Start(Seconds(1.)); client->Start(Seconds(2.));