blob: 8c92c935c93c5047ca2c3fedbc674c69e9158421 [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
21#ifndef CCNX_L3_PROTOCOL_H
22#define CCNX_L3_PROTOCOL_H
23
24#include <list>
25#include <vector>
26#include <stdint.h>
27#include "ns3/ptr.h"
28#include "ns3/net-device.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070029#include "ns3/traced-callback.h"
30
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070031#include "ccnx.h"
32
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070033namespace ns3 {
34
35class Packet;
36class NetDevice;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070037class Node;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070038class CcnxFace;
39class CcnxRoute;
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070040class CcnxForwardingStrategy;
41class Header;
42class CcnxInterestHeader;
43class CcnxContentObjectHeader;
Ilya Moiseenko888161d2011-08-29 13:01:17 -070044//class CcnxContentStore;
Alexander Afanasyev070aa482011-08-20 00:38:25 -070045
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070046/**
Alexander Afanasyev7112f482011-08-17 14:05:57 -070047 * \ingroup ccnx
48 * \brief Actual implementation of the Ccnx network layer
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070049 *
Alexander Afanasyev7112f482011-08-17 14:05:57 -070050 * \todo This description is incorrect. Should be changed accordingly
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070051 *
52 * This class contains two distinct groups of trace sources. The
53 * trace sources 'Rx' and 'Tx' are called, respectively, immediately
54 * after receiving from the NetDevice and immediately before sending
55 * to a NetDevice for transmitting a packet. These are low level
56 * trace sources that include the CcnxHeader already serialized into
57 * the packet. In contrast, the Drop, SendOutgoing, UnicastForward,
58 * and LocalDeliver trace sources are slightly higher-level and pass
59 * around the CcnxHeader as an explicit parameter and not as part of
60 * the packet.
61 */
62class CcnxL3Protocol : public Ccnx
63{
64public:
Alexander Afanasyev7112f482011-08-17 14:05:57 -070065 /**
66 * \brief Interface ID
67 *
68 * \return interface ID
69 */
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070070 static TypeId GetTypeId ();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070071
Alexander Afanasyev7112f482011-08-17 14:05:57 -070072 static const uint16_t ETHERNET_FRAME_TYPE; ///< \brief Ethernet Frame Type of CCNx
73 static const uint16_t IP_PROTOCOL_TYPE; ///< \brief IP protocol type of CCNx
74 static const uint16_t UDP_PORT; ///< \brief UDP port of CCNx
75
76 /**
77 * \brief Default constructor. Creates an empty stack without forwarding strategy set
78 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070079 CcnxL3Protocol();
80 virtual ~CcnxL3Protocol ();
81
82 /**
83 * \enum DropReason
84 * \brief Reason why a packet has been dropped.
85 */
86 enum DropReason
87 {
Alexander Afanasyev98256102011-08-14 01:00:02 -070088 /** \todo Fill reasons from QualNet code */
89 DROP_DUPLICATE_INTEREST=1, /**< Duplicate Interest */
90 DROP_CONGESTION, /**< Congestion detected */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070091 DROP_NO_ROUTE, /**< No route to host */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070092 DROP_INTERFACE_DOWN, /**< Interface is down so can not send packet */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070093 };
94
Alexander Afanasyev7112f482011-08-17 14:05:57 -070095 /**
96 * \brief Assigns node to the CCNx stack
97 *
98 * \param node Simulation node
99 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700100 void SetNode (Ptr<Node> node);
101
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700102 ////////////////////////////////////////////////////////////////////
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700103 // functions defined in base class Ccnx
Alexander Afanasyev98256102011-08-14 01:00:02 -0700104
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700105 void SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700106 Ptr<CcnxForwardingStrategy> GetForwardingStrategy () const;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700107
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700108 virtual void Send (const Ptr<CcnxFace> &face, const Ptr<Packet> &packet);
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700109 virtual void Receive (const Ptr<CcnxFace> &face, const Ptr<const Packet> &p);
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700110
111 virtual uint32_t AddFace (const Ptr<CcnxFace> &face);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700112 virtual uint32_t GetNFaces () const;
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700113 virtual Ptr<CcnxFace> GetFace (uint32_t face) const;
114
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700115protected:
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700116 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700117 * \brief Actual processing of incoming CCNx interests
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700118 *
119 * Processing Interest packets
Alexander Afanasyev98256102011-08-14 01:00:02 -0700120 */
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700121 virtual void
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700122 ReceiveAndProcess (const Ptr<CcnxFace> &face,
123 const Ptr<CcnxInterestHeader> &header,
124 const Ptr<Packet> &p);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700125
126
127 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700128 * \brief Actual processing of incoming CCNx content objects
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700129 *
130 * Processing ContentObject packets
131 */
132 virtual void
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700133 ReceiveAndProcess (const Ptr<CcnxFace> &face,
134 const Ptr<CcnxContentObjectHeader> &header,
135 const Ptr<Packet> &p);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700136
137protected:
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700138 virtual void DoDispose (void);
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700139
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700140 /**
141 * This function will notify other components connected to the node that a new stack member is now connected
142 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
143 */
144 virtual void NotifyNewAggregate ();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700145
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700146private:
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700147 CcnxL3Protocol(const CcnxL3Protocol &); ///< copy constructor is disabled
148 CcnxL3Protocol &operator = (const CcnxL3Protocol &); ///< copy operator is disabled
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700149
Alexander Afanasyev98256102011-08-14 01:00:02 -0700150 /**
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700151 * \brief Fake function. should never be called. Just to trick C++ to compile
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700152 */
153 virtual void
154 ReceiveAndProcess (Ptr<CcnxFace> face, Ptr<Header> header, Ptr<Packet> p);
155
Alexander Afanasyev98256102011-08-14 01:00:02 -0700156private:
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700157 uint32_t m_faceCounter; ///< \brief counter of faces. Increased every time a new face is added to the stack
Alexander Afanasyev98256102011-08-14 01:00:02 -0700158 typedef std::vector<Ptr<CcnxFace> > CcnxFaceList;
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700159 CcnxFaceList m_faces; ///< \brief list of faces that belongs to ccnx stack on this node
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700160
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700161 Ptr<Node> m_node; ///< \brief node on which ccnx stack is installed
162 Ptr<CcnxForwardingStrategy> m_forwardingStrategy; ///< \brief smart pointer to the selected forwarding strategy
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700163
Ilya Moiseenko888161d2011-08-29 13:01:17 -0700164 //Ptr<CcnxContentStore> m_contentStore;
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700165
166 /**
167 * \brief Trace of transmitted packets, including all headers
168 * \internal
169 */
170 TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_txTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700171
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700172 /**
173 * \brief Trace of received packets, including all headers
174 * \internal
175 */
176 TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_rxTrace;
177
178 /**
179 * \brief Trace of dropped packets, including reason and all headers
180 * \internal
181 */
182 TracedCallback<Ptr<const Packet>, DropReason, Ptr<const Ccnx>, Ptr<const CcnxFace> > m_dropTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700183};
184
185} // Namespace ns3
186
187#endif /* CCNX_L3_PROTOCOL_H */