From da1cf74f9093ef863ce4f0f2c08efbfebb43e0c2 Mon Sep 17 00:00:00 2001 From: Mitch Watrous Date: Mon, 20 Aug 2012 14:25:35 -0700 Subject: [PATCH] Replace various instances of RandomVariable with RandomVariableStream --- examples/matrix-topology/matrix-topology.cc | 10 +-- examples/routing/manet-routing-compare.cc | 8 +-- examples/wireless/multirate.cc | 28 +++++--- src/core/examples/sample-simulator.cc | 9 ++- src/core/examples/sample-simulator.py | 4 +- src/core/test/attribute-test-suite.cc | 65 ++++++++++++++----- src/dsdv/examples/dsdv-manet.cc | 21 +++--- src/dsr/examples/dsr.cc | 24 +++++-- .../examples/wifi-olsr-flowmon.py | 5 +- src/lte/examples/lena-profiling.cc | 12 ++-- src/lte/examples/lena-rem-sector-antenna.cc | 12 ++-- src/mpi/examples/nms-p2p-nix-distributed.cc | 18 ++--- src/netanim/examples/dynamic_linknode.cc | 4 +- src/netanim/examples/uan-animation.cc | 18 +++-- src/network/examples/droptail_vs_red.cc | 4 +- src/network/model/application.cc | 1 - src/network/test/buffer-test.cc | 9 ++- src/network/utils/error-model.cc | 1 - .../examples/nms-p2p-nix.cc | 4 +- .../wifi-msdu-aggregator-test-suite.cc | 1 - .../examples/topology-example-sim.cc | 10 +-- .../examples/virtual-net-device.cc | 5 +- 22 files changed, 176 insertions(+), 97 deletions(-) mode change 100644 => 100755 src/core/examples/sample-simulator.py diff --git a/examples/matrix-topology/matrix-topology.cc b/examples/matrix-topology/matrix-topology.cc index 5c6366a82..81d569021 100644 --- a/examples/matrix-topology/matrix-topology.cc +++ b/examples/matrix-topology/matrix-topology.cc @@ -243,15 +243,17 @@ int main (int argc, char *argv[]) // same time. This rn is added to AppStartTime to have the sources // start at different time, however they will still send at the same rate. - UniformVariable x (0,1); - double rn = x.GetValue (); + Ptr x = CreateObject (); + x->SetAttribute ("Min", DoubleValue (0)); + x->SetAttribute ("Max", DoubleValue (1)); + double rn = x->GetValue (); Ptr n = nodes.Get (j); Ptr ipv4 = n->GetObject (); Ipv4InterfaceAddress ipv4_int_addr = ipv4->GetAddress (1, 0); Ipv4Address ip_addr = ipv4_int_addr.GetLocal (); OnOffHelper onoff ("ns3::UdpSocketFactory", InetSocketAddress (ip_addr, port)); // traffic flows from node[i] to node[j] - onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); - onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); + onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]")); + onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]")); ApplicationContainer apps = onoff.Install (nodes.Get (i)); // traffic sources are installed on all nodes apps.Start (Seconds (AppStartTime + rn)); apps.Stop (Seconds (AppStopTime)); diff --git a/examples/routing/manet-routing-compare.cc b/examples/routing/manet-routing-compare.cc index 0383f936b..24b725d80 100644 --- a/examples/routing/manet-routing-compare.cc +++ b/examples/routing/manet-routing-compare.cc @@ -340,8 +340,8 @@ RoutingExperiment::Run (int nSinks, double txp, std::string CSVfileName) adhocInterfaces = addressAdhoc.Assign (adhocDevices); OnOffHelper onoff1 ("ns3::UdpSocketFactory",Address ()); - onoff1.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); - onoff1.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); + onoff1.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]")); + onoff1.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]")); for (int i = 0; i <= nSinks - 1; i++) { @@ -350,9 +350,9 @@ RoutingExperiment::Run (int nSinks, double txp, std::string CSVfileName) AddressValue remoteAddress (InetSocketAddress (adhocInterfaces.GetAddress (i), port)); onoff1.SetAttribute ("Remote", remoteAddress); - UniformVariable var; + Ptr var = CreateObject (); ApplicationContainer temp = onoff1.Install (adhocNodes.Get (i + nSinks)); - temp.Start (Seconds (var.GetValue (100.0,101.0))); + temp.Start (Seconds (var->GetValue (100.0,101.0))); temp.Stop (Seconds (TotalTime)); } diff --git a/examples/wireless/multirate.cc b/examples/wireless/multirate.cc index e8b740416..3e82a47f0 100644 --- a/examples/wireless/multirate.cc +++ b/examples/wireless/multirate.cc @@ -53,7 +53,7 @@ #include "ns3/applications-module.h" #include "ns3/mobility-module.h" #include "ns3/tools-module.h" -#include "ns3/random-variable.h" +#include "ns3/random-variable-stream.h" #include "ns3/wifi-module.h" #include "ns3/internet-module.h" #include "ns3/flow-monitor-helper.h" @@ -253,12 +253,16 @@ void Experiment::SelectSrcDest (NodeContainer c) { uint32_t totalNodes = c.GetN (); - UniformVariable uvSrc (0, totalNodes/2 -1); - UniformVariable uvDest (totalNodes/2, totalNodes); + Ptr uvSrc = CreateObject (); + uvSrc->SetAttribute ("Min", DoubleValue (0)); + uvSrc->SetAttribute ("Max", DoubleValue (totalNodes/2 -1)); + Ptr uvDest = CreateObject (); + uvDest->SetAttribute ("Min", DoubleValue (totalNodes/2)); + uvDest->SetAttribute ("Max", DoubleValue (totalNodes)); for (uint32_t i=0; i < totalNodes/3; i++) { - ApplicationSetup (c.Get (uvSrc.RandomVariable::GetInteger ()), c.Get (uvDest.RandomVariable::GetInteger ()), 0, totalTime); + ApplicationSetup (c.Get (uvSrc->GetInteger ()), c.Get (uvDest->GetInteger ()), 0, totalTime); } } @@ -273,21 +277,25 @@ Experiment::SendMultiDestinations (Ptr sender, NodeContainer c) { // UniformVariable params: (Xrange, Yrange) - UniformVariable uv (0, c.GetN ()); + Ptr uv = CreateObject (); + uv->SetAttribute ("Min", DoubleValue (0)); + uv->SetAttribute ("Max", DoubleValue (c.GetN ())); // ExponentialVariable params: (mean, upperbound) - ExponentialVariable ev (expMean, totalTime); + Ptr ev = CreateObject (); + ev->SetAttribute ("Mean", DoubleValue (expMean)); + ev->SetAttribute ("Bound", DoubleValue (totalTime)); double start=0.0, stop=totalTime; uint32_t destIndex; for (uint32_t i=0; i < c.GetN (); i++) { - stop = start + ev.GetValue (); + stop = start + ev->GetValue (); NS_LOG_DEBUG ("Start=" << start << " Stop=" << stop); do { - destIndex = (uint32_t) uv.GetValue (); + destIndex = (uint32_t) uv->GetValue (); } while ( (c.Get (destIndex))->GetId () == sender->GetId ()); ApplicationSetup (sender, c.Get (destIndex), start, stop); @@ -420,8 +428,8 @@ Experiment::Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy, //Rectangle (xMin, xMax, yMin, yMax) mobil.SetMobilityModel ("ns3::RandomDirection2dMobilityModel", "Bounds", RectangleValue (Rectangle (0, 500, 0, 500)), - "Speed", RandomVariableValue (ConstantVariable (10)), - "Pause", RandomVariableValue (ConstantVariable (0.2))); + "Speed", StringValue ("ns3::ConstantRandomVariable[Constant=10]"), + "Pause", StringValue ("ns3::ConstantRandomVariable[Constant=0.2]")); } mobil.Install (c); diff --git a/src/core/examples/sample-simulator.cc b/src/core/examples/sample-simulator.cc index 85ca62ae3..4accc4b45 100644 --- a/src/core/examples/sample-simulator.cc +++ b/src/core/examples/sample-simulator.cc @@ -22,7 +22,8 @@ #include "ns3/simulator.h" #include "ns3/nstime.h" #include "ns3/command-line.h" -#include "ns3/random-variable.h" +#include "ns3/double.h" +#include "ns3/random-variable-stream.h" using namespace ns3; @@ -76,11 +77,13 @@ int main (int argc, char *argv[]) cmd.Parse (argc, argv); MyModel model; - UniformVariable v = UniformVariable (10, 20); + Ptr v = CreateObject (); + v->SetAttribute ("Min", DoubleValue (10)); + v->SetAttribute ("Max", DoubleValue (20)); Simulator::Schedule (Seconds (10.0), &ExampleFunction, &model); - Simulator::Schedule (Seconds (v.GetValue ()), &RandomFunction); + Simulator::Schedule (Seconds (v->GetValue ()), &RandomFunction); EventId id = Simulator::Schedule (Seconds (30.0), &CancelledEvent); Simulator::Cancel (id); diff --git a/src/core/examples/sample-simulator.py b/src/core/examples/sample-simulator.py old mode 100644 new mode 100755 index 3c8acc4c3..f466b90be --- a/src/core/examples/sample-simulator.py +++ b/src/core/examples/sample-simulator.py @@ -44,7 +44,9 @@ def CancelledEvent(): def main(dummy_argv): model = MyModel() - v = ns.core.UniformVariable(10,20) + v = ns.core.UniformRandomVariable() + v.SetAttribute("Min", ns.core.DoubleValue (10)) + v.SetAttribute("Max", ns.core.DoubleValue (20)) ns.core.Simulator.Schedule(ns.core.Seconds(10.0), ExampleFunction, model) diff --git a/src/core/test/attribute-test-suite.cc b/src/core/test/attribute-test-suite.cc index e1d45b2a7..704ce9e8f 100644 --- a/src/core/test/attribute-test-suite.cc +++ b/src/core/test/attribute-test-suite.cc @@ -24,7 +24,7 @@ #include "ns3/config.h" #include "ns3/enum.h" #include "ns3/string.h" -#include "ns3/random-variable.h" +#include "ns3/random-variable-stream.h" #include "ns3/double.h" #include "ns3/object-vector.h" #include "ns3/object-map.h" @@ -119,9 +119,9 @@ public: TEST_B, "TestB", TEST_C, "TestC")) .AddAttribute ("TestRandom", "help text", - RandomVariableValue (ConstantVariable (1.0)), - MakeRandomVariableAccessor (&AttributeObjectTest::m_random), - MakeRandomVariableChecker ()) + StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"), + MakePointerAccessor (&AttributeObjectTest::m_random), + MakePointerChecker ()) .AddAttribute ("TestFloat", "help text", DoubleValue (-1.1), MakeDoubleAccessor (&AttributeObjectTest::m_float), @@ -227,7 +227,7 @@ private: uint8_t m_uint8; float m_float; enum Test_e m_enum; - RandomVariable m_random; + Ptr m_random; std::vector > m_vector1; std::vector > m_vector2; std::map > m_map1; @@ -643,8 +643,39 @@ AttributeTestCase::DoRun (void) NS_TEST_ASSERT_MSG_EQ (ok, true, "Error in SetAttributeFailSafe() but value changes"); } -template <> void -AttributeTestCase::DoRun (void) +// =========================================================================== +// Test the Attributes of type RandomVariableStream. +// =========================================================================== +class RandomVariableStreamAttributeTestCase : public TestCase +{ +public: + RandomVariableStreamAttributeTestCase (std::string description); + virtual ~RandomVariableStreamAttributeTestCase () {} + + void InvokeCbValue (int8_t a) + { + if (!m_cbValue.IsNull ()) { + m_cbValue (a); + } + } + +private: + virtual void DoRun (void); + + Callback m_cbValue; + + void NotifyCallbackValue (int8_t a) { m_gotCbValue = a; } + + int16_t m_gotCbValue; +}; + +RandomVariableStreamAttributeTestCase::RandomVariableStreamAttributeTestCase (std::string description) + : TestCase (description) +{ +} + +void +RandomVariableStreamAttributeTestCase::DoRun (void) { Ptr p; bool ok; @@ -653,16 +684,20 @@ AttributeTestCase::DoRun (void) NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject"); // - // Try to set a UniformVariable + // Try to set a UniformRandomVariable // - ok = p->SetAttributeFailSafe ("TestRandom", RandomVariableValue (UniformVariable (0., 1.))); - NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a UniformVariable"); + ok = p->SetAttributeFailSafe ("TestRandom", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]")); + NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a UniformRandomVariable"); // - // Try to set a ConstantVariable + // Try to set a ConstantRandomVariable // - ok = p->SetAttributeFailSafe ("TestRandom", RandomVariableValue (ConstantVariable (10.))); - NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a UniformVariable"); + // ok = p->SetAttributeFailSafe ("TestRandom", StringValue ("ns3::ConstantRandomVariable[Constant=10.0]")); + //ok = p->SetAttributeFailSafe ("TestRandom", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]")); + + ok = p->SetAttributeFailSafe ("TestRandom", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]")); + + NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a ConstantRandomVariable"); } // =========================================================================== @@ -1147,7 +1182,7 @@ PointerAttributeTestCase::DoRun (void) } // =========================================================================== -// Test the Attributes of type CallbackVale. +// Test the Attributes of type CallbackValue. // =========================================================================== class CallbackValueTestCase : public TestCase { @@ -1244,7 +1279,7 @@ AttributesTestSuite::AttributesTestSuite () AddTestCase (new AttributeTestCase ("Check Attributes of type UintegerValue")); AddTestCase (new AttributeTestCase ("Check Attributes of type DoubleValue")); AddTestCase (new AttributeTestCase ("Check Attributes of type EnumValue")); - AddTestCase (new AttributeTestCase ("Check Attributes of type RandomVariableValue")); + AddTestCase (new RandomVariableStreamAttributeTestCase ("Check Attributes of type RandomVariableStream")); AddTestCase (new ObjectVectorAttributeTestCase ("Check Attributes of type ObjectVectorValue")); AddTestCase (new ObjectMapAttributeTestCase ("Check Attributes of type ObjectMapValue")); AddTestCase (new IntegerTraceSourceAttributeTestCase ("Ensure TracedValue can be set like IntegerValue")); diff --git a/src/dsdv/examples/dsdv-manet.cc b/src/dsdv/examples/dsdv-manet.cc index 574a53f2f..36ceaf20d 100644 --- a/src/dsdv/examples/dsdv-manet.cc +++ b/src/dsdv/examples/dsdv-manet.cc @@ -247,12 +247,17 @@ DsdvManetExample::SetupMobility () MobilityHelper mobility; ObjectFactory pos; pos.SetTypeId ("ns3::RandomRectanglePositionAllocator"); - pos.Set ("X", RandomVariableValue (UniformVariable (0, 1000))); - pos.Set ("Y", RandomVariableValue (UniformVariable (0, 1000))); + pos.Set ("X", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=1000.0]")); + pos.Set ("Y", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=1000.0]")); + + ostringstream speedConstantRandomVariableStream; + speedConstantRandomVariableStream << "ns3::ConstantRandomVariable[Constant=" + << m_nodeSpeed + << "]"; Ptr taPositionAlloc = pos.Create ()->GetObject (); - mobility.SetMobilityModel ("ns3::RandomWaypointMobilityModel", "Speed", RandomVariableValue (ConstantVariable (m_nodeSpeed)), - "Pause", RandomVariableValue (ConstantVariable (2.0)), "PositionAllocator", PointerValue (taPositionAlloc)); + mobility.SetMobilityModel ("ns3::RandomWaypointMobilityModel", "Speed", StringValue (speedConstantRandomVariableStream.str ()), + "Pause", StringValue ("ns3::ConstantRandomVariable[Constant=2.0]"), "PositionAllocator", PointerValue (taPositionAlloc)); mobility.SetPositionAllocator (taPositionAlloc); mobility.Install (nodes); } @@ -312,14 +317,14 @@ DsdvManetExample::InstallApplications () for (uint32_t j = 0; j <= m_nSinks - 1; j++ ) { OnOffHelper onoff1 ("ns3::UdpSocketFactory", Address (InetSocketAddress (interfaces.GetAddress (j), port))); - onoff1.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); - onoff1.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); + onoff1.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]")); + onoff1.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]")); if (j != clientNode) { ApplicationContainer apps1 = onoff1.Install (nodes.Get (clientNode)); - UniformVariable var; - apps1.Start (Seconds (var.GetValue (m_dataStart, m_dataStart + 1))); + Ptr var = CreateObject (); + apps1.Start (Seconds (var->GetValue (m_dataStart, m_dataStart + 1))); apps1.Stop (Seconds (m_totalTime)); } } diff --git a/src/dsr/examples/dsr.cc b/src/dsr/examples/dsr.cc index 0d8604130..1997cf561 100644 --- a/src/dsr/examples/dsr.cc +++ b/src/dsr/examples/dsr.cc @@ -37,6 +37,7 @@ #include "ns3/wifi-module.h" #include "ns3/internet-module.h" #include "ns3/dsr-module.h" +#include using namespace ns3; NS_LOG_COMPONENT_DEFINE ("DsrTest"); @@ -142,13 +143,24 @@ main (int argc, char *argv[]) MobilityHelper adhocMobility; ObjectFactory pos; pos.SetTypeId ("ns3::RandomRectanglePositionAllocator"); - pos.Set ("X", RandomVariableValue (UniformVariable (0.0, 300.0))); - pos.Set ("Y", RandomVariableValue (UniformVariable (0.0, 1500.0))); + pos.Set ("X", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=300.0]")); + pos.Set ("Y", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=1500.0]")); Ptr taPositionAlloc = pos.Create ()->GetObject (); + ostringstream speedUniformRandomVariableStream; + speedUniformRandomVariableStream << "ns3::UniformRandomVariable[Min=0.0|Max=" + << nodeSpeed + << "]"; + + ostringstream pauseConstantRandomVariableStream; + pauseConstantRandomVariableStream << "ns3::ConstantRandomVariable[Constant=" + << pauseTime + << "]"; + adhocMobility.SetMobilityModel ("ns3::RandomWaypointMobilityModel", - "Speed", RandomVariableValue (UniformVariable (0.0, nodeSpeed)), - "Pause", RandomVariableValue (ConstantVariable (pauseTime)), + // "Speed", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=nodeSpeed]"), + "Speed", StringValue (speedUniformRandomVariableStream.str ()), + "Pause", StringValue (pauseConstantRandomVariableStream.str ()), "PositionAllocator", PointerValue (taPositionAlloc) ); adhocMobility.Install (adhocNodes); @@ -176,8 +188,8 @@ main (int argc, char *argv[]) apps_sink.Stop (Seconds (TotalTime)); OnOffHelper onoff1 ("ns3::UdpSocketFactory", Address (InetSocketAddress (allInterfaces.GetAddress (i), port))); - onoff1.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); - onoff1.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); + onoff1.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]")); + onoff1.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]")); onoff1.SetAttribute ("PacketSize", UintegerValue (packetSize)); onoff1.SetAttribute ("DataRate", DataRateValue (DataRate (rate))); diff --git a/src/flow-monitor/examples/wifi-olsr-flowmon.py b/src/flow-monitor/examples/wifi-olsr-flowmon.py index 8a3ad8fe5..8be38023b 100644 --- a/src/flow-monitor/examples/wifi-olsr-flowmon.py +++ b/src/flow-monitor/examples/wifi-olsr-flowmon.py @@ -102,8 +102,9 @@ def main(argv): #print i, destaddr onOffHelper.SetAttribute("Remote", ns.network.AddressValue(ns.network.InetSocketAddress(destaddr, port))) app = onOffHelper.Install(ns.network.NodeContainer(node)) - app.Start(ns.core.Seconds(ns.core.UniformVariable(20, 30).GetValue())) - + urv = ns.core.UniformRandomVariable() + app.Start(ns.core.Seconds(urv.GetValue(20, 30))) + #internet.EnablePcapAll("wifi-olsr") flowmon_helper = ns.flow_monitor.FlowMonitorHelper() #flowmon_helper.SetMonitorAttribute("StartTime", ns.core.TimeValue(ns.core.Seconds(31))) diff --git a/src/lte/examples/lena-profiling.cc b/src/lte/examples/lena-profiling.cc index dc2f65c27..af2b6dd11 100644 --- a/src/lte/examples/lena-profiling.cc +++ b/src/lte/examples/lena-profiling.cc @@ -116,14 +116,16 @@ main (int argc, char *argv[]) // Position of UEs attached to eNB for (uint32_t i = 0; i < nEnb; i++) { - UniformVariable posX (enbPosition.at(i).x - roomLength * 0.5, - enbPosition.at(i).x + roomLength * 0.5); - UniformVariable posY (enbPosition.at(i).y - roomLength * 0.5, - enbPosition.at(i).y + roomLength * 0.5); + Ptr posX = CreateObject (); + posX->SetAttribute ("Min", DoubleValue (enbPosition.at(i).x - roomLength * 0.5)); + posX->SetAttribute ("Max", DoubleValue (enbPosition.at(i).x + roomLength * 0.5)); + Ptr posY = CreateObject (); + posY->SetAttribute ("Min", DoubleValue (enbPosition.at(i).y - roomLength * 0.5)); + posY->SetAttribute ("Max", DoubleValue (enbPosition.at(i).y + roomLength * 0.5)); positionAlloc = CreateObject (); for (uint32_t j = 0; j < nUe; j++) { - positionAlloc->Add (Vector (posX.GetValue (), posY.GetValue (), nodeHeight)); + positionAlloc->Add (Vector (posX->GetValue (), posY->GetValue (), nodeHeight)); mobility.SetPositionAllocator (positionAlloc); } mobility.Install (ueNodes.at(i)); diff --git a/src/lte/examples/lena-rem-sector-antenna.cc b/src/lte/examples/lena-rem-sector-antenna.cc index 66e7b22fa..ddefca68e 100644 --- a/src/lte/examples/lena-rem-sector-antenna.cc +++ b/src/lte/examples/lena-rem-sector-antenna.cc @@ -131,10 +131,12 @@ main (int argc, char *argv[]) // Position of UEs attached to eNB for (uint32_t i = 0; i < nEnb; i++) { - UniformVariable posX (enbPosition.at(i).x - roomLength * 0, - enbPosition.at(i).x + roomLength * 0); - UniformVariable posY (enbPosition.at(i).y - roomLength * 0, - enbPosition.at(i).y + roomLength * 0); + Ptr posX = CreateObject (); + posX->SetAttribute ("Min", DoubleValue (enbPosition.at(i).x - roomLength * 0)); + posX->SetAttribute ("Max", DoubleValue (enbPosition.at(i).x + roomLength * 0)); + Ptr posY = CreateObject (); + posY->SetAttribute ("Min", DoubleValue (enbPosition.at(i).y - roomLength * 0)); + posY->SetAttribute ("Max", DoubleValue (enbPosition.at(i).y + roomLength * 0)); positionAlloc = CreateObject (); for (uint32_t j = 0; j < nUe; j++) { @@ -152,7 +154,7 @@ main (int argc, char *argv[]) } else { - positionAlloc->Add (Vector (posX.GetValue (), posY.GetValue (), nodeHeight)); + positionAlloc->Add (Vector (posX->GetValue (), posY->GetValue (), nodeHeight)); } mobility.SetPositionAllocator (positionAlloc); } diff --git a/src/mpi/examples/nms-p2p-nix-distributed.cc b/src/mpi/examples/nms-p2p-nix-distributed.cc index ed2961347..690669be1 100644 --- a/src/mpi/examples/nms-p2p-nix-distributed.cc +++ b/src/mpi/examples/nms-p2p-nix-distributed.cc @@ -441,7 +441,7 @@ main (int argc, char *argv[]) } else { - UniformVariable urng; + Ptr urng = CreateObject (); int r1; double r2; for (uint32_t z = 0; z < nCN; ++z) @@ -483,8 +483,8 @@ main (int argc, char *argv[]) // Sources if (systemCount == 1) { - r1 = 2 + (int)(4 * urng.GetValue ()); - r2 = 10 * urng.GetValue (); + r1 = 2 + (int)(4 * urng->GetValue ()); + r2 = 10 * urng->GetValue (); OnOffHelper client ("ns3::UdpSocketFactory", Address ()); AddressValue remoteAddress @@ -497,8 +497,8 @@ main (int argc, char *argv[]) } else if (systemId == x % systemCount) { - r1 = 2 + (int)(4 * urng.GetValue ()); - r2 = 10 * urng.GetValue (); + r1 = 2 + (int)(4 * urng->GetValue ()); + r2 = 10 * urng->GetValue (); OnOffHelper client ("ns3::UdpSocketFactory", Address ()); AddressValue remoteAddress @@ -543,8 +543,8 @@ main (int argc, char *argv[]) // Sources if (systemCount == 1) { - r1 = 2 + (int)(4 * urng.GetValue ()); - r2 = 10 * urng.GetValue (); + r1 = 2 + (int)(4 * urng->GetValue ()); + r2 = 10 * urng->GetValue (); OnOffHelper client ("ns3::UdpSocketFactory", Address ()); AddressValue remoteAddress @@ -557,8 +557,8 @@ main (int argc, char *argv[]) } else if (systemId == x % systemCount) { - r1 = 2 + (int)(4 * urng.GetValue ()); - r2 = 10 * urng.GetValue (); + r1 = 2 + (int)(4 * urng->GetValue ()); + r2 = 10 * urng->GetValue (); OnOffHelper client ("ns3::UdpSocketFactory", Address ()); AddressValue remoteAddress diff --git a/src/netanim/examples/dynamic_linknode.cc b/src/netanim/examples/dynamic_linknode.cc index 63f6004ea..a2991a169 100644 --- a/src/netanim/examples/dynamic_linknode.cc +++ b/src/netanim/examples/dynamic_linknode.cc @@ -133,9 +133,9 @@ int main (int argc, char *argv[]) // Install on/off app on all right side nodes OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ()); clientHelper.SetAttribute - ("OnTime", RandomVariableValue (UniformVariable (0, 1))); + ("OnTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]")); clientHelper.SetAttribute - ("OffTime", RandomVariableValue (UniformVariable (0, 1))); + ("OffTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]")); ApplicationContainer clientApps; for (uint32_t i = 0; i < d.RightCount (); ++i) diff --git a/src/netanim/examples/uan-animation.cc b/src/netanim/examples/uan-animation.cc index b5acc2e1a..17e57db2f 100644 --- a/src/netanim/examples/uan-animation.cc +++ b/src/netanim/examples/uan-animation.cc @@ -99,11 +99,13 @@ NetAnimExperiment::UpdatePositions (NodeContainer &nodes) NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Updating positions"); NodeContainer::Iterator it = nodes.Begin (); - UniformVariable uv (0, m_boundary); + Ptr uv = CreateObject (); + uv->SetAttribute ("Min", DoubleValue (0.0)); + uv->SetAttribute ("Max", DoubleValue (m_boundary)); for (; it != nodes.End (); it++) { Ptr mp = (*it)->GetObject (); - mp->SetPosition (Vector (uv.GetValue (), uv.GetValue (), 70.0)); + mp->SetPosition (Vector (uv->GetValue (), uv->GetValue (), 70.0)); } } @@ -147,15 +149,17 @@ NetAnimExperiment::Run (UanHelper &uan) Ptr pos = CreateObject (); { - UniformVariable urv (0, m_boundary); + Ptr urv = CreateObject (); + urv->SetAttribute ("Min", DoubleValue (0.0)); + urv->SetAttribute ("Max", DoubleValue (m_boundary)); pos->Add (Vector (m_boundary / 2.0, m_boundary / 2.0, m_depth)); double rsum = 0; double minr = 2 * m_boundary; for (uint32_t i = 0; i < m_numNodes; i++) { - double x = urv.GetValue (); - double y = urv.GetValue (); + double x = urv->GetValue (); + double y = urv->GetValue (); double newr = sqrt ((x - m_boundary / 2.0) * (x - m_boundary / 2.0) + (y - m_boundary / 2.0) * (y - m_boundary / 2.0)); rsum += newr; @@ -179,8 +183,8 @@ NetAnimExperiment::Run (UanHelper &uan) socket.SetProtocol (0); OnOffHelper app ("ns3::PacketSocketFactory", Address (socket)); - app.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); - app.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); + app.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]")); + app.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]")); app.SetAttribute ("DataRate", DataRateValue (m_dataRate)); app.SetAttribute ("PacketSize", UintegerValue (m_packetSize)); diff --git a/src/network/examples/droptail_vs_red.cc b/src/network/examples/droptail_vs_red.cc index f2c062352..7aaf1aa2f 100644 --- a/src/network/examples/droptail_vs_red.cc +++ b/src/network/examples/droptail_vs_red.cc @@ -116,8 +116,8 @@ int main (int argc, char *argv[]) // Install on/off app on all right side nodes OnOffHelper clientHelper ("ns3::TcpSocketFactory", Address ()); - clientHelper.SetAttribute ("OnTime", RandomVariableValue (UniformVariable (0, 1))); - clientHelper.SetAttribute ("OffTime", RandomVariableValue (UniformVariable (0, 1))); + clientHelper.SetAttribute ("OnTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]")); + clientHelper.SetAttribute ("OffTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]")); Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress); ApplicationContainer sinkApps; diff --git a/src/network/model/application.cc b/src/network/model/application.cc index 7d2f38f35..bf4d8cdcc 100644 --- a/src/network/model/application.cc +++ b/src/network/model/application.cc @@ -24,7 +24,6 @@ #include "application.h" #include "ns3/node.h" #include "ns3/nstime.h" -#include "ns3/random-variable.h" #include "ns3/simulator.h" using namespace std; diff --git a/src/network/test/buffer-test.cc b/src/network/test/buffer-test.cc index 51572ee5f..d765759c4 100644 --- a/src/network/test/buffer-test.cc +++ b/src/network/test/buffer-test.cc @@ -1,5 +1,6 @@ #include "ns3/buffer.h" -#include "ns3/random-variable.h" +#include "ns3/random-variable-stream.h" +#include "ns3/double.h" #include "ns3/test.h" namespace ns3 { @@ -247,7 +248,9 @@ BufferTest::DoRun (void) { const uint32_t actualSize = 72602; const uint32_t chunkSize = 67624; - UniformVariable bytesRng (0, 256); + Ptr bytesRng = CreateObject (); + bytesRng->SetAttribute ("Min", DoubleValue (0)); + bytesRng->SetAttribute ("Max", DoubleValue (256)); Buffer inputBuffer; Buffer outputBuffer; @@ -256,7 +259,7 @@ BufferTest::DoRun (void) { Buffer::Iterator iter = inputBuffer.Begin (); for (uint32_t i = 0; i < actualSize; i++) - iter.WriteU8 (static_cast (bytesRng.GetValue ())); + iter.WriteU8 (static_cast (bytesRng->GetValue ())); } outputBuffer.AddAtEnd (chunkSize); diff --git a/src/network/utils/error-model.cc b/src/network/utils/error-model.cc index 09443fc22..79ac21f29 100644 --- a/src/network/utils/error-model.cc +++ b/src/network/utils/error-model.cc @@ -59,7 +59,6 @@ #include "ns3/packet.h" #include "ns3/assert.h" #include "ns3/log.h" -#include "ns3/random-variable.h" #include "ns3/boolean.h" #include "ns3/enum.h" #include "ns3/double.h" diff --git a/src/nix-vector-routing/examples/nms-p2p-nix.cc b/src/nix-vector-routing/examples/nms-p2p-nix.cc index 756606924..d69c5f55e 100644 --- a/src/nix-vector-routing/examples/nms-p2p-nix.cc +++ b/src/nix-vector-routing/examples/nms-p2p-nix.cc @@ -435,9 +435,9 @@ main (int argc, char *argv[]) cout << "Creating TCP Traffic Flows:" << endl; Config::SetDefault ("ns3::OnOffApplication::MaxBytes", UintegerValue (500000)); Config::SetDefault ("ns3::OnOffApplication::OnTime", - RandomVariableValue (ConstantVariable (1))); + StringValue ("ns3::ConstantRandomVariable[Constant=1.0]")); Config::SetDefault ("ns3::OnOffApplication::OffTime", - RandomVariableValue (ConstantVariable (0))); + StringValue ("ns3::ConstantRandomVariable[Constant=0.0]")); Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (512)); UniformVariable urng; diff --git a/src/test/ns3wifi/wifi-msdu-aggregator-test-suite.cc b/src/test/ns3wifi/wifi-msdu-aggregator-test-suite.cc index 58bbd399c..b1b8bd091 100644 --- a/src/test/ns3wifi/wifi-msdu-aggregator-test-suite.cc +++ b/src/test/ns3wifi/wifi-msdu-aggregator-test-suite.cc @@ -29,7 +29,6 @@ #include "ns3/data-rate.h" #include "ns3/inet-socket-address.h" #include "ns3/packet-sink.h" -#include "ns3/random-variable.h" #include "ns3/wifi-helper.h" #include "ns3/qos-wifi-mac-helper.h" diff --git a/src/topology-read/examples/topology-example-sim.cc b/src/topology-read/examples/topology-example-sim.cc index 21e9ea6c6..5005a82b5 100644 --- a/src/topology-read/examples/topology-example-sim.cc +++ b/src/topology-read/examples/topology-example-sim.cc @@ -152,9 +152,11 @@ int main (int argc, char *argv[]) uint32_t totalNodes = nodes.GetN (); - UniformVariable unifRandom (0, totalNodes - 1); + Ptr unifRandom = CreateObject (); + unifRandom->SetAttribute ("Min", DoubleValue (0)); + unifRandom->SetAttribute ("Max", DoubleValue (totalNodes - 1)); - unsigned int randomServerNumber = unifRandom.GetInteger (0, totalNodes - 1); + unsigned int randomServerNumber = unifRandom->GetInteger (0, totalNodes - 1); Ptr randomServerNode = nodes.Get (randomServerNumber); Ptr ipv4Server = randomServerNode->GetObject (); @@ -168,8 +170,8 @@ int main (int argc, char *argv[]) InetSocketAddress dst = InetSocketAddress ( ipv4AddrServer ); OnOffHelper onoff = OnOffHelper ("ns3::Ipv4RawSocketFactory", dst); - onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1.0))); - onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0))); + onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]")); + onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]")); onoff.SetAttribute ("DataRate", DataRateValue (DataRate (15000))); onoff.SetAttribute ("PacketSize", UintegerValue (1200)); diff --git a/src/virtual-net-device/examples/virtual-net-device.cc b/src/virtual-net-device/examples/virtual-net-device.cc index f288933fe..6030ad610 100644 --- a/src/virtual-net-device/examples/virtual-net-device.cc +++ b/src/virtual-net-device/examples/virtual-net-device.cc @@ -71,7 +71,7 @@ class Tunnel Ipv4Address m_n3Address; Ipv4Address m_n0Address; Ipv4Address m_n1Address; - UniformVariable m_rng; + Ptr m_rng; Ptr m_n0Tap; Ptr m_n1Tap; Ptr m_n3Tap; @@ -96,7 +96,7 @@ class Tunnel bool N3VirtualSend (Ptr packet, const Address& source, const Address& dest, uint16_t protocolNumber) { - if (m_rng.GetValue () < 0.25) + if (m_rng->GetValue () < 0.25) { NS_LOG_DEBUG ("Send to " << m_n0Address << ": " << *packet); m_n3Socket->SendTo (packet, 0, InetSocketAddress (m_n0Address, 667)); @@ -142,6 +142,7 @@ public: Ipv4Address n3Addr, Ipv4Address n0Addr, Ipv4Address n1Addr) : m_n3Address (n3Addr), m_n0Address (n0Addr), m_n1Address (n1Addr) { + m_rng = CreateObject (); m_n3Socket = Socket::CreateSocket (n3, TypeId::LookupByName ("ns3::UdpSocketFactory")); m_n3Socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), 667)); m_n3Socket->SetRecvCallback (MakeCallback (&Tunnel::N3SocketRecv, this));