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 | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2011 University of California, Los Angeles |
| 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 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 | /** |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 46 | * \ingroup ccnx |
| 47 | * \brief Actual implementation of the Ccnx network layer |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 48 | * |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 49 | * \todo This description is incorrect. Should be changed accordingly |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 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: |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 64 | /** |
| 65 | * \brief Interface ID |
| 66 | * |
| 67 | * \return interface ID |
| 68 | */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 69 | static TypeId GetTypeId (void); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 70 | |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 71 | static const uint16_t ETHERNET_FRAME_TYPE; ///< \brief Ethernet Frame Type of CCNx |
| 72 | static const uint16_t IP_PROTOCOL_TYPE; ///< \brief IP protocol type of CCNx |
| 73 | static const uint16_t UDP_PORT; ///< \brief UDP port of CCNx |
| 74 | |
| 75 | /** |
| 76 | * \brief Default constructor. Creates an empty stack without forwarding strategy set |
| 77 | */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 78 | CcnxL3Protocol(); |
| 79 | virtual ~CcnxL3Protocol (); |
| 80 | |
| 81 | /** |
| 82 | * \enum DropReason |
| 83 | * \brief Reason why a packet has been dropped. |
| 84 | */ |
| 85 | enum DropReason |
| 86 | { |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 87 | /** \todo Fill reasons from QualNet code */ |
| 88 | DROP_DUPLICATE_INTEREST=1, /**< Duplicate Interest */ |
| 89 | DROP_CONGESTION, /**< Congestion detected */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 90 | DROP_NO_ROUTE, /**< No route to host */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 91 | DROP_INTERFACE_DOWN, /**< Interface is down so can not send packet */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 94 | /** |
| 95 | * \brief Assigns node to the CCNx stack |
| 96 | * |
| 97 | * \param node Simulation node |
| 98 | */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 99 | void SetNode (Ptr<Node> node); |
| 100 | |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 101 | //////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 102 | // functions defined in base class Ccnx |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 103 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 104 | void SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy); |
| 105 | Ptr<CcnxForwardingStrategy> GetForwardingStrategy (void) const; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 106 | |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 107 | virtual void Send (Ptr<Packet> packet, const Ptr<CcnxFace> &face); |
| 108 | |
| 109 | virtual uint32_t AddFace (const Ptr<CcnxFace> &face); |
| 110 | virtual uint32_t GetNFaces (void) const; |
| 111 | virtual Ptr<CcnxFace> GetFace (uint32_t face) const; |
| 112 | |
| 113 | virtual void SetMetric (uint32_t i, uint16_t metric); |
| 114 | virtual uint16_t GetMetric (uint32_t i) const; |
| 115 | virtual uint16_t GetMtu (uint32_t i) const; |
| 116 | virtual bool IsUp (uint32_t i) const; |
| 117 | virtual void SetUp (uint32_t i); |
| 118 | virtual void SetDown (uint32_t i); |
| 119 | |
| 120 | protected: |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 121 | /** |
| 122 | * Lower layer calls this method after calling L3Demux::Lookup |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 123 | * |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 124 | * \param device network device |
| 125 | * \param p the packet |
| 126 | * \param protocol lower layer protocol value |
| 127 | * \param from lower layer address of the correspondant |
| 128 | * \param to lower layer address of the destination |
| 129 | * \param packetType type of the packet (broadcast/multicast/unicast/otherhost) |
| 130 | */ |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 131 | void ReceiveFromLower (Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 132 | const Address &from, |
| 133 | const Address &to, |
| 134 | NetDevice::PacketType packetType); |
| 135 | |
| 136 | /** |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 137 | * 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] | 138 | * |
| 139 | * Processing Interest packets |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 140 | */ |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 141 | virtual void |
| 142 | ReceiveAndProcess (Ptr<CcnxFace> face, Ptr<CcnxInterestHeader> header, Ptr<Packet> p); |
| 143 | |
| 144 | |
| 145 | /** |
| 146 | * Actual processing of incoming CCNx packets. Also processing packets coming from local apps |
| 147 | * |
| 148 | * Processing ContentObject packets |
| 149 | */ |
| 150 | virtual void |
| 151 | ReceiveAndProcess (Ptr<CcnxFace> face, Ptr<CcnxContentObjectHeader> header, Ptr<Packet> p); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 152 | |
| 153 | protected: |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 154 | virtual void DoDispose (void); |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 155 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 156 | /** |
| 157 | * This function will notify other components connected to the node that a new stack member is now connected |
| 158 | * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together. |
| 159 | */ |
| 160 | virtual void NotifyNewAggregate (); |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 161 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 162 | private: |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 163 | CcnxL3Protocol(const CcnxL3Protocol &); ///< copy constructor is disabled |
| 164 | CcnxL3Protocol &operator = (const CcnxL3Protocol &); ///< copy operator is disabled |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 165 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 166 | /** |
| 167 | * Helper function to get CcnxFace from NetDevice |
| 168 | */ |
| 169 | Ptr<CcnxFace> GetFaceForDevice (Ptr<const NetDevice> device) const; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 170 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 171 | /** |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 172 | * \brief Fake function. should never be called. Just to trick C++ to compile |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 173 | */ |
| 174 | virtual void |
| 175 | ReceiveAndProcess (Ptr<CcnxFace> face, Ptr<Header> header, Ptr<Packet> p); |
| 176 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 177 | private: |
| 178 | typedef std::vector<Ptr<CcnxFace> > CcnxFaceList; |
| 179 | CcnxFaceList m_faces; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 180 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 181 | Ptr<Node> m_node; |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 182 | Ptr<CcnxForwardingStrategy> m_forwardingStrategy; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 183 | |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 184 | // TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_sendOutgoingTrace; |
| 185 | // TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_unicastForwardTrace; |
| 186 | // TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_localDeliverTrace; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 187 | |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 188 | // // The following two traces pass a packet with an IP header |
| 189 | // TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_txTrace; |
| 190 | // TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_rxTrace; |
| 191 | // // <ip-header, payload, reason, ifindex> (ifindex not valid if reason is DROP_NO_ROUTE) |
| 192 | // 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] | 193 | }; |
| 194 | |
| 195 | } // Namespace ns3 |
| 196 | |
| 197 | #endif /* CCNX_L3_PROTOCOL_H */ |