blob: 20d92a452ba607f6a8ae3ce4ebf6b2661d3f3ba2 [file] [log] [blame]
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
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 * Ilya Moiseenko <iliamo@cs.ucla.edu>
20 */
21#ifndef CCNX_FORWARDING_STRATEGY_H
22#define CCNX_FORWARDING_STRATEGY_H
23
24#include "ns3/packet.h"
25#include "ns3/callback.h"
26#include "ns3/object.h"
27#include "ns3/traced-callback.h"
28
29namespace ns3 {
30
31class CcnxFace;
32class CcnxInterestHeader;
33class CcnxContentObjectHeader;
34class CcnxPit;
35class CcnxPitEntry;
36class CcnxFibFaceMetric;
37class CcnxFib;
38class CcnxContentStore;
39
40/**
41 * \ingroup ccnx
42 * \brief Abstract base class for CCNx forwarding strategies
43 */
44class CcnxForwardingStrategy : public Object
45{
46public:
47 static TypeId GetTypeId (void);
48
49 /**
50 * @brief Default constructor
51 */
52 CcnxForwardingStrategy ();
53 virtual ~CcnxForwardingStrategy ();
54
55 /**
56 * \brief Actual processing of incoming CCNx interests. Note, interests do not have payload
57 *
58 * Processing Interest packets
59 * @param face incoming face
60 * @param header deserialized Interest header
61 * @param packet original packet
62 */
63 virtual void
64 OnInterest (const Ptr<CcnxFace> &face,
65 Ptr<CcnxInterestHeader> &header,
66 const Ptr<const Packet> &p);
67
68 /**
69 * \brief Actual processing of incoming CCNx content objects
70 *
71 * Processing ContentObject packets
72 * @param face incoming face
73 * @param header deserialized ContentObject header
74 * @param payload data packet payload
75 * @param packet original packet
76 */
77 virtual void
78 OnData (const Ptr<CcnxFace> &face,
79 Ptr<CcnxContentObjectHeader> &header,
80 Ptr<Packet> &payload,
81 const Ptr<const Packet> &packet);
82
83// protected:
84 /**
85 * @brief Base method to propagate the interest according to the forwarding strategy
86 *
87 * @param pitEntry Reference to PIT entry (reference to corresponding FIB entry inside)
88 * @param incomingFace Incoming face
89 * @param header CcnxInterestHeader
90 * @param packet Original Interest packet
91 * @param sendCallback Send callback
92 *
93 * @return true if interest was successfully propagated, false if all options have failed
94 */
95 virtual bool
96 PropagateInterest (Ptr<CcnxPitEntry> pitEntry,
97 const Ptr<CcnxFace> &incomingFace,
98 Ptr<CcnxInterestHeader> &header,
99 const Ptr<const Packet> &packet) = 0;
100
101protected:
102 /**
103 * @brief Propagate interest via a green interface. Fail, if no green interfaces available
104 *
105 * @param pitEntry Reference to PIT entry (reference to corresponding FIB entry inside)
106 * @param incomingFace Incoming face
107 * @param header CcnxInterestHeader
108 * @param packet Original Interest packet
109 * @param sendCallback Send callback
110 * @return true if interest was successfully propagated, false if all options have failed
111 *
112 * \see PropagateInterest
113 */
114 bool
115 PropagateInterestViaGreen (Ptr<CcnxPitEntry> pitEntry,
116 const Ptr<CcnxFace> &incomingFace,
117 Ptr<CcnxInterestHeader> &header,
118 const Ptr<const Packet> &packet);
119
120 virtual void
121 GiveUpInterest (Ptr<CcnxPitEntry> pitEntry,
122 Ptr<CcnxInterestHeader> header);
123
124 virtual void
125 OnDataDelayed (Ptr<const CcnxContentObjectHeader> header,
126 Ptr<const Packet> payload,
127 const Ptr<const Packet> &packet);
128
129protected:
130 // inherited from Object class
131 virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object
132 virtual void DoDispose (); ///< @brief Do cleanup
133
134protected:
135 Ptr<CcnxPit> m_pit; ///< \brief Reference to PIT to which this forwarding strategy is associated
136 Ptr<CcnxFib> m_fib; ///< \brief FIB
137 Ptr<CcnxContentStore> m_contentStore; ///< \brief Content store (for caching purposes only)
138
139 bool m_nacksEnabled;
140 bool m_cacheUnsolicitedData;
141
142 // transmittedInterestTrace is inside ForwardingStrategy
143
144
145 TracedCallback<Ptr<const CcnxInterestHeader>,
146 Ptr<const CcnxFace> > m_outInterests; ///< @brief Transmitted interests trace
147
148 TracedCallback<Ptr<const CcnxInterestHeader>,
149 Ptr<const CcnxFace> > m_inInterests; ///< @brief trace of incoming Interests
150
151 TracedCallback<Ptr<const CcnxInterestHeader>,
152 Ptr<const CcnxFace> > m_dropInterests; ///< @brief trace of dropped Interests
153
154 ////////////////////////////////////////////////////////////////////
155 ////////////////////////////////////////////////////////////////////
156 ////////////////////////////////////////////////////////////////////
157
158 TracedCallback<Ptr<const CcnxInterestHeader>,
159 Ptr<const CcnxFace> > m_outNacks; ///< @brief trace of outgoing NACKs
160
161 TracedCallback<Ptr<const CcnxInterestHeader>,
162 Ptr<const CcnxFace> > m_inNacks; ///< @brief trace of incoming NACKs
163
164 TracedCallback<Ptr<const CcnxInterestHeader>,
165 Ptr<const CcnxFace> > m_dropNacks; ///< @brief trace of dropped NACKs
166
167 ////////////////////////////////////////////////////////////////////
168 ////////////////////////////////////////////////////////////////////
169 ////////////////////////////////////////////////////////////////////
170
171 TracedCallback<Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>,
172 bool /*from cache*/,
173 Ptr<const CcnxFace> > m_outData; ///< @brief trace of outgoing Data
174
175 TracedCallback<Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>,
176 Ptr<const CcnxFace> > m_inData; ///< @brief trace of incoming Data
177
178 TracedCallback<Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>,
179 Ptr<const CcnxFace> > m_dropData; ///< @brief trace of dropped Data
180};
181
182} //namespace ns3
183
184#endif /* CCNX_FORWARDING_STRATEGY_H */