introduce the ns3::String class, get rid of the string -> Attribute implicit conversion, and get rid of MakeDataRate, port PointToPointNetDevice to Attributes
This commit is contained in:
@@ -289,7 +289,7 @@ main (int argc, char *argv[])
|
||||
"Protocol", TypeId::LookupByName ("Udp"),
|
||||
"OnTime", ConstantVariable(1),
|
||||
"OffTime", ConstantVariable(0),
|
||||
"DataRate", MakeDataRate ("255b/s"),
|
||||
"DataRate", DataRate ("255b/s"),
|
||||
"PacketSize", Uinteger (128));
|
||||
n0->AddApplication (ooff);
|
||||
//
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "ns3/ptr.h"
|
||||
#include "ns3/random-variable.h"
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/string.h"
|
||||
|
||||
#include "ns3/simulator.h"
|
||||
#include "ns3/nstime.h"
|
||||
@@ -63,7 +64,7 @@ CreateCsmaDevice (Ptr<Node> node, Ptr<CsmaChannel> channel)
|
||||
{
|
||||
Ptr<CsmaNetDevice> device = CreateObjectWith<CsmaNetDevice> ("Node", node,
|
||||
"Address", Mac48Address::Allocate (),
|
||||
"EncapsulationMode", "Llc");
|
||||
"EncapsulationMode", String ("Llc"));
|
||||
node->AddDevice (device);
|
||||
device->Attach (channel);
|
||||
Ptr<Queue> queue = Queue::CreateDefault ();
|
||||
|
||||
@@ -113,7 +113,7 @@ main (int argc, char *argv[])
|
||||
DefaultValue::Bind ("Queue", "DropTailQueue");
|
||||
|
||||
Config::SetDefault ("OnOffApplication::PacketSize", Uinteger (210));
|
||||
Config::SetDefault ("OnOffApplication::DataRate", MakeDataRate ("448kb/s"));
|
||||
Config::SetDefault ("OnOffApplication::DataRate", DataRate ("448kb/s"));
|
||||
|
||||
// Allow the user to override any of the defaults and the above
|
||||
// Bind ()s at run-time, via command-line arguments
|
||||
@@ -198,7 +198,7 @@ main (int argc, char *argv[])
|
||||
"Protocol", TypeId::LookupByName ("Udp"),
|
||||
"OnTime", ConstantVariable (1),
|
||||
"OffTime", ConstantVariable (0),
|
||||
"DataRate", MakeDataRate("300bps"),
|
||||
"DataRate", DataRate("300bps"),
|
||||
"PacketSize", Uinteger (50));
|
||||
n0->AddApplication (ooff);
|
||||
// Start the application
|
||||
|
||||
@@ -108,7 +108,7 @@ main (int argc, char *argv[])
|
||||
DefaultValue::Bind ("Queue", "DropTailQueue");
|
||||
|
||||
Config::SetDefault ("OnOffApplication::PacketSize", Uinteger (210));
|
||||
Config::SetDefault ("OnOffApplication::DataRate", MakeDataRate ("300b/s"));
|
||||
Config::SetDefault ("OnOffApplication::DataRate", DataRate ("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
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "ns3/ptr.h"
|
||||
#include "ns3/config.h"
|
||||
#include "ns3/uinteger.h"
|
||||
#include "ns3/string.h"
|
||||
|
||||
#include "ns3/simulator.h"
|
||||
#include "ns3/nstime.h"
|
||||
@@ -83,10 +84,10 @@ main (int argc, char *argv[])
|
||||
|
||||
// Set a few parameters
|
||||
Config::SetDefault ("RateErrorModel::ErrorRate", Double (0.01));
|
||||
Config::SetDefault ("RateErrorModel::ErrorUnit", "EU_PKT");
|
||||
Config::SetDefault ("RateErrorModel::ErrorUnit", String ("EU_PKT"));
|
||||
|
||||
Config::SetDefault ("OnOffApplication::PacketSize", Uinteger (210));
|
||||
Config::SetDefault ("OnOffApplication::DataRate", MakeDataRate ("448kb/s"));
|
||||
Config::SetDefault ("OnOffApplication::DataRate", DataRate ("448kb/s"));
|
||||
|
||||
|
||||
// Allow the user to override any of the defaults and the above
|
||||
|
||||
@@ -113,7 +113,7 @@ main (int argc, char *argv[])
|
||||
DefaultValue::Bind ("Queue", "DropTailQueue");
|
||||
|
||||
Config::SetDefault ("OnOffApplication::PacketSize", Uinteger (210));
|
||||
Config::SetDefault ("OnOffApplication::DataRate", MakeDataRate ("448kb/s"));
|
||||
Config::SetDefault ("OnOffApplication::DataRate", DataRate ("448kb/s"));
|
||||
|
||||
//DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30);
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include "ns3/ptr.h"
|
||||
#include "ns3/random-variable.h"
|
||||
#include "ns3/config.h"
|
||||
#include "ns3/string.h"
|
||||
|
||||
#include "ns3/simulator.h"
|
||||
#include "ns3/nstime.h"
|
||||
@@ -101,8 +102,8 @@ main (int argc, char *argv[])
|
||||
|
||||
// Set up some default values for the simulation.
|
||||
|
||||
Config::SetDefault ("OnOffApplication::PacketSize", "210");
|
||||
Config::SetDefault ("OnOffApplication::DataRate", "448kb/s");
|
||||
Config::SetDefault ("OnOffApplication::PacketSize", String ("210"));
|
||||
Config::SetDefault ("OnOffApplication::DataRate", String ("448kb/s"));
|
||||
|
||||
//DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30);
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include "ns3/ptr.h"
|
||||
#include "ns3/random-variable.h"
|
||||
#include "ns3/config.h"
|
||||
#include "ns3/string.h"
|
||||
|
||||
#include "ns3/simulator.h"
|
||||
#include "ns3/nstime.h"
|
||||
@@ -78,8 +79,8 @@ main (int argc, char *argv[])
|
||||
|
||||
// Set up some default values for the simulation.
|
||||
|
||||
Config::SetDefault ("OnOffApplication::PacketSize", "210");
|
||||
Config::SetDefault ("OnOffApplication::DataRate", "448kb/s");
|
||||
Config::SetDefault ("OnOffApplication::PacketSize", String ("210"));
|
||||
Config::SetDefault ("OnOffApplication::DataRate", String ("448kb/s"));
|
||||
|
||||
// Allow the user to override any of the defaults and the above
|
||||
// Bind()s at run-time, via command-line arguments
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "ns3/mobility-helper.h"
|
||||
#include "ns3/uinteger.h"
|
||||
#include "ns3/double.h"
|
||||
#include "ns3/string.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
@@ -33,7 +34,7 @@ int main (int argc, char *argv[])
|
||||
"DeltaX", Double (5.0),
|
||||
"DeltaY", Double (20.0),
|
||||
"GridWidth", Uinteger (20),
|
||||
"LayoutType", "RowFirst");
|
||||
"LayoutType", String ("RowFirst"));
|
||||
// each object will be attached a static position.
|
||||
// i.e., once set by the "position allocator", the
|
||||
// position will never change.
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "ns3/node.h"
|
||||
#include "ns3/mobility-helper.h"
|
||||
#include "ns3/node-list.h"
|
||||
#include "ns3/string.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
@@ -37,9 +38,9 @@ int main (int argc, char *argv[])
|
||||
MobilityHelper mobility;
|
||||
mobility.EnableNotifier ();
|
||||
mobility.SetPositionAllocator ("RandomDiscPositionAllocator",
|
||||
"X", "100.0",
|
||||
"Y", "100.0",
|
||||
"Rho", "Uniform:0:30");
|
||||
"X", String ("100.0"),
|
||||
"Y", String ("100.0"),
|
||||
"Rho", String ("Uniform:0:30"));
|
||||
mobility.SetMobilityModel ("StaticMobilityModel");
|
||||
mobility.Layout (objects.begin (), objects.end ());
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "ns3/node.h"
|
||||
#include "ns3/node-list.h"
|
||||
#include "ns3/mobility-helper.h"
|
||||
#include "ns3/string.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
@@ -44,14 +45,14 @@ int main (int argc, char *argv[])
|
||||
MobilityHelper mobility;
|
||||
mobility.EnableNotifier ();
|
||||
mobility.SetPositionAllocator ("RandomDiscPositionAllocator",
|
||||
"X", "100.0",
|
||||
"Y", "100.0",
|
||||
"Rho", "Uniform:0:30");
|
||||
"X", String ("100.0"),
|
||||
"Y", String ("100.0"),
|
||||
"Rho", String ("Uniform:0:30"));
|
||||
mobility.SetMobilityModel ("RandomWalk2dMobilityModel",
|
||||
"Mode", "Time",
|
||||
"Time", "2s",
|
||||
"Speed", "Constant:1.0",
|
||||
"Bounds", "0:200:0:100");
|
||||
"Mode", String ("Time"),
|
||||
"Time", String ("2s"),
|
||||
"Speed", String ("Constant:1.0"),
|
||||
"Bounds", String ("0:200:0:100"));
|
||||
mobility.Layout (NodeList::Begin (), NodeList::End ());
|
||||
NodeList::Connect ("/nodes/*/$MobilityModelNotifier/course-change",
|
||||
MakeCallback (&CourseChange));
|
||||
|
||||
@@ -52,7 +52,7 @@ OnOffApplication::GetTypeId (void)
|
||||
.SetParent<Application> ()
|
||||
.AddConstructor<OnOffApplication> ()
|
||||
.AddAttribute ("DataRate", "The data rate in on state.",
|
||||
MakeDataRate ("500kb/s"),
|
||||
DataRate ("500kb/s"),
|
||||
MakeDataRateAccessor (&OnOffApplication::m_cbrRate),
|
||||
MakeDataRateChecker ())
|
||||
.AddAttribute ("PacketSize", "The size of packets sent in on state",
|
||||
|
||||
@@ -175,15 +175,13 @@ uint64_t DataRate::GetBitRate() const
|
||||
return m_bps;
|
||||
}
|
||||
|
||||
DataRate MakeDataRate (std::string rate)
|
||||
DataRate::DataRate (std::string rate)
|
||||
{
|
||||
uint64_t bps;
|
||||
bool ok = DoParse (rate, &bps);
|
||||
bool ok = DoParse (rate, &m_bps);
|
||||
if (!ok)
|
||||
{
|
||||
NS_FATAL_ERROR ("Could not parse rate.");
|
||||
NS_FATAL_ERROR ("Could not parse rate: "<<rate);
|
||||
}
|
||||
return DataRate (bps);
|
||||
}
|
||||
|
||||
std::ostream &operator << (std::ostream &os, const DataRate &rate)
|
||||
|
||||
@@ -58,6 +58,7 @@ public:
|
||||
* non-trivial bitrate availiable.
|
||||
*/
|
||||
DataRate (uint64_t bps);
|
||||
DataRate (std::string rate);
|
||||
|
||||
bool operator < (const DataRate& rhs) const;
|
||||
bool operator <= (const DataRate& rhs) const;
|
||||
@@ -87,8 +88,6 @@ private:
|
||||
static uint64_t Parse(const std::string);
|
||||
};
|
||||
|
||||
DataRate MakeDataRate (std::string rate);
|
||||
|
||||
std::ostream &operator << (std::ostream &os, const DataRate &rate);
|
||||
std::istream &operator >> (std::istream &is, DataRate &rate);
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef VALUE_HELPER_H
|
||||
#define VALUE_HELPER_H
|
||||
|
||||
#include "attribute.h"
|
||||
#include "object-base.h"
|
||||
#include "attribute-accessor-helper.h"
|
||||
#include <sstream>
|
||||
#include "fatal-error.h"
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "integer.h"
|
||||
#include "uinteger.h"
|
||||
#include "enum.h"
|
||||
#include "string.h"
|
||||
#include "random-variable.h"
|
||||
#include "double.h"
|
||||
#include "object-vector.h"
|
||||
@@ -239,12 +240,12 @@ AttributeTest::RunTests (void)
|
||||
|
||||
AttributeList params;
|
||||
Ptr<AttributeObjectTest> p;
|
||||
NS_TEST_ASSERT (params.Set ("AttributeObjectTest::TestBoolName", "false"));
|
||||
NS_TEST_ASSERT (params.Set ("AttributeObjectTest::TestBoolName", String ("false")));
|
||||
p = CreateObject<AttributeObjectTest> (params);
|
||||
CHECK_GET_STR (p, "TestBoolName", "false");
|
||||
CHECK_GET_PARAM (p, "TestBoolName", Boolean, false);
|
||||
|
||||
NS_TEST_ASSERT (p->SetAttribute("TestBoolName", "true"));
|
||||
NS_TEST_ASSERT (p->SetAttribute("TestBoolName", String ("true")));
|
||||
CHECK_GET_STR (p, "TestBoolName", "true");
|
||||
CHECK_GET_PARAM (p, "TestBoolName", Boolean, true);
|
||||
|
||||
@@ -252,7 +253,7 @@ AttributeTest::RunTests (void)
|
||||
CHECK_GET_STR (p, "TestBoolName", "false");
|
||||
CHECK_GET_PARAM (p, "TestBoolName", Boolean, false);
|
||||
|
||||
p = CreateObjectWith<AttributeObjectTest> ("TestBoolName", "true");
|
||||
p = CreateObjectWith<AttributeObjectTest> ("TestBoolName", String ("true"));
|
||||
CHECK_GET_STR (p, "TestBoolName", "true");
|
||||
CHECK_GET_PARAM (p, "TestBoolName", Boolean, true);
|
||||
|
||||
@@ -260,11 +261,11 @@ AttributeTest::RunTests (void)
|
||||
CHECK_GET_STR (p, "TestBoolName", "true");
|
||||
CHECK_GET_PARAM (p, "TestBoolName", Boolean, true);
|
||||
|
||||
NS_TEST_ASSERT (p->SetAttribute("TestBoolA", "false"));
|
||||
NS_TEST_ASSERT (p->SetAttribute("TestBoolA", String ("false")));
|
||||
CHECK_GET_STR (p, "TestBoolA", "false");
|
||||
CHECK_GET_PARAM (p, "TestBoolA", Boolean, false);
|
||||
|
||||
NS_TEST_ASSERT (p->SetAttribute("TestBoolA", "true"));
|
||||
NS_TEST_ASSERT (p->SetAttribute("TestBoolA", String ("true")));
|
||||
CHECK_GET_STR (p, "TestBoolA", "true");
|
||||
CHECK_GET_PARAM (p, "TestBoolA", Boolean, true);
|
||||
|
||||
@@ -289,7 +290,7 @@ AttributeTest::RunTests (void)
|
||||
CHECK_GET_STR (p, "TestInt16", "-2");
|
||||
CHECK_GET_PARAM (p, "TestInt16", Integer, -2);
|
||||
|
||||
NS_TEST_ASSERT (p->SetAttribute("TestInt16", "-5"));
|
||||
NS_TEST_ASSERT (p->SetAttribute("TestInt16", String ("-5")));
|
||||
CHECK_GET_STR (p, "TestInt16", "-5");
|
||||
CHECK_GET_PARAM (p, "TestInt16", Integer, -5);
|
||||
|
||||
@@ -341,13 +342,13 @@ AttributeTest::RunTests (void)
|
||||
NS_TEST_ASSERT (p->SetAttribute("TestUint8", Uinteger (255)));
|
||||
CHECK_GET_STR (p, "TestUint8", "255");
|
||||
CHECK_GET_PARAM (p, "TestUint8", Uinteger, 255);
|
||||
NS_TEST_ASSERT (p->SetAttribute("TestUint8", "255"));
|
||||
NS_TEST_ASSERT (p->SetAttribute("TestUint8", String ("255")));
|
||||
CHECK_GET_STR (p, "TestUint8", "255");
|
||||
CHECK_GET_PARAM (p, "TestUint8", Uinteger, 255);
|
||||
NS_TEST_ASSERT (!p->SetAttribute("TestUint8", "256"));
|
||||
NS_TEST_ASSERT (!p->SetAttribute("TestUint8", String ("256")));
|
||||
CHECK_GET_STR (p, "TestUint8", "255");
|
||||
CHECK_GET_PARAM (p, "TestUint8", Uinteger, 255);
|
||||
NS_TEST_ASSERT (!p->SetAttribute("TestUint8", "-1"));
|
||||
NS_TEST_ASSERT (!p->SetAttribute("TestUint8", String ("-1")));
|
||||
CHECK_GET_STR (p, "TestUint8", "255");
|
||||
CHECK_GET_PARAM (p, "TestUint8", Uinteger, 255);
|
||||
NS_TEST_ASSERT (!p->SetAttribute("TestUint8", Uinteger ((uint64_t)-1)));
|
||||
@@ -363,10 +364,10 @@ AttributeTest::RunTests (void)
|
||||
NS_TEST_ASSERT (p->SetAttribute("TestEnum", Enum (AttributeObjectTest::TEST_C)));
|
||||
CHECK_GET_STR (p, "TestEnum", "TestC");
|
||||
CHECK_GET_PARAM (p, "TestEnum", Enum, AttributeObjectTest::TEST_C);
|
||||
NS_TEST_ASSERT (p->SetAttribute("TestEnum", "TestB"));
|
||||
NS_TEST_ASSERT (p->SetAttribute("TestEnum", String ("TestB")));
|
||||
CHECK_GET_STR (p, "TestEnum", "TestB");
|
||||
CHECK_GET_PARAM (p, "TestEnum", Enum, AttributeObjectTest::TEST_B);
|
||||
NS_TEST_ASSERT (!p->SetAttribute("TestEnum", "TestD"));
|
||||
NS_TEST_ASSERT (!p->SetAttribute("TestEnum", String ("TestD")));
|
||||
CHECK_GET_STR (p, "TestEnum", "TestB");
|
||||
CHECK_GET_PARAM (p, "TestEnum", Enum, AttributeObjectTest::TEST_B);
|
||||
NS_TEST_ASSERT (!p->SetAttribute("TestEnum", Enum (5)));
|
||||
@@ -407,12 +408,12 @@ AttributeTest::RunTests (void)
|
||||
NS_TEST_ASSERT_EQUAL (vector.GetN (), 2);
|
||||
}
|
||||
|
||||
NS_TEST_ASSERT (AttributeList::GetGlobal ()->Set ("AttributeObjectTest::TestBoolName", "true"));
|
||||
NS_TEST_ASSERT (AttributeList::GetGlobal ()->Set ("AttributeObjectTest::TestBoolName", String ("true")));
|
||||
p = CreateObjectWith<AttributeObjectTest> ();
|
||||
Boolean boolV = p->GetAttribute ("TestBoolName");
|
||||
NS_TEST_ASSERT_EQUAL (boolV, Boolean (true));
|
||||
|
||||
NS_TEST_ASSERT (AttributeList::GetGlobal ()->Set ("AttributeObjectTest::TestBoolName", "false"));
|
||||
NS_TEST_ASSERT (AttributeList::GetGlobal ()->Set ("AttributeObjectTest::TestBoolName", String ("false")));
|
||||
p = CreateObjectWith<AttributeObjectTest> ();
|
||||
boolV = p->GetAttribute ("TestBoolName");
|
||||
NS_TEST_ASSERT_EQUAL (boolV, Boolean (false));
|
||||
|
||||
@@ -113,14 +113,6 @@ Attribute::DeserializeFromString (std::string value, Ptr<const AttributeChecker>
|
||||
return m_value->DeserializeFromString (value, checker);
|
||||
}
|
||||
|
||||
Attribute::Attribute (const char *value)
|
||||
: m_value (new StringValue (value))
|
||||
{}
|
||||
Attribute::Attribute (std::string value)
|
||||
: m_value (new StringValue (value))
|
||||
{}
|
||||
|
||||
|
||||
AttributeAccessor::AttributeAccessor ()
|
||||
: m_count (1)
|
||||
{}
|
||||
@@ -161,53 +153,6 @@ AttributeChecker::Unref (void) const
|
||||
AttributeChecker::~AttributeChecker ()
|
||||
{}
|
||||
|
||||
StringValue::StringValue (const char *value)
|
||||
: m_value (value)
|
||||
{}
|
||||
StringValue::StringValue (std::string value)
|
||||
: m_value (value)
|
||||
{}
|
||||
void
|
||||
StringValue::Set (std::string value)
|
||||
{
|
||||
m_value = value;
|
||||
}
|
||||
std::string
|
||||
StringValue::Get (void) const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
Attribute
|
||||
StringValue::Copy (void) const
|
||||
{
|
||||
return Attribute::Create<StringValue> (*this);
|
||||
}
|
||||
std::string
|
||||
StringValue::SerializeToString (Ptr<const AttributeChecker> checker) const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
bool
|
||||
StringValue::DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker)
|
||||
{
|
||||
m_value = value;
|
||||
return true;
|
||||
}
|
||||
StringValue::StringValue (Attribute value)
|
||||
{
|
||||
const StringValue *v = value.DynCast<const StringValue *> ();
|
||||
if (v == 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Expected value of type String.");
|
||||
}
|
||||
m_value = v->Get ();
|
||||
}
|
||||
StringValue::operator Attribute () const
|
||||
{
|
||||
return Attribute::Create<StringValue> (*this);
|
||||
}
|
||||
|
||||
|
||||
std::string
|
||||
PtrValueBase::SerializeToString (Ptr<const AttributeChecker> checker) const
|
||||
{
|
||||
|
||||
@@ -53,8 +53,6 @@ public:
|
||||
template <typename T>
|
||||
operator Ptr<T> ();
|
||||
|
||||
Attribute (const char *value);
|
||||
Attribute (std::string value);
|
||||
private:
|
||||
Attribute (AttributeValue *value);
|
||||
AttributeValue *m_value;
|
||||
@@ -119,29 +117,6 @@ Ptr<AttributeChecker> MakePtrChecker (void);
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
/********************************************************
|
||||
* A class used to hold std::string values.
|
||||
********************************************************/
|
||||
|
||||
class StringValue : public AttributeValue
|
||||
{
|
||||
public:
|
||||
StringValue (const char *value);
|
||||
StringValue (std::string value);
|
||||
void Set (std::string value);
|
||||
std::string Get (void) const;
|
||||
|
||||
virtual Attribute Copy (void) const;
|
||||
virtual std::string SerializeToString (Ptr<const AttributeChecker> checker) const;
|
||||
virtual bool DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker);
|
||||
|
||||
StringValue (Attribute value);
|
||||
operator Attribute () const;
|
||||
private:
|
||||
std::string m_value;
|
||||
};
|
||||
|
||||
|
||||
/********************************************************
|
||||
* The class used to access the pointer stored in a
|
||||
* PtrValue<T> AttributeValue instance.
|
||||
|
||||
@@ -27,12 +27,6 @@ ObjectFactory::Set (std::string name, Attribute value)
|
||||
m_parameters.SetWithTid (m_tid, name, value);
|
||||
}
|
||||
|
||||
void
|
||||
ObjectFactory::Set (std::string name, std::string value)
|
||||
{
|
||||
m_parameters.SetWithTid (m_tid, name, value);
|
||||
}
|
||||
|
||||
TypeId
|
||||
ObjectFactory::GetTypeId (void) const
|
||||
{
|
||||
|
||||
@@ -15,7 +15,6 @@ public:
|
||||
void SetTypeId (std::string tid);
|
||||
void SetTypeId (const char *tid);
|
||||
void Set (std::string name, Attribute value);
|
||||
void Set (std::string name, std::string value);
|
||||
|
||||
TypeId GetTypeId (void) const;
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "attribute.h"
|
||||
#include "trace-source-accessor.h"
|
||||
#include "log.h"
|
||||
#include "string.h"
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
@@ -860,7 +861,7 @@ AttributeList::DoSet (struct TypeId::AttributeInfo *info, Attribute value)
|
||||
}
|
||||
// attempt to convert back to value.
|
||||
Attribute v = info->initialValue.Copy ();
|
||||
ok = v.DeserializeFromString (str->Get (), info->checker);
|
||||
ok = v.DeserializeFromString (str->Get ().Get (), info->checker);
|
||||
if (!ok)
|
||||
{
|
||||
return false;
|
||||
@@ -1087,7 +1088,7 @@ Object::DoSet (Ptr<const AttributeAccessor> spec, Attribute initialValue,
|
||||
}
|
||||
// attempt to convert back from string.
|
||||
Attribute v = initialValue.Copy ();
|
||||
ok = v.DeserializeFromString (str->Get (), checker);
|
||||
ok = v.DeserializeFromString (str->Get ().Get (), checker);
|
||||
if (!ok)
|
||||
{
|
||||
return false;
|
||||
|
||||
45
src/core/string.cc
Normal file
45
src/core/string.cc
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "string.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
String::String ()
|
||||
: m_value ()
|
||||
{}
|
||||
String::String (const char *value)
|
||||
: m_value (value)
|
||||
{}
|
||||
String::String (std::string value)
|
||||
: m_value (value)
|
||||
{}
|
||||
void
|
||||
String::Set (std::string value)
|
||||
{
|
||||
m_value = value;
|
||||
}
|
||||
void
|
||||
String::Set (const char *value)
|
||||
{
|
||||
m_value = value;
|
||||
}
|
||||
std::string
|
||||
String::Get (void) const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
std::ostream & operator << (std::ostream &os, const String &value)
|
||||
{
|
||||
os << value.Get ();
|
||||
return os;
|
||||
}
|
||||
std::istream &operator >> (std::istream &is, String &value)
|
||||
{
|
||||
std::string str;
|
||||
is >> str;
|
||||
value = String (str);
|
||||
return is;
|
||||
}
|
||||
|
||||
VALUE_HELPER_CPP (String);
|
||||
|
||||
} // namespace ns3
|
||||
32
src/core/string.h
Normal file
32
src/core/string.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef NS3_STRING_H
|
||||
#define NS3_STRING_H
|
||||
|
||||
#include <string>
|
||||
#include "attribute-helper.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class String
|
||||
{
|
||||
public:
|
||||
String ();
|
||||
String (const char *value);
|
||||
String (std::string value);
|
||||
void Set (std::string value);
|
||||
void Set (const char *value);
|
||||
std::string Get (void) const;
|
||||
|
||||
VALUE_HELPER_HEADER_1 (String);
|
||||
private:
|
||||
std::string m_value;
|
||||
};
|
||||
|
||||
std::ostream & operator << (std::ostream &os, const String &value);
|
||||
std::istream &operator >> (std::istream &is, String &value);
|
||||
|
||||
VALUE_HELPER_HEADER_2 (String);
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
|
||||
#endif /* NS3_STRING_H */
|
||||
@@ -60,6 +60,7 @@ def build(bld):
|
||||
'uinteger.cc',
|
||||
'enum.cc',
|
||||
'double.cc',
|
||||
'string.cc',
|
||||
'object-factory.cc',
|
||||
'object-vector.cc',
|
||||
'global-value.cc',
|
||||
@@ -117,6 +118,7 @@ def build(bld):
|
||||
'uinteger.h',
|
||||
'double.h',
|
||||
'enum.h',
|
||||
'string.h',
|
||||
'object-factory.h',
|
||||
'attribute-helper.h',
|
||||
'global-value.h',
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "ns3/ipv4-address.h"
|
||||
#include "ns3/ipv4.h"
|
||||
#include "ns3/queue.h"
|
||||
#include "ns3/string.h"
|
||||
|
||||
#include "csma-channel.h"
|
||||
#include "csma-net-device.h"
|
||||
@@ -44,7 +45,7 @@ CsmaIpv4Topology::AddIpv4CsmaNetDevice(
|
||||
// assume full-duplex
|
||||
Ptr<CsmaNetDevice> nd = CreateObjectWith<CsmaNetDevice> ("Node", node,
|
||||
"Address", addr,
|
||||
"EncapsulationMode", "IpArp");
|
||||
"EncapsulationMode", String ("IpArp"));
|
||||
node->AddDevice (nd);
|
||||
|
||||
nd->AddQueue(q);
|
||||
@@ -62,7 +63,7 @@ CsmaIpv4Topology::AddIpv4LlcCsmaNode(Ptr<Node> n1,
|
||||
|
||||
Ptr<CsmaNetDevice> nd0 = CreateObjectWith<CsmaNetDevice> ("Node", n1,
|
||||
"Address", addr,
|
||||
"EncapsulationMode", "Llc");
|
||||
"EncapsulationMode", String ("Llc"));
|
||||
n1->AddDevice (nd0);
|
||||
nd0->SetSendEnable (true);
|
||||
nd0->SetReceiveEnable (false);
|
||||
@@ -71,7 +72,7 @@ CsmaIpv4Topology::AddIpv4LlcCsmaNode(Ptr<Node> n1,
|
||||
|
||||
Ptr<CsmaNetDevice> nd1 = CreateObjectWith<CsmaNetDevice> ("Node", n1,
|
||||
"Address", addr,
|
||||
"EncapsulationMode", "Llc");
|
||||
"EncapsulationMode", String ("Llc"));
|
||||
n1->AddDevice (nd1);
|
||||
nd1->SetSendEnable (false);
|
||||
nd1->SetReceiveEnable (true);
|
||||
@@ -88,7 +89,7 @@ CsmaIpv4Topology::AddIpv4RawCsmaNode(Ptr<Node> n1,
|
||||
|
||||
Ptr<CsmaNetDevice> nd0 = CreateObjectWith<CsmaNetDevice> ("Node", n1,
|
||||
"Address", addr,
|
||||
"EncapsulationMode", "Raw");
|
||||
"EncapsulationMode", String ("Raw"));
|
||||
n1->AddDevice (nd0);
|
||||
nd0->SetSendEnable (true);
|
||||
nd0->SetReceiveEnable (false);
|
||||
@@ -97,7 +98,7 @@ CsmaIpv4Topology::AddIpv4RawCsmaNode(Ptr<Node> n1,
|
||||
|
||||
Ptr<CsmaNetDevice> nd1 = CreateObjectWith<CsmaNetDevice> ("Node", n1,
|
||||
"Address", addr,
|
||||
"EncapsulationMode", "Raw");
|
||||
"EncapsulationMode", String ("Raw"));
|
||||
n1->AddDevice (nd1);
|
||||
nd1->SetSendEnable (false);
|
||||
nd1->SetReceiveEnable (true);
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/queue.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include "ns3/composite-trace-resolver.h"
|
||||
#include "ns3/mac48-address.h"
|
||||
#include "ns3/llc-snap-header.h"
|
||||
#include "ns3/error-model.h"
|
||||
#include "ns3/trace-source-accessor.h"
|
||||
#include "point-to-point-net-device.h"
|
||||
#include "point-to-point-channel.h"
|
||||
|
||||
@@ -34,77 +34,59 @@ NS_LOG_COMPONENT_DEFINE ("PointToPointNetDevice");
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
DataRateDefaultValue PointToPointNetDevice::g_defaultRate(
|
||||
"PointToPointLinkDataRate",
|
||||
"The default data rate for point to point links",
|
||||
MakeDataRate ("10Mb/s"));
|
||||
NS_OBJECT_ENSURE_REGISTERED (PointToPointNetDevice);
|
||||
|
||||
PointToPointTraceType::PointToPointTraceType (enum Type type)
|
||||
: m_type (type)
|
||||
TypeId
|
||||
PointToPointNetDevice::GetTypeId (void)
|
||||
{
|
||||
NS_LOG_FUNCTION;
|
||||
}
|
||||
PointToPointTraceType::PointToPointTraceType ()
|
||||
: m_type (RX)
|
||||
{
|
||||
NS_LOG_FUNCTION;
|
||||
static TypeId tid = TypeId ("PointToPointNetDevice")
|
||||
.SetParent<NetDevice> ()
|
||||
.AddConstructor<PointToPointNetDevice> ()
|
||||
.AddAttribute ("Node", "The node with which this device is associated",
|
||||
TypeId::ATTR_GET | TypeId::ATTR_CONSTRUCT,
|
||||
Ptr<Node> (0),
|
||||
MakePtrAccessor (&PointToPointNetDevice::m_node),
|
||||
MakePtrChecker<Node> ())
|
||||
.AddAttribute ("Address", "The address of this device.",
|
||||
Mac48Address ("ff:ff:ff:ff:ff:ff"),
|
||||
MakeMac48AddressAccessor (&PointToPointNetDevice::m_address),
|
||||
MakeMac48AddressChecker ())
|
||||
.AddAttribute ("DataRate", "The default data rate for point to point links",
|
||||
DataRate ("10Mb/s"),
|
||||
MakeDataRateAccessor (&PointToPointNetDevice::m_bps),
|
||||
MakeDataRateChecker ())
|
||||
.AddAttribute ("RxErrorModel", "XXX",
|
||||
Ptr<ErrorModel> (0),
|
||||
MakePtrAccessor (&PointToPointNetDevice::m_receiveErrorModel),
|
||||
MakePtrChecker<ErrorModel> ())
|
||||
.AddAttribute ("TxQueue", "XXX",
|
||||
Ptr<Queue> (0),
|
||||
MakePtrAccessor (&PointToPointNetDevice::m_queue),
|
||||
MakePtrChecker<Queue> ())
|
||||
.AddAttribute ("InterframeGap", "XXX",
|
||||
Seconds (0.0),
|
||||
MakeTimeAccessor (&PointToPointNetDevice::m_tInterframeGap),
|
||||
MakeTimeChecker ())
|
||||
.AddTraceSource ("Rx", "Receive MAC packet.",
|
||||
MakeTraceSourceAccessor (&PointToPointNetDevice::m_rxTrace))
|
||||
.AddTraceSource ("Drop", "Drop MAC packet.",
|
||||
MakeTraceSourceAccessor (&PointToPointNetDevice::m_dropTrace))
|
||||
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
|
||||
void
|
||||
PointToPointTraceType::Print (std::ostream &os) const
|
||||
{
|
||||
switch (m_type) {
|
||||
case RX:
|
||||
os << "dev-rx";
|
||||
break;
|
||||
case DROP:
|
||||
os << "dev-drop";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t
|
||||
PointToPointTraceType::GetUid (void)
|
||||
{
|
||||
NS_LOG_FUNCTION;
|
||||
static uint16_t uid = AllocateUid<PointToPointTraceType> ("PointToPointTraceType");
|
||||
return uid;
|
||||
}
|
||||
|
||||
std::string
|
||||
PointToPointTraceType::GetTypeName (void) const
|
||||
{
|
||||
NS_LOG_FUNCTION;
|
||||
return "ns3::PointToPointTraceType";
|
||||
}
|
||||
|
||||
enum PointToPointTraceType::Type
|
||||
PointToPointTraceType::Get (void) const
|
||||
{
|
||||
NS_LOG_FUNCTION;
|
||||
return m_type;
|
||||
}
|
||||
|
||||
PointToPointNetDevice::PointToPointNetDevice (Ptr<Node> node,
|
||||
Mac48Address address,
|
||||
const DataRate& rate)
|
||||
PointToPointNetDevice::PointToPointNetDevice ()
|
||||
:
|
||||
m_txMachineState (READY),
|
||||
m_bps (rate),
|
||||
m_tInterframeGap (Seconds(0)),
|
||||
m_channel (0),
|
||||
m_queue (0),
|
||||
m_rxTrace (),
|
||||
m_dropTrace (),
|
||||
m_receiveErrorModel (0),
|
||||
m_node (node),
|
||||
m_address (address),
|
||||
m_name (""),
|
||||
m_linkUp (false),
|
||||
m_mtu (0xffff)
|
||||
{
|
||||
NS_LOG_FUNCTION;
|
||||
NS_LOG_PARAMS (this << node);
|
||||
NS_LOG_PARAMS (this);
|
||||
}
|
||||
|
||||
PointToPointNetDevice::~PointToPointNetDevice ()
|
||||
@@ -199,26 +181,6 @@ void PointToPointNetDevice::TransmitComplete (void)
|
||||
TransmitStart(p);
|
||||
}
|
||||
|
||||
Ptr<TraceResolver>
|
||||
PointToPointNetDevice::GetTraceResolver (void) const
|
||||
{
|
||||
NS_LOG_FUNCTION;
|
||||
Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
|
||||
resolver->AddComposite ("queue", m_queue);
|
||||
resolver->AddSource ("rx",
|
||||
TraceDoc ("receive MAC packet",
|
||||
"Ptr<const Packet>", "packet received"),
|
||||
m_rxTrace,
|
||||
PointToPointTraceType (PointToPointTraceType::RX));
|
||||
resolver->AddSource ("drop",
|
||||
TraceDoc ("drop MAC packet",
|
||||
"Ptr<const Packet>", "packet dropped"),
|
||||
m_dropTrace,
|
||||
PointToPointTraceType (PointToPointTraceType::DROP));
|
||||
resolver->SetParentResolver (NetDevice::GetTraceResolver ());
|
||||
return resolver;
|
||||
}
|
||||
|
||||
bool
|
||||
PointToPointNetDevice::Attach (Ptr<PointToPointChannel> ch)
|
||||
{
|
||||
|
||||
@@ -27,10 +27,9 @@
|
||||
#include "ns3/net-device.h"
|
||||
#include "ns3/callback.h"
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/callback-trace-source.h"
|
||||
#include "ns3/traced-callback.h"
|
||||
#include "ns3/nstime.h"
|
||||
#include "ns3/data-rate.h"
|
||||
#include "ns3/default-value.h"
|
||||
#include "ns3/ptr.h"
|
||||
#include "ns3/mac48-address.h"
|
||||
|
||||
@@ -40,29 +39,6 @@ class Queue;
|
||||
class PointToPointChannel;
|
||||
class ErrorModel;
|
||||
|
||||
/**
|
||||
* \brief hold in a TraceContext the type of trace source from a PointToPointNetDevice
|
||||
*/
|
||||
class PointToPointTraceType : public TraceContextElement
|
||||
{
|
||||
public:
|
||||
enum Type {
|
||||
RX,
|
||||
DROP
|
||||
};
|
||||
PointToPointTraceType (enum Type type);
|
||||
PointToPointTraceType ();
|
||||
void Print (std::ostream &os) const;
|
||||
static uint16_t GetUid (void);
|
||||
std::string GetTypeName (void) const;
|
||||
/**
|
||||
* \returns the type of the trace source which generated an event.
|
||||
*/
|
||||
enum Type Get (void) const;
|
||||
private:
|
||||
enum Type m_type;
|
||||
};
|
||||
|
||||
/**
|
||||
* \class PointToPointNetDevice
|
||||
* \brief A Device for a Point to Point Network Link.
|
||||
@@ -78,6 +54,8 @@ private:
|
||||
class PointToPointNetDevice : public NetDevice
|
||||
{
|
||||
public:
|
||||
static TypeId GetTypeId (void);
|
||||
|
||||
/**
|
||||
* Construct a PointToPointNetDevice
|
||||
*
|
||||
@@ -86,12 +64,8 @@ public:
|
||||
* as well as an optional DataRate object.
|
||||
*
|
||||
* @see PointToPointTopology::AddPointToPointLink ()
|
||||
* @param node the Node to which this device is connected.
|
||||
* @param rate (optional) DataRate object
|
||||
*/
|
||||
PointToPointNetDevice (Ptr<Node> node,
|
||||
Mac48Address address,
|
||||
const DataRate& rate = g_defaultRate.GetValue());
|
||||
PointToPointNetDevice ();
|
||||
/**
|
||||
* Destroy a PointToPointNetDevice
|
||||
*
|
||||
@@ -194,12 +168,6 @@ public:
|
||||
virtual void SetReceiveCallback (NetDevice::ReceiveCallback cb);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Create a Trace Resolver for events in the net device.
|
||||
*
|
||||
* @see class TraceResolver
|
||||
*/
|
||||
virtual Ptr<TraceResolver> GetTraceResolver (void) const;
|
||||
|
||||
virtual void DoDispose (void);
|
||||
/**
|
||||
@@ -213,18 +181,6 @@ private:
|
||||
*/
|
||||
Ptr<Queue> GetQueue(void) const;
|
||||
|
||||
|
||||
/**
|
||||
* Set a new default data rate
|
||||
*/
|
||||
static void SetDefaultRate(const DataRate&);
|
||||
|
||||
/**
|
||||
* Get the current default rate.
|
||||
* @returns a const reference to current default
|
||||
*/
|
||||
static const DataRate& GetDefaultRate();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Adds the necessary headers and trailers to a packet of data in order to
|
||||
@@ -310,7 +266,7 @@ private:
|
||||
* @see class CallBackTraceSource
|
||||
* @see class TraceResolver
|
||||
*/
|
||||
CallbackTraceSource<Ptr<const Packet> > m_rxTrace;
|
||||
TracedCallback<Ptr<const Packet> > m_rxTrace;
|
||||
/**
|
||||
* The trace source for the packet drop events that the device can
|
||||
* fire.
|
||||
@@ -318,11 +274,7 @@ private:
|
||||
* @see class CallBackTraceSource
|
||||
* @see class TraceResolver
|
||||
*/
|
||||
CallbackTraceSource<Ptr<const Packet> > m_dropTrace;
|
||||
/**
|
||||
* Default data rate. Used for all newly created p2p net devices
|
||||
*/
|
||||
static DataRateDefaultValue g_defaultRate;
|
||||
TracedCallback<Ptr<const Packet> > m_dropTrace;
|
||||
|
||||
/**
|
||||
* Error model for receive packet events
|
||||
@@ -339,7 +291,7 @@ private:
|
||||
uint16_t m_mtu;
|
||||
};
|
||||
|
||||
}; // namespace ns3
|
||||
} // namespace ns3
|
||||
|
||||
#endif // POINT_TO_POINT_NET_DEVICE_H
|
||||
|
||||
|
||||
@@ -47,14 +47,16 @@ PointToPointTopology::AddPointToPointLink(
|
||||
{
|
||||
Ptr<PointToPointChannel> channel = CreateObject<PointToPointChannel> (bps, delay);
|
||||
|
||||
Ptr<PointToPointNetDevice> net1 = CreateObject<PointToPointNetDevice> (n1, Mac48Address::Allocate ());
|
||||
Ptr<PointToPointNetDevice> net1 = CreateObjectWith<PointToPointNetDevice> ("Node", n1,
|
||||
"Address", Mac48Address::Allocate ());
|
||||
n1->AddDevice (net1);
|
||||
|
||||
Ptr<Queue> q = Queue::CreateDefault ();
|
||||
net1->AddQueue(q);
|
||||
net1->Attach (channel);
|
||||
|
||||
Ptr<PointToPointNetDevice> net2 = CreateObject<PointToPointNetDevice> (n2, Mac48Address::Allocate ());
|
||||
Ptr<PointToPointNetDevice> net2 = CreateObjectWith<PointToPointNetDevice> ("Node", n2,
|
||||
"Address", Mac48Address::Allocate ());
|
||||
n2->AddDevice (net2);
|
||||
|
||||
q = Queue::CreateDefault ();
|
||||
|
||||
@@ -305,14 +305,14 @@ std::istream & operator >> (std::istream &is, Ipv4Address &address)
|
||||
{
|
||||
std::string str;
|
||||
is >> str;
|
||||
address = Ipv4Address (str);
|
||||
address = Ipv4Address (str.c_str ());
|
||||
return is;
|
||||
}
|
||||
std::istream & operator >> (std::istream &is, Ipv4Mask &mask)
|
||||
{
|
||||
std::string str;
|
||||
is >> str;
|
||||
mask = Ipv4Mask (str);
|
||||
mask = Ipv4Mask (str.c_str ());
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,9 @@ PointToPointIpv4Topology::AddNetDevice (
|
||||
{
|
||||
NS_ASSERT (channel->GetNDevices () <= 1);
|
||||
|
||||
Ptr<PointToPointNetDevice> nd = CreateObject<PointToPointNetDevice> (node, Mac48Address::Allocate ());
|
||||
Ptr<PointToPointNetDevice> nd =
|
||||
CreateObjectWith<PointToPointNetDevice> ("Node", node,
|
||||
"Address", Mac48Address::Allocate ());
|
||||
node->AddDevice (nd);
|
||||
Ptr<Queue> q = Queue::CreateDefault ();
|
||||
nd->AddQueue(q);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "ns3/queue.h"
|
||||
#include "ns3/mobility-model-notifier.h"
|
||||
#include "ns3/default-value.h"
|
||||
#include "ns3/string.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
@@ -119,12 +120,13 @@ int main (int argc, char *argv[])
|
||||
Ptr<Node> node = CreateObject<InternetNode> ();
|
||||
node->AggregateObject (CreateObject<MobilityModelNotifier> ());
|
||||
|
||||
Ptr<PointToPointNetDevice> p2p = CreateObject<PointToPointNetDevice> (node, Mac48Address::Allocate ());
|
||||
Ptr<PointToPointNetDevice> p2p = CreateObjectWith<PointToPointNetDevice> ("Node", node,
|
||||
"Address", Mac48Address::Allocate ());
|
||||
node->AddDevice (p2p);
|
||||
p2p->AddQueue (Queue::CreateDefault ());
|
||||
Ptr<CsmaNetDevice> csma = CreateObjectWith<CsmaNetDevice> ("Node", node,
|
||||
"Address", Mac48Address::Allocate (),
|
||||
"EncapsulationMode", "Llc");
|
||||
"EncapsulationMode", String ("Llc"));
|
||||
node->AddDevice (csma);
|
||||
csma->AddQueue (Queue::CreateDefault ());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user