OLD | NEW |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2008 INRIA | 3 * Copyright (c) 2008 INRIA |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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 | 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 | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> | 18 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
19 */ | 19 */ |
20 | 20 |
21 #ifndef INTERNET_STACK_HELPER_H | 21 #ifndef INTERNET_STACK_HELPER_H |
22 #define INTERNET_STACK_HELPER_H | 22 #define INTERNET_STACK_HELPER_H |
23 | 23 |
24 #include "node-container.h" | 24 #include "node-container.h" |
25 #include "net-device-container.h" | 25 #include "net-device-container.h" |
26 #include "ns3/packet.h" | 26 #include "ns3/packet.h" |
27 #include "ns3/ptr.h" | 27 #include "ns3/ptr.h" |
28 #include "ns3/object-factory.h" | 28 #include "ns3/object-factory.h" |
29 #include "ns3/pcap-writer.h" | |
30 #include "ns3/ascii-writer.h" | |
31 #include "ns3/ipv4-l3-protocol.h" | 29 #include "ns3/ipv4-l3-protocol.h" |
32 #include "ns3/ipv6-l3-protocol.h" | 30 #include "ns3/ipv6-l3-protocol.h" |
| 31 #include "trace-helper.h" |
33 | 32 |
34 namespace ns3 { | 33 namespace ns3 { |
35 | 34 |
36 class Node; | 35 class Node; |
37 class Ipv4RoutingHelper; | 36 class Ipv4RoutingHelper; |
38 class Ipv6RoutingHelper; | 37 class Ipv6RoutingHelper; |
39 | 38 |
40 /** | 39 /** |
41 * \brief aggregate IP/TCP/UDP functionality to existing Nodes. | 40 * \brief aggregate IP/TCP/UDP functionality to existing Nodes. |
| 41 * |
| 42 * This helper enables pcap and ascii tracing of events in the internet stack |
| 43 * associated with a node. This is substantially similar to the tracing |
| 44 * that happens in device helpers, but the important difference is that, well, |
| 45 * there is no device. This means that the creation of output file names will |
| 46 * change, and also the user-visible methods will not reference devices and |
| 47 * therefore the number of trace enable methods is reduced. |
| 48 * |
| 49 * Normally we eschew multiple inheritance, however, the classes· |
| 50 * PcapUserHelperForIpv4 and AsciiTraceUserHelperForIpv4 are |
| 51 * treated as "mixins". A mixin is a self-contained class that |
| 52 * encapsulates a general attribute or a set of functionality that |
| 53 * may be of interest to many other classes. |
42 */ | 54 */ |
43 class InternetStackHelper | 55 class InternetStackHelper : public TraceHelperForProtocol |
44 { | 56 { |
45 public: | 57 public: |
46 /** | 58 /** |
47 * Create a new InternetStackHelper which uses a mix of static routing | 59 * Create a new InternetStackHelper which uses a mix of static routing |
48 * and global routing by default. The static routing protocol· | 60 * and global routing by default. The static routing protocol· |
49 * (ns3::Ipv4StaticRouting) and the global routing protocol are | 61 * (ns3::Ipv4StaticRouting) and the global routing protocol are |
50 * stored in an ns3::Ipv4ListRouting protocol with priorities 0, and -10 | 62 * stored in an ns3::Ipv4ListRouting protocol with priorities 0, and -10 |
51 * by default. If you wish to use different priorites and different | 63 * by default. If you wish to use different priorites and different |
52 * routing protocols, you need to use an adhoc ns3::Ipv4RoutingHelper,· | 64 * routing protocols, you need to use an adhoc ns3::Ipv4RoutingHelper,· |
53 * such as ns3::OlsrHelper | 65 * such as ns3::OlsrHelper |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 * be setup and val is its value. The attribute is the stack implementation· | 150 * be setup and val is its value. The attribute is the stack implementation· |
139 * to be used and the value is the shared library name. | 151 * to be used and the value is the shared library name. |
140 *· | 152 *· |
141 * \param tid The type id, for the case of nsc it would be "ns3::NscTcpL4Proto
col"· | 153 * \param tid The type id, for the case of nsc it would be "ns3::NscTcpL4Proto
col"· |
142 * \param attr The attribute name that must be setup, for example "Library" | 154 * \param attr The attribute name that must be setup, for example "Library" |
143 * \param val The attribute value, which will be in fact the shared library na
me (example:"liblinux2.6.26.so") | 155 * \param val The attribute value, which will be in fact the shared library na
me (example:"liblinux2.6.26.so") |
144 */ | 156 */ |
145 void SetTcp (std::string tid, std::string attr, const AttributeValue &val);· | 157 void SetTcp (std::string tid, std::string attr, const AttributeValue &val);· |
146 | 158 |
147 /** | 159 /** |
148 * \param os output stream | |
149 * \param n node container | |
150 * | |
151 * Enable ascii output on these drop traces, for each node in the NodeContaine
r.. | |
152 * /NodeList/[i]/$ns3ArpL3Protocol/Drop· | |
153 * /NodeList/[i]/$ns3Ipv4L3Protocol/Drop· | |
154 * /NodeList/[i]/$ns3Ipv6L3Protocol/Drop· | |
155 */ | |
156 static void EnableAscii (std::ostream &os, NodeContainer n); | |
157 | |
158 /** | |
159 * \param os output stream | |
160 * | |
161 * Enable ascii output on these drop traces, for all nodes. | |
162 * /NodeList/[i]/$ns3ArpL3Protocol/Drop· | |
163 * /NodeList/[i]/$ns3Ipv4L3Protocol/Drop· | |
164 * /NodeList/[i]/$ns3Ipv6L3Protocol/Drop· | |
165 */ | |
166 static void EnableAsciiAll (std::ostream &os); | |
167 | |
168 /** | |
169 * Enable pcap output on each protocol instance which is of the | |
170 * ns3::Ipv4L3Protocol or ns3::Ipv6L3Protocol type. Both Tx and· | |
171 * Rx events will be logged. | |
172 * | |
173 * \param filename filename prefix to use for pcap files. | |
174 * | |
175 * \warning If you perform multiple simulations in a single script, | |
176 * each iteration of the simulation will result in the trace files | |
177 * being overwritten. We don't attempt to anticipate what a user | |
178 * might actually want to do, so we leave it up to them. If you want | |
179 * to save any particular data, do so manually at inter-simulation· | |
180 * time. | |
181 */ | |
182 static void EnablePcapAll (std::string filename); | |
183 | |
184 /** | |
185 * \brief Enable/disable IPv4 stack install. | 160 * \brief Enable/disable IPv4 stack install. |
186 * \param enable enable state | 161 * \param enable enable state |
187 */ | 162 */ |
188 void SetIpv4StackInstall (bool enable); | 163 void SetIpv4StackInstall (bool enable); |
189 | 164 |
190 /** | 165 /** |
191 * \brief Enable/disable IPv6 stack install. | 166 * \brief Enable/disable IPv6 stack install. |
192 * \param enable enable state | 167 * \param enable enable state |
193 */ | 168 */ |
194 void SetIpv6StackInstall (bool enable); | 169 void SetIpv6StackInstall (bool enable); |
195 | 170 |
196 private: | 171 private: |
| 172 /** |
| 173 * @brief Enable pcap output the indicated Ipv4 and interface pair. |
| 174 * @internal |
| 175 * |
| 176 * @param prefix Filename prefix to use for pcap files. |
| 177 * @param ipv4 Ptr to the Ipv4 interface on which you want to enable tracing. |
| 178 * @param interface Interface ID on the Ipv4 on which you want to enable traci
ng. |
| 179 */ |
| 180 virtual void EnablePcapIpv4Internal (std::string prefix,· |
| 181 Ptr<Ipv4> ipv4, uint32_t interface); |
| 182 |
| 183 /** |
| 184 * @brief Enable ascii trace output on the indicated Ipv4 and interface pair. |
| 185 * @internal |
| 186 * |
| 187 * @param stream An OutputStreamObject representing an existing file to use |
| 188 * when writing trace data. |
| 189 * @param prefix Filename prefix to use for ascii trace files. |
| 190 * @param ipv4 Ptr to the Ipv4 interface on which you want to enable tracing. |
| 191 * @param interface Interface ID on the Ipv4 on which you want to enable traci
ng. |
| 192 */ |
| 193 virtual void EnableAsciiIpv4Internal (Ptr<OutputStreamObject> stream, std::str
ing prefix,· |
| 194 Ptr<Ipv4> ipv4, uint32_t interface); |
| 195 |
| 196 /** |
| 197 * @brief Enable pcap output the indicated Ipv4 and interface pair. |
| 198 * @internal |
| 199 * |
| 200 * @param prefix Filename prefix to use for pcap files. |
| 201 * @param ipv4 Ptr to the Ipv4 interface on which you want to enable tracing. |
| 202 * @param interface Interface ID on the Ipv4 on which you want to enable traci
ng. |
| 203 */ |
| 204 virtual void EnablePcapIpv6Internal (std::string prefix,· |
| 205 Ptr<Ipv6> ipv6, uint32_t interface); |
| 206 |
| 207 /** |
| 208 * @brief Enable ascii trace output on the indicated Ipv4 and interface pair. |
| 209 * @internal |
| 210 * |
| 211 * @param stream An OutputStreamObject representing an existing file to use |
| 212 * when writing trace data. |
| 213 * @param prefix Filename prefix to use for ascii trace files. |
| 214 * @param ipv4 Ptr to the Ipv4 interface on which you want to enable tracing. |
| 215 * @param interface Interface ID on the Ipv4 on which you want to enable traci
ng. |
| 216 */ |
| 217 virtual void EnableAsciiIpv6Internal (Ptr<OutputStreamObject> stream, std::str
ing prefix,· |
| 218 Ptr<Ipv6> ipv6, uint32_t interface); |
| 219 |
197 void Initialize (void); | 220 void Initialize (void); |
198 ObjectFactory m_tcpFactory; | 221 ObjectFactory m_tcpFactory; |
199 const Ipv4RoutingHelper *m_routing; | 222 const Ipv4RoutingHelper *m_routing; |
200 ·· | 223 ·· |
201 /** | 224 /** |
202 * \internal | 225 * \internal |
203 * \brief IPv6 routing helper. | 226 * \brief IPv6 routing helper. |
204 */ | 227 */ |
205 const Ipv6RoutingHelper *m_routingv6; | 228 const Ipv6RoutingHelper *m_routingv6; |
206 | 229 |
207 /** | 230 /** |
208 * \internal | 231 * \internal |
209 */ | 232 */ |
210 static void CreateAndAggregateObjectFromTypeId (Ptr<Node> node, const std::str
ing typeId); | 233 static void CreateAndAggregateObjectFromTypeId (Ptr<Node> node, const std::str
ing typeId); |
211 | 234 |
212 /** | 235 /** |
213 * \internal | 236 * \internal |
214 */ | 237 */ |
215 static void Cleanup (void); | 238 static void Cleanup (void); |
216 | 239 |
217 /** | 240 /** |
218 * \internal | 241 * \internal |
219 */ | 242 */ |
220 static void LogRxIp (std::string context, Ptr<const Packet> packet, uint32_t d
eviceId); | 243 bool PcapHooked (Ptr<Ipv4> ipv4); |
221 | 244 |
222 /** | 245 /** |
223 * \internal | 246 * \internal |
224 */ | 247 */ |
225 static void LogTxIp (std::string context, Ptr<const Packet> packet, uint32_t d
eviceId); | 248 bool AsciiHooked (Ptr<Ipv4> ipv4); |
226 | 249 |
227 /** | 250 /** |
228 * \internal | 251 * \internal |
229 */ | 252 */ |
230 static Ptr<PcapWriter> GetStream (uint32_t nodeId, uint32_t interfaceId); | 253 bool PcapHooked (Ptr<Ipv6> ipv6); |
231 | |
232 struct Trace { | |
233 uint32_t nodeId; | |
234 uint32_t interfaceId; | |
235 Ptr<PcapWriter> writer; | |
236 }; | |
237 | 254 |
238 /** | 255 /** |
239 * \internal | 256 * \internal |
240 */ | 257 */ |
241 static void AsciiDropEventIpv4 (Ptr<AsciiWriter> writer, std::string path, | 258 bool AsciiHooked (Ptr<Ipv6> ipv6); |
242 Ipv4Header const &header, Ptr<const Packet> pa
cket, | |
243 Ipv4L3Protocol::DropReason reason, uint32_t in
terface); | |
244 /** | |
245 * \internal | |
246 */ | |
247 static void AsciiDropEventArp (Ptr<AsciiWriter> writer, std::string path, Ptr<
const Packet> packet); | |
248 | |
249 /** | |
250 * \internal | |
251 */ | |
252 static void AsciiDropEventIpv6 (Ptr<AsciiWriter> writer, std::string path, | |
253 Ipv6Header const &header, Ptr<const Packet> pa
cket, | |
254 Ipv6L3Protocol::DropReason reason, uint32_t in
terface); | |
255 | |
256 static std::string m_pcapBaseFilename; | |
257 | |
258 /** | |
259 * \internal | |
260 */ | |
261 static uint32_t GetNodeIndex (std::string context); | |
262 | |
263 static std::vector<Trace> m_traces; | |
264 | 259 |
265 /** | 260 /** |
266 * \brief IPv4 install state (enabled/disabled) ? | 261 * \brief IPv4 install state (enabled/disabled) ? |
267 */ | 262 */ |
268 bool m_ipv4Enabled; | 263 bool m_ipv4Enabled; |
269 | 264 |
270 /** | 265 /** |
271 * \brief IPv6 install state (enabled/disabled) ? | 266 * \brief IPv6 install state (enabled/disabled) ? |
272 */ | 267 */ |
273 bool m_ipv6Enabled; | 268 bool m_ipv6Enabled; |
274 }; | 269 }; |
275 | 270 |
276 } // namespace ns3 | 271 } // namespace ns3 |
277 | 272 |
278 #endif /* INTERNET_STACK_HELPER_H */ | 273 #endif /* INTERNET_STACK_HELPER_H */ |
OLD | NEW |