Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 2 | /* |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 3 | * Copyright (c) 2011 University of California, Los Angeles |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 18 | * Authors: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 19 | */ |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 20 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 21 | #ifndef CCNX_FACE_H |
| 22 | #define CCNX_FACE_H |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 24 | #include <ostream> |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 25 | #include <algorithm> |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 26 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 27 | #include "ns3/ptr.h" |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 28 | #include "ns3/ccnx.h" |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 29 | #include "ns3/nstime.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 30 | |
| 31 | namespace ns3 { |
| 32 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 33 | class Packet; |
| 34 | class Node; |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 35 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 36 | /** |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 37 | * \ingroup ccnx |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 38 | * \defgroup ccnx-face Faces |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 39 | */ |
| 40 | /** |
| 41 | * \ingroup ccnx-face |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 42 | * \brief Virtual class defining CCNx face |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 43 | * |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 44 | * This class defines basic functionality of CCNx face. Face is core |
| 45 | * component responsible for actual delivery of data packet to and |
| 46 | * from CCNx stack |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 47 | * |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 48 | * \see CcnxLocalFace, CcnxNetDeviceFace, CcnxIpv4Face, CcnxUdpFace |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 49 | */ |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 50 | class CcnxFace : public Object |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 51 | { |
| 52 | public: |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 53 | static TypeId |
| 54 | GetTypeId (); |
| 55 | |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 56 | /** |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 57 | * \brief Ccnx protocol handler |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 58 | * |
| 59 | * \param face Face from which packet has been received |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 60 | * \param packet Original packet |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 61 | */ |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 62 | typedef Callback<void,const Ptr<CcnxFace>&,const Ptr<const Packet>& > ProtocolHandler; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 63 | |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 64 | /** |
| 65 | * \brief Default constructor |
| 66 | */ |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 67 | CcnxFace (Ptr<Node> node); |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 68 | virtual ~CcnxFace(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 69 | |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 70 | Ptr<Node> |
| 71 | GetNode () const; |
| 72 | |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 73 | //////////////////////////////////////////////////////////////////// |
| 74 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 75 | /** |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 76 | * \brief Register callback to call when new packet arrives on the face |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 77 | * |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 78 | * This method should call protocol-dependent registration function |
| 79 | */ |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 80 | virtual void |
| 81 | RegisterProtocolHandler (ProtocolHandler handler); |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 82 | |
| 83 | /** |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 84 | * @brief Check if Interest limit is reached |
| 85 | * |
| 86 | * Side effect: if limit is not yet reached, the number of outstanding packets will be increased |
| 87 | * |
| 88 | * @returns true if Interest limit is not yet reached |
| 89 | */ |
| 90 | bool |
| 91 | IsBelowLimit (); |
| 92 | |
| 93 | /** |
| 94 | * \brief Send packet on a face |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 95 | * |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 96 | * This method will be called by lower layers to send data to device or application |
| 97 | * |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 98 | * \param p smart pointer to a packet to send |
| 99 | * |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 100 | * @return false if either limit is reached |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 101 | */ |
| 102 | bool |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 103 | Send (Ptr<Packet> p); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * \brief Receive packet from application or another node and forward it to the CCNx stack |
| 107 | * |
| 108 | * \todo The only reason for this call is to handle tracing, if requested |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 109 | */ |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 110 | bool |
| 111 | Receive (const Ptr<const Packet> &p); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 112 | //////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 113 | |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 114 | /** |
| 115 | * \Brief Assign routing/forwarding metric with face |
| 116 | * |
| 117 | * \param metric configured routing metric (cost) of this face |
| 118 | */ |
| 119 | virtual void SetMetric (uint16_t metric); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 120 | |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 121 | /** |
| 122 | * \brief Get routing/forwarding metric assigned to the face |
| 123 | * |
| 124 | * \returns configured routing/forwarding metric (cost) of this face |
| 125 | */ |
| 126 | virtual uint16_t GetMetric (void) const; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 127 | |
| 128 | /** |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 129 | * These are face states and may be distinct from actual lower-layer |
| 130 | * device states, such as found in real implementations (where the |
| 131 | * device may be down but ccnx face state is still up). |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 132 | */ |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 133 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 134 | /** |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 135 | * \brief Enable or disable this face |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 136 | */ |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 137 | virtual void |
| 138 | SetUp (bool up = true); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 139 | |
| 140 | /** |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 141 | * \brief Returns true if this face is enabled, false otherwise. |
| 142 | */ |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 143 | virtual bool |
| 144 | IsUp () const; |
Ilya Moiseenko | acac1ea | 2011-10-28 13:16:53 -0700 | [diff] [blame] | 145 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 146 | virtual std::ostream& |
| 147 | Print (std::ostream &os) const; |
| 148 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 149 | /** |
| 150 | * \brief Set node Id |
| 151 | * |
| 152 | * Id is purely informative and should not be used for any other purpose |
| 153 | * |
| 154 | * \param id id to set |
| 155 | */ |
| 156 | inline void |
| 157 | SetId (uint32_t id); |
| 158 | |
| 159 | /** |
| 160 | * \brief Get node Id |
| 161 | * |
| 162 | * Id is purely informative and should not be used for any other purpose |
| 163 | * |
| 164 | * \returns id id to set |
| 165 | */ |
| 166 | inline uint32_t |
| 167 | GetId () const; |
| 168 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 169 | /** |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 170 | * @brief Set maximum value for Interest allowance |
| 171 | * |
| 172 | * @param bucket maximum value for Interest allowance. If < 0, then limit will be disabled |
| 173 | */ |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 174 | void |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 175 | SetBucketMax (double bucket); |
| 176 | |
| 177 | /** |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 178 | * @brief Set a normalized value (one second) for Interest allowance bucket leak |
| 179 | */ |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 180 | void |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 181 | SetBucketLeak (double leak); |
| 182 | |
| 183 | /** |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 184 | * @brief Leak the Interest allowance bucket by (1/interval) * m_bucketMax amount, |
| 185 | * where interval is time between two consecutive calls of LeakBucket |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 186 | */ |
Alexander Afanasyev | b5703a9 | 2011-11-25 16:46:15 -0800 | [diff] [blame] | 187 | void |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 188 | LeakBucket (); |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 189 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 190 | /** |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 191 | * \brief Compare two faces. Only two faces on the same node could be compared. |
| 192 | * |
| 193 | * Internal index is used for comparison. |
| 194 | */ |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 195 | bool |
| 196 | operator== (const CcnxFace &face) const; |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 197 | |
| 198 | /** |
| 199 | * \brief Compare two faces. Only two faces on the same node could be compared. |
| 200 | * |
| 201 | * Internal index is used for comparison. |
| 202 | */ |
| 203 | bool |
| 204 | operator< (const CcnxFace &face) const; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 205 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 206 | protected: |
| 207 | /** |
| 208 | * \brief Send packet on a face (actual implementation) |
| 209 | * |
| 210 | * \param p smart pointer to a packet to send |
| 211 | */ |
| 212 | virtual void |
| 213 | SendImpl (Ptr<Packet> p) = 0; |
| 214 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 215 | private: |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 216 | CcnxFace (const CcnxFace &); ///< \brief Disabled copy constructor |
| 217 | CcnxFace& operator= (const CcnxFace &); ///< \brief Disabled copy operator |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 218 | |
| 219 | protected: |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 220 | // uint16_t m_metric; ///< \brief Routing/forwarding metric |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 221 | Ptr<Node> m_node; ///< \brief Smart pointer to Node |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 222 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 223 | double m_bucket; ///< \brief Value representing current size of the Interest allowance for this face |
| 224 | double m_bucketMax; ///< \brief Maximum Interest allowance for this face |
| 225 | double m_bucketLeak; ///< \brief Normalized amount that should be leaked every second |
| 226 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 227 | private: |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 228 | ProtocolHandler m_protocolHandler; ///< Callback via which packets are getting send to CCNx stack |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 229 | bool m_ifup; ///< \brief flag indicating that the interface is UP |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 230 | uint32_t m_id; ///< \brief id of the interface in CCNx stack (per-node uniqueness) |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 231 | Time m_lastLeakTime; |
| 232 | uint32_t m_metric; ///< \brief metric of the face |
| 233 | |
| 234 | bool m_enableMetricTagging; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 235 | }; |
| 236 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 237 | std::ostream& operator<< (std::ostream& os, const CcnxFace &face); |
| 238 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 239 | inline bool |
| 240 | operator < (const Ptr<CcnxFace> &lhs, const Ptr<CcnxFace> &rhs) |
| 241 | { |
| 242 | return *lhs < *rhs; |
| 243 | } |
| 244 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 245 | void |
| 246 | CcnxFace::SetId (uint32_t id) |
| 247 | { |
| 248 | m_id = id; |
| 249 | } |
| 250 | |
| 251 | uint32_t |
| 252 | CcnxFace::GetId () const |
| 253 | { |
| 254 | return m_id; |
| 255 | } |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 256 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 257 | } // namespace ns3 |
| 258 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 259 | #endif //CCNX_FACE_H |