1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
|
2 /* |
|
3 * This program is free software; you can redistribute it and/or modify |
|
4 * it under the terms of the GNU General Public License version 2 as |
|
5 * published by the Free Software Foundation; |
|
6 * |
|
7 * This program is distributed in the hope that it will be useful, |
|
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10 * GNU General Public License for more details. |
|
11 * |
|
12 * You should have received a copy of the GNU General Public License |
|
13 * along with this program; if not, write to the Free Software |
|
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
15 * |
|
16 * Author: George F. Riley<[email protected]> |
|
17 */ |
|
18 |
|
19 // Interface between ns3 and the network animator |
|
20 |
|
21 #ifndef ANIMATION_INTERFACE__H |
|
22 #define ANIMATION_INTERFACE__H |
|
23 |
|
24 #include <string> |
|
25 |
|
26 #include "ns3/ptr.h" |
|
27 #include "ns3/net-device.h" |
|
28 #include "ns3/nstime.h" |
|
29 #include "ns3/log.h" |
|
30 #include "ns3/node-list.h" |
|
31 |
|
32 |
|
33 namespace ns3 { |
|
34 class NetModel; |
|
35 |
|
36 /** |
|
37 * \brief Interface to network animator |
|
38 * |
|
39 * Provides functions that facilitate communications with an |
|
40 * external or internal network animator. |
|
41 */ |
|
42 class AnimationInterface |
|
43 { |
|
44 public: |
|
45 /** |
|
46 * @brief Construct the animator interface. No arguments needed. |
|
47 */ |
|
48 AnimationInterface (); |
|
49 /** |
|
50 * @brief Destructor for the animator interface. |
|
51 */ |
|
52 ~AnimationInterface (); |
|
53 /** |
|
54 * @brief Specify that animation commands are to be written |
|
55 * to the specified output file. |
|
56 * |
|
57 * This call is used to write the animation information to a text |
|
58 * file that can later be used as input to the network animator tool. |
|
59 * |
|
60 * @param fn The name of the output file. |
|
61 * @returns true if successful open. |
|
62 */ |
|
63 bool SetOutputFile (const std::string& fn); |
|
64 |
|
65 /** |
|
66 * @brief Specify that animation commands are to be written to |
|
67 * a socket. |
|
68 * |
|
69 * This call is used to set the ns3 process in server mode, waiting |
|
70 * for a TCP connection from the animator. This call will not |
|
71 * return until the animator connects in, or if the bind to the |
|
72 * specified port fails. |
|
73 * |
|
74 * @param port Port number to bind to. |
|
75 * @returns true if connection created, false if bind failed. |
|
76 */ |
|
77 bool SetServerPort (uint16_t port); |
|
78 |
|
79 /** |
|
80 * @brief Writes the topology information and sets up the appropriate |
|
81 * animation packet tx callback |
|
82 * |
|
83 * Writes the topology information to the appropriate output, depending |
|
84 * on prior calls to SetOutputFile, SetServerPort, or SetInternalAnimation. |
|
85 * Then creates the callbacks needed for the animator to start processing |
|
86 * packets. |
|
87 * |
|
88 */ |
|
89 void StartAnimation (); |
|
90 |
|
91 /** |
|
92 * @brief Closes the interface to the animator. |
|
93 * |
|
94 */ |
|
95 void StopAnimation (); |
|
96 |
|
97 |
|
98 private: |
|
99 // Packet tx animation callback |
|
100 void DevTxTrace (std::string context, Ptr<const Packet> p, |
|
101 Ptr<NetDevice> tx, Ptr<NetDevice> rx, |
|
102 Time txTime, Time rxTime); |
|
103 // Write specified amount of data to the specified handle |
|
104 int WriteN (int, const char*, uint32_t); |
|
105 private: |
|
106 int m_fHandle; // File handle for output (-1 if none) |
|
107 NetModel* m_model; // If non nil, points to the internal network model |
|
108 // for the interlan animator |
|
109 }; |
|
110 } |
|
111 #endif |
|
112 |
|