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