blob: 75b67ea4552980452f523588dd1a098b1a885952 [file] [log] [blame]
Alexander Afanasyev6315ef72012-06-01 20:56:31 -07001ndnSIM applications
2===================
3
4ndnSIM includes a few reference applications that can be used as a base for NDN simulations.
5
6Reference applications
7++++++++++++++++++++++
8
9CcnxConsumerCbr
10^^^^^^^^^^^^^^^
11
12:ndnsim:`CcnxConsumerCbr` an application that generates Interest traffic with predefined pattern (constant frequency, constant average rate with inter-Interest gap distributed uniformly at random, exponentially at random, etc.).
13
14.. code-block:: c++
15
16 // Create application using the app helper
17 CcnxAppHelper helper ("ns3::CcnxConsumerCbr");
18
19This applications has the following attributes:
20
21* Frequency
22
23 .. note::
24 default: ``1.0`` (1 per second)
25
26 Either exact (for contant version) or expected (for randomized version) frequency with which Interests are generated
27
28 .. code-block:: c++
29
30 // Set attribute using the app helper
31 helper.SetAttribute ("Frequency", DoubleValue (1.0));
32
33* Randomize
34
35 .. note::
36 default: ``"none"``
37
38 Specify whether to do randomization for inter-Interest gap or not. The following variants are currently supported:
39
40 - ``"none"``: no randomization
41
42 - ``"uniform"``: uniform distribution in range (0, 1/Frequency)
43
44 - ``"exponential"``: exponential distribution with mean 1/Frequency
45
46 .. code-block:: c++
47
48 // Set attribute using the app helper
49 helper.SetAttribute ("Randomize", StringValue ("uniform"));
50
51CcnxConsumerBatches
52^^^^^^^^^^^^^^^^^^^
53
54:ndnsim:`CcnxConsumerBatches` is an on-off-style application gen- erating a specified number of Interests at specified points of simulation.
55
56.. code-block:: c++
57
58 // Create application using the app helper
59 CcnxAppHelper consumerHelper ("ns3::CcnxConsumerBatches");
60
61This applications has the following attributes:
62
63* Batches
64
65 .. note::
66 default: Empty
67
68 Specify exact pattern of Interest packets, specifying when and how many Interest packets should be sent.
69 The following example defines that 1 Interest should be requested at time 1s, 5 Interests at time 5s, and 2 Interests at time 10s.:
70
71 .. code-block:: c++
72
73 // Set attribute using the app helper
74 helper.SetAttribute ("Batches", StringValue ("1s 1 2s 5 10s 2"));
75
76
77CcnxConsumerWindow
78^^^^^^^^^^^^^^^^^^
79
80:ndnsim:`CcnxConsumerWindow` is an application generating a variable rate Interest traffic. It relies on an optional NACK-Interest feature and implements a simple sliding-window-based Interest generation mecha- nism.
81
82.. code-block:: c++
83
84 // Create application using the app helper
85 CcnxAppHelper consumerHelper ("ns3::CcnxConsumerWindow");
86
87
88This applications has the following attributes:
89
90* Window
91
92 .. note::
93 default: ``1``
94
95 Initial number of Interests that will be send out without waiting for the data (number of outstanding Interests)
96
97* PayloadSize
98
99 .. note::
100 default: ``1040``
101
102 Expected size of the Data payload (necessary only when Size is specified)
103
104* Size
105
106 .. note::
107 default: ``-1``
108
109 Amount of data to be requested (will stop issuing Interests after ``Size`` data is received)
110
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700111 If ``Size`` is set to -1, Interests will be requested till the end of the simulation.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700112
113CcnxProducer
114^^^^^^^^^^^^
115
116:ndnsim:`CcnxProducer` a simple Interest-sink application, which replying every incoming Interest with Data packet with a specified size and name same as in Interest.
117
118.. code-block:: c++
119
120 // Create application using the app helper
121 CcnxAppHelper consumerHelper ("ns3::CcnxProducer");
122
123
124Custom applications
125+++++++++++++++++++
126
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700127Applications interact with the core of the system using :ndnsim:`CcnxLocalFace` realization of Face abstraction.
128To simplify implementation of specific NDN application, ndnSIM provides a base :ndnsim:`CcnxApp` class that takes care of creating :ndnsim:`CcnxLocalFace` and registering it inside the NDN protocol stack, as well as provides default processing for incoming Interest and Data packets.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700129
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700130.. Base CcnxApp class
131.. ^^^^^^^^^^^^^^^^^^
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700132
133
134
135Example
136^^^^^^^
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700137
138The following code shows how a simple ndnSIM application can be created. For details refer to API documentation of ndnSIM and NS-3.
139
140.. code-block:: c++
141
142 class CustomApp : public CcnxApp
143 {
144 public:
145 // overridden from CcnxApp
146
147 // Processing upon start of the application
148 virtual void
149 StartApplication ()
150 {
151 // initialize CcnxApp
152 CcnxApp::StartApplication ();
153
154 // Create a name components object for name ``/prefix/sub``
155 Ptr<CcnxNameComponents> prefix = Create<CcnxNameComponents> (); // now prefix contains ``/``
156 prefix->Add ("prefix"); // now prefix contains ``/prefix``
157 prefix->Add ("sub"); // now prefix contains ``/prefix/sub``
158
159 /////////////////////////////////////////////////////////////////////////////
160 // Creating FIB entry that ensures that we will receive incoming Interests //
161 /////////////////////////////////////////////////////////////////////////////
162
163 // Get FIB object
164 Ptr<CcnxFib> fib = GetNode ()->GetObject<CcnxFib> ();
165
166 // Add entry to FIB
167 // Note that ``m_face`` is cretaed by CcnxApp
168 CcnxFibEntryContainer::type::iterator fibEntry = fib->Add (*prefix, m_face, 0);
169
170 /////////////////////////////////////
171 // Sending one Interest packet out //
172 /////////////////////////////////////
173
174 // Create and configure CcnxInterestHeader
175 CcnxInterestHeader interestHeader;
176 UniformVariable rand (0,std::numeric_limits<uint32_t>::max ());
177 interestHeader.SetNonce (rand.GetValue ());
178 interestHeader.SetName (prefix);
179 interestHeader.SetInterestLifetime (Seconds (1.0));
180
181 // Create packet and add CcnxInterestHeader
182 Ptr<Packet> packet = Create<Packet> ();
183 packet->AddHeader (interestHeader);
184
185 // Forward packet to lower (network) layer
186 m_protocolHandler (packet);
187
188 // Call trace (for logging purposes)
189 m_transmittedInterests (&interestHeader, this, m_face);
190 }
191
192 // Processing when application is stopped
193 virtual void
194 StopApplication ()
195 {
196 // cleanup CcnxApp
197 CcnxApp::StopApplication ();
198 }
199
200 // Callback that will be called when Interest arrives
201 virtual void
202 OnInterest (const Ptr<const CcnxInterestHeader> &interest, Ptr<Packet> packet)
203 {
204 // Create and configure CcnxContentObjectHeader and CcnxContentObjectTail
205 // (header is added in front of the packet, tail is added at the end of the packet)
206
207 CcnxContentObjectHeader data;
208 data.SetName (Create<CcnxNameComponents> (interest->GetName ())); // data will have the same name as Interests
209
210 CcnxContentObjectTail trailer; // doesn't require any configuration
211
212 // Create packet and add header and trailer
213 Ptr<Packet> packet = Create<Packet> (1024);
214 packet->AddHeader (data);
215 packet->AddTrailer (trailer);
216
217 // Forward packet to lower (network) layer
218 m_protocolHandler (packet);
219
220 // Call trace (for logging purposes)
221 m_transmittedInterests (&interestHeader, this, m_face);
222 m_transmittedContentObjects (&data, packet, this, m_face);
223 }
224
225 // Callback that will be called when Data arrives
226 virtual void
227 OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject,
228 Ptr<Packet> payload)
229 {
230 std::cout << "DATA received for name " << contentObject->GetName () << std::endl;
231 }
232 };