11#include "ns3/fatal-error.h"
36 : m_nixVector(o.m_nixVector),
38 m_totalBitSize(o.m_totalBitSize),
81 if (numberOfBits > 32)
83 NS_FATAL_ERROR(
"Can't add more than 32 bits to a nix-vector at one time");
89 if (currentVectorBitSize == 0)
98 if (currentVectorBitSize + numberOfBits > 32)
103 tempBits = newBits << currentVectorBitSize;
110 newBits = newBits >> (32 - currentVectorBitSize);
120 newBits = newBits << currentVectorBitSize;
137 if (numberOfBits > 32)
139 NS_FATAL_ERROR(
"Can't extract more than 32 bits to a nix-vector at one time");
146 if (numberOfBits > totalRemainingBits)
148 NS_FATAL_ERROR(
"You've tried to extract too many bits of the Nix-vector, "
149 <<
this <<
". NumberBits: " << numberOfBits
150 <<
" Remaining: " << totalRemainingBits);
153 if (numberOfBits <= 0)
155 NS_FATAL_ERROR(
"You've specified a number of bits for Nix-vector <= 0!");
162 vectorIndex = ((totalRemainingBits - 1) / 32);
168 if ((numberOfBits - 1) > ((totalRemainingBits - 1) % 32))
170 extractedBits =
m_nixVector.at(vectorIndex) << (32 - (totalRemainingBits % 32));
171 extractedBits = extractedBits >> ((32 - (totalRemainingBits % 32)) -
172 (numberOfBits - (totalRemainingBits % 32)));
173 extractedBits |= (
m_nixVector.at(vectorIndex - 1) >>
174 (32 - (numberOfBits - (totalRemainingBits % 32))));
176 return extractedBits;
181 extractedBits =
m_nixVector.at(vectorIndex) << (32 - (totalRemainingBits % 32));
182 extractedBits = extractedBits >> (32 - (numberOfBits));
184 return extractedBits;
234 "NixVector minimum serialized length is " <<
sizeof(
m_totalBitSize) <<
" bytes");
253 "NixVector serialized length should have been " << 16 + nixVectorLength
254 <<
" but buffer is shorter");
255 if (size < 16 + nixVectorLength * 4)
265 for (
uint32_t j = 0; j < nixVectorLength; j++)
288 std::vector<uint32_t>::const_reverse_iterator rIter;
328 if (numberOfNeighbors < 2)
334 for (numberOfNeighbors -= 1; numberOfNeighbors != 0; numberOfNeighbors >>= 1)
348 for (; bitCount > 0; bitCount--)
356 for (; bitCount > 1; bitCount--)
365 os << decimalNum % 2;
Neighbor-index data structure for nix-vector routing.
void AddNeighborIndex(uint32_t newBits, uint32_t numberOfBits)
uint32_t m_used
For tracking where we are in the nix-vector.
uint32_t GetSerializedSize() const
uint32_t m_epoch
Epoch of the Nix-vector creation.
uint32_t GetRemainingBits() const
NixVector & operator=(const NixVector &o)
uint32_t m_totalBitSize
A counter of how total bits are in the nix-vector.
uint32_t Serialize(uint32_t *buffer, uint32_t maxSize) const
uint32_t ExtractNeighborIndex(uint32_t numberOfBits)
NixBits_t m_nixVector
the actual nix-vector
void SetEpoch(uint32_t epoch)
Set the NixVector Epoch.
void DumpNixVector(std::ostream &os) const
Print the NixVector.
uint32_t Deserialize(const uint32_t *buffer, uint32_t size)
Ptr< NixVector > Copy() const
uint32_t BitCount(uint32_t numberOfNeighbors) const
void PrintDec2BinNix(uint32_t decimalNum, uint32_t bitCount, std::ostream &os) const
Internal for pretty printing of nix-vector (no fill)
uint32_t GetEpoch() const
Get the NixVector Epoch.
Smart pointer class similar to boost::intrusive_ptr.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
std::vector< uint32_t > NixBits_t
typedef for the nixVector