--- a/src/internet/model/ipv4-address-generator.cc Sun Nov 24 23:48:49 2013 +0100
+++ b/src/internet/model/ipv4-address-generator.cc Wed Nov 20 20:15:02 2013 +0100
@@ -27,53 +27,160 @@
namespace ns3 {
+/**
+ * \internal
+ * \ingroup address
+ *
+ * \brief Implementation class of Ipv4AddressGenerator
+ * This generator assigns addresses sequentially from a provided
+ * network address; used in topology code. It also keeps track of all
+ * addresses assigned to perform duplicate detection.
+ */
class Ipv4AddressGeneratorImpl
{
public:
Ipv4AddressGeneratorImpl ();
virtual ~Ipv4AddressGeneratorImpl ();
+ /**
+ * \internal
+ * \brief Initialise the base network, mask and address for the generator
+ *
+ * The first call to NextAddress() or GetAddress() will return the
+ * value passed in.
+ *
+ * \param net The network for the base Ipv4Address
+ * \param mask The network mask of the base Ipv4Address
+ * \param addr The base address used for initialization
+ */
void Init (const Ipv4Address net, const Ipv4Mask mask,
const Ipv4Address addr);
+ /**
+ * \internal
+ * \brief Get the current network of the given Ipv4Mask
+ *
+ * Does not change the internal state; this just peeks at the current
+ * network
+ *
+ * \param mask The Ipv4Mask for the current network
+ * \returns the IPv4 address of the current network
+ */
Ipv4Address GetNetwork (const Ipv4Mask mask) const;
+
+ /**
+ * \internal
+ * \brief Get the next network according to the given Ipv4Mask
+ *
+ * This operation is a pre-increment, meaning that the internal state
+ * is changed before returning the new network address.
+ *
+ * This also resets the address to the base address that was
+ * used for initialization.
+ *
+ * \param mask The Ipv4Mask used to set the next network
+ * \returns the IPv4 address of the next network
+ */
Ipv4Address NextNetwork (const Ipv4Mask mask);
+ /**
+ * \internal
+ * \brief Set the address for the given mask
+ *
+ * \param addr The address to set for the current mask
+ * \param mask The Ipv4Mask whose address is to be set
+ */
void InitAddress (const Ipv4Address addr, const Ipv4Mask mask);
- Ipv4Address GetAddress (const Ipv4Mask mask) const;
+
+ /**
+ * \internal
+ * \brief Allocate the next Ipv4Address for the configured network and mask
+ *
+ * This operation is a post-increment, meaning that the first address
+ * allocated will be the one that was initially configured.
+ *
+ * \param mask The Ipv4Mask for the current network
+ * \returns the IPv4 address
+ */
Ipv4Address NextAddress (const Ipv4Mask mask);
+ /**
+ * \internal
+ * \brief Get the Ipv4Address that will be allocated upon NextAddress ()
+ *
+ * Does not change the internal state; just is used to peek the next
+ * address that will be allocated upon NextAddress ()
+ *
+ * \param mask The Ipv4Mask for the current network
+ * \returns the IPv4 address
+ */
+ Ipv4Address GetAddress (const Ipv4Mask mask) const;
+
+ /**
+ * \internal
+ * \brief Reset the networks and Ipv4Address to zero
+ */
void Reset (void);
+
+ /**
+ * \internal
+ * \brief Add the Ipv4Address to the list of IPv4 entries
+ *
+ * Typically, this is used by external address allocators that want
+ * to make use of this class's ability to track duplicates. AddAllocated
+ * is always called internally for any address generated by NextAddress ()
+ *
+ * \param addr The Ipv4Address to be added to the list of Ipv4 entries
+ * \returns true on success
+ */
bool AddAllocated (const Ipv4Address addr);
+ /**
+ * \internal
+ * \brief Used to turn off fatal errors and assertions, for testing
+ */
void TestMode (void);
private:
- static const uint32_t N_BITS = 32;
- static const uint32_t MOST_SIGNIFICANT_BIT = 0x80000000;
+ static const uint32_t N_BITS = 32; //!< /internal the number of bits in the address
+ static const uint32_t MOST_SIGNIFICANT_BIT = 0x80000000; //!< /internal MSB set to 1
+ /**
+ * \internal
+ * \brief Create an index number for the network mask
+ * \param mask the mask to index
+ * \returns an index
+ */
uint32_t MaskToIndex (Ipv4Mask mask) const;
+ /**
+ * \internal
+ * \brief This class holds the state for a given network
+ */
class NetworkState
{
public:
- uint32_t mask;
- uint32_t shift;
- uint32_t network;
- uint32_t addr;
- uint32_t addrMax;
+ uint32_t mask; //!< /internal the network mask
+ uint32_t shift; //!< /internal a shift
+ uint32_t network; //!< /internal the network
+ uint32_t addr; //!< /internal the address
+ uint32_t addrMax; //!< /internal the maximum address
};
- NetworkState m_netTable[N_BITS];
+ NetworkState m_netTable[N_BITS]; //!< /internal the available networks
+ /**
+ * \internal
+ * \brief This class holds the allocated addresses
+ */
class Entry
{
public:
- uint32_t addrLow;
- uint32_t addrHigh;
+ uint32_t addrLow; //!< /internal the lowest allocated address
+ uint32_t addrHigh; //!< /internal the highest allocated address
};
- std::list<Entry> m_entries;
- bool m_test;
+ std::list<Entry> m_entries; //!< /internal contained of allocated addresses
+ bool m_test; //!< /internal test mode (if true)
};
Ipv4AddressGeneratorImpl::Ipv4AddressGeneratorImpl ()