blob: 2650515725f161338fe70abc80c80ff51e74710e [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -07002/*
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 Afanasyev56f79ea2011-08-17 23:54:27 -070018 * Authors: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070019 */
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070020
Alexander Afanasyev98256102011-08-14 01:00:02 -070021#ifndef CCNX_FACE_H
22#define CCNX_FACE_H
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070023
Alexander Afanasyev98256102011-08-14 01:00:02 -070024#include <ostream>
25
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070026#include "ns3/ptr.h"
27#include "ns3/object.h"
28
29namespace ns3 {
30
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070031class Packet;
32class Node;
33
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070034
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070035/**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070036 * \ingroup ccnx
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070037 * \defgroup ccnx-face Faces
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070038 */
39/**
40 * \ingroup ccnx-face
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070041 * \brief Virtual class defining CCNx face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070042 *
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070043 * This class defines basic functionality of CCNx face. Face is core
44 * component responsible for actual delivery of data packet to and
45 * from CCNx stack
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070046 *
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070047 * \see CcnxLocalFace, CcnxNetDeviceFace, CcnxIpv4Face, CcnxUdpFace
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070048 */
Alexander Afanasyev98256102011-08-14 01:00:02 -070049class CcnxFace : public Object
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070050{
51public:
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070052 /**
53 * \brief Ccnx protocol hanler
54 *
55 * \param face Face from which packet has been received
56 * \param packet Received packet
57 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070058 typedef Callback<void,const Ptr<CcnxFace>&,const Ptr<const Packet>& > ProtocolHandler;
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070059
60 /**
61 * \brief Interface ID
62 *
63 * \return interface ID
64 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070065 static TypeId GetTypeId (void);
66
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070067 /**
68 * \brief Default constructor
69 */
Alexander Afanasyev98256102011-08-14 01:00:02 -070070 CcnxFace ();
71 virtual ~CcnxFace();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070072
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070073 ////////////////////////////////////////////////////////////////////
74
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070075 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070076 * \brief Register callback to call when new packet arrives on the face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070077 *
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070078 * This method should call protocol-dependent registration function
79 */
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070080 virtual void RegisterProtocolHandler (ProtocolHandler handler) = 0;
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070081
82 /**
83 * \brief Send packet on a face
84 *
85 * \param p smart pointer to a packet to send
86 */
87 virtual void Send (Ptr<Packet> p) = 0;
88
89 ////////////////////////////////////////////////////////////////////
90
91 /**
92 * \brief Associate Node object with face
93 *
94 * \param node smart pointer to a Node object
95 */
96 virtual void SetNode (Ptr<Node> node);
97
98 /**
99 * \brief Assign routing/forwarding metric with face
100 *
101 * \param metric configured routing metric (cost) of this face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700102 */
Alexander Afanasyev98256102011-08-14 01:00:02 -0700103 virtual void SetMetric (uint16_t metric);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700104
105 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700106 * \brief Get routing/forwarding metric assigned to the face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700107 *
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700108 * \returns configured routing/forwarding metric (cost) of this face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700109 */
Alexander Afanasyev98256102011-08-14 01:00:02 -0700110 virtual uint16_t GetMetric (void) const;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700111
112 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700113 * These are face states and may be distinct from actual lower-layer
114 * device states, such as found in real implementations (where the
115 * device may be down but ccnx face state is still up).
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700116 */
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700117
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700118 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700119 * \brief Enable this face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700120 */
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700121 virtual void SetUp ();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700122
123 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700124 * \brief Disable this face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700125 */
Alexander Afanasyev98256102011-08-14 01:00:02 -0700126 virtual void SetDown (void);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700127
128 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700129 * \brief Returns true if this face is enabled, false otherwise.
130 */
131 virtual bool IsUp () const;
132
133 /**
134 * \brief Returns true if this face is disabled, false otherwise.
135 */
136 virtual bool IsDown () const;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700137
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700138 /**
139 * \brief Set node Id
140 *
141 * Id is purely informative and should not be used for any other purpose
142 *
143 * \param id id to set
144 */
145 inline void
146 SetId (uint32_t id);
147
148 /**
149 * \brief Get node Id
150 *
151 * Id is purely informative and should not be used for any other purpose
152 *
153 * \returns id id to set
154 */
155 inline uint32_t
156 GetId () const;
157
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700158 /**
159 * \brief Compare two faces. Only two faces on the same node could be compared.
160 *
161 * Internal index is used for comparison.
162 */
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700163 bool
164 operator== (const CcnxFace &face) const;
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700165
166 /**
167 * \brief Compare two faces. Only two faces on the same node could be compared.
168 *
169 * Internal index is used for comparison.
170 */
171 bool
172 operator< (const CcnxFace &face) const;
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700173
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700174protected:
175 virtual void DoDispose (void);
176
177private:
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700178 CcnxFace (const CcnxFace &); ///< \brief Disabled copy constructor
179 CcnxFace& operator= (const CcnxFace &); ///< \brief Disabled copy operator
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700180
181protected:
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700182 uint16_t m_metric; ///< \brief Routing/forwarding metric
183 Ptr<Node> m_node; ///< \brief Smart pointer to Node
184 ProtocolHandler m_protocolHandler; ///< Callback via which packets are getting send to CCNx stack
185
186private:
187 bool m_ifup; ///< \brief flag indicating that the interface is UP
188 uint32_t m_id; ///< \brief id of the interface in CCNx stack (per-node uniqueness)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700189};
190
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700191std::ostream& operator<< (std::ostream& os, const CcnxFace &face);
192
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700193inline bool
194operator < (const Ptr<CcnxFace> &lhs, const Ptr<CcnxFace> &rhs)
195{
196 return *lhs < *rhs;
197}
198
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700199void
200CcnxFace::SetId (uint32_t id)
201{
202 m_id = id;
203}
204
205uint32_t
206CcnxFace::GetId () const
207{
208 return m_id;
209}
Alexander Afanasyev98256102011-08-14 01:00:02 -0700210
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700211} // namespace ns3
212
Alexander Afanasyev98256102011-08-14 01:00:02 -0700213#endif //CCNX_FACE_H