blob: 28a8d061bab0c3fdb0fcbb349793c9c955e519d6 [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;
44
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070045/**
Alexander Afanasyev7112f482011-08-17 14:05:57 -070046 * \ingroup ccnx
47 * \brief Actual implementation of the Ccnx network layer
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070048 *
Alexander Afanasyev7112f482011-08-17 14:05:57 -070049 * \todo This description is incorrect. Should be changed accordingly
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070050 *
51 * This class contains two distinct groups of trace sources. The
52 * trace sources 'Rx' and 'Tx' are called, respectively, immediately
53 * after receiving from the NetDevice and immediately before sending
54 * to a NetDevice for transmitting a packet. These are low level
55 * trace sources that include the CcnxHeader already serialized into
56 * the packet. In contrast, the Drop, SendOutgoing, UnicastForward,
57 * and LocalDeliver trace sources are slightly higher-level and pass
58 * around the CcnxHeader as an explicit parameter and not as part of
59 * the packet.
60 */
61class CcnxL3Protocol : public Ccnx
62{
63public:
Alexander Afanasyev7112f482011-08-17 14:05:57 -070064 /**
65 * \brief Interface ID
66 *
67 * \return interface ID
68 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070069 static TypeId GetTypeId (void);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070070
Alexander Afanasyev7112f482011-08-17 14:05:57 -070071 static const uint16_t ETHERNET_FRAME_TYPE; ///< \brief Ethernet Frame Type of CCNx
72 static const uint16_t IP_PROTOCOL_TYPE; ///< \brief IP protocol type of CCNx
73 static const uint16_t UDP_PORT; ///< \brief UDP port of CCNx
74
75 /**
76 * \brief Default constructor. Creates an empty stack without forwarding strategy set
77 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070078 CcnxL3Protocol();
79 virtual ~CcnxL3Protocol ();
80
81 /**
82 * \enum DropReason
83 * \brief Reason why a packet has been dropped.
84 */
85 enum DropReason
86 {
Alexander Afanasyev98256102011-08-14 01:00:02 -070087 /** \todo Fill reasons from QualNet code */
88 DROP_DUPLICATE_INTEREST=1, /**< Duplicate Interest */
89 DROP_CONGESTION, /**< Congestion detected */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070090 DROP_NO_ROUTE, /**< No route to host */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070091 DROP_INTERFACE_DOWN, /**< Interface is down so can not send packet */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070092 };
93
Alexander Afanasyev7112f482011-08-17 14:05:57 -070094 /**
95 * \brief Assigns node to the CCNx stack
96 *
97 * \param node Simulation node
98 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070099 void SetNode (Ptr<Node> node);
100
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700101 ////////////////////////////////////////////////////////////////////
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700102 // functions defined in base class Ccnx
Alexander Afanasyev98256102011-08-14 01:00:02 -0700103
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700104 void SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy);
105 Ptr<CcnxForwardingStrategy> GetForwardingStrategy (void) const;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700106
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700107 virtual void Send (const Ptr<CcnxFace> &face, Ptr<Packet> packet);
108 virtual void ReceiveFromLower (const Ptr<Face> &device, Ptr<const Packet> p);
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700109
110 virtual uint32_t AddFace (const Ptr<CcnxFace> &face);
111 virtual uint32_t GetNFaces (void) const;
112 virtual Ptr<CcnxFace> GetFace (uint32_t face) const;
113
114 virtual void SetMetric (uint32_t i, uint16_t metric);
115 virtual uint16_t GetMetric (uint32_t i) const;
116 virtual uint16_t GetMtu (uint32_t i) const;
117 virtual bool IsUp (uint32_t i) const;
118 virtual void SetUp (uint32_t i);
119 virtual void SetDown (uint32_t i);
120
121protected:
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700122 /**
Alexander Afanasyev98256102011-08-14 01:00:02 -0700123 * Actual processing of incoming CCNx packets. Also processing packets coming from local apps
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700124 *
125 * Processing Interest packets
Alexander Afanasyev98256102011-08-14 01:00:02 -0700126 */
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700127 virtual void
128 ReceiveAndProcess (Ptr<CcnxFace> face, Ptr<CcnxInterestHeader> header, Ptr<Packet> p);
129
130
131 /**
132 * Actual processing of incoming CCNx packets. Also processing packets coming from local apps
133 *
134 * Processing ContentObject packets
135 */
136 virtual void
137 ReceiveAndProcess (Ptr<CcnxFace> face, Ptr<CcnxContentObjectHeader> header, Ptr<Packet> p);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700138
139protected:
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700140 virtual void DoDispose (void);
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700141
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700142 /**
143 * This function will notify other components connected to the node that a new stack member is now connected
144 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
145 */
146 virtual void NotifyNewAggregate ();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700147
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700148private:
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700149 CcnxL3Protocol(const CcnxL3Protocol &); ///< copy constructor is disabled
150 CcnxL3Protocol &operator = (const CcnxL3Protocol &); ///< copy operator is disabled
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700151
Alexander Afanasyev98256102011-08-14 01:00:02 -0700152 /**
153 * Helper function to get CcnxFace from NetDevice
154 */
155 Ptr<CcnxFace> GetFaceForDevice (Ptr<const NetDevice> device) const;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700156
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700157 /**
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700158 * \brief Fake function. should never be called. Just to trick C++ to compile
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700159 */
160 virtual void
161 ReceiveAndProcess (Ptr<CcnxFace> face, Ptr<Header> header, Ptr<Packet> p);
162
Alexander Afanasyev98256102011-08-14 01:00:02 -0700163private:
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700164 uint32_t m_faceCounter; ///< counter of faces. Increased every time a new face is added to the stack
Alexander Afanasyev98256102011-08-14 01:00:02 -0700165 typedef std::vector<Ptr<CcnxFace> > CcnxFaceList;
166 CcnxFaceList m_faces;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700167
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700168 Ptr<Node> m_node;
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700169 Ptr<CcnxForwardingStrategy> m_forwardingStrategy;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700170
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700171 // TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_sendOutgoingTrace;
172 // TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_unicastForwardTrace;
173 // TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_localDeliverTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700174
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700175 // // The following two traces pass a packet with an IP header
176 // TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_txTrace;
177 // TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_rxTrace;
178 // // <ip-header, payload, reason, ifindex> (ifindex not valid if reason is DROP_NO_ROUTE)
179 // TracedCallback<Ptr<const Packet>, DropReason, Ptr<const Ccnx>, Ptr<const CcnxFace> > m_dropTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700180};
181
182} // Namespace ns3
183
184#endif /* CCNX_L3_PROTOCOL_H */