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 | /* |
| 3 | * Copyright (c) 2005,2006,2007 INRIA |
| 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> |
| 25 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 26 | #include "ns3/ptr.h" |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 27 | #include "ns3/simple-ref-count.h" |
| 28 | #include "ns3/callback.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 29 | |
| 30 | namespace ns3 { |
| 31 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 32 | class Packet; |
| 33 | class Node; |
| 34 | |
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 | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 50 | class CcnxFace : public SimpleRefCount<CcnxFace> |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 51 | { |
| 52 | public: |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 53 | /** |
| 54 | * \brief Ccnx protocol hanler |
| 55 | * |
| 56 | * \param face Face from which packet has been received |
| 57 | * \param packet Received packet |
| 58 | */ |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 59 | typedef Callback<void,const Ptr<CcnxFace>&,const Ptr<const Packet>& > ProtocolHandler; |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 60 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 61 | // /** |
| 62 | // * \brief Interface ID |
| 63 | // * |
| 64 | // * \return interface ID |
| 65 | // */ |
| 66 | // static TypeId GetTypeId (void); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 67 | |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 68 | /** |
| 69 | * \brief Default constructor |
| 70 | */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 71 | CcnxFace (); |
| 72 | virtual ~CcnxFace(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 73 | |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 74 | //////////////////////////////////////////////////////////////////// |
| 75 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 76 | /** |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 77 | * \brief Register callback to call when new packet arrives on the face |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 78 | * |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 79 | * This method should call protocol-dependent registration function |
| 80 | */ |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 81 | virtual void RegisterProtocolHandler (ProtocolHandler handler) = 0; |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 82 | |
| 83 | /** |
| 84 | * \brief Send packet on a face |
| 85 | * |
| 86 | * \param p smart pointer to a packet to send |
| 87 | */ |
| 88 | virtual void Send (Ptr<Packet> p) = 0; |
| 89 | |
| 90 | //////////////////////////////////////////////////////////////////// |
| 91 | |
| 92 | /** |
| 93 | * \brief Associate Node object with face |
| 94 | * |
| 95 | * \param node smart pointer to a Node object |
| 96 | */ |
| 97 | virtual void SetNode (Ptr<Node> node); |
| 98 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 99 | // /** |
| 100 | // * \Brief Assign routing/forwarding metric with face |
| 101 | // * |
| 102 | // * \param metric configured routing metric (cost) of this face |
| 103 | // */ |
| 104 | // virtual void SetMetric (uint16_t metric); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 105 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 106 | // /** |
| 107 | // * \brief Get routing/forwarding metric assigned to the face |
| 108 | // * |
| 109 | // * \returns configured routing/forwarding metric (cost) of this face |
| 110 | // */ |
| 111 | // virtual uint16_t GetMetric (void) const; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 112 | |
| 113 | /** |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 114 | * These are face states and may be distinct from actual lower-layer |
| 115 | * device states, such as found in real implementations (where the |
| 116 | * device may be down but ccnx face state is still up). |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 117 | */ |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 118 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 119 | /** |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 120 | * \brief Enable this face |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 121 | */ |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 122 | virtual void SetUp (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 123 | |
| 124 | /** |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 125 | * \brief Disable this face |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 126 | */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 127 | virtual void SetDown (void); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 128 | |
| 129 | /** |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 130 | * \brief Returns true if this face is enabled, false otherwise. |
| 131 | */ |
| 132 | virtual bool IsUp () const; |
| 133 | |
| 134 | /** |
| 135 | * \brief Returns true if this face is disabled, false otherwise. |
| 136 | */ |
| 137 | virtual bool IsDown () const; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 138 | |
Ilya Moiseenko | acac1ea | 2011-10-28 13:16:53 -0700 | [diff] [blame] | 139 | /** |
| 140 | * \brief Return true for LocalFace, otherwise false |
| 141 | */ |
| 142 | virtual bool IsLocal () const; |
| 143 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 144 | virtual std::ostream& |
| 145 | Print (std::ostream &os) const; |
| 146 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 147 | /** |
| 148 | * \brief Set node Id |
| 149 | * |
| 150 | * Id is purely informative and should not be used for any other purpose |
| 151 | * |
| 152 | * \param id id to set |
| 153 | */ |
| 154 | inline void |
| 155 | SetId (uint32_t id); |
| 156 | |
| 157 | /** |
| 158 | * \brief Get node Id |
| 159 | * |
| 160 | * Id is purely informative and should not be used for any other purpose |
| 161 | * |
| 162 | * \returns id id to set |
| 163 | */ |
| 164 | inline uint32_t |
| 165 | GetId () const; |
| 166 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 167 | /** |
| 168 | * \brief Compare two faces. Only two faces on the same node could be compared. |
| 169 | * |
| 170 | * Internal index is used for comparison. |
| 171 | */ |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 172 | bool |
| 173 | operator== (const CcnxFace &face) const; |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 174 | |
| 175 | /** |
| 176 | * \brief Compare two faces. Only two faces on the same node could be compared. |
| 177 | * |
| 178 | * Internal index is used for comparison. |
| 179 | */ |
| 180 | bool |
| 181 | operator< (const CcnxFace &face) const; |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 182 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 183 | // protected: |
| 184 | // virtual void DoDispose (void); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 185 | |
| 186 | private: |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 187 | CcnxFace (const CcnxFace &); ///< \brief Disabled copy constructor |
| 188 | CcnxFace& operator= (const CcnxFace &); ///< \brief Disabled copy operator |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 189 | |
| 190 | protected: |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 191 | // uint16_t m_metric; ///< \brief Routing/forwarding metric |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 192 | Ptr<Node> m_node; ///< \brief Smart pointer to Node |
| 193 | ProtocolHandler m_protocolHandler; ///< Callback via which packets are getting send to CCNx stack |
Ilya Moiseenko | acac1ea | 2011-10-28 13:16:53 -0700 | [diff] [blame] | 194 | bool m_isLocal; |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 195 | private: |
| 196 | bool m_ifup; ///< \brief flag indicating that the interface is UP |
| 197 | uint32_t m_id; ///< \brief id of the interface in CCNx stack (per-node uniqueness) |
Ilya Moiseenko | acac1ea | 2011-10-28 13:16:53 -0700 | [diff] [blame] | 198 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 199 | }; |
| 200 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 201 | std::ostream& operator<< (std::ostream& os, const CcnxFace &face); |
| 202 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 203 | inline bool |
| 204 | operator < (const Ptr<CcnxFace> &lhs, const Ptr<CcnxFace> &rhs) |
| 205 | { |
| 206 | return *lhs < *rhs; |
| 207 | } |
| 208 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 209 | void |
| 210 | CcnxFace::SetId (uint32_t id) |
| 211 | { |
| 212 | m_id = id; |
| 213 | } |
| 214 | |
| 215 | uint32_t |
| 216 | CcnxFace::GetId () const |
| 217 | { |
| 218 | return m_id; |
| 219 | } |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 220 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 221 | } // namespace ns3 |
| 222 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 223 | #endif //CCNX_FACE_H |