Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 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 Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 18 | // Author: |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 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" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 29 | #include "ns3/traced-callback.h" |
| 30 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 31 | #include "ccnx.h" |
| 32 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 33 | namespace ns3 { |
| 34 | |
| 35 | class Packet; |
| 36 | class NetDevice; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 37 | class Node; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 38 | class CcnxFace; |
| 39 | class CcnxRoute; |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 40 | class CcnxForwardingStrategy; |
| 41 | class Header; |
| 42 | class CcnxInterestHeader; |
| 43 | class CcnxContentObjectHeader; |
| 44 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 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 | */ |
| 61 | class CcnxL3Protocol : public Ccnx |
| 62 | { |
| 63 | public: |
| 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 Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 76 | /** \todo Fill reasons from QualNet code */ |
| 77 | DROP_DUPLICATE_INTEREST=1, /**< Duplicate Interest */ |
| 78 | DROP_CONGESTION, /**< Congestion detected */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 79 | DROP_NO_ROUTE, /**< No route to host */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 80 | 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 Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 87 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 88 | void SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy); |
| 89 | Ptr<CcnxForwardingStrategy> GetForwardingStrategy (void) const; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 90 | |
| 91 | /** |
| 92 | * Lower layer calls this method after calling L3Demux::Lookup |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 93 | * |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 94 | * \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 Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 101 | void ReceiveFromLower (Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 102 | const Address &from, |
| 103 | const Address &to, |
| 104 | NetDevice::PacketType packetType); |
| 105 | |
| 106 | /** |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 107 | * Actual processing of incoming CCNx packets. Also processing packets coming from local apps |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 108 | * |
| 109 | * Processing Interest packets |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 110 | */ |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 111 | 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 Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 122 | |
| 123 | /** |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 124 | * \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 Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 130 | virtual void Send (Ptr<Packet> packet, Ptr<CcnxRoute> route); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 131 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 132 | virtual uint32_t AddFace (Ptr<CcnxFace> face); |
| 133 | virtual uint32_t GetNFaces (void) const; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 134 | virtual Ptr<CcnxFace> GetFace (uint32_t face) const; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 135 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 136 | 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 Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 142 | |
| 143 | protected: |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 144 | 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 Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 150 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 151 | private: |
| 152 | // friend class CcnxL3ProtocolTestCase; |
| 153 | CcnxL3Protocol(const CcnxL3Protocol &); |
| 154 | CcnxL3Protocol &operator = (const CcnxL3Protocol &); |
| 155 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 156 | /** |
| 157 | * Helper function to get CcnxFace from NetDevice |
| 158 | */ |
| 159 | Ptr<CcnxFace> GetFaceForDevice (Ptr<const NetDevice> device) const; |
| 160 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 161 | void RouteInputError (Ptr<Packet> p); |
| 162 | //, Socket::SocketErrno sockErrno); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 163 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 164 | /** |
| 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 Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 170 | private: |
| 171 | typedef std::vector<Ptr<CcnxFace> > CcnxFaceList; |
| 172 | CcnxFaceList m_faces; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 173 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 174 | Ptr<Node> m_node; |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 175 | Ptr<CcnxForwardingStrategy> m_forwardingStrategy; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 176 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 177 | 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 Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 180 | |
| 181 | // The following two traces pass a packet with an IP header |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 182 | TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_txTrace; |
| 183 | TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_rxTrace; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 184 | // <ip-header, payload, reason, ifindex> (ifindex not valid if reason is DROP_NO_ROUTE) |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 185 | TracedCallback<Ptr<const Packet>, DropReason, Ptr<const Ccnx>, Ptr<const CcnxFace> > m_dropTrace; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 186 | }; |
| 187 | |
| 188 | } // Namespace ns3 |
| 189 | |
| 190 | #endif /* CCNX_L3_PROTOCOL_H */ |