blob: 121c1468fded03a77004e70881046c6a74931c48 [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 *
18 * Authors:
19 */
Alexander Afanasyev98256102011-08-14 01:00:02 -070020#ifndef CCNX_FACE_H
21#define CCNX_FACE_H
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070022
23#include <list>
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
31class NetDevice;
32class Packet;
33class Node;
34
35/**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070036 * \ingroup ccnx
37 * \brief Virtual class defining CCNx face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070038 *
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070039 * 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 Afanasyev08d984e2011-08-13 19:20:22 -070042 *
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070043 * \see CcnxLocalFace, CcnxNetDeviceFace, CcnxIpv4Face, CcnxUdpFace
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070044 */
Alexander Afanasyev98256102011-08-14 01:00:02 -070045class CcnxFace : public Object
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070046{
47public:
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070048 /**
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 Afanasyev08d984e2011-08-13 19:20:22 -070061 static TypeId GetTypeId (void);
62
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070063 /**
64 * \brief Default constructor
65 */
Alexander Afanasyev98256102011-08-14 01:00:02 -070066 CcnxFace ();
67 virtual ~CcnxFace();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070068
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070069 ////////////////////////////////////////////////////////////////////
70
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070071 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070072 * \brief Register callback to call when new packet arrives on the face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070073 *
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070074 * 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 Afanasyev08d984e2011-08-13 19:20:22 -070098 */
Alexander Afanasyev98256102011-08-14 01:00:02 -070099 virtual void SetMetric (uint16_t metric);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700100
101 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700102 * \brief Get routing/forwarding metric assigned to the face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700103 *
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700104 * \returns configured routing/forwarding metric (cost) of this face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700105 */
Alexander Afanasyev98256102011-08-14 01:00:02 -0700106 virtual uint16_t GetMetric (void) const;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700107
108 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700109 * 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 Afanasyev08d984e2011-08-13 19:20:22 -0700112 */
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700113
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700114 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700115 * \brief Enable this face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700116 */
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700117 virtual void SetUp ();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700118
119 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700120 * \brief Disable this face
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700121 */
Alexander Afanasyev98256102011-08-14 01:00:02 -0700122 virtual void SetDown (void);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700123
124 /**
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700125 * \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 Afanasyev08d984e2011-08-13 19:20:22 -0700133
134protected:
135 virtual void DoDispose (void);
136
137private:
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700138 CcnxFace (const CcnxFace &) {} ///< Disabled copy constructor
139 CcnxFace& operator= (const CcnxFace &) {} ///< Disabled copy operator
140
141protected:
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700142 bool m_ifup;
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700143 uint32_t m_id; ///< id of the interface in the CCNx stack (per-node uniqueness)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700144 uint16_t m_metric;
145 Ptr<Node> m_node;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700146};
147
Alexander Afanasyev98256102011-08-14 01:00:02 -0700148std::ostream& operator<< (std::ostream& os, CcnxFace const& face);
149
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700150} // namespace ns3
151
Alexander Afanasyev98256102011-08-14 01:00:02 -0700152#endif //CCNX_FACE_H