blob: 787bfa0d55aeb1840ad8754021c24bda64b4f07c [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
34/**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070035 * \ingroup ccnx
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070036 * \defgroup ccnx-face
37 */
38/**
39 * \ingroup ccnx-face
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070040 * \brief Virtual class defining CCNx face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070041 *
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070042 * 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 Afanasyev08d984e2011-08-13 19:20:22 -070045 *
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070046 * \see CcnxLocalFace, CcnxNetDeviceFace, CcnxIpv4Face, CcnxUdpFace
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070047 */
Alexander Afanasyev98256102011-08-14 01:00:02 -070048class CcnxFace : public Object
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070049{
50public:
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070051 /**
52 * \brief Ccnx protocol hanler
53 *
54 * \param face Face from which packet has been received
55 * \param packet Received packet
56 */
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070057 typedef Callback<void,const Ptr<CcnxFace>&,const Ptr<Packet>& > ProtocolHandler;
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070058
59 /**
60 * \brief Interface ID
61 *
62 * \return interface ID
63 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070064 static TypeId GetTypeId (void);
65
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070066 /**
67 * \brief Default constructor
68 */
Alexander Afanasyev98256102011-08-14 01:00:02 -070069 CcnxFace ();
70 virtual ~CcnxFace();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070071
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070072 ////////////////////////////////////////////////////////////////////
73
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070074 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070075 * \brief Register callback to call when new packet arrives on the face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070076 *
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070077 * This method should call protocol-dependent registration function
78 */
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070079 virtual void RegisterProtocolHandler (ProtocolHandler handler) = 0;
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070080
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 Afanasyev08d984e2011-08-13 19:20:22 -0700101 */
Alexander Afanasyev98256102011-08-14 01:00:02 -0700102 virtual void SetMetric (uint16_t metric);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700103
104 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700105 * \brief Get routing/forwarding metric assigned to the face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700106 *
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700107 * \returns configured routing/forwarding metric (cost) of this face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700108 */
Alexander Afanasyev98256102011-08-14 01:00:02 -0700109 virtual uint16_t GetMetric (void) const;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700110
111 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700112 * 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 Afanasyev08d984e2011-08-13 19:20:22 -0700115 */
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700116
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700117 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700118 * \brief Enable this face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700119 */
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700120 virtual void SetUp ();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700121
122 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700123 * \brief Disable this face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700124 */
Alexander Afanasyev98256102011-08-14 01:00:02 -0700125 virtual void SetDown (void);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700126
127 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700128 * \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 Afanasyev08d984e2011-08-13 19:20:22 -0700136
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700137 /**
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 Afanasyev08d984e2011-08-13 19:20:22 -0700160protected:
161 virtual void DoDispose (void);
162
163private:
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700164 CcnxFace (const CcnxFace &); ///< \brief Disabled copy constructor
165 CcnxFace& operator= (const CcnxFace &); ///< \brief Disabled copy operator
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700166
167protected:
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700168 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
172private:
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 Afanasyev08d984e2011-08-13 19:20:22 -0700175};
176
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700177std::ostream& operator<< (std::ostream& os, const CcnxFace &face);
178
179void
180CcnxFace::SetId (uint32_t id)
181{
182 m_id = id;
183}
184
185uint32_t
186CcnxFace::GetId () const
187{
188 return m_id;
189}
Alexander Afanasyev98256102011-08-14 01:00:02 -0700190
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700191} // namespace ns3
192
Alexander Afanasyev98256102011-08-14 01:00:02 -0700193#endif //CCNX_FACE_H