blob: 3af0c9a86b951c1d4f9e019138ec0c9864088403 [file] [log] [blame]
Alexander Afanasyev45b92d42011-08-14 23:11:38 -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 Afanasyev98256102011-08-14 01:00:02 -070040class CcnxForwardingProtocol;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070041
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070042/**
43 * \brief Implement the Ccnx layer.
44 *
45 * This is the actual implementation of IP. It contains APIs to send and
46 * receive packets at the IP layer, as well as APIs for IP routing.
47 *
48 * This class contains two distinct groups of trace sources. The
49 * trace sources 'Rx' and 'Tx' are called, respectively, immediately
50 * after receiving from the NetDevice and immediately before sending
51 * to a NetDevice for transmitting a packet. These are low level
52 * trace sources that include the CcnxHeader already serialized into
53 * the packet. In contrast, the Drop, SendOutgoing, UnicastForward,
54 * and LocalDeliver trace sources are slightly higher-level and pass
55 * around the CcnxHeader as an explicit parameter and not as part of
56 * the packet.
57 */
58class CcnxL3Protocol : public Ccnx
59{
60public:
61 static TypeId GetTypeId (void);
62 static const uint16_t PROT_NUMBER;
63
64 CcnxL3Protocol();
65 virtual ~CcnxL3Protocol ();
66
67 /**
68 * \enum DropReason
69 * \brief Reason why a packet has been dropped.
70 */
71 enum DropReason
72 {
Alexander Afanasyev98256102011-08-14 01:00:02 -070073 /** \todo Fill reasons from QualNet code */
74 DROP_DUPLICATE_INTEREST=1, /**< Duplicate Interest */
75 DROP_CONGESTION, /**< Congestion detected */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070076 DROP_NO_ROUTE, /**< No route to host */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070077 DROP_INTERFACE_DOWN, /**< Interface is down so can not send packet */
78 DROP_ROUTE_ERROR, /**< Route error */
79 };
80
81 void SetNode (Ptr<Node> node);
82
83 // functions defined in base class Ccnx
Alexander Afanasyev98256102011-08-14 01:00:02 -070084
85 void SetForwardingProtocol (Ptr<CcnxForwardingProtocol> forwardingProtocol);
86 Ptr<CcnxForwardingProtocol> GetForwardingProtocol (void) const;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070087
88 /**
89 * Lower layer calls this method after calling L3Demux::Lookup
Alexander Afanasyev98256102011-08-14 01:00:02 -070090 *
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070091 * \param device network device
92 * \param p the packet
93 * \param protocol lower layer protocol value
94 * \param from lower layer address of the correspondant
95 * \param to lower layer address of the destination
96 * \param packetType type of the packet (broadcast/multicast/unicast/otherhost)
97 */
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070098 void ReceiveFromLower (Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol,
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070099 const Address &from,
100 const Address &to,
101 NetDevice::PacketType packetType);
102
103 /**
Alexander Afanasyev98256102011-08-14 01:00:02 -0700104 * Actual processing of incoming CCNx packets. Also processing packets coming from local apps
105 */
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700106 void ReceiveAndProcess (Ptr<CcnxFace> face, Ptr<Packet> p);
Alexander Afanasyev98256102011-08-14 01:00:02 -0700107
108 /**
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700109 * \param packet packet to send
110 * \param route route entry
111 *
112 * Higher-level layers call this method to send a packet
113 * down the stack to the MAC and PHY layers.
114 */
Alexander Afanasyev98256102011-08-14 01:00:02 -0700115 virtual void Send (Ptr<Packet> packet, Ptr<CcnxRoute> route);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700116
Alexander Afanasyev98256102011-08-14 01:00:02 -0700117 virtual uint32_t AddFace (Ptr<CcnxFace> face);
118 virtual uint32_t GetNFaces (void) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700119 virtual Ptr<CcnxFace> GetFace (uint32_t face) const;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700120
Alexander Afanasyev98256102011-08-14 01:00:02 -0700121 virtual void SetMetric (uint32_t i, uint16_t metric);
122 virtual uint16_t GetMetric (uint32_t i) const;
123 virtual uint16_t GetMtu (uint32_t i) const;
124 virtual bool IsUp (uint32_t i) const;
125 virtual void SetUp (uint32_t i);
126 virtual void SetDown (uint32_t i);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700127
128protected:
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700129 virtual void DoDispose (void);
130 /**
131 * This function will notify other components connected to the node that a new stack member is now connected
132 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
133 */
134 virtual void NotifyNewAggregate ();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700135
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700136private:
137 // friend class CcnxL3ProtocolTestCase;
138 CcnxL3Protocol(const CcnxL3Protocol &);
139 CcnxL3Protocol &operator = (const CcnxL3Protocol &);
140
Alexander Afanasyev98256102011-08-14 01:00:02 -0700141 /**
142 * Helper function to get CcnxFace from NetDevice
143 */
144 Ptr<CcnxFace> GetFaceForDevice (Ptr<const NetDevice> device) const;
145
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700146 void RouteInputError (Ptr<Packet> p);
147 //, Socket::SocketErrno sockErrno);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700148
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 Afanasyev45b92d42011-08-14 23:11:38 -0700154 Ptr<CcnxForwardingProtocol> m_forwardingProtocol;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700155
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700156 TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_sendOutgoingTrace;
157 TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_unicastForwardTrace;
158 TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_localDeliverTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700159
160 // The following two traces pass a packet with an IP header
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700161 TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_txTrace;
162 TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_rxTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700163 // <ip-header, payload, reason, ifindex> (ifindex not valid if reason is DROP_NO_ROUTE)
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700164 TracedCallback<Ptr<const Packet>, DropReason, Ptr<const Ccnx>, Ptr<const CcnxFace> > m_dropTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700165};
166
167} // Namespace ns3
168
169#endif /* CCNX_L3_PROTOCOL_H */