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" |
| 27 | #include "ns3/object.h" |
| 28 | |
| 29 | namespace ns3 { |
| 30 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 31 | class Packet; |
| 32 | class Node; |
| 33 | |
| 34 | /** |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 35 | * \ingroup ccnx |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 36 | * \defgroup ccnx-face |
| 37 | */ |
| 38 | /** |
| 39 | * \ingroup ccnx-face |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 40 | * \brief Virtual class defining CCNx face |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 41 | * |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 42 | * This class defines basic functionality of CCNx face. Face is core |
| 43 | * component responsible for actual delivery of data packet to and |
| 44 | * from CCNx stack |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 45 | * |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 46 | * \see CcnxLocalFace, CcnxNetDeviceFace, CcnxIpv4Face, CcnxUdpFace |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 47 | */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 48 | class CcnxFace : public Object |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 49 | { |
| 50 | public: |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 51 | /** |
| 52 | * \brief Ccnx protocol hanler |
| 53 | * |
| 54 | * \param face Face from which packet has been received |
| 55 | * \param packet Received packet |
| 56 | */ |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 57 | typedef Callback<void,const Ptr<CcnxFace>&,const Ptr<Packet>& > ProtocolHandler; |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 58 | |
| 59 | /** |
| 60 | * \brief Interface ID |
| 61 | * |
| 62 | * \return interface ID |
| 63 | */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 64 | static TypeId GetTypeId (void); |
| 65 | |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 66 | /** |
| 67 | * \brief Default constructor |
| 68 | */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 69 | CcnxFace (); |
| 70 | virtual ~CcnxFace(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 71 | |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 72 | //////////////////////////////////////////////////////////////////// |
| 73 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 74 | /** |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 75 | * \brief Register callback to call when new packet arrives on the face |
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 | * This method should call protocol-dependent registration function |
| 78 | */ |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 79 | virtual void RegisterProtocolHandler (ProtocolHandler handler) = 0; |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 80 | |
| 81 | /** |
| 82 | * \brief Send packet on a face |
| 83 | * |
| 84 | * \param p smart pointer to a packet to send |
| 85 | */ |
| 86 | virtual void Send (Ptr<Packet> p) = 0; |
| 87 | |
| 88 | //////////////////////////////////////////////////////////////////// |
| 89 | |
| 90 | /** |
| 91 | * \brief Associate Node object with face |
| 92 | * |
| 93 | * \param node smart pointer to a Node object |
| 94 | */ |
| 95 | virtual void SetNode (Ptr<Node> node); |
| 96 | |
| 97 | /** |
| 98 | * \brief Assign routing/forwarding metric with face |
| 99 | * |
| 100 | * \param metric configured routing metric (cost) of this face |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 101 | */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 102 | virtual void SetMetric (uint16_t metric); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 103 | |
| 104 | /** |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 105 | * \brief Get routing/forwarding metric assigned to the face |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 106 | * |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 107 | * \returns configured routing/forwarding metric (cost) of this face |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 108 | */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 109 | virtual uint16_t GetMetric (void) const; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 110 | |
| 111 | /** |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 112 | * These are face states and may be distinct from actual lower-layer |
| 113 | * device states, such as found in real implementations (where the |
| 114 | * device may be down but ccnx face state is still up). |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 115 | */ |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 116 | |
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 | * \brief Enable this face |
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 | virtual void SetUp (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 121 | |
| 122 | /** |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 123 | * \brief Disable this face |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 124 | */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 125 | virtual void SetDown (void); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 126 | |
| 127 | /** |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 128 | * \brief Returns true if this face is enabled, false otherwise. |
| 129 | */ |
| 130 | virtual bool IsUp () const; |
| 131 | |
| 132 | /** |
| 133 | * \brief Returns true if this face is disabled, false otherwise. |
| 134 | */ |
| 135 | virtual bool IsDown () const; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 136 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 137 | /** |
| 138 | * \brief Set node Id |
| 139 | * |
| 140 | * Id is purely informative and should not be used for any other purpose |
| 141 | * |
| 142 | * \param id id to set |
| 143 | */ |
| 144 | inline void |
| 145 | SetId (uint32_t id); |
| 146 | |
| 147 | /** |
| 148 | * \brief Get node Id |
| 149 | * |
| 150 | * Id is purely informative and should not be used for any other purpose |
| 151 | * |
| 152 | * \returns id id to set |
| 153 | */ |
| 154 | inline uint32_t |
| 155 | GetId () const; |
| 156 | |
| 157 | bool |
| 158 | operator== (const CcnxFace &face) const; |
| 159 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 160 | protected: |
| 161 | virtual void DoDispose (void); |
| 162 | |
| 163 | private: |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 164 | CcnxFace (const CcnxFace &); ///< \brief Disabled copy constructor |
| 165 | CcnxFace& operator= (const CcnxFace &); ///< \brief Disabled copy operator |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 166 | |
| 167 | protected: |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 168 | uint16_t m_metric; ///< \brief Routing/forwarding metric |
| 169 | Ptr<Node> m_node; ///< \brief Smart pointer to Node |
| 170 | ProtocolHandler m_protocolHandler; ///< Callback via which packets are getting send to CCNx stack |
| 171 | |
| 172 | private: |
| 173 | bool m_ifup; ///< \brief flag indicating that the interface is UP |
| 174 | uint32_t m_id; ///< \brief id of the interface in CCNx stack (per-node uniqueness) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 175 | }; |
| 176 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 177 | std::ostream& operator<< (std::ostream& os, const CcnxFace &face); |
| 178 | |
| 179 | void |
| 180 | CcnxFace::SetId (uint32_t id) |
| 181 | { |
| 182 | m_id = id; |
| 183 | } |
| 184 | |
| 185 | uint32_t |
| 186 | CcnxFace::GetId () const |
| 187 | { |
| 188 | return m_id; |
| 189 | } |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 190 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 191 | } // namespace ns3 |
| 192 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 193 | #endif //CCNX_FACE_H |