ns-3 Direct Code Execution
Home
Tutorials ▼
Docs ▼
Wiki
Manual
Develop ▼
API
Bugs
API
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
linux-stack-helper.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2012 INRIA
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: Frédéric Urbani
19
*/
20
#include "
linux-stack-helper.h
"
21
#include "
ipv4-linux.h
"
22
#include "
linux-socket-fd-factory.h
"
23
#include "
dce-application-helper.h
"
24
#include "ns3/node.h"
25
#include "ns3/node-container.h"
26
#include "ns3/names.h"
27
28
namespace
ns3 {
29
void
30
LinuxStackHelper::Install
(Ptr<Node> node)
31
{
32
#ifdef KERNEL_STACK
33
Ipv4Linux::InstallNode
(node);
34
#endif
35
}
36
void
37
LinuxStackHelper::Install
(std::string nodeName)
38
{
39
#ifdef KERNEL_STACK
40
Ptr<Node> node = Names::Find<Node> (nodeName);
41
Install
(node);
42
#endif
43
}
44
void
45
LinuxStackHelper::Install
(NodeContainer c)
46
{
47
#ifdef KERNEL_STACK
48
for
(NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
49
{
50
Install
(*i);
51
}
52
#endif
53
}
54
void
55
LinuxStackHelper::InstallAll
(
void
)
56
{
57
#ifdef KERNEL_STACK
58
Install
(NodeContainer::GetGlobal ());
59
#endif
60
}
61
62
void
63
LinuxStackHelper::PopulateRoutingTables
()
64
{
65
#ifdef KERNEL_STACK
66
NodeContainer c = NodeContainer::GetGlobal ();
67
for
(NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
68
{
69
Ptr<Node> node = *i;
70
Ptr<Ipv4Linux> ipv4 = node->GetObject<
Ipv4Linux
> ();
71
ipv4->
PopulateRoutingTable
();
72
}
73
#endif
74
}
75
76
void
77
LinuxStackHelper::RunIp
(Ptr<Node> node, Time at, std::string str)
78
{
79
#ifdef KERNEL_STACK
80
DceApplicationHelper
process;
81
ApplicationContainer apps;
82
process.
SetBinary
(
"ip"
);
83
process.
SetStackSize
(1 << 16);
84
process.
ResetArguments
();
85
process.
ParseArguments
(str.c_str ());
86
apps = process.
Install
(node);
87
apps.Start (at);
88
#endif
89
}
90
91
void
92
LinuxStackHelper::SysctlGetCallback
(Ptr<Node> node, std::string path,
93
void
(*callback)(std::string, std::string))
94
{
95
#ifdef KERNEL_STACK
96
Ptr<LinuxSocketFdFactory> sock = node->GetObject<
LinuxSocketFdFactory
> ();
97
if
(!sock)
98
{
99
callback (
"error"
,
"no socket factory"
);
100
NS_ASSERT_MSG (0,
"No LinuxSocketFdFactory is installed. "
101
"You may need to do it via DceManagerHelper::Install ()"
);
102
return
;
103
}
104
105
std::string value = sock->Get (path);
106
callback (path, value);
107
return
;
108
#endif
109
}
110
111
void
112
LinuxStackHelper::SysctlGet
(Ptr<Node> node, Time at, std::string path,
113
void
(*callback)(std::string, std::string))
114
{
115
#ifdef KERNEL_STACK
116
Ptr<LinuxSocketFdFactory> sock = node->GetObject<
LinuxSocketFdFactory
> ();
117
if
(!sock)
118
{
119
callback (
"error"
,
"no socket factory"
);
120
NS_ASSERT_MSG (0,
"No LinuxSocketFdFactory is installed. "
121
"You may need to do it via DceManagerHelper::Install ()"
);
122
return
;
123
}
124
Simulator::ScheduleWithContext (node->GetId (), at,
125
&
LinuxSocketFdFactory::ScheduleTask
, sock,
126
MakeEvent (&
LinuxStackHelper::SysctlGetCallback
,
127
node, path, callback));
128
return
;
129
#endif
130
}
131
void
132
LinuxStackHelper::SysctlSet
(NodeContainer c, std::string path, std::string value)
133
{
134
#ifdef KERNEL_STACK
135
for
(NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
136
{
137
Ptr<Node> node = *i;
138
Ptr<LinuxSocketFdFactory> sock = node->GetObject<
LinuxSocketFdFactory
> ();
139
if
(!sock)
140
{
141
NS_ASSERT_MSG (0,
"No LinuxSocketFdFactory is installed. "
142
"You may need to do it via DceManagerHelper::Install ()"
);
143
}
144
Simulator::ScheduleWithContext (node->GetId (), Seconds (0.1),
145
MakeEvent (&
LinuxSocketFdFactory::Set
, sock,
146
path, value));
147
}
148
#endif
149
}
150
151
}
// namespace ns3
helper
linux-stack-helper.cc
Generated on Fri Aug 30 2013 13:57:55 for ns-3-dce by
1.8.1.2