blob: d83f6878eae85852048c08ca93bf5610cecb2902 [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//
18// Author: George F. Riley<riley@ece.gatech.edu>
19//
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;
37// class CcnxAddress;
38// class CcnxHeader;
39// class CcnxRoutingTableEntry;
40class CcnxRoute;
41class Node;
42class Socket;
43
44
45/**
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 {
76 DROP_TTL_EXPIRED = 1, /**< Packet TTL has expired */
77 DROP_NO_ROUTE, /**< No route to host */
78 DROP_BAD_CHECKSUM, /**< Bad checksum */
79 DROP_INTERFACE_DOWN, /**< Interface is down so can not send packet */
80 DROP_ROUTE_ERROR, /**< Route error */
81 };
82
83 void SetNode (Ptr<Node> node);
84
85 // functions defined in base class Ccnx
86
87 // void SetRoutingProtocol (Ptr<CcnxRoutingProtocol> routingProtocol);
88 // Ptr<CcnxRoutingProtocol> GetRoutingProtocol (void) const;
89
90 // Ptr<Socket> CreateRawSocket (void);
91 // void DeleteRawSocket (Ptr<Socket> socket);
92
93 /**
94 * Lower layer calls this method after calling L3Demux::Lookup
95 * The ARP subclass needs to know from which NetDevice this
96 * packet is coming to:
97 * - implement a per-NetDevice ARP cache
98 * - send back arp replies on the right device
99 * \param device network device
100 * \param p the packet
101 * \param protocol lower layer protocol value
102 * \param from lower layer address of the correspondant
103 * \param to lower layer address of the destination
104 * \param packetType type of the packet (broadcast/multicast/unicast/otherhost)
105 */
106 void Receive ( Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol,
107 const Address &from,
108 const Address &to,
109 NetDevice::PacketType packetType);
110
111 /**
112 * \param packet packet to send
113 * \param route route entry
114 *
115 * Higher-level layers call this method to send a packet
116 * down the stack to the MAC and PHY layers.
117 */
118 void Send (Ptr<Packet> packet, Ptr<CcnxRoute> route);
119
120 uint32_t AddInterface (Ptr<NetDevice> device);
121 Ptr<CcnxInterface> GetInterface (uint32_t i) const;
122 uint32_t GetNInterfaces (void) const;
123
124 int32_t GetInterfaceForDevice (Ptr<const NetDevice> device) const;
125 // bool IsDestinationAddress (CcnxAddress address, uint32_t iif) const;
126
127 void SetMetric (uint32_t i, uint16_t metric);
128 uint16_t GetMetric (uint32_t i) const;
129 uint16_t GetMtu (uint32_t i) const;
130 bool IsUp (uint32_t i) const;
131 void SetUp (uint32_t i);
132 void SetDown (uint32_t i);
133
134 Ptr<NetDevice> GetNetDevice (uint32_t i);
135
136protected:
137
138 virtual void DoDispose (void);
139 /**
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 ();
144private:
145 // friend class CcnxL3ProtocolTestCase;
146 CcnxL3Protocol(const CcnxL3Protocol &);
147 CcnxL3Protocol &operator = (const CcnxL3Protocol &);
148
149 void
150 SendRealOut (Ptr<CcnxRoute> route,
151 Ptr<Packet> packet,
152 CcnxHeader const &ipHeader);
153
154 // void
155 // IpForward (Ptr<CcnxRoute> rtentry,
156 // Ptr<const Packet> p,
157 // const CcnxHeader &header);
158
159 // void
160 // IpMulticastForward (Ptr<CcnxMulticastRoute> mrtentry,
161 // Ptr<const Packet> p,
162 // const CcnxHeader &header);
163
164 void LocalDeliver (Ptr<const Packet> p, CcnxHeader const&ip, uint32_t iif);
165 void RouteInputError (Ptr<const Packet> p, const CcnxHeader & ipHeader, Socket::SocketErrno sockErrno);
166
167 uint32_t AddCcnxInterface (Ptr<CcnxInterface> interface);
168
169 typedef std::vector<Ptr<CcnxInterface> > CcnxInterfaceList;
170
171 CcnxInterfaceList m_interfaces;
172 uint16_t m_identification;
173 Ptr<Node> m_node;
174 CcnxL4Protocol m_layer4;
175
176 TracedCallback<const CcnxHeader &, Ptr<const Packet>, uint32_t> m_sendOutgoingTrace;
177 TracedCallback<const CcnxHeader &, Ptr<const Packet>, uint32_t> m_unicastForwardTrace;
178 TracedCallback<const CcnxHeader &, Ptr<const Packet>, uint32_t> m_localDeliverTrace;
179
180 // The following two traces pass a packet with an IP header
181 TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, uint32_t> m_txTrace;
182 TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, uint32_t> m_rxTrace;
183 // <ip-header, payload, reason, ifindex> (ifindex not valid if reason is DROP_NO_ROUTE)
184 TracedCallback<const CcnxHeader &, Ptr<const Packet>, DropReason, Ptr<Ccnx>, uint32_t> m_dropTrace;
185
186 // Ptr<CcnxRoutingProtocol> m_routingProtocol;
187};
188
189} // Namespace ns3
190
191#endif /* CCNX_L3_PROTOCOL_H */