blob: 63e4ff29908259bde9fef5541c91d6b21abe1e93 [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev7112f482011-08-17 14:05:57 -07002/*
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 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070020
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070021#ifndef NDN_L3_PROTOCOL_H
22#define NDN_L3_PROTOCOL_H
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070023
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070024#include "ns3/ndnSIM/model/ndn-common.hpp"
Alexander Afanasyev82d5ffe2014-12-30 23:55:38 -080025#include "ns3/ndnSIM/model/ndn-face.hpp"
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070026
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070027#include <list>
28#include <vector>
Alexander Afanasyev4975f732011-12-20 17:52:19 -080029
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070030#include "ns3/ptr.h"
31#include "ns3/net-device.h"
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -080032#include "ns3/nstime.h"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080033#include "ns3/traced-callback.h"
34
35namespace nfd {
36class Forwarder;
37class FibManager;
38class StrategyChoiceManager;
39} // namespace nfd
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070040
41namespace ns3 {
42
43class Packet;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070044class Node;
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070045class Header;
Ilya Moiseenko172763c2011-10-28 13:21:53 -070046
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070047namespace ndn {
48
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070049/**
50 * \defgroup ndn ndnSIM: NDN simulation module
51 *
Alexander Afanasyevb989b122013-07-10 17:15:46 -070052 * This is a modular implementation of NDN protocol for NS-3
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070053 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070054/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070055 * \ingroup ndn
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070056 * \brief Implementation network-layer of NDN stack
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070057 *
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070058 * This class defines the API to manipulate the following aspects of
59 * the NDN stack implementation:
60 * -# register a face (Face-derived object) for use by the NDN
61 * layer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080062 *
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070063 * Each Face-derived object has conceptually a single NDN
64 * interface associated with it.
65 *
66 * In addition, this class defines NDN packet coding constants
67 *
68 * \see Face, ForwardingStrategy
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070069 */
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080070class L3Protocol : boost::noncopyable, public Object {
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070071public:
Alexander Afanasyev7112f482011-08-17 14:05:57 -070072 /**
73 * \brief Interface ID
74 *
75 * \return interface ID
76 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080077 static TypeId
78 GetTypeId();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070079
Alexander Afanasyev016a5d82013-07-15 10:41:29 -070080 static const uint16_t ETHERNET_FRAME_TYPE; ///< @brief Ethernet Frame Type of Ndn
81 static const uint16_t IP_STACK_PORT; ///< @brief TCP/UDP port for NDN stack
82 // static const uint16_t IP_PROTOCOL_TYPE; ///< \brief IP protocol type of NDN
Alexander Afanasyev7112f482011-08-17 14:05:57 -070083
84 /**
85 * \brief Default constructor. Creates an empty stack without forwarding strategy set
86 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070087 L3Protocol();
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080088 virtual ~L3Protocol();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070089
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070090 /**
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080091 * \brief Initialize NFD instance
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070092 */
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080093 void
94 initialize();
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080095
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070096 /**
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080097 * \brief Get smart pointer to nfd::Forwarder installed on the node
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070098 */
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080099 shared_ptr<nfd::Forwarder>
100 getForwarder();
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700101
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700102 /**
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800103 * \brief Get smart pointer to nfd::FibManager, used by node's NFD
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700104 */
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800105 shared_ptr<nfd::FibManager>
106 getFibManager();
107
108 /**
109 * \brief Get smart pointer to nfd::StrategyChoiceManager, used by node's NFD
110 */
111 shared_ptr<nfd::StrategyChoiceManager>
112 getStrategyChoiceManager();
113
114
115 /**
116 * \brief Add face to NDN stack
117 *
118 * \param face smart pointer to Face-derived object (AppFace, NetDeviceFace)
119 * \return nfd::FaceId
120 *
121 * \see AppFace, NetDeviceFace
122 */
123 nfd::FaceId
124 addFace(shared_ptr<Face> face);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800125
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700126 /**
127 * \brief Get face by face ID
128 * \param face The face ID number
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800129 * \returns The Face associated with the Ndn face number.
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700130 */
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800131 shared_ptr<Face>
132 getFaceById(nfd::FaceId face) const;
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700133
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800134 // /**
135 // * \brief Remove face from ndn stack (remove callbacks)
136 // */
137 // virtual void
138 // removeFace(shared_ptr<Face> face);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800139
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700140 /**
141 * \brief Get face for NetDevice
142 */
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800143 shared_ptr<Face>
144 getFaceByNetDevice(Ptr<NetDevice> netDevice) const;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700145
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700146protected:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800147 virtual void
148 DoDispose(void); ///< @brief Do cleanup
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700149
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700150 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800151 * This function will notify other components connected to the node that a new stack member is now
152 * connected
153 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them
154 * together.
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700155 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800156 virtual void
157 NotifyNewAggregate();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700158
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700159private:
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800160 void
161 initializeManagement();
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800162
Alexander Afanasyev98256102011-08-14 01:00:02 -0700163private:
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800164 class Impl;
165 std::unique_ptr<Impl> m_impl;
166
167 // These objects are aggregated, but for optimization, get them here
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700168 Ptr<Node> m_node; ///< \brief node on which ndn stack is installed
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800169
170 TracedCallback<const Interest&, const Face&>
171 m_inInterests; ///< @brief trace of incoming Interests
172 TracedCallback<const Interest&, const Face&>
173 m_outInterests; ///< @brief Transmitted interests trace
174
175 TracedCallback<const Data&, const Face&> m_outData; ///< @brief trace of outgoing Data
176 TracedCallback<const Data&, const Face&> m_inData; ///< @brief trace of incoming Data
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700177};
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700178
179} // namespace ndn
180} // namespace ns3
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700181
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700182#endif /* NDN_L3_PROTOCOL_H */