blob: 32425c4756f2fbbd1819ff9048f3161a97e8037f [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -07002//
3// Copyright (c) 2006 Georgia Tech Research Corporation
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//
Alexander Afanasyev98256102011-08-14 01:00:02 -070018// Author:
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070019//
20
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/**
46 * \brief Implement the Ccnx layer.
47 *
48 * This is the actual implementation of IP. It contains APIs to send and
49 * receive packets at the IP layer, as well as APIs for IP routing.
50 *
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:
64 static TypeId GetTypeId (void);
65 static const uint16_t PROT_NUMBER;
66
67 CcnxL3Protocol();
68 virtual ~CcnxL3Protocol ();
69
70 /**
71 * \enum DropReason
72 * \brief Reason why a packet has been dropped.
73 */
74 enum DropReason
75 {
Alexander Afanasyev98256102011-08-14 01:00:02 -070076 /** \todo Fill reasons from QualNet code */
77 DROP_DUPLICATE_INTEREST=1, /**< Duplicate Interest */
78 DROP_CONGESTION, /**< Congestion detected */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070079 DROP_NO_ROUTE, /**< No route to host */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070080 DROP_INTERFACE_DOWN, /**< Interface is down so can not send packet */
81 DROP_ROUTE_ERROR, /**< Route error */
82 };
83
84 void SetNode (Ptr<Node> node);
85
86 // functions defined in base class Ccnx
Alexander Afanasyev98256102011-08-14 01:00:02 -070087
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070088 void SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy);
89 Ptr<CcnxForwardingStrategy> GetForwardingStrategy (void) const;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070090
91 /**
92 * Lower layer calls this method after calling L3Demux::Lookup
Alexander Afanasyev98256102011-08-14 01:00:02 -070093 *
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070094 * \param device network device
95 * \param p the packet
96 * \param protocol lower layer protocol value
97 * \param from lower layer address of the correspondant
98 * \param to lower layer address of the destination
99 * \param packetType type of the packet (broadcast/multicast/unicast/otherhost)
100 */
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700101 void ReceiveFromLower (Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol,
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700102 const Address &from,
103 const Address &to,
104 NetDevice::PacketType packetType);
105
106 /**
Alexander Afanasyev98256102011-08-14 01:00:02 -0700107 * Actual processing of incoming CCNx packets. Also processing packets coming from local apps
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700108 *
109 * Processing Interest packets
Alexander Afanasyev98256102011-08-14 01:00:02 -0700110 */
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700111 virtual void
112 ReceiveAndProcess (Ptr<CcnxFace> face, Ptr<CcnxInterestHeader> header, Ptr<Packet> p);
113
114
115 /**
116 * Actual processing of incoming CCNx packets. Also processing packets coming from local apps
117 *
118 * Processing ContentObject packets
119 */
120 virtual void
121 ReceiveAndProcess (Ptr<CcnxFace> face, Ptr<CcnxContentObjectHeader> header, Ptr<Packet> p);
Alexander Afanasyev98256102011-08-14 01:00:02 -0700122
123 /**
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700124 * \param packet packet to send
125 * \param route route entry
126 *
127 * Higher-level layers call this method to send a packet
128 * down the stack to the MAC and PHY layers.
129 */
Alexander Afanasyev98256102011-08-14 01:00:02 -0700130 virtual void Send (Ptr<Packet> packet, Ptr<CcnxRoute> route);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700131
Alexander Afanasyev98256102011-08-14 01:00:02 -0700132 virtual uint32_t AddFace (Ptr<CcnxFace> face);
133 virtual uint32_t GetNFaces (void) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700134 virtual Ptr<CcnxFace> GetFace (uint32_t face) const;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700135
Alexander Afanasyev98256102011-08-14 01:00:02 -0700136 virtual void SetMetric (uint32_t i, uint16_t metric);
137 virtual uint16_t GetMetric (uint32_t i) const;
138 virtual uint16_t GetMtu (uint32_t i) const;
139 virtual bool IsUp (uint32_t i) const;
140 virtual void SetUp (uint32_t i);
141 virtual void SetDown (uint32_t i);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700142
143protected:
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700144 virtual void DoDispose (void);
145 /**
146 * This function will notify other components connected to the node that a new stack member is now connected
147 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
148 */
149 virtual void NotifyNewAggregate ();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700150
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700151private:
152 // friend class CcnxL3ProtocolTestCase;
153 CcnxL3Protocol(const CcnxL3Protocol &);
154 CcnxL3Protocol &operator = (const CcnxL3Protocol &);
155
Alexander Afanasyev98256102011-08-14 01:00:02 -0700156 /**
157 * Helper function to get CcnxFace from NetDevice
158 */
159 Ptr<CcnxFace> GetFaceForDevice (Ptr<const NetDevice> device) const;
160
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700161 void RouteInputError (Ptr<Packet> p);
162 //, Socket::SocketErrno sockErrno);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700163
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700164 /**
165 * false function. should never be called. Just to trick C++ to compile
166 */
167 virtual void
168 ReceiveAndProcess (Ptr<CcnxFace> face, Ptr<Header> header, Ptr<Packet> p);
169
Alexander Afanasyev98256102011-08-14 01:00:02 -0700170private:
171 typedef std::vector<Ptr<CcnxFace> > CcnxFaceList;
172 CcnxFaceList m_faces;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700173
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700174 Ptr<Node> m_node;
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700175 Ptr<CcnxForwardingStrategy> m_forwardingStrategy;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700176
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700177 TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_sendOutgoingTrace;
178 TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_unicastForwardTrace;
179 TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_localDeliverTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700180
181 // The following two traces pass a packet with an IP header
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700182 TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_txTrace;
183 TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_rxTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700184 // <ip-header, payload, reason, ifindex> (ifindex not valid if reason is DROP_NO_ROUTE)
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700185 TracedCallback<Ptr<const Packet>, DropReason, Ptr<const Ccnx>, Ptr<const CcnxFace> > m_dropTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700186};
187
188} // Namespace ns3
189
190#endif /* CCNX_L3_PROTOCOL_H */