Browse Source

fix coding style

ndnSIM-v1
Mathieu Lacage 19 years ago
parent
commit
7f8eb2c50b
  1. 16
      samples/main-callback.cc
  2. 46
      samples/main-packet.cc
  3. 26
      samples/main-simulator.cc
  4. 8
      samples/main-test.cc
  5. 34
      samples/main-trace.cc
  6. 310
      src/common/buffer.cc
  7. 194
      src/common/buffer.h
  8. 14
      src/common/callback-tracer.h
  9. 20
      src/common/data-writer.cc
  10. 2
      src/common/f-variable-tracer.h
  11. 20
      src/common/header.cc
  12. 26
      src/common/header.h
  13. 94
      src/common/packet.cc
  14. 70
      src/common/packet.h
  15. 46
      src/common/pcap-writer.cc
  16. 12
      src/common/pcap-writer.h
  17. 60
      src/common/si-variable-tracer.h
  18. 4
      src/common/stream-tracer-test.cc
  19. 2
      src/common/stream-tracer.h
  20. 60
      src/common/tags.cc
  21. 72
      src/common/tags.h
  22. 26
      src/common/trace-container.cc
  23. 50
      src/common/trace-container.h
  24. 20
      src/common/trailer.cc
  25. 26
      src/common/trailer.h
  26. 60
      src/common/ui-variable-tracer.h
  27. 20
      src/common/variable-tracer-test.cc
  28. 74
      src/core/callback-test.cc
  29. 102
      src/core/callback.h
  30. 22
      src/core/reference-list-test.cc
  31. 20
      src/core/reference-list.h
  32. 4
      src/core/system-file.h
  33. 4
      src/core/system-wall-clock-ms.h
  34. 26
      src/core/test.cc
  35. 16
      src/core/test.h
  36. 16
      src/core/unix-system-file.cc
  37. 16
      src/core/unix-system-wall-clock-ms.cc
  38. 12
      src/core/win32-system-file.cc
  39. 12
      src/core/win32-system-wall-clock-ms.cc
  40. 14
      src/simulator/event-id.cc
  41. 10
      src/simulator/event-id.h
  42. 10
      src/simulator/event-impl.cc
  43. 10
      src/simulator/event-impl.h
  44. 24
      src/simulator/nstime.h
  45. 4
      src/simulator/scheduler-factory.cc
  46. 4
      src/simulator/scheduler-factory.h
  47. 126
      src/simulator/scheduler-heap.cc
  48. 44
      src/simulator/scheduler-heap.h
  49. 40
      src/simulator/scheduler-list.cc
  50. 18
      src/simulator/scheduler-list.h
  51. 32
      src/simulator/scheduler-map.cc
  52. 18
      src/simulator/scheduler-map.h
  53. 36
      src/simulator/scheduler.cc
  54. 28
      src/simulator/scheduler.h
  55. 234
      src/simulator/simulator.cc
  56. 126
      src/simulator/simulator.h
  57. 32
      src/simulator/time.cc
  58. 46
      utils/bench-simulator.cc
  59. 30
      utils/replay-simulation.cc
  60. 4
      utils/run-tests.cc

16
samples/main-callback.cc

