blob: d45f0b3ad1b507b5ab9cfb17f737c381a49450c7 [file] [log] [blame]
Alexander Afanasyev08d984e2011-08-13 19:20:22 -07001// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
2//
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"
29#include "ns3/ccnx.h"
30#include "ns3/traced-callback.h"
31
32namespace ns3 {
33
34class Packet;
35class NetDevice;
36class CcnxInterface;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070037class CcnxRoute;
38class Node;
39class Socket;
Alexander Afanasyev98256102011-08-14 01:00:02 -070040class CcnxForwardingProtocol;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070041
42
43/**
44 * \brief Implement the Ccnx layer.
45 *
46 * This is the actual implementation of IP. It contains APIs to send and
47 * receive packets at the IP layer, as well as APIs for IP routing.
48 *
49 * This class contains two distinct groups of trace sources. The
50 * trace sources 'Rx' and 'Tx' are called, respectively, immediately
51 * after receiving from the NetDevice and immediately before sending
52 * to a NetDevice for transmitting a packet. These are low level
53 * trace sources that include the CcnxHeader already serialized into
54 * the packet. In contrast, the Drop, SendOutgoing, UnicastForward,
55 * and LocalDeliver trace sources are slightly higher-level and pass
56 * around the CcnxHeader as an explicit parameter and not as part of
57 * the packet.
58 */
59class CcnxL3Protocol : public Ccnx
60{
61public:
62 static TypeId GetTypeId (void);
63 static const uint16_t PROT_NUMBER;
64
65 CcnxL3Protocol();
66 virtual ~CcnxL3Protocol ();
67
68 /**
69 * \enum DropReason
70 * \brief Reason why a packet has been dropped.
71 */
72 enum DropReason
73 {
Alexander Afanasyev98256102011-08-14 01:00:02 -070074 /** \todo Fill reasons from QualNet code */
75 DROP_DUPLICATE_INTEREST=1, /**< Duplicate Interest */
76 DROP_CONGESTION, /**< Congestion detected */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070077 DROP_NO_ROUTE, /**< No route to host */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070078 DROP_INTERFACE_DOWN, /**< Interface is down so can not send packet */
79 DROP_ROUTE_ERROR, /**< Route error */
80 };
81
82 void SetNode (Ptr<Node> node);
83
84 // functions defined in base class Ccnx
Alexander Afanasyev98256102011-08-14 01:00:02 -070085
86 void SetForwardingProtocol (Ptr<CcnxForwardingProtocol> forwardingProtocol);
87 Ptr<CcnxForwardingProtocol> GetForwardingProtocol (void) const;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070088
89 /**
90 * Lower layer calls this method after calling L3Demux::Lookup
Alexander Afanasyev98256102011-08-14 01:00:02 -070091 *
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070092 * \param device network device
93 * \param p the packet
94 * \param protocol lower layer protocol value
95 * \param from lower layer address of the correspondant
96 * \param to lower layer address of the destination
97 * \param packetType type of the packet (broadcast/multicast/unicast/otherhost)
98 */
Alexander Afanasyev98256102011-08-14 01:00:02 -070099 void Receive (Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol,
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700100 const Address &from,
101 const Address &to,
102 NetDevice::PacketType packetType);
103
104 /**
Alexander Afanasyev98256102011-08-14 01:00:02 -0700105 * Actual processing of incoming CCNx packets. Also processing packets coming from local apps
106 */
107 void Receive (Ptr<CcnxFace> face, Ptr<const Packet> p);
108
109 /**
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700110 * \param packet packet to send
111 * \param route route entry
112 *
113 * Higher-level layers call this method to send a packet
114 * down the stack to the MAC and PHY layers.
115 */
Alexander Afanasyev98256102011-08-14 01:00:02 -0700116 virtual void Send (Ptr<Packet> packet, Ptr<CcnxRoute> route);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700117
Alexander Afanasyev98256102011-08-14 01:00:02 -0700118 virtual uint32_t AddFace (Ptr<CcnxFace> face);
119 virtual uint32_t GetNFaces (void) const;
120 virtual Ptr<CcnxFace> GetFace (uint32_t face);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700121
Alexander Afanasyev98256102011-08-14 01:00:02 -0700122 virtual void SetMetric (uint32_t i, uint16_t metric);
123 virtual uint16_t GetMetric (uint32_t i) const;
124 virtual uint16_t GetMtu (uint32_t i) const;
125 virtual bool IsUp (uint32_t i) const;
126 virtual void SetUp (uint32_t i);
127 virtual void SetDown (uint32_t i);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700128
129protected:
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700130 virtual void DoDispose (void);
131 /**
132 * This function will notify other components connected to the node that a new stack member is now connected
133 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
134 */
135 virtual void NotifyNewAggregate ();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700136
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700137private:
138 // friend class CcnxL3ProtocolTestCase;
139 CcnxL3Protocol(const CcnxL3Protocol &);
140 CcnxL3Protocol &operator = (const CcnxL3Protocol &);
141
Alexander Afanasyev98256102011-08-14 01:00:02 -0700142 /**
143 * Helper function to get CcnxFace from NetDevice
144 */
145 Ptr<CcnxFace> GetFaceForDevice (Ptr<const NetDevice> device) const;
146
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700147 void RouteInputError (Ptr<const Packet> p, const CcnxHeader & ipHeader, Socket::SocketErrno sockErrno);
148
Alexander Afanasyev98256102011-08-14 01:00:02 -0700149private:
150 typedef std::vector<Ptr<CcnxFace> > CcnxFaceList;
151 CcnxFaceList m_faces;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700152
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700153 Ptr<Node> m_node;
Alexander Afanasyev98256102011-08-14 01:00:02 -0700154 // Ptr<CcnxForwardingProtocol> m_forwardingProtocol;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700155
156 TracedCallback<const CcnxHeader &, Ptr<const Packet>, uint32_t> m_sendOutgoingTrace;
157 TracedCallback<const CcnxHeader &, Ptr<const Packet>, uint32_t> m_unicastForwardTrace;
158 TracedCallback<const CcnxHeader &, Ptr<const Packet>, uint32_t> m_localDeliverTrace;
159
160 // The following two traces pass a packet with an IP header
161 TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, uint32_t> m_txTrace;
162 TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, uint32_t> m_rxTrace;
163 // <ip-header, payload, reason, ifindex> (ifindex not valid if reason is DROP_NO_ROUTE)
164 TracedCallback<const CcnxHeader &, Ptr<const Packet>, DropReason, Ptr<Ccnx>, uint32_t> m_dropTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700165};
166
167} // Namespace ns3
168
169#endif /* CCNX_L3_PROTOCOL_H */