Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2009 University of Washington |
| 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 | #ifndef CCNX_FORWARDING_PROTOCOL_H |
| 19 | #define CCNX_FORWARDING_PROTOCOL_H |
| 20 | |
| 21 | #include "ns3/packet.h" |
| 22 | #include "ns3/callback.h" |
| 23 | #include "ns3/object.h" |
| 24 | #include "ns3/socket.h" |
| 25 | #include "ccnx-header.h" |
| 26 | #include "ns3/ccnx-interface-address.h" |
| 27 | #include "ccnx.h" |
| 28 | #include "ns3/output-stream-wrapper.h" |
| 29 | |
| 30 | namespace ns3 { |
| 31 | |
| 32 | class CcnxRoute; |
| 33 | class CcnxFace; |
| 34 | |
| 35 | /** |
| 36 | * \ingroup internet |
| 37 | * \defgroup ccnxForwarding CcnxForwardingProtocol |
| 38 | */ |
| 39 | /** |
| 40 | * \ingroup ccnxForwarding |
| 41 | * \brief Abstract base class for Ccnx forwarding protocols. |
| 42 | * |
| 43 | * Defines two virtual functions for packet forwarding and forwarding. The first, |
| 44 | * RouteOutput(), is used for locally originated packets, and the second, |
| 45 | * RouteInput(), is used for forwarding and/or delivering received packets. |
| 46 | * Also defines the signatures of four callbacks used in RouteInput(). |
| 47 | * |
| 48 | */ |
| 49 | class CcnxForwardingProtocol : public Object |
| 50 | { |
| 51 | public: |
| 52 | static TypeId GetTypeId (void); |
| 53 | |
| 54 | typedef Callback<void, Ptr<const Packet>, Ptr<CcnxRoute> > SendCallback; |
| 55 | typedef Callback<void, Ptr<const Packet>, Socket::SocketErrno > ErrorCallback; |
| 56 | |
| 57 | /** |
| 58 | * \brief Query forwarding cache for an existing route, for an outbound packet |
| 59 | // * |
| 60 | // * This lookup is used by transport protocols. It does not cause any |
| 61 | // * packet to be forwarded, and is synchronous. Can be used for |
| 62 | // * multicast or unicast. The Linux equivalent is ip_route_output() |
| 63 | // * |
| 64 | // * \param p packet to be routed. Note that this method may modify the packet. |
| 65 | // * Callers may also pass in a null pointer. |
| 66 | // * \param header input parameter (used to form key to search for the route) |
| 67 | // * \param oif Output interface Netdevice. May be zero, or may be bound via |
| 68 | // * socket options to a particular output interface. |
| 69 | // * \param sockerr Output parameter; socket errno |
| 70 | // * |
| 71 | // * \returns a code that indicates what happened in the lookup |
| 72 | // */ |
| 73 | // virtual Ptr<CcnxRoute> RouteOutput (Ptr<Packet> p, const CcnxHeader &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) = 0; |
| 74 | |
| 75 | /** |
| 76 | * \brief Route an input packet (to be forwarded or locally delivered) |
| 77 | * |
| 78 | * This lookup is used in the forwarding process. The packet is |
| 79 | * handed over to the CcnxForwardingProtocol, and will get forwarded onward |
| 80 | * by one of the callbacks. The Linux equivalent is ip_route_input(). |
| 81 | * There are four valid outcomes, and a matching callbacks to handle each. |
| 82 | * |
| 83 | * \param p received packet |
| 84 | * \param header input parameter used to form a search key for a route |
| 85 | * \param iface Pointer to ingress face |
| 86 | * \param ucb Callback for the case in which the packet is to be forwarded |
| 87 | * \param ecb Callback to call if there is an error in forwarding |
| 88 | * \returns true if the CcnxForwardingProtocol takes responsibility for |
| 89 | * forwarding or delivering the packet, false otherwise |
| 90 | */ |
| 91 | virtual bool RouteInput (Ptr<const Packet> p, Ptr<const CcnxFace> iface, |
| 92 | SendCallback ucb, ErrorCallback ecb) = 0; |
| 93 | |
| 94 | /** |
| 95 | * \param interface the index of the interface we are being notified about |
| 96 | * |
| 97 | * Protocols are expected to implement this method to be notified of the state change of |
| 98 | * an interface in a node. |
| 99 | */ |
| 100 | virtual void NotifyInterfaceUp (uint32_t interface) = 0; |
| 101 | /** |
| 102 | * \param interface the index of the interface we are being notified about |
| 103 | * |
| 104 | * Protocols are expected to implement this method to be notified of the state change of |
| 105 | * an interface in a node. |
| 106 | */ |
| 107 | virtual void NotifyInterfaceDown (uint32_t interface) = 0; |
| 108 | |
| 109 | /** |
| 110 | * \param interface the index of the interface we are being notified about |
| 111 | * \param address a new address being added to an interface |
| 112 | * |
| 113 | * Protocols are expected to implement this method to be notified whenever |
| 114 | * a new address is added to an interface. Typically used to add a 'network route' on an |
| 115 | * interface. Can be invoked on an up or down interface. |
| 116 | */ |
| 117 | virtual void NotifyAddAddress (uint32_t interface, CcnxInterfaceAddress address) = 0; |
| 118 | |
| 119 | /** |
| 120 | * \param interface the index of the interface we are being notified about |
| 121 | * \param address a new address being added to an interface |
| 122 | * |
| 123 | * Protocols are expected to implement this method to be notified whenever |
| 124 | * a new address is removed from an interface. Typically used to remove the 'network route' of an |
| 125 | * interface. Can be invoked on an up or down interface. |
| 126 | */ |
| 127 | virtual void NotifyRemoveAddress (uint32_t interface, CcnxInterfaceAddress address) = 0; |
| 128 | |
| 129 | /** |
| 130 | * \param ccnx the ccnx object this forwarding protocol is being associated with |
| 131 | * |
| 132 | * Typically, invoked directly or indirectly from ns3::Ccnx::SetForwardingProtocol |
| 133 | */ |
| 134 | virtual void SetCcnx (Ptr<Ccnx> ccnx); |
| 135 | |
| 136 | virtual void PrintForwardingTable (Ptr<OutputStreamWrapper> stream) const = 0; |
| 137 | |
| 138 | protected: |
| 139 | Ptr<Ccnx> m_ccnx; |
| 140 | }; |
| 141 | |
| 142 | } //namespace ns3 |
| 143 | |
| 144 | #endif /* CCNX_FORWARDING_PROTOCOL_H */ |