NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
ndn-face.h
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2 /*
3  * Copyright (c) 2011 University of California, Los Angeles
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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19  */
20 
21 #ifndef NDN_FACE_H
22 #define NDN_FACE_H
23 
24 #include <ostream>
25 #include <algorithm>
26 
27 #include "ns3/ptr.h"
28 #include "ns3/object.h"
29 #include "ns3/nstime.h"
30 #include "ns3/type-id.h"
31 #include "ns3/traced-callback.h"
32 #include "ns3/ndn-name.h"
33 
34 namespace ns3 {
35 
36 class Packet;
37 class Node;
38 
39 namespace ndn {
40 
41 class Interest;
42 class Data;
43 
58 class Face :
59  public Object
60 {
61 public:
62  static TypeId
63  GetTypeId ();
64 
71  typedef Callback<void, Ptr<Face>, Ptr<Interest> > InterestHandler;
72  typedef Callback<void, Ptr<Face>, Ptr<Data> > DataHandler;
73 
77  Face (Ptr<Node> node);
78  virtual ~Face();
79 
83  Ptr<Node>
84  GetNode () const;
85 
87 
93  virtual void
94  RegisterProtocolHandlers (const InterestHandler &interestHandler, const DataHandler &dataHandler);
95 
101  virtual void
103 
111  virtual bool
112  SendInterest (Ptr<const Interest> interest);
113 
121  virtual bool
122  SendData (Ptr<const Data> data);
123 
129  virtual bool
130  ReceiveInterest (Ptr<Interest> interest);
131 
137  virtual bool
138  ReceiveData (Ptr<Data> data);
140 
146  virtual void
147  SetMetric (uint16_t metric);
148 
154  virtual uint16_t
155  GetMetric (void) const;
156 
166  inline void
167  SetUp (bool up = true);
168 
172  inline bool
173  IsUp () const;
174 
183  inline uint32_t
184  GetFlags () const;
185 
189  enum Flags
190  {
192  };
193 
198  virtual std::ostream&
199  Print (std::ostream &os) const;
200 
208  inline void
209  SetId (uint32_t id);
210 
218  inline uint32_t
219  GetId () const;
220 
226  bool
227  operator== (const Face &face) const;
228 
234  inline bool
235  operator!= (const Face &face) const;
236 
242  bool
243  operator< (const Face &face) const;
244 
245 protected:
249  virtual bool
250  Send (Ptr<Packet> packet);
251 
255  virtual bool
256  Receive (Ptr<const Packet> p);
257 
261  void
262  SetFlags (uint32_t flags);
263 
264 private:
265  Face (const Face &);
266  Face& operator= (const Face &);
267 
268 protected:
269  Ptr<Node> m_node;
270 
271 private:
272  InterestHandler m_upstreamInterestHandler;
273  DataHandler m_upstreamDataHandler;
274  bool m_ifup;
275  uint32_t m_id;
276  uint16_t m_metric;
277  uint32_t m_flags;
278 };
279 
280 std::ostream&
281 operator<< (std::ostream& os, const Face &face);
282 
283 inline bool
284 Face::IsUp (void) const
285 {
286  return m_ifup;
287 }
288 
289 inline void
290 Face::SetUp (bool up/* = true*/)
291 {
292  m_ifup = up;
293 }
294 
295 inline uint32_t
297 {
298  return m_flags;
299 }
300 
301 inline bool
302 operator < (const Ptr<Face> &lhs, const Ptr<Face> &rhs)
303 {
304  return *lhs < *rhs;
305 }
306 
307 void
308 Face::SetId (uint32_t id)
309 {
310  m_id = id;
311 }
312 
313 uint32_t
314 Face::GetId () const
315 {
316  return m_id;
317 }
318 
319 inline bool
320 Face::operator!= (const Face &face) const
321 {
322  return !(*this == face);
323 }
324 
325 } // namespace ndn
326 } // namespace ns3
327 
328 #endif // NDN_FACE_H
void SetUp(bool up=true)
These are face states and may be distinct from actual lower-layer device states, such as found in rea...
Definition: ndn-face.h:290
Ptr< Node > m_node
Smart pointer to Node.
Definition: ndn-face.h:269
virtual std::ostream & Print(std::ostream &os) const
Print information about the face into the stream.
Definition: ndn-face.cc:267
virtual bool SendData(Ptr< const Data > data)
Send out Dat packet through the face.
Definition: ndn-face.cc:136
bool operator<(const Face &face) const
Compare two faces.
Definition: ndn-face.cc:258
virtual bool SendInterest(Ptr< const Interest > interest)
Send out interest through the face.
Definition: ndn-face.cc:123
virtual bool ReceiveInterest(Ptr< Interest > interest)
Receive interest from application or another node and forward it up to the NDN stack.
Definition: ndn-face.cc:204
uint32_t GetId() const
Get face Id.
Definition: ndn-face.h:314
uint32_t GetFlags() const
Get face flags.
Definition: ndn-face.h:296
void SetId(uint32_t id)
Set face Id.
Definition: ndn-face.h:308
bool operator==(const Face &face) const
Compare two faces.
Definition: ndn-face.cc:249
virtual void UnRegisterProtocolHandlers()
Un-Register callback to call when new packet arrives on the face.
Definition: ndn-face.cc:113
bool operator!=(const Face &face) const
Compare two faces.
Definition: ndn-face.h:320
virtual void RegisterProtocolHandlers(const InterestHandler &interestHandler, const DataHandler &dataHandler)
Register callback to call when new packet arrives on the face.
Definition: ndn-face.cc:104
Virtual class defining NDN face.
Definition: ndn-face.h:58
virtual void SetMetric(uint16_t metric)
Assign routing/forwarding metric with face.
Definition: ndn-face.cc:230
An application face.
Definition: ndn-face.h:191
virtual bool Receive(Ptr< const Packet > p)
Send packet up to the stack (towards forwarding strategy)
Definition: ndn-face.cc:163
void SetFlags(uint32_t flags)
Set face flags.
Definition: ndn-face.cc:243
virtual uint16_t GetMetric(void) const
Get routing/forwarding metric assigned to the face.
Definition: ndn-face.cc:237
virtual bool Send(Ptr< Packet > packet)
Send packet down to the stack (towards app or network)
Definition: ndn-face.cc:149
Face(Ptr< Node > node)
Default constructor.
Definition: ndn-face.cc:69
Ptr< Node > GetNode() const
Get node to which this face is associated.
Definition: ndn-face.cc:98
Flags
List of currently defined face flags.
Definition: ndn-face.h:189
virtual bool ReceiveData(Ptr< Data > data)
Receive Data packet from application or another node and forward it up to the NDN stack...
Definition: ndn-face.cc:217
Callback< void, Ptr< Face >, Ptr< Interest > > InterestHandler
NDN protocol handlers.
Definition: ndn-face.h:71
bool IsUp() const
Returns true if this face is enabled, false otherwise.
Definition: ndn-face.h:284