Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -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 | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 40 | class CcnxForwardingProtocol; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 41 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 42 | /** |
| 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 | */ |
| 58 | class CcnxL3Protocol : public Ccnx |
| 59 | { |
| 60 | public: |
| 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 Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 73 | /** \todo Fill reasons from QualNet code */ |
| 74 | DROP_DUPLICATE_INTEREST=1, /**< Duplicate Interest */ |
| 75 | DROP_CONGESTION, /**< Congestion detected */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 76 | DROP_NO_ROUTE, /**< No route to host */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 77 | 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 Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 84 | |
| 85 | void SetForwardingProtocol (Ptr<CcnxForwardingProtocol> forwardingProtocol); |
| 86 | Ptr<CcnxForwardingProtocol> GetForwardingProtocol (void) const; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 87 | |
| 88 | /** |
| 89 | * Lower layer calls this method after calling L3Demux::Lookup |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 90 | * |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 91 | * \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 Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame^] | 98 | void ReceiveFromLower (Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 99 | const Address &from, |
| 100 | const Address &to, |
| 101 | NetDevice::PacketType packetType); |
| 102 | |
| 103 | /** |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 104 | * Actual processing of incoming CCNx packets. Also processing packets coming from local apps |
| 105 | */ |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame^] | 106 | void ReceiveAndProcess (Ptr<CcnxFace> face, Ptr<Packet> p); |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 107 | |
| 108 | /** |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 109 | * \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 Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 115 | virtual void Send (Ptr<Packet> packet, Ptr<CcnxRoute> route); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 116 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 117 | virtual uint32_t AddFace (Ptr<CcnxFace> face); |
| 118 | virtual uint32_t GetNFaces (void) const; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame^] | 119 | virtual Ptr<CcnxFace> GetFace (uint32_t face) const; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 120 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 121 | 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 Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 127 | |
| 128 | protected: |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 129 | 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 Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 135 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 136 | private: |
| 137 | // friend class CcnxL3ProtocolTestCase; |
| 138 | CcnxL3Protocol(const CcnxL3Protocol &); |
| 139 | CcnxL3Protocol &operator = (const CcnxL3Protocol &); |
| 140 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 141 | /** |
| 142 | * Helper function to get CcnxFace from NetDevice |
| 143 | */ |
| 144 | Ptr<CcnxFace> GetFaceForDevice (Ptr<const NetDevice> device) const; |
| 145 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame^] | 146 | void RouteInputError (Ptr<Packet> p); |
| 147 | //, Socket::SocketErrno sockErrno); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 148 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 149 | private: |
| 150 | typedef std::vector<Ptr<CcnxFace> > CcnxFaceList; |
| 151 | CcnxFaceList m_faces; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 152 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 153 | Ptr<Node> m_node; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame^] | 154 | Ptr<CcnxForwardingProtocol> m_forwardingProtocol; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 155 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame^] | 156 | 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 Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 159 | |
| 160 | // The following two traces pass a packet with an IP header |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame^] | 161 | TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_txTrace; |
| 162 | TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_rxTrace; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 163 | // <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^] | 164 | 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] | 165 | }; |
| 166 | |
| 167 | } // Namespace ns3 |
| 168 | |
| 169 | #endif /* CCNX_L3_PROTOCOL_H */ |