1 #include "ns3/buffer.h"
2 #include "ns3/random-variable-stream.h"
3 #include "ns3/double.h"
13 void EnsureWrittenBytes (
Buffer b, uint32_t n, uint8_t array[],
const char *file,
int line);
15 virtual void DoRun (
void);
28 uint8_t *expected = array;
31 for (uint32_t j = 0; j < n; j++)
33 if (got[j] != expected[j])
40 std::ostringstream failure;
41 failure <<
"Buffer -- ";
42 failure <<
"expected: n=";
44 failure.setf (std::ios::hex, std::ios::basefield);
45 for (uint32_t j = 0; j < n; j++)
47 failure << (uint16_t)expected[j] <<
" ";
49 failure.setf (std::ios::dec, std::ios::basefield);
51 failure.setf (std::ios::hex, std::ios::basefield);
52 for (uint32_t j = 0; j < n; j++)
54 failure << (uint16_t)got[j] <<
" ";
65 #define ENSURE_WRITTEN_BYTES(buffer, n, ...) \
67 uint8_t bytes[] = { __VA_ARGS__}; \
68 EnsureWrittenBytes (buffer, n, bytes, __FILE__, __LINE__); \
98 ENSURE_WRITTEN_BYTES (buffer, 10, 0, 0, 0x63, 0x69, 0xde, 0xad, 0xbe, 0xaf, 0, 0);
178 i.WriteHtonU32 (0xdeadbeaf);
212 ENSURE_WRITTEN_BYTES (buffer, 11, 0x30, 0x31, 0x32, 0, 0, 0xac, 0xad, 0xae, 0xaf, 0xba, 0xbb);
219 i.WriteHtonU16 (0xabcd);
227 buffer.AddAtStart (9);
234 buffer.AddAtStart (3);
235 buffer.RemoveAtEnd (8);
242 buffer.AddAtEnd (100);
249 const uint32_t actualSize = 72602;
250 const uint32_t chunkSize = 67624;
261 for (uint32_t i = 0; i < actualSize; i++)
267 iter.
Prev (chunkSize);
289 buffer.AddAtStart (2);
298 ENSURE_WRITTEN_BYTES (buffer, 9, 0x1, 0x2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3, 0x4);
302 i.
Write (buffer.Begin (), buffer.End ());
303 ENSURE_WRITTEN_BYTES (other, 9, 0x1, 0x2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3, 0x4);
306 std::string ct (
"This is the next content of the buffer.");
308 buffer.AddAtStart (ct.size ());
310 i.Write ((
const uint8_t*)ct.c_str (), ct.size ());
311 uint32_t sizeBuffer = buffer.GetSize ();
313 uint8_t
const* evilBuffer = buffer.PeekData ();
315 uint8_t *cBuf = (uint8_t*) malloc ( sizeBuffer );
316 uint32_t copyLen = buffer.CopyData (cBuf, sizeBuffer);
318 for (uint8_t i=0; i < sizeBuffer ; i++ )