blob: e8a0d2288ecf02486637ea362995b18e3dd8e944 [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 Afanasyev7112f482011-08-17 14:05:57 -0700107 virtual void Send (Ptr<Packet> packet, const Ptr<CcnxFace> &face);
108
109 virtual uint32_t AddFace (const Ptr<CcnxFace> &face);
110 virtual uint32_t GetNFaces (void) const;
111 virtual Ptr<CcnxFace> GetFace (uint32_t face) const;
112
113 virtual void SetMetric (uint32_t i, uint16_t metric);
114 virtual uint16_t GetMetric (uint32_t i) const;
115 virtual uint16_t GetMtu (uint32_t i) const;
116 virtual bool IsUp (uint32_t i) const;
117 virtual void SetUp (uint32_t i);
118 virtual void SetDown (uint32_t i);
119
120protected:
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700121 /**
122 * Lower layer calls this method after calling L3Demux::Lookup
Alexander Afanasyev98256102011-08-14 01:00:02 -0700123 *
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700124 * \param device network device
125 * \param p the packet
126 * \param protocol lower layer protocol value
127 * \param from lower layer address of the correspondant
128 * \param to lower layer address of the destination
129 * \param packetType type of the packet (broadcast/multicast/unicast/otherhost)
130 */
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700131 void ReceiveFromLower (Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol,
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700132 const Address &from,
133 const Address &to,
134 NetDevice::PacketType packetType);
135
136 /**
Alexander Afanasyev98256102011-08-14 01:00:02 -0700137 * Actual processing of incoming CCNx packets. Also processing packets coming from local apps
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700138 *
139 * Processing Interest packets
Alexander Afanasyev98256102011-08-14 01:00:02 -0700140 */
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700141 virtual void
142 ReceiveAndProcess (Ptr<CcnxFace> face, Ptr<CcnxInterestHeader> header, Ptr<Packet> p);
143
144
145 /**
146 * Actual processing of incoming CCNx packets. Also processing packets coming from local apps
147 *
148 * Processing ContentObject packets
149 */
150 virtual void
151 ReceiveAndProcess (Ptr<CcnxFace> face, Ptr<CcnxContentObjectHeader> header, Ptr<Packet> p);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700152
153protected:
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700154 virtual void DoDispose (void);
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700155
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700156 /**
157 * This function will notify other components connected to the node that a new stack member is now connected
158 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
159 */
160 virtual void NotifyNewAggregate ();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700161
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700162private:
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700163 CcnxL3Protocol(const CcnxL3Protocol &); ///< copy constructor is disabled
164 CcnxL3Protocol &operator = (const CcnxL3Protocol &); ///< copy operator is disabled
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700165
Alexander Afanasyev98256102011-08-14 01:00:02 -0700166 /**
167 * Helper function to get CcnxFace from NetDevice
168 */
169 Ptr<CcnxFace> GetFaceForDevice (Ptr<const NetDevice> device) const;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700170
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700171 /**
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700172 * \brief Fake function. should never be called. Just to trick C++ to compile
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700173 */
174 virtual void
175 ReceiveAndProcess (Ptr<CcnxFace> face, Ptr<Header> header, Ptr<Packet> p);
176
Alexander Afanasyev98256102011-08-14 01:00:02 -0700177private:
178 typedef std::vector<Ptr<CcnxFace> > CcnxFaceList;
179 CcnxFaceList m_faces;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700180
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700181 Ptr<Node> m_node;
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700182 Ptr<CcnxForwardingStrategy> m_forwardingStrategy;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700183
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700184 // TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_sendOutgoingTrace;
185 // TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_unicastForwardTrace;
186 // TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_localDeliverTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700187
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700188 // // The following two traces pass a packet with an IP header
189 // TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_txTrace;
190 // TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_rxTrace;
191 // // <ip-header, payload, reason, ifindex> (ifindex not valid if reason is DROP_NO_ROUTE)
192 // TracedCallback<Ptr<const Packet>, DropReason, Ptr<const Ccnx>, Ptr<const CcnxFace> > m_dropTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700193};
194
195} // Namespace ns3
196
197#endif /* CCNX_L3_PROTOCOL_H */