@ -6,7 +6,7 @@
using namespace ns3;
static double
cbOne (double a, double b)
CbOne (double a, double b)
{
std::cout << "invoke cbOne a=" << a << ", b=" << b << std::endl;
return a;
@ -14,7 +14,7 @@ cbOne (double a, double b)
class MyCb {
public:
int cbTwo (double a) {
int CbTwo (double a) {
std::cout << "invoke cbTwo a=" << a << std::endl;
return -5;
}
@ -28,9 +28,9 @@ int main (int argc, char *argv[])
// second arg type: double
Callback<double, double, double> one;
// build callback instance which points to cbOne function
one = makeCallback (&cbOne);
one = MakeCallback (&CbOne);
// this is not a null callback
assert (!one.isNull ());
assert (!one.IsNull ());
// invoke cbOne function through callback instance
double retOne;
retOne = one (10.0, 20.0);
@ -40,19 +40,19 @@ int main (int argc, char *argv[])
Callback<int, double> two;
MyCb cb;
// build callback instance which points to MyCb::cbTwo
two = makeCallback (&MyCb::cbTwo, &cb);
two = MakeCallback (&MyCb::CbTwo, &cb);
// this is not a null callback
assert (!two.isNull ());
assert (!two.IsNull ());
// invoke MyCb::cbTwo through callback instance
int retTwo;
retTwo = two (10.0);
two = makeNullCallback<int, double> ();
two = MakeNullCallback<int, double> ();
// invoking a null callback is just like
// invoking a null function pointer:
// it will crash.
//int retTwoNull = two (20.0);
assert (two.isNull ());
assert (two.IsNull ());
return 0;
}

46
samples/main-packet.cc

@ -12,13 +12,13 @@ public:
MyHeader ();
virtual ~MyHeader ();
void setData (uint16_t data);
uint16_t getData (void) const;
void SetData (uint16_t data);
uint16_t GetData (void) const;
private:
virtual void printTo (std::ostream &os) const;
virtual void serializeTo (Buffer::Iterator start) const;
virtual void deserializeFrom (Buffer::Iterator start);
virtual uint32_t getSerializedSize (void) const;
virtual void PrintTo (std::ostream &os) const;
virtual void SerializeTo (Buffer::Iterator start) const;
virtual void DeserializeFrom (Buffer::Iterator start);
virtual uint32_t GetSerializedSize (void) const;
uint16_t m_data;
};
@ -28,35 +28,35 @@ MyHeader::MyHeader ()
MyHeader::~MyHeader ()
{}
void
MyHeader::printTo (std::ostream &os) const
MyHeader::PrintTo (std::ostream &os) const
{
os << "MyHeader data=" << m_data << std::endl;
}
uint32_t
MyHeader::getSerializedSize (void) const
MyHeader::GetSerializedSize (void) const
{
return 2;
}
void
MyHeader::serializeTo (Buffer::Iterator start) const
MyHeader::SerializeTo (Buffer::Iterator start) const
{
// serialize in head of buffer
start.writeHtonU16 (m_data);
start.WriteHtonU16 (m_data);
}
void
MyHeader::deserializeFrom (Buffer::Iterator start)
MyHeader::DeserializeFrom (Buffer::Iterator start)
{
// deserialize from head of buffer
m_data = start.readNtohU16 ();
m_data = start.ReadNtohU16 ();
}
void
MyHeader::setData (uint16_t data)
MyHeader::SetData (uint16_t data)
{
m_data = data;
}
uint16_t
MyHeader::getData (void) const
MyHeader::GetData (void) const
{
return m_data;
}
@ -71,14 +71,14 @@ static TagRegistration<struct MyTag> g_MyTagRegistration ("ns3::MyTag", 0);
static void
receive (Packet p)
Receive (Packet p)
{
MyHeader my;
p.peek (my);
p.remove (my);
std::cout << "received data=" << my.getData () << std::endl;
p.Peek (my);
p.Remove (my);
std::cout << "received data=" << my.GetData () << std::endl;
struct MyTag myTag;
p.peekTag (myTag);
p.PeekTag (myTag);
}
@ -86,12 +86,12 @@ int main (int argc, char *argv[])
{
Packet p;
MyHeader my;
my.setData (2);
my.SetData (2);
std::cout << "send data=2" << std::endl;
p.add (my);
p.Add (my);
struct MyTag myTag;
myTag.m_streamId = 5;
p.addTag (myTag);
receive (p);
p.AddTag (myTag);
Receive (p);
return 0;
}

26
samples/main-simulator.cc

@ -7,22 +7,22 @@ using namespace ns3;
class MyModel {
public:
void start (void);
void Start (void);
private:
void dealWithEvent (double eventValue);
void DealWithEvent (double eventValue);
};
void
MyModel::start (void)
MyModel::Start (void)
{
Simulator::schedule (Time::relS (10.0),
&MyModel::dealWithEvent,
this, Simulator::now ().s ());
Simulator::Schedule (Time::RelS (10.0),
&MyModel::DealWithEvent,
this, Simulator::Now ().S ());
}
void
MyModel::dealWithEvent (double value)
MyModel::DealWithEvent (double value)
{
std::cout << "Member method received event at " << Simulator::now ().s () <<
std::cout << "Member method received event at " << Simulator::Now ().S () <<
"s started at " << value << "s" << std::endl;
}
@ -30,8 +30,8 @@ static void
random_function (MyModel *model)
{
std::cout << "random function received event at " <<
Simulator::now ().s () << "s" << std::endl;
model->start ();
Simulator::Now ().S () << "s" << std::endl;
model->Start ();
}
@ -39,9 +39,9 @@ int main (int argc, char *argv[])
{
MyModel model;
Simulator::schedule (Time::absS (10.0), &random_function, &model);
Simulator::Schedule (Time::AbsS (10.0), &random_function, &model);
Simulator::run ();
Simulator::Run ();
Simulator::destroy ();
Simulator::Destroy ();
}

8
samples/main-test.cc

@ -11,7 +11,7 @@ class MyTest : public Test {
public:
MyTest (bool ok);
virtual ~MyTest ();
virtual bool runTests (void);
virtual bool RunTests (void);
private:
bool m_ok;
};
@ -24,7 +24,7 @@ MyTest::MyTest (bool ok)
MyTest::~MyTest ()
{}
bool
MyTest::runTests (void)
MyTest::RunTests (void)
{
return m_ok;
}
@ -37,7 +37,7 @@ static MyTest g_my_test = MyTest (true);
int main (int argc, char *argv[])
{
// run tests
TestManager::enableVerbose ();
TestManager::runTests ();
TestManager::EnableVerbose ();
TestManager::RunTests ();
return 0;
}

34
samples/main-trace.cc

@ -15,15 +15,15 @@ StreamTracer c;
CallbackTracer<double, int> d;
void
registerAllTraceSources (TraceContainer *container)
RegisterAllTraceSources (TraceContainer *container)
{
container->registerCallback ("source-a", &a);
container->registerUiVariable ("source-b", &b);
container->registerStream ("source-c", &c);
container->registerCallback ("source-d", &d);
container->RegisterCallback ("source-a", &a);
container->RegisterUiVariable ("source-b", &b);
container->RegisterStream ("source-c", &c);
container->RegisterCallback ("source-d", &d);
}
void
generateTraceEvents (void)
GenerateTraceEvents (void)
{
// log en empty packet
a (Packet ());
@ -36,26 +36,26 @@ generateTraceEvents (void)
}
void
variableEvent (uint64_t old, uint64_t cur)
VariableEvent (uint64_t old, uint64_t cur)
{}
void
callbackEvent (double a, int b)
CallbackEvent (double a, int b)
{}
int main (int argc, char *argv[])
{
TraceContainer traces;
registerAllTraceSources (&traces);
RegisterAllTraceSources (&traces);
PcapWriter pcap;
pcap.open ("trace-test.log");
pcap.writeHeaderEthernet ();
traces.setCallback ("source-a",
makeCallback (&PcapWriter::writePacket, &pcap));
traces.setUiVariableCallback ("source-b", makeCallback (&variableEvent));
traces.setStream ("source-c", &std::cout);
traces.setCallback ("source-d", makeCallback (&callbackEvent));
generateTraceEvents ();
pcap.Open ("trace-test.log");
pcap.WriteHeaderEthernet ();
traces.SetCallback ("source-a",
MakeCallback (&PcapWriter::WritePacket, &pcap));
traces.SetUiVariableCallback ("source-b", MakeCallback (&VariableEvent));
traces.SetStream ("source-c", &std::cout);
traces.SetCallback ("source-d", MakeCallback (&CallbackEvent));
GenerateTraceEvents ();
return 0;
}

310
src/common/buffer.cc

@ -32,7 +32,7 @@ uint32_t Buffer::m_maxTotalAddStart = 0;
uint32_t Buffer::m_maxTotalAddEnd = 0;
struct Buffer::BufferData *
Buffer::allocate (uint32_t reqSize, uint32_t reqStart)
Buffer::Allocate (uint32_t reqSize, uint32_t reqStart)
{
if (reqSize == 0) {
reqSize = 1;
@ -50,31 +50,31 @@ Buffer::allocate (uint32_t reqSize, uint32_t reqStart)
}
void
Buffer::deallocate (struct Buffer::BufferData *data)
Buffer::Deallocate (struct Buffer::BufferData *data)
{
uint8_t *buf = reinterpret_cast<uint8_t *> (data);
delete [] buf;
}
#ifdef USE_FREE_LIST
void
Buffer::recycle (struct Buffer::BufferData *data)
Buffer::Recycle (struct Buffer::BufferData *data)
{
assert (data->m_count == 0);
/* get rid of it if it is too small for later reuse. */
if (data->m_size < (Buffer::m_maxTotalAddStart + Buffer::m_maxTotalAddEnd)) {
Buffer::deallocate (data);
Buffer::Deallocate (data);
return;
}
/* feed into free list */
if (Buffer::m_freeList.size () > 1000) {
Buffer::deallocate (data);
Buffer::Deallocate (data);
} else {
Buffer::m_freeList.push_back (data);
}
}
Buffer::BufferData *
Buffer::create (void)
Buffer::Create (void)
{
/* try to find a buffer correctly sized. */
while (!Buffer::m_freeList.empty ()) {
@ -87,25 +87,25 @@ Buffer::create (void)
data->m_count = 1;
return data;
}
Buffer::deallocate (data);
Buffer::Deallocate (data);
}
struct Buffer::BufferData *data = Buffer::allocate (m_maxTotalAddStart+m_maxTotalAddEnd,
struct Buffer::BufferData *data = Buffer::Allocate (m_maxTotalAddStart+m_maxTotalAddEnd,
m_maxTotalAddStart);
assert (data->m_count == 1);
return data;
}
#else
void
Buffer::recycle (struct Buffer::BufferData *data)
Buffer::Recycle (struct Buffer::BufferData *data)
{
Buffer::deallocate (data);
Buffer::Deallocate (data);
}
Buffer::BufferData *
Buffer::create (void)
Buffer::Create (void)
{
return Buffer::allocate (m_maxTotalAddStart+m_maxTotalAddEnd,
m_maxTotalAddStart);
return Buffer::Allocate (m_maxTotalAddStart+m_maxTotalAddEnd,
m_maxTotalAddStart);
}
#endif
@ -118,7 +118,7 @@ namespace ns3 {
void
Buffer::addAtStart (uint32_t start)
Buffer::AddAtStart (uint32_t start)
{
assert (m_start <= m_data->m_initialStart);
bool isDirty = m_data->m_count > 1 && m_start > m_data->m_dirtyStart;
@ -128,20 +128,20 @@ Buffer::addAtStart (uint32_t start)
m_size += start;
} else if (m_size + start <= m_data->m_size && !isDirty) {
/* enough space but need to move data around to fit new data */
memmove (m_data->m_data + start, getStart (), m_size);
memmove (m_data->m_data + start, GetStart (), m_size);
assert (start > m_start);
m_data->m_initialStart += start;
m_start = 0;
m_size += start;
m_start = 0;
m_size += start;
} else if (m_start < start) {
/* not enough space in buffer */
uint32_t newSize = m_size + start;
struct Buffer::BufferData *newData = Buffer::allocate (newSize, 0);
memcpy (newData->m_data + start, getStart (), m_size);
struct Buffer::BufferData *newData = Buffer::Allocate (newSize, 0);
memcpy (newData->m_data + start, GetStart (), m_size);
newData->m_initialStart = m_data->m_initialStart + start;
m_data->m_count--;
if (m_data->m_count == 0) {
Buffer::deallocate (m_data);
Buffer::Deallocate (m_data);
}
m_data = newData;
m_start = 0;
@ -149,12 +149,12 @@ Buffer::addAtStart (uint32_t start)
} else {
/* enough space in the buffer but it is dirty ! */
assert (isDirty);
struct Buffer::BufferData *newData = Buffer::create ();
memcpy (newData->m_data + m_start, getStart (), m_size);
struct Buffer::BufferData *newData = Buffer::Create ();
memcpy (newData->m_data + m_start, GetStart (), m_size);
newData->m_initialStart = m_data->m_initialStart;
m_data->m_count--;
if (m_data->m_count == 0) {
recycle (m_data);
Recycle (m_data);
}
m_data = newData;
m_start -= start;
@ -178,7 +178,7 @@ Buffer::addAtStart (uint32_t start)
", dirty start="<<m_data->m_dirtyStart<<", dirty size="<<m_data->m_dirtySize);
}
void
Buffer::addAtEnd (uint32_t end)
Buffer::AddAtEnd (uint32_t end)
{
assert (m_start <= m_data->m_initialStart);
bool isDirty = m_data->m_count > 1 &&
@ -188,21 +188,21 @@ Buffer::addAtEnd (uint32_t end)
m_size += end;
} else if (m_size + end <= m_data->m_size && !isDirty) {
/* enough space but need to move data around to fit the extra data */
uint32_t newStart = m_data->m_size - (m_size + end);
memmove (m_data->m_data + newStart, getStart (), m_size);
uint32_t newStart = m_data->m_size - (m_size + end);
memmove (m_data->m_data + newStart, GetStart (), m_size);
assert (newStart < m_start);
m_data->m_initialStart -= m_start - newStart;
m_start = newStart;
m_size += end;
m_start = newStart;
m_size += end;
} else if (m_start + m_size + end > m_data->m_size) {
/* not enough space in buffer */
uint32_t newSize = m_size + end;
struct Buffer::BufferData *newData = Buffer::allocate (newSize, 0);
memcpy (newData->m_data, getStart (), m_size);
struct Buffer::BufferData *newData = Buffer::Allocate (newSize, 0);
memcpy (newData->m_data, GetStart (), m_size);
newData->m_initialStart = m_data->m_initialStart;
m_data->m_count--;
if (m_data->m_count == 0) {
Buffer::deallocate (m_data);
Buffer::Deallocate (m_data);
}
m_data = newData;
m_size = newSize;
@ -210,12 +210,12 @@ Buffer::addAtEnd (uint32_t end)
} else {
/* enough space in the buffer but it is dirty ! */
assert (isDirty);
struct Buffer::BufferData *newData = Buffer::create ();
memcpy (newData->m_data + m_start, getStart (), m_size);
struct Buffer::BufferData *newData = Buffer::Create ();
memcpy (newData->m_data + m_start, GetStart (), m_size);
newData->m_initialStart = m_data->m_initialStart;
m_data->m_count--;
if (m_data->m_count == 0) {
recycle (m_data);
Recycle (m_data);
}
m_data = newData;
m_size += end;
@ -240,7 +240,7 @@ Buffer::addAtEnd (uint32_t end)
}
void
Buffer::removeAtStart (uint32_t start)
Buffer::RemoveAtStart (uint32_t start)
{
if (m_zeroAreaSize == 0) {
if (m_size <= start) {
@ -284,7 +284,7 @@ Buffer::removeAtStart (uint32_t start)
", dirty start="<<m_data->m_dirtyStart<<", dirty size="<<m_data->m_dirtySize);
}
void
Buffer::removeAtEnd (uint32_t end)
Buffer::RemoveAtEnd (uint32_t end)
{
if (m_zeroAreaSize == 0) {
if (m_size <= end) {
@ -325,47 +325,47 @@ Buffer::removeAtEnd (uint32_t end)
}
Buffer
Buffer::createFragment (uint32_t start, uint32_t length) const
Buffer::CreateFragment (uint32_t start, uint32_t length) const
{
uint32_t zeroStart = m_data->m_initialStart - m_start;
uint32_t zeroEnd = zeroStart + m_zeroAreaSize;
if (m_zeroAreaSize != 0 &&
start + length > zeroStart &&
start <= zeroEnd) {
transformIntoRealBuffer ();
TransformIntoRealBuffer ();
}
Buffer tmp = *this;
tmp.removeAtStart (start);
tmp.removeAtEnd (getSize () - (start + length));
tmp.RemoveAtStart (start);
tmp.RemoveAtEnd (GetSize () - (start + length));
return tmp;
}
void
Buffer::transformIntoRealBuffer (void) const
Buffer::TransformIntoRealBuffer (void) const
{
if (m_zeroAreaSize != 0) {
assert (m_data->m_initialStart >= m_start);
assert (m_size >= (m_data->m_initialStart - m_start));
Buffer tmp;
tmp.addAtStart (m_zeroAreaSize);
tmp.begin ().writeU8 (0, m_zeroAreaSize);
tmp.AddAtStart (m_zeroAreaSize);
tmp.Begin ().WriteU8 (0, m_zeroAreaSize);
uint32_t dataStart = m_data->m_initialStart - m_start;
tmp.addAtStart (dataStart);
tmp.begin ().write (m_data->m_data+m_start, dataStart);
tmp.AddAtStart (dataStart);
tmp.Begin ().Write (m_data->m_data+m_start, dataStart);
uint32_t dataEnd = m_size - (m_data->m_initialStart - m_start);
tmp.addAtEnd (dataEnd);
Buffer::Iterator i = tmp.end ();
i.prev (dataEnd);
i.write (m_data->m_data+m_data->m_initialStart,dataEnd);
tmp.AddAtEnd (dataEnd);
Buffer::Iterator i = tmp.End ();
i.Prev (dataEnd);
i.Write (m_data->m_data+m_data->m_initialStart,dataEnd);
*const_cast<Buffer *> (this) = tmp;
}
}
uint8_t const*
Buffer::peekData (void) const
Buffer::PeekData (void) const
{
transformIntoRealBuffer ();
TransformIntoRealBuffer ();
return m_data->m_data + m_start;
}
@ -384,10 +384,10 @@ namespace ns3 {
class BufferTest: public Test {
private:
bool ensureWrittenBytes (Buffer b, uint32_t n, uint8_t array[]);
bool EnsureWrittenBytes (Buffer b, uint32_t n, uint8_t array[]);
public:
virtual bool runTests (void);
BufferTest ();
virtual bool RunTests (void);
BufferTest ();
};
@ -395,32 +395,32 @@ BufferTest::BufferTest ()
: Test ("Buffer") {}
bool
BufferTest::ensureWrittenBytes (Buffer b, uint32_t n, uint8_t array[])
BufferTest::EnsureWrittenBytes (Buffer b, uint32_t n, uint8_t array[])
{
bool success = true;
uint8_t *expected = array;
uint8_t const*got;
got = b.peekData ();
got = b.PeekData ();
for (uint32_t j = 0; j < n; j++) {
if (got[j] != expected[j]) {
success = false;
}
}
if (!success) {
failure () << "Buffer -- ";
failure () << "expected: n=";
failure () << n << ", ";
failure ().setf (std::ios::hex, std::ios::basefield);
Failure () << "Buffer -- ";
Failure () << "expected: n=";
Failure () << n << ", ";
Failure ().setf (std::ios::hex, std::ios::basefield);
for (uint32_t j = 0; j < n; j++) {
failure () << (uint16_t)expected[j] << " ";
Failure () << (uint16_t)expected[j] << " ";
}
failure ().setf (std::ios::dec, std::ios::basefield);
failure () << "got: ";
failure ().setf (std::ios::hex, std::ios::basefield);
Failure ().setf (std::ios::dec, std::ios::basefield);
Failure () << "got: ";
Failure ().setf (std::ios::hex, std::ios::basefield);
for (uint32_t j = 0; j < n; j++) {
failure () << (uint16_t)got[j] << " ";
Failure () << (uint16_t)got[j] << " ";
}
failure () << std::endl;
Failure () << std::endl;
}
return success;
}
@ -432,75 +432,75 @@ BufferTest::ensureWrittenBytes (Buffer b, uint32_t n, uint8_t array[])
#define ENSURE_WRITTEN_BYTES(buffer, n, ...) \
{ \
uint8_t bytes[] = {__VA_ARGS__}; \
if (!ensureWrittenBytes (buffer, n , bytes)) { \
if (!EnsureWrittenBytes (buffer, n , bytes)) { \
ok = false; \
} \
}
bool
BufferTest::runTests (void)
BufferTest::RunTests (void)
{
bool ok = true;
Buffer buffer;
Buffer::Iterator i;
buffer.addAtStart (6);
i = buffer.begin ();
i.writeU8 (0x66);
buffer.AddAtStart (6);
i = buffer.Begin ();
i.WriteU8 (0x66);
ENSURE_WRITTEN_BYTES (buffer, 1, 0x66);
i = buffer.begin ();
i.writeU8 (0x67);
i = buffer.Begin ();
i.WriteU8 (0x67);
ENSURE_WRITTEN_BYTES (buffer, 1, 0x67);
i.writeHtonU16 (0x6568);
i = buffer.begin ();
i.WriteHtonU16 (0x6568);
i = buffer.Begin ();
ENSURE_WRITTEN_BYTES (buffer, 3, 0x67, 0x65, 0x68);
i.writeHtonU16 (0x6369);
i.WriteHtonU16 (0x6369);
ENSURE_WRITTEN_BYTES (buffer, 3, 0x63, 0x69, 0x68);
i.writeHtonU32 (0xdeadbeaf);
i.WriteHtonU32 (0xdeadbeaf);
ENSURE_WRITTEN_BYTES (buffer, 6, 0x63, 0x69, 0xde, 0xad, 0xbe, 0xaf);
buffer.addAtStart (2);
i = buffer.begin ();
i.writeU16 (0);
buffer.AddAtStart (2);
i = buffer.Begin ();
i.WriteU16 (0);
ENSURE_WRITTEN_BYTES (buffer, 8, 0, 0, 0x63, 0x69, 0xde, 0xad, 0xbe, 0xaf);
buffer.addAtEnd (2);
i = buffer.begin ();
i.next (8);
i.writeU16 (0);
buffer.AddAtEnd (2);
i = buffer.Begin ();
i.Next (8);
i.WriteU16 (0);
ENSURE_WRITTEN_BYTES (buffer, 10, 0, 0, 0x63, 0x69, 0xde, 0xad, 0xbe, 0xaf, 0, 0);
buffer.removeAtStart (3);
i = buffer.begin ();
buffer.RemoveAtStart (3);
i = buffer.Begin ();
ENSURE_WRITTEN_BYTES (buffer, 7, 0x69, 0xde, 0xad, 0xbe, 0xaf, 0, 0);
buffer.removeAtEnd (4);
i = buffer.begin ();
buffer.RemoveAtEnd (4);
i = buffer.Begin ();
ENSURE_WRITTEN_BYTES (buffer, 3, 0x69, 0xde, 0xad);
buffer.addAtStart (1);
i = buffer.begin ();
i.writeU8 (0xff);
buffer.AddAtStart (1);
i = buffer.Begin ();
i.WriteU8 (0xff);
ENSURE_WRITTEN_BYTES (buffer, 4, 0xff, 0x69, 0xde, 0xad);
buffer.addAtEnd (1);
i = buffer.begin ();
i.next (4);
i.writeU8 (0xff);
i.prev (2);
uint16_t saved = i.readU16 ();
i.prev (2);
i.writeHtonU16 (0xff00);
i.prev (2);
if (i.readNtohU16 () != 0xff00) {
buffer.AddAtEnd (1);
i = buffer.Begin ();
i.Next (4);
i.WriteU8 (0xff);
i.Prev (2);
uint16_t saved = i.ReadU16 ();
i.Prev (2);
i.WriteHtonU16 (0xff00);
i.Prev (2);
if (i.ReadNtohU16 () != 0xff00) {
ok = false;
}
i.prev (2);
i.writeU16 (saved);
i.Prev (2);
i.WriteU16 (saved);
ENSURE_WRITTEN_BYTES (buffer, 5, 0xff, 0x69, 0xde, 0xad, 0xff);
Buffer o = buffer;
ENSURE_WRITTEN_BYTES (o, 5, 0xff, 0x69, 0xde, 0xad, 0xff);
o.addAtStart (1);
i = o.begin ();
i.writeU8 (0xfe);
o.AddAtStart (1);
i = o.Begin ();
i.WriteU8 (0xfe);
ENSURE_WRITTEN_BYTES (o, 6, 0xfe, 0xff, 0x69, 0xde, 0xad, 0xff);
buffer.addAtStart (2);
i = buffer.begin ();
i.writeU8 (0xfd);
i.writeU8 (0xfd);
buffer.AddAtStart (2);
i = buffer.Begin ();
i.WriteU8 (0xfd);
i.WriteU8 (0xfd);
ENSURE_WRITTEN_BYTES (o, 6, 0xfe, 0xff, 0x69, 0xde, 0xad, 0xff);
ENSURE_WRITTEN_BYTES (buffer, 7, 0xfd, 0xfd, 0xff, 0x69, 0xde, 0xad, 0xff);
@ -510,71 +510,71 @@ BufferTest::runTests (void)
a = a;
}
// test remove start.
// test Remove start.
buffer = Buffer (5);
ENSURE_WRITTEN_BYTES (buffer, 5, 0, 0, 0, 0, 0);
buffer.removeAtStart (1);
buffer.RemoveAtStart (1);
ENSURE_WRITTEN_BYTES (buffer, 4, 0, 0, 0, 0);
buffer.addAtStart (1);
buffer.begin ().writeU8 (0xff);
buffer.AddAtStart (1);
buffer.Begin ().WriteU8 (0xff);
ENSURE_WRITTEN_BYTES (buffer, 5, 0xff, 0, 0, 0, 0);
buffer.removeAtStart(3);
buffer.RemoveAtStart(3);
ENSURE_WRITTEN_BYTES (buffer, 2, 0, 0);
buffer.addAtStart (4);
buffer.begin ().writeHtonU32 (0xdeadbeaf);
buffer.AddAtStart (4);
buffer.Begin ().WriteHtonU32 (0xdeadbeaf);
ENSURE_WRITTEN_BYTES (buffer, 6, 0xde, 0xad, 0xbe, 0xaf, 0, 0);
buffer.removeAtStart (2);
buffer.RemoveAtStart (2);
ENSURE_WRITTEN_BYTES (buffer, 4, 0xbe, 0xaf, 0, 0);
buffer.addAtEnd (4);
i = buffer.begin ();
i.next (4);
i.writeHtonU32 (0xdeadbeaf);
buffer.AddAtEnd (4);
i = buffer.Begin ();
i.Next (4);
i.WriteHtonU32 (0xdeadbeaf);
ENSURE_WRITTEN_BYTES (buffer, 8, 0xbe, 0xaf, 0, 0, 0xde, 0xad, 0xbe, 0xaf);
buffer.removeAtStart (5);
buffer.RemoveAtStart (5);
ENSURE_WRITTEN_BYTES (buffer, 3, 0xad, 0xbe, 0xaf);
// test remove end
// test Remove end
buffer = Buffer (5);
ENSURE_WRITTEN_BYTES (buffer, 5, 0, 0, 0, 0, 0);
buffer.removeAtEnd (1);
buffer.RemoveAtEnd (1);
ENSURE_WRITTEN_BYTES (buffer, 4, 0, 0, 0, 0);
buffer.addAtEnd (2);
i = buffer.begin ();
i.next (4);
i.writeU8 (0xab);
i.writeU8 (0xac);
buffer.AddAtEnd (2);
i = buffer.Begin ();
i.Next (4);
i.WriteU8 (0xab);
i.WriteU8 (0xac);
ENSURE_WRITTEN_BYTES (buffer, 6, 0, 0, 0, 0, 0xab, 0xac);
buffer.removeAtEnd (1);
buffer.RemoveAtEnd (1);
ENSURE_WRITTEN_BYTES (buffer, 5, 0, 0, 0, 0, 0xab);
buffer.removeAtEnd (3);
buffer.RemoveAtEnd (3);
ENSURE_WRITTEN_BYTES (buffer, 2, 0, 0);
buffer.addAtEnd (6);
i = buffer.begin ();
i.next (2);
i.writeU8 (0xac);
i.writeU8 (0xad);
i.writeU8 (0xae);
i.writeU8 (0xaf);
i.writeU8 (0xba);
i.writeU8 (0xbb);
buffer.AddAtEnd (6);
i = buffer.Begin ();
i.Next (2);
i.WriteU8 (0xac);
i.WriteU8 (0xad);
i.WriteU8 (0xae);
i.WriteU8 (0xaf);
i.WriteU8 (0xba);
i.WriteU8 (0xbb);
ENSURE_WRITTEN_BYTES (buffer, 8, 0, 0, 0xac, 0xad, 0xae, 0xaf, 0xba, 0xbb);
buffer.addAtStart (3);
i = buffer.begin ();
i.writeU8 (0x30);
i.writeU8 (0x31);
i.writeU8 (0x32);
buffer.AddAtStart (3);
i = buffer.Begin ();
i.WriteU8 (0x30);
i.WriteU8 (0x31);
i.WriteU8 (0x32);
ENSURE_WRITTEN_BYTES (buffer, 11, 0x30, 0x31, 0x32, 0, 0, 0xac, 0xad, 0xae, 0xaf, 0xba, 0xbb);
buffer.removeAtEnd (9);
buffer.RemoveAtEnd (9);
ENSURE_WRITTEN_BYTES (buffer, 2, 0x30, 0x31);
buffer = Buffer (3);
buffer.addAtEnd (2);
i = buffer.begin ();
i.next (3);
i.writeHtonU16 (0xabcd);
buffer.addAtStart (1);
buffer.begin ().writeU8 (0x21);
buffer.AddAtEnd (2);
i = buffer.Begin ();
i.Next (3);
i.WriteHtonU16 (0xabcd);
buffer.AddAtStart (1);
buffer.Begin ().WriteU8 (0x21);
ENSURE_WRITTEN_BYTES (buffer, 6, 0x21, 0, 0, 0, 0xab, 0xcd);
buffer.removeAtEnd (8);
if (buffer.getSize () != 0) {
buffer.RemoveAtEnd (8);
if (buffer.GetSize () != 0) {
ok = false;
}

194
src/common/buffer.h

@ -48,19 +48,19 @@ public:
/**
* go forward by one byte
*/
inline void next (void);
inline void Next (void);
/**
* go backward by one byte
*/
inline void prev (void);
inline void Prev (void);
/**
* \param delta number of bytes to go forward
*/
inline void next (uint32_t delta);
inline void Next (uint32_t delta);
/**
* \param delta number of bytes to go backward
*/
inline void prev (uint32_t delta);
inline void Prev (uint32_t delta);
/**
* \param o the second iterator
* \return number of bytes included between the two iterators
@ -69,18 +69,18 @@ public:
* to the same underlying buffer. Debug builds ensure
* this with an assert.
*/
inline int32_t getDistanceFrom (Iterator const &o) const;
inline int32_t GetDistanceFrom (Iterator const &o) const;
/**
* \return true if this iterator points to the end of the byte array.
* false otherwise.
*/
inline bool isEnd (void) const;
inline bool IsEnd (void) const;
/**
* \return true if this iterator points to the start of the byte array.
* false otherwise.
*/
inline bool isStart (void) const;
inline bool IsStart (void) const;
/**
* \param data data to write in buffer
@ -88,7 +88,7 @@ public:
* Write the data in buffer and avance the iterator position
* by one byte.
*/
inline void writeU8 (uint8_t data);
inline void WriteU8 (uint8_t data);
/**
* \param data data to write in buffer
* \param len number of times data must be written in buffer
@ -96,7 +96,7 @@ public:
* Write the data in buffer len times and avance the iterator position
* by len byte.
*/
inline void writeU8 (uint8_t data, uint32_t len);
inline void WriteU8 (uint8_t data, uint32_t len);
/**
* \param data data to write in buffer
*
@ -106,7 +106,7 @@ public:
* return exactly what we wrote with writeU16 if the program
* is run on the same machine.
*/
inline void writeU16 (uint16_t data);
inline void WriteU16 (uint16_t data);
/**
* \param data data to write in buffer
*
@ -116,7 +116,7 @@ public:
* return exactly what we wrote with writeU32 if the program
* is run on the same machine.
*/
inline void writeU32 (uint32_t data);
inline void WriteU32 (uint32_t data);
/**
* \param data data to write in buffer
*
@ -126,7 +126,7 @@ public:
* return exactly what we wrote with writeU64 if the program
* is run on the same machine.
*/
inline void writeU64 (uint64_t data);
inline void WriteU64 (uint64_t data);
/**
* \param data data to write in buffer
*
@ -134,7 +134,7 @@ public:
* by two bytes. The data is written in network order and the
* input data is expected to be in host order.
*/
inline void writeHtonU16 (uint16_t data);
inline void WriteHtonU16 (uint16_t data);
/**
* \param data data to write in buffer
*
@ -142,7 +142,7 @@ public:
* by four bytes. The data is written in network order and the
* input data is expected to be in host order.
*/
inline void writeHtonU32 (uint32_t data);
inline void WriteHtonU32 (uint32_t data);
/**
* \param data data to write in buffer
*
@ -150,7 +150,7 @@ public:
* by eight bytes. The data is written in network order and the
* input data is expected to be in host order.
*/
inline void writeHtonU64 (uint64_t data);
inline void WriteHtonU64 (uint64_t data);
/**
* \param buffer a byte buffer to copy in the internal buffer.
* \param size number of bytes to copy.
@ -158,7 +158,7 @@ public:
* Write the data in buffer and avance the iterator position
* by size bytes.
*/
inline void write (uint8_t const*buffer, uint16_t size);
inline void Write (uint8_t const*buffer, uint16_t size);
/**
* \param start the start of the data to copy
* \param end the end of the data to copy
@ -170,7 +170,7 @@ public:
* we do to avoid overlapping copies. This is enforced
* in debug builds by asserts.
*/
inline void write (Iterator start, Iterator end);
inline void Write (Iterator start, Iterator end);
/**
* \return the byte read in the buffer.
@ -178,7 +178,7 @@ public:
* Read data and advance the Iterator by the number of bytes
* read.
*/
inline uint8_t readU8 (void);
inline uint8_t ReadU8 (void);
/**
* \return the two bytes read in the buffer.
*
@ -186,7 +186,7 @@ public:
* read.
* The data is read in the format written by writeU16.
*/
inline uint16_t readU16 (void);
inline uint16_t ReadU16 (void);
/**
* \return the four bytes read in the buffer.
*
@ -194,7 +194,7 @@ public:
* read.
* The data is read in the format written by writeU32.
*/
inline uint32_t readU32 (void);
inline uint32_t ReadU32 (void);
/**
* \return the eight bytes read in the buffer.
*
@ -202,7 +202,7 @@ public:
* read.
* The data is read in the format written by writeU64.
*/
inline uint64_t readU64 (void);
inline uint64_t ReadU64 (void);
/**
* \return the two bytes read in the buffer.
*
@ -210,7 +210,7 @@ public:
* read.
* The data is read in network format and return in host format.
*/
inline uint16_t readNtohU16 (void);
inline uint16_t ReadNtohU16 (void);
/**
* \return the four bytes read in the buffer.
*
@ -218,7 +218,7 @@ public:
* read.
* The data is read in network format and return in host format.
*/
inline uint32_t readNtohU32 (void);
inline uint32_t ReadNtohU32 (void);
/**
* \return the eight bytes read in the buffer.
*
@ -226,7 +226,7 @@ public:
* read.
* The data is read in network format and return in host format.
*/
inline uint64_t readNtohU64 (void);
inline uint64_t ReadNtohU64 (void);
/**
* \param buffer buffer to copy data into
* \param size number of bytes to copy
@ -235,11 +235,11 @@ public:
* input buffer and avance the Iterator by the number of
* bytes read.
*/
inline void read (uint8_t *buffer, uint16_t size);
inline void Read (uint8_t *buffer, uint16_t size);
private:
friend class Buffer;
inline Iterator (Buffer const*buffer, uint32_t m_current);
inline uint32_t getIndex (uint32_t n);
inline uint32_t GetIndex (uint32_t n);
uint32_t m_zeroStart;
uint32_t m_zeroEnd;
uint32_t m_dataEnd;
@ -250,18 +250,18 @@ public:
/**
* \return the number of bytes stored in this buffer.
*/
inline uint32_t getSize (void) const;
inline uint32_t GetSize (void) const;
/**
* \return a pointer to the start of the internal
* byte buffer.
*
* The returned pointer points to an area of
* memory which is ns3::Buffer::getSize () bytes big.
* memory which is ns3::Buffer::GetSize () bytes big.
* Please, try to never ever use this method. It is really
* evil and is present only for a few specific uses.
*/
uint8_t const*peekData (void) const;
uint8_t const*PeekData (void) const;
/**
* \param start size to reserve
@ -272,7 +272,7 @@ public:
* Any call to this method invalidates any Iterator
* pointing to this Buffer.
*/
void addAtStart (uint32_t start);
void AddAtStart (uint32_t start);
/**
* \param end size to reserve
*
@ -282,7 +282,7 @@ public:
* Any call to this method invalidates any Iterator
* pointing to this Buffer.
*/
void addAtEnd (uint32_t end);
void AddAtEnd (uint32_t end);
/**
* \param start size to remove
*
@ -290,7 +290,7 @@ public:
* Any call to this method invalidates any Iterator
* pointing to this Buffer.
*/
void removeAtStart (uint32_t start);
void RemoveAtStart (uint32_t start);
/**
* \param end size to remove
*
@ -298,7 +298,7 @@ public:
* Any call to this method invalidates any Iterator
* pointing to this Buffer.
*/
void removeAtEnd (uint32_t end);
void RemoveAtEnd (uint32_t end);
/**
* \param start offset from start of packet
@ -307,18 +307,18 @@ public:
* \return a fragment of size length starting at offset
* start.
*/
Buffer createFragment (uint32_t start, uint32_t length) const;
Buffer CreateFragment (uint32_t start, uint32_t length) const;
/**
* \return an Iterator which points to the
* start of this Buffer.
*/
inline Buffer::Iterator begin (void) const;
inline Buffer::Iterator Begin (void) const;
/**
* \return an Iterator which points to the
* end of this Buffer.
*/
inline Buffer::Iterator end (void) const;
inline Buffer::Iterator End (void) const;
inline Buffer (Buffer const &o);
inline Buffer &operator = (Buffer const &o);
@ -336,12 +336,12 @@ private:
};
typedef std::vector<struct Buffer::BufferData*> BufferDataList;
inline uint8_t *getStart (void) const;
void transformIntoRealBuffer (void) const;
static void recycle (struct Buffer::BufferData *data);
static struct Buffer::BufferData *create (void);
static struct Buffer::BufferData *allocate (uint32_t size, uint32_t start);
static void deallocate (struct Buffer::BufferData *data);
inline uint8_t *GetStart (void) const;
void TransformIntoRealBuffer (void) const;
static void Recycle (struct Buffer::BufferData *data);
static struct Buffer::BufferData *Create (void);
static struct Buffer::BufferData *Allocate (uint32_t size, uint32_t start);
static void Deallocate (struct Buffer::BufferData *data);
static BufferDataList m_freeList;
static uint32_t m_maxTotalAddStart;
@ -366,7 +366,7 @@ private:
namespace ns3 {
Buffer::Buffer ()
: m_data (Buffer::create ()),
: m_data (Buffer::Create ()),
m_zeroAreaSize (0),
m_start (m_maxTotalAddStart),
m_size (0)
@ -378,7 +378,7 @@ Buffer::Buffer ()
}
Buffer::Buffer (uint32_t dataSize)
: m_data (Buffer::create ()),
: m_data (Buffer::Create ()),
m_zeroAreaSize (dataSize),
m_start (m_maxTotalAddStart),
m_size (0)
@ -407,7 +407,7 @@ Buffer::operator = (Buffer const&o)
// not assignment to self.
m_data->m_count--;
if (m_data->m_count == 0) {
recycle (m_data);
Recycle (m_data);
}
m_data = o.m_data;
m_data->m_count++;
@ -423,32 +423,32 @@ Buffer::~Buffer ()
{
m_data->m_count--;
if (m_data->m_count == 0) {
recycle (m_data);
Recycle (m_data);
}
}
uint8_t *
Buffer::getStart (void) const
Buffer::GetStart (void) const
{
return m_data->m_data + m_start;
}
uint32_t
Buffer::getSize (void) const
Buffer::GetSize (void) const
{
return m_size + m_zeroAreaSize;
}
Buffer::Iterator
Buffer::begin (void) const
Buffer::Begin (void) const
{
return Buffer::Iterator (this, 0);
}
Buffer::Iterator
Buffer::end (void) const
Buffer::End (void) const
{
return Buffer::Iterator (this, getSize ());
return Buffer::Iterator (this, GetSize ());
}
@ -462,37 +462,37 @@ Buffer::Iterator::Iterator ()
Buffer::Iterator::Iterator (Buffer const*buffer, uint32_t current)
: m_zeroStart (buffer->m_data->m_initialStart-buffer->m_start),
m_zeroEnd (m_zeroStart+buffer->m_zeroAreaSize),
m_dataEnd (buffer->getSize ()),
m_dataEnd (buffer->GetSize ()),
m_current (current),
m_data (buffer->m_data->m_data+buffer->m_start)
{}
void
Buffer::Iterator::next (void)
Buffer::Iterator::Next (void)
{
assert (m_current + 1 <= m_dataEnd);
m_current++;
}
void
Buffer::Iterator::prev (void)
Buffer::Iterator::Prev (void)
{
assert (m_current >= 1);
m_current--;
}
void
Buffer::Iterator::next (uint32_t delta)
Buffer::Iterator::Next (uint32_t delta)
{
assert (m_current + delta <= m_dataEnd);
m_current += delta;
}
void
Buffer::Iterator::prev (uint32_t delta)
Buffer::Iterator::Prev (uint32_t delta)
{
assert (m_current >= delta);
m_current -= delta;
}
int32_t
Buffer::Iterator::getDistanceFrom (Iterator const &o) const
Buffer::Iterator::GetDistanceFrom (Iterator const &o) const
{
assert (m_data == o.m_data);
int32_t start = m_current;
@ -501,18 +501,18 @@ Buffer::Iterator::getDistanceFrom (Iterator const &o) const
}
bool
Buffer::Iterator::isEnd (void) const
Buffer::Iterator::IsEnd (void) const
{
return m_current == m_dataEnd;
}
bool
Buffer::Iterator::isStart (void) const
Buffer::Iterator::IsStart (void) const
{
return m_current == 0;
}
uint32_t
Buffer::Iterator::getIndex (uint32_t n)
Buffer::Iterator::GetIndex (uint32_t n)
{
assert (
(m_current + n <= m_dataEnd) &&
@ -530,64 +530,64 @@ Buffer::Iterator::getIndex (uint32_t n)
void
Buffer::Iterator::write (Iterator start, Iterator end)
Buffer::Iterator::Write (Iterator start, Iterator end)
{
assert (start.m_data == end.m_data);
assert (start.m_current <= end.m_current);
assert (m_data != start.m_data);
uint32_t size = end.m_current - start.m_current;
uint8_t *src = start.m_data + start.getIndex (size);
uint8_t *dest = m_data + getIndex (size);
uint8_t *src = start.m_data + start.GetIndex (size);
uint8_t *dest = m_data + GetIndex (size);
memcpy (dest, src, size);
m_current += size;
}
void
Buffer::Iterator::writeU8 (uint8_t data, uint32_t len)
Buffer::Iterator::WriteU8 (uint8_t data, uint32_t len)
{
uint8_t *current = m_data + getIndex (len);
uint8_t *current = m_data + GetIndex (len);
memset (current, data, len);
m_current += len;
}
void
Buffer::Iterator::writeU8 (uint8_t data)
Buffer::Iterator::WriteU8 (uint8_t data)
{
m_data[getIndex (1)] = data;
m_data[GetIndex (1)] = data;
m_current++;
}
void
Buffer::Iterator::writeU16 (uint16_t data)
Buffer::Iterator::WriteU16 (uint16_t data)
{
uint16_t *buffer = (uint16_t *)(m_data + getIndex (2));
uint16_t *buffer = (uint16_t *)(m_data + GetIndex (2));
*buffer = data;
m_current += 2;
}
void
Buffer::Iterator::writeU32 (uint32_t data)
Buffer::Iterator::WriteU32 (uint32_t data)
{
uint32_t *buffer = (uint32_t *)(m_data + getIndex (4));
uint32_t *buffer = (uint32_t *)(m_data + GetIndex (4));
*buffer = data;
m_current += 4;
}
void
Buffer::Iterator::writeU64 (uint64_t data)
Buffer::Iterator::WriteU64 (uint64_t data)
{
uint64_t *buffer = (uint64_t *)(m_data + getIndex (8));
uint64_t *buffer = (uint64_t *)(m_data + GetIndex (8));
*buffer = data;
m_current += 8;
}
void
Buffer::Iterator::writeHtonU16 (uint16_t data)
Buffer::Iterator::WriteHtonU16 (uint16_t data)
{
uint8_t *current = m_data + getIndex (2);
uint8_t *current = m_data + GetIndex (2);
*(current+0) = (data >> 8) & 0xff;
*(current+1) = (data >> 0) & 0xff;
m_current += 2;
}
void
Buffer::Iterator::writeHtonU32 (uint32_t data)
Buffer::Iterator::WriteHtonU32 (uint32_t data)
{
uint8_t *current = m_data + getIndex (4);
uint8_t *current = m_data + GetIndex (4);
*(current+0) = (data >> 24) & 0xff;
*(current+1) = (data >> 16) & 0xff;
*(current+2) = (data >> 8) & 0xff;
@ -595,9 +595,9 @@ Buffer::Iterator::writeHtonU32 (uint32_t data)
m_current += 4;
}
void
Buffer::Iterator::writeHtonU64 (uint64_t data)
Buffer::Iterator::WriteHtonU64 (uint64_t data)
{
uint8_t *current = m_data + getIndex (8);
uint8_t *current = m_data + GetIndex (8);
*(current+0) = (data >> 56) & 0xff;
*(current+1) = (data >> 48) & 0xff;
*(current+2) = (data >> 40) & 0xff;
@ -609,45 +609,45 @@ Buffer::Iterator::writeHtonU64 (uint64_t data)
m_current += 8;
}
void
Buffer::Iterator::write (uint8_t const*buffer, uint16_t size)
Buffer::Iterator::Write (uint8_t const*buffer, uint16_t size)
{
uint8_t *current = m_data + getIndex (size);
uint8_t *current = m_data + GetIndex (size);
memcpy (current, buffer, size);
m_current += size;
}
uint8_t
Buffer::Iterator::readU8 (void)
Buffer::Iterator::ReadU8 (void)
{
uint8_t data = m_data[getIndex(1)];
uint8_t data = m_data[GetIndex(1)];
m_current++;
return data;
}
uint16_t
Buffer::Iterator::readU16 (void)
Buffer::Iterator::ReadU16 (void)
{
uint16_t *buffer = reinterpret_cast<uint16_t *>(m_data + getIndex (2));
uint16_t *buffer = reinterpret_cast<uint16_t *>(m_data + GetIndex (2));
m_current += 2;
return *buffer;
}
uint32_t
Buffer::Iterator::readU32 (void)
Buffer::Iterator::ReadU32 (void)
{
uint32_t *buffer = reinterpret_cast<uint32_t *>(m_data + getIndex (4));
uint32_t *buffer = reinterpret_cast<uint32_t *>(m_data + GetIndex (4));
m_current += 4;
return *buffer;
}
uint64_t
Buffer::Iterator::readU64 (void)
Buffer::Iterator::ReadU64 (void)
{
uint64_t *buffer = reinterpret_cast<uint64_t *>(m_data + getIndex (8));
uint64_t *buffer = reinterpret_cast<uint64_t *>(m_data + GetIndex (8));
m_current += 8;
return *buffer;
}
uint16_t
Buffer::Iterator::readNtohU16 (void)
Buffer::Iterator::ReadNtohU16 (void)
{
uint8_t *current = m_data + getIndex (2);
uint8_t *current = m_data + GetIndex (2);
uint16_t retval = 0;
retval |= static_cast<uint16_t> (current[0]) << 8;
retval |= static_cast<uint16_t> (current[1]) << 0;
@ -655,9 +655,9 @@ Buffer::Iterator::readNtohU16 (void)
return retval;
}
uint32_t
Buffer::Iterator::readNtohU32 (void)
Buffer::Iterator::ReadNtohU32 (void)
{
uint8_t *current = m_data + getIndex (4);
uint8_t *current = m_data + GetIndex (4);
uint32_t retval = 0;
retval |= static_cast<uint32_t> (current[0]) << 24;
retval |= static_cast<uint32_t> (current[1]) << 16;
@ -667,9 +667,9 @@ Buffer::Iterator::readNtohU32 (void)
return retval;
}
uint64_t
Buffer::Iterator::readNtohU64 (void)
Buffer::Iterator::ReadNtohU64 (void)
{
uint8_t *current = m_data + getIndex (8);
uint8_t *current = m_data + GetIndex (8);
uint64_t retval = 0;
retval |= static_cast<uint64_t> (current[0]) << 56;
retval |= static_cast<uint64_t> (current[1]) << 48;
@ -683,9 +683,9 @@ Buffer::Iterator::readNtohU64 (void)
return retval;
}
void
Buffer::Iterator::read (uint8_t *buffer, uint16_t size)
Buffer::Iterator::Read (uint8_t *buffer, uint16_t size)
{
uint8_t *current = m_data + getIndex (size);
uint8_t *current = m_data + GetIndex (size);
memcpy (buffer, current, size);
m_current += size;
}

14
src/common/callback-tracer.h

@ -41,36 +41,36 @@ class CallbackTracer : public CallbackTracerBase{
public:
CallbackTracer ()
: m_callback () {}
void setCallback (Callback<void,T1,T2,T3,T4,T5> callback) {
void SetCallback (Callback<void,T1,T2,T3,T4,T5> callback) {
m_callback = callback;
}
void operator() (void) {
if (!m_callback.isNull ()) {
if (!m_callback.IsNull ()) {
m_callback ();
}
}
void operator() (T1 a1) {
if (!m_callback.isNull ()) {
if (!m_callback.IsNull ()) {
m_callback (a1);
}
}
void operator() (T1 a1, T2 a2) {
if (!m_callback.isNull ()) {
if (!m_callback.IsNull ()) {
m_callback (a1,a2);
}
}
void operator() (T1 a1, T2 a2, T3 a3) {
if (!m_callback.isNull ()) {
if (!m_callback.IsNull ()) {
m_callback (a1,a2,a3);
}
}
void operator() (T1 a1, T2 a2, T3 a3, T4 a4) {
if (!m_callback.isNull ()) {
if (!m_callback.IsNull ()) {
m_callback (a1,a2,a3,a4);
}
}
void operator() (T1 a1, T2 a2, T3 a3, T4 a4,T5 a5) {
if (!m_callback.isNull ()) {
if (!m_callback.IsNull ()) {
m_callback (a1,a2,a3,a4,a5);
}
}

20
src/common/data-writer.cc

@ -62,15 +62,15 @@ DataWriterPrivate::DataWriterPrivate ()
{}
DataWriterPrivate::~DataWriterPrivate ()
{
::write (m_fd, m_data, m_current);
::close (m_fd);
::Write (m_fd, m_data, m_current);
::Close (m_fd);
}
void
DataWriterPrivate::open (char const *filename)
DataWriterPrivate::Open (char const *filename)
{
m_fd = ::open (filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
m_fd = ::Open (filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
assert (m_fd != -1);
}
@ -79,7 +79,7 @@ DataWriterPrivate::open (char const *filename)
#endif /* min */
void
DataWriterPrivate::write (uint8_t *buffer, uint32_t size)
DataWriterPrivate::Write (uint8_t *buffer, uint32_t size)
{
while (size > 0) {
uint32_t toCopy = min (BUFFER_SIZE - m_current, size);
@ -89,7 +89,7 @@ DataWriterPrivate::write (uint8_t *buffer, uint32_t size)
buffer += toCopy;
if (m_current == BUFFER_SIZE) {
ssize_t written = 0;
written = ::write (m_fd, m_data, BUFFER_SIZE);
written = ::Write (m_fd, m_data, BUFFER_SIZE);
assert (written == BUFFER_SIZE);
m_current = 0;
}
@ -106,14 +106,14 @@ DataWriter::~DataWriter ()
}
void
DataWriter::open (char const *filename)
DataWriter::Open (char const *filename)
{
m_priv->open (filename);
m_priv->Open (filename);
}
void
DataWriter::write (uint8_t *buffer, uint32_t size)
DataWriter::Write (uint8_t *buffer, uint32_t size)
{
m_priv->write (buffer, size);
m_priv->Write (buffer, size);
}
}; // namespace

2
src/common/f-variable-tracer.h

@ -44,7 +44,7 @@ public:
}
protected:
void notify (double oldVal, double newVal) {
if (oldVal != newVal && !m_callback.isNull ()) {
if (oldVal != newVal && !m_callback.IsNull ()) {
m_callback (oldVal, newVal);
}
}

20
src/common/header.cc

@ -28,28 +28,28 @@ Header::Header ()
: m_isDeserialized (false) {}
void
Header::print (std::ostream &os) const
Header::Print (std::ostream &os) const
{
printTo (os);
PrintTo (os);
}
uint32_t
Header::getSize (void) const
Header::GetSize (void) const
{
return getSerializedSize ();
return GetSerializedSize ();
}
void
Header::serialize (Buffer::Iterator start) const
Header::Serialize (Buffer::Iterator start) const
{
serializeTo (start);
SerializeTo (start);
}
void
Header::deserialize (Buffer::Iterator start)
Header::Deserialize (Buffer::Iterator start)
{
deserializeFrom (start);
DeserializeFrom (start);
m_isDeserialized = true;
}
bool
Header::isDeserialized (void) const
Header::IsDeserialized (void) const
{
return m_isDeserialized;
}
@ -61,7 +61,7 @@ Header::~Header ()
std::ostream& operator<< (std::ostream& os, Header const& header)
{
header.print (os);
header.Print (os);
return os;
}

26
src/common/header.h

@ -34,10 +34,10 @@ namespace ns3 {
* Every Protocol header which needs to be inserted and removed
* from a Packet instance must derive from this abstract base class
* and implement the private pure virtual methods listed below:
* - ns3::Header::serializeTo
* - ns3::Header::deserializeFrom
* - ns3::Header::getSerializedSize
* - ns3::Header::printTo
* - ns3::Header::SerializeTo
* - ns3::Header::DeserializeFrom
* - ns3::Header::GetSerializedSize
* - ns3::Header::PrintTo
*/
class Header {
public:
@ -47,34 +47,34 @@ public:
*/
virtual ~Header () = 0;
void print (std::ostream &os) const;
uint32_t getSize (void) const;
void serialize (Buffer::Iterator start) const;
void deserialize (Buffer::Iterator start);
bool isDeserialized (void) const;
void Print (std::ostream &os) const;
uint32_t GetSize (void) const;
void Serialize (Buffer::Iterator start) const;
void Deserialize (Buffer::Iterator start);
bool IsDeserialized (void) const;
private:
bool m_isDeserialized;
/**
* \param os the std output stream in which this
* protocol header must print itself.
*/
virtual void printTo (std::ostream &os) const = 0;
virtual void PrintTo (std::ostream &os) const = 0;
/**
* \returns the size of the serialized Header.
*/
virtual uint32_t getSerializedSize (void) const = 0;
virtual uint32_t GetSerializedSize (void) const = 0;
/**
* \param start the buffer iterator in which the protocol header
* must serialize itself.
*/
virtual void serializeTo (Buffer::Iterator start) const = 0;
virtual void SerializeTo (Buffer::Iterator start) const = 0;
/**
* \param start the buffer iterator from which the protocol header must
* deserialize itself.
*/
virtual void deserializeFrom (Buffer::Iterator start) = 0;
virtual void DeserializeFrom (Buffer::Iterator start) = 0;
};
std::ostream& operator<< (std::ostream& os, Header const& header);

94
src/common/packet.cc

@ -45,114 +45,114 @@ Packet::Packet (Buffer buffer, Tags tags, uint32_t uid)
{}
Packet
Packet::createFragment (uint32_t start, uint32_t length) const
Packet::CreateFragment (uint32_t start, uint32_t length) const
{
Buffer tmp = m_buffer.createFragment (start, length);
Buffer tmp = m_buffer.CreateFragment (start, length);
return Packet (tmp, m_tags, m_uid);
}
uint32_t
Packet::getSize (void) const
Packet::GetSize (void) const
{
return m_buffer.getSize ();
return m_buffer.GetSize ();
}
void
Packet::add (Header const &header)
Packet::Add (Header const &header)
{
m_buffer.addAtStart (header.getSize ());
header.serialize (m_buffer.begin ());
m_buffer.AddAtStart (header.GetSize ());
header.Serialize (m_buffer.Begin ());
}
void
Packet::peek (Header &header)
Packet::Peek (Header &header)
{
header.deserialize (m_buffer.begin ());
header.Deserialize (m_buffer.Begin ());
}
void
Packet::remove (Header const &header)
Packet::Remove (Header const &header)
{
assert (header.isDeserialized ());
m_buffer.removeAtStart (header.getSize ());
assert (header.IsDeserialized ());
m_buffer.RemoveAtStart (header.GetSize ());
}
void
Packet::add (Trailer const &trailer)
Packet::Add (Trailer const &trailer)
{
m_buffer.addAtEnd (trailer.getSize ());
Buffer::Iterator start = m_buffer.end ();
start.prev (trailer.getSize ());
trailer.serialize (start);
m_buffer.AddAtEnd (trailer.GetSize ());
Buffer::Iterator start = m_buffer.End ();
start.Prev (trailer.GetSize ());
trailer.Serialize (start);
}
void
Packet::peek (Trailer &trailer)
Packet::Peek (Trailer &trailer)
{
Buffer::Iterator start = m_buffer.end ();
start.prev (trailer.getSize ());
trailer.deserialize (start);
Buffer::Iterator start = m_buffer.End ();
start.Prev (trailer.GetSize ());
trailer.Deserialize (start);
}
void
Packet::remove (Trailer const &trailer)
Packet::Remove (Trailer const &trailer)
{
assert (trailer.isDeserialized ());
m_buffer.removeAtEnd (trailer.getSize ());
assert (trailer.IsDeserialized ());
m_buffer.RemoveAtEnd (trailer.GetSize ());
}
void
Packet::addAtEnd (Packet packet)
Packet::AddAtEnd (Packet packet)
{
Buffer src = packet.m_buffer;
m_buffer.addAtEnd (src.getSize ());
Buffer::Iterator destStart = m_buffer.end ();
destStart.prev (src.getSize ());
destStart.write (src.begin (), src.end ());
m_buffer.AddAtEnd (src.GetSize ());
Buffer::Iterator destStart = m_buffer.End ();
destStart.Prev (src.GetSize ());
destStart.Write (src.Begin (), src.End ());
/**
* XXX: we might need to merge the tag list of the
* other packet into the current packet.
*/
}
void
Packet::addAtEnd (Packet packet, uint32_t start, uint32_t size)
Packet::AddAtEnd (Packet packet, uint32_t start, uint32_t size)
{
assert (packet.getSize () <= start + size);
assert (packet.GetSize () <= start + size);
Buffer src = packet.m_buffer;
m_buffer.addAtEnd (src.getSize ());
Buffer::Iterator destStart = m_buffer.end ();
destStart.prev (size);
Buffer::Iterator srcStart = src.begin ();
srcStart.next (start);
m_buffer.AddAtEnd (src.GetSize ());
Buffer::Iterator destStart = m_buffer.End ();
destStart.Prev (size);
Buffer::Iterator srcStart = src.Begin ();
srcStart.Next (start);
Buffer::Iterator srcEnd = srcStart;
srcEnd.next (size);
destStart.write (srcStart, srcEnd);
srcEnd.Next (size);
destStart.Write (srcStart, srcEnd);
/**
* XXX: we might need to merge the tag list of the
* other packet into the current packet.
*/
}
void
Packet::removeAtEnd (uint32_t size)
Packet::RemoveAtEnd (uint32_t size)
{
m_buffer.removeAtEnd (size);
m_buffer.RemoveAtEnd (size);
}
void
Packet::removeAtStart (uint32_t size)
Packet::RemoveAtStart (uint32_t size)
{
m_buffer.removeAtStart (size);
m_buffer.RemoveAtStart (size);
}
void
Packet::removeAllTags (void)
Packet::RemoveAllTags (void)
{
m_tags.removeAll ();
m_tags.RemoveAll ();
}
uint8_t const *
Packet::peekData (void) const
Packet::PeekData (void) const
{
return m_buffer.peekData ();
return m_buffer.PeekData ();
}
uint32_t
Packet::getUid (void) const
Packet::GetUid (void) const
{
return m_uid;
}

70
src/common/packet.h

@ -65,19 +65,19 @@ namespace ns3 {
* to detect when an operation is "dirty".
*
* Dirty operations:
* - ns3::Packet::removeTag
* - ns3::Packet::add
* - both versions of ns3::Packet::addAtEnd
* - ns3::Packet::RemoveTag
* - ns3::Packet::Add
* - both versions of ns3::Packet::AddAtEnd
*
* Non-dirty operations:
* - ns3::Packet::addTag
* - ns3::Packet::removeAllTags
* - ns3::Packet::peekTag
* - ns3::Packet::peek
* - ns3::Packet::remove
* - ns3::Packet::createFragment
* - ns3::Packet::removeAtStart
* - ns3::Packet::removeAtEnd
* - ns3::Packet::AddTag
* - ns3::Packet::RemoveAllTags
* - ns3::Packet::PeekTag
* - ns3::Packet::Peek
* - ns3::Packet::Remove
* - ns3::Packet::CreateFragment
* - ns3::Packet::RemoveAtStart
* - ns3::Packet::RemoveAtEnd
*
* Dirty operations will always be slower than non-dirty operations,
* sometimes by several orders of magnitude. However, even the
@ -111,12 +111,12 @@ public:
* \param length length of fragment to create
* \returns a fragment of the original packet
*/
Packet createFragment (uint32_t start, uint32_t length) const;
Packet CreateFragment (uint32_t start, uint32_t length) const;
/**
* \returns the size in bytes of the packet (including the zero-filled
* initial payload)
*/
uint32_t getSize (void) const;
uint32_t GetSize (void) const;
/**
* Add header to this packet. This method invokes the
* ns3::Header::serializeTo method to request the header to serialize
@ -124,7 +124,7 @@ public:
*
* \param header a reference to the header to add to this packet.
*/
void add (Header const &header);
void Add (Header const &header);
/**
* Deserialize header from this packet. This method invokes the
* ns3::Header::deserializeFrom method to request the header to deserialize
@ -133,7 +133,7 @@ public:
*
* \param header a reference to the header to deserialize from the buffer
*/
void peek (Header &header);
void Peek (Header &header);
/**
* Remove a deserialized header from the internal buffer.
* This method removes the bytes read by Packet::peek from
@ -141,7 +141,7 @@ public:
*
* \param header a reference to the header to remove from the internal buffer.
*/
void remove (Header const &header);
void Remove (Header const &header);
/**
* Add trailer to this packet. This method invokes the
* ns3::Trailer::serializeTo method to request the trailer to serialize
@ -149,7 +149,7 @@ public:
*
* \param trailer a reference to the trailer to add to this packet.
*/
void add (Trailer const &trailer);
void Add (Trailer const &trailer);
/**
* Deserialize trailer from this packet. This method invokes the
* ns3::Trailer::deserializeFrom method to request the trailer to deserialize
@ -158,7 +158,7 @@ public:
*
* \param trailer a reference to the trailer to deserialize from the buffer
*/
void peek (Trailer &trailer);
void Peek (Trailer &trailer);
/**
* Remove a deserialized trailer from the internal buffer.
* This method removes the bytes read by Packet::peek from
@ -166,7 +166,7 @@ public:
*
* \param trailer a reference to the trailer to remove from the internal buffer.
*/
void remove (Trailer const &trailer);
void Remove (Trailer const &trailer);
/**
* Attach a tag to this packet. The tag is fully copied
* in a packet-specific internal buffer. This operation
@ -175,7 +175,7 @@ public:
* \param tag a pointer to the tag to attach to this packet.
*/
template <typename T>
void addTag (T const &tag);
void AddTag (T const &tag);
/**
* Remove a tag from this packet. The data stored internally
* for this tag is copied in the input tag if an instance
@ -193,7 +193,7 @@ public:
* in this packet, false otherwise.
*/
template <typename T>
bool removeTag (T &tag);
bool RemoveTag (T &tag);
/**
* Copy a tag stored internally to the input tag. If no instance
* of this tag is present internally, the input tag is not modified.
@ -203,19 +203,19 @@ public:
* in this packet, false otherwise.
*/
template <typename T>
bool peekTag (T &tag) const;
bool PeekTag (T &tag) const;
/**
* Remove all the tags stored in this packet. This operation is
* much much faster than invoking removeTag n times.
*/
void removeAllTags (void);
void RemoveAllTags (void);
/**
* Concatenate the input packet at the end of the current
* packet. This does not alter the uid of either packet.
*
* \param packet packet to concatenate
*/
void addAtEnd (Packet packet);
void AddAtEnd (Packet packet);
/**
* Concatenate the fragment of the input packet identified
* by the offset and size parameters at the end of the current
@ -225,7 +225,7 @@ public:
* \param offset offset of fragment to copy from the start of the input packet
* \param size size of fragment of input packet to copy.
*/
void addAtEnd (Packet packet, uint32_t offset, uint32_t size);
void AddAtEnd (Packet packet, uint32_t offset, uint32_t size);
/**
* Remove size bytes from the end of the current packet
* It is safe to remove more bytes that what is present in
@ -233,7 +233,7 @@ public:
*
* \param size number of bytes from remove
*/
void removeAtEnd (uint32_t size);
void RemoveAtEnd (uint32_t size);
/**
* Remove size bytes from the start of the current packet.
* It is safe to remove more bytes that what is present in
@ -241,7 +241,7 @@ public:
*
* \param size number of bytes from remove
*/
void removeAtStart (uint32_t size);
void RemoveAtStart (uint32_t size);
/**
* If you try to change the content of the buffer
@ -249,7 +249,7 @@ public:
*
* \returns a pointer to the internal buffer of the packet.
*/
uint8_t const *peekData (void) const;
uint8_t const *PeekData (void) const;
/**
* A packet is allocated a new uid when it is created
@ -258,7 +258,7 @@ public:
* \returns an integer identifier which uniquely
* identifies this packet.
*/
uint32_t getUid (void) const;
uint32_t GetUid (void) const;
private:
Packet (Buffer buffer, Tags tags, uint32_t uid);
Buffer m_buffer;
@ -278,19 +278,19 @@ private:
namespace ns3 {
template <typename T>
void Packet::addTag (T const& tag)
void Packet::AddTag (T const& tag)
{
m_tags.add (tag);
m_tags.Add (tag);
}
template <typename T>
bool Packet::removeTag (T & tag)
bool Packet::RemoveTag (T & tag)
{
return m_tags.remove (tag);
return m_tags.Remove (tag);
}
template <typename T>
bool Packet::peekTag (T & tag) const
bool Packet::PeekTag (T & tag) const
{
return m_tags.peek (tag);
return m_tags.Peek (tag);
}
}; // namespace ns3

46
src/common/pcap-writer.cc

@ -46,53 +46,53 @@ PcapWriter::~PcapWriter ()
}
void
PcapWriter::open (char const *name)
PcapWriter::Open (char const *name)
{
m_writer = new SystemFile ();
m_writer->open (name);
m_writer->Open (name);
}
void
PcapWriter::writeHeaderEthernet (void)
PcapWriter::WriteHeaderEthernet (void)
{
write_32 (0xa1b2c3d4);
write_16 (2);
write_16 (4);
write_32 (0);
write_32 (0);
write_32 (0xffff);
write_32 (PCAP_ETHERNET);
Write32 (0xa1b2c3d4);
Write16 (2);
Write16 (4);
Write32 (0);
Write32 (0);
Write32 (0xffff);
Write32 (PCAP_ETHERNET);
}
void
PcapWriter::writePacket (Packet const packet)
PcapWriter::WritePacket (Packet const packet)
{
if (m_writer != 0) {
uint64_t current = Simulator::now ().us ();
uint64_t current = Simulator::Now ().Us ();
uint64_t s = current / 1000000;
uint64_t us = current % 1000000;
write_32 (s & 0xffffffff);
write_32 (us & 0xffffffff);
write_32 (packet.getSize ());
write_32 (packet.getSize ());
m_writer->write (packet.peekData (), packet.getSize ());
Write32 (s & 0xffffffff);
Write32 (us & 0xffffffff);
Write32 (packet.GetSize ());
Write32 (packet.GetSize ());
m_writer->Write (packet.PeekData (), packet.GetSize ());
}
}
void
PcapWriter::writeData (uint8_t *buffer, uint32_t size)
PcapWriter::WriteData (uint8_t *buffer, uint32_t size)
{
m_writer->write (buffer, size);
m_writer->Write (buffer, size);
}
void
PcapWriter::write_32 (uint32_t data)
PcapWriter::Write32 (uint32_t data)
{
m_writer->write ((uint8_t*)&data, 4);
m_writer->Write ((uint8_t*)&data, 4);
}
void
PcapWriter::write_16 (uint16_t data)
PcapWriter::Write16 (uint16_t data)
{
m_writer->write ((uint8_t*)&data, 2);
m_writer->Write ((uint8_t*)&data, 2);
}
}; // namespace ns3

12
src/common/pcap-writer.h

@ -46,7 +46,7 @@ public:
* This method creates the file if it does not exist. If it
* exists, the file is emptied.
*/
void open (char const *name);
void Open (char const *name);
/**
* Write a pcap header in the output file which specifies
@ -55,17 +55,17 @@ public:
* be invoked before ns3::PcapWriter::writePacket and after
* ns3::PcapWriter::open.
*/
void writeHeaderEthernet (void);
void WriteHeaderEthernet (void);
/**
* \param packet packet to write to output file
*/
void writePacket (Packet const packet);
void WritePacket (Packet const packet);
private:
void writeData (uint8_t *buffer, uint32_t size);
void write_32 (uint32_t data);
void write_16 (uint16_t data);
void WriteData (uint8_t *buffer, uint32_t size);
void Write32 (uint32_t data);
void Write16 (uint16_t data);
SystemFile *m_writer;
Callback<void,uint8_t *,uint32_t> m_writeCallback;
};

60
src/common/si-variable-tracer.h

@ -39,12 +39,12 @@ public:
~SiVariableTracerBase () {}
void setCallback(ChangeNotifyCallback callback) {
void SetCallback(ChangeNotifyCallback callback) {
m_callback = callback;
}
protected:
void notify (int64_t oldVal, int64_t newVal) {
if (oldVal != newVal && !m_callback.isNull ()) {
void Notify (int64_t oldVal, int64_t newVal) {
if (oldVal != newVal && !m_callback.IsNull ()) {
m_callback (oldVal, newVal);
}
}
@ -91,25 +91,25 @@ public:
{}
SiVariableTracer &operator = (SiVariableTracer const &o) {
assign (o.get ());
Assign (o.Get ());
return *this;
}
template <typename TT>
SiVariableTracer &operator = (SiVariableTracer<TT> const &o) {
assign (o.get ());
Assign (o.Get ());
return *this;
}
template <typename TT>
SiVariableTracer &operator = (UiVariableTracer<TT> const &o) {
assign (o.get ());
Assign (o.Get ());
return *this;
}
SiVariableTracer &operator++ () {
assign (get () + 1);
Assign (Get () + 1);
return *this;
}
SiVariableTracer &operator-- () {
assign (get () - 1);
Assign (Get () - 1);
return *this;
}
SiVariableTracer operator++ (int) {
@ -123,15 +123,15 @@ public:
return old;
}
operator T () const {
return get ();
return Get ();
}
void assign (T var) {
notify (m_var, var);
void Assign (T var) {
Notify (m_var, var);
m_var = var;
}
T get (void) const {
T Get (void) const {
return m_var;
}
@ -141,94 +141,94 @@ private:
template <typename T>
SiVariableTracer<T> &operator += (SiVariableTracer<T> &lhs, SiVariableTracer<T> const &rhs) {
lhs.assign (lhs.get () + rhs.get ());
lhs.Assign (lhs.Get () + rhs.Get ());
return lhs;
}
template <typename T>
SiVariableTracer<T> &operator -= (SiVariableTracer<T> &lhs, SiVariableTracer<T> const &rhs) {
lhs.assign (lhs.get () - rhs.get ());
lhs.Assign (lhs.Get () - rhs.Get ());
return lhs;
}
template <typename T>
SiVariableTracer<T> &operator *= (SiVariableTracer<T> &lhs, SiVariableTracer<T> const &rhs) {
lhs.assign (lhs.get () * rhs.get ());
lhs.Assign (lhs.Get () * rhs.Get ());
return lhs;
}
template <typename T>
SiVariableTracer<T> &operator /= (SiVariableTracer<T> &lhs, SiVariableTracer<T> const &rhs) {
lhs.assign (lhs.get () / rhs.get ());
lhs.Assign (lhs.Get () / rhs.Get ());
return lhs;
}
template <typename T>
SiVariableTracer<T> &operator <<= (SiVariableTracer<T> &lhs, SiVariableTracer<T> const &rhs) {
lhs.assign (lhs.get () << rhs.get ());
lhs.Assign (lhs.Get () << rhs.Get ());
return lhs;
}
template <typename T>
SiVariableTracer<T> &operator >>= (SiVariableTracer<T> &lhs, SiVariableTracer<T> const &rhs) {
lhs.assign (lhs.get () >> rhs.get ());
lhs.Assign (lhs.Get () >> rhs.Get ());
return lhs;
}
template <typename T>
SiVariableTracer<T> &operator &= (SiVariableTracer<T> &lhs, SiVariableTracer<T> const &rhs) {
lhs.assign (lhs.get () & rhs.get ());
lhs.Assign (lhs.Get () & rhs.Get ());
return lhs;
}
template <typename T>
SiVariableTracer<T> &operator |= (SiVariableTracer<T> &lhs, SiVariableTracer<T> const &rhs) {
lhs.assign (lhs.get () | rhs.get ());
lhs.Assign (lhs.Get () | rhs.Get ());
return lhs;
}
template <typename T>
SiVariableTracer<T> &operator ^= (SiVariableTracer<T> &lhs, SiVariableTracer<T> const &rhs) {
lhs.assign (lhs.get () ^ rhs.get ());
lhs.Assign (lhs.Get () ^ rhs.Get ());
return lhs;
}
template <typename T, typename U>
SiVariableTracer<T> &operator += (SiVariableTracer<T> &lhs, U const &rhs) {
lhs.assign (lhs.get () + rhs);
lhs.Assign (lhs.Get () + rhs);
return lhs;
}
template <typename T, typename U>
SiVariableTracer<T> &operator -= (SiVariableTracer<T> &lhs, U const &rhs) {
lhs.assign (lhs.get () - rhs);
lhs.Assign (lhs.Get () - rhs);
return lhs;
}
template <typename T, typename U>
SiVariableTracer<T> &operator *= (SiVariableTracer<T> &lhs, U const &rhs) {
lhs.assign (lhs.get () * rhs);
lhs.Assign (lhs.Get () * rhs);
return lhs;
}
template <typename T, typename U>
SiVariableTracer<T> &operator /= (SiVariableTracer<T> &lhs, U const &rhs) {
lhs.assign (lhs.get () / rhs);
lhs.Assign (lhs.Get () / rhs);
return lhs;
}
template <typename T, typename U>
SiVariableTracer<T> &operator <<= (SiVariableTracer<T> &lhs, U const &rhs) {
lhs.assign (lhs.get () << rhs);
lhs.Assign (lhs.Get () << rhs);
return lhs;
}
template <typename T, typename U>
SiVariableTracer<T> &operator >>= (SiVariableTracer<T> &lhs, U const &rhs) {
lhs.assign (lhs.get () >> rhs);
lhs.Assign (lhs.Get () >> rhs);
return lhs;
}
template <typename T, typename U>
SiVariableTracer<T> &operator &= (SiVariableTracer<T> &lhs, U const &rhs) {
lhs.assign (lhs.get () & rhs);
lhs.Assign (lhs.Get () & rhs);
return lhs;
}
template <typename T, typename U>
SiVariableTracer<T> &operator |= (SiVariableTracer<T> &lhs, U const &rhs) {
lhs.assign (lhs.get () | rhs);
lhs.Assign (lhs.Get () | rhs);
return lhs;
}
template <typename T, typename U>
SiVariableTracer<T> &operator ^= (SiVariableTracer<T> &lhs, U const &rhs) {
lhs.assign (lhs.get () ^ rhs);
lhs.Assign (lhs.Get () ^ rhs);
return lhs;
}

4
src/common/stream-tracer-test.cc

@ -29,7 +29,7 @@ namespace {
class TestStreamTracer : public ns3::Test {
public:
TestStreamTracer ();
virtual bool runTests (void);
virtual bool RunTests (void);
};
static TestStreamTracer gTestStream;
@ -39,7 +39,7 @@ TestStreamTracer::TestStreamTracer ()
{}
bool
TestStreamTracer::runTests (void)
TestStreamTracer::RunTests (void)
{
bool ok = true;
ns3::StreamTracer trace;

2
src/common/stream-tracer.h

@ -60,7 +60,7 @@ public:
/**
* \param os the output stream to store
*/
void setStream (std::ostream * os) {
void SetStream (std::ostream * os) {
m_os = os;
}
private:

60
src/common/tags.cc

@ -28,13 +28,13 @@ TagRegistry::TagsData TagRegistry::m_registry;
void
TagRegistry::record (std::string uuid, PrettyPrinter prettyPrinter)
TagRegistry::Record (std::string uuid, PrettyPrinter prettyPrinter)
{
assert (!m_sorted);
m_registry.push_back (make_pair (uuid, prettyPrinter));
}
uint32_t
TagRegistry::lookupUid (std::string uuid)
TagRegistry::LookupUid (std::string uuid)
{
if (!m_sorted) {
std::sort (m_registry.begin (), m_registry.end ());
@ -55,7 +55,7 @@ TagRegistry::lookupUid (std::string uuid)
return 0;
}
void
TagRegistry::prettyPrint (uint32_t uid, uint8_t buf[Tags::SIZE], std::ostream &os)
TagRegistry::PrettyPrint (uint32_t uid, uint8_t buf[Tags::SIZE], std::ostream &os)
{
assert (m_registry.size () > uid);
PrettyPrinter prettyPrinter = m_registry[uid].second;
@ -71,7 +71,7 @@ struct Tags::TagData *Tags::gFree = 0;
uint32_t Tags::gN_free = 0;
struct Tags::TagData *
Tags::allocData (void)
Tags::AllocData (void)
{
struct Tags::TagData *retval;
if (gFree != 0) {
@ -85,7 +85,7 @@ Tags::allocData (void)
}
void
Tags::freeData (struct TagData *data)
Tags::FreeData (struct TagData *data)
{
if (gN_free > 1000) {
delete data;
@ -97,7 +97,7 @@ Tags::freeData (struct TagData *data)
}
#else
struct Tags::TagData *
Tags::allocData (void)
Tags::AllocData (void)
{
struct Tags::TagData *retval;
retval = new struct Tags::TagData ();
@ -105,14 +105,14 @@ Tags::allocData (void)
}
void
Tags::freeData (struct TagData *data)
Tags::FreeData (struct TagData *data)
{
delete data;
}
#endif
bool
Tags::remove (uint32_t id)
Tags::Remove (uint32_t id)
{
bool found = false;
for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) {
@ -135,7 +135,7 @@ Tags::remove (uint32_t id)
*/
continue;
}
struct TagData *copy = allocData ();
struct TagData *copy = AllocData ();
copy->m_id = cur->m_id;
copy->m_count = 1;
copy->m_next = 0;
@ -144,16 +144,16 @@ Tags::remove (uint32_t id)
prevNext = &copy->m_next;
}
*prevNext = 0;
removeAll ();
RemoveAll ();
m_next = start;
return true;
}
void
Tags::prettyPrint (std::ostream &os)
Tags::PrettyPrint (std::ostream &os)
{
for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) {
TagRegistry::prettyPrint (cur->m_id, cur->m_data, os);
TagRegistry::PrettyPrint (cur->m_id, cur->m_data, os);
}
}
@ -172,7 +172,7 @@ class TagsTest : Test {
public:
TagsTest ();
virtual ~TagsTest ();
virtual bool runTests (void);
virtual bool RunTests (void);
};
struct myTagA {
@ -217,7 +217,7 @@ TagsTest::~TagsTest ()
{}
bool
TagsTest::runTests (void)
TagsTest::RunTests (void)
{
bool ok = true;
@ -225,18 +225,18 @@ TagsTest::runTests (void)
Tags tags;
struct myTagA a;
a.a = 10;
tags.add (a);
tags.Add (a);
a.a = 0;
tags.peek (a);
tags.Peek (a);
if (a.a != 10) {
ok = false;
}
//tags.prettyPrint (std::cout);
struct myTagB b;
b.b = 0xff;
tags.add (b);
tags.Add (b);
b.b = 0;
tags.peek (b);
tags.Peek (b);
if (b.b != 0xff) {
ok = false;
}
@ -248,29 +248,29 @@ TagsTest::runTests (void)
//tags.prettyPrint (std::cout);
struct myTagA oA;
oA.a = 0;
other.peek (oA);
other.Peek (oA);
if (oA.a != 10) {
ok = false;
}
struct myTagB oB;
other.peek (oB);
other.Peek (oB);
if (oB.b != 0xff) {
ok = false;
}
// remove data.
other.remove (oA);
if (other.peek (oA)) {
other.Remove (oA);
if (other.Peek (oA)) {
ok = false;
}
//other.prettyPrint (std::cout);
if (!tags.peek (oA)) {
if (!tags.Peek (oA)) {
ok = false;
}
other.remove (oB);
if (other.peek (oB)) {
other.Remove (oB);
if (other.Peek (oB)) {
ok = false;
}
if (!tags.peek (oB)) {
if (!tags.Peek (oB)) {
ok = false;
}
@ -278,13 +278,13 @@ TagsTest::runTests (void)
Tags another = other;
struct myTagC c;
c.c[0] = 0x66;
another.add (c);
another.Add (c);
c.c[0] = 0;
another.peek (c);
if (!another.peek (c)) {
another.Peek (c);
if (!another.Peek (c)) {
ok = false;
}
if (tags.peek (c)) {
if (tags.Peek (c)) {
ok = false;
}

72
src/common/tags.h

@ -46,17 +46,17 @@ public:
inline ~Tags ();
template <typename T>
void add (T const&tag);
void Add (T const&tag);
template <typename T>
bool remove (T &tag);
bool Remove (T &tag);
template <typename T>
bool peek (T &tag) const;
bool Peek (T &tag) const;
void prettyPrint (std::ostream &os);
void PrettyPrint (std::ostream &os);
inline void removeAll (void);
inline void RemoveAll (void);
enum {
SIZE = TAGS_MAX_SIZE
@ -69,9 +69,9 @@ private:
uint8_t m_data[Tags::SIZE];
};
bool remove (uint32_t id);
struct Tags::TagData *allocData (void);
void freeData (struct TagData *data);
bool Remove (uint32_t id);
struct Tags::TagData *AllocData (void);
void FreeData (struct TagData *data);
static struct Tags::TagData *gFree;
static uint32_t gN_free;
@ -98,7 +98,7 @@ public:
*/
TagRegistration<T> (std::string uuid, void(*fn) (T *, std::ostream &));
private:
static void prettyPrinterCb (uint8_t *buf, std::ostream &os);
static void PrettyPrinterCb (uint8_t *buf, std::ostream &os);
static void(*m_prettyPrinter) (T *, std::ostream &);
};
@ -117,9 +117,9 @@ namespace ns3 {
class TagRegistry {
public:
typedef void (*PrettyPrinter) (uint8_t [Tags::SIZE], std::ostream &);
static void record (std::string uuid, PrettyPrinter prettyPrinter);
static uint32_t lookupUid (std::string uuid);
static void prettyPrint (uint32_t uid, uint8_t buf[Tags::SIZE], std::ostream &os);
static void Record (std::string uuid, PrettyPrinter prettyPrinter);
static uint32_t LookupUid (std::string uuid);
static void PrettyPrint (uint32_t uid, uint8_t buf[Tags::SIZE], std::ostream &os);
private:
typedef std::vector<std::pair<std::string,PrettyPrinter> > TagsData;
typedef std::vector<std::pair<std::string,PrettyPrinter> >::const_iterator TagsDataCI;
@ -137,28 +137,28 @@ private:
template <typename T>
class TypeUid {
public:
static void record (std::string uuid);
static const uint32_t getUid (void);
static void Record (std::string uuid);
static const uint32_t GetUid (void);
private:
static std::string *getUuid (void);
static std::string *GetUuid (void);
T m_realType;
};
template <typename T>
void TypeUid<T>::record (std::string uuid)
void TypeUid<T>::Record (std::string uuid)
{
*(getUuid ()) = uuid;
*(GetUuid ()) = uuid;
}
template <typename T>
const uint32_t TypeUid<T>::getUid (void)
const uint32_t TypeUid<T>::GetUid (void)
{
static const uint32_t uid = TagRegistry::lookupUid (*(getUuid ()));
static const uint32_t uid = TagRegistry::LookupUid (*(GetUuid ()));
return uid;
}
template <typename T>
std::string *TypeUid<T>::getUuid (void)
std::string *TypeUid<T>::GetUuid (void)
{
static std::string uuid;
return &uuid;
@ -177,12 +177,12 @@ TagRegistration<T>::TagRegistration (std::string uuid, void (*prettyPrinter) (T
{
assert (sizeof (T) <= Tags::SIZE);
m_prettyPrinter = prettyPrinter;
TagRegistry::record (uuid, &TagRegistration<T>::prettyPrinterCb);
TypeUid<T>::record (uuid);
TagRegistry::Record (uuid, &TagRegistration<T>::PrettyPrinterCb);
TypeUid<T>::Record (uuid);
}
template <typename T>
void
TagRegistration<T>::prettyPrinterCb (uint8_t *buf, std::ostream &os)
TagRegistration<T>::PrettyPrinterCb (uint8_t *buf, std::ostream &os)
{
assert (sizeof (T) <= Tags::SIZE);
T *tag = reinterpret_cast<T *> (buf);
@ -197,18 +197,18 @@ void (*TagRegistration<T>::m_prettyPrinter) (T *, std::ostream &) = 0;
template <typename T>
void
Tags::add (T const&tag)
Tags::Add (T const&tag)
{
assert (sizeof (T) <= Tags::SIZE);
uint8_t const*buf = reinterpret_cast<uint8_t const*> (&tag);
// ensure this id was not yet added
for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) {
assert (cur->m_id != TypeUid<T>::getUid ());
assert (cur->m_id != TypeUid<T>::GetUid ());
}
struct TagData *newStart = allocData ();
struct TagData *newStart = AllocData ();
newStart->m_count = 1;
newStart->m_next = 0;
newStart->m_id = TypeUid<T>::getUid ();
newStart->m_id = TypeUid<T>::GetUid ();
memcpy (newStart->m_data, buf, sizeof (T));
newStart->m_next = m_next;
m_next = newStart;
@ -216,20 +216,20 @@ Tags::add (T const&tag)
template <typename T>
bool
Tags::remove (T &tag)
Tags::Remove (T &tag)
{
assert (sizeof (T) <= Tags::SIZE);
return remove (TypeUid<T>::getUid ());
return Remove (TypeUid<T>::GetUid ());
}
template <typename T>
bool
Tags::peek (T &tag) const
Tags::Peek (T &tag) const
{
assert (sizeof (T) <= Tags::SIZE);
uint8_t *buf = reinterpret_cast<uint8_t *> (&tag);
for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) {
if (cur->m_id == TypeUid<T>::getUid ()) {
if (cur->m_id == TypeUid<T>::GetUid ()) {
/* found tag */
memcpy (buf, cur->m_data, sizeof (T));
return true;
@ -258,7 +258,7 @@ Tags::operator = (Tags const &o)
if (m_next == o.m_next) {
return *this;
}
removeAll ();
RemoveAll ();
m_next = o.m_next;
if (m_next != 0) {
m_next->m_count++;
@ -268,11 +268,11 @@ Tags::operator = (Tags const &o)
Tags::~Tags ()
{
removeAll ();
RemoveAll ();
}
void
Tags::removeAll (void)
Tags::RemoveAll (void)
{
struct TagData *prev = 0;
for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) {
@ -281,12 +281,12 @@ Tags::removeAll (void)
break;
}
if (prev != 0) {
freeData (prev);
FreeData (prev);
}
prev = cur;
}
if (prev != 0) {
freeData (prev);
FreeData (prev);
}
m_next = 0;
}

26
src/common/trace-container.cc

@ -36,38 +36,38 @@ TraceContainer::~TraceContainer ()
}
void
TraceContainer::setUiVariableCallback (char const *name, Callback<void,uint64_t, uint64_t> callback)
TraceContainer::SetUiVariableCallback (char const *name, Callback<void,uint64_t, uint64_t> callback)
{
for (UiListI i = m_uiList.begin (); i != m_uiList.end (); i++) {
if ((*i).second == name) {
(*i).first->setCallback (callback);
(*i).first->SetCallback (callback);
return;
}
}
assert (false);
}
void
TraceContainer::setSiVariableCallback (char const *name, Callback<void,int64_t, int64_t> callback)
TraceContainer::SetSiVariableCallback (char const *name, Callback<void,int64_t, int64_t> callback)
{
for (SiListI i = m_siList.begin (); i != m_siList.end (); i++) {
if ((*i).second == name) {
(*i).first->setCallback (callback);
(*i).first->SetCallback (callback);
return;
}
}
assert (false);
}
void
TraceContainer::setFVariableCallback (char const *name, Callback<void,double, double> callback)
TraceContainer::SetFVariableCallback (char const *name, Callback<void,double, double> callback)
{
assert (false);
}
void
TraceContainer::setStream (char const *name, std::ostream *os)
TraceContainer::SetStream (char const *name, std::ostream *os)
{
for (StreamTracerListI i = m_traceStreamList.begin (); i != m_traceStreamList.end (); i++) {
if ((*i).second == name) {
(*i).first->setStream (os);
(*i).first->SetStream (os);
return;
}
}
@ -75,7 +75,7 @@ TraceContainer::setStream (char const *name, std::ostream *os)
}
void
TraceContainer::registerUiVariable (char const *name, UiVariableTracerBase *var)
TraceContainer::RegisterUiVariable (char const *name, UiVariableTracerBase *var)
{
// ensure unicity
for (UiListI i = m_uiList.begin (); i != m_uiList.end (); i++) {
@ -87,7 +87,7 @@ TraceContainer::registerUiVariable (char const *name, UiVariableTracerBase *var)
m_uiList.push_back (std::make_pair (var, name));
}
void
TraceContainer::registerSiVariable (char const *name, SiVariableTracerBase *var)
TraceContainer::RegisterSiVariable (char const *name, SiVariableTracerBase *var)
{
// ensure unicity
for (SiListI i = m_siList.begin (); i != m_siList.end (); i++) {
@ -99,13 +99,13 @@ TraceContainer::registerSiVariable (char const *name, SiVariableTracerBase *var)
m_siList.push_back (std::make_pair (var, name));
}
void
TraceContainer::registerFVariable (char const *name, FVariableTracerBase *var)
TraceContainer::RegisterFVariable (char const *name, FVariableTracerBase *var)
{
assert (false);
}
void
TraceContainer::registerStream (char const *name, StreamTracer *stream)
TraceContainer::RegisterStream (char const *name, StreamTracer *stream)
{
// ensure unicity
for (StreamTracerListI i = m_traceStreamList.begin (); i != m_traceStreamList.end (); i++) {
@ -119,7 +119,7 @@ TraceContainer::registerStream (char const *name, StreamTracer *stream)
}
void
TraceContainer::registerCallback (char const *name, CallbackTracerBase *tracer)
TraceContainer::RegisterCallback (char const *name, CallbackTracerBase *tracer)
{
for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) {
if (i->second == name) {
@ -137,7 +137,7 @@ TraceContainer::registerCallback (char const *name, CallbackTracerBase *tracer)
#include <iostream>
void
ns3::TraceContainer::printDebug (void)
ns3::TraceContainer::PrintDebug (void)
{
if (!m_uiList.empty ()) {
std::cout << "ui var: " << std::endl;

50
src/common/trace-container.h

@ -68,7 +68,7 @@ public:
* This method targets only event sources which are variables of any unsigned
* integer type.
*/
void setUiVariableCallback (char const *name,
void SetUiVariableCallback (char const *name,
Callback<void,uint64_t, uint64_t> callback);
/**
* \param name the name of the target event source
@ -77,21 +77,21 @@ public:
* This method targets only event sources which are variables of any signed
* integer type.
*/
void setSiVariableCallback (char const *name, Callback<void,int64_t, int64_t> callback);
void SetSiVariableCallback (char const *name, Callback<void,int64_t, int64_t> callback);
/**
* \param name the name of the target event source
* \param callback the callback being connected to the target event source
*
* This method targets only event sources which are variables of any double type.
*/
void setFVariableCallback (char const *name, Callback<void,double, double> callback);
void SetFVariableCallback (char const *name, Callback<void,double, double> callback);
/**
* \param name the name of the target event source
* \param os the output stream being connected to the source trace stream
*
* This method targets only event sources which are of type StreamTracer.
*/
void setStream (char const *name, std::ostream *os);
void SetStream (char const *name, std::ostream *os);
/**
* \param name the name of the target event source
@ -100,7 +100,7 @@ public:
* This method targets only event sources which are of type CallbackTracer<T1>
*/
template <typename T1>
void setCallback (char const *name, Callback<void,T1> callback);
void SetCallback (char const *name, Callback<void,T1> callback);
/**
* \param name the name of the target event source
* \param callback the callback being connected to the target event source.
@ -108,7 +108,7 @@ public:
* This method targets only event sources which are of type CallbackTracer<T1,T2>
*/
template <typename T1, typename T2>
void setCallback (char const *name, Callback<void,T1,T2> callback);
void SetCallback (char const *name, Callback<void,T1,T2> callback);
/**
* \param name the name of the target event source
* \param callback the callback being connected to the target event source.
@ -116,7 +116,7 @@ public:
* This method targets only event sources which are of type CallbackTracer<T1,T2,T3>
*/
template <typename T1, typename T2, typename T3>
void setCallback (char const *name, Callback<void,T1,T2,T3> callback);
void SetCallback (char const *name, Callback<void,T1,T2,T3> callback);
/**
* \param name the name of the target event source
* \param callback the callback being connected to the target event source.
@ -124,7 +124,7 @@ public:
* This method targets only event sources which are of type CallbackTracer<T1,T2,T3,T4>
*/
template <typename T1, typename T2, typename T3, typename T4>
void setCallback (char const *name, Callback<void,T1,T2,T3,T4> callback);
void SetCallback (char const *name, Callback<void,T1,T2,T3,T4> callback);
/**
* \param name the name of the target event source
* \param callback the callback being connected to the target event source.
@ -132,7 +132,7 @@ public:
* This method targets only event sources which are of type CallbackTracer<T1,T2,T3,T4,T5>
*/
template <typename T1, typename T2, typename T3, typename T4, typename T5>
void setCallback (char const *name, Callback<void,T1,T2,T3,T4,T5> callback);
void SetCallback (char const *name, Callback<void,T1,T2,T3,T4,T5> callback);
/**
* \param name the name of the registered event source
@ -140,28 +140,28 @@ public:
*
* This method registers only event sources of type "unsigned integer".
*/
void registerUiVariable (char const *name, UiVariableTracerBase *var);
void RegisterUiVariable (char const *name, UiVariableTracerBase *var);
/**
* \param name the name of the registered event source
* \param var the event source being registered
*
* This method registers only event sources of type "signed integer".
*/
void registerSiVariable (char const *name, SiVariableTracerBase *var);
void RegisterSiVariable (char const *name, SiVariableTracerBase *var);
/**
* \param name the name of the registered event source
* \param var the event source being registered
*
* This method registers only event sources of type "double".
*/
void registerFVariable (char const *name, FVariableTracerBase *var);
void RegisterFVariable (char const *name, FVariableTracerBase *var);
/**
* \param name the name of the registered event source
* \param stream the event source being registered
*
* This method registers only event sources of type StreamTracer.
*/
void registerStream (char const *name, StreamTracer *stream);
void RegisterStream (char const *name, StreamTracer *stream);
/**
* \param name the name of the registeref event source
@ -169,12 +169,12 @@ public:
*
* This method registers only event sources of type CallbackTracer
*/
void registerCallback (char const *name, CallbackTracerBase*tracer);
void RegisterCallback (char const *name, CallbackTracerBase*tracer);
/**
* Print the list of registered event sources in this container only.
*/
void printDebug (void);
void PrintDebug (void);
private:
typedef std::list<std::pair<UiVariableTracerBase *, std::string> > UiList;
typedef std::list<std::pair<UiVariableTracerBase *, std::string> >::iterator UiListI;
@ -204,11 +204,11 @@ namespace ns3 {
template <typename T1>
void
TraceContainer::setCallback (char const *name, Callback<void,T1> callback)
TraceContainer::SetCallback (char const *name, Callback<void,T1> callback)
{
for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) {
if (i->second == name) {
static_cast<CallbackTracer<T1> *> (i->first)->setCallback (callback);
static_cast<CallbackTracer<T1> *> (i->first)->SetCallback (callback);
return;
}
}
@ -218,11 +218,11 @@ TraceContainer::setCallback (char const *name, Callback<void,T1> callback)
}
template <typename T1, typename T2>
void
TraceContainer::setCallback (char const *name, Callback<void,T1,T2> callback)
TraceContainer::SetCallback (char const *name, Callback<void,T1,T2> callback)
{
for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) {
if (i->second == name) {
static_cast<CallbackTracer<T1,T2> *> (i->first)->setCallback (callback);
static_cast<CallbackTracer<T1,T2> *> (i->first)->SetCallback (callback);
return;
}
}
@ -232,11 +232,11 @@ TraceContainer::setCallback (char const *name, Callback<void,T1,T2> callback)
}
template <typename T1, typename T2, typename T3>
void
TraceContainer::setCallback (char const *name, Callback<void,T1,T2,T3> callback)
TraceContainer::SetCallback (char const *name, Callback<void,T1,T2,T3> callback)
{
for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) {
if (i->second == name) {
static_cast<CallbackTracer<T1,T2,T3> *> (i->first)->setCallback (callback);
static_cast<CallbackTracer<T1,T2,T3> *> (i->first)->SetCallback (callback);
return;
}
}
@ -246,11 +246,11 @@ TraceContainer::setCallback (char const *name, Callback<void,T1,T2,T3> callback)
}
template <typename T1, typename T2, typename T3, typename T4>
void
TraceContainer::setCallback (char const *name, Callback<void,T1,T2,T3,T4> callback)
TraceContainer::SetCallback (char const *name, Callback<void,T1,T2,T3,T4> callback)
{
for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) {
if (i->second == name) {
static_cast<CallbackTracer<T1,T2,T3,T4> *> (i->first)->setCallback (callback);
static_cast<CallbackTracer<T1,T2,T3,T4> *> (i->first)->SetCallback (callback);
return;
}
}
@ -260,11 +260,11 @@ TraceContainer::setCallback (char const *name, Callback<void,T1,T2,T3,T4> callba
}
template <typename T1, typename T2, typename T3, typename T4, typename T5>
void
TraceContainer::setCallback (char const *name, Callback<void,T1,T2,T3,T4,T5> callback)
TraceContainer::SetCallback (char const *name, Callback<void,T1,T2,T3,T4,T5> callback)
{
for (CallbackListI i = m_callbackList.begin (); i != m_callbackList.end (); i++) {
if (i->second == name) {
static_cast<CallbackTracer<T1,T2,T3,T4,T5> *> (i->first)->setCallback (callback);
static_cast<CallbackTracer<T1,T2,T3,T4,T5> *> (i->first)->SetCallback (callback);
return;
}
}

20
src/common/trailer.cc

@ -28,28 +28,28 @@ Trailer::Trailer ()
: m_isDeserialized (false) {}
void
Trailer::print (std::ostream &os) const
Trailer::Print (std::ostream &os) const
{
printTo (os);
PrintTo (os);
}
uint32_t
Trailer::getSize (void) const
Trailer::GetSize (void) const
{
return getSerializedSize ();
return GetSerializedSize ();
}
void
Trailer::serialize (Buffer::Iterator start) const
Trailer::Serialize (Buffer::Iterator start) const
{
serializeTo (start);
SerializeTo (start);
}
void
Trailer::deserialize (Buffer::Iterator start)
Trailer::Deserialize (Buffer::Iterator start)
{
deserializeFrom (start);
DeserializeFrom (start);
m_isDeserialized = true;
}
bool
Trailer::isDeserialized (void) const
Trailer::IsDeserialized (void) const
{
return m_isDeserialized;
}
@ -61,7 +61,7 @@ Trailer::~Trailer ()
std::ostream& operator<< (std::ostream& os, Trailer const& trailer)
{
trailer.print (os);
trailer.Print (os);
return os;
}

26
src/common/trailer.h

@ -34,10 +34,10 @@ namespace ns3 {
* Every Protocol trailer which needs to be inserted and removed
* from a Packet instance must derive from this abstract base class
* and implement the private pure virtual methods listed below:
* - ns3::Trailer::serializeTo
* - ns3::Trailer::deserializeFrom
* - ns3::Trailer::getSerializedSize
* - ns3::Trailer::printTo
* - ns3::Trailer::SerializeTo
* - ns3::Trailer::DeserializeFrom
* - ns3::Trailer::GetSerializedSize
* - ns3::Trailer::PrintTo
*/
class Trailer {
public:
@ -47,34 +47,34 @@ public:
*/
virtual ~Trailer () = 0;
void print (std::ostream &os) const;
uint32_t getSize (void) const;
void serialize (Buffer::Iterator start) const;
void deserialize (Buffer::Iterator start);
bool isDeserialized (void) const;
void Print (std::ostream &os) const;
uint32_t GetSize (void) const;
void Serialize (Buffer::Iterator start) const;
void Deserialize (Buffer::Iterator start);
bool IsDeserialized (void) const;
private:
bool m_isDeserialized;
/**
* \param os the std output stream in which this
* protocol trailer must print itself.
*/
virtual void printTo (std::ostream &os) const = 0;
virtual void PrintTo (std::ostream &os) const = 0;
/**
* \returns the size of the serialized Trailer.
*/
virtual uint32_t getSerializedSize (void) const = 0;
virtual uint32_t GetSerializedSize (void) const = 0;
/**
* \param start the buffer iterator in which the protocol trailer
* must serialize itself.
*/
virtual void serializeTo (Buffer::Iterator start) const = 0;
virtual void SerializeTo (Buffer::Iterator start) const = 0;
/**
* \param start the buffer iterator from which the protocol trailer must
* deserialize itself.
*/
virtual void deserializeFrom (Buffer::Iterator start) = 0;
virtual void DeserializeFrom (Buffer::Iterator start) = 0;
};
std::ostream& operator<< (std::ostream& os, Trailer const& trailer);

60
src/common/ui-variable-tracer.h

@ -42,12 +42,12 @@ public:
}
~UiVariableTracerBase () {}
void setCallback(ChangeNotifyCallback callback) {
void SetCallback(ChangeNotifyCallback callback) {
m_callback = callback;
}
protected:
void notify (uint64_t oldVal, uint64_t newVal) {
if (oldVal != newVal && !m_callback.isNull ()) {
void Notify (uint64_t oldVal, uint64_t newVal) {
if (oldVal != newVal && !m_callback.IsNull ()) {
m_callback (oldVal, newVal);
}
}
@ -93,25 +93,25 @@ public:
{}
UiVariableTracer &operator = (UiVariableTracer const &o) {
assign (o.get ());
Assign (o.Get ());
return *this;
}
template <typename TT>
UiVariableTracer &operator = (UiVariableTracer<TT> const &o) {
assign (o.get ());
Assign (o.Get ());
return *this;
}
template <typename TT>
UiVariableTracer &operator = (SiVariableTracer<TT> const &o) {
assign (o.get ());
Assign (o.Get ());
return *this;
}
UiVariableTracer &operator++ () {
assign (get () + 1);
Assign (Get () + 1);
return *this;
}
UiVariableTracer &operator-- () {
assign (get () - 1);
Assign (Get () - 1);
return *this;
}
UiVariableTracer operator++ (int) {
@ -125,15 +125,15 @@ public:
return old;
}
operator T () const {
return get ();
return Get ();
}
void assign (T var) {
notify (m_var, var);
void Assign (T var) {
Notify (m_var, var);
m_var = var;
}
T get (void) const {
T Get (void) const {
return m_var;
}
@ -143,94 +143,94 @@ private:
template <typename T>
UiVariableTracer<T> &operator += (UiVariableTracer<T> &lhs, UiVariableTracer<T> const &rhs) {
lhs.assign (lhs.get () + rhs.get ());
lhs.Assign (lhs.Get () + rhs.Get ());
return lhs;
}
template <typename T>
UiVariableTracer<T> &operator -= (UiVariableTracer<T> &lhs, UiVariableTracer<T> const &rhs) {
lhs.assign (lhs.get () - rhs.get ());
lhs.Assign (lhs.Get () - rhs.Get ());
return lhs;
}
template <typename T>
UiVariableTracer<T> &operator *= (UiVariableTracer<T> &lhs, UiVariableTracer<T> const &rhs) {
lhs.assign (lhs.get () * rhs.get ());
lhs.Assign (lhs.Get () * rhs.Get ());
return lhs;
}
template <typename T>
UiVariableTracer<T> &operator /= (UiVariableTracer<T> &lhs, UiVariableTracer<T> const &rhs) {
lhs.assign (lhs.get () / rhs.get ());
lhs.Assign (lhs.Get () / rhs.Get ());
return lhs;
}
template <typename T>
UiVariableTracer<T> &operator <<= (UiVariableTracer<T> &lhs, UiVariableTracer<T> const &rhs) {
lhs.assign (lhs.get () << rhs.get ());
lhs.Assign (lhs.Get () << rhs.Get ());
return lhs;
}
template <typename T>
UiVariableTracer<T> &operator >>= (UiVariableTracer<T> &lhs, UiVariableTracer<T> const &rhs) {
lhs.assign (lhs.get () >> rhs.get ());
lhs.Assign (lhs.Get () >> rhs.Get ());
return lhs;
}
template <typename T>
UiVariableTracer<T> &operator &= (UiVariableTracer<T> &lhs, UiVariableTracer<T> const &rhs) {
lhs.assign (lhs.get () & rhs.get ());
lhs.Assign (lhs.Get () & rhs.Get ());
return lhs;
}
template <typename T>
UiVariableTracer<T> &operator |= (UiVariableTracer<T> &lhs, UiVariableTracer<T> const &rhs) {
lhs.assign (lhs.get () | rhs.get ());
lhs.Assign (lhs.Get () | rhs.Get ());
return lhs;
}
template <typename T>
UiVariableTracer<T> &operator ^= (UiVariableTracer<T> &lhs, UiVariableTracer<T> const &rhs) {
lhs.assign (lhs.get () ^ rhs.get ());
lhs.Assign (lhs.Get () ^ rhs.Get ());
return lhs;
}
template <typename T, typename U>
UiVariableTracer<T> &operator += (UiVariableTracer<T> &lhs, U const &rhs) {
lhs.assign (lhs.get () + rhs);
lhs.Assign (lhs.Get () + rhs);
return lhs;
}
template <typename T, typename U>
UiVariableTracer<T> &operator -= (UiVariableTracer<T> &lhs, U const &rhs) {
lhs.assign (lhs.get () - rhs);
lhs.Assign (lhs.Get () - rhs);
return lhs;
}
template <typename T, typename U>
UiVariableTracer<T> &operator *= (UiVariableTracer<T> &lhs, U const &rhs) {
lhs.assign (lhs.get () * rhs);
lhs.Assign (lhs.Get () * rhs);
return lhs;
}
template <typename T, typename U>
UiVariableTracer<T> &operator /= (UiVariableTracer<T> &lhs, U const &rhs) {
lhs.assign (lhs.get () / rhs);
lhs.Assign (lhs.Get () / rhs);
return lhs;
}
template <typename T, typename U>
UiVariableTracer<T> &operator <<= (UiVariableTracer<T> &lhs, U const &rhs) {
lhs.assign (lhs.get () << rhs);
lhs.Assign (lhs.Get () << rhs);
return lhs;
}
template <typename T, typename U>
UiVariableTracer<T> &operator >>= (UiVariableTracer<T> &lhs, U const &rhs) {
lhs.assign (lhs.get () >> rhs);
lhs.Assign (lhs.Get () >> rhs);
return lhs;
}
template <typename T, typename U>
UiVariableTracer<T> &operator &= (UiVariableTracer<T> &lhs, U const &rhs) {
lhs.assign (lhs.get () & rhs);
lhs.Assign (lhs.Get () & rhs);
return lhs;
}
template <typename T, typename U>
UiVariableTracer<T> &operator |= (UiVariableTracer<T> &lhs, U const &rhs) {
lhs.assign (lhs.get () | rhs);
lhs.Assign (lhs.Get () | rhs);
return lhs;
}
template <typename T, typename U>
UiVariableTracer<T> &operator ^= (UiVariableTracer<T> &lhs, U const &rhs) {
lhs.assign (lhs.get () ^ rhs);
lhs.Assign (lhs.Get () ^ rhs);
return lhs;
}

20
src/common/variable-tracer-test.cc

@ -29,24 +29,24 @@ namespace ns3 {
class Foo {
public:
void notify (uint64_t oldVal, uint64_t newVal) {}
void Notify (uint64_t oldVal, uint64_t newVal) {}
};
class VariableTracerTest: public Test {
public:
VariableTracerTest ();
void runUnsignedTests (void);
void runSignedUnsignedTests (void);
virtual bool runTests (void);
void RunUnsignedTests (void);
void RunSignedUnsignedTests (void);
virtual bool RunTests (void);
};
void
VariableTracerTest::runUnsignedTests (void)
VariableTracerTest::RunUnsignedTests (void)
{
UiVariableTracer<uint32_t> var, ovar, tmp;
uint32_t utmp;
Foo *foo = new Foo ();
var.setCallback (makeCallback (&Foo::notify, foo));
var.SetCallback (MakeCallback (&Foo::Notify, foo));
var = 10;
ovar = var;
@ -198,7 +198,7 @@ VariableTracerTest::runUnsignedTests (void)
}
void
VariableTracerTest::runSignedUnsignedTests (void)
VariableTracerTest::RunSignedUnsignedTests (void)
{
unsigned short utmp = 10;
unsigned int uitmp = 7;
@ -234,10 +234,10 @@ VariableTracerTest::runSignedUnsignedTests (void)
}
bool
VariableTracerTest::runTests (void)
VariableTracerTest::RunTests (void)
{
runUnsignedTests ();
runSignedUnsignedTests ();
RunUnsignedTests ();
RunSignedUnsignedTests ();
return true;
}

74
src/core/callback-test.cc

@ -31,17 +31,17 @@ static bool gTest5 = false;
static bool gTest6 = false;
static bool gTest7 = false;
void test5 (void)
void Test5 (void)
{
gTest5 = true;
}
void test6 (int)
void Test6 (int)
{
gTest6 = true;
}
int test7 (int a)
int Test7 (int a)
{
gTest7 = true;
return a;
@ -55,14 +55,14 @@ private:
bool m_test4;
public:
CallbackTest ();
virtual bool runTests (void);
void reset (void);
bool isWrong (void);
void test1 (void);
int test2 (void);
void test3 (double a);
int test4 (double a, int b);
void test8 (Callback<void, int> callback);
virtual bool RunTests (void);
void Reset (void);
bool IsWrong (void);
void Test1 (void);
int Test2 (void);
void Test3 (double a);
int Test4 (double a, int b);
void Test8 (Callback<void, int> callback);
};
CallbackTest::CallbackTest ()
@ -74,34 +74,34 @@ CallbackTest::CallbackTest ()
{}
void
CallbackTest::test1 (void)
CallbackTest::Test1 (void)
{
m_test1 = true;
}
int
CallbackTest::test2 (void)
CallbackTest::Test2 (void)
{
m_test2 = true;
return 2;
}
void
CallbackTest::test3 (double a)
CallbackTest::Test3 (double a)
{
m_test3 = true;
}
int
CallbackTest::test4 (double a, int b)
CallbackTest::Test4 (double a, int b)
{
m_test4 = true;
return 4;
}
void
CallbackTest::test8 (Callback<void,int> callback)
CallbackTest::Test8 (Callback<void,int> callback)
{
callback (3);
}
bool
CallbackTest::isWrong (void)
CallbackTest::IsWrong (void)
{
if (!m_test1 ||
!m_test2 ||
@ -116,7 +116,7 @@ CallbackTest::isWrong (void)
}
void
CallbackTest::reset (void)
CallbackTest::Reset (void)
{
m_test1 = false;
m_test2 = false;
@ -129,7 +129,7 @@ CallbackTest::reset (void)
bool
CallbackTest::runTests (void)
CallbackTest::RunTests (void)
{
bool ok = true;
@ -141,14 +141,14 @@ CallbackTest::runTests (void)
typedef ns3::Callback<void,int> F;
typedef ns3::Callback<int,int> G;
A a0 (this, &CallbackTest::test1);
A a0 (this, &CallbackTest::Test1);
B b0;
b0 = B (this, &CallbackTest::test2);
C c0 = C (this, &CallbackTest::test3);
D d0 = D (this, &CallbackTest::test4);
E e0 = E (&test5);
F f0 = F (&test6);
G g0 = G (&test7);
b0 = B (this, &CallbackTest::Test2);
C c0 = C (this, &CallbackTest::Test3);
D d0 = D (this, &CallbackTest::Test4);
E e0 = E (&Test5);
F f0 = F (&Test6);
G g0 = G (&Test7);
a0 ();
b0 ();
@ -158,19 +158,19 @@ CallbackTest::runTests (void)
f0 (1);
g0 (1);
if (isWrong ()) {
if (IsWrong ()) {
ok = false;
}
reset ();
Reset ();
A a1 = ns3::makeCallback (&CallbackTest::test1, this);
B b1 = ns3::makeCallback (&CallbackTest::test2, this);
C c1 = ns3::makeCallback (&CallbackTest::test3, this);
D d1 = ns3::makeCallback (&CallbackTest::test4, this);
E e1 = ns3::makeCallback (&test5);
F f1 = ns3::makeCallback (&test6);
G g1 = ns3::makeCallback (&test7);
A a1 = ns3::MakeCallback (&CallbackTest::Test1, this);
B b1 = ns3::MakeCallback (&CallbackTest::Test2, this);
C c1 = ns3::MakeCallback (&CallbackTest::Test3, this);
D d1 = ns3::MakeCallback (&CallbackTest::Test4, this);
E e1 = ns3::MakeCallback (&Test5);
F f1 = ns3::MakeCallback (&Test6);
G g1 = ns3::MakeCallback (&Test7);
a1 ();
b1 ();
@ -180,11 +180,11 @@ CallbackTest::runTests (void)
f1 (1);
g1 (2);
test8 (f1);
Test8 (f1);
Callback<void, int64_t,int64_t> a2;
if (isWrong ()) {
if (IsWrong ()) {
ok = false;
}
return ok;

102
src/core/callback.h

@ -181,14 +181,14 @@ private:
* - the sixth optional template argument represents
* the type of the fifth argument to the callback.
*
* Callback instances are built with the \ref makeCallback
* Callback instances are built with the \ref MakeCallback
* template functions. Callback instances have POD semantics:
* the memory they allocate is managed automatically, without
* user intervention which allows you to pass around Callback
* instances by value.
*
* Sample code which shows how to use this class template
* as well as the function templates \ref makeCallback :
* as well as the function templates \ref MakeCallback :
* \include samples/main-callback.cc
*/
template<typename R,
@ -211,40 +211,40 @@ public:
: m_impl (impl)
{}
bool isNull (void) {
return (m_impl.get () == 0)?true:false;
bool IsNull (void) {
return (m_impl.Get () == 0)?true:false;
}
Callback () : m_impl () {}
R operator() (void) {
return (*(m_impl.get ())) ();
return (*(m_impl.Get ())) ();
}
R operator() (T1 a1) {
return (*(m_impl.get ())) (a1);
return (*(m_impl.Get ())) (a1);
}
R operator() (T1 a1, T2 a2) {
return (*(m_impl).get ()) (a1,a2);
return (*(m_impl).Get ()) (a1,a2);
}
R operator() (T1 a1, T2 a2, T3 a3) {
return (*(m_impl).get ()) (a1,a2,a3);
return (*(m_impl).Get ()) (a1,a2,a3);
}
R operator() (T1 a1, T2 a2, T3 a3, T4 a4) {
return (*(m_impl).get ()) (a1,a2,a3,a4);
return (*(m_impl).Get ()) (a1,a2,a3,a4);
}
R operator() (T1 a1, T2 a2, T3 a3, T4 a4,T5 a5) {
return (*(m_impl).get ()) (a1,a2,a3,a4,a5);
return (*(m_impl).Get ()) (a1,a2,a3,a4,a5);
}
private:
ReferenceList<CallbackImpl<R,T1,T2,T3,T4,T5>*> m_impl;
};
/**
* \defgroup makeCallback makeCallback
* \defgroup MakeCallback MakeCallback
*
*/
/**
* \ingroup makeCallback
* \ingroup MakeCallback
* \param mem_ptr class method member pointer
* \param objPtr class instance
* \return a wrapper Callback
@ -252,11 +252,11 @@ private:
* and potentially return a value.
*/
template <typename OBJ, typename R>
Callback<R> makeCallback (R (OBJ::*mem_ptr) (), OBJ *const objPtr) {
Callback<R> MakeCallback (R (OBJ::*mem_ptr) (), OBJ *const objPtr) {
return Callback<R> (objPtr, mem_ptr);
}
/**
* \ingroup makeCallback
* \ingroup MakeCallback
* \param mem_ptr class method member pointer
* \param objPtr class instance
* \return a wrapper Callback
@ -264,11 +264,11 @@ Callback<R> makeCallback (R (OBJ::*mem_ptr) (), OBJ *const objPtr) {
* and potentially return a value.
*/
template <typename OBJ, typename R, typename T1>
Callback<R,T1> makeCallback (R (OBJ::*mem_ptr) (T1), OBJ *const objPtr) {
Callback<R,T1> MakeCallback (R (OBJ::*mem_ptr) (T1), OBJ *const objPtr) {
return Callback<R,T1> (objPtr, mem_ptr);
}
/**
* \ingroup makeCallback
* \ingroup MakeCallback
* \param mem_ptr class method member pointer
* \param objPtr class instance
* \return a wrapper Callback
@ -276,11 +276,11 @@ Callback<R,T1> makeCallback (R (OBJ::*mem_ptr) (T1), OBJ *const objPtr) {
* and potentially return a value.
*/
template <typename OBJ, typename R, typename T1, typename T2>
Callback<R,T1,T2> makeCallback (R (OBJ::*mem_ptr) (T1,T2), OBJ *const objPtr) {
Callback<R,T1,T2> MakeCallback (R (OBJ::*mem_ptr) (T1,T2), OBJ *const objPtr) {
return Callback<R,T1,T2> (objPtr, mem_ptr);
}
/**
* \ingroup makeCallback
* \ingroup MakeCallback
* \param mem_ptr class method member pointer
* \param objPtr class instance
* \return a wrapper Callback
@ -288,11 +288,11 @@ Callback<R,T1,T2> makeCallback (R (OBJ::*mem_ptr) (T1,T2), OBJ *const objPtr) {
* and potentially return a value.
*/
template <typename OBJ, typename R, typename T1,typename T2, typename T3>
Callback<R,T1,T2,T3> makeCallback (R (OBJ::*mem_ptr) (T1,T2,T3), OBJ *const objPtr) {
Callback<R,T1,T2,T3> MakeCallback (R (OBJ::*mem_ptr) (T1,T2,T3), OBJ *const objPtr) {
return Callback<R,T1,T2,T3> (objPtr, mem_ptr);
}
/**
* \ingroup makeCallback
* \ingroup MakeCallback
* \param mem_ptr class method member pointer
* \param objPtr class instance
* \return a wrapper Callback
@ -300,11 +300,11 @@ Callback<R,T1,T2,T3> makeCallback (R (OBJ::*mem_ptr) (T1,T2,T3), OBJ *const objP
* and potentially return a value.
*/
template <typename OBJ, typename R, typename T1, typename T2, typename T3, typename T4>
Callback<R,T1,T2,T3,T4> makeCallback (R (OBJ::*mem_ptr) (T1,T2,T3,T4), OBJ *const objPtr) {
Callback<R,T1,T2,T3,T4> MakeCallback (R (OBJ::*mem_ptr) (T1,T2,T3,T4), OBJ *const objPtr) {
return Callback<R,T1,T2,T3,T4> (objPtr, mem_ptr);
}
/**
* \ingroup makeCallback
* \ingroup MakeCallback
* \param mem_ptr class method member pointer
* \param objPtr class instance
* \return a wrapper Callback
@ -312,137 +312,137 @@ Callback<R,T1,T2,T3,T4> makeCallback (R (OBJ::*mem_ptr) (T1,T2,T3,T4), OBJ *cons
* and potentially return a value.
*/
template <typename OBJ, typename R, typename T1, typename T2, typename T3, typename T4,typename T5>
Callback<R,T1,T2,T3,T4,T5> makeCallback (R (OBJ::*mem_ptr) (T1,T2,T3,T4,T5), OBJ *const objPtr) {
Callback<R,T1,T2,T3,T4,T5> MakeCallback (R (OBJ::*mem_ptr) (T1,T2,T3,T4,T5), OBJ *const objPtr) {
return Callback<R,T1,T2,T3,T4,T5> (objPtr, mem_ptr);
}
/**
* \ingroup makeCallback
* \ingroup MakeCallback
* \param fnPtr function pointer
* \return a wrapper Callback
* Build Callbacks for functions which takes no arguments
* and potentially return a value.
*/
template <typename R>
Callback<R> makeCallback (R (*fnPtr) ()) {
Callback<R> MakeCallback (R (*fnPtr) ()) {
return Callback<R> (fnPtr);
}
/**
* \ingroup makeCallback
* \ingroup MakeCallback
* \param fnPtr function pointer
* \return a wrapper Callback
* Build Callbacks for functions which takes one argument
* and potentially return a value.
*/
template <typename R, typename T1>
Callback<R,T1> makeCallback (R (*fnPtr) (T1)) {
Callback<R,T1> MakeCallback (R (*fnPtr) (T1)) {
return Callback<R,T1> (fnPtr);
}
/**
* \ingroup makeCallback
* \ingroup MakeCallback
* \param fnPtr function pointer
* \return a wrapper Callback
* Build Callbacks for functions which takes two arguments
* and potentially return a value.
*/
template <typename R, typename T1, typename T2>
Callback<R,T1,T2> makeCallback (R (*fnPtr) (T1,T2)) {
Callback<R,T1,T2> MakeCallback (R (*fnPtr) (T1,T2)) {
return Callback<R,T1,T2> (fnPtr);
}
/**
* \ingroup makeCallback
* \ingroup MakeCallback
* \param fnPtr function pointer
* \return a wrapper Callback
* Build Callbacks for functions which takes three arguments
* and potentially return a value.
*/
template <typename R, typename T1, typename T2,typename T3>
Callback<R,T1,T2,T3> makeCallback (R (*fnPtr) (T1,T2,T3)) {
Callback<R,T1,T2,T3> MakeCallback (R (*fnPtr) (T1,T2,T3)) {
return Callback<R,T1,T2,T3> (fnPtr);
}
/**
* \ingroup makeCallback
* \ingroup MakeCallback
* \param fnPtr function pointer
* \return a wrapper Callback
* Build Callbacks for functions which takes four arguments
* and potentially return a value.
*/
template <typename R, typename T1, typename T2,typename T3,typename T4>
Callback<R,T1,T2,T3,T4> makeCallback (R (*fnPtr) (T1,T2,T3,T4)) {
Callback<R,T1,T2,T3,T4> MakeCallback (R (*fnPtr) (T1,T2,T3,T4)) {
return Callback<R,T1,T2,T3,T4> (fnPtr);
}
/**
* \ingroup makeCallback
* \ingroup MakeCallback
* \param fnPtr function pointer
* \return a wrapper Callback
* Build Callbacks for functions which takes five arguments
* and potentially return a value.
*/
template <typename R, typename T1, typename T2,typename T3,typename T4,typename T5>
Callback<R,T1,T2,T3,T4,T5> makeCallback (R (*fnPtr) (T1,T2,T3,T4,T5)) {
Callback<R,T1,T2,T3,T4,T5> MakeCallback (R (*fnPtr) (T1,T2,T3,T4,T5)) {
return Callback<R,T1,T2,T3,T4,T5> (fnPtr);
}
/**
* \ingroup makeCallback
* \ingroup MakeCallback
* \return a wrapper Callback
* Build a null callback which takes no arguments
* and potentially return a value.
*/
template <typename R>
Callback<R> makeNullCallback (void) {
Callback<R> MakeNullCallback (void) {
return Callback<R> ();
}
/**
* \ingroup makeCallback
* \ingroup MakeCallback
* \return a wrapper Callback
* Build a null callback which takes one argument
* and potentially return a value.
*/
template <typename R, typename T1>
Callback<R,T1> makeNullCallback (void) {
Callback<R,T1> MakeNullCallback (void) {
return Callback<R,T1> ();
}
/**
* \ingroup makeCallback
* \ingroup MakeCallback
* \return a wrapper Callback
* Build a null callback which takes two arguments
* and potentially return a value.
*/
template <typename R, typename T1, typename T2>
Callback<R,T1,T2> makeNullCallback (void) {
Callback<R,T1,T2> MakeNullCallback (void) {
return Callback<R,T1,T2> ();
}
/**
* \ingroup makeCallback
* \ingroup MakeCallback
* \return a wrapper Callback
* Build a null callback which takes three arguments
* and potentially return a value.
*/
template <typename R, typename T1, typename T2,typename T3>
Callback<R,T1,T2,T3> makeNullCallback (void) {
Callback<R,T1,T2,T3> MakeNullCallback (void) {
return Callback<R,T1,T2,T3> ();
}
/**
* \ingroup makeCallback
* \ingroup MakeCallback
* \return a wrapper Callback
* Build a null callback which takes four arguments
* and potentially return a value.
*/
template <typename R, typename T1, typename T2,typename T3,typename T4>
Callback<R,T1,T2,T3,T4> makeNullCallback (void) {
Callback<R,T1,T2,T3,T4> MakeNullCallback (void) {
return Callback<R,T1,T2,T3,T4> ();
}
/**
* \ingroup makeCallback
* \ingroup MakeCallback
* \return a wrapper Callback
* Build a null callback which takes five arguments
* and potentially return a value.
*/
template <typename R, typename T1, typename T2,typename T3,typename T4,typename T5>
Callback<R,T1,T2,T3,T4,T5> makeNullCallback (void) {
Callback<R,T1,T2,T3,T4,T5> MakeNullCallback (void) {
return Callback<R,T1,T2,T3,T4,T5> ();
}
@ -483,7 +483,7 @@ private:
};
template <typename R, typename TX, typename T1>
Callback<R,T1> makeBoundCallback (R (*fnPtr) (TX,T1), TX a) {
Callback<R,T1> MakeBoundCallback (R (*fnPtr) (TX,T1), TX a) {
ReferenceList<CallbackImpl<R,T1,empty,empty,empty,empty>*> impl =
ReferenceList<CallbackImpl<R,T1,empty,empty,empty,empty>*> (
new BoundFunctorCallbackImpl<R (*) (TX,T1),R,TX,T1,empty,empty,empty,empty> (fnPtr, a)
@ -491,7 +491,7 @@ Callback<R,T1> makeBoundCallback (R (*fnPtr) (TX,T1), TX a) {
return Callback<R,T1> (impl);
}
template <typename R, typename TX, typename T1, typename T2>
Callback<R,T1,T2> makeBoundCallback (R (*fnPtr) (TX,T1,T2), TX a) {
Callback<R,T1,T2> MakeBoundCallback (R (*fnPtr) (TX,T1,T2), TX a) {
ReferenceList<CallbackImpl<R,T1,T2,empty,empty,empty>*> impl =
ReferenceList<CallbackImpl<R,T1,T2,empty,empty,empty>*> (
new BoundFunctorCallbackImpl<R (*) (TX,T1,T2),R,TX,T1,T2,empty,empty,empty> (fnPtr, a)
@ -499,7 +499,7 @@ Callback<R,T1,T2> makeBoundCallback (R (*fnPtr) (TX,T1,T2), TX a) {
return Callback<R,T1,T2> (impl);
}
template <typename R, typename TX, typename T1, typename T2,typename T3,typename T4>
Callback<R,T1,T2,T3,T4> makeBoundCallback (R (*fnPtr) (TX,T1,T2,T3,T4), TX a) {
Callback<R,T1,T2,T3,T4> MakeBoundCallback (R (*fnPtr) (TX,T1,T2,T3,T4), TX a) {
ReferenceList<CallbackImpl<R,T1,T2,T3,T4,empty>*> impl =
ReferenceList<CallbackImpl<R,T1,T2,T3,T4,empty>*> (
new BoundFunctorCallbackImpl<R (*) (TX,T1,T2,T3,T4),R,TX,T1,T2,T3,T4,empty> (fnPtr, a)
@ -508,7 +508,7 @@ Callback<R,T1,T2,T3,T4> makeBoundCallback (R (*fnPtr) (TX,T1,T2,T3,T4), TX a) {
}
template <typename R, typename TX, typename T1, typename T2,typename T3,typename T4,typename T5>
Callback<R,T1,T2,T3,T4,T5> makeBoundCallback (R (*fnPtr) (TX,T1,T2,T3,T4,T5), TX a) {
Callback<R,T1,T2,T3,T4,T5> MakeBoundCallback (R (*fnPtr) (TX,T1,T2,T3,T4,T5), TX a) {
ReferenceList<CallbackImpl<R,T1,T2,T3,T4,T5>*> impl =
ReferenceList<CallbackImpl<R,T1,T2,T3,T4,T5>*> (
new BoundFunctorCallbackImpl<R (*) (TX,T1,T2,T3,T4,T5),R,TX,T1,T2,T3,T4,T5> (fnPtr, a)

22
src/core/reference-list-test.cc

@ -43,7 +43,7 @@ public:
~A () {
TRACE ("destructor");
}
void trace (void) {
void Trace (void) {
TRACE ("trace");
}
};
@ -51,9 +51,9 @@ public:
class RefTest : public ns3::Test {
public:
RefTest ();
virtual bool runTests (void);
virtual bool RunTests (void);
private:
void test (ns3::ReferenceList<A *>);
void OneTest (ns3::ReferenceList<A *>);
};
RefTest::RefTest ()
@ -61,13 +61,13 @@ RefTest::RefTest ()
{}
void
RefTest::test (ns3::ReferenceList<A *> a)
RefTest::OneTest (ns3::ReferenceList<A *> a)
{
a->trace ();
a->Trace ();
}
bool
RefTest::runTests (void)
RefTest::RunTests (void)
{
bool ok = true;
@ -76,14 +76,14 @@ RefTest::runTests (void)
{
ns3::ReferenceList<A *> a (new A ());
test (a);
OneTest (a);
tmp = a;
test (tmp);
OneTest (tmp);
a = tmp;
test (a);
OneTest (a);
TRACE ("leave inner scope");
}
test (tmp);
OneTest (tmp);
TRACE ("leave outer scope");
}
@ -97,7 +97,7 @@ RefTest::runTests (void)
{
ns3::ReferenceList<A *> tmp;
tmp.set (new A ());
tmp.Set (new A ());
}
{

20
src/core/reference-list.h

@ -52,7 +52,7 @@ public:
{
m_prev = this;
m_next = this;
insertSelfInOther (o);
InsertSelfInOther (o);
}
ReferenceList (ReferenceList const&o)
: m_objPtr (),
@ -61,7 +61,7 @@ public:
{
m_prev = this;
m_next = this;
insertSelfInOther (o);
InsertSelfInOther (o);
}
ReferenceList (OBJ_PTR const &objPtr)
: m_objPtr (objPtr),
@ -72,33 +72,33 @@ public:
m_next = this;
}
~ReferenceList () {
removeFrom_list ();
RemoveFromList ();
}
ReferenceList & operator= (ReferenceList const&o) {
removeFrom_list ();
insertSelfInOther (o);
RemoveFromList ();
InsertSelfInOther (o);
return *this;
}
OBJ_PTR operator-> () {
return m_objPtr;
}
void set (OBJ_PTR objPtr) {
removeFrom_list ();
void Set (OBJ_PTR objPtr) {
RemoveFromList ();
m_objPtr = objPtr;
}
OBJ_PTR get (void) {
OBJ_PTR Get (void) {
// explicit conversion to raw pointer type.
return m_objPtr;
}
private:
void insertSelfInOther (ReferenceList const&o) {
void InsertSelfInOther (ReferenceList const&o) {
m_prev = &o;
m_next = o.m_next;
m_next->m_prev = this;
o.m_next = this;
m_objPtr = o.m_objPtr;
}
void removeFrom_list (void) {
void RemoveFromList (void) {
if (m_prev == this) {
//assert (m_next == this);
delete m_objPtr;

4
src/core/system-file.h

@ -53,7 +53,7 @@ public:
* exist, it is created. If it exists, it is
* emptied first.
*/
void open (char const *filename);
void Open (char const *filename);
/**
* \param buffer data to write
* \param size size of data to write
@ -67,7 +67,7 @@ public:
* To make sure the data is written to disk, destroy
* this object.
*/
void write (uint8_t const*buffer, uint32_t size);
void Write (uint8_t const*buffer, uint32_t size);
private:
SystemFilePrivate *m_priv;
};

4
src/core/system-wall-clock-ms.h

@ -35,7 +35,7 @@ public:
/**
* Start a measure.
*/
void start (void);
void Start (void);
/**
* \returns the measured elapsed wall clock time since
* ns3::SystemWallClockMs::start was invoked.
@ -43,7 +43,7 @@ public:
* It is possible to start a new measurement with ns3::SystemWallClockMs::start
* after this method returns.
*/
unsigned long long end (void);
unsigned long long End (void);
private:
class SystemWallClockMsPrivate *m_priv;
};

26
src/core/test.cc

@ -27,7 +27,7 @@
namespace ns3 {
TestManager *
TestManager::get (void)
TestManager::Get (void)
{
static TestManager manager;
return &manager;
@ -46,32 +46,32 @@ TestManager::~TestManager ()
}
}
void
TestManager::add (Test *test, char const *name)
TestManager::Add (Test *test, char const *name)
{
get ()->m_tests.push_back (std::make_pair (test, new std::string (name)));
Get ()->m_tests.push_back (std::make_pair (test, new std::string (name)));
}
void
TestManager::enableVerbose (void)
TestManager::EnableVerbose (void)
{
get ()->m_verbose = true;
Get ()->m_verbose = true;
}
std::ostream &
TestManager::failure (void)
TestManager::Failure (void)
{
return std::cerr;
}
bool
TestManager::runTests (void)
TestManager::RunTests (void)
{
return get ()->realRunTests ();
return Get ()->RealRunTests ();
}
bool
TestManager::realRunTests (void)
TestManager::RealRunTests (void)
{
bool isSuccess = true;
for (TestsCI i = m_tests.begin (); i != m_tests.end (); i++) {
std::string *testName = (*i).second;
if (!(*i).first->runTests ()) {
if (!(*i).first->RunTests ()) {
isSuccess = false;
if (m_verbose) {
std::cerr << "FAIL " << *testName << std::endl;
@ -90,16 +90,16 @@ TestManager::realRunTests (void)
Test::Test (char const *name)
{
TestManager::add (this, name);
TestManager::Add (this, name);
}
Test::~Test ()
{}
std::ostream &
Test::failure (void)
Test::Failure (void)
{
return TestManager::failure ();
return TestManager::Failure ();
}
}; // namespace ns3

16
src/core/test.h

@ -55,14 +55,14 @@ public:
/**
* \returns true if the test was successful, false otherwise.
*/
virtual bool runTests (void) = 0;
virtual bool RunTests (void) = 0;
protected:
/**
* \returns an output stream which base classes can write to
* to return extra information on test errors.
*/
std::ostream &failure (void);
std::ostream &Failure (void);
};
/**
@ -74,20 +74,20 @@ public:
* Enable verbose output. If you do not enable verbose output,
* nothing is printed on screen during the test runs.
*/
static void enableVerbose (void);
static void EnableVerbose (void);
/**
* \returns true if all tests passed, false otherwise.
*
* run all registered regression tests
*/
static bool runTests (void);
static bool RunTests (void);
private:
friend class Test;
static void add (Test *test, char const *name);
static std::ostream &failure (void);
static TestManager *get (void);
bool realRunTests (void);
static void Add (Test *test, char const *name);
static std::ostream &Failure (void);
static TestManager *Get (void);
bool RealRunTests (void);
TestManager ();
~TestManager ();

16
src/core/unix-system-file.cc

@ -49,8 +49,8 @@ public:
SystemFilePrivate ();
~SystemFilePrivate ();
void open (char const *filename);
void write (uint8_t const*buffer, uint32_t size);
void Open (char const *filename);
void Write (uint8_t const*buffer, uint32_t size);
private:
uint8_t m_data[BUFFER_SIZE];
uint32_t m_current;
@ -68,7 +68,7 @@ SystemFilePrivate::~SystemFilePrivate ()
void
SystemFilePrivate::open (char const *filename)
SystemFilePrivate::Open (char const *filename)
{
m_fd = ::open (filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
assert (m_fd != -1);
@ -79,7 +79,7 @@ SystemFilePrivate::open (char const *filename)
#endif /* min */
void
SystemFilePrivate::write (uint8_t const*buffer, uint32_t size)
SystemFilePrivate::Write (uint8_t const*buffer, uint32_t size)
{
while (size > 0) {
uint32_t toCopy = min (BUFFER_SIZE - m_current, size);
@ -106,14 +106,14 @@ SystemFile::~SystemFile ()
}
void
SystemFile::open (char const *filename)
SystemFile::Open (char const *filename)
{
m_priv->open (filename);
m_priv->Open (filename);
}
void
SystemFile::write (uint8_t const*buffer, uint32_t size)
SystemFile::Write (uint8_t const*buffer, uint32_t size)
{
m_priv->write (buffer, size);
m_priv->Write (buffer, size);
}
}; // namespace

16
src/core/unix-system-wall-clock-ms.cc

@ -26,22 +26,22 @@ namespace ns3 {
class SystemWallClockMsPrivate {
public:
void start (void);
unsigned long long end (void);
void Start (void);
unsigned long long End (void);
private:
struct timeval m_startTv;
struct timeval m_endTv;
};
void
SystemWallClockMsPrivate::start (void)
SystemWallClockMsPrivate::Start (void)
{
struct timezone tz;
gettimeofday (&m_startTv, &tz);
}
unsigned long long
SystemWallClockMsPrivate::end (void)
SystemWallClockMsPrivate::End (void)
{
struct timezone tz;
gettimeofday (&m_endTv, &tz);
@ -61,14 +61,14 @@ SystemWallClockMs::~SystemWallClockMs ()
}
void
SystemWallClockMs::start (void)
SystemWallClockMs::Start (void)
{
m_priv->start ();
m_priv->Start ();
}
unsigned long long
SystemWallClockMs::end (void)
SystemWallClockMs::End (void)
{
return m_priv->end ();
return m_priv->End ();
}
}; // namespace ns3

12
src/core/win32-system-file.cc

@ -54,12 +54,12 @@ SystemFilePrivate::~SystemFilePrivate ()
void
SystemFilePrivate::open (char const *filename)
SystemFilePrivate::Open (char const *filename)
{
}
void
SystemFilePrivate::write (uint8_t const*buffer, uint32_t size)
SystemFilePrivate::Write (uint8_t const*buffer, uint32_t size)
{
}
@ -73,14 +73,14 @@ SystemFile::~SystemFile ()
}
void
SystemFile::open (char const *filename)
SystemFile::Open (char const *filename)
{
m_priv->open (filename);
m_priv->Open (filename);
}
void
SystemFile::write (uint8_t const*buffer, uint32_t size)
SystemFile::Write (uint8_t const*buffer, uint32_t size)
{
m_priv->write (buffer, size);
m_priv->Write (buffer, size);
}
}; // namespace

12
src/core/win32-system-wall-clock-ms.cc

@ -31,12 +31,12 @@ private:
};
void
SystemWallClockMsPrivate::start (void)
SystemWallClockMsPrivate::Start (void)
{
}
unsigned long long
SystemWallClockMsPrivate::end (void)
SystemWallClockMsPrivate::End (void)
{
return 0;
}
@ -52,14 +52,14 @@ SystemWallClockMs::~SystemWallClockMs ()
}
void
SystemWallClockMs::start (void)
SystemWallClockMs::Start (void)
{
m_priv->start ();
m_priv->Start ();
}
unsigned long long
SystemWallClockMs::end (void)
SystemWallClockMs::End (void)
{
return m_priv->end ();
return m_priv->End ();
}
}; // namespace ns3

14
src/simulator/event-id.cc

@ -35,27 +35,27 @@ EventId::EventId (EventImpl *impl, uint64_t ns, uint32_t uid)
m_uid (uid)
{}
void
EventId::cancel (void)
EventId::Cancel (void)
{
Simulator::cancel (*this);
Simulator::Cancel (*this);
}
bool
EventId::isExpired (void)
EventId::IsExpired (void)
{
return Simulator::isExpired (*this);
return Simulator::IsExpired (*this);
}
EventImpl *
EventId::getEventImpl (void) const
EventId::GetEventImpl (void) const
{
return m_eventImpl;
}
uint64_t
EventId::getNs (void) const
EventId::GetNs (void) const
{
return m_ns;
}
uint32_t
EventId::getUid (void) const
EventId::GetUid (void) const
{
return m_uid;
}

10
src/simulator/event-id.h

@ -38,21 +38,21 @@ public:
* This method is syntactic sugar for the ns3::Simulator::cancel
* method.
*/
void cancel (void);
void Cancel (void);
/**
* This method is syntactic sugar for the ns3::Simulator::isExpired
* method.
* \returns true if the event has expired, false otherwise.
*/
bool isExpired (void);
bool IsExpired (void);
public:
/* The following methods are semi-private
* they are supposed to be invoked only by
* subclasses of the Scheduler base class.
*/
EventImpl *getEventImpl (void) const;
uint64_t getNs (void) const;
uint32_t getUid (void) const;
EventImpl *GetEventImpl (void) const;
uint64_t GetNs (void) const;
uint32_t GetUid (void) const;
private:
EventImpl *m_eventImpl;
uint64_t m_ns;

10
src/simulator/event-impl.cc

@ -33,24 +33,24 @@ EventImpl::EventImpl ()
m_cancel (false)
{}
void
EventImpl::invoke (void)
EventImpl::Invoke (void)
{
if (!m_cancel) {
notify ();
Notify ();
}
}
void
EventImpl::setInternalIterator (void *tag)
EventImpl::SetInternalIterator (void *tag)
{
m_internalIterator = tag;
}
void *
EventImpl::getInternalIterator (void) const
EventImpl::GetInternalIterator (void) const
{
return m_internalIterator;
}
void
EventImpl::cancel (void)
EventImpl::Cancel (void)
{
m_cancel = true;
}

10
src/simulator/event-impl.h

@ -29,12 +29,12 @@ class EventImpl {
public:
EventImpl ();
virtual ~EventImpl () = 0;
void invoke (void);
void cancel (void);
void setInternalIterator (void *iterator);
void *getInternalIterator (void) const;
void Invoke (void);
void Cancel (void);
void SetInternalIterator (void *iterator);
void *GetInternalIterator (void) const;
protected:
virtual void notify (void) = 0;
virtual void Notify (void) = 0;
private:
friend class Event;
void *m_internalIterator;

24
src/simulator/nstime.h

@ -39,64 +39,64 @@ public:
* \returns the time stored in this
* instance as seconds.
*/
double s (void) const;
double S (void) const;
/**
* \returns the time stored in this
* instance as microseconds.
*/
uint64_t us (void) const;
uint64_t Us (void) const;
/**
* \returns the time stored in this
* instance as nanoseconds.
*/
uint64_t ns (void) const;
uint64_t Ns (void) const;
/**
* \returns true if this instance represents
* the "destroy" time.
*/
bool isDestroy (void) const;
bool IsDestroy (void) const;
/**
* \param s absolute time in seconds
* \returns a constructed Time object
*/
static Time absS (double s);
static Time AbsS (double s);
/**
* \param us absolute time in microseconds
* \returns a constructed Time object
*/
static Time absUs (uint64_t us);
static Time AbsUs (uint64_t us);
/**
* \param ns absolute time in nanoseconds
* \returns a constructed Time object
*/
static Time absNs (uint64_t ns);
static Time AbsNs (uint64_t ns);
/**
* \param s relative time in seconds
* \returns a constructed Time object
*/
static Time relS (double s);
static Time RelS (double s);
/**
* \param us relative time in microseconds
* \returns a constructed Time object
*/
static Time relUs (uint64_t us);
static Time RelUs (uint64_t us);
/**
* \param ns relative time in nanoseconds
* \returns a constructed Time object
*/
static Time relNs (uint64_t ns);
static Time RelNs (uint64_t ns);
/**
* \returns a constructed Time object which represents
* the current simulation time
*/
static Time now (void);
static Time Now (void);
/**
* \returns a constructed Time object which represents
* the current "destroy" simulation time, that
* is, the time when Simulator::destroy is
* invoked by the user.
*/
static Time destroy (void);
static Time Destroy (void);
private:
Time (uint64_t ns);
Time ();

4
src/simulator/scheduler-factory.cc

@ -26,9 +26,9 @@ SchedulerFactory::~SchedulerFactory ()
{}
Scheduler *
SchedulerFactory::create (void) const
SchedulerFactory::Create (void) const
{
return realCreate ();
return RealCreate ();
}
}; // namespace ns3

4
src/simulator/scheduler-factory.h

@ -36,13 +36,13 @@ class Scheduler;
class SchedulerFactory {
public:
virtual ~SchedulerFactory ();
Scheduler *create (void) const;
Scheduler *Create (void) const;
private:
/**
* \returns a newly-created scheduler. The caller takes
* ownership of the returned pointer.
*/
virtual Scheduler *realCreate (void) const = 0;
virtual Scheduler *RealCreate (void) const = 0;
};
}; // namespace ns3

126
src/simulator/scheduler-heap.cc

@ -64,182 +64,182 @@ SchedulerHeap::~SchedulerHeap ()
{}
void
SchedulerHeap::storeInEvent (EventImpl *ev, uint32_t index) const
SchedulerHeap::StoreInEvent (EventImpl *ev, uint32_t index) const
{
long tmp = index;
ev->setInternalIterator ((void *)tmp);
ev->SetInternalIterator ((void *)tmp);
}
uint32_t
SchedulerHeap::getFrom_event (EventImpl *ev) const
SchedulerHeap::GetFromEvent (EventImpl *ev) const
{
long tmp = (long)ev->getInternalIterator ();
long tmp = (long)ev->GetInternalIterator ();
return (uint32_t)tmp;
}
uint32_t
SchedulerHeap::parent (uint32_t id) const
SchedulerHeap::Parent (uint32_t id) const
{
return id / 2;
}
uint32_t
SchedulerHeap::sibling (uint32_t id) const
SchedulerHeap::Sibling (uint32_t id) const
{
return id + 1;
}
uint32_t
SchedulerHeap::leftChild (uint32_t id) const
SchedulerHeap::LeftChild (uint32_t id) const
{
return id * 2;
}
uint32_t
SchedulerHeap::rightChild (uint32_t id) const
SchedulerHeap::RightChild (uint32_t id) const
{
return id * 2 + 1;
}
uint32_t
SchedulerHeap::root (void) const
SchedulerHeap::Root (void) const
{
return 1;
}
bool
SchedulerHeap::isRoot (uint32_t id) const
SchedulerHeap::IsRoot (uint32_t id) const
{
return (id == root ())?true:false;
return (id == Root ())?true:false;
}
uint32_t
SchedulerHeap::last (void) const
SchedulerHeap::Last (void) const
{
return m_heap.size () - 1;
}
bool
SchedulerHeap::isBottom (uint32_t id) const
SchedulerHeap::IsBottom (uint32_t id) const
{
return (id >= m_heap.size ())?true:false;
}
void
SchedulerHeap::exch (uint32_t a, uint32_t b)
SchedulerHeap::Exch (uint32_t a, uint32_t b)
{
assert (b < m_heap.size () && a < m_heap.size ());
TRACE ("exch " << a << ", " << b);
TRACE ("Exch " << a << ", " << b);
std::pair<EventImpl*, Scheduler::EventKey> tmp (m_heap[a]);
m_heap[a] = m_heap[b];
m_heap[b] = tmp;
storeInEvent (m_heap[a].first, a);
storeInEvent (m_heap[b].first, b);
StoreInEvent (m_heap[a].first, a);
StoreInEvent (m_heap[b].first, b);
}
bool
SchedulerHeap::isLess (uint32_t a, uint32_t b)
SchedulerHeap::IsLess (uint32_t a, uint32_t b)
{
Scheduler::EventKeyCompare compare;
return compare (m_heap[a].second, m_heap[b].second);
}
uint32_t
SchedulerHeap::smallest (uint32_t a, uint32_t b)
SchedulerHeap::Smallest (uint32_t a, uint32_t b)
{
return isLess (a,b)?a:b;
return IsLess (a,b)?a:b;
}
bool
SchedulerHeap::realIsEmpty (void) const
SchedulerHeap::RealIsEmpty (void) const
{
return (m_heap.size () == 1)?true:false;
}
void
SchedulerHeap::bottom_up (void)
SchedulerHeap::BottomUp (void)
{
uint32_t index = last ();
while (!isRoot (index) &&
isLess (index, parent (index))) {
exch(index, parent (index));
index = parent (index);
uint32_t index = Last ();
while (!IsRoot (index) &&
IsLess (index, Parent (index))) {
Exch(index, Parent (index));
index = Parent (index);
}
}
void
SchedulerHeap::topDown (void)
{
uint32_t index = root ();
uint32_t right = rightChild (index);
while (!isBottom (right)) {
uint32_t left = leftChild (index);
uint32_t tmp = smallest (left, right);
if (isLess (index, tmp)) {
SchedulerHeap::TopDown (void)
{
uint32_t index = Root ();
uint32_t right = RightChild (index);
while (!IsBottom (right)) {
uint32_t left = LeftChild (index);
uint32_t tmp = Smallest (left, right);
if (IsLess (index, tmp)) {
return;
}
exch (index, tmp);
Exch (index, tmp);
index = tmp;
right = rightChild (index);
right = RightChild (index);
}
if (isBottom (index)) {
if (IsBottom (index)) {
return;
}
assert (!isBottom (index));
uint32_t left = leftChild (index);
if (isBottom (left)) {
assert (!IsBottom (index));
uint32_t left = LeftChild (index);
if (IsBottom (left)) {
return;
}
if (isLess (index, left)) {
if (IsLess (index, left)) {
return;
}
exch (index, left);
Exch (index, left);
}
EventId
SchedulerHeap::realInsert (EventImpl *event, Scheduler::EventKey key)
SchedulerHeap::RealInsert (EventImpl *event, Scheduler::EventKey key)
{
m_heap.push_back (std::make_pair (event, key));
bottom_up ();
storeInEvent (event, last ());
BottomUp ();
StoreInEvent (event, Last ());
return EventId (event, key.m_ns, key.m_uid);
}
EventImpl *
SchedulerHeap::realPeekNext (void) const
SchedulerHeap::RealPeekNext (void) const
{
return m_heap[root ()].first;
return m_heap[Root ()].first;
}
Scheduler::EventKey
SchedulerHeap::realPeekNextKey (void) const
SchedulerHeap::RealPeekNextKey (void) const
{
return m_heap[root ()].second;
return m_heap[Root ()].second;
}
void
SchedulerHeap::realRemoveNext (void)
SchedulerHeap::RealRemoveNext (void)
{
exch (root (), last ());
Exch (Root (), Last ());
m_heap.pop_back ();
topDown ();
TopDown ();
}
EventImpl *
SchedulerHeap::realRemove (EventId id, Scheduler::EventKey *key)
SchedulerHeap::RealRemove (EventId id, Scheduler::EventKey *key)
{
EventImpl *ev = id.getEventImpl ();
uint32_t i = getFrom_event (ev);
EventImpl *ev = id.GetEventImpl ();
uint32_t i = GetFromEvent (ev);
*key = m_heap[i].second;
exch (i, last ());
Exch (i, Last ());
m_heap.pop_back ();
topDown ();
TopDown ();
return ev;
}
bool
SchedulerHeap::realIsValid (EventId id)
SchedulerHeap::RealIsValid (EventId id)
{
EventImpl *ev = id.getEventImpl ();
uint32_t i = getFrom_event (ev);
EventImpl *ev = id.GetEventImpl ();
uint32_t i = GetFromEvent (ev);
Scheduler::EventKey key = m_heap[i].second;
return (key.m_ns == id.getNs () &&
key.m_uid == id.getUid ());
return (key.m_ns == id.GetNs () &&
key.m_uid == id.GetUid ());
}
}; // namespace ns3

44
src/simulator/scheduler-heap.h

@ -36,32 +36,32 @@ public:
virtual ~SchedulerHeap ();
private:
virtual EventId realInsert (EventImpl *event, Scheduler::EventKey key);
virtual bool realIsEmpty (void) const;
virtual EventImpl *realPeekNext (void) const;
virtual Scheduler::EventKey realPeekNextKey (void) const;
virtual void realRemoveNext (void);
virtual EventImpl *realRemove (EventId ev, Scheduler::EventKey *key);
virtual bool realIsValid (EventId id);
virtual EventId RealInsert (EventImpl *event, Scheduler::EventKey key);
virtual bool RealIsEmpty (void) const;
virtual EventImpl *RealPeekNext (void) const;
virtual Scheduler::EventKey RealPeekNextKey (void) const;
virtual void RealRemoveNext (void);
virtual EventImpl *RealRemove (EventId ev, Scheduler::EventKey *key);
virtual bool RealIsValid (EventId id);
typedef std::vector<std::pair<EventImpl *, Scheduler::EventKey> > BinaryHeap;
inline void storeInEvent (EventImpl *ev, uint32_t index) const;
uint32_t getFrom_event (EventImpl *ev) const;
inline void StoreInEvent (EventImpl *ev, uint32_t index) const;
uint32_t GetFromEvent (EventImpl *ev) const;
inline uint32_t parent (uint32_t id) const;
uint32_t sibling (uint32_t id) const;
inline uint32_t leftChild (uint32_t id) const;
inline uint32_t rightChild (uint32_t id) const;
inline uint32_t root (void) const;
uint32_t last (void) const;
inline bool isRoot (uint32_t id) const;
inline bool isBottom (uint32_t id) const;
inline bool isLess (uint32_t a, uint32_t b);
inline uint32_t smallest (uint32_t a, uint32_t b);
inline uint32_t Parent (uint32_t id) const;
uint32_t Sibling (uint32_t id) const;
inline uint32_t LeftChild (uint32_t id) const;
inline uint32_t RightChild (uint32_t id) const;
inline uint32_t Root (void) const;
uint32_t Last (void) const;
inline bool IsRoot (uint32_t id) const;
inline bool IsBottom (uint32_t id) const;
inline bool IsLess (uint32_t a, uint32_t b);
inline uint32_t Smallest (uint32_t a, uint32_t b);
inline void exch (uint32_t a, uint32_t b);
void bottom_up (void);
void topDown (void);
inline void Exch (uint32_t a, uint32_t b);
void BottomUp (void);
void TopDown (void);
BinaryHeap m_heap;
};

40
src/simulator/scheduler-list.cc

@ -38,81 +38,81 @@ SchedulerList::~SchedulerList ()
* member variable, a pointer.
*/
EventId
SchedulerList::getEventId (Scheduler::EventKey key, EventsI i)
SchedulerList::GetEventId (Scheduler::EventKey key, EventsI i)
{
assert (sizeof (i) <= sizeof (void *));
void *internalIterator;
memcpy ((char *)&(internalIterator), (char *)&i, sizeof (void *));
EventImpl *ev = i->first;
ev->setInternalIterator (internalIterator);
ev->SetInternalIterator (internalIterator);
return EventId (ev, key.m_ns, key.m_uid);
}
SchedulerList::EventsI
SchedulerList::getIterator (EventId id)
SchedulerList::GetIterator (EventId id)
{
SchedulerList::EventsI i;
assert (sizeof (i) <= sizeof (void *));
EventImpl *ev = id.getEventImpl ();
void *internalIterator = ev->getInternalIterator ();
EventImpl *ev = id.GetEventImpl ();
void *internalIterator = ev->GetInternalIterator ();
memcpy ((char *)&i, (char *)&(internalIterator), sizeof (void *));
return i;
}
EventId
SchedulerList::realInsert (EventImpl *event, Scheduler::EventKey key)
SchedulerList::RealInsert (EventImpl *event, Scheduler::EventKey key)
{
Scheduler::EventKeyCompare compare;
for (EventsI i = m_events.begin (); i != m_events.end (); i++) {
if (compare (key, i->second)) {
m_events.insert (i, std::make_pair (event, key));
return getEventId (key, i);
return GetEventId (key, i);
}
}
m_events.push_back (std::make_pair (event, key));
return getEventId (key, --(m_events.end ()));
return GetEventId (key, --(m_events.end ()));
}
bool
SchedulerList::realIsEmpty (void) const
SchedulerList::RealIsEmpty (void) const
{
return m_events.empty ();
}
EventImpl *
SchedulerList::realPeekNext (void) const
SchedulerList::RealPeekNext (void) const
{
return m_events.front ().first;
}
Scheduler::EventKey
SchedulerList::realPeekNextKey (void) const
SchedulerList::RealPeekNextKey (void) const
{
return m_events.front ().second;
}
void
SchedulerList::realRemoveNext (void)
SchedulerList::RealRemoveNext (void)
{
m_events.pop_front ();
}
EventImpl *
SchedulerList::realRemove (EventId id, Scheduler::EventKey *key)
SchedulerList::RealRemove (EventId id, Scheduler::EventKey *key)
{
EventsI i = getIterator (id);
EventsI i = GetIterator (id);
*key = i->second;
assert (key->m_ns == id.getNs () &&
key->m_uid == id.getUid ());
assert (key->m_ns == id.GetNs () &&
key->m_uid == id.GetUid ());
EventImpl *ev = i->first;
m_events.erase (i);
return ev;
}
bool
SchedulerList::realIsValid (EventId id)
SchedulerList::RealIsValid (EventId id)
{
EventsI i = getIterator (id);
EventsI i = GetIterator (id);
Scheduler::EventKey key = i->second;
return (key.m_ns == id.getNs () &&
key.m_uid == id.getUid ());
return (key.m_ns == id.GetNs () &&
key.m_uid == id.GetUid ());
}

18
src/simulator/scheduler-list.h

@ -38,18 +38,18 @@ class SchedulerList : public Scheduler {
virtual ~SchedulerList ();
private:
virtual EventId realInsert (EventImpl *event, EventKey key);
virtual bool realIsEmpty (void) const;
virtual EventImpl *realPeekNext (void) const;
virtual Scheduler::EventKey realPeekNextKey (void) const;
virtual void realRemoveNext (void);
virtual EventImpl *realRemove (EventId ev, Scheduler::EventKey *key);
virtual bool realIsValid (EventId id);
virtual EventId RealInsert (EventImpl *event, EventKey key);
virtual bool RealIsEmpty (void) const;
virtual EventImpl *RealPeekNext (void) const;
virtual Scheduler::EventKey RealPeekNextKey (void) const;
virtual void RealRemoveNext (void);
virtual EventImpl *RealRemove (EventId ev, Scheduler::EventKey *key);
virtual bool RealIsValid (EventId id);
typedef std::list<std::pair<EventImpl*, EventKey> > Events;
typedef std::list<std::pair<EventImpl*, EventKey> >::iterator EventsI;
EventId getEventId (Scheduler::EventKey key, EventsI i);
EventsI getIterator (EventId id);
EventId GetEventId (Scheduler::EventKey key, EventsI i);
EventsI GetIterator (EventId id);
Events m_events;
};

32
src/simulator/scheduler-map.cc

@ -45,72 +45,72 @@ SchedulerMap::~SchedulerMap ()
void
SchedulerMap::storeInEvent (EventImpl *ev, EventMapI i) const
SchedulerMap::StoreInEvent (EventImpl *ev, EventMapI i) const
{
void *tag;
memcpy (&(tag), &i, sizeof (tag));
ev->setInternalIterator (tag);
ev->SetInternalIterator (tag);
}
SchedulerMap::EventMapI
SchedulerMap::getFrom_event (EventImpl *ev) const
SchedulerMap::GetFromEvent (EventImpl *ev) const
{
EventMapI i;
void *tag = ev->getInternalIterator ();
void *tag = ev->GetInternalIterator ();
memcpy (&i, &(tag), sizeof (i));
return i;
}
EventId
SchedulerMap::realInsert (EventImpl *event, Scheduler::EventKey key)
SchedulerMap::RealInsert (EventImpl *event, Scheduler::EventKey key)
{
std::pair<EventMapI,bool> result = m_list.insert (std::make_pair (key, event));
assert (result.second);
storeInEvent (event, result.first);
StoreInEvent (event, result.first);
return EventId (event, key.m_ns, key.m_uid);
}
bool
SchedulerMap::realIsEmpty (void) const
SchedulerMap::RealIsEmpty (void) const
{
return m_list.empty ();
}
EventImpl *
SchedulerMap::realPeekNext (void) const
SchedulerMap::RealPeekNext (void) const
{
EventMapCI i = m_list.begin ();
assert (i != m_list.end ());
return (*i).second;
}
Scheduler::EventKey
SchedulerMap::realPeekNextKey (void) const
SchedulerMap::RealPeekNextKey (void) const
{
EventMapCI i = m_list.begin ();
assert (i != m_list.end ());
return (*i).first;
}
void
SchedulerMap::realRemoveNext (void)
SchedulerMap::RealRemoveNext (void)
{
m_list.erase (m_list.begin ());
}
EventImpl *
SchedulerMap::realRemove (EventId id, Scheduler::EventKey *key)
SchedulerMap::RealRemove (EventId id, Scheduler::EventKey *key)
{
EventMapI i = getFrom_event (id.getEventImpl ());
EventMapI i = GetFromEvent (id.GetEventImpl ());
*key = i->first;
m_list.erase (i);
return i->second;
}
bool
SchedulerMap::realIsValid (EventId id)
SchedulerMap::RealIsValid (EventId id)
{
EventMapI i = getFrom_event (id.getEventImpl ());
EventMapI i = GetFromEvent (id.GetEventImpl ());
Scheduler::EventKey key = i->first;
return (key.m_ns == id.getNs () &&
key.m_uid == id.getUid ());
return (key.m_ns == id.GetNs () &&
key.m_uid == id.GetUid ());
}

18
src/simulator/scheduler-map.h

@ -37,20 +37,20 @@ public:
virtual ~SchedulerMap ();
private:
virtual EventId realInsert (EventImpl *event, Scheduler::EventKey key);
virtual bool realIsEmpty (void) const;
virtual EventImpl *realPeekNext (void) const;
virtual Scheduler::EventKey realPeekNextKey (void) const;
virtual void realRemoveNext (void);
virtual EventImpl *realRemove (EventId ev, Scheduler::EventKey *key);
virtual bool realIsValid (EventId id);
virtual EventId RealInsert (EventImpl *event, Scheduler::EventKey key);
virtual bool RealIsEmpty (void) const;
virtual EventImpl *RealPeekNext (void) const;
virtual Scheduler::EventKey RealPeekNextKey (void) const;
virtual void RealRemoveNext (void);
virtual EventImpl *RealRemove (EventId ev, Scheduler::EventKey *key);
virtual bool RealIsValid (EventId id);
typedef std::map<Scheduler::EventKey, EventImpl*, Scheduler::EventKeyCompare> EventMap;
typedef std::map<Scheduler::EventKey, EventImpl*, Scheduler::EventKeyCompare>::iterator EventMapI;
typedef std::map<Scheduler::EventKey, EventImpl*, Scheduler::EventKeyCompare>::const_iterator EventMapCI;
void storeInEvent (EventImpl *ev, EventMapI i) const;
SchedulerMap::EventMapI getFrom_event (EventImpl *ev) const;
void StoreInEvent (EventImpl *ev, EventMapI i) const;
SchedulerMap::EventMapI GetFromEvent (EventImpl *ev) const;
EventMap m_list;
uint32_t m_uid;

36
src/simulator/scheduler.cc

@ -47,43 +47,43 @@ Scheduler::EventKeyCompare::operator () (struct EventKey a, struct EventKey b)
EventId
Scheduler::insert (EventImpl *event, struct EventKey key)
Scheduler::Insert (EventImpl *event, struct EventKey key)
{
return realInsert (event, key);
return RealInsert (event, key);
}
bool
Scheduler::isEmpty (void) const
Scheduler::IsEmpty (void) const
{
return realIsEmpty ();
return RealIsEmpty ();
}
EventImpl *
Scheduler::peekNext (void) const
Scheduler::PeekNext (void) const
{
assert (!realIsEmpty ());
return realPeekNext ();
assert (!RealIsEmpty ());
return RealPeekNext ();
}
Scheduler::EventKey
Scheduler::peekNextKey (void) const
Scheduler::PeekNextKey (void) const
{
assert (!realIsEmpty ());
return realPeekNextKey ();
assert (!RealIsEmpty ());
return RealPeekNextKey ();
}
void
Scheduler::removeNext (void)
Scheduler::RemoveNext (void)
{
assert (!realIsEmpty ());
return realRemoveNext ();
assert (!RealIsEmpty ());
return RealRemoveNext ();
}
EventImpl *
Scheduler::remove (EventId id, EventKey *key)
Scheduler::Remove (EventId id, EventKey *key)
{
assert (!realIsEmpty ());
return realRemove (id, key);
assert (!RealIsEmpty ());
return RealRemove (id, key);
}
bool
Scheduler::isValid (EventId id)
Scheduler::IsValid (EventId id)
{
return realIsValid (id);
return RealIsValid (id);
}
}; // namespace ns3

28
src/simulator/scheduler.h

@ -65,13 +65,13 @@ class Scheduler {
virtual ~Scheduler () = 0;
EventId insert (EventImpl *event, EventKey key);
bool isEmpty (void) const;
EventImpl *peekNext (void) const;
Scheduler::EventKey peekNextKey (void) const ;
void removeNext (void);
EventImpl *remove (EventId id, EventKey *key);
bool isValid (EventId id);
EventId Insert (EventImpl *event, EventKey key);
bool IsEmpty (void) const;
EventImpl *PeekNext (void) const;
Scheduler::EventKey PeekNextKey (void) const ;
void RemoveNext (void);
EventImpl *Remove (EventId id, EventKey *key);
bool IsValid (EventId id);
private:
/**
@ -81,29 +81,29 @@ private:
*
* This method takes ownership of the event pointer.
*/
virtual EventId realInsert (EventImpl *event, EventKey key) = 0;
virtual EventId RealInsert (EventImpl *event, EventKey key) = 0;
/**
* \returns true if the event list is empty and false otherwise.
*/
virtual bool realIsEmpty (void) const = 0;
virtual bool RealIsEmpty (void) const = 0;
/**
* \returns a pointer to the next earliest event. The caller
* takes ownership of the returned pointer.
*
* This method cannot be invoked if the list is empty.
*/
virtual EventImpl *realPeekNext (void) const = 0;
virtual EventImpl *RealPeekNext (void) const = 0;
/**
* \returns the timecode associated with the next earliest event.
*
* This method cannot be invoked if the list is empty.
*/
virtual Scheduler::EventKey realPeekNextKey (void) const = 0;
virtual Scheduler::EventKey RealPeekNextKey (void) const = 0;
/**
* This method cannot be invoked if the list is empty.
* Remove the next earliest event from the event list.
*/
virtual void realRemoveNext (void) = 0;
virtual void RealRemoveNext (void) = 0;
/**
* \param id the id of the event to remove
* \param key the timecode of the event removed
@ -112,13 +112,13 @@ private:
*
* This methods cannot be invoked if the list is empty.
*/
virtual EventImpl *realRemove (EventId id, EventKey *key) = 0;
virtual EventImpl *RealRemove (EventId id, EventKey *key) = 0;
/**
* \param id event id to validate
* \returns true if the event id identifies an existing valid
* event stored in the event list and false otherwise.
*/
virtual bool realIsValid (EventId id) = 0;
virtual bool RealIsValid (EventId id) = 0;
};
}; // namespace ns3

234
src/simulator/simulator.cc

@ -35,7 +35,7 @@
#ifdef TRACE_SIMU
#include <iostream>
# define TRACE(x) \
std::cout << "SIMU TRACE " << Simulator::nowS () << " " << x << std::endl;
std::Cout << "SIMU TRACE " << Simulator::nowS () << " " << x << std::endl;
# define TRACE_S(x) \
std::cout << "SIMU TRACE " << x << std::endl;
#else /* TRACE_SIMU */
@ -52,21 +52,21 @@ public:
SimulatorPrivate (Scheduler *events);
~SimulatorPrivate ();
void enableLogTo (char const *filename);
void EnableLogTo (char const *filename);
bool isFinished (void) const;
Time next (void) const;
void stop (void);
void stopAt (Time const &time);
EventId schedule (Time const &time, EventImpl *event);
void remove (EventId ev);
void cancel (EventId ev);
bool isExpired (EventId ev);
void run (void);
Time now (void) const;
bool IsFinished (void) const;
Time Next (void) const;
void Stop (void);
void StopAt (Time const &time);
EventId Schedule (Time const &time, EventImpl *event);
void Remove (EventId ev);
void Cancel (EventId ev);
bool IsExpired (EventId ev);
void Run (void);
Time Now (void) const;
private:
void processOneEvent (void);
void ProcessOneEvent (void);
typedef std::list<std::pair<EventImpl *,uint32_t> > Events;
Events m_destroy;
@ -100,7 +100,7 @@ SimulatorPrivate::~SimulatorPrivate ()
EventImpl *ev = m_destroy.front ().first;
m_destroy.pop_front ();
TRACE ("handle destroy " << ev);
ev->invoke ();
ev->Invoke ();
delete ev;
}
delete m_events;
@ -109,117 +109,117 @@ SimulatorPrivate::~SimulatorPrivate ()
void
SimulatorPrivate::enableLogTo (char const *filename)
SimulatorPrivate::EnableLogTo (char const *filename)
{
m_log.open (filename);
m_logEnable = true;
}
void
SimulatorPrivate::processOneEvent (void)
SimulatorPrivate::ProcessOneEvent (void)
{
EventImpl *nextEv = m_events->peekNext ();
Scheduler::EventKey nextKey = m_events->peekNextKey ();
m_events->removeNext ();
EventImpl *nextEv = m_events->PeekNext ();
Scheduler::EventKey nextKey = m_events->PeekNextKey ();
m_events->RemoveNext ();
TRACE ("handle " << nextEv);
m_currentNs = nextKey.m_ns;
m_currentUid = nextKey.m_uid;
if (m_logEnable) {
m_log << "e "<<nextKey.m_uid << " " << nextKey.m_ns << std::endl;
}
nextEv->invoke ();
nextEv->Invoke ();
delete nextEv;
}
bool
SimulatorPrivate::isFinished (void) const
SimulatorPrivate::IsFinished (void) const
{
return m_events->isEmpty ();
return m_events->IsEmpty ();
}
Time
SimulatorPrivate::next (void) const
SimulatorPrivate::Next (void) const
{
assert (!m_events->isEmpty ());
Scheduler::EventKey nextKey = m_events->peekNextKey ();
return Time::absNs (nextKey.m_ns);
assert (!m_events->IsEmpty ());
Scheduler::EventKey nextKey = m_events->PeekNextKey ();
return Time::AbsNs (nextKey.m_ns);
}
void
SimulatorPrivate::run (void)
SimulatorPrivate::Run (void)
{
while (!m_events->isEmpty () && !m_stop &&
(m_stopAt == 0 || m_stopAt > next ().ns ())) {
processOneEvent ();
while (!m_events->IsEmpty () && !m_stop &&
(m_stopAt == 0 || m_stopAt > Next ().Ns ())) {
ProcessOneEvent ();
}
m_log.close ();
}
void
SimulatorPrivate::stop (void)
SimulatorPrivate::Stop (void)
{
m_stop = true;
}
void
SimulatorPrivate::stopAt (Time const &at)
SimulatorPrivate::StopAt (Time const &at)
{
m_stopAt = at.ns ();
m_stopAt = at.Ns ();
}
EventId
SimulatorPrivate::schedule (Time const &time, EventImpl *event)
SimulatorPrivate::Schedule (Time const &time, EventImpl *event)
{
if (time.isDestroy ()) {
if (time.IsDestroy ()) {
m_destroy.push_back (std::make_pair (event, m_uid));
if (m_logEnable) {
m_log << "id " << m_currentUid << " " << now ().ns () << " "
m_log << "id " << m_currentUid << " " << Now ().Ns () << " "
<< m_uid << std::endl;
}
m_uid++;
//XXX
return EventId ();
}
assert (time.ns () >= now ().ns ());
Scheduler::EventKey key = {time.ns (), m_uid};
assert (time.Ns () >= Now ().Ns ());
Scheduler::EventKey key = {time.Ns (), m_uid};
if (m_logEnable) {
m_log << "i "<<m_currentUid<<" "<<now ().ns ()<<" "
<<m_uid<<" "<<time.ns () << std::endl;
m_log << "i "<<m_currentUid<<" "<<Now ().Ns ()<<" "
<<m_uid<<" "<<time.Ns () << std::endl;
}
m_uid++;
return m_events->insert (event, key);
return m_events->Insert (event, key);
}
Time
SimulatorPrivate::now (void) const
SimulatorPrivate::Now (void) const
{
return Time::absNs (m_currentNs);
return Time::AbsNs (m_currentNs);
}
void
SimulatorPrivate::remove (EventId ev)
SimulatorPrivate::Remove (EventId ev)
{
Scheduler::EventKey key;
EventImpl *impl = m_events->remove (ev, &key);
EventImpl *impl = m_events->Remove (ev, &key);
delete impl;
if (m_logEnable) {
m_log << "r " << m_currentUid << " " << now ().ns () << " "
m_log << "r " << m_currentUid << " " << Now ().Ns () << " "
<< key.m_uid << " " << key.m_ns << std::endl;
}
}
void
SimulatorPrivate::cancel (EventId id)
SimulatorPrivate::Cancel (EventId id)
{
assert (m_events->isValid (id));
EventImpl *ev = id.getEventImpl ();
ev->cancel ();
assert (m_events->IsValid (id));
EventImpl *ev = id.GetEventImpl ();
ev->Cancel ();
}
bool
SimulatorPrivate::isExpired (EventId ev)
SimulatorPrivate::IsExpired (EventId ev)
{
if (ev.getEventImpl () != 0 &&
ev.getNs () <= now ().ns () &&
ev.getUid () < m_currentUid) {
if (ev.GetEventImpl () != 0 &&
ev.GetNs () <= Now ().Ns () &&
ev.GetUid () < m_currentUid) {
return false;
}
return true;
@ -241,33 +241,33 @@ SimulatorPrivate *Simulator::m_priv = 0;
Simulator::ListType Simulator::m_listType = LINKED_LIST;
SchedulerFactory const*Simulator::m_schedFactory = 0;
void Simulator::setLinkedList (void)
void Simulator::SetLinkedList (void)
{
m_listType = LINKED_LIST;
}
void Simulator::setBinaryHeap (void)
void Simulator::SetBinaryHeap (void)
{
m_listType = BINARY_HEAP;
}
void Simulator::setStdMap (void)
void Simulator::SetStdMap (void)
{
m_listType = STD_MAP;
}
void
Simulator::setExternal (SchedulerFactory const*factory)
Simulator::SetExternal (SchedulerFactory const*factory)
{
assert (factory != 0);
m_schedFactory = factory;
m_listType = EXTERNAL;
}
void Simulator::enableLogTo (char const *filename)
void Simulator::EnableLogTo (char const *filename)
{
getPriv ()->enableLogTo (filename);
GetPriv ()->EnableLogTo (filename);
}
SimulatorPrivate *
Simulator::getPriv (void)
Simulator::GetPriv (void)
{
if (m_priv == 0) {
Scheduler *events;
@ -282,7 +282,7 @@ Simulator::getPriv (void)
events = new SchedulerMap ();
break;
case EXTERNAL:
events = m_schedFactory->create ();
events = m_schedFactory->Create ();
default: // not reached
events = 0;
assert (false);
@ -295,7 +295,7 @@ Simulator::getPriv (void)
}
void
Simulator::destroy (void)
Simulator::Destroy (void)
{
delete m_priv;
m_priv = 0;
@ -303,46 +303,46 @@ Simulator::destroy (void)
bool
Simulator::isFinished (void)
Simulator::IsFinished (void)
{
return getPriv ()->isFinished ();
return GetPriv ()->IsFinished ();
}
Time
Simulator::next (void)
Simulator::Next (void)
{
return getPriv ()->next ();
return GetPriv ()->Next ();
}
void
Simulator::run (void)
Simulator::Run (void)
{
getPriv ()->run ();
GetPriv ()->Run ();
}
void
Simulator::stop (void)
Simulator::Stop (void)
{
TRACE ("stop");
getPriv ()->stop ();
GetPriv ()->Stop ();
}
void
Simulator::stopAt (Time const &at)
Simulator::StopAt (Time const &at)
{
getPriv ()->stopAt (at);
GetPriv ()->StopAt (at);
}
Time
Simulator::now (void)
Simulator::Now (void)
{
return getPriv ()->now ();
return GetPriv ()->Now ();
}
EventId
Simulator::schedule (Time const &time, EventImpl *ev)
Simulator::Schedule (Time const &time, EventImpl *ev)
{
return getPriv ()->schedule (time, ev);
return GetPriv ()->Schedule (time, ev);
}
EventId
Simulator::schedule (Time const &time, void (*f) (void))
Simulator::Schedule (Time const &time, void (*f) (void))
{
// zero arg version
class EventFunctionImpl0 : public EventImpl {
@ -354,31 +354,31 @@ Simulator::schedule (Time const &time, void (*f) (void))
{}
virtual ~EventFunctionImpl0 () {}
protected:
virtual void notify (void) {
virtual void Notify (void) {
(*m_function) ();
}
}
private:
F m_function;
} *ev = new EventFunctionImpl0 (f);
return schedule (time, ev);
return Schedule (time, ev);
}
void
Simulator::remove (EventId ev)
Simulator::Remove (EventId ev)
{
return getPriv ()->remove (ev);
return GetPriv ()->Remove (ev);
}
void
Simulator::cancel (EventId ev)
Simulator::Cancel (EventId ev)
{
return getPriv ()->cancel (ev);
return GetPriv ()->Cancel (ev);
}
bool
Simulator::isExpired (EventId id)
Simulator::IsExpired (EventId id)
{
return getPriv ()->isExpired (id);
return GetPriv ()->IsExpired (id);
}
}; // namespace ns3
@ -394,13 +394,13 @@ class SimulatorTests : public Test {
public:
SimulatorTests ();
virtual ~SimulatorTests ();
virtual bool runTests (void);
virtual bool RunTests (void);
private:
bool runOneTest (void);
void a (int a);
void b (int b);
void c (int c);
void d (int d);
bool RunOneTest (void);
void A (int a);
void B (int b);
void C (int c);
void D (int d);
bool m_b;
bool m_a;
bool m_c;
@ -414,37 +414,37 @@ SimulatorTests::SimulatorTests ()
SimulatorTests::~SimulatorTests ()
{}
void
SimulatorTests::a (int a)
SimulatorTests::A (int a)
{
m_a = false;
}
void
SimulatorTests::b (int b)
SimulatorTests::B (int b)
{
if (b != 2 || Simulator::now ().us () != 11) {
if (b != 2 || Simulator::Now ().Us () != 11) {
m_b = false;
} else {
m_b = true;
}
Simulator::remove (m_idC);
Simulator::schedule (Time::relUs (10), &SimulatorTests::d, this, 4);
Simulator::Remove (m_idC);
Simulator::Schedule (Time::RelUs (10), &SimulatorTests::D, this, 4);
}
void
SimulatorTests::c (int c)
SimulatorTests::C (int c)
{
m_c = false;
}
void
SimulatorTests::d (int d)
SimulatorTests::D (int d)
{
if (d != 4 || Simulator::now ().us () != (11+10)) {
if (d != 4 || Simulator::Now ().Us () != (11+10)) {
m_d = false;
} else {
m_d = true;
}
}
bool
SimulatorTests::runOneTest (void)
SimulatorTests::RunOneTest (void)
{
bool ok = true;
m_a = true;
@ -452,12 +452,12 @@ SimulatorTests::runOneTest (void)
m_c = true;
m_d = false;
EventId a = Simulator::schedule (Time::absUs (10), &SimulatorTests::a, this, 1);
Simulator::schedule (Time::absUs (11), &SimulatorTests::b, this, 2);
m_idC = Simulator::schedule (Time::absUs (12), &SimulatorTests::c, this, 3);
EventId a = Simulator::Schedule (Time::AbsUs (10), &SimulatorTests::A, this, 1);
Simulator::Schedule (Time::AbsUs (11), &SimulatorTests::B, this, 2);
m_idC = Simulator::Schedule (Time::AbsUs (12), &SimulatorTests::C, this, 3);
Simulator::cancel (a);
Simulator::run ();
Simulator::Cancel (a);
Simulator::Run ();
if (!m_a || !m_b || !m_c || !m_d) {
ok = false;
@ -465,25 +465,25 @@ SimulatorTests::runOneTest (void)
return ok;
}
bool
SimulatorTests::runTests (void)
SimulatorTests::RunTests (void)
{
bool ok = true;
Simulator::setLinkedList ();
if (!runOneTest ()) {
Simulator::SetLinkedList ();
if (!RunOneTest ()) {
ok = false;
}
Simulator::destroy ();
Simulator::setBinaryHeap ();
if (!runOneTest ()) {
Simulator::Destroy ();
Simulator::SetBinaryHeap ();
if (!RunOneTest ()) {
ok = false;
}
Simulator::destroy ();
Simulator::setStdMap ();
if (!runOneTest ()) {
Simulator::Destroy ();
Simulator::SetStdMap ();
if (!RunOneTest ()) {
ok = false;
}
Simulator::destroy ();
Simulator::Destroy ();
return ok;
}

126
src/simulator/simulator.h

@ -54,7 +54,7 @@ public:
* This method must be invoked before every other method exported
* by the Simulator class.
*/
static void enableParallelSimulation (void);
static void EnableParallelSimulation (void);
/**
* Force the use of an event scheduler based on a linked-list.
* This method must be invoked before any other method exported
@ -62,7 +62,7 @@ public:
* - insert: O(n)
* - remove: O(1)
*/
static void setLinkedList (void);
static void SetLinkedList (void);
/**
* Force the use of an event scheduler based on a binary heap.
* This method must be invoked before any other method exported
@ -70,7 +70,7 @@ public:
* - insert: O(log(n))
* - remove: O(log(n))
*/
static void setBinaryHeap (void);
static void SetBinaryHeap (void);
/**
* Force the use of an event scheduler based on a std::map.
* This method must be invoked before any other method exported
@ -78,14 +78,14 @@ public:
* - insert: O(log(n))
* - remove: O(log(n))
*/
static void setStdMap (void);
static void SetStdMap (void);
/**
* Force the use of a user-provided event scheduler.
* This method must be invoked before any other method exported
* by the Simulator class.
*/
static void setExternal (SchedulerFactory const*factory);
static void SetExternal (SchedulerFactory const*factory);
/**
* Enable logging to the file identified by filename. If the file
@ -100,7 +100,7 @@ public:
* This method must be invoked before any call to Simulator::run
* @param filename the name of the file to log to
*/
static void enableLogTo (char const *filename);
static void EnableLogTo (char const *filename);
/**
* Every event scheduled by the Simulator::insertAtDestroy method is
@ -112,20 +112,20 @@ public:
* to restart a new simulation with a set of calls to Simulator::run
* and Simulator::insert_*.
*/
static void destroy (void);
static void Destroy (void);
/**
* If there any any events lefts to be scheduled, return
* true. Return false otherwise.
*/
static bool isFinished (void);
static bool IsFinished (void);
/**
* If Simulator::isFinished returns true, the behavior of this
* method is undefined. Otherwise, it returns the microsecond-based
* time of the next event expected to be scheduled.
*/
static Time next (void);
static Time Next (void);
/**
* Run the simulation until one of:
@ -135,20 +135,20 @@ public:
* expiration time of the next event to be processed
* is greater than or equal to the stop time.
*/
static void run (void);
static void Run (void);
/**
* If an event invokes this method, it will be the last
* event scheduled by the Simulator::run method before
* returning to the caller.
*/
static void stop (void);
static void Stop (void);
/**
* Force the Simulator::run method to return to the caller
* when the expiration time of the next event to be processed
* is greater than or equal to the stop time.
* @param time the stop time.
*/
static void stopAt (Time const &time);
static void StopAt (Time const &time);
/**
* Schedule an event to expire when time is reached.
@ -161,7 +161,7 @@ public:
* @returns an id for the scheduled event.
*/
template <typename T>
static EventId schedule (Time const &time, void (T::*mem_ptr) (void), T *obj);
static EventId Schedule (Time const &time, void (T::*mem_ptr) (void), T *obj);
/**
* @param time the expiration time of the event.
* @param mem_ptr member method pointer to invoke
@ -170,7 +170,7 @@ public:
* @returns an id for the scheduled event.
*/
template <typename T, typename T1>
static EventId schedule (Time const &time, void (T::*mem_ptr) (T1), T* obj, T1 a1);
static EventId Schedule (Time const &time, void (T::*mem_ptr) (T1), T* obj, T1 a1);
/**
* @param time the expiration time of the event.
* @param mem_ptr member method pointer to invoke
@ -180,7 +180,7 @@ public:
* @returns an id for the scheduled event.
*/
template <typename T, typename T1, typename T2>
static EventId schedule (Time const &time, void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2);
static EventId Schedule (Time const &time, void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2);
/**
* @param time the expiration time of the event.
* @param mem_ptr member method pointer to invoke
@ -191,7 +191,7 @@ public:
* @returns an id for the scheduled event.
*/
template <typename T, typename T1, typename T2, typename T3>
static EventId schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3);
static EventId Schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3);
/**
* @param time the expiration time of the event.
* @param mem_ptr member method pointer to invoke
@ -203,7 +203,7 @@ public:
* @returns an id for the scheduled event.
*/
template <typename T, typename T1, typename T2, typename T3, typename T4>
static EventId schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3,T4), T* obj, T1 a1, T2 a2, T3 a3, T4 a4);
static EventId Schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3,T4), T* obj, T1 a1, T2 a2, T3 a3, T4 a4);
/**
* @param time the expiration time of the event.
* @param mem_ptr member method pointer to invoke
@ -216,14 +216,14 @@ public:
* @returns an id for the scheduled event.
*/
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
static EventId schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj,
static EventId Schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj,
T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
/**
* @param time the expiration time of the event.
* @param f the function to invoke
* @returns an id for the scheduled event.
*/
static EventId schedule (Time const &time, void (*f) (void));
static EventId Schedule (Time const &time, void (*f) (void));
/**
* @param time the expiration time of the event.
* @param f the function to invoke
@ -231,7 +231,7 @@ public:
* @returns an id for the scheduled event.
*/
template <typename T1>
static EventId schedule (Time const &time, void (*f) (T1), T1 a1);
static EventId Schedule (Time const &time, void (*f) (T1), T1 a1);
/**
* @param time the expiration time of the event.
* @param f the function to invoke
@ -240,7 +240,7 @@ public:
* @returns an id for the scheduled event.
*/
template <typename T1, typename T2>
static EventId schedule (Time const &time, void (*f) (T1,T2), T1 a1, T2 a2);
static EventId Schedule (Time const &time, void (*f) (T1,T2), T1 a1, T2 a2);
/**
* @param time the expiration time of the event.
* @param f the function to invoke
@ -250,7 +250,7 @@ public:
* @returns an id for the scheduled event.
*/
template <typename T1, typename T2, typename T3>
static EventId schedule (Time const &time, void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3);
static EventId Schedule (Time const &time, void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3);
/**
* @param time the expiration time of the event.
* @param f the function to invoke
@ -261,7 +261,7 @@ public:
* @returns an id for the scheduled event.
*/
template <typename T1, typename T2, typename T3, typename T4>
static EventId schedule (Time const &time, void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4);
static EventId Schedule (Time const &time, void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4);
/**
* @param time the expiration time of the event.
* @param f the function to invoke
@ -273,7 +273,7 @@ public:
* @returns an id for the scheduled event.
*/
template <typename T1, typename T2, typename T3, typename T4, typename T5>
static EventId schedule (Time const &time, void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
static EventId Schedule (Time const &time, void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
/**
* Remove an event from the event list.
* This method has the same visible effect as the
@ -285,7 +285,7 @@ public:
*
* @param id the event to remove from the list of scheduled events.
*/
static void remove (EventId id);
static void Remove (EventId id);
/**
* Set the cancel bit on this event: the event's associated function
* will not be invoked when it expires.
@ -298,7 +298,7 @@ public:
*
* @param id the event to cancel
*/
static void cancel (EventId id);
static void Cancel (EventId id);
/**
* This method has O(1) complexity.
* Note that it is not possible to test for the expiration of
@ -308,16 +308,16 @@ public:
* @param id the event to test for expiration
* @returns true if the event has expired, false otherwise.
*/
static bool isExpired (EventId id);
static bool IsExpired (EventId id);
/**
* Return the "current simulation time".
*/
static Time now (void);
static Time Now (void);
private:
Simulator ();
~Simulator ();
static SimulatorPrivate *getPriv (void);
static EventId schedule (Time const &time, EventImpl *event);
static SimulatorPrivate *GetPriv (void);
static EventId Schedule (Time const &time, EventImpl *event);
static SimulatorPrivate *m_priv;
static SchedulerFactory const*m_schedFactory;
static enum ListType {
@ -338,7 +338,7 @@ private:
namespace ns3 {
template <typename T>
EventId Simulator::schedule (Time const &time, void (T::*mem_ptr) (void), T *obj)
EventId Simulator::Schedule (Time const &time, void (T::*mem_ptr) (void), T *obj)
{
// zero argument version
class EventMemberImpl0 : public EventImpl {
@ -350,18 +350,18 @@ EventId Simulator::schedule (Time const &time, void (T::*mem_ptr) (void), T *obj
{}
virtual ~EventMemberImpl0 () {}
private:
virtual void notify (void) {
virtual void Notify (void) {
(m_obj->*m_function) ();
}
T* m_obj;
F m_function;
} *ev = new EventMemberImpl0 (obj, mem_ptr);
return schedule (time, ev);
return Schedule (time, ev);
}
template <typename T, typename T1>
EventId Simulator::schedule (Time const &time, void (T::*mem_ptr) (T1), T* obj, T1 a1)
EventId Simulator::Schedule (Time const &time, void (T::*mem_ptr) (T1), T* obj, T1 a1)
{
// one argument version
class EventMemberImpl1 : public EventImpl {
@ -375,18 +375,18 @@ EventId Simulator::schedule (Time const &time, void (T::*mem_ptr) (T1), T* obj,
protected:
virtual ~EventMemberImpl1 () {}
private:
virtual void notify (void) {
virtual void Notify (void) {
(m_obj->*m_function) (m_a1);
}
T* m_obj;
F m_function;
T1 m_a1;
} *ev = new EventMemberImpl1 (obj, mem_ptr, a1);
return schedule (time, ev);
return Schedule (time, ev);
}
template <typename T, typename T1, typename T2>
EventId Simulator::schedule (Time const &time, void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2)
EventId Simulator::Schedule (Time const &time, void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2)
{
// two argument version
class EventMemberImpl2 : public EventImpl {
@ -402,7 +402,7 @@ EventId Simulator::schedule (Time const &time, void (T::*mem_ptr) (T1,T2), T* ob
protected:
virtual ~EventMemberImpl2 () {}
private:
virtual void notify (void) {
virtual void Notify (void) {
(m_obj->*m_function) (m_a1, m_a2);
}
T* m_obj;
@ -411,11 +411,11 @@ EventId Simulator::schedule (Time const &time, void (T::*mem_ptr) (T1,T2), T* ob
T2 m_a2;
} *ev = new EventMemberImpl2 (obj, mem_ptr, a1, a2);
return schedule (time, ev);
return Schedule (time, ev);
}
template <typename T, typename T1, typename T2, typename T3>
EventId Simulator::schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3)
EventId Simulator::Schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3)
{
// three argument version
class EventMemberImpl3 : public EventImpl {
@ -432,7 +432,7 @@ EventId Simulator::schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3), T*
protected:
virtual ~EventMemberImpl3 () {}
private:
virtual void notify (void) {
virtual void Notify (void) {
(m_obj->*m_function) (m_a1, m_a2, m_a3);
}
T* m_obj;
@ -441,11 +441,11 @@ EventId Simulator::schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3), T*
T2 m_a2;
T3 m_a3;
} *ev = new EventMemberImpl3 (obj, mem_ptr, a1, a2, a3);
return schedule (time, ev);
return Schedule (time, ev);
}
template <typename T, typename T1, typename T2, typename T3, typename T4>
EventId Simulator::schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3,T4), T* obj, T1 a1, T2 a2, T3 a3, T4 a4)
EventId Simulator::Schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3,T4), T* obj, T1 a1, T2 a2, T3 a3, T4 a4)
{
// four argument version
class EventMemberImpl4 : public EventImpl {
@ -463,7 +463,7 @@ EventId Simulator::schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3,T4),
protected:
virtual ~EventMemberImpl4 () {}
private:
virtual void notify (void) {
virtual void Notify (void) {
(m_obj->*m_function) (m_a1, m_a2, m_a3, m_a4);
}
T* m_obj;
@ -473,11 +473,11 @@ EventId Simulator::schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3,T4),
T3 m_a3;
T4 m_a4;
} *ev = new EventMemberImpl4 (obj, mem_ptr, a1, a2, a3, a4);
return schedule (time, ev);
return Schedule (time, ev);
}
template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
EventId Simulator::schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj,
EventId Simulator::Schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj,
T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
{
// five argument version
@ -497,7 +497,7 @@ EventId Simulator::schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3,T4,T
protected:
virtual ~EventMemberImpl5 () {}
private:
virtual void notify (void) {
virtual void Notify (void) {
(m_obj->*m_function) (m_a1, m_a2, m_a3, m_a4, m_a5);
}
T* m_obj;
@ -508,11 +508,11 @@ EventId Simulator::schedule (Time const &time, void (T::*mem_ptr) (T1,T2,T3,T4,T
T4 m_a4;
T5 m_a5;
} *ev = new EventMemberImpl5 (obj, mem_ptr, a1, a2, a3, a4, a5);
return schedule (time, ev);
return Schedule (time, ev);
}
template <typename T1>
EventId Simulator::schedule (Time const &time, void (*f) (T1), T1 a1)
EventId Simulator::Schedule (Time const &time, void (*f) (T1), T1 a1)
{
// one arg version
class EventFunctionImpl1 : public EventImpl {
@ -526,17 +526,17 @@ EventId Simulator::schedule (Time const &time, void (*f) (T1), T1 a1)
protected:
virtual ~EventFunctionImpl1 () {}
private:
virtual void notify (void) {
virtual void Notify (void) {
(*m_function) (m_a1);
}
F m_function;
T1 m_a1;
} *ev = new EventFunctionImpl1(f, a1);
return schedule (time, ev);
return Schedule (time, ev);
}
template <typename T1, typename T2>
EventId Simulator::schedule (Time const &time, void (*f) (T1,T2), T1 a1, T2 a2)
EventId Simulator::Schedule (Time const &time, void (*f) (T1,T2), T1 a1, T2 a2)
{
// two arg version
class EventFunctionImpl2 : public EventImpl {
@ -551,18 +551,18 @@ EventId Simulator::schedule (Time const &time, void (*f) (T1,T2), T1 a1, T2 a2)
protected:
virtual ~EventFunctionImpl2 () {}
private:
virtual void notify (void) {
virtual void Notify (void) {
(*m_function) (m_a1, m_a2);
}
F m_function;
T1 m_a1;
T2 m_a2;
} *ev = new EventFunctionImpl2 (f, a1, a2);
return schedule (time, ev);
return Schedule (time, ev);
}
template <typename T1, typename T2, typename T3>
EventId Simulator::schedule (Time const &time, void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3)
EventId Simulator::Schedule (Time const &time, void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3)
{
// three arg version
class EventFunctionImpl3 : public EventImpl {
@ -578,7 +578,7 @@ EventId Simulator::schedule (Time const &time, void (*f) (T1,T2,T3), T1 a1, T2 a
protected:
virtual ~EventFunctionImpl3 () {}
private:
virtual void notify (void) {
virtual void Notify (void) {
(*m_function) (m_a1, m_a2, m_a3);
}
F m_function;
@ -586,11 +586,11 @@ EventId Simulator::schedule (Time const &time, void (*f) (T1,T2,T3), T1 a1, T2 a
T2 m_a2;
T3 m_a3;
} *ev = new EventFunctionImpl3 (f, a1, a2, a3);
return schedule (time, ev);
return Schedule (time, ev);
}
template <typename T1, typename T2, typename T3, typename T4>
EventId Simulator::schedule (Time const &time, void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4)
EventId Simulator::Schedule (Time const &time, void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4)
{
// four arg version
class EventFunctionImpl4 : public EventImpl {
@ -607,7 +607,7 @@ EventId Simulator::schedule (Time const &time, void (*f) (T1,T2,T3,T4), T1 a1, T
protected:
virtual ~EventFunctionImpl4 () {}
private:
virtual void notify (void) {
virtual void Notify (void) {
(*m_function) (m_a1, m_a2, m_a3, m_a4);
}
F m_function;
@ -616,11 +616,11 @@ EventId Simulator::schedule (Time const &time, void (*f) (T1,T2,T3,T4), T1 a1, T
T3 m_a3;
T4 m_a4;
} *ev = new EventFunctionImpl4 (f, a1, a2, a3, a4);
return schedule (time, ev);
return Schedule (time, ev);
}
template <typename T1, typename T2, typename T3, typename T4, typename T5>
static EventId schedule (Time const &time, void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
static EventId Schedule (Time const &time, void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
{
// five arg version
class EventFunctionImpl5 : public EventImpl {
@ -638,7 +638,7 @@ static EventId schedule (Time const &time, void (*f) (T1,T2,T3,T4,T5), T1 a1, T2
protected:
virtual ~EventFunctionImpl5 () {}
private:
virtual void notify (void) {
virtual void Notify (void) {
(*m_function) (m_a1, m_a2, m_a3, m_a4, m_a5);
}
F m_function;
@ -648,7 +648,7 @@ static EventId schedule (Time const &time, void (*f) (T1,T2,T3,T4,T5), T1 a1, T2
T4 m_a4;
T5 m_a5;
} *ev = new EventFunctionImpl5 (f, a1, a2, a3, a4, a5);
return schedule (time, ev);
return Schedule (time, ev);
}
}; // namespace ns3

32
src/simulator/time.cc

@ -44,72 +44,72 @@ Time::Time (uint64_t ns)
{}
double
Time::s (void) const
Time::S (void) const
{
double ns = m_ns;
ns /= 1000000000;
return ns;
}
uint64_t
Time::us (void) const
Time::Us (void) const
{
uint64_t us = m_ns / 1000;
return us;
}
uint64_t
Time::ns (void) const
Time::Ns (void) const
{
return m_ns;
}
bool
Time::isDestroy (void) const
Time::IsDestroy (void) const
{
return m_isDestroy;
}
Time
Time::absS (double s)
Time::AbsS (double s)
{
int64_t ns = (int64_t)(s * 1000000000.0);
return Time (ns);
}
Time
Time::absUs (uint64_t us)
Time::AbsUs (uint64_t us)
{
int64_t ns = us * 1000;
return Time (ns);
}
Time
Time::absNs (uint64_t ns)
Time::AbsNs (uint64_t ns)
{
return Time (ns);
}
Time
Time::relS (double s)
Time::RelS (double s)
{
int64_t ns = (int64_t)(s * 1000000000.0);
return Time (Simulator::now ().ns () + ns);
return Time (Simulator::Now ().Ns () + ns);
}
Time
Time::relUs (uint64_t us)
Time::RelUs (uint64_t us)
{
return Time (Simulator::now ().ns () + us * 1000);
return Time (Simulator::Now ().Ns () + us * 1000);
}
Time
Time::relNs (uint64_t ns)
Time::RelNs (uint64_t ns)
{
return Time (Simulator::now ().ns () + ns);
return Time (Simulator::Now ().Ns () + ns);
}
Time
Time::now (void)
Time::Now (void)
{
return Time (Simulator::now ().ns ());
return Time (Simulator::Now ().Ns ());
}
Time
Time::destroy (void)
Time::Destroy (void)
{
return Time ();
}

46
utils/bench-simulator.cc

@ -32,11 +32,11 @@ bool gDebug = false;
class Bench {
public:
void readDistribution (std::istream &istream);
void setTotal (uint32_t total);
void bench (void);
void ReadDistribution (std::istream &istream);
void SetTotal (uint32_t total);
void RunBench (void);
private:
void cb (void);
void Cb (void);
std::vector<uint64_t> m_distribution;
std::vector<uint64_t>::const_iterator m_current;
uint32_t m_n;
@ -44,13 +44,13 @@ private:
};
void
Bench::setTotal (uint32_t total)
Bench::SetTotal (uint32_t total)
{
m_total = total;
}
void
Bench::readDistribution (std::istream &input)
Bench::ReadDistribution (std::istream &input)
{
double data;
while (!input.eof ()) {
@ -66,22 +66,22 @@ Bench::readDistribution (std::istream &input)
}
void
Bench::bench (void)
Bench::RunBench (void)
{
SystemWallClockMs time;
double init, simu;
time.start ();
time.Start ();
for (std::vector<uint64_t>::const_iterator i = m_distribution.begin ();
i != m_distribution.end (); i++) {
Simulator::schedule (Time::absNs (*i), &Bench::cb, this);
Simulator::Schedule (Time::AbsNs (*i), &Bench::Cb, this);
}
init = time.end ();
init = time.End ();
m_current = m_distribution.begin ();
time.start ();
Simulator::run ();
simu = time.end ();
time.Start ();
Simulator::Run ();
simu = time.End ();
std::cout <<
"init n=" << m_distribution.size () << ", time=" << init << "s" << std::endl <<
@ -94,7 +94,7 @@ Bench::bench (void)
}
void
Bench::cb (void)
Bench::Cb (void)
{
if (m_n > m_total) {
return;
@ -103,9 +103,9 @@ Bench::cb (void)
m_current = m_distribution.begin ();
}
if (gDebug) {
std::cerr << "event at " << Simulator::now ().s () << "s" << std::endl;
std::cerr << "event at " << Simulator::Now ().S () << "s" << std::endl;
}
Simulator::schedule (Time::absNs (*m_current), &Bench::cb, this);
Simulator::Schedule (Time::AbsNs (*m_current), &Bench::Cb, this);
m_current++;
m_n++;
}
@ -123,24 +123,24 @@ int main (int argc, char *argv[])
}
while (argc > 0) {
if (strcmp ("--list", argv[0]) == 0) {
Simulator::setLinkedList ();
Simulator::SetLinkedList ();
} else if (strcmp ("--heap", argv[0]) == 0) {
Simulator::setBinaryHeap ();
Simulator::SetBinaryHeap ();
} else if (strcmp ("--map", argv[0]) == 0) {
Simulator::setStdMap ();
Simulator::SetStdMap ();
} else if (strcmp ("--debug", argv[0]) == 0) {
gDebug = true;
} else if (strncmp ("--log=", argv[0],strlen ("--log=")) == 0) {
char const *filename = argv[0] + strlen ("--log=");
Simulator::enableLogTo (filename);
Simulator::EnableLogTo (filename);
}
argc--;
argv++;
}
Bench *bench = new Bench ();
bench->readDistribution (*input);
bench->setTotal (20000);
bench->bench ();
bench->ReadDistribution (*input);
bench->SetTotal (20000);
bench->RunBench ();
return 0;
}

30
utils/replay-simulation.cc

@ -77,7 +77,7 @@ typedef std::vector<std::pair<uint32_t, uint32_t> > Removes;
typedef std::vector<std::pair<uint32_t, uint32_t> >::iterator RemovesI;
void
LogReader::readFrom_filename (char const *filename)
LogReader::ReadFrom_filename (char const *filename)
{
std::ifstream log;
std::cout << "read log..." << std::endl;
@ -103,7 +103,7 @@ LogReader::readFrom_filename (char const *filename)
cmd.m_type = Command::REMOVE;
cmd.m_uid = nowUid;
m_commands.push_back (cmd);
removes.push_back (std::make_pair (nowUid, evUid));
removes.push_back (std::Make_pair (nowUid, evUid));
} else if (type == "il") {
uint32_t nowUid, evUid;
uint64_t nowUs, evUs;
@ -150,7 +150,7 @@ LogReader::readFrom_filename (char const *filename)
}
}
void
LogReader::executeLogCommands (uint32_t uid)
LogReader::ExecuteLogCommands (uint32_t uid)
{
if (m_command == m_commands.end ()) {
return;
@ -162,27 +162,27 @@ LogReader::executeLogCommands (uint32_t uid)
m_command++;
switch (cmd.m_type) {
case Command::INSERT:
//std::cout << "exec insert now=" << Simulator::nowUs ()
//std::Cout << "exec insert now=" << Simulator::nowUs ()
//<< ", time=" << cmd.insert.m_evUs << std::endl;
Simulator::scheduleAbsUs (cmd.insert.m_evUs,
Simulator::ScheduleAbsUs (cmd.insert.m_evUs,
makeEvent (&LogReader::executeLogCommands, this, m_uid));
m_uid++;
break;
case Command::INSERT_LATER:
//std::cout << "exec insert later" << std::endl;
Simulator::scheduleNow (makeEvent (&LogReader::executeLogCommands, this, m_uid));
Simulator::ScheduleNow (makeEvent (&LogReader::executeLogCommands, this, m_uid));
m_uid++;
break;
case Command::REMOVE: {
//std::cout << "exec remove" << std::endl;
Event ev = m_removeEvents.front ();
m_removeEvents.pop_front ();
Simulator::remove (ev);
Simulator::Remove (ev);
} break;
case Command::INSERT_REMOVE: {
//std::cout << "exec insert remove" << std::endl;
Event ev = makeEvent (&LogReader::executeLogCommands, this, m_uid);
Simulator::scheduleAbsUs (cmd.insertRemove.m_evUs, ev);
Simulator::ScheduleAbsUs (cmd.insertRemove.m_evUs, ev);
m_removeEvents[cmd.insertRemove.m_evLoc] = ev;
m_uid++;
} break;
@ -192,7 +192,7 @@ LogReader::executeLogCommands (uint32_t uid)
}
void
LogReader::printStats (void)
LogReader::PrintStats (void)
{
uint32_t nInserts = 0;
uint32_t nRemoves = 0;
@ -217,14 +217,14 @@ LogReader::printStats (void)
}
void
LogReader::run (void)
LogReader::Run (void)
{
m_uid = 0;
WallClockMs time;
time.start ();
m_command = m_commands.begin ();
executeLogCommands (m_uid);
Simulator::run ();
Simulator::Run ();
unsigned long long delta = time.end ();
double delay = ((double)delta)/1000;
std::cout << "runtime="<<delay<<"s"<<std::endl;
@ -237,18 +237,18 @@ int main (int argc, char *argv[])
uint32_t n = 1;
while (argc > 0) {
if (strcmp ("--list", argv[0]) == 0) {
Simulator::setLinkedList ();
Simulator::SetLinkedList ();
} else if (strcmp ("--heap", argv[0]) == 0) {
Simulator::setBinaryHeap ();
Simulator::SetBinaryHeap ();
} else if (strcmp ("--map", argv[0]) == 0) {
Simulator::setStdMap ();
Simulator::SetStdMap ();
} else if (strncmp ("--n=", argv[0], strlen("--n=")) == 0) {
n = atoi (argv[0]+strlen ("--n="));
} else if (strncmp ("--input=", argv[0],strlen ("--input=")) == 0) {
input = argv[0] + strlen ("--input=");
} else if (strncmp ("--log=", argv[0],strlen ("--log=")) == 0) {
char const *filename = argv[0] + strlen ("--log=");
Simulator::enableLogTo (filename);
Simulator::EnableLogTo (filename);
}
argc--;
argv++;

4
utils/run-tests.cc

@ -24,8 +24,8 @@
int main (int argc, char *argv[])
{
#ifdef RUN_SELF_TESTS
ns3::TestManager::enableVerbose ();
ns3::TestManager::runTests ();
ns3::TestManager::EnableVerbose ();
ns3::TestManager::RunTests ();
#endif /* RUN_SELF_TESTS */
return 0;

Loading…
Cancel
Save