blob: 07561a0eb731cb118e029d1d932a8b75369e4a66 [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"
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070027#include "ns3/simple-ref-count.h"
28#include "ns3/callback.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070029
30namespace ns3 {
31
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070032class Packet;
33class Node;
34
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070035
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070036/**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070037 * \ingroup ccnx
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070038 * \defgroup ccnx-face Faces
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070039 */
40/**
41 * \ingroup ccnx-face
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070042 * \brief Virtual class defining CCNx face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070043 *
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070044 * 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 Afanasyev08d984e2011-08-13 19:20:22 -070047 *
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070048 * \see CcnxLocalFace, CcnxNetDeviceFace, CcnxIpv4Face, CcnxUdpFace
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070049 */
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070050class CcnxFace : public SimpleRefCount<CcnxFace>
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070051{
52public:
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070053 /**
54 * \brief Ccnx protocol hanler
55 *
56 * \param face Face from which packet has been received
57 * \param packet Received packet
58 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070059 typedef Callback<void,const Ptr<CcnxFace>&,const Ptr<const Packet>& > ProtocolHandler;
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070060
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070061 // /**
62 // * \brief Interface ID
63 // *
64 // * \return interface ID
65 // */
66 // static TypeId GetTypeId (void);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070067
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070068 /**
69 * \brief Default constructor
70 */
Alexander Afanasyev98256102011-08-14 01:00:02 -070071 CcnxFace ();
72 virtual ~CcnxFace();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070073
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070074 ////////////////////////////////////////////////////////////////////
75
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070076 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070077 * \brief Register callback to call when new packet arrives on the face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070078 *
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070079 * This method should call protocol-dependent registration function
80 */
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070081 virtual void RegisterProtocolHandler (ProtocolHandler handler) = 0;
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070082
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 Afanasyevc5a23e22011-09-07 00:37:36 -070099 // /**
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 Afanasyev08d984e2011-08-13 19:20:22 -0700105
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700106 // /**
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 Afanasyev08d984e2011-08-13 19:20:22 -0700112
113 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700114 * 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 Afanasyev08d984e2011-08-13 19:20:22 -0700117 */
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700118
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700119 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700120 * \brief Enable this face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700121 */
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700122 virtual void SetUp ();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700123
124 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700125 * \brief Disable this face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700126 */
Alexander Afanasyev98256102011-08-14 01:00:02 -0700127 virtual void SetDown (void);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700128
129 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700130 * \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 Afanasyev08d984e2011-08-13 19:20:22 -0700138
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700139 virtual std::ostream&
140 Print (std::ostream &os) const;
141
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700142 /**
143 * \brief Set node Id
144 *
145 * Id is purely informative and should not be used for any other purpose
146 *
147 * \param id id to set
148 */
149 inline void
150 SetId (uint32_t id);
151
152 /**
153 * \brief Get node Id
154 *
155 * Id is purely informative and should not be used for any other purpose
156 *
157 * \returns id id to set
158 */
159 inline uint32_t
160 GetId () const;
161
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700162 /**
163 * \brief Compare two faces. Only two faces on the same node could be compared.
164 *
165 * Internal index is used for comparison.
166 */
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700167 bool
168 operator== (const CcnxFace &face) const;
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700169
170 /**
171 * \brief Compare two faces. Only two faces on the same node could be compared.
172 *
173 * Internal index is used for comparison.
174 */
175 bool
176 operator< (const CcnxFace &face) const;
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700177
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700178// protected:
179// virtual void DoDispose (void);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700180
181private:
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700182 CcnxFace (const CcnxFace &); ///< \brief Disabled copy constructor
183 CcnxFace& operator= (const CcnxFace &); ///< \brief Disabled copy operator
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700184
185protected:
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700186 // uint16_t m_metric; ///< \brief Routing/forwarding metric
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700187 Ptr<Node> m_node; ///< \brief Smart pointer to Node
188 ProtocolHandler m_protocolHandler; ///< Callback via which packets are getting send to CCNx stack
189
190private:
191 bool m_ifup; ///< \brief flag indicating that the interface is UP
192 uint32_t m_id; ///< \brief id of the interface in CCNx stack (per-node uniqueness)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700193};
194
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700195std::ostream& operator<< (std::ostream& os, const CcnxFace &face);
196
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700197inline bool
198operator < (const Ptr<CcnxFace> &lhs, const Ptr<CcnxFace> &rhs)
199{
200 return *lhs < *rhs;
201}
202
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700203void
204CcnxFace::SetId (uint32_t id)
205{
206 m_id = id;
207}
208
209uint32_t
210CcnxFace::GetId () const
211{
212 return m_id;
213}
Alexander Afanasyev98256102011-08-14 01:00:02 -0700214
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700215} // namespace ns3
216
Alexander Afanasyev98256102011-08-14 01:00:02 -0700217#endif //CCNX_FACE_H