22 #include "ns3/fatal-error.h"
47 : m_nixVector (o.m_nixVector),
49 m_totalBitSize (o.m_totalBitSize),
91 if (numberOfBits > 32)
93 NS_FATAL_ERROR (
"Can't add more than 32 bits to a nix-vector at one time");
99 if (currentVectorBitSize == 0)
108 if (currentVectorBitSize + numberOfBits > 32)
112 uint32_t tempBits = newBits;
113 tempBits = newBits << currentVectorBitSize;
120 newBits = newBits >> (32 - currentVectorBitSize);
130 newBits = newBits << currentVectorBitSize;
147 if (numberOfBits > 32)
149 NS_FATAL_ERROR (
"Can't extract more than 32 bits to a nix-vector at one time");
152 uint32_t vectorIndex = 0;
153 uint32_t extractedBits = 0;
156 if (numberOfBits > totalRemainingBits)
158 NS_FATAL_ERROR (
"You've tried to extract too many bits of the Nix-vector, " <<
this <<
". NumberBits: "
159 << numberOfBits <<
" Remaining: " << totalRemainingBits);
162 if (numberOfBits <= 0)
164 NS_FATAL_ERROR (
"You've specified a number of bits for Nix-vector <= 0!");
171 vectorIndex = ((totalRemainingBits-1) / 32);
177 if ((numberOfBits-1) > ((totalRemainingBits-1) % 32))
179 extractedBits =
m_nixVector.at (vectorIndex) << (32 - (totalRemainingBits % 32));
180 extractedBits = extractedBits >> ((32 - (totalRemainingBits % 32))
181 - (numberOfBits - (totalRemainingBits % 32)));
183 >> (32 - (numberOfBits - (totalRemainingBits % 32))));
185 return extractedBits;
190 extractedBits =
m_nixVector.at (vectorIndex) << (32 - (totalRemainingBits % 32));
191 extractedBits = extractedBits >> (32 - (numberOfBits));
193 return extractedBits;
214 uint32_t* p = buffer;
240 const uint32_t* p = buffer;
243 "NixVector minimum serialized length is " <<
sizeof (
m_totalBitSize) <<
" bytes");
261 NS_ASSERT_MSG (size >= 16 + nixVectorLenth,
"NixVector serialized length should have been "
262 << 16 + nixVectorLenth
263 <<
" but buffer is shorter");
264 if (size < 16 + nixVectorLenth * 4)
274 for (uint32_t j = 0; j < nixVectorLenth; j++)
297 std::vector<uint32_t>::const_reverse_iterator rIter;
335 uint32_t bitCount = 0;
337 if (numberOfNeighbors < 2)
343 for (numberOfNeighbors -= 1; numberOfNeighbors != 0; numberOfNeighbors >>= 1)
357 for (; bitCount > 0; bitCount--)
365 for (; bitCount > 1; bitCount--)
374 os << decimalNum % 2;
Neighbor-index data structure for nix-vector routing.
void AddNeighborIndex(uint32_t newBits, uint32_t numberOfBits)
Ptr< NixVector > Copy(void) const
uint32_t m_used
For tracking where we are in the nix-vector.
uint32_t m_epoch
Epoch of the Nix-vector creation.
uint32_t GetRemainingBits(void) const
NixVector & operator=(const NixVector &o)
uint32_t m_totalBitSize
A counter of how total bits are in the nix-vector.
uint32_t GetSerializedSize(void) const
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)
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.
#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::vector< uint32_t > NixBits_t
typedef for the nixVector
std::ostream & operator<<(std::ostream &os, const Angles &a)