Browse Source

variable/method/function coding style update

ndnSIM-v1
Mathieu Lacage 19 years ago
parent
commit
e57dd3faa5
  1. 38
      samples/main-callback.cc
  2. 42
      samples/main-packet.cc
  3. 10
      samples/main-simulator.cc
  4. 32
      samples/main-trace.cc
  5. 326
      src/common/buffer.cc
  6. 164
      src/common/buffer.h
  7. 14
      src/common/callback-tracer.h
  8. 16
      src/common/chunk-constant-data.cc
  9. 6
      src/common/chunk-constant-data.h
  10. 6
      src/common/chunk.cc
  11. 6
      src/common/chunk.h
  12. 10
      src/common/data-writer.cc
  13. 8
      src/common/f-variable-tracer.h
  14. 56
      src/common/packet.cc
  15. 30
      src/common/packet.h
  16. 12
      src/common/pcap-writer.cc
  17. 6
      src/common/pcap-writer.h
  18. 8
      src/common/si-variable-tracer.h
  19. 8
      src/common/stream-tracer-test.cc
  20. 2
      src/common/stream-tracer.h
  21. 150
      src/common/tags.cc
  22. 72
      src/common/tags.h
  23. 26
      src/common/trace-container.cc
  24. 50
      src/common/trace-container.h
  25. 10
      src/common/ui-variable-tracer.h
  26. 22
      src/common/variable-tracer-test.cc
  27. 52
      src/core/callback-test.cc
  28. 154
      src/core/callback.h
  29. 6
      src/core/reference-list-test.cc
  30. 24
      src/core/reference-list.h
  31. 24
      src/core/test.cc
  32. 8
      src/core/test.h
  33. 10
      src/core/unix-system-file.cc
  34. 10
      src/simulator/event-id.cc
  35. 8
      src/simulator/event-id.h
  36. 4
      src/simulator/event-impl.cc
  37. 4
      src/simulator/event-impl.h
  38. 2
      src/simulator/scheduler-factory.cc
  39. 4
      src/simulator/scheduler-factory.h
  40. 86
      src/simulator/scheduler-heap.cc
  41. 30
      src/simulator/scheduler-heap.h
  42. 46
      src/simulator/scheduler-list.cc
  43. 18
      src/simulator/scheduler-list.h
  44. 32
      src/simulator/scheduler-map.cc
  45. 18
      src/simulator/scheduler-map.h
  46. 32
      src/simulator/scheduler.cc
  47. 40
      src/simulator/scheduler.h
  48. 122
      src/simulator/simulator.cc
  49. 24
      src/simulator/simulator.h
  50. 14
      src/simulator/time.cc
  51. 14
      src/simulator/time.h
  52. 30
      utils/bench-packets.cc
  53. 30
      utils/bench-simulator.cc
  54. 90
      utils/replay-simulation.cc
  55. 4
      utils/run-tests.cc

38
samples/main-callback.cc

@ -6,16 +6,16 @@
using namespace ns3;
static double
cb_one (double a, double b)
cbOne (double a, double b)
{
std::cout << "invoke cb_one a=" << a << ", b=" << b << std::endl;
std::cout << "invoke cbOne a=" << a << ", b=" << b << std::endl;
return a;
}
class MyCb {
public:
int cb_two (double a) {
std::cout << "invoke cb_two a=" << a << std::endl;
int cbTwo (double a) {
std::cout << "invoke cbTwo a=" << a << std::endl;
return -5;
}
};
@ -27,32 +27,32 @@ int main (int argc, char *argv[])
// first arg type: double
// second arg type: double
Callback<double, double, double> one;
// build callback instance which points to cb_one function
one = make_callback (&cb_one);
// build callback instance which points to cbOne function
one = makeCallback (&cbOne);
// this is not a null callback
assert (!one.is_null ());
// invoke cb_one function through callback instance
double ret_one;
ret_one = one (10.0, 20.0);
assert (!one.isNull ());
// invoke cbOne function through callback instance
double retOne;
retOne = one (10.0, 20.0);
// return type: int
// first arg type: double
Callback<int, double> two;
MyCb cb;
// build callback instance which points to MyCb::cb_two
two = make_callback (&MyCb::cb_two, &cb);
// build callback instance which points to MyCb::cbTwo
two = makeCallback (&MyCb::cbTwo, &cb);
// this is not a null callback
assert (!two.is_null ());
// invoke MyCb::cb_two through callback instance
int ret_two;
ret_two = two (10.0);
assert (!two.isNull ());
// invoke MyCb::cbTwo through callback instance
int retTwo;
retTwo = two (10.0);
two = make_null_callback<int, double> ();
two = makeNullCallback<int, double> ();
// invoking a null callback is just like
// invoking a null function pointer:
// it will crash.
//int ret_two_null = two (20.0);
assert (two.is_null ());
//int retTwoNull = two (20.0);
assert (two.isNull ());
return 0;
}

42
samples/main-packet.cc

@ -12,13 +12,13 @@ public:
MyChunk ();
virtual ~MyChunk ();
void set_data (uint16_t data);
uint16_t get_data (void) const;
void setData (uint16_t data);
uint16_t getData (void) const;
private:
virtual void print (std::ostream *os) const;
virtual void add_to (Buffer *buffer) const;
virtual void peek_from (Buffer const *buffer);
virtual void remove_from (Buffer *buffer);
virtual void addTo (Buffer *buffer) const;
virtual void peekFrom (Buffer const *buffer);
virtual void removeFrom (Buffer *buffer);
uint16_t m_data;
};
@ -33,35 +33,35 @@ MyChunk::print (std::ostream *os) const
*os << "MyChunk data=" << m_data << std::endl;
}
void
MyChunk::add_to (Buffer *buffer) const
MyChunk::addTo (Buffer *buffer) const
{
// reserve 2 bytes at head of buffer
buffer->add_at_start (2);
buffer->addAtStart (2);
Buffer::Iterator i = buffer->begin ();
// serialize in head of buffer
i.write_hton_u16 (m_data);
i.writeHtonU16 (m_data);
}
void
MyChunk::peek_from (Buffer const *buffer)
MyChunk::peekFrom (Buffer const *buffer)
{
Buffer::Iterator i = buffer->begin ();
// deserialize from head of buffer
m_data = i.read_ntoh_u16 ();
m_data = i.readNtohU16 ();
}
void
MyChunk::remove_from (Buffer *buffer)
MyChunk::removeFrom (Buffer *buffer)
{
// remove deserialized data
buffer->remove_at_start (2);
buffer->removeAtStart (2);
}
void
MyChunk::set_data (uint16_t data)
MyChunk::setData (uint16_t data)
{
m_data = data;
}
uint16_t
MyChunk::get_data (void) const
MyChunk::getData (void) const
{
return m_data;
}
@ -79,9 +79,9 @@ receive (Packet p)
MyChunk my;
p.peek (&my);
p.remove (&my);
std::cout << "received data=" << my.get_data () << std::endl;
struct MyTag my_tag;
p.peek_tag (&my_tag);
std::cout << "received data=" << my.getData () << std::endl;
struct MyTag myTag;
p.peekTag (&myTag);
}
@ -89,12 +89,12 @@ int main (int argc, char *argv[])
{
Packet p;
MyChunk my;
my.set_data (2);
my.setData (2);
std::cout << "send data=2" << std::endl;
p.add (&my);
struct MyTag my_tag;
my_tag.m_streamId = 5;
p.add_tag (&my_tag);
struct MyTag myTag;
myTag.m_streamId = 5;
p.addTag (&myTag);
receive (p);
return 0;
}

10
samples/main-simulator.cc

