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 | * |
| 18 | * Authors: |
| 19 | */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 20 | #ifndef CCNX_FACE_H |
| 21 | #define CCNX_FACE_H |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 22 | |
| 23 | #include <list> |
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 | |
| 31 | class NetDevice; |
| 32 | class Packet; |
| 33 | class Node; |
| 34 | |
| 35 | /** |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame^] | 36 | * \ingroup ccnx |
| 37 | * \brief Virtual class defining CCNx face |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 38 | * |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame^] | 39 | * This class defines basic functionality of CCNx face. Face is core |
| 40 | * component responsible for actual delivery of data packet to and |
| 41 | * from CCNx stack |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 42 | * |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame^] | 43 | * \see CcnxLocalFace, CcnxNetDeviceFace, CcnxIpv4Face, CcnxUdpFace |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 44 | */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 45 | class CcnxFace : public Object |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 46 | { |
| 47 | public: |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame^] | 48 | /** |
| 49 | * \brief Ccnx protocol hanler |
| 50 | * |
| 51 | * \param face Face from which packet has been received |
| 52 | * \param packet Received packet |
| 53 | */ |
| 54 | typedef Callback<void,Ptr<CcnxFace>,Ptr<Packet> > ProtocolHandler; |
| 55 | |
| 56 | /** |
| 57 | * \brief Interface ID |
| 58 | * |
| 59 | * \return interface ID |
| 60 | */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 61 | static TypeId GetTypeId (void); |
| 62 | |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame^] | 63 | /** |
| 64 | * \brief Default constructor |
| 65 | */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 66 | CcnxFace (); |
| 67 | virtual ~CcnxFace(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 68 | |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame^] | 69 | //////////////////////////////////////////////////////////////////// |
| 70 | |
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 | * \brief Register callback to call when new packet arrives on the face |
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 | * This method should call protocol-dependent registration function |
| 75 | */ |
| 76 | void RegisterProtocolHandler (ProtocolHandler handler) = 0; |
| 77 | |
| 78 | /** |
| 79 | * \brief Send packet on a face |
| 80 | * |
| 81 | * \param p smart pointer to a packet to send |
| 82 | */ |
| 83 | virtual void Send (Ptr<Packet> p) = 0; |
| 84 | |
| 85 | //////////////////////////////////////////////////////////////////// |
| 86 | |
| 87 | /** |
| 88 | * \brief Associate Node object with face |
| 89 | * |
| 90 | * \param node smart pointer to a Node object |
| 91 | */ |
| 92 | virtual void SetNode (Ptr<Node> node); |
| 93 | |
| 94 | /** |
| 95 | * \brief Assign routing/forwarding metric with face |
| 96 | * |
| 97 | * \param metric configured routing metric (cost) of this face |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 98 | */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 99 | virtual void SetMetric (uint16_t metric); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 100 | |
| 101 | /** |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame^] | 102 | * \brief Get routing/forwarding metric assigned to the face |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 103 | * |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame^] | 104 | * \returns configured routing/forwarding metric (cost) of this face |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 105 | */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 106 | virtual uint16_t GetMetric (void) const; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 107 | |
| 108 | /** |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame^] | 109 | * These are face states and may be distinct from actual lower-layer |
| 110 | * device states, such as found in real implementations (where the |
| 111 | * device may be down but ccnx face state is still up). |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 112 | */ |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame^] | 113 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 114 | /** |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame^] | 115 | * \brief Enable this face |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 116 | */ |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame^] | 117 | virtual void SetUp (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 118 | |
| 119 | /** |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame^] | 120 | * \brief Disable this face |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 121 | */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 122 | virtual void SetDown (void); |
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 Returns true if this face is enabled, false otherwise. |
| 126 | */ |
| 127 | virtual bool IsUp () const; |
| 128 | |
| 129 | /** |
| 130 | * \brief Returns true if this face is disabled, false otherwise. |
| 131 | */ |
| 132 | virtual bool IsDown () const; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 133 | |
| 134 | protected: |
| 135 | virtual void DoDispose (void); |
| 136 | |
| 137 | private: |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame^] | 138 | CcnxFace (const CcnxFace &) {} ///< Disabled copy constructor |
| 139 | CcnxFace& operator= (const CcnxFace &) {} ///< Disabled copy operator |
| 140 | |
| 141 | protected: |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 142 | bool m_ifup; |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame^] | 143 | uint32_t m_id; ///< id of the interface in the CCNx stack (per-node uniqueness) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 144 | uint16_t m_metric; |
| 145 | Ptr<Node> m_node; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 146 | }; |
| 147 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 148 | std::ostream& operator<< (std::ostream& os, CcnxFace const& face); |
| 149 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 150 | } // namespace ns3 |
| 151 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 152 | #endif //CCNX_FACE_H |