ns-3 Direct Code Execution
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dce-manager-helper.cc
Go to the documentation of this file.
1 #include "dce-manager-helper.h"
2 #include "dce-manager.h"
3 #include "socket-fd-factory.h"
5 #include "task-scheduler.h"
6 #include "task-manager.h"
7 #include "loader-factory.h"
8 #include "ns3/random-variable.h"
9 #include "ns3/uinteger.h"
10 #include "ns3/string.h"
11 #include "ns3/config.h"
12 #include "ns3/log.h"
13 #include "dce-node-context.h"
14 #include "ipv4-linux.h"
15 #include "dce-application-helper.h"
16 #include "ns3/ipv4-routing-protocol.h"
17 #include "ns3/ipv4-global-routing.h"
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <limits.h>
21 #include <errno.h>
22 
23 NS_LOG_COMPONENT_DEFINE ("DceManagerHelper");
24 
25 namespace ns3 {
26 
27 UniformVariable g_firstPid;
28 
30 
31 TypeId
33 {
34  static TypeId tid = TypeId ("ns3::DceManagerHelper")
35  .SetParent<ObjectBase> ()
36  .AddAttribute ("LoaderFactory",
37  "The kind of loader factory created when Install is called",
38  StringValue ("ns3::CoojaLoaderFactory[]"),
39  MakeObjectFactoryAccessor (&DceManagerHelper::m_loaderFactory),
40  MakeObjectFactoryChecker ())
41  ;
42  return tid;
43 }
44 TypeId
46 {
48 }
49 
51 {
52  ConstructSelf (AttributeConstructionList ());
53  m_taskManagerFactory.SetTypeId ("ns3::TaskManager");
54  m_schedulerFactory.SetTypeId ("ns3::RrTaskScheduler");
55  m_managerFactory.SetTypeId ("ns3::DceManager");
56  m_networkStackFactory.SetTypeId ("ns3::Ns3SocketFdFactory");
57  m_delayFactory.SetTypeId ("ns3::RandomProcessDelayModel");
58  m_virtualPath = "";
59 }
60 void
62  std::string n0, const AttributeValue &v0,
63  std::string n1, const AttributeValue &v1)
64 {
65  m_schedulerFactory.SetTypeId (type);
66  m_schedulerFactory.Set (n0, v0);
67  m_schedulerFactory.Set (n1, v1);
68 }
69 void
71  std::string n0, const AttributeValue &v0,
72  std::string n1, const AttributeValue &v1)
73 {
74  m_delayFactory.SetTypeId (type);
75  m_delayFactory.Set (n0, v0);
76  m_delayFactory.Set (n1, v1);
77 }
78 void
79 DceManagerHelper::SetTaskManagerAttribute (std::string n0, const AttributeValue &v0)
80 {
81  m_taskManagerFactory.Set (n0, v0);
82 }
83 void
84 DceManagerHelper::SetLoader (std::string type)
85 {
86  m_loaderFactory.SetTypeId (type);
87 }
88 void
90  std::string n0, const AttributeValue &v0)
91 {
92  m_networkStackFactory.SetTypeId (type);
93  m_networkStackFactory.Set (n0, v0);
94 }
95 void
96 DceManagerHelper::SetAttribute (std::string n1, const AttributeValue &v1)
97 {
98  m_managerFactory.Set (n1, v1);
99 }
100 void
101 DceManagerHelper::Install (NodeContainer nodes)
102 {
103  for (NodeContainer::Iterator i = nodes.Begin (); i != nodes.End (); ++i)
104  {
105  Ptr<DceManager> manager = m_managerFactory.Create<DceManager> ();
106  Ptr<TaskManager> taskManager = m_taskManagerFactory.Create<TaskManager> ();
107  Ptr<TaskScheduler> scheduler = m_schedulerFactory.Create<TaskScheduler> ();
108  Ptr<LoaderFactory> loader = m_loaderFactory.Create<LoaderFactory> ();
109  Ptr<SocketFdFactory> networkStack = m_networkStackFactory.Create<SocketFdFactory> ();
110  Ptr<ProcessDelayModel> delay = m_delayFactory.Create<ProcessDelayModel> ();
111 
112  taskManager->SetScheduler (scheduler);
113  taskManager->SetDelayModel (delay);
114  manager->SetAttribute ("FirstPid", UintegerValue (g_firstPid.GetInteger (0, 0xffff)));
115  Ptr<Node> node = *i;
116  node->AggregateObject (taskManager);
117  node->AggregateObject (loader);
118  node->AggregateObject (manager);
119  node->AggregateObject (networkStack);
120  node->AggregateObject (CreateObject<LocalSocketFdFactory> ());
121  manager->AggregateObject (CreateObject<DceNodeContext> ());
122  manager->SetVirtualPath (GetVirtualPath ());
123  }
124 }
125 void
127 {
128  m_virtualPath = p;
129 }
130 std::string
132 {
133  return m_virtualPath;
134 }
135 
136 std::vector<ProcStatus>
138 {
139  FILE *f = fopen ("exitprocs","r");
140  std::vector<ProcStatus> res;
141 
142  if (f)
143  {
144  char buffer[10 * 1024];
145 
146  while ((!feof (f)) && (fgets (buffer, sizeof(buffer),f)))
147  {
148  if (0 == strncmp (buffer, "NODE",4))
149  {
150  // SKIP First line
151  }
152  else
153  {
154  long int ret = 0;
155  char *crsr = buffer;
156  char *next = 0;
157 
158  errno = 0;
159  ret = strtol (crsr, &next, 10);
160  if ((ret == LONG_MIN) || (ret == LONG_MAX) || (ERANGE == errno) || (next == crsr))
161  {
162  continue;
163  }
164  int node = (int) ret;
165  crsr = next;
166  next = 0;
167 
168  errno = 0;
169  ret = strtol (crsr, &next, 10);
170  if ((ret == LONG_MIN) || (ret == LONG_MAX) || (ERANGE == errno) || (next == crsr))
171  {
172  continue;
173  }
174  int exitcode = (int) ret;
175  crsr = next;
176  next = 0;
177 
178  errno = 0;
179  ret = strtol (crsr, &next, 10);
180  if ((ret == LONG_MIN) || (ret == LONG_MAX) || (ERANGE == errno) || (next == crsr))
181  {
182  continue;
183  }
184  int pid = (int) ret;
185  crsr = next;
186  next = 0;
187 
188  unsigned long long int ret2 = 0;
189  errno = 0;
190  ret2 = strtoll (crsr, &next, 10);
191  if ((ret == LLONG_MIN) || (ret == LLONG_MAX) || (ERANGE == errno) || (next == crsr))
192  {
193  continue;
194  }
195  int64_t nst = (int64_t) ret2;
196  crsr = next;
197  next = 0;
198 
199  errno = 0;
200  ret2 = strtoll (crsr, &next, 10);
201  if ((ret == LLONG_MIN) || (ret == LLONG_MAX) || (ERANGE == errno) || (next == crsr))
202  {
203  continue;
204  }
205  int64_t ned = (int64_t) ret2;
206  crsr = next;
207  next = 0;
208 
209  errno = 0;
210  ret = strtol (crsr, &next, 10);
211  if ((ret == LONG_MIN) || (ret == LONG_MAX) || (ERANGE == errno) || (next == crsr))
212  {
213  continue;
214  }
215  long rst = (long) ret;
216  crsr = next;
217  next = 0;
218 
219  errno = 0;
220  ret = strtol (crsr, &next, 10);
221  if ((ret == LONG_MIN) || (ret == LONG_MAX) || (ERANGE == errno) || (next == crsr))
222  {
223  continue;
224  }
225  long red = (long) ret;
226  crsr = next;
227  next = 0;
228 
229  double ret3;
230  errno = 0;
231  ret3 = strtod (crsr, &next);
232  if ((ERANGE == errno) || (next == crsr))
233  {
234  continue;
235  }
236  double dur3 = ret3;
237  crsr = next;
238  next = 0;
239 
240  errno = 0;
241  ret = strtol (crsr, &next, 10);
242  if ((ret == LONG_MIN) || (ret == LONG_MAX) || (ERANGE == errno) || (next == crsr))
243  {
244  continue;
245  }
246  long durr = (long) ret;
247  crsr = next;
248  next = 0;
249 
250  ProcStatus st (node, exitcode, pid, nst, ned, rst, red, dur3, durr, crsr + 1);
251 
252  res.push_back (st);
253  }
254  }
255 
256  fclose (f);
257  }
258 
259  return res;
260 }
261 
262 ProcStatus::ProcStatus (int n, int e, int p, int64_t ns, int64_t ne, long rs, long re, double nd, long rd, std::string cmd)
263  : m_node (n),
264  m_exitCode (e),
265  m_pid (p),
266  m_ns3StartTime (ns),
267  m_ns3EndTime (ne),
268  m_realStartTime (rs),
269  m_realEndTime (re),
270  m_ns3Duration (nd),
271  m_realDuration (rd),
272  m_cmdLine (cmd)
273 {
274 }
275 
276 int
278 {
279  return m_node;
280 }
281 
282 int
284 {
285  return m_exitCode;
286 }
287 
288 int
289 ProcStatus::GetPid (void) const
290 {
291  return m_pid;
292 }
293 
294 int64_t
296 {
297  return m_ns3StartTime;
298 }
299 
301 {
302  return m_ns3EndTime;
303 }
304 
305 long
307 {
308  return m_realStartTime;
309 }
310 
311 /* Real End Time */
312 long
314 {
315  return m_realEndTime;
316 }
317 
318 double
320 {
321  return m_ns3Duration;
322 }
323 
324 long
326 {
327  return m_realDuration;
328 }
329 
330 std::string
332 {
333  return m_cmdLine;
334 }
335 
336 } // namespace ns3