@ -9,18 +9,18 @@ class MyModel {
public:
void start (void);
private:
void deal_with_event (double event_value);
void dealWithEvent (double eventValue);
};
void
MyModel::start (void)
{
Simulator::schedule (Time::rel_s (10.0),
&MyModel::deal_with_event,
Simulator::schedule (Time::relS (10.0),
&MyModel::dealWithEvent,
this, Simulator::now ().s ());
}
void
MyModel::deal_with_event (double value)
MyModel::dealWithEvent (double value)
{
std::cout << "Member method received event at " << Simulator::now ().s () <<
"s started at " << value << "s" << std::endl;
@ -39,7 +39,7 @@ int main (int argc, char *argv[])
{
MyModel model;
Simulator::schedule (Time::abs_s (10.0), &random_function, &model);
Simulator::schedule (Time::absS (10.0), &random_function, &model);
Simulator::run ();

32
samples/main-trace.cc

@ -15,15 +15,15 @@ StreamTracer c;
CallbackTracer<double, int> d;
void
register_all_trace_sources (TraceContainer *container)
registerAllTraceSources (TraceContainer *container)
{
container->register_callback ("source-a", &a);
container->register_ui_variable ("source-b", &b);
container->register_stream ("source-c", &c);
container->register_callback ("source-d", &d);
container->registerCallback ("source-a", &a);
container->registerUiVariable ("source-b", &b);
container->registerStream ("source-c", &c);
container->registerCallback ("source-d", &d);
}
void
generate_trace_events (void)
generateTraceEvents (void)
{
// log en empty packet
a (Packet ());
@ -36,26 +36,26 @@ generate_trace_events (void)
}
void
variable_event (uint64_t old, uint64_t cur)
variableEvent (uint64_t old, uint64_t cur)
{}
void
callback_event (double a, int b)
callbackEvent (double a, int b)
{}
int main (int argc, char *argv[])
{
TraceContainer traces;
register_all_trace_sources (&traces);
registerAllTraceSources (&traces);
PcapWriter pcap;
pcap.open ("trace-test.log");
pcap.write_header_ethernet ();
traces.set_callback ("source-a",
make_callback (&PcapWriter::write_packet, &pcap));
traces.set_ui_variable_callback ("source-b", make_callback (&variable_event));
traces.set_stream ("source-c", &std::cout);
traces.set_callback ("source-d", make_callback (&callback_event));
generate_trace_events ();
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;
}

326
src/common/buffer.cc

@ -32,18 +32,18 @@ uint32_t Buffer::m_maxTotalAddStart = 0;
uint32_t Buffer::m_maxTotalAddEnd = 0;
struct Buffer::BufferData *
Buffer::allocate (uint32_t req_size, uint32_t req_start)
Buffer::allocate (uint32_t reqSize, uint32_t reqStart)
{
if (req_size == 0) {
req_size = 1;
if (reqSize == 0) {
reqSize = 1;
}
assert (req_size >= 1);
uint32_t size = req_size - 1 + sizeof (struct Buffer::BufferData);
assert (reqSize >= 1);
uint32_t size = reqSize - 1 + sizeof (struct Buffer::BufferData);
uint8_t *b = new uint8_t [size];
struct BufferData *data = reinterpret_cast<struct Buffer::BufferData*>(b);
data->m_size = req_size;
data->m_initialStart = req_start;
data->m_dirtyStart = req_start;
data->m_size = reqSize;
data->m_initialStart = reqStart;
data->m_dirtyStart = reqStart;
data->m_dirtySize = 0;
data->m_count = 1;
return data;
@ -118,45 +118,45 @@ namespace ns3 {
void
Buffer::add_at_start (uint32_t start)
Buffer::addAtStart (uint32_t start)
{
assert (m_start <= m_data->m_initialStart);
bool is_dirty = m_data->m_count > 1 && m_start > m_data->m_dirtyStart;
if (m_start >= start && !is_dirty) {
bool isDirty = m_data->m_count > 1 && m_start > m_data->m_dirtyStart;
if (m_start >= start && !isDirty) {
/* enough space in the buffer and not dirty. */
m_start -= start;
m_size += start;
} else if (m_size + start <= m_data->m_size && !is_dirty) {
} 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, get_start (), 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;
} else if (m_start < start) {
/* not enough space in buffer */
uint32_t new_size = m_size + start;
struct Buffer::BufferData *new_data = Buffer::allocate (new_size, 0);
memcpy (new_data->m_data + start, get_start (), m_size);
new_data->m_initialStart = m_data->m_initialStart + start;
uint32_t newSize = m_size + start;
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);
}
m_data = new_data;
m_data = newData;
m_start = 0;
m_size = new_size;
m_size = newSize;
} else {
/* enough space in the buffer but it is dirty ! */
assert (is_dirty);
struct Buffer::BufferData *new_data = Buffer::create ();
memcpy (new_data->m_data + m_start, get_start (), m_size);
new_data->m_initialStart = m_data->m_initialStart;
assert (isDirty);
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);
}
m_data = new_data;
m_data = newData;
m_start -= start;
m_size += start;
}
@ -164,75 +164,75 @@ Buffer::add_at_start (uint32_t start)
m_data->m_dirtyStart = m_start;
m_data->m_dirtySize = m_size;
// update m_maxTotalAddStart
uint32_t added_at_start;
uint32_t addedAtStart;
if (m_data->m_initialStart > m_start) {
added_at_start = m_data->m_initialStart - m_start;
addedAtStart = m_data->m_initialStart - m_start;
} else {
added_at_start = 0;
addedAtStart = 0;
}
if (added_at_start > m_maxTotalAddStart) {
m_maxTotalAddStart = added_at_start;
if (addedAtStart > m_maxTotalAddStart) {
m_maxTotalAddStart = addedAtStart;
}
TRACE ("start add="<<start<<", start="<<m_start<<", size="<<m_size<<", zero="<<m_zeroAreaSize<<
", real size="<<m_data->m_size<<", ini start="<<m_data->m_initialStart<<
", dirty start="<<m_data->m_dirtyStart<<", dirty size="<<m_data->m_dirtySize);
}
void
Buffer::add_at_end (uint32_t end)
Buffer::addAtEnd (uint32_t end)
{
assert (m_start <= m_data->m_initialStart);
bool is_dirty = m_data->m_count > 1 &&
bool isDirty = m_data->m_count > 1 &&
m_start + m_size < m_data->m_dirtyStart + m_data->m_dirtySize;
if (m_start + m_size + end <= m_data->m_size && !is_dirty) {
if (m_start + m_size + end <= m_data->m_size && !isDirty) {
/* enough space in buffer and not dirty */
m_size += end;
} else if (m_size + end <= m_data->m_size && !is_dirty) {
} 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 new_start = m_data->m_size - (m_size + end);
memmove (m_data->m_data + new_start, get_start (), m_size);
assert (new_start < m_start);
m_data->m_initialStart -= m_start - new_start;
m_start = new_start;
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;
} else if (m_start + m_size + end > m_data->m_size) {
/* not enough space in buffer */
uint32_t new_size = m_size + end;
struct Buffer::BufferData *new_data = Buffer::allocate (new_size, 0);
memcpy (new_data->m_data, get_start (), m_size);
new_data->m_initialStart = m_data->m_initialStart;
uint32_t newSize = m_size + end;
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);
}
m_data = new_data;
m_size = new_size;
m_data = newData;
m_size = newSize;
m_start = 0;
} else {
/* enough space in the buffer but it is dirty ! */
assert (is_dirty);
struct Buffer::BufferData *new_data = Buffer::create ();
memcpy (new_data->m_data + m_start, get_start (), m_size);
new_data->m_initialStart = m_data->m_initialStart;
assert (isDirty);
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);
}
m_data = new_data;
m_data = newData;
m_size += end;
}
// update dirty area
m_data->m_dirtyStart = m_start;
m_data->m_dirtySize = m_size;
// update m_maxTotalAddEnd
uint32_t end_loc = m_start + m_size;
uint32_t added_at_end;
if (m_data->m_initialStart < end_loc) {
added_at_end = end_loc - m_data->m_initialStart;
uint32_t endLoc = m_start + m_size;
uint32_t addedAtEnd;
if (m_data->m_initialStart < endLoc) {
addedAtEnd = endLoc - m_data->m_initialStart;
} else {
added_at_end = 0;
addedAtEnd = 0;
}
if (added_at_end > m_maxTotalAddEnd) {
m_maxTotalAddEnd = added_at_end;
if (addedAtEnd > m_maxTotalAddEnd) {
m_maxTotalAddEnd = addedAtEnd;
}
TRACE ("end add="<<end<<", start="<<m_start<<", size="<<m_size<<", zero="<<m_zeroAreaSize<<
", real size="<<m_data->m_size<<", ini start="<<m_data->m_initialStart<<
@ -240,7 +240,7 @@ Buffer::add_at_end (uint32_t end)
}
void
Buffer::remove_at_start (uint32_t start)
Buffer::removeAtStart (uint32_t start)
{
if (m_zeroAreaSize == 0) {
if (m_size <= start) {
@ -252,21 +252,21 @@ Buffer::remove_at_start (uint32_t start)
}
} else {
assert (m_data->m_initialStart >= m_start);
uint32_t zero_start = m_data->m_initialStart - m_start;
uint32_t zero_end = zero_start + m_zeroAreaSize;
uint32_t data_end = m_size + m_zeroAreaSize;
if (start <= zero_start) {
uint32_t zeroStart = m_data->m_initialStart - m_start;
uint32_t zeroEnd = zeroStart + m_zeroAreaSize;
uint32_t dataEnd = m_size + m_zeroAreaSize;
if (start <= zeroStart) {
/* only remove start of buffer */
m_start += start;
m_size -= start;
} else if (start <= zero_end) {
} else if (start <= zeroEnd) {
/* remove start of buffer _and_ start of zero area */
m_start += zero_start;
uint32_t zero_delta = start - zero_start;
m_zeroAreaSize -= zero_delta;
assert (zero_delta <= start);
m_size -= zero_start;
} else if (start <= data_end) {
m_start += zeroStart;
uint32_t zeroDelta = start - zeroStart;
m_zeroAreaSize -= zeroDelta;
assert (zeroDelta <= start);
m_size -= zeroStart;
} else if (start <= dataEnd) {
/* remove start of buffer, complete zero area, and part
* of end of buffer */
m_start += start - m_zeroAreaSize;
@ -284,7 +284,7 @@ Buffer::remove_at_start (uint32_t start)
", dirty start="<<m_data->m_dirtyStart<<", dirty size="<<m_data->m_dirtySize);
}
void
Buffer::remove_at_end (uint32_t end)
Buffer::removeAtEnd (uint32_t end)
{
if (m_zeroAreaSize == 0) {
if (m_size <= end) {
@ -294,26 +294,26 @@ Buffer::remove_at_end (uint32_t end)
}
} else {
assert (m_data->m_initialStart >= m_start);
uint32_t zero_start = m_data->m_initialStart - m_start;
uint32_t zero_end = zero_start + m_zeroAreaSize;
uint32_t data_end = m_size + m_zeroAreaSize;
assert (zero_start <= m_size);
assert (zero_end <= m_size + m_zeroAreaSize);
if (data_end <= end) {
uint32_t zeroStart = m_data->m_initialStart - m_start;
uint32_t zeroEnd = zeroStart + m_zeroAreaSize;
uint32_t dataEnd = m_size + m_zeroAreaSize;
assert (zeroStart <= m_size);
assert (zeroEnd <= m_size + m_zeroAreaSize);
if (dataEnd <= end) {
/* remove all buffer */
m_zeroAreaSize = 0;
m_start += m_size;
m_size = 0;
} else if (data_end - zero_start <= end) {
} else if (dataEnd - zeroStart <= end) {
/* remove end of buffer, zero area, part of start of buffer */
assert (end >= m_zeroAreaSize);
m_size -= end - m_zeroAreaSize;
m_zeroAreaSize = 0;
} else if (data_end - zero_end <= end) {
} else if (dataEnd - zeroEnd <= end) {
/* remove end of buffer, part of zero area */
uint32_t zero_delta = end - (data_end - zero_end);
m_zeroAreaSize -= zero_delta;
m_size -= end - zero_delta;
uint32_t zeroDelta = end - (dataEnd - zeroEnd);
m_zeroAreaSize -= zeroDelta;
m_size -= end - zeroDelta;
} else {
/* remove part of end of buffer */
m_size -= end;
@ -325,18 +325,18 @@ Buffer::remove_at_end (uint32_t end)
}
Buffer
Buffer::create_fragment (uint32_t start, uint32_t length) const
Buffer::createFragment (uint32_t start, uint32_t length) const
{
uint32_t zero_start = m_data->m_initialStart - m_start;
uint32_t zero_end = zero_start + m_zeroAreaSize;
uint32_t zeroStart = m_data->m_initialStart - m_start;
uint32_t zeroEnd = zeroStart + m_zeroAreaSize;
if (m_zeroAreaSize != 0 &&
start + length > zero_start &&
start <= zero_end) {
start + length > zeroStart &&
start <= zeroEnd) {
transform_intoRealBuffer ();
}
Buffer tmp = *this;
tmp.remove_at_start (start);
tmp.remove_at_end (get_size () - (start + length));
tmp.removeAtStart (start);
tmp.removeAtEnd (getSize () - (start + length));
return tmp;
}
@ -347,23 +347,23 @@ Buffer::transform_intoRealBuffer (void) const
assert (m_data->m_initialStart >= m_start);
assert (m_size >= (m_data->m_initialStart - m_start));
Buffer tmp;
tmp.add_at_start (m_zeroAreaSize);
tmp.begin ().write_u8 (0, m_zeroAreaSize);
uint32_t data_start = m_data->m_initialStart - m_start;
tmp.add_at_start (data_start);
tmp.begin ().write (m_data->m_data+m_start, data_start);
uint32_t data_end = m_size - (m_data->m_initialStart - m_start);
tmp.add_at_end (data_end);
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);
uint32_t dataEnd = m_size - (m_data->m_initialStart - m_start);
tmp.addAtEnd (dataEnd);
Buffer::Iterator i = tmp.end ();
i.prev (data_end);
i.write (m_data->m_data+m_data->m_initialStart,data_end);
i.prev (dataEnd);
i.write (m_data->m_data+m_data->m_initialStart,dataEnd);
*const_cast<Buffer *> (this) = tmp;
}
}
uint8_t *
Buffer::peek_data (void) const
Buffer::peekData (void) const
{
transform_intoRealBuffer ();
return m_data->m_data + m_start;
@ -384,9 +384,9 @@ namespace ns3 {
class BufferTest: public Test {
private:
bool ensure_written_bytes (Buffer b, uint32_t n, uint8_t array[]);
bool ensureWrittenBytes (Buffer b, uint32_t n, uint8_t array[]);
public:
virtual bool run_tests (void);
virtual bool runTests (void);
BufferTest ();
};
@ -395,12 +395,12 @@ BufferTest::BufferTest ()
: Test ("Buffer") {}
bool
BufferTest::ensure_written_bytes (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 *got;
got = b.peek_data ();
got = b.peekData ();
for (uint32_t j = 0; j < n; j++) {
if (got[j] != expected[j]) {
success = false;
@ -432,75 +432,75 @@ BufferTest::ensure_written_bytes (Buffer b, uint32_t n, uint8_t array[])
#define ENSURE_WRITTEN_BYTES(buffer, n, ...) \
{ \
uint8_t bytes[] = {__VA_ARGS__}; \
if (!ensure_written_bytes (buffer, n , bytes)) { \
if (!ensureWrittenBytes (buffer, n , bytes)) { \
ok = false; \
} \
}
bool
BufferTest::run_tests (void)
BufferTest::runTests (void)
{
bool ok = true;
Buffer buffer;
Buffer::Iterator i;
buffer.add_at_start (6);
buffer.addAtStart (6);
i = buffer.begin ();
i.write_u8 (0x66);
i.writeU8 (0x66);
ENSURE_WRITTEN_BYTES (buffer, 1, 0x66);
i = buffer.begin ();
i.write_u8 (0x67);
i.writeU8 (0x67);
ENSURE_WRITTEN_BYTES (buffer, 1, 0x67);
i.write_hton_u16 (0x6568);
i.writeHtonU16 (0x6568);
i = buffer.begin ();
ENSURE_WRITTEN_BYTES (buffer, 3, 0x67, 0x65, 0x68);
i.write_hton_u16 (0x6369);
i.writeHtonU16 (0x6369);
ENSURE_WRITTEN_BYTES (buffer, 3, 0x63, 0x69, 0x68);
i.write_hton_u32 (0xdeadbeaf);
i.writeHtonU32 (0xdeadbeaf);
ENSURE_WRITTEN_BYTES (buffer, 6, 0x63, 0x69, 0xde, 0xad, 0xbe, 0xaf);
buffer.add_at_start (2);
buffer.addAtStart (2);
i = buffer.begin ();
i.write_u16 (0);
i.writeU16 (0);
ENSURE_WRITTEN_BYTES (buffer, 8, 0, 0, 0x63, 0x69, 0xde, 0xad, 0xbe, 0xaf);
buffer.add_at_end (2);
buffer.addAtEnd (2);
i = buffer.begin ();
i.next (8);
i.write_u16 (0);
i.writeU16 (0);
ENSURE_WRITTEN_BYTES (buffer, 10, 0, 0, 0x63, 0x69, 0xde, 0xad, 0xbe, 0xaf, 0, 0);
buffer.remove_at_start (3);
buffer.removeAtStart (3);
i = buffer.begin ();
ENSURE_WRITTEN_BYTES (buffer, 7, 0x69, 0xde, 0xad, 0xbe, 0xaf, 0, 0);
buffer.remove_at_end (4);
buffer.removeAtEnd (4);
i = buffer.begin ();
ENSURE_WRITTEN_BYTES (buffer, 3, 0x69, 0xde, 0xad);
buffer.add_at_start (1);
buffer.addAtStart (1);
i = buffer.begin ();
i.write_u8 (0xff);
i.writeU8 (0xff);
ENSURE_WRITTEN_BYTES (buffer, 4, 0xff, 0x69, 0xde, 0xad);
buffer.add_at_end (1);
buffer.addAtEnd (1);
i = buffer.begin ();
i.next (4);
i.write_u8 (0xff);
i.writeU8 (0xff);
i.prev (2);
uint16_t saved = i.read_u16 ();
uint16_t saved = i.readU16 ();
i.prev (2);
i.write_hton_u16 (0xff00);
i.writeHtonU16 (0xff00);
i.prev (2);
if (i.read_ntoh_u16 () != 0xff00) {
if (i.readNtohU16 () != 0xff00) {
ok = false;
}
i.prev (2);
i.write_u16 (saved);
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.add_at_start (1);
o.addAtStart (1);
i = o.begin ();
i.write_u8 (0xfe);
i.writeU8 (0xfe);
ENSURE_WRITTEN_BYTES (o, 6, 0xfe, 0xff, 0x69, 0xde, 0xad, 0xff);
buffer.add_at_start (2);
buffer.addAtStart (2);
i = buffer.begin ();
i.write_u8 (0xfd);
i.write_u8 (0xfd);
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);
@ -513,68 +513,68 @@ BufferTest::run_tests (void)
// test remove start.
buffer = Buffer (5);
ENSURE_WRITTEN_BYTES (buffer, 5, 0, 0, 0, 0, 0);
buffer.remove_at_start (1);
buffer.removeAtStart (1);
ENSURE_WRITTEN_BYTES (buffer, 4, 0, 0, 0, 0);
buffer.add_at_start (1);
buffer.begin ().write_u8 (0xff);
buffer.addAtStart (1);
buffer.begin ().writeU8 (0xff);
ENSURE_WRITTEN_BYTES (buffer, 5, 0xff, 0, 0, 0, 0);
buffer.remove_at_start(3);
buffer.removeAtStart(3);
ENSURE_WRITTEN_BYTES (buffer, 2, 0, 0);
buffer.add_at_start (4);
buffer.begin ().write_hton_u32 (0xdeadbeaf);
buffer.addAtStart (4);
buffer.begin ().writeHtonU32 (0xdeadbeaf);
ENSURE_WRITTEN_BYTES (buffer, 6, 0xde, 0xad, 0xbe, 0xaf, 0, 0);
buffer.remove_at_start (2);
buffer.removeAtStart (2);
ENSURE_WRITTEN_BYTES (buffer, 4, 0xbe, 0xaf, 0, 0);
buffer.add_at_end (4);
buffer.addAtEnd (4);
i = buffer.begin ();
i.next (4);
i.write_hton_u32 (0xdeadbeaf);
i.writeHtonU32 (0xdeadbeaf);
ENSURE_WRITTEN_BYTES (buffer, 8, 0xbe, 0xaf, 0, 0, 0xde, 0xad, 0xbe, 0xaf);
buffer.remove_at_start (5);
buffer.removeAtStart (5);
ENSURE_WRITTEN_BYTES (buffer, 3, 0xad, 0xbe, 0xaf);
// test remove end
buffer = Buffer (5);
ENSURE_WRITTEN_BYTES (buffer, 5, 0, 0, 0, 0, 0);
buffer.remove_at_end (1);
buffer.removeAtEnd (1);
ENSURE_WRITTEN_BYTES (buffer, 4, 0, 0, 0, 0);
buffer.add_at_end (2);
buffer.addAtEnd (2);
i = buffer.begin ();
i.next (4);
i.write_u8 (0xab);
i.write_u8 (0xac);
i.writeU8 (0xab);
i.writeU8 (0xac);
ENSURE_WRITTEN_BYTES (buffer, 6, 0, 0, 0, 0, 0xab, 0xac);
buffer.remove_at_end (1);
buffer.removeAtEnd (1);
ENSURE_WRITTEN_BYTES (buffer, 5, 0, 0, 0, 0, 0xab);
buffer.remove_at_end (3);
buffer.removeAtEnd (3);
ENSURE_WRITTEN_BYTES (buffer, 2, 0, 0);
buffer.add_at_end (6);
buffer.addAtEnd (6);
i = buffer.begin ();
i.next (2);
i.write_u8 (0xac);
i.write_u8 (0xad);
i.write_u8 (0xae);
i.write_u8 (0xaf);
i.write_u8 (0xba);
i.write_u8 (0xbb);
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.add_at_start (3);
buffer.addAtStart (3);
i = buffer.begin ();
i.write_u8 (0x30);
i.write_u8 (0x31);
i.write_u8 (0x32);
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.remove_at_end (9);
buffer.removeAtEnd (9);
ENSURE_WRITTEN_BYTES (buffer, 2, 0x30, 0x31);
buffer = Buffer (3);
buffer.add_at_end (2);
buffer.addAtEnd (2);
i = buffer.begin ();
i.next (3);
i.write_hton_u16 (0xabcd);
buffer.add_at_start (1);
buffer.begin ().write_u8 (0x21);
i.writeHtonU16 (0xabcd);
buffer.addAtStart (1);
buffer.begin ().writeU8 (0x21);
ENSURE_WRITTEN_BYTES (buffer, 6, 0x21, 0, 0, 0, 0xab, 0xcd);
buffer.remove_at_end (8);
if (buffer.get_size () != 0) {
buffer.removeAtEnd (8);
if (buffer.getSize () != 0) {
ok = false;
}
@ -586,7 +586,7 @@ BufferTest::run_tests (void)
static BufferTest g_buffer_test;
static BufferTest gBufferTest;
}; // namespace ns3

164
src/common/buffer.h

@ -69,18 +69,18 @@ public:
* to the same underlying buffer. Debug builds ensure
* this with an assert.
*/
inline int32_t get_distance_from (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 is_end (void) const;
inline bool isEnd (void) const;
/**
* \return true if this iterator points to the start of the byte array.
* false otherwise.
*/
inline bool is_start (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 write_u8 (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,37 +96,37 @@ public:
* Write the data in buffer len times and avance the iterator position
* by len byte.
*/
inline void write_u8 (uint8_t data, uint32_t len);
inline void writeU8 (uint8_t data, uint32_t len);
/**
* \param data data to write in buffer
*
* Write the data in buffer and avance the iterator position
* by two bytes. The format of the data written in the byte
* buffer is non-portable. We only ensure that read_u16 will
* return exactly what we wrote with write_u16 if the program
* buffer is non-portable. We only ensure that readU16 will
* return exactly what we wrote with writeU16 if the program
* is run on the same machine.
*/
inline void write_u16 (uint16_t data);
inline void writeU16 (uint16_t data);
/**
* \param data data to write in buffer
*
* Write the data in buffer and avance the iterator position
* by four bytes. The format of the data written in the byte
* buffer is non-portable. We only ensure that read_u32 will
* return exactly what we wrote with write_u32 if the program
* buffer is non-portable. We only ensure that readU32 will
* return exactly what we wrote with writeU32 if the program
* is run on the same machine.
*/
inline void write_u32 (uint32_t data);
inline void writeU32 (uint32_t data);
/**
* \param data data to write in buffer
*
* Write the data in buffer and avance the iterator position
* by eight bytes. The format of the data written in the byte
* buffer is non-portable. We only ensure that read_u64 will
* return exactly what we wrote with write_u64 if the program
* buffer is non-portable. We only ensure that readU64 will
* return exactly what we wrote with writeU64 if the program
* is run on the same machine.
*/
inline void write_u64 (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 write_hton_u16 (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 write_hton_u32 (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 write_hton_u64 (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.
@ -178,31 +178,31 @@ public:
* Read data and advance the Iterator by the number of bytes
* read.
*/
inline uint8_t read_u8 (void);
inline uint8_t readU8 (void);
/**
* \return the two bytes read in the buffer.
*
* Read data and advance the Iterator by the number of bytes
* read.
* The data is read in the format written by write_u16.
* The data is read in the format written by writeU16.
*/
inline uint16_t read_u16 (void);
inline uint16_t readU16 (void);
/**
* \return the four bytes read in the buffer.
*
* Read data and advance the Iterator by the number of bytes
* read.
* The data is read in the format written by write_u32.
* The data is read in the format written by writeU32.
*/
inline uint32_t read_u32 (void);
inline uint32_t readU32 (void);
/**
* \return the eight bytes read in the buffer.
*
* Read data and advance the Iterator by the number of bytes
* read.
* The data is read in the format written by write_u64.
* The data is read in the format written by writeU64.
*/
inline uint64_t read_u64 (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 read_ntoh_u16 (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 read_ntoh_u32 (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 read_ntoh_u64 (void);
inline uint64_t readNtohU64 (void);
/**
* \param buffer buffer to copy data into
* \param size number of bytes to copy
@ -239,7 +239,7 @@ public:
private:
friend class Buffer;
inline Iterator (Buffer const*buffer, uint32_t m_current);
inline uint32_t get_index (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 get_size (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::get_size () 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 *peek_data (void) const;
uint8_t *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 add_at_start (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 add_at_end (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 remove_at_start (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 remove_at_end (uint32_t end);
void removeAtEnd (uint32_t end);
/**
* \param start offset from start of packet
@ -307,7 +307,7 @@ public:
* \return a fragment of size length starting at offset
* start.
*/
Buffer create_fragment (uint32_t start, uint32_t length) const;
Buffer createFragment (uint32_t start, uint32_t length) const;
/**
* \return an Iterator which points to the
@ -323,7 +323,7 @@ public:
inline Buffer (Buffer const &o);
inline Buffer &operator = (Buffer const &o);
inline Buffer ();
inline Buffer (uint32_t data_size);
inline Buffer (uint32_t dataSize);
inline ~Buffer ();
private:
struct BufferData {
@ -336,7 +336,7 @@ private:
};
typedef std::vector<struct Buffer::BufferData*> BufferDataList;
inline uint8_t *get_start (void) const;
inline uint8_t *getStart (void) const;
void transform_intoRealBuffer (void) const;
static void recycle (struct Buffer::BufferData *data);
static struct Buffer::BufferData *create (void);
@ -371,9 +371,9 @@ Buffer::Buffer ()
assert (m_start <= m_data->m_size);
}
Buffer::Buffer (uint32_t data_size)
Buffer::Buffer (uint32_t dataSize)
: m_data (Buffer::create ()),
m_zeroAreaSize (data_size),
m_zeroAreaSize (dataSize),
m_start (m_maxTotalAddStart),
m_size (0)
{
@ -423,13 +423,13 @@ Buffer::~Buffer ()
uint8_t *
Buffer::get_start (void) const
Buffer::getStart (void) const
{
return m_data->m_data + m_start;
}
uint32_t
Buffer::get_size (void) const
Buffer::getSize (void) const
{
return m_size + m_zeroAreaSize;
}
@ -442,7 +442,7 @@ Buffer::begin (void) const
Buffer::Iterator
Buffer::end (void) const
{
return Buffer::Iterator (this, get_size ());
return Buffer::Iterator (this, getSize ());
}
@ -456,7 +456,7 @@ 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->get_size ()),
m_dataEnd (buffer->getSize ()),
m_current (current),
m_data (buffer->m_data->m_data+buffer->m_start)
{}
@ -486,7 +486,7 @@ Buffer::Iterator::prev (uint32_t delta)
m_current -= delta;
}
int32_t
Buffer::Iterator::get_distance_from (Iterator const &o) const
Buffer::Iterator::getDistanceFrom (Iterator const &o) const
{
assert (m_data == o.m_data);
int32_t start = m_current;
@ -495,18 +495,18 @@ Buffer::Iterator::get_distance_from (Iterator const &o) const
}
bool
Buffer::Iterator::is_end (void) const
Buffer::Iterator::isEnd (void) const
{
return m_current == m_dataEnd;
}
bool
Buffer::Iterator::is_start (void) const
Buffer::Iterator::isStart (void) const
{
return m_current == 0;
}
uint32_t
Buffer::Iterator::get_index (uint32_t n)
Buffer::Iterator::getIndex (uint32_t n)
{
assert (
(m_current + n <= m_dataEnd) &&
@ -530,58 +530,58 @@ Buffer::Iterator::write (Iterator start, Iterator end)
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.get_index (size);
uint8_t *dest = m_data + get_index (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::write_u8 (uint8_t data, uint32_t len)
Buffer::Iterator::writeU8 (uint8_t data, uint32_t len)
{
uint8_t *current = m_data + get_index (len);
uint8_t *current = m_data + getIndex (len);
memset (current, data, len);
m_current += len;
}
void
Buffer::Iterator::write_u8 (uint8_t data)
Buffer::Iterator::writeU8 (uint8_t data)
{
m_data[get_index (1)] = data;
m_data[getIndex (1)] = data;
m_current++;
}
void
Buffer::Iterator::write_u16 (uint16_t data)
Buffer::Iterator::writeU16 (uint16_t data)
{
uint16_t *buffer = (uint16_t *)(m_data + get_index (2));
uint16_t *buffer = (uint16_t *)(m_data + getIndex (2));
*buffer = data;
m_current += 2;
}
void
Buffer::Iterator::write_u32 (uint32_t data)
Buffer::Iterator::writeU32 (uint32_t data)
{
uint32_t *buffer = (uint32_t *)(m_data + get_index (4));
uint32_t *buffer = (uint32_t *)(m_data + getIndex (4));
*buffer = data;
m_current += 4;
}
void
Buffer::Iterator::write_u64 (uint64_t data)
Buffer::Iterator::writeU64 (uint64_t data)
{
uint64_t *buffer = (uint64_t *)(m_data + get_index (8));
uint64_t *buffer = (uint64_t *)(m_data + getIndex (8));
*buffer = data;
m_current += 8;
}
void
Buffer::Iterator::write_hton_u16 (uint16_t data)
Buffer::Iterator::writeHtonU16 (uint16_t data)
{
uint8_t *current = m_data + get_index (2);
uint8_t *current = m_data + getIndex (2);
*(current+0) = (data >> 8) & 0xff;
*(current+1) = (data >> 0) & 0xff;
m_current += 2;
}
void
Buffer::Iterator::write_hton_u32 (uint32_t data)
Buffer::Iterator::writeHtonU32 (uint32_t data)
{
uint8_t *current = m_data + get_index (4);
uint8_t *current = m_data + getIndex (4);
*(current+0) = (data >> 24) & 0xff;
*(current+1) = (data >> 16) & 0xff;
*(current+2) = (data >> 8) & 0xff;
@ -589,9 +589,9 @@ Buffer::Iterator::write_hton_u32 (uint32_t data)
m_current += 4;
}
void
Buffer::Iterator::write_hton_u64 (uint64_t data)
Buffer::Iterator::writeHtonU64 (uint64_t data)
{
uint8_t *current = m_data + get_index (8);
uint8_t *current = m_data + getIndex (8);
*(current+0) = (data >> 56) & 0xff;
*(current+1) = (data >> 48) & 0xff;
*(current+2) = (data >> 40) & 0xff;
@ -605,43 +605,43 @@ Buffer::Iterator::write_hton_u64 (uint64_t data)
void
Buffer::Iterator::write (uint8_t const*buffer, uint16_t size)
{
uint8_t *current = m_data + get_index (size);
uint8_t *current = m_data + getIndex (size);
memcpy (current, buffer, size);
m_current += size;
}
uint8_t
Buffer::Iterator::read_u8 (void)
Buffer::Iterator::readU8 (void)
{
uint8_t data = m_data[get_index(1)];
uint8_t data = m_data[getIndex(1)];
m_current++;
return data;
}
uint16_t
Buffer::Iterator::read_u16 (void)
Buffer::Iterator::readU16 (void)
{
uint16_t *buffer = reinterpret_cast<uint16_t *>(m_data + get_index (2));
uint16_t *buffer = reinterpret_cast<uint16_t *>(m_data + getIndex (2));
m_current += 2;
return *buffer;
}
uint32_t
Buffer::Iterator::read_u32 (void)
Buffer::Iterator::readU32 (void)
{
uint32_t *buffer = reinterpret_cast<uint32_t *>(m_data + get_index (4));
uint32_t *buffer = reinterpret_cast<uint32_t *>(m_data + getIndex (4));
m_current += 4;
return *buffer;
}
uint64_t
Buffer::Iterator::read_u64 (void)
Buffer::Iterator::readU64 (void)
{
uint64_t *buffer = reinterpret_cast<uint64_t *>(m_data + get_index (8));
uint64_t *buffer = reinterpret_cast<uint64_t *>(m_data + getIndex (8));
m_current += 8;
return *buffer;
}
uint16_t
Buffer::Iterator::read_ntoh_u16 (void)
Buffer::Iterator::readNtohU16 (void)
{
uint8_t *current = m_data + get_index (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;
@ -649,9 +649,9 @@ Buffer::Iterator::read_ntoh_u16 (void)
return retval;
}
uint32_t
Buffer::Iterator::read_ntoh_u32 (void)
Buffer::Iterator::readNtohU32 (void)
{
uint8_t *current = m_data + get_index (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;
@ -661,9 +661,9 @@ Buffer::Iterator::read_ntoh_u32 (void)
return retval;
}
uint64_t
Buffer::Iterator::read_ntoh_u64 (void)
Buffer::Iterator::readNtohU64 (void)
{
uint8_t *current = m_data + get_index (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;
@ -679,7 +679,7 @@ Buffer::Iterator::read_ntoh_u64 (void)
void
Buffer::Iterator::read (uint8_t *buffer, uint16_t size)
{
uint8_t *current = m_data + get_index (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 set_callback (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.is_null ()) {
if (!m_callback.isNull ()) {
m_callback ();
}
}
void operator() (T1 a1) {
if (!m_callback.is_null ()) {
if (!m_callback.isNull ()) {
m_callback (a1);
}
}
void operator() (T1 a1, T2 a2) {
if (!m_callback.is_null ()) {
if (!m_callback.isNull ()) {
m_callback (a1,a2);
}
}
void operator() (T1 a1, T2 a2, T3 a3) {
if (!m_callback.is_null ()) {
if (!m_callback.isNull ()) {
m_callback (a1,a2,a3);
}
}
void operator() (T1 a1, T2 a2, T3 a3, T4 a4) {
if (!m_callback.is_null ()) {
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.is_null ()) {
if (!m_callback.isNull ()) {
m_callback (a1,a2,a3,a4,a5);
}
}

16
src/common/chunk-constant-data.cc

@ -40,23 +40,23 @@ ChunkConstantData::print (std::ostream *os) const
}
void
ChunkConstantData::add_to (Buffer *buffer) const
ChunkConstantData::addTo (Buffer *buffer) const
{
buffer->add_at_start (m_len);
buffer->addAtStart (m_len);
#ifndef NDEBUG
buffer->begin ().write_u8 (m_data, m_len);
buffer->begin ().writeU8 (m_data, m_len);
#endif
}
void
ChunkConstantData::peek_from (Buffer const *buffer)
ChunkConstantData::peekFrom (Buffer const *buffer)
{
m_len = buffer->get_size ();
m_data = buffer->begin ().read_u8 ();
m_len = buffer->getSize ();
m_data = buffer->begin ().readU8 ();
}
void
ChunkConstantData::remove_from (Buffer *buffer)
ChunkConstantData::removeFrom (Buffer *buffer)
{
buffer->remove_at_start (m_len);
buffer->removeAtStart (m_len);
}

6
src/common/chunk-constant-data.h

@ -35,9 +35,9 @@ public:
private:
virtual void print (std::ostream *os) const;
virtual void add_to (Buffer *buffer) const;
virtual void peek_from (Buffer const *buffer);
virtual void remove_from (Buffer *buffer);
virtual void addTo (Buffer *buffer) const;
virtual void peekFrom (Buffer const *buffer);
virtual void removeFrom (Buffer *buffer);
uint32_t m_len;
uint8_t m_data;
};

6
src/common/chunk.cc

@ -35,19 +35,19 @@ Chunk::print (std::ostream &os) const
void
Chunk::add (Buffer *buffer) const
{
add_to (buffer);
addTo (buffer);
}
void
Chunk::peek (Buffer const *buffer)
{
peek_from (buffer);
peekFrom (buffer);
m_mustPeekBeforeRemove = true;
}
void
Chunk::remove (Buffer *buffer)
{
assert (m_mustPeekBeforeRemove);
remove_from (buffer);
removeFrom (buffer);
m_mustPeekBeforeRemove = false;
}

6
src/common/chunk.h

@ -64,13 +64,13 @@ private:
* - reserve room for its serialized representation in the input buffer
* - serialize itself in this reserved room
*/
virtual void add_to (Buffer *buffer) const = 0;
virtual void addTo (Buffer *buffer) const = 0;
/**
* \param buffer the buffer from which the protocol header must
* deserialize itself.
*
*/
virtual void peek_from (Buffer const *buffer) = 0;
virtual void peekFrom (Buffer const *buffer) = 0;
/**
* \param buffer the buffer from which the protocol header
* must remove itself.
@ -79,7 +79,7 @@ private:
* from the input buffer. This method does not need to deserialize
* the data itself.
*/
virtual void remove_from (Buffer *buffer) = 0;
virtual void removeFrom (Buffer *buffer) = 0;
};
std::ostream& operator<< (std::ostream& os, Chunk const& chunk);

10
src/common/data-writer.cc

@ -82,11 +82,11 @@ void
DataWriterPrivate::write (uint8_t *buffer, uint32_t size)
{
while (size > 0) {
uint32_t to_copy = min (BUFFER_SIZE - m_current, size);
memcpy (m_data + m_current, buffer, to_copy);
size -= to_copy;
m_current += to_copy;
buffer += to_copy;
uint32_t toCopy = min (BUFFER_SIZE - m_current, size);
memcpy (m_data + m_current, buffer, toCopy);
size -= toCopy;
m_current += toCopy;
buffer += toCopy;
if (m_current == BUFFER_SIZE) {
ssize_t written = 0;
written = ::write (m_fd, m_data, BUFFER_SIZE);

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

@ -39,13 +39,13 @@ public:
~FVariableTracerBase () {}
void set_callback(ChangeNotifyCallback callback) {
void setCallback(ChangeNotifyCallback callback) {
m_callback = callback;
}
protected:
void notify (double old_val, double new_val) {
if (old_val != new_val && !m_callback.is_null ()) {
m_callback (old_val, new_val);
void notify (double oldVal, double newVal) {
if (oldVal != newVal && !m_callback.isNull ()) {
m_callback (oldVal, newVal);
}
}
private:

56
src/common/packet.cc

@ -36,16 +36,16 @@ Packet::Packet (Buffer buffer, Tags tags)
Packet
Packet::create_fragment (uint32_t start, uint32_t length) const
Packet::createFragment (uint32_t start, uint32_t length) const
{
Buffer tmp = m_buffer.create_fragment (start, length);
Buffer tmp = m_buffer.createFragment (start, length);
return Packet (tmp, m_tags);
}
uint32_t
Packet::get_size (void) const
Packet::getSize (void) const
{
return m_buffer.get_size ();
return m_buffer.getSize ();
}
void
@ -70,58 +70,58 @@ Packet::remove (Chunk *chunk)
void
Packet::write (PacketReadWriteCallback callback) const
{
uint8_t *data = m_buffer.peek_data ();
uint32_t to_write = get_size ();
callback (data, to_write);
uint8_t *data = m_buffer.peekData ();
uint32_t toWrite = getSize ();
callback (data, toWrite);
}
void
Packet::add_at_end (Packet packet)
Packet::addAtEnd (Packet packet)
{
Buffer src = packet.m_buffer;
m_buffer.add_at_end (src.get_size ());
Buffer::Iterator dest_start = m_buffer.end ();
dest_start.prev (src.get_size ());
dest_start.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::add_at_end (Packet packet, uint32_t start, uint32_t size)
Packet::addAtEnd (Packet packet, uint32_t start, uint32_t size)
{
assert (packet.get_size () <= start + size);
assert (packet.getSize () <= start + size);
Buffer src = packet.m_buffer;
m_buffer.add_at_end (src.get_size ());
Buffer::Iterator dest_start = m_buffer.end ();
dest_start.prev (size);
Buffer::Iterator src_start = src.begin ();
src_start.next (start);
Buffer::Iterator src_end = src_start;
src_end.next (size);
dest_start.write (src_start, src_end);
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);
/**
* XXX: we might need to merge the tag list of the
* other packet into the current packet.
*/
}
void
Packet::remove_at_end (uint32_t size)
Packet::removeAtEnd (uint32_t size)
{
m_buffer.remove_at_end (size);
m_buffer.removeAtEnd (size);
}
void
Packet::remove_at_start (uint32_t size)
Packet::removeAtStart (uint32_t size)
{
m_buffer.remove_at_start (size);
m_buffer.removeAtStart (size);
}
void
Packet::remove_all_tags (void)
Packet::removeAllTags (void)
{
m_tags.remove_all ();
m_tags.removeAll ();
}
}; // namespace ns3

30
src/common/packet.h

@ -34,25 +34,25 @@ public:
typedef Callback<void,uint8_t *,uint32_t> PacketReadWriteCallback;
Packet ();
Packet (uint32_t size);
Packet create_fragment (uint32_t start, uint32_t length) const;
uint32_t get_size (void) const;
Packet createFragment (uint32_t start, uint32_t length) const;
uint32_t getSize (void) const;
void add (Chunk *chunk);
void peek (Chunk *chunk) const;
void remove (Chunk *chunk);
template <typename T>
void add_tag (T const *tag);
void addTag (T const *tag);
template <typename T>
bool remove_tag (T *tag);
bool removeTag (T *tag);
template <typename T>
bool peek_tag (T *tag) const;
bool peekTag (T *tag) const;
template <typename T>
bool update_tag (T const*tag);
void remove_all_tags (void);
bool updateTag (T const*tag);
void removeAllTags (void);
void write (PacketReadWriteCallback callback) const;
void add_at_end (Packet packet);
void add_at_end (Packet packet, uint32_t offset, uint32_t size);
void remove_at_end (uint32_t size);
void remove_at_start (uint32_t size);
void addAtEnd (Packet packet);
void addAtEnd (Packet packet, uint32_t offset, uint32_t size);
void removeAtEnd (uint32_t size);
void removeAtStart (uint32_t size);
private:
Packet (Buffer buffer, Tags tags);
@ -65,22 +65,22 @@ private:
namespace ns3 {
template <typename T>
void Packet::add_tag (T const*tag)
void Packet::addTag (T const*tag)
{
m_tags.add (tag);
}
template <typename T>
bool Packet::remove_tag (T *tag)
bool Packet::removeTag (T *tag)
{
return m_tags.remove (tag);
}
template <typename T>
bool Packet::peek_tag (T *tag) const
bool Packet::peekTag (T *tag) const
{
return m_tags.peek (tag);
}
template <typename T>
bool Packet::update_tag (T const*tag)
bool Packet::updateTag (T const*tag)
{
return m_tags.update (tag);
}

12
src/common/pcap-writer.cc

@ -39,7 +39,7 @@ enum {
PcapWriter::PcapWriter ()
{
m_writer = 0;
m_writeCallback = make_callback (&PcapWriter::write_data, this);
m_writeCallback = makeCallback (&PcapWriter::writeData, this);
}
PcapWriter::~PcapWriter ()
{
@ -54,7 +54,7 @@ PcapWriter::open (char const *name)
}
void
PcapWriter::write_header_ethernet (void)
PcapWriter::writeHeaderEthernet (void)
{
write_32 (0xa1b2c3d4);
write_16 (2);
@ -66,7 +66,7 @@ PcapWriter::write_header_ethernet (void)
}
void
PcapWriter::write_packet (Packet const packet)
PcapWriter::writePacket (Packet const packet)
{
if (m_writer != 0) {
uint64_t current = Simulator::now ().us ();
@ -74,14 +74,14 @@ PcapWriter::write_packet (Packet const packet)
uint64_t us = current % 1000000;
write_32 (s & 0xffffffff);
write_32 (us & 0xffffffff);
write_32 (packet.get_size ());
write_32 (packet.get_size ());
write_32 (packet.getSize ());
write_32 (packet.getSize ());
packet.write (m_writeCallback);
}
}
void
PcapWriter::write_data (uint8_t *buffer, uint32_t size)
PcapWriter::writeData (uint8_t *buffer, uint32_t size)
{
m_writer->write (buffer, size);
}

6
src/common/pcap-writer.h

@ -53,15 +53,15 @@ public:
* that the content of the file will Packets with
* Ethernet/LLC/SNAP encapsulation.
*/
void write_header_ethernet (void);
void writeHeaderEthernet (void);
/**
* \param packet packet to write to output file
*/
void write_packet (Packet const packet);
void writePacket (Packet const packet);
private:
void write_data (uint8_t *buffer, uint32_t size);
void writeData (uint8_t *buffer, uint32_t size);
void write_32 (uint32_t data);
void write_16 (uint16_t data);
SystemFile *m_writer;

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

@ -39,13 +39,13 @@ public:
~SiVariableTracerBase () {}
void set_callback(ChangeNotifyCallback callback) {
void setCallback(ChangeNotifyCallback callback) {
m_callback = callback;
}
protected:
void notify (int64_t old_val, int64_t new_val) {
if (old_val != new_val && !m_callback.is_null ()) {
m_callback (old_val, new_val);
void notify (int64_t oldVal, int64_t newVal) {
if (oldVal != newVal && !m_callback.isNull ()) {
m_callback (oldVal, newVal);
}
}
private:

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

@ -29,21 +29,21 @@ namespace {
class TestStreamTracer : public ns3::Test {
public:
TestStreamTracer ();
virtual bool run_tests (void);
virtual bool runTests (void);
};
static TestStreamTracer g_test_stream;
static TestStreamTracer gTestStream;
TestStreamTracer::TestStreamTracer ()
: Test ("StreamTracer")
{}
bool
TestStreamTracer::run_tests (void)
TestStreamTracer::runTests (void)
{
bool ok = true;
ns3::StreamTracer trace;
//trace.set_stream (&std::cout);
//trace.setStream (&std::cout);
trace << 1;
trace << " X ";
trace << 1.0;

2
src/common/stream-tracer.h

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

150
src/common/tags.cc

@ -23,25 +23,25 @@
namespace ns3 {
TagsPrettyPrinterRegistry::PrettyPrinters TagsPrettyPrinterRegistry::g_pretty_printers;
TagsPrettyPrinterRegistry::PrettyPrinters TagsPrettyPrinterRegistry::gPrettyPrinters;
void
TagsPrettyPrinterRegistry::record (uint32_t uid, void (*cb) (uint8_t [Tags::SIZE], std::ostream &))
{
for (PrettyPrintersI i = g_pretty_printers.begin ();
i != g_pretty_printers.end (); i++) {
for (PrettyPrintersI i = gPrettyPrinters.begin ();
i != gPrettyPrinters.end (); i++) {
if (i->first == uid) {
i->second = cb;
return;
}
}
g_pretty_printers.push_back (std::make_pair (uid, cb));
gPrettyPrinters.push_back (std::make_pair (uid, cb));
}
void
TagsPrettyPrinterRegistry::pretty_print (uint32_t uid, uint8_t buf[Tags::SIZE], std::ostream &os)
TagsPrettyPrinterRegistry::prettyPrint (uint32_t uid, uint8_t buf[Tags::SIZE], std::ostream &os)
{
for (PrettyPrintersI i = g_pretty_printers.begin ();
i != g_pretty_printers.end (); i++) {
for (PrettyPrintersI i = gPrettyPrinters.begin ();
i != gPrettyPrinters.end (); i++) {
if (i->first == uid) {
if (i->second == 0) {
os << "tag uid="<<uid<<" null pretty printer."<<std::endl;
@ -67,17 +67,17 @@ Tags::UidFactory::create (void)
#ifdef USE_FREE_LIST
struct Tags::TagData *Tags::g_free = 0;
uint32_t Tags::g_n_free = 0;
struct Tags::TagData *Tags::gFree = 0;
uint32_t Tags::gN_free = 0;
struct Tags::TagData *
Tags::alloc_data (void)
Tags::allocData (void)
{
struct Tags::TagData *retval;
if (g_free != 0) {
retval = g_free;
g_free = g_free->m_next;
g_n_free--;
if (gFree != 0) {
retval = gFree;
gFree = gFree->m_next;
gN_free--;
} else {
retval = new struct Tags::TagData ();
}
@ -85,19 +85,19 @@ Tags::alloc_data (void)
}
void
Tags::free_data (struct TagData *data)
Tags::freeData (struct TagData *data)
{
if (g_n_free > 1000) {
if (gN_free > 1000) {
delete data;
return;
}
g_n_free++;
data->m_next = g_free;
g_free = data;
gN_free++;
data->m_next = gFree;
gFree = data;
}
#else
struct Tags::TagData *
Tags::alloc_data (void)
Tags::allocData (void)
{
struct Tags::TagData *retval;
retval = new struct Tags::TagData ();
@ -105,7 +105,7 @@ Tags::alloc_data (void)
}
void
Tags::free_data (struct TagData *data)
Tags::freeData (struct TagData *data)
{
delete data;
}
@ -124,7 +124,7 @@ Tags::remove (uint32_t id)
return false;
}
struct TagData *start = 0;
struct TagData **prev_next = &start;
struct TagData **prevNext = &start;
for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) {
if (cur->m_id == id) {
/**
@ -135,16 +135,16 @@ Tags::remove (uint32_t id)
*/
continue;
}
struct TagData *copy = alloc_data ();
struct TagData *copy = allocData ();
copy->m_id = cur->m_id;
copy->m_count = 1;
copy->m_next = 0;
memcpy (copy->m_data, cur->m_data, Tags::SIZE);
*prev_next = copy;
prev_next = &copy->m_next;
*prevNext = copy;
prevNext = &copy->m_next;
}
*prev_next = 0;
remove_all ();
*prevNext = 0;
removeAll ();
m_next = start;
return true;
}
@ -155,21 +155,21 @@ Tags::update (uint8_t const*buffer, uint32_t id)
if (!remove (id)) {
return false;
}
struct TagData *new_start = alloc_data ();
new_start->m_count = 1;
new_start->m_next = 0;
new_start->m_id = id;
memcpy (new_start->m_data, buffer, Tags::SIZE);
new_start->m_next = m_next;
m_next = new_start;
struct TagData *newStart = allocData ();
newStart->m_count = 1;
newStart->m_next = 0;
newStart->m_id = id;
memcpy (newStart->m_data, buffer, Tags::SIZE);
newStart->m_next = m_next;
m_next = newStart;
return true;
}
void
Tags::pretty_print (std::ostream &os)
Tags::prettyPrint (std::ostream &os)
{
for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) {
TagsPrettyPrinterRegistry::pretty_print (cur->m_id, cur->m_data, os);
TagsPrettyPrinterRegistry::prettyPrint (cur->m_id, cur->m_data, os);
}
}
@ -188,42 +188,42 @@ class TagsTest : Test {
public:
TagsTest ();
virtual ~TagsTest ();
virtual bool run_tests (void);
virtual bool runTests (void);
};
struct my_tag_a {
struct myTagA {
uint8_t a;
};
struct my_tag_b {
struct myTagB {
uint32_t b;
};
struct my_tag_c {
struct myTagC {
uint8_t c [Tags::SIZE];
};
struct my_invalid_tag {
struct myInvalidTag {
uint8_t invalid [Tags::SIZE+1];
};
static void
my_tag_a_pretty_printer_cb (struct my_tag_a *a, std::ostream &os)
myTagAPrettyPrinterCb (struct myTagA *a, std::ostream &os)
{
os << "struct my_tag_a, a="<<(uint32_t)a->a<<std::endl;
os << "struct myTagA, a="<<(uint32_t)a->a<<std::endl;
}
static void
my_tag_b_pretty_printer_cb (struct my_tag_b *b, std::ostream &os)
myTagBPrettyPrinterCb (struct myTagB *b, std::ostream &os)
{
os << "struct my_tag_b, b="<<b->b<<std::endl;
os << "struct myTagB, b="<<b->b<<std::endl;
}
static void
my_tag_c_pretty_printer_cb (struct my_tag_c *c, std::ostream &os)
myTagCPrettyPrinterCb (struct myTagC *c, std::ostream &os)
{
os << "struct my_tag_c, c="<<(uint32_t)c->c[0]<<std::endl;
os << "struct myTagC, c="<<(uint32_t)c->c[0]<<std::endl;
}
static TagPrettyPrinter<struct my_tag_a> g_my_tag_a_pretty_printer (&my_tag_a_pretty_printer_cb);
static TagPrettyPrinter<struct my_tag_b> g_my_tag_b_pretty_printer (&my_tag_b_pretty_printer_cb);
static TagPrettyPrinter<struct my_tag_c> g_my_tag_c_pretty_printer (&my_tag_c_pretty_printer_cb);
static TagPrettyPrinter<struct myTagA> gMyTagAPrettyPrinter (&myTagAPrettyPrinterCb);
static TagPrettyPrinter<struct myTagB> gMyTagBPrettyPrinter (&myTagBPrettyPrinterCb);
static TagPrettyPrinter<struct myTagC> gMyTagCPrettyPrinter (&myTagCPrettyPrinterCb);
TagsTest::TagsTest ()
@ -233,13 +233,13 @@ TagsTest::~TagsTest ()
{}
bool
TagsTest::run_tests (void)
TagsTest::runTests (void)
{
bool ok = true;
// build initial tag.
Tags tags;
struct my_tag_a a;
struct myTagA a;
a.a = 10;
tags.add (&a);
a.a = 0;
@ -247,8 +247,8 @@ TagsTest::run_tests (void)
if (a.a != 10) {
ok = false;
}
//tags.pretty_print (std::cout);
struct my_tag_b b;
//tags.prettyPrint (std::cout);
struct myTagB b;
b.b = 0xff;
tags.add (&b);
b.b = 0;
@ -256,43 +256,43 @@ TagsTest::run_tests (void)
if (b.b != 0xff) {
ok = false;
}
//tags.pretty_print (std::cout);
//tags.prettyPrint (std::cout);
// make sure copy contains copy.
Tags other = tags;
//other.pretty_print (std::cout);
//tags.pretty_print (std::cout);
struct my_tag_a o_a;
o_a.a = 0;
other.peek (&o_a);
if (o_a.a != 10) {
//other.prettyPrint (std::cout);
//tags.prettyPrint (std::cout);
struct myTagA oA;
oA.a = 0;
other.peek (&oA);
if (oA.a != 10) {
ok = false;
}
struct my_tag_b o_b;
other.peek (&o_b);
if (o_b.b != 0xff) {
struct myTagB oB;
other.peek (&oB);
if (oB.b != 0xff) {
ok = false;
}
// remove data.
other.remove (&o_a);
if (other.peek (&o_a)) {
other.remove (&oA);
if (other.peek (&oA)) {
ok = false;
}
//other.pretty_print (std::cout);
if (!tags.peek (&o_a)) {
//other.prettyPrint (std::cout);
if (!tags.peek (&oA)) {
ok = false;
}
other.remove (&o_b);
if (other.peek (&o_b)) {
other.remove (&oB);
if (other.peek (&oB)) {
ok = false;
}
if (!tags.peek (&o_b)) {
if (!tags.peek (&oB)) {
ok = false;
}
other = tags;
Tags another = other;
struct my_tag_c c;
struct myTagC c;
c.c[0] = 0x66;
another.add (&c);
c.c[0] = 0;
@ -305,15 +305,15 @@ TagsTest::run_tests (void)
}
other = other;
//other.pretty_print (std::cout);
//other.prettyPrint (std::cout);
//struct my_invalid_tag invalid;
//struct myInvalidTag invalid;
//tags.add (&invalid);
return ok;
}
static TagsTest g_tags_test;
static TagsTest gTagsTest;
}; // namespace ns3

72
src/common/tags.h

@ -49,9 +49,9 @@ public:
template <typename T>
bool update (T const*tag);
void pretty_print (std::ostream &os);
void prettyPrint (std::ostream &os);
inline void remove_all (void);
inline void removeAll (void);
enum {
SIZE = 16
@ -70,11 +70,11 @@ private:
bool remove (uint32_t id);
bool update (uint8_t const*buffer, uint32_t id);
struct Tags::TagData *alloc_data (void);
void free_data (struct TagData *data);
struct Tags::TagData *allocData (void);
void freeData (struct TagData *data);
static struct Tags::TagData *g_free;
static uint32_t g_n_free;
static struct Tags::TagData *gFree;
static uint32_t gN_free;
struct TagData *m_next;
};
@ -95,18 +95,18 @@ public:
TagPrettyPrinter<T> (void(*) (T *, std::ostream &));
private:
TagPrettyPrinter<T> ();
static void pretty_print_cb (uint8_t *buf, std::ostream &os);
static void(*g_pretty_printer) (T *, std::ostream &);
static void prettyPrintCb (uint8_t *buf, std::ostream &os);
static void(*gPrettyPrinter) (T *, std::ostream &);
};
class TagsPrettyPrinterRegistry {
public:
static void record (uint32_t uid, void (*cb) (uint8_t buf[Tags::SIZE], std::ostream &os));
static void pretty_print (uint32_t uid, uint8_t buf[Tags::SIZE], std::ostream &os);
static void prettyPrint (uint32_t uid, uint8_t buf[Tags::SIZE], std::ostream &os);
private:
typedef std::vector<std::pair<uint32_t, void (*) (uint8_t [Tags::SIZE], std::ostream &)> > PrettyPrinters;
typedef std::vector<std::pair<uint32_t, void (*) (uint8_t [Tags::SIZE], std::ostream &)> >::iterator PrettyPrintersI;
static PrettyPrinters g_pretty_printers;
static PrettyPrinters gPrettyPrinters;
};
@ -138,13 +138,13 @@ namespace ns3 {
template <typename T>
class TypeUid {
public:
static const uint32_t get_uid (void);
static const uint32_t getUid (void);
private:
T real_type;
T realType;
};
template <typename T>
const uint32_t TypeUid<T>::get_uid (void)
const uint32_t TypeUid<T>::getUid (void)
{
static const uint32_t uid = Tags::UidFactory::create ();
return uid;
@ -159,23 +159,23 @@ const uint32_t TypeUid<T>::get_uid (void)
* the call to the user-provided function.
*/
template <typename T>
TagPrettyPrinter<T>::TagPrettyPrinter (void(*pretty_printer) (T *, std::ostream &))
TagPrettyPrinter<T>::TagPrettyPrinter (void(*prettyPrinter) (T *, std::ostream &))
{
g_pretty_printer = pretty_printer;
TagsPrettyPrinterRegistry::record (TypeUid<T>::get_uid (),
&TagPrettyPrinter<T>::pretty_print_cb);
gPrettyPrinter = prettyPrinter;
TagsPrettyPrinterRegistry::record (TypeUid<T>::getUid (),
&TagPrettyPrinter<T>::prettyPrintCb);
}
template <typename T>
void
TagPrettyPrinter<T>::pretty_print_cb (uint8_t buf[Tags::SIZE], std::ostream &os)
TagPrettyPrinter<T>::prettyPrintCb (uint8_t buf[Tags::SIZE], std::ostream &os)
{
assert (sizeof (T) <= Tags::SIZE);
T *tag = reinterpret_cast<T *> (buf);
(*g_pretty_printer) (tag, os);
(*gPrettyPrinter) (tag, os);
}
template <typename T>
void (*TagPrettyPrinter<T>::g_pretty_printer) (T *, std::ostream &) = 0;
void (*TagPrettyPrinter<T>::gPrettyPrinter) (T *, std::ostream &) = 0;
@ -188,15 +188,15 @@ Tags::add (T const*tag)
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>::get_uid ());
assert (cur->m_id != TypeUid<T>::getUid ());
}
struct TagData *new_start = alloc_data ();
new_start->m_count = 1;
new_start->m_next = 0;
new_start->m_id = TypeUid<T>::get_uid ();
memcpy (new_start->m_data, buf, sizeof (T));
new_start->m_next = m_next;
m_next = new_start;
struct TagData *newStart = allocData ();
newStart->m_count = 1;
newStart->m_next = 0;
newStart->m_id = TypeUid<T>::getUid ();
memcpy (newStart->m_data, buf, sizeof (T));
newStart->m_next = m_next;
m_next = newStart;
}
template <typename T>
@ -204,7 +204,7 @@ bool
Tags::remove (T *tag)
{
assert (sizeof (T) <= Tags::SIZE);
return remove (TypeUid<T>::get_uid ());
return remove (TypeUid<T>::getUid ());
}
template <typename T>
@ -214,7 +214,7 @@ 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>::get_uid ()) {
if (cur->m_id == TypeUid<T>::getUid ()) {
/* found tag */
memcpy (buf, cur->m_data, sizeof (T));
return true;
@ -230,7 +230,7 @@ Tags::update (T const*tag)
{
assert (sizeof (T) <= Tags::SIZE);
uint8_t const*buf = reinterpret_cast<uint8_t const*> (tag);
return update (buf, TypeUid<T>::get_uid ());
return update (buf, TypeUid<T>::getUid ());
}
@ -253,7 +253,7 @@ Tags::operator = (Tags const &o)
if (m_next == o.m_next) {
return *this;
}
remove_all ();
removeAll ();
m_next = o.m_next;
if (m_next != 0) {
m_next->m_count++;
@ -263,11 +263,11 @@ Tags::operator = (Tags const &o)
Tags::~Tags ()
{
remove_all ();
removeAll ();
}
void
Tags::remove_all (void)
Tags::removeAll (void)
{
struct TagData *prev = 0;
for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) {
@ -276,12 +276,12 @@ Tags::remove_all (void)
break;
}
if (prev != 0) {
free_data (prev);
freeData (prev);
}
prev = cur;
}
if (prev != 0) {
free_data (prev);
freeData (prev);
}
m_next = 0;
}

26
src/common/trace-container.cc

@ -36,38 +36,38 @@ TraceContainer::~TraceContainer ()
}
void
TraceContainer::set_ui_variable_callback (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->set_callback (callback);
(*i).first->setCallback (callback);
return;
}
}
assert (false);
}
void
TraceContainer::set_si_variable_callback (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->set_callback (callback);
(*i).first->setCallback (callback);
return;
}
}
assert (false);
}
void
TraceContainer::set_f_variable_callback (char const *name, Callback<void,double, double> callback)
TraceContainer::setFVariableCallback (char const *name, Callback<void,double, double> callback)
{
assert (false);
}
void
TraceContainer::set_stream (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->set_stream (os);
(*i).first->setStream (os);
return;
}
}
@ -75,7 +75,7 @@ TraceContainer::set_stream (char const *name, std::ostream *os)
}
void
TraceContainer::register_ui_variable (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::register_ui_variable (char const *name, UiVariableTracerBase *va
m_uiList.push_back (std::make_pair (var, name));
}
void
TraceContainer::register_si_variable (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::register_si_variable (char const *name, SiVariableTracerBase *va
m_siList.push_back (std::make_pair (var, name));
}
void
TraceContainer::register_f_variable (char const *name, FVariableTracerBase *var)
TraceContainer::registerFVariable (char const *name, FVariableTracerBase *var)
{
assert (false);
}
void
TraceContainer::register_stream (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::register_stream (char const *name, StreamTracer *stream)
}
void
TraceContainer::register_callback (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::register_callback (char const *name, CallbackTracerBase *tracer)
#include <iostream>
void
ns3::TraceContainer::print_debug (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 set_ui_variable_callback (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 set_si_variable_callback (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 set_f_variable_callback (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 set_stream (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 set_callback (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 set_callback (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 set_callback (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 set_callback (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 set_callback (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 register_ui_variable (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 register_si_variable (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 register_f_variable (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 register_stream (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 register_callback (char const *name, CallbackTracerBase*tracer);
void registerCallback (char const *name, CallbackTracerBase*tracer);
/**
* Print the list of registered event sources in this container only.
*/
void print_debug (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::set_callback (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)->set_callback (callback);
static_cast<CallbackTracer<T1> *> (i->first)->setCallback (callback);
return;
}
}
@ -218,11 +218,11 @@ TraceContainer::set_callback (char const *name, Callback<void,T1> callback)
}
template <typename T1, typename T2>
void
TraceContainer::set_callback (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)->set_callback (callback);
static_cast<CallbackTracer<T1,T2> *> (i->first)->setCallback (callback);
return;
}
}
@ -232,11 +232,11 @@ TraceContainer::set_callback (char const *name, Callback<void,T1,T2> callback)
}
template <typename T1, typename T2, typename T3>
void
TraceContainer::set_callback (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)->set_callback (callback);
static_cast<CallbackTracer<T1,T2,T3> *> (i->first)->setCallback (callback);
return;
}
}
@ -246,11 +246,11 @@ TraceContainer::set_callback (char const *name, Callback<void,T1,T2,T3> callback
}
template <typename T1, typename T2, typename T3, typename T4>
void
TraceContainer::set_callback (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)->set_callback (callback);
static_cast<CallbackTracer<T1,T2,T3,T4> *> (i->first)->setCallback (callback);
return;
}
}
@ -260,11 +260,11 @@ TraceContainer::set_callback (char const *name, Callback<void,T1,T2,T3,T4> callb
}
template <typename T1, typename T2, typename T3, typename T4, typename T5>
void
TraceContainer::set_callback (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)->set_callback (callback);
static_cast<CallbackTracer<T1,T2,T3,T4,T5> *> (i->first)->setCallback (callback);
return;
}
}

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

@ -33,7 +33,7 @@ public:
UiVariableTracerBase ()
: m_callback () {}
/* We don't want to copy the base callback. Only set_callback on
/* We don't want to copy the base callback. Only setCallback on
* a specific instance will do something to it. */
UiVariableTracerBase (UiVariableTracerBase const &o)
: m_callback () {}
@ -42,13 +42,13 @@ public:
}
~UiVariableTracerBase () {}
void set_callback(ChangeNotifyCallback callback) {
void setCallback(ChangeNotifyCallback callback) {
m_callback = callback;
}
protected:
void notify (uint64_t old_val, uint64_t new_val) {
if (old_val != new_val && !m_callback.is_null ()) {
m_callback (old_val, new_val);
void notify (uint64_t oldVal, uint64_t newVal) {
if (oldVal != newVal && !m_callback.isNull ()) {
m_callback (oldVal, newVal);
}
}
private:

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

@ -29,24 +29,24 @@ namespace ns3 {
class Foo {
public:
void notify (uint64_t old_val, uint64_t new_val) {}
void notify (uint64_t oldVal, uint64_t newVal) {}
};
class VariableTracerTest: public Test {
public:
VariableTracerTest ();
void run_unsigned_tests (void);
void run_signed_unsigned_tests (void);
virtual bool run_tests (void);
void runUnsignedTests (void);
void runSignedUnsignedTests (void);
virtual bool runTests (void);
};
void
VariableTracerTest::run_unsigned_tests (void)
VariableTracerTest::runUnsignedTests (void)
{
UiVariableTracer<uint32_t> var, ovar, tmp;
uint32_t utmp;
Foo *foo = new Foo ();
var.set_callback (make_callback (&Foo::notify, foo));
var.setCallback (makeCallback (&Foo::notify, foo));
var = 10;
ovar = var;
@ -198,7 +198,7 @@ VariableTracerTest::run_unsigned_tests (void)
}
void
VariableTracerTest::run_signed_unsigned_tests (void)
VariableTracerTest::runSignedUnsignedTests (void)
{
unsigned short utmp = 10;
unsigned int uitmp = 7;
@ -234,10 +234,10 @@ VariableTracerTest::run_signed_unsigned_tests (void)
}
bool
VariableTracerTest::run_tests (void)
VariableTracerTest::runTests (void)
{
run_unsigned_tests ();
run_signed_unsigned_tests ();
runUnsignedTests ();
runSignedUnsignedTests ();
return true;
}
@ -245,7 +245,7 @@ VariableTracerTest::run_tests (void)
VariableTracerTest::VariableTracerTest ()
: Test ("VariableTracer") {}
static VariableTracerTest g_variable_tracer_test;
static VariableTracerTest gVariableTracerTest;
}; // namespace ns3

52
src/core/callback-test.cc

@ -27,23 +27,23 @@
namespace ns3 {
static bool g_test5 = false;
static bool g_test6 = false;
static bool g_test7 = false;
static bool gTest5 = false;
static bool gTest6 = false;
static bool gTest7 = false;
void test5 (void)
{
g_test5 = true;
gTest5 = true;
}
void test6 (int)
{
g_test6 = true;
gTest6 = true;
}
int test7 (int a)
{
g_test7 = true;
gTest7 = true;
return a;
}
@ -55,9 +55,9 @@ private:
bool m_test4;
public:
CallbackTest ();
virtual bool run_tests (void);
virtual bool runTests (void);
void reset (void);
bool is_wrong (void);
bool isWrong (void);
void test1 (void);
int test2 (void);
void test3 (double a);
@ -101,15 +101,15 @@ CallbackTest::test8 (Callback<void,int> callback)
callback (3);
}
bool
CallbackTest::is_wrong (void)
CallbackTest::isWrong (void)
{
if (!m_test1 ||
!m_test2 ||
!m_test3 ||
!m_test4 ||
!g_test5 ||
!g_test6 ||
!g_test7) {
!gTest5 ||
!gTest6 ||
!gTest7) {
return true;
}
return false;
@ -122,14 +122,14 @@ CallbackTest::reset (void)
m_test2 = false;
m_test3 = false;
m_test4 = false;
g_test5 = false;
g_test6 = false;
g_test7 = false;
gTest5 = false;
gTest6 = false;
gTest7 = false;
}
bool
CallbackTest::run_tests (void)
CallbackTest::runTests (void)
{
bool ok = true;
@ -158,19 +158,19 @@ CallbackTest::run_tests (void)
f0 (1);
g0 (1);
if (is_wrong ()) {
if (isWrong ()) {
ok = false;
}
reset ();
A a1 = ns3::make_callback (&CallbackTest::test1, this);
B b1 = ns3::make_callback (&CallbackTest::test2, this);
C c1 = ns3::make_callback (&CallbackTest::test3, this);
D d1 = ns3::make_callback (&CallbackTest::test4, this);
E e1 = ns3::make_callback (&test5);
F f1 = ns3::make_callback (&test6);
G g1 = ns3::make_callback (&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 ();
@ -184,13 +184,13 @@ CallbackTest::run_tests (void)
Callback<void, int64_t,int64_t> a2;
if (is_wrong ()) {
if (isWrong ()) {
ok = false;
}
return ok;
}
static CallbackTest g_callback_test;
static CallbackTest gCallbackTest;
}; // namespace

154
src/core/callback.h

@ -52,7 +52,7 @@ namespace ns3 {
* implementation in that it does not use type lists to specify
* and pass around the types of the callback arguments.
* Of course, it also does not use copy-destruction semantics
* and relies on a reference list rather than auto_ptr to hold
* and relies on a reference list rather than autoPtr to hold
* the pointer.
*/
class empty {};
@ -168,8 +168,8 @@ private:
template <typename OBJ_PTR, typename MEM_PTR, typename R, typename T1, typename T2, typename T3, typename T4, typename T5>
class MemPtrCallbackImpl : public CallbackImpl<R,T1,T2,T3,T4,T5> {
public:
MemPtrCallbackImpl (OBJ_PTR const&obj_ptr, MEM_PTR mem_ptr)
: m_objPtr (obj_ptr), m_memPtr (mem_ptr) {}
MemPtrCallbackImpl (OBJ_PTR const&objPtr, MEM_PTR mem_ptr)
: m_objPtr (objPtr), m_memPtr (mem_ptr) {}
virtual ~MemPtrCallbackImpl () {}
R operator() (void) {
return ((*m_objPtr).*m_memPtr) ();
@ -212,14 +212,14 @@ private:
* - the sixth optional template argument represents
* the type of the fifth argument to the callback.
*
* Callback instances are built with the \ref make_callback
* 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 make_callback :
* as well as the function templates \ref makeCallback :
* \include samples/main-callback.cc
*/
template<typename R,
@ -234,15 +234,15 @@ public:
{}
template <typename OBJ_PTR, typename MEM_PTR>
Callback (OBJ_PTR const &obj_ptr, MEM_PTR mem_ptr)
: m_impl (new MemPtrCallbackImpl<OBJ_PTR,MEM_PTR,R,T1,T2,T3,T4,T5> (obj_ptr, mem_ptr))
Callback (OBJ_PTR const &objPtr, MEM_PTR mem_ptr)
: m_impl (new MemPtrCallbackImpl<OBJ_PTR,MEM_PTR,R,T1,T2,T3,T4,T5> (objPtr, mem_ptr))
{}
Callback (ReferenceList<CallbackImpl<R,T1,T2,T3,T4,T5> *> const &impl)
: m_impl (impl)
{}
bool is_null (void) {
bool isNull (void) {
return (m_impl.get () == 0)?true:false;
}
@ -270,243 +270,243 @@ private:
};
/**
* \defgroup make_callback make_callback
* \defgroup makeCallback makeCallback
*
*/
/**
* \ingroup make_callback
* \ingroup makeCallback
* \param mem_ptr class method member pointer
* \param obj_ptr class instance
* \param objPtr class instance
* \return a wrapper Callback
* Build Callbacks for class method members which takes no arguments
* and potentially return a value.
*/
template <typename OBJ, typename R>
Callback<R> make_callback (R (OBJ::*mem_ptr) (), OBJ *const obj_ptr) {
return Callback<R> (obj_ptr, mem_ptr);
Callback<R> makeCallback (R (OBJ::*mem_ptr) (), OBJ *const objPtr) {
return Callback<R> (objPtr, mem_ptr);
}
/**
* \ingroup make_callback
* \ingroup makeCallback
* \param mem_ptr class method member pointer
* \param obj_ptr class instance
* \param objPtr class instance
* \return a wrapper Callback
* Build Callbacks for class method members which takes one argument
* and potentially return a value.
*/
template <typename OBJ, typename R, typename T1>
Callback<R,T1> make_callback (R (OBJ::*mem_ptr) (T1), OBJ *const obj_ptr) {
return Callback<R,T1> (obj_ptr, mem_ptr);
Callback<R,T1> makeCallback (R (OBJ::*mem_ptr) (T1), OBJ *const objPtr) {
return Callback<R,T1> (objPtr, mem_ptr);
}
/**
* \ingroup make_callback
* \ingroup makeCallback
* \param mem_ptr class method member pointer
* \param obj_ptr class instance
* \param objPtr class instance
* \return a wrapper Callback
* Build Callbacks for class method members which takes two arguments
* and potentially return a value.
*/
template <typename OBJ, typename R, typename T1, typename T2>
Callback<R,T1,T2> make_callback (R (OBJ::*mem_ptr) (T1,T2), OBJ *const obj_ptr) {
return Callback<R,T1,T2> (obj_ptr, mem_ptr);
Callback<R,T1,T2> makeCallback (R (OBJ::*mem_ptr) (T1,T2), OBJ *const objPtr) {
return Callback<R,T1,T2> (objPtr, mem_ptr);
}
/**
* \ingroup make_callback
* \ingroup makeCallback
* \param mem_ptr class method member pointer
* \param obj_ptr class instance
* \param objPtr class instance
* \return a wrapper Callback
* Build Callbacks for class method members which takes three arguments
* and potentially return a value.
*/
template <typename OBJ, typename R, typename T1,typename T2, typename T3>
Callback<R,T1,T2,T3> make_callback (R (OBJ::*mem_ptr) (T1,T2,T3), OBJ *const obj_ptr) {
return Callback<R,T1,T2,T3> (obj_ptr, mem_ptr);
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 make_callback
* \ingroup makeCallback
* \param mem_ptr class method member pointer
* \param obj_ptr class instance
* \param objPtr class instance
* \return a wrapper Callback
* Build Callbacks for class method members which takes four arguments
* and potentially return a value.
*/
template <typename OBJ, typename R, typename T1, typename T2, typename T3, typename T4>
Callback<R,T1,T2,T3,T4> make_callback (R (OBJ::*mem_ptr) (T1,T2,T3,T4), OBJ *const obj_ptr) {
return Callback<R,T1,T2,T3,T4> (obj_ptr, mem_ptr);
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 make_callback
* \ingroup makeCallback
* \param mem_ptr class method member pointer
* \param obj_ptr class instance
* \param objPtr class instance
* \return a wrapper Callback
* Build Callbacks for class method members which takes five arguments
* 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> make_callback (R (OBJ::*mem_ptr) (T1,T2,T3,T4,T5), OBJ *const obj_ptr) {
return Callback<R,T1,T2,T3,T4,T5> (obj_ptr, mem_ptr);
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 make_callback
* \param fn_ptr function pointer
* \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> make_callback (R (*fn_ptr) ()) {
return Callback<R> (fn_ptr);
Callback<R> makeCallback (R (*fnPtr) ()) {
return Callback<R> (fnPtr);
}
/**
* \ingroup make_callback
* \param fn_ptr function pointer
* \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> make_callback (R (*fn_ptr) (T1)) {
return Callback<R,T1> (fn_ptr);
Callback<R,T1> makeCallback (R (*fnPtr) (T1)) {
return Callback<R,T1> (fnPtr);
}
/**
* \ingroup make_callback
* \param fn_ptr function pointer
* \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> make_callback (R (*fn_ptr) (T1,T2)) {
return Callback<R,T1,T2> (fn_ptr);
Callback<R,T1,T2> makeCallback (R (*fnPtr) (T1,T2)) {
return Callback<R,T1,T2> (fnPtr);
}
/**
* \ingroup make_callback
* \param fn_ptr function pointer
* \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> make_callback (R (*fn_ptr) (T1,T2,T3)) {
return Callback<R,T1,T2,T3> (fn_ptr);
Callback<R,T1,T2,T3> makeCallback (R (*fnPtr) (T1,T2,T3)) {
return Callback<R,T1,T2,T3> (fnPtr);
}
/**
* \ingroup make_callback
* \param fn_ptr function pointer
* \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> make_callback (R (*fn_ptr) (T1,T2,T3,T4)) {
return Callback<R,T1,T2,T3,T4> (fn_ptr);
Callback<R,T1,T2,T3,T4> makeCallback (R (*fnPtr) (T1,T2,T3,T4)) {
return Callback<R,T1,T2,T3,T4> (fnPtr);
}
/**
* \ingroup make_callback
* \param fn_ptr function pointer
* \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> make_callback (R (*fn_ptr) (T1,T2,T3,T4,T5)) {
return Callback<R,T1,T2,T3,T4,T5> (fn_ptr);
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 make_callback
* \ingroup makeCallback
* \return a wrapper Callback
* Build a null callback which takes no arguments
* and potentially return a value.
*/
template <typename R>
Callback<R> make_null_callback (void) {
Callback<R> makeNullCallback (void) {
return Callback<R> ();
}
/**
* \ingroup make_callback
* \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> make_null_callback (void) {
Callback<R,T1> makeNullCallback (void) {
return Callback<R,T1> ();
}
/**
* \ingroup make_callback
* \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> make_null_callback (void) {
Callback<R,T1,T2> makeNullCallback (void) {
return Callback<R,T1,T2> ();
}
/**
* \ingroup make_callback
* \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> make_null_callback (void) {
Callback<R,T1,T2,T3> makeNullCallback (void) {
return Callback<R,T1,T2,T3> ();
}
/**
* \ingroup make_callback
* \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> make_null_callback (void) {
Callback<R,T1,T2,T3,T4> makeNullCallback (void) {
return Callback<R,T1,T2,T3,T4> ();
}
/**
* \ingroup make_callback
* \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> make_null_callback (void) {
Callback<R,T1,T2,T3,T4,T5> makeNullCallback (void) {
return Callback<R,T1,T2,T3,T4,T5> ();
}
template <typename R, typename TX, typename T1>
Callback<R,T1> make_bound_callback (R (*fn_ptr) (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> (fn_ptr, a)
new BoundFunctorCallbackImpl<R (*) (TX,T1),R,TX,T1,empty,empty,empty,empty> (fnPtr, a)
);
return Callback<R,T1> (impl);
}
template <typename R, typename TX, typename T1, typename T2>
Callback<R,T1,T2> make_bound_callback (R (*fn_ptr) (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> (fn_ptr, a)
new BoundFunctorCallbackImpl<R (*) (TX,T1,T2),R,TX,T1,T2,empty,empty,empty> (fnPtr, 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> make_bound_callback (R (*fn_ptr) (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> (fn_ptr, a)
new BoundFunctorCallbackImpl<R (*) (TX,T1,T2,T3,T4),R,TX,T1,T2,T3,T4,empty> (fnPtr, a)
);
return Callback<R,T1,T2,T3,T4> (impl);
}
template <typename R, typename TX, typename T1, typename T2,typename T3,typename T4,typename T5>
Callback<R,T1,T2,T3,T4,T5> make_bound_callback (R (*fn_ptr) (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> (fn_ptr, a)
new BoundFunctorCallbackImpl<R (*) (TX,T1,T2,T3,T4,T5),R,TX,T1,T2,T3,T4,T5> (fnPtr, a)
);
return Callback<R,T1,T2,T3,T4,T5> (impl);
}

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

@ -51,7 +51,7 @@ public:
class RefTest : public ns3::Test {
public:
RefTest ();
virtual bool run_tests (void);
virtual bool runTests (void);
private:
void test (ns3::ReferenceList<A *>);
};
@ -67,7 +67,7 @@ RefTest::test (ns3::ReferenceList<A *> a)
}
bool
RefTest::run_tests (void)
RefTest::runTests (void)
{
bool ok = true;
@ -113,7 +113,7 @@ RefTest::run_tests (void)
}
static RefTest g_ref_test = RefTest ();
static RefTest gRefTest = RefTest ();
}; // namespace

24
src/core/reference-list.h

@ -52,7 +52,7 @@ public:
{
m_prev = this;
m_next = this;
insert_self_in_other (o);
insertSelfInOther (o);
}
ReferenceList (ReferenceList const&o)
: m_objPtr (),
@ -61,10 +61,10 @@ public:
{
m_prev = this;
m_next = this;
insert_self_in_other (o);
insertSelfInOther (o);
}
ReferenceList (OBJ_PTR const &obj_ptr)
: m_objPtr (obj_ptr),
ReferenceList (OBJ_PTR const &objPtr)
: m_objPtr (objPtr),
m_prev (),
m_next ()
{
@ -72,33 +72,33 @@ public:
m_next = this;
}
~ReferenceList () {
remove_from_list ();
removeFrom_list ();
}
ReferenceList & operator= (ReferenceList const&o) {
remove_from_list ();
insert_self_in_other (o);
removeFrom_list ();
insertSelfInOther (o);
return *this;
}
OBJ_PTR operator-> () {
return m_objPtr;
}
void set (OBJ_PTR obj_ptr) {
remove_from_list ();
m_objPtr = obj_ptr;
void set (OBJ_PTR objPtr) {
removeFrom_list ();
m_objPtr = objPtr;
}
OBJ_PTR get (void) {
// explicit conversion to raw pointer type.
return m_objPtr;
}
private:
void insert_self_in_other (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 remove_from_list (void) {
void removeFrom_list (void) {
if (m_prev == this) {
//assert (m_next == this);
delete m_objPtr;

24
src/core/test.cc

@ -51,7 +51,7 @@ TestManager::add (Test *test, char const *name)
get ()->m_tests.push_back (std::make_pair (test, new std::string (name)));
}
void
TestManager::enable_verbose (void)
TestManager::enableVerbose (void)
{
get ()->m_verbose = true;
}
@ -61,31 +61,31 @@ TestManager::failure (void)
return std::cerr;
}
bool
TestManager::run_tests (void)
TestManager::runTests (void)
{
return get ()->real_run_tests ();
return get ()->realRunTests ();
}
bool
TestManager::real_run_tests (void)
TestManager::realRunTests (void)
{
bool is_success = true;
bool isSuccess = true;
for (TestsCI i = m_tests.begin (); i != m_tests.end (); i++) {
std::string *test_name = (*i).second;
if (!(*i).first->run_tests ()) {
is_success = false;
std::string *testName = (*i).second;
if (!(*i).first->runTests ()) {
isSuccess = false;
if (m_verbose) {
std::cerr << "FAIL " << *test_name << std::endl;
std::cerr << "FAIL " << *testName << std::endl;
}
} else {
if (m_verbose) {
std::cerr << "PASS "<<*test_name << std::endl;
std::cerr << "PASS "<<*testName << std::endl;
}
}
}
if (!is_success) {
if (!isSuccess) {
std::cerr << "FAIL" << std::endl;
}
return is_success;
return isSuccess;
}
Test::Test (char const *name)

8
src/core/test.h

@ -38,7 +38,7 @@ public:
Test (char const *name);
virtual ~Test ();
virtual bool run_tests (void) = 0;
virtual bool runTests (void) = 0;
protected:
std::ostream &failure (void);
@ -48,15 +48,15 @@ class TestManager {
public:
// main methods the test runner is supposed to
// invoke.
static void enable_verbose (void);
static bool run_tests (void);
static void enableVerbose (void);
static bool runTests (void);
// helper methods
static void add (Test *test, char const *name);
static std::ostream &failure (void);
private:
static TestManager *get (void);
bool real_run_tests (void);
bool realRunTests (void);
TestManager ();
~TestManager ();

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

@ -82,11 +82,11 @@ void
SystemFilePrivate::write (uint8_t *buffer, uint32_t size)
{
while (size > 0) {
uint32_t to_copy = min (BUFFER_SIZE - m_current, size);
memcpy (m_data + m_current, buffer, to_copy);
size -= to_copy;
m_current += to_copy;
buffer += to_copy;
uint32_t toCopy = min (BUFFER_SIZE - m_current, size);
memcpy (m_data + m_current, buffer, toCopy);
size -= toCopy;
m_current += toCopy;
buffer += toCopy;
if (m_current == BUFFER_SIZE) {
ssize_t written = 0;
written = ::write (m_fd, m_data, BUFFER_SIZE);

10
src/simulator/event-id.cc

@ -40,22 +40,22 @@ EventId::cancel (void)
Simulator::cancel (*this);
}
bool
EventId::is_expired (void)
EventId::isExpired (void)
{
return Simulator::is_expired (*this);
return Simulator::isExpired (*this);
}
EventImpl *
EventId::get_event_impl (void) const
EventId::getEventImpl (void) const
{
return m_eventImpl;
}
uint64_t
EventId::get_ns (void) const
EventId::getNs (void) const
{
return m_ns;
}
uint32_t
EventId::get_uid (void) const
EventId::getUid (void) const
{
return m_uid;
}

8
src/simulator/event-id.h

@ -32,15 +32,15 @@ public:
EventId ();
EventId (EventImpl *impl, uint64_t ns, uint32_t uid);
void cancel (void);
bool is_expired (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 *get_event_impl (void) const;
uint64_t get_ns (void) const;
uint32_t get_uid (void) const;
EventImpl *getEventImpl (void) const;
uint64_t getNs (void) const;
uint32_t getUid (void) const;
private:
EventImpl *m_eventImpl;
uint64_t m_ns;

4
src/simulator/event-impl.cc

@ -40,12 +40,12 @@ EventImpl::invoke (void)
}
}
void
EventImpl::set_internal_iterator (void *tag)
EventImpl::setInternalIterator (void *tag)
{
m_internalIterator = tag;
}
void *
EventImpl::get_internal_iterator (void) const
EventImpl::getInternalIterator (void) const
{
return m_internalIterator;
}

4
src/simulator/event-impl.h

@ -31,8 +31,8 @@ public:
virtual ~EventImpl () = 0;
void invoke (void);
void cancel (void);
void set_internal_iterator (void *iterator);
void *get_internal_iterator (void) const;
void setInternalIterator (void *iterator);
void *getInternalIterator (void) const;
protected:
virtual void notify (void) = 0;
private:

2
src/simulator/scheduler-factory.cc

@ -28,7 +28,7 @@ SchedulerFactory::~SchedulerFactory ()
Scheduler *
SchedulerFactory::create (void) const
{
return real_create ();
return realCreate ();
}
}; // namespace ns3

4
src/simulator/scheduler-factory.h

@ -31,7 +31,7 @@ class Scheduler;
* If you want to make the core simulation engine use a new
* event scheduler without editing the code of the simulator,
* you need to create a subclass of this base class and implement
* the ns3::SchedulerFactory::real_create method.
* the ns3::SchedulerFactory::realCreate method.
*/
class SchedulerFactory {
public:
@ -42,7 +42,7 @@ private:
* \returns a newly-created scheduler. The caller takes
* ownership of the returned pointer.
*/
virtual Scheduler *real_create (void) const = 0;
virtual Scheduler *realCreate (void) const = 0;
};
}; // namespace ns3

86
src/simulator/scheduler-heap.cc

@ -56,22 +56,22 @@ SchedulerHeap::SchedulerHeap ()
// we purposedly waste an item at the start of
// the array to make sure the indexes in the
// array start at one.
Scheduler::EventKey empty_key = {0,0};
m_heap.push_back (std::make_pair (static_cast<EventImpl *>(0), empty_key));
Scheduler::EventKey emptyKey = {0,0};
m_heap.push_back (std::make_pair (static_cast<EventImpl *>(0), emptyKey));
}
SchedulerHeap::~SchedulerHeap ()
{}
void
SchedulerHeap::store_in_event (EventImpl *ev, uint32_t index) const
SchedulerHeap::storeInEvent (EventImpl *ev, uint32_t index) const
{
ev->set_internal_iterator ((void *)index);
ev->setInternalIterator ((void *)index);
}
uint32_t
SchedulerHeap::get_from_event (EventImpl *ev) const
SchedulerHeap::getFrom_event (EventImpl *ev) const
{
return (uint32_t)ev->get_internal_iterator ();
return (uint32_t)ev->getInternalIterator ();
}
uint32_t
SchedulerHeap::parent (uint32_t id) const
@ -84,12 +84,12 @@ SchedulerHeap::sibling (uint32_t id) const
return id + 1;
}
uint32_t
SchedulerHeap::left_child (uint32_t id) const
SchedulerHeap::leftChild (uint32_t id) const
{
return id * 2;
}
uint32_t
SchedulerHeap::right_child (uint32_t id) const
SchedulerHeap::rightChild (uint32_t id) const
{
return id * 2 + 1;
}
@ -101,7 +101,7 @@ SchedulerHeap::root (void) const
}
bool
SchedulerHeap::is_root (uint32_t id) const
SchedulerHeap::isRoot (uint32_t id) const
{
return (id == root ())?true:false;
}
@ -114,7 +114,7 @@ SchedulerHeap::last (void) const
bool
SchedulerHeap::is_bottom (uint32_t id) const
SchedulerHeap::isBottom (uint32_t id) const
{
return (id >= m_heap.size ())?true:false;
}
@ -127,12 +127,12 @@ SchedulerHeap::exch (uint32_t a, uint32_t b)
std::pair<EventImpl*, Scheduler::EventKey> tmp (m_heap[a]);
m_heap[a] = m_heap[b];
m_heap[b] = tmp;
store_in_event (m_heap[a].first, a);
store_in_event (m_heap[b].first, b);
storeInEvent (m_heap[a].first, a);
storeInEvent (m_heap[b].first, b);
}
bool
SchedulerHeap::is_less (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);
@ -141,11 +141,11 @@ SchedulerHeap::is_less (uint32_t a, uint32_t b)
uint32_t
SchedulerHeap::smallest (uint32_t a, uint32_t b)
{
return is_less (a,b)?a:b;
return isLess (a,b)?a:b;
}
bool
SchedulerHeap::real_is_empty (void) const
SchedulerHeap::realIsEmpty (void) const
{
return (m_heap.size () == 1)?true:false;
}
@ -154,37 +154,37 @@ void
SchedulerHeap::bottom_up (void)
{
uint32_t index = last ();
while (!is_root (index) &&
is_less (index, parent (index))) {
while (!isRoot (index) &&
isLess (index, parent (index))) {
exch(index, parent (index));
index = parent (index);
}
}
void
SchedulerHeap::top_down (void)
SchedulerHeap::topDown (void)
{
uint32_t index = root ();
uint32_t right = right_child (index);
while (!is_bottom (right)) {
uint32_t left = left_child (index);
uint32_t right = rightChild (index);
while (!isBottom (right)) {
uint32_t left = leftChild (index);
uint32_t tmp = smallest (left, right);
if (is_less (index, tmp)) {
if (isLess (index, tmp)) {
return;
}
exch (index, tmp);
index = tmp;
right = right_child (index);
right = rightChild (index);
}
if (is_bottom (index)) {
if (isBottom (index)) {
return;
}
assert (!is_bottom (index));
uint32_t left = left_child (index);
if (is_bottom (left)) {
assert (!isBottom (index));
uint32_t left = leftChild (index);
if (isBottom (left)) {
return;
}
if (is_less (index, left)) {
if (isLess (index, left)) {
return;
}
exch (index, left);
@ -192,52 +192,52 @@ SchedulerHeap::top_down (void)
EventId
SchedulerHeap::real_insert (EventImpl *event, Scheduler::EventKey key)
SchedulerHeap::realInsert (EventImpl *event, Scheduler::EventKey key)
{
m_heap.push_back (std::make_pair (event, key));
bottom_up ();
store_in_event (event, last ());
storeInEvent (event, last ());
return EventId (event, key.m_ns, key.m_uid);
}
EventImpl *
SchedulerHeap::real_peek_next (void) const
SchedulerHeap::realPeekNext (void) const
{
return m_heap[root ()].first;
}
Scheduler::EventKey
SchedulerHeap::real_peek_next_key (void) const
SchedulerHeap::realPeekNextKey (void) const
{
return m_heap[root ()].second;
}
void
SchedulerHeap::real_remove_next (void)
SchedulerHeap::realRemoveNext (void)
{
exch (root (), last ());
m_heap.pop_back ();
top_down ();
topDown ();
}
EventImpl *
SchedulerHeap::real_remove (EventId id, Scheduler::EventKey *key)
SchedulerHeap::realRemove (EventId id, Scheduler::EventKey *key)
{
EventImpl *ev = id.get_event_impl ();
uint32_t i = get_from_event (ev);
EventImpl *ev = id.getEventImpl ();
uint32_t i = getFrom_event (ev);
*key = m_heap[i].second;
exch (i, last ());
m_heap.pop_back ();
top_down ();
topDown ();
return ev;
}
bool
SchedulerHeap::real_is_valid (EventId id)
SchedulerHeap::realIsValid (EventId id)
{
EventImpl *ev = id.get_event_impl ();
uint32_t i = get_from_event (ev);
EventImpl *ev = id.getEventImpl ();
uint32_t i = getFrom_event (ev);
Scheduler::EventKey key = m_heap[i].second;
return (key.m_ns == id.get_ns () &&
key.m_uid == id.get_uid ());
return (key.m_ns == id.getNs () &&
key.m_uid == id.getUid ());
}
}; // namespace ns3

30
src/simulator/scheduler-heap.h

@ -36,32 +36,32 @@ public:
virtual ~SchedulerHeap ();
private:
virtual EventId real_insert (EventImpl *event, Scheduler::EventKey key);
virtual bool real_is_empty (void) const;
virtual EventImpl *real_peek_next (void) const;
virtual Scheduler::EventKey real_peek_next_key (void) const;
virtual void real_remove_next (void);
virtual EventImpl *real_remove (EventId ev, Scheduler::EventKey *key);
virtual bool real_is_valid (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 store_in_event (EventImpl *ev, uint32_t index) const;
uint32_t get_from_event (EventImpl *ev) const;
inline void storeInEvent (EventImpl *ev, uint32_t index) const;
uint32_t getFrom_event (EventImpl *ev) const;
inline uint32_t parent (uint32_t id) const;
uint32_t sibling (uint32_t id) const;
inline uint32_t left_child (uint32_t id) const;
inline uint32_t right_child (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 is_root (uint32_t id) const;
inline bool is_bottom (uint32_t id) const;
inline bool is_less (uint32_t a, uint32_t b);
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 top_down (void);
void topDown (void);
BinaryHeap m_heap;
};

46
src/simulator/scheduler-list.cc

@ -38,81 +38,81 @@ SchedulerList::~SchedulerList ()
* member variable, a pointer.
*/
EventId
SchedulerList::get_event_id (Scheduler::EventKey key, EventsI i)
SchedulerList::getEventId (Scheduler::EventKey key, EventsI i)
{
assert (sizeof (i) <= sizeof (void *));
void *internal_iterator;
memcpy ((char *)&(internal_iterator), (char *)&i, sizeof (void *));
void *internalIterator;
memcpy ((char *)&(internalIterator), (char *)&i, sizeof (void *));
EventImpl *ev = i->first;
ev->set_internal_iterator (internal_iterator);
ev->setInternalIterator (internalIterator);
return EventId (ev, key.m_ns, key.m_uid);
}
SchedulerList::EventsI
SchedulerList::get_iterator (EventId id)
SchedulerList::getIterator (EventId id)
{
SchedulerList::EventsI i;
assert (sizeof (i) <= sizeof (void *));
EventImpl *ev = id.get_event_impl ();
void *internal_iterator = ev->get_internal_iterator ();
memcpy ((char *)&i, (char *)&(internal_iterator), sizeof (void *));
EventImpl *ev = id.getEventImpl ();
void *internalIterator = ev->getInternalIterator ();
memcpy ((char *)&i, (char *)&(internalIterator), sizeof (void *));
return i;
}
EventId
SchedulerList::real_insert (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 get_event_id (key, i);
return getEventId (key, i);
}
}
m_events.push_back (std::make_pair (event, key));
return get_event_id (key, --(m_events.end ()));
return getEventId (key, --(m_events.end ()));
}
bool
SchedulerList::real_is_empty (void) const
SchedulerList::realIsEmpty (void) const
{
return m_events.empty ();
}
EventImpl *
SchedulerList::real_peek_next (void) const
SchedulerList::realPeekNext (void) const
{
return m_events.front ().first;
}
Scheduler::EventKey
SchedulerList::real_peek_next_key (void) const
SchedulerList::realPeekNextKey (void) const
{
return m_events.front ().second;
}
void
SchedulerList::real_remove_next (void)
SchedulerList::realRemoveNext (void)
{
m_events.pop_front ();
}
EventImpl *
SchedulerList::real_remove (EventId id, Scheduler::EventKey *key)
SchedulerList::realRemove (EventId id, Scheduler::EventKey *key)
{
EventsI i = get_iterator (id);
EventsI i = getIterator (id);
*key = i->second;
assert (key->m_ns == id.get_ns () &&
key->m_uid == id.get_uid ());
assert (key->m_ns == id.getNs () &&
key->m_uid == id.getUid ());
EventImpl *ev = i->first;
m_events.erase (i);
return ev;
}
bool
SchedulerList::real_is_valid (EventId id)
SchedulerList::realIsValid (EventId id)
{
EventsI i = get_iterator (id);
EventsI i = getIterator (id);
Scheduler::EventKey key = i->second;
return (key.m_ns == id.get_ns () &&
key.m_uid == id.get_uid ());
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 real_insert (EventImpl *event, EventKey key);
virtual bool real_is_empty (void) const;
virtual EventImpl *real_peek_next (void) const;
virtual Scheduler::EventKey real_peek_next_key (void) const;
virtual void real_remove_next (void);
virtual EventImpl *real_remove (EventId ev, Scheduler::EventKey *key);
virtual bool real_is_valid (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 get_event_id (Scheduler::EventKey key, EventsI i);
EventsI get_iterator (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::store_in_event (EventImpl *ev, EventMapI i) const
SchedulerMap::storeInEvent (EventImpl *ev, EventMapI i) const
{
void *tag;
memcpy (&(tag), &i, sizeof (tag));
ev->set_internal_iterator (tag);
ev->setInternalIterator (tag);
}
SchedulerMap::EventMapI
SchedulerMap::get_from_event (EventImpl *ev) const
SchedulerMap::getFrom_event (EventImpl *ev) const
{
EventMapI i;
void *tag = ev->get_internal_iterator ();
void *tag = ev->getInternalIterator ();
memcpy (&i, &(tag), sizeof (i));
return i;
}
EventId
SchedulerMap::real_insert (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);
store_in_event (event, result.first);
storeInEvent (event, result.first);
return EventId (event, key.m_ns, key.m_uid);
}
bool
SchedulerMap::real_is_empty (void) const
SchedulerMap::realIsEmpty (void) const
{
return m_list.empty ();
}
EventImpl *
SchedulerMap::real_peek_next (void) const
SchedulerMap::realPeekNext (void) const
{
EventMapCI i = m_list.begin ();
assert (i != m_list.end ());
return (*i).second;
}
Scheduler::EventKey
SchedulerMap::real_peek_next_key (void) const
SchedulerMap::realPeekNextKey (void) const
{
EventMapCI i = m_list.begin ();
assert (i != m_list.end ());
return (*i).first;
}
void
SchedulerMap::real_remove_next (void)
SchedulerMap::realRemoveNext (void)
{
m_list.erase (m_list.begin ());
}
EventImpl *
SchedulerMap::real_remove (EventId id, Scheduler::EventKey *key)
SchedulerMap::realRemove (EventId id, Scheduler::EventKey *key)
{
EventMapI i = get_from_event (id.get_event_impl ());
EventMapI i = getFrom_event (id.getEventImpl ());
*key = i->first;
m_list.erase (i);
return i->second;
}
bool
SchedulerMap::real_is_valid (EventId id)
SchedulerMap::realIsValid (EventId id)
{
EventMapI i = get_from_event (id.get_event_impl ());
EventMapI i = getFrom_event (id.getEventImpl ());
Scheduler::EventKey key = i->first;
return (key.m_ns == id.get_ns () &&
key.m_uid == id.get_uid ());
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 real_insert (EventImpl *event, Scheduler::EventKey key);
virtual bool real_is_empty (void) const;
virtual EventImpl *real_peek_next (void) const;
virtual Scheduler::EventKey real_peek_next_key (void) const;
virtual void real_remove_next (void);
virtual EventImpl *real_remove (EventId ev, Scheduler::EventKey *key);
virtual bool real_is_valid (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 store_in_event (EventImpl *ev, EventMapI i) const;
SchedulerMap::EventMapI get_from_event (EventImpl *ev) const;
void storeInEvent (EventImpl *ev, EventMapI i) const;
SchedulerMap::EventMapI getFrom_event (EventImpl *ev) const;
EventMap m_list;
uint32_t m_uid;

32
src/simulator/scheduler.cc

@ -49,41 +49,41 @@ Scheduler::EventKeyCompare::operator () (struct EventKey a, struct EventKey b)
EventId
Scheduler::insert (EventImpl *event, struct EventKey key)
{
return real_insert (event, key);
return realInsert (event, key);
}
bool
Scheduler::is_empty (void) const
Scheduler::isEmpty (void) const
{
return real_is_empty ();
return realIsEmpty ();
}
EventImpl *
Scheduler::peek_next (void) const
Scheduler::peekNext (void) const
{
assert (!real_is_empty ());
return real_peek_next ();
assert (!realIsEmpty ());
return realPeekNext ();
}
Scheduler::EventKey
Scheduler::peek_next_key (void) const
Scheduler::peekNextKey (void) const
{
assert (!real_is_empty ());
return real_peek_next_key ();
assert (!realIsEmpty ());
return realPeekNextKey ();
}
void
Scheduler::remove_next (void)
Scheduler::removeNext (void)
{
assert (!real_is_empty ());
return real_remove_next ();
assert (!realIsEmpty ());
return realRemoveNext ();
}
EventImpl *
Scheduler::remove (EventId id, EventKey *key)
{
assert (!real_is_empty ());
return real_remove (id, key);
assert (!realIsEmpty ());
return realRemove (id, key);
}
bool
Scheduler::is_valid (EventId id)
Scheduler::isValid (EventId id)
{
return real_is_valid (id);
return realIsValid (id);
}
}; // namespace ns3

40
src/simulator/scheduler.h

@ -36,18 +36,18 @@ class EventImpl;
* event list. If you want to provide a new event list scheduler,
* you need to create a subclass of this base class and implement
* all the private pure virtual methods defined here. Namely:
* - ns3::Scheduler::real_insert
* - ns3::Scheduler::real_is_empty
* - ns3::Scheduler::real_peek_next
* - ns3::Scheduler::real_peek_next_key
* - ns3::Scheduler::real_remove_next
* - ns3::Scheduler::real_remove
* - ns3::Scheduler::real_is_valid
* - ns3::Scheduler::realInsert
* - ns3::Scheduler::realIsEmpty
* - ns3::Scheduler::realPeekNext
* - ns3::Scheduler::realPeekNextKey
* - ns3::Scheduler::realRemoveNext
* - ns3::Scheduler::realRemove
* - ns3::Scheduler::realIsValid
*
* If you need to provide a new event list scheduler without
* editing the main simulator class, you need to also implement
* a subclass of the ns3::SchedulerFactory base class and
* feed it to ns3::Simulator::set_external.
* feed it to ns3::Simulator::setExternal.
*/
class Scheduler {
public:
@ -63,12 +63,12 @@ class Scheduler {
virtual ~Scheduler () = 0;
EventId insert (EventImpl *event, EventKey key);
bool is_empty (void) const;
EventImpl *peek_next (void) const;
Scheduler::EventKey peek_next_key (void) const ;
void remove_next (void);
bool isEmpty (void) const;
EventImpl *peekNext (void) const;
Scheduler::EventKey peekNextKey (void) const ;
void removeNext (void);
EventImpl *remove (EventId id, EventKey *key);
bool is_valid (EventId id);
bool isValid (EventId id);
private:
/**
@ -78,29 +78,29 @@ private:
*
* This method takes ownership of the event pointer.
*/
virtual EventId real_insert (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 real_is_empty (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 *real_peek_next (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 real_peek_next_key (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 real_remove_next (void) = 0;
virtual void realRemoveNext (void) = 0;
/**
* \param id the id of the event to remove
* \param key the timecode of the event removed
@ -109,13 +109,13 @@ private:
*
* This methods cannot be invoked if the list is empty.
*/
virtual EventImpl *real_remove (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 real_is_valid (EventId id) = 0;
virtual bool realIsValid (EventId id) = 0;
};
}; // namespace ns3

122
src/simulator/simulator.cc

@ -35,7 +35,7 @@
#ifdef TRACE_SIMU
#include <iostream>
# define TRACE(x) \
std::cout << "SIMU TRACE " << Simulator::now_s () << " " << 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 enable_log_to (char const *filename);
void enableLogTo (char const *filename);
bool is_finished (void) const;
bool isFinished (void) const;
Time next (void) const;
void stop (void);
void stop_at (Time time);
void stopAt (Time time);
EventId schedule (Time time, EventImpl *event);
void remove (EventId ev);
void cancel (EventId ev);
bool is_expired (EventId ev);
bool isExpired (EventId ev);
void run (void);
Time now (void) const;
private:
void process_one_event (void);
void processOneEvent (void);
typedef std::list<std::pair<EventImpl *,uint32_t> > Events;
Events m_destroy;
@ -109,48 +109,48 @@ SimulatorPrivate::~SimulatorPrivate ()
void
SimulatorPrivate::enable_log_to (char const *filename)
SimulatorPrivate::enableLogTo (char const *filename)
{
m_log.open (filename);
m_logEnable = true;
}
void
SimulatorPrivate::process_one_event (void)
{
EventImpl *next_ev = m_events->peek_next ();
Scheduler::EventKey next_key = m_events->peek_next_key ();
m_events->remove_next ();
TRACE ("handle " << next_ev);
m_currentNs = next_key.m_ns;
m_currentUid = next_key.m_uid;
SimulatorPrivate::processOneEvent (void)
{
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 "<<next_key.m_uid << " " << next_key.m_ns << std::endl;
m_log << "e "<<nextKey.m_uid << " " << nextKey.m_ns << std::endl;
}
next_ev->invoke ();
delete next_ev;
nextEv->invoke ();
delete nextEv;
}
bool
SimulatorPrivate::is_finished (void) const
SimulatorPrivate::isFinished (void) const
{
return m_events->is_empty ();
return m_events->isEmpty ();
}
Time
SimulatorPrivate::next (void) const
{
assert (!m_events->is_empty ());
Scheduler::EventKey next_key = m_events->peek_next_key ();
return Time::abs_ns (next_key.m_ns);
assert (!m_events->isEmpty ());
Scheduler::EventKey nextKey = m_events->peekNextKey ();
return Time::absNs (nextKey.m_ns);
}
void
SimulatorPrivate::run (void)
{
while (!m_events->is_empty () && !m_stop &&
while (!m_events->isEmpty () && !m_stop &&
(m_stopAt == 0 || m_stopAt > next ().ns ())) {
process_one_event ();
processOneEvent ();
}
m_log.close ();
}
@ -162,14 +162,14 @@ SimulatorPrivate::stop (void)
m_stop = true;
}
void
SimulatorPrivate::stop_at (Time at)
SimulatorPrivate::stopAt (Time at)
{
m_stopAt = at.ns ();
}
EventId
SimulatorPrivate::schedule (Time time, EventImpl *event)
{
if (time.is_destroy ()) {
if (time.isDestroy ()) {
m_destroy.push_back (std::make_pair (event, m_uid));
if (m_logEnable) {
m_log << "id " << m_currentUid << " " << now ().ns () << " "
@ -191,7 +191,7 @@ SimulatorPrivate::schedule (Time time, EventImpl *event)
Time
SimulatorPrivate::now (void) const
{
return Time::abs_ns (m_currentNs);
return Time::absNs (m_currentNs);
}
void
@ -209,17 +209,17 @@ SimulatorPrivate::remove (EventId ev)
void
SimulatorPrivate::cancel (EventId id)
{
assert (m_events->is_valid (id));
EventImpl *ev = id.get_event_impl ();
assert (m_events->isValid (id));
EventImpl *ev = id.getEventImpl ();
ev->cancel ();
}
bool
SimulatorPrivate::is_expired (EventId ev)
SimulatorPrivate::isExpired (EventId ev)
{
if (ev.get_event_impl () != 0 &&
ev.get_ns () <= now ().ns () &&
ev.get_uid () < 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::set_linked_list (void)
void Simulator::setLinkedList (void)
{
m_listType = LINKED_LIST;
}
void Simulator::set_binary_heap (void)
void Simulator::setBinaryHeap (void)
{
m_listType = BINARY_HEAP;
}
void Simulator::set_std_map (void)
void Simulator::setStdMap (void)
{
m_listType = STD_MAP;
}
void
Simulator::set_external (SchedulerFactory const*factory)
Simulator::setExternal (SchedulerFactory const*factory)
{
assert (factory != 0);
m_schedFactory = factory;
m_listType = EXTERNAL;
}
void Simulator::enable_log_to (char const *filename)
void Simulator::enableLogTo (char const *filename)
{
get_priv ()->enable_log_to (filename);
getPriv ()->enableLogTo (filename);
}
SimulatorPrivate *
Simulator::get_priv (void)
Simulator::getPriv (void)
{
if (m_priv == 0) {
Scheduler *events;
@ -303,60 +303,60 @@ Simulator::destroy (void)
bool
Simulator::is_finished (void)
Simulator::isFinished (void)
{
return get_priv ()->is_finished ();
return getPriv ()->isFinished ();
}
Time
Simulator::next (void)
{
return get_priv ()->next ();
return getPriv ()->next ();
}
void
Simulator::run (void)
{
get_priv ()->run ();
getPriv ()->run ();
}
void
Simulator::stop (void)
{
TRACE ("stop");
get_priv ()->stop ();
getPriv ()->stop ();
}
void
Simulator::stop_at (Time at)
Simulator::stopAt (Time at)
{
get_priv ()->stop_at (at);
getPriv ()->stopAt (at);
}
Time
Simulator::now (void)
{
return get_priv ()->now ();
return getPriv ()->now ();
}
EventId
Simulator::schedule (Time time, EventImpl *ev)
{
return get_priv ()->schedule (time, ev);
return getPriv ()->schedule (time, ev);
}
void
Simulator::remove (EventId ev)
{
return get_priv ()->remove (ev);
return getPriv ()->remove (ev);
}
void
Simulator::cancel (EventId ev)
{
return get_priv ()->cancel (ev);
return getPriv ()->cancel (ev);
}
bool
Simulator::is_expired (EventId id)
Simulator::isExpired (EventId id)
{
return get_priv ()->is_expired (id);
return getPriv ()->isExpired (id);
}
}; // namespace ns3
@ -372,7 +372,7 @@ class SimulatorTests : public Test {
public:
SimulatorTests ();
virtual ~SimulatorTests ();
virtual bool run_tests (void);
virtual bool runTests (void);
private:
void a (int a);
void b (int b);
@ -404,7 +404,7 @@ SimulatorTests::b (int b)
m_b = true;
}
Simulator::remove (m_idC);
Simulator::schedule (Time::rel_us (10), &SimulatorTests::d, this, 4);
Simulator::schedule (Time::relUs (10), &SimulatorTests::d, this, 4);
}
void
SimulatorTests::c (int c)
@ -421,16 +421,16 @@ SimulatorTests::d (int d)
}
}
bool
SimulatorTests::run_tests (void)
SimulatorTests::runTests (void)
{
bool ok = true;
m_a = true;
m_b = false;
m_c = true;
m_d = false;
EventId a = Simulator::schedule (Time::abs_us (10), &SimulatorTests::a, this, 1);
EventId b = Simulator::schedule (Time::abs_us (11), &SimulatorTests::b, this, 2);
m_idC = Simulator::schedule (Time::abs_us (12), &SimulatorTests::c, this, 3);
EventId a = Simulator::schedule (Time::absUs (10), &SimulatorTests::a, this, 1);
EventId b = 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 ();
@ -442,7 +442,7 @@ SimulatorTests::run_tests (void)
return ok;
}
SimulatorTests g_simulator_tests;
SimulatorTests gSimulatorTests;
}; // namespace ns3

24
src/simulator/simulator.h

@ -52,7 +52,7 @@ public:
* - insert: O(n)
* - remove: O(1)
*/
static void set_linked_list (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
@ -60,7 +60,7 @@ public:
* - insert: O(log(n))
* - remove: O(log(n))
*/
static void set_binary_heap (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
@ -68,14 +68,14 @@ public:
* - insert: O(log(n))
* - remove: O(log(n))
*/
static void set_std_map (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 set_external (SchedulerFactory const*factory);
static void setExternal (SchedulerFactory const*factory);
/**
* Enable logging to the file identified by filename. If the file
@ -90,10 +90,10 @@ public:
* This method must be invoked before any call to Simulator::run
* @param filename the name of the file to log to
*/
static void enable_log_to (char const *filename);
static void enableLogTo (char const *filename);
/**
* Every event scheduled by the Simulator::insert_at_destroy method is
* Every event scheduled by the Simulator::insertAtDestroy method is
* invoked. Then, we ensure that any memory allocated by the
* Simulator is freed.
* This method is typically invoked at the end of a simulation
@ -109,9 +109,9 @@ public:
* If there any any events lefts to be scheduled, return
* true. Return false otherwise.
*/
static bool is_finished (void);
static bool isFinished (void);
/**
* If Simulator::is_finished returns true, the behavior of this
* 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.
*/
@ -121,7 +121,7 @@ public:
* Run the simulation until one of:
* - no events are present anymore
* - the user called Simulator::stop
* - the user called Simulator::stop_at_us and the
* - the user called Simulator::stopAtUs and the
* expiration time of the next event to be processed
* is greater than or equal to the stop time.
*/
@ -138,7 +138,7 @@ public:
* is greater than or equal to the stop time.
* @param at the stop time.
*/
static void stop_at (Time time);
static void stopAt (Time time);
/**
* Schedule an event to expire at time.
@ -469,7 +469,7 @@ public:
/*
XXX
*/
static bool is_expired (EventId id);
static bool isExpired (EventId id);
/**
* Return the "current time".
*/
@ -477,7 +477,7 @@ public:
private:
Simulator ();
~Simulator ();
static SimulatorPrivate *get_priv (void);
static SimulatorPrivate *getPriv (void);
static EventId schedule (Time time, EventImpl *event);
static SimulatorPrivate *m_priv;
static SchedulerFactory const*m_schedFactory;

14
src/simulator/time.cc

@ -64,41 +64,41 @@ Time::ns (void) const
}
bool
Time::is_destroy (void) const
Time::isDestroy (void) const
{
return m_isDestroy;
}
Time
Time::abs_s (double s)
Time::absS (double s)
{
int64_t ns = (int64_t)(s * 1000000000.0);
return Time (ns);
}
Time
Time::abs_us (uint64_t us)
Time::absUs (uint64_t us)
{
int64_t ns = us * 1000;
return Time (ns);
}
Time
Time::abs_ns (uint64_t ns)
Time::absNs (uint64_t ns)
{
return Time (ns);
}
Time
Time::rel_s (double s)
Time::relS (double s)
{
int64_t ns = (int64_t)(s * 1000000000.0);
return Time (Simulator::now ().ns () + ns);
}
Time
Time::rel_us (uint64_t us)
Time::relUs (uint64_t us)
{
return Time (Simulator::now ().ns () + us * 1000);
}
Time
Time::rel_ns (uint64_t ns)
Time::relNs (uint64_t ns)
{
return Time (Simulator::now ().ns () + ns);
}

14
src/simulator/time.h

@ -32,13 +32,13 @@ public:
double s (void) const;
uint64_t us (void) const;
uint64_t ns (void) const;
bool is_destroy (void) const;
static Time abs_s (double s);
static Time abs_us (uint64_t us);
static Time abs_ns (uint64_t ns);
static Time rel_s (double s);
static Time rel_us (uint64_t us);
static Time rel_ns (uint64_t ns);
bool isDestroy (void) const;
static Time absS (double s);
static Time absUs (uint64_t us);
static Time absNs (uint64_t ns);
static Time relS (double s);
static Time relUs (uint64_t us);
static Time relNs (uint64_t ns);
static Time now (void);
static Time destroy (void);
protected:

30
utils/bench-packets.cc

@ -28,7 +28,7 @@
using namespace ns3;
static void
bench_ptr_a (uint32_t n)
benchPtrA (uint32_t n)
{
ChunkConstantData data = ChunkConstantData (2000, 1);
ChunkUdp udp;
@ -50,7 +50,7 @@ bench_ptr_a (uint32_t n)
}
static void
bench_ptr_b (uint32_t n)
benchPtrB (uint32_t n)
{
ChunkConstantData data = ChunkConstantData (2000, 1);
ChunkUdp udp;
@ -65,7 +65,7 @@ bench_ptr_b (uint32_t n)
}
static void
ptr_c2 (Packet p)
ptrC2 (Packet p)
{
ChunkConstantData data = ChunkConstantData (2000, 1);
ChunkUdp udp;
@ -77,16 +77,16 @@ ptr_c2 (Packet p)
}
static void
ptr_c1 (Packet p)
ptrC1 (Packet p)
{
ChunkIpv4 ipv4;
p.peek (&ipv4);
p.remove (&ipv4);
ptr_c2 (p);
ptrC2 (p);
}
static void
bench_ptr_c (uint32_t n)
benchPtrC (uint32_t n)
{
ChunkConstantData data = ChunkConstantData (2000, 1);
ChunkUdp udp;
@ -97,21 +97,21 @@ bench_ptr_c (uint32_t n)
p.add (&data);
p.add (&udp);
p.add (&ipv4);
ptr_c1 (p);
ptrC1 (p);
}
}
static void
run_bench (void (*bench) (uint32_t), uint32_t n, char const *name)
runBench (void (*bench) (uint32_t), uint32_t n, char const *name)
{
WallClockMs time;
time.start ();
(*bench) (n);
unsigned long long delta_ms = time.end ();
unsigned long long deltaMs = time.end ();
double ps = n;
ps *= 1000;
ps /= delta_ms;
ps /= deltaMs;
std::cout << name<<"=" << ps << " packets/s" << std::endl;
}
@ -120,16 +120,16 @@ int main (int argc, char *argv[])
uint32_t n = 0;
while (argc > 0) {
if (strncmp ("--n=", argv[0],strlen ("--n=")) == 0) {
char const *n_ascii = argv[0] + strlen ("--n=");
n = atoi (n_ascii);
char const *nAscii = argv[0] + strlen ("--n=");
n = atoi (nAscii);
}
argc--;
argv++;
}
run_bench (&bench_ptr_a, n, "a");
run_bench (&bench_ptr_b, n, "b");
run_bench (&bench_ptr_c, n, "c");
runBench (&benchPtrA, n, "a");
runBench (&benchPtrB, n, "b");
runBench (&benchPtrC, n, "c");
return 0;
}

30
utils/bench-simulator.cc

@ -28,12 +28,12 @@
using namespace ns3;
bool g_debug = false;
bool gDebug = false;
class Bench {
public:
void read_distribution (std::istream &istream);
void set_total (uint32_t total);
void readDistribution (std::istream &istream);
void setTotal (uint32_t total);
void bench (void);
private:
void cb (void);
@ -44,13 +44,13 @@ private:
};
void
Bench::set_total (uint32_t total)
Bench::setTotal (uint32_t total)
{
m_total = total;
}
void
Bench::read_distribution (std::istream &input)
Bench::readDistribution (std::istream &input)
{
double data;
while (!input.eof ()) {
@ -73,7 +73,7 @@ Bench::bench (void)
time.start ();
for (std::vector<uint64_t>::const_iterator i = m_distribution.begin ();
i != m_distribution.end (); i++) {
Simulator::schedule (Time::abs_ns (*i), &Bench::cb, this);
Simulator::schedule (Time::absNs (*i), &Bench::cb, this);
}
init = time.end ();
@ -102,10 +102,10 @@ Bench::cb (void)
if (m_current == m_distribution.end ()) {
m_current = m_distribution.begin ();
}
if (g_debug) {
if (gDebug) {
std::cerr << "event at " << Simulator::now ().s () << "s" << std::endl;
}
Simulator::schedule (Time::abs_ns (*m_current), &Bench::cb, this);
Simulator::schedule (Time::absNs (*m_current), &Bench::cb, this);
m_current++;
m_n++;
}
@ -123,23 +123,23 @@ int main (int argc, char *argv[])
}
while (argc > 0) {
if (strcmp ("--list", argv[0]) == 0) {
Simulator::set_linked_list ();
Simulator::setLinkedList ();
} else if (strcmp ("--heap", argv[0]) == 0) {
Simulator::set_binary_heap ();
Simulator::setBinaryHeap ();
} else if (strcmp ("--map", argv[0]) == 0) {
Simulator::set_std_map ();
Simulator::setStdMap ();
} else if (strcmp ("--debug", argv[0]) == 0) {
g_debug = true;
gDebug = true;
} else if (strncmp ("--log=", argv[0],strlen ("--log=")) == 0) {
char const *filename = argv[0] + strlen ("--log=");
Simulator::enable_log_to (filename);
Simulator::enableLogTo (filename);
}
argc--;
argv++;
}
Bench *bench = new Bench ();
bench->read_distribution (*input);
bench->set_total (20000);
bench->readDistribution (*input);
bench->setTotal (20000);
bench->bench ();
return 0;

90
utils/replay-simulation.cc

@ -32,9 +32,9 @@ using namespace ns3;
class LogReader {
public:
void read_from_filename (char const *filename);
void readFrom_filename (char const *filename);
void run (void);
void print_stats (void);
void printStats (void);
private:
struct Command {
enum {
@ -57,10 +57,10 @@ private:
uint32_t m_evLoc;
// time at which the event is supposed to expire
uint64_t m_evUs;
} insert_remove;
} insertRemove;
};
};
void execute_log_commands (uint32_t uid);
void executeLogCommands (uint32_t uid);
typedef std::deque<struct Command> Commands;
typedef std::deque<struct Command>::iterator CommandsI;
@ -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::read_from_filename (char const *filename)
LogReader::readFrom_filename (char const *filename)
{
std::ifstream log;
std::cout << "read log..." << std::endl;
@ -87,30 +87,30 @@ LogReader::read_from_filename (char const *filename)
std::string type;
log >> type;
if (type == "i") {
uint32_t now_uid, ev_uid;
uint64_t now_us, ev_us;
log >> now_uid >> now_us >> ev_uid >> ev_us;
uint32_t nowUid, evUid;
uint64_t nowUs, evUs;
log >> nowUid >> nowUs >> evUid >> evUs;
struct Command cmd;
cmd.m_type = Command::INSERT;
cmd.m_uid = now_uid;
cmd.insert.m_evUs = ev_us;
cmd.m_uid = nowUid;
cmd.insert.m_evUs = evUs;
m_commands.push_back (cmd);
} else if (type == "r") {
uint32_t now_uid, ev_uid;
uint64_t now_us, ev_us;
log >> now_uid >> now_us >> ev_uid >> ev_us;
uint32_t nowUid, evUid;
uint64_t nowUs, evUs;
log >> nowUid >> nowUs >> evUid >> evUs;
struct Command cmd;
cmd.m_type = Command::REMOVE;
cmd.m_uid = now_uid;
cmd.m_uid = nowUid;
m_commands.push_back (cmd);
removes.push_back (std::make_pair (now_uid, ev_uid));
removes.push_back (std::make_pair (nowUid, evUid));
} else if (type == "il") {
uint32_t now_uid, ev_uid;
uint64_t now_us, ev_us;
log >> now_uid >> now_us >> ev_uid >> ev_us;
uint32_t nowUid, evUid;
uint64_t nowUs, evUs;
log >> nowUid >> nowUs >> evUid >> evUs;
struct Command cmd;
cmd.m_type = Command::INSERT_LATER;
cmd.m_uid = now_uid;
cmd.m_uid = nowUid;
m_commands.push_back (cmd);
}
}
@ -126,8 +126,8 @@ LogReader::read_from_filename (char const *filename)
uint32_t uid = i->m_uid;
i->m_type = Command::INSERT_REMOVE;
i->m_uid = uid;
i->insert_remove.m_evUs = us;
i->insert_remove.m_evLoc = j->first;
i->insertRemove.m_evUs = us;
i->insertRemove.m_evLoc = j->first;
break;
}
}
@ -140,8 +140,8 @@ LogReader::read_from_filename (char const *filename)
uint32_t loc = 0;
for (CommandsI tmp = i; tmp != m_commands.end (); tmp++) {
if (tmp->m_type == Command::REMOVE &&
tmp->m_uid == i->insert_remove.m_evLoc) {
i->insert_remove.m_evLoc = loc;
tmp->m_uid == i->insertRemove.m_evLoc) {
i->insertRemove.m_evLoc = loc;
break;
}
loc++;
@ -150,7 +150,7 @@ LogReader::read_from_filename (char const *filename)
}
}
void
LogReader::execute_log_commands (uint32_t uid)
LogReader::executeLogCommands (uint32_t uid)
{
if (m_command == m_commands.end ()) {
return;
@ -162,15 +162,15 @@ LogReader::execute_log_commands (uint32_t uid)
m_command++;
switch (cmd.m_type) {
case Command::INSERT:
//std::cout << "exec insert now=" << Simulator::now_us ()
//std::cout << "exec insert now=" << Simulator::nowUs ()
//<< ", time=" << cmd.insert.m_evUs << std::endl;
Simulator::schedule_abs_us (cmd.insert.m_evUs,
make_event (&LogReader::execute_log_commands, this, m_uid));
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::schedule_now (make_event (&LogReader::execute_log_commands, this, m_uid));
Simulator::scheduleNow (makeEvent (&LogReader::executeLogCommands, this, m_uid));
m_uid++;
break;
case Command::REMOVE: {
@ -181,9 +181,9 @@ LogReader::execute_log_commands (uint32_t uid)
} break;
case Command::INSERT_REMOVE: {
//std::cout << "exec insert remove" << std::endl;
Event ev = make_event (&LogReader::execute_log_commands, this, m_uid);
Simulator::schedule_abs_us (cmd.insert_remove.m_evUs, ev);
m_removeEvents[cmd.insert_remove.m_evLoc] = ev;
Event ev = makeEvent (&LogReader::executeLogCommands, this, m_uid);
Simulator::scheduleAbsUs (cmd.insertRemove.m_evUs, ev);
m_removeEvents[cmd.insertRemove.m_evLoc] = ev;
m_uid++;
} break;
}
@ -192,27 +192,27 @@ LogReader::execute_log_commands (uint32_t uid)
}
void
LogReader::print_stats (void)
LogReader::printStats (void)
{
uint32_t n_inserts = 0;
uint32_t n_removes = 0;
uint32_t nInserts = 0;
uint32_t nRemoves = 0;
for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) {
switch (i->m_type) {
case Command::INSERT:
n_inserts++;
nInserts++;
break;
case Command::INSERT_LATER:
n_inserts++;
nInserts++;
break;
case Command::INSERT_REMOVE:
n_inserts++;
nInserts++;
break;
case Command::REMOVE:
n_removes++;
nRemoves++;
break;
}
}
std::cout << "inserts="<<n_inserts<<", removes="<<n_removes<<std::endl;
std::cout << "inserts="<<nInserts<<", removes="<<nRemoves<<std::endl;
std::cout << "run simulation..."<<std::endl;
}
@ -223,7 +223,7 @@ LogReader::run (void)
WallClockMs time;
time.start ();
m_command = m_commands.begin ();
execute_log_commands (m_uid);
executeLogCommands (m_uid);
Simulator::run ();
unsigned long long delta = time.end ();
double delay = ((double)delta)/1000;
@ -237,18 +237,18 @@ int main (int argc, char *argv[])
uint32_t n = 1;
while (argc > 0) {
if (strcmp ("--list", argv[0]) == 0) {
Simulator::set_linked_list ();
Simulator::setLinkedList ();
} else if (strcmp ("--heap", argv[0]) == 0) {
Simulator::set_binary_heap ();
Simulator::setBinaryHeap ();
} else if (strcmp ("--map", argv[0]) == 0) {
Simulator::set_std_map ();
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::enable_log_to (filename);
Simulator::enableLogTo (filename);
}
argc--;
argv++;
@ -258,7 +258,7 @@ int main (int argc, char *argv[])
return 1;
}
LogReader log;
log.read_from_filename (input);
log.readFrom_filename (input);
for (uint32_t i = 0; i < n; i++) {
log.run ();
}

4
utils/run-tests.cc

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

Loading…
Cancel
Save