blob: 4743bdd5805fa804406dd82852ae4ebffa08c9cb [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 Afanasyev56f79ea2011-08-17 23:54:27 -070069 static TypeId GetTypeId ();
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);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700105 Ptr<CcnxForwardingStrategy> GetForwardingStrategy () const;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700106
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700107 virtual void Send (const Ptr<CcnxFace> &face, const Ptr<Packet> &packet);
108 virtual void Receive (const Ptr<CcnxFace> &device, const Ptr<Packet> &p);
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700109
110 virtual uint32_t AddFace (const Ptr<CcnxFace> &face);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700111 virtual uint32_t GetNFaces () const;
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700112 virtual Ptr<CcnxFace> GetFace (uint32_t face) const;
113
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700114protected:
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700115 /**
Alexander Afanasyev98256102011-08-14 01:00:02 -0700116 * Actual processing of incoming CCNx packets. Also processing packets coming from local apps
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700117 *
118 * Processing Interest packets
Alexander Afanasyev98256102011-08-14 01:00:02 -0700119 */
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700120 virtual void
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700121 ReceiveAndProcess (const Ptr<CcnxFace> &face,
122 const Ptr<CcnxInterestHeader> &header,
123 const Ptr<Packet> &p);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700124
125
126 /**
127 * Actual processing of incoming CCNx packets. Also processing packets coming from local apps
128 *
129 * Processing ContentObject packets
130 */
131 virtual void
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700132 ReceiveAndProcess (const Ptr<CcnxFace> &face,
133 const Ptr<CcnxContentObjectHeader> &header,
134 const Ptr<Packet> &p);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700135
136protected:
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700137 virtual void DoDispose (void);
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700138
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700139 /**
140 * This function will notify other components connected to the node that a new stack member is now connected
141 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
142 */
143 virtual void NotifyNewAggregate ();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700144
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700145private:
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700146 CcnxL3Protocol(const CcnxL3Protocol &); ///< copy constructor is disabled
147 CcnxL3Protocol &operator = (const CcnxL3Protocol &); ///< copy operator is disabled
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700148
Alexander Afanasyev98256102011-08-14 01:00:02 -0700149 /**
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700150 * \brief Fake function. should never be called. Just to trick C++ to compile
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700151 */
152 virtual void
153 ReceiveAndProcess (Ptr<CcnxFace> face, Ptr<Header> header, Ptr<Packet> p);
154
Alexander Afanasyev98256102011-08-14 01:00:02 -0700155private:
Alexander Afanasyevab1d5602011-08-17 19:17:18 -0700156 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 -0700157 typedef std::vector<Ptr<CcnxFace> > CcnxFaceList;
158 CcnxFaceList m_faces;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700159
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700160 Ptr<Node> m_node;
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700161 Ptr<CcnxForwardingStrategy> m_forwardingStrategy;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700162
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700163 // TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_sendOutgoingTrace;
164 // TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_unicastForwardTrace;
165 // TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_localDeliverTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700166
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700167 // // The following two traces pass a packet with an IP header
168 // TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_txTrace;
169 // TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_rxTrace;
170 // // <ip-header, payload, reason, ifindex> (ifindex not valid if reason is DROP_NO_ROUTE)
171 // TracedCallback<Ptr<const Packet>, DropReason, Ptr<const Ccnx>, Ptr<const CcnxFace> > m_dropTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700172};
173
174} // Namespace ns3
175
176#endif /* CCNX_L3_PROTOCOL_H */