blob: 6a76531fb934af91dc25699e663a196fb6223541 [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev98256102011-08-14 01:00:02 -07002/*
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 Afanasyevc74a6022011-08-15 20:01:35 -070018#ifndef CCNX_FORWARDING_STRATEGY_H
19#define CCNX_FORWARDING_STRATEGY_H
Alexander Afanasyev98256102011-08-14 01:00:02 -070020
21#include "ns3/packet.h"
22#include "ns3/callback.h"
23#include "ns3/object.h"
24#include "ns3/socket.h"
Alexander Afanasyev98256102011-08-14 01:00:02 -070025#include "ns3/output-stream-wrapper.h"
26
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070027#include "ccnx.h"
28
Alexander Afanasyev98256102011-08-14 01:00:02 -070029namespace ns3 {
30
31class CcnxRoute;
32class CcnxFace;
33
34/**
35 * \ingroup internet
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070036 * \defgroup ccnxForwarding CcnxForwardingStrategy
Alexander Afanasyev98256102011-08-14 01:00:02 -070037 */
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 Afanasyevc74a6022011-08-15 20:01:35 -070048class CcnxForwardingStrategy : public Object
Alexander Afanasyev98256102011-08-14 01:00:02 -070049{
50public:
51 static TypeId GetTypeId (void);
52
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070053 typedef Callback<void, Ptr<Packet>, Ptr<CcnxRoute> > SendCallback;
54 typedef Callback<void, Ptr<Packet>/*, Socket::SocketErrno*/ > ErrorCallback;
Alexander Afanasyev98256102011-08-14 01:00:02 -070055
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 Afanasyevc74a6022011-08-15 20:01:35 -070078 * handed over to the CcnxForwardingStrategy, and will get forwarded onward
Alexander Afanasyev98256102011-08-14 01:00:02 -070079 * 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 Afanasyevc74a6022011-08-15 20:01:35 -070087 * \returns true if the CcnxForwardingStrategy takes responsibility for
Alexander Afanasyev98256102011-08-14 01:00:02 -070088 * forwarding or delivering the packet, false otherwise
89 */
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070090 virtual bool RouteInput (Ptr<Packet> p, Ptr<CcnxFace> iface,
Alexander Afanasyev98256102011-08-14 01:00:02 -070091 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 Afanasyev45b92d42011-08-14 23:11:38 -0700108
109 // Should be modified to notify about new prefixes ?
110
Alexander Afanasyev98256102011-08-14 01:00:02 -0700111 /**
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 Afanasyev45b92d42011-08-14 23:11:38 -0700119 // virtual void NotifyAddAddress (uint32_t interface, CcnxInterfaceAddress address) = 0;
Alexander Afanasyev98256102011-08-14 01:00:02 -0700120
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 Afanasyev45b92d42011-08-14 23:11:38 -0700129 // virtual void NotifyRemoveAddress (uint32_t interface, CcnxInterfaceAddress address) = 0;
Alexander Afanasyev98256102011-08-14 01:00:02 -0700130
131 /**
132 * \param ccnx the ccnx object this forwarding protocol is being associated with
133 *
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700134 * Typically, invoked directly or indirectly from ns3::Ccnx::SetForwardingStrategy
Alexander Afanasyev98256102011-08-14 01:00:02 -0700135 */
136 virtual void SetCcnx (Ptr<Ccnx> ccnx);
137
138 virtual void PrintForwardingTable (Ptr<OutputStreamWrapper> stream) const = 0;
139
140protected:
141 Ptr<Ccnx> m_ccnx;
142};
143
144} //namespace ns3
145
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700146#endif /* CCNX_FORWARDING_STRATEGY_H */