Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | |
| 3 | #ifndef CCNX_FACE_CONTAINER_H |
| 4 | #define CCNX_FACE_CONTAINER_H |
| 5 | |
| 6 | #include <stdint.h> |
| 7 | #include <vector> |
| 8 | #include "ns3/ccnx.h" |
| 9 | |
| 10 | namespace ns3 { |
| 11 | |
| 12 | /** |
| 13 | * \brief holds a vector of std::pair of Ptr<Ccnx> and face index. |
| 14 | * |
| 15 | * Typically ns-3 CcnxFaces are installed on devices using an Ccnx address |
| 16 | * helper. The helper's Assign() method takes a NetDeviceContainer which holds |
| 17 | * some number of Ptr<NetDevice>. For each of the NetDevices in the |
| 18 | * NetDeviceContainer the helper will find the associated Ptr<Node> and |
| 19 | * Ptr<Ccnx>. It makes sure that an face exists on the node for the |
| 20 | * device and then adds an CcnxAddress according to the address helper settings |
| 21 | * (incrementing the CcnxAddress somehow as it goes). The helper then converts |
| 22 | * the Ptr<Ccnx> and the face index to a std::pair and adds them to a |
| 23 | * container -- a container of this type. |
| 24 | * |
| 25 | * The point is then to be able to implicitly associate an index into the |
| 26 | * original NetDeviceContainer (that identifies a particular net device) with |
| 27 | * an identical index into the CcnxFaceContainer that has a std::pair with |
| 28 | * the Ptr<Ccnx> and face index you need to play with the face. |
| 29 | * |
| 30 | * @see CcnxAddressHelper |
| 31 | * @see Ccnx |
| 32 | */ |
| 33 | class CcnxFaceContainer |
| 34 | { |
| 35 | public: |
| 36 | typedef std::vector<std::pair<Ptr<Ccnx>, uint32_t> >::const_iterator Iterator; |
| 37 | |
| 38 | /** |
| 39 | * Create an empty CcnxFaceContainer. |
| 40 | */ |
| 41 | CcnxFaceContainer (); |
| 42 | |
| 43 | /** |
| 44 | * Concatenate the entries in the other container with ours. |
| 45 | * \param other container |
| 46 | */ |
| 47 | void Add (CcnxFaceContainer other); |
| 48 | |
| 49 | /** |
| 50 | * \brief Get an iterator which refers to the first pair in the |
| 51 | * container. |
| 52 | * |
| 53 | * Pairs can be retrieved from the container in two ways. First, |
| 54 | * directly by an index into the container, and second, using an iterator. |
| 55 | * This method is used in the iterator method and is typically used in a |
| 56 | * for-loop to run through the pairs |
| 57 | * |
| 58 | * \code |
| 59 | * ccnxFaceContainer::Iterator i; |
| 60 | * for (i = container.Begin (); i != container.End (); ++i) |
| 61 | * { |
| 62 | * std::pair<Ptr<Ccnx>, uint32_t> pair = *i; |
| 63 | * method (pair.first, pair.second); // use the pair |
| 64 | * } |
| 65 | * \endcode |
| 66 | * |
| 67 | * \returns an iterator which refers to the first pair in the container. |
| 68 | */ |
| 69 | Iterator Begin (void) const; |
| 70 | |
| 71 | /** |
| 72 | * \brief Get an iterator which indicates past-the-last Node in the |
| 73 | * container. |
| 74 | * |
| 75 | * Nodes can be retrieved from the container in two ways. First, |
| 76 | * directly by an index into the container, and second, using an iterator. |
| 77 | * This method is used in the iterator method and is typically used in a |
| 78 | * for-loop to run through the Nodes |
| 79 | * |
| 80 | * \code |
| 81 | * NodeContainer::Iterator i; |
| 82 | * for (i = container.Begin (); i != container.End (); ++i) |
| 83 | * { |
| 84 | * std::pair<Ptr<Ccnx>, uint32_t> pair = *i; |
| 85 | * method (pair.first, pair.second); // use the pair |
| 86 | * } |
| 87 | * \endcode |
| 88 | * |
| 89 | * \returns an iterator which indicates an ending condition for a loop. |
| 90 | */ |
| 91 | Iterator End (void) const; |
| 92 | |
| 93 | /** |
| 94 | * \returns the number of Ptr<Ccnx> and face pairs stored in this |
| 95 | * ccnxFaceContainer. |
| 96 | * |
| 97 | * Pairs can be retrieved from the container in two ways. First, |
| 98 | * directly by an index into the container, and second, using an iterator. |
| 99 | * This method is used in the direct method and is typically used to |
| 100 | * define an ending condition in a for-loop that runs through the stored |
| 101 | * Nodes |
| 102 | * |
| 103 | * \code |
| 104 | * uint32_t nNodes = container.GetN (); |
| 105 | * for (uint32_t i = 0 i < nNodes; ++i) |
| 106 | * { |
| 107 | * std::pair<Ptr<Ccnx>, uint32_t> pair = container.Get (i); |
| 108 | * method (pair.first, pair.second); // use the pair |
| 109 | * } |
| 110 | * \endcode |
| 111 | * |
| 112 | * \returns the number of Ptr<Node> stored in this container. |
| 113 | */ |
| 114 | uint32_t GetN (void) const; |
| 115 | |
| 116 | /** |
| 117 | * \param i index of ipfacePair in container |
| 118 | * \param j face address index (if face has multiple addresses) |
| 119 | * \returns the ccnx address of the j'th address of the face |
| 120 | * corresponding to index i. |
| 121 | * |
| 122 | * If the second parameter is omitted, the zeroth indexed address of |
| 123 | * the face is returned. Unless IP aliasing is being used on |
| 124 | * the face, the second parameter may typically be omitted. |
| 125 | */ |
| 126 | // ccnxAddress GetAddress (uint32_t i, uint32_t j = 0) const; |
| 127 | |
| 128 | void SetMetric (uint32_t i, uint16_t metric); |
| 129 | |
| 130 | /** |
| 131 | * Manually add an entry to the container consisting of the individual parts |
| 132 | * of an entry std::pair. |
| 133 | * |
| 134 | * \param ccnx pointer to ccnx object |
| 135 | * \param face face index of the ccnxface to add to the container |
| 136 | * |
| 137 | * @see ccnxfaceContainer |
| 138 | */ |
| 139 | void Add (Ptr<Ccnx> ccnx, uint32_t face); |
| 140 | |
| 141 | /** |
| 142 | * Manually add an entry to the container consisting of a previously composed |
| 143 | * entry std::pair. |
| 144 | * |
| 145 | * \param ipfacePair the pair of a pointer to ccnx object and face index of the ccnxface to add to the container |
| 146 | * |
| 147 | * @see ccnxfaceContainer |
| 148 | */ |
| 149 | void Add (std::pair<Ptr<Ccnx>, uint32_t> ipFacePair); |
| 150 | |
| 151 | /** |
| 152 | * Manually add an entry to the container consisting of the individual parts |
| 153 | * of an entry std::pair. |
| 154 | * |
| 155 | * \param ccnxName std:string referring to the saved name of an ccnx Object that |
| 156 | * has been previously named using the Object Name Service. |
| 157 | * \param face face index of the ccnxface to add to the container |
| 158 | * |
| 159 | * @see ccnxfaceContainer |
| 160 | */ |
| 161 | void Add (std::string ccnxName, uint32_t face); |
| 162 | |
| 163 | /** |
| 164 | * Get the std::pair of an Ptr<Ccnx> and face stored at the location |
| 165 | * specified by the index. |
| 166 | * |
| 167 | * \param i the index of the entery to retrieve. |
| 168 | * |
| 169 | * @see ccnxfaceContainer |
| 170 | */ |
| 171 | std::pair<Ptr<Ccnx>, uint32_t> Get (uint32_t i) const; |
| 172 | |
| 173 | private: |
| 174 | |
| 175 | typedef std::vector<std::pair<Ptr<Ccnx>,uint32_t> > FaceVector; |
| 176 | FaceVector m_faces; |
| 177 | }; |
| 178 | |
| 179 | } // namespace ns3 |
| 180 | |
| 181 | #endif /* CCNX_FACE_CONTAINER_H */ |