author | Hajime Tazaki <tazaki@nict.go.jp> |
Wed, 11 Apr 2012 11:21:19 +0900 | |
changeset 18 | 1811be862c59 |
parent 14 | 6f4976897048 |
child 20 | 5ca51e147e7f |
permissions | -rw-r--r-- |
12 | 1 |
* * * |
2 |
quagga ospfd with ns-3-linux support |
|
3 |
||
4 |
diff -r 28c0c7f781c1 example/dce-zebra-simple.cc |
|
5 |
--- a/example/dce-zebra-simple.cc Thu Mar 29 17:00:46 2012 +0200 |
|
6 |
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
7 |
@@ -1,114 +0,0 @@ |
|
8 |
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
|
9 |
-/* |
|
10 |
- * Copyright (c) 2011 UCLA |
|
11 |
- * |
|
12 |
- * This program is free software; you can redistribute it and/or modify |
|
13 |
- * it under the terms of the GNU General Public License version 2 as |
|
14 |
- * published by the Free Software Foundation; |
|
15 |
- * |
|
16 |
- * This program is distributed in the hope that it will be useful, |
|
17 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 |
- * GNU General Public License for more details. |
|
20 |
- * |
|
21 |
- * You should have received a copy of the GNU General Public License |
|
22 |
- * along with this program; if not, write to the Free Software |
|
23 |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
- * |
|
25 |
- * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
|
26 |
- */ |
|
27 |
- |
|
28 |
-#include "ns3/network-module.h" |
|
29 |
-#include "ns3/core-module.h" |
|
30 |
-#include "ns3/internet-module.h" |
|
31 |
-#include "ns3/ipv4-global-routing-helper.h" |
|
32 |
-#include "ns3/dce-module.h" |
|
33 |
-#include "ns3/quagga-helper.h" |
|
34 |
-#include "ns3/point-to-point-grid.h" |
|
35 |
-#include "../helper/ipv4-dce-routing-helper.h" |
|
36 |
- |
|
37 |
-using namespace ns3; |
|
38 |
- |
|
39 |
-NS_LOG_COMPONENT_DEFINE ("quagga"); |
|
40 |
- |
|
41 |
-void |
|
42 |
-procExit (std::string path, uint16_t pid, int retcode) |
|
43 |
-{ |
|
44 |
- std::cout << "Process exit path=" << path << " pid=" << pid << " retcode=" << retcode << std::endl; |
|
45 |
-} |
|
46 |
- |
|
47 |
-// Parameters |
|
48 |
-uint32_t nNodes = 2; |
|
49 |
-uint32_t stopTime = 60; |
|
50 |
-std::string netStack = "ns3"; |
|
51 |
- |
|
52 |
-void TestDisable (Ptr<Node> node) |
|
53 |
-{ |
|
54 |
- NS_LOG_FUNCTION (node->GetId ()); |
|
55 |
- |
|
56 |
- Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
|
57 |
- NS_ASSERT_MSG (ipv4 != 0, "ipv4 should not be null"); |
|
58 |
- |
|
59 |
- // The thing I didn't know is that interface status (isUp/isDown) and device status (isLinkUp) are two totally different things. It is possible to set interface up and down, but there is not an easy way to alter status of device. This similar to reality: it is possible to programmatically disable interface, but to actually disable a link one needs to physically cut the cable |
|
60 |
- ipv4->SetDown (2); |
|
61 |
-} |
|
62 |
- |
|
63 |
-int main (int argc, char *argv[]) |
|
64 |
-{ |
|
65 |
- CommandLine cmd; |
|
66 |
- cmd.AddValue ("nNodes", "Number of Router nodes", nNodes); |
|
67 |
- cmd.AddValue ("stopTime", "Time to stop(seconds)", stopTime); |
|
68 |
- cmd.AddValue ("netStack", "What network stack", netStack); |
|
69 |
- cmd.Parse (argc, argv); |
|
70 |
- |
|
71 |
- PointToPointHelper p2p; |
|
72 |
- InternetStackHelper stack; |
|
73 |
- Ipv4DceRoutingHelper ipv4RoutingHelper; |
|
74 |
- |
|
75 |
- stack.SetRoutingHelper (ipv4RoutingHelper); |
|
76 |
- |
|
77 |
- PointToPointGridHelper grid (nNodes, nNodes, p2p); |
|
78 |
- grid.InstallStack (stack); |
|
79 |
- |
|
80 |
- grid.AssignIpv4Addresses ( |
|
81 |
- Ipv4AddressHelper("10.1.0.0", "255.255.255.0"), |
|
82 |
- Ipv4AddressHelper("10.2.0.0", "255.255.255.0") |
|
83 |
- ); |
|
84 |
- |
|
85 |
- Ptr<DceManagerHelper> dceManager = CreateObject<DceManagerHelper> (); |
|
86 |
- dceManager->SetNetworkStack("ns3::Ns3SocketFdFactory"); |
|
87 |
- |
|
88 |
- QuaggaHelper quagga; |
|
89 |
- |
|
90 |
- ApplicationContainer apps; |
|
91 |
- |
|
92 |
- for (int i=0; i<nNodes; i++) |
|
93 |
- for (int j=0; j<nNodes; j++) |
|
94 |
- { |
|
95 |
- Ptr<Node> node = grid.GetNode (i,j); |
|
96 |
- dceManager->Install (node); |
|
97 |
- quagga.EnableOspf (node); |
|
98 |
- quagga.EnableOspfDebug (node); |
|
99 |
- quagga.EnableZebraDebug (node); |
|
100 |
- apps.Add (quagga.Install (node)); |
|
101 |
- } |
|
102 |
- |
|
103 |
- apps.Stop (Seconds(150.0)); |
|
104 |
- |
|
105 |
- Simulator::ScheduleWithContext (grid.GetNode (0,0)->GetId (), |
|
106 |
- Seconds (80.0), TestDisable, grid.GetNode (0,0)); |
|
107 |
- |
|
108 |
- Config::Connect ("/NodeList/*/$ns3::DceManager/Exit", MakeCallback (&procExit)); |
|
109 |
- |
|
110 |
- // Trace routing tables |
|
111 |
- Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("routes.log", std::ios::out); |
|
112 |
- ipv4RoutingHelper.PrintRoutingTableAllEvery (Seconds (10), routingStream); |
|
113 |
- |
|
114 |
- Simulator::Stop (Seconds(160.0)); |
|
115 |
- Simulator::Run (); |
|
116 |
- Simulator::Destroy (); |
|
117 |
- |
|
118 |
- NS_LOG_INFO ("End of experiment"); |
|
119 |
- |
|
120 |
- return 0; |
|
121 |
-} |
|
122 |
diff -r 28c0c7f781c1 helper/quagga-helper.cc |
|
123 |
--- a/helper/quagga-helper.cc Thu Mar 29 17:00:46 2012 +0200 |
|
124 |
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
125 |
@@ -1,596 +0,0 @@ |
|
126 |
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
|
127 |
-/* |
|
128 |
- * Copyright (c) 2010 Hajime Tazaki |
|
129 |
- * |
|
130 |
- * This program is free software; you can redistribute it and/or modify |
|
131 |
- * it under the terms of the GNU General Public License version 2 as |
|
132 |
- * published by the Free Software Foundation; |
|
133 |
- * |
|
134 |
- * This program is distributed in the hope that it will be useful, |
|
135 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
136 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
137 |
- * GNU General Public License for more details. |
|
138 |
- * |
|
139 |
- * You should have received a copy of the GNU General Public License |
|
140 |
- * along with this program; if not, write to the Free Software |
|
141 |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
142 |
- * |
|
143 |
- * Author: Hajime Tazaki <tazaki@sfc.wide.ad.jp> |
|
144 |
- */ |
|
145 |
- |
|
146 |
-#include "ns3/object-factory.h" |
|
147 |
-#include "quagga-helper.h" |
|
148 |
-#include "ns3/names.h" |
|
149 |
-#include "ns3/ipv4-l3-protocol.h" |
|
150 |
-//#include "ns3/utils.h" |
|
151 |
-#include <fstream> |
|
152 |
-#include <map> |
|
153 |
-#include <sys/stat.h> |
|
154 |
-#include "ns3/log.h" |
|
155 |
- |
|
156 |
-NS_LOG_COMPONENT_DEFINE ("QuaggaHelper"); |
|
157 |
- |
|
158 |
-namespace ns3 { |
|
159 |
- |
|
160 |
-class QuaggaConfig: public Object |
|
161 |
-{ |
|
162 |
-private: |
|
163 |
- static int index; |
|
164 |
- std::string router_id; |
|
165 |
- std::map<std::string, uint32_t> *networks; |
|
166 |
-public: |
|
167 |
- QuaggaConfig () |
|
168 |
- : m_tdpenable (false), |
|
169 |
- m_zebradebug (false), |
|
170 |
- m_usemanualconf (false) |
|
171 |
- { |
|
172 |
- m_radvd_if = new std::vector<std::string> (); |
|
173 |
- m_egress_if = new std::vector<std::string> (); |
|
174 |
- m_haflag_if = new std::vector<std::string> (); |
|
175 |
- } |
|
176 |
- virtual ~QuaggaConfig () |
|
177 |
- { |
|
178 |
- } |
|
179 |
- |
|
180 |
- static TypeId |
|
181 |
- GetTypeId (void) |
|
182 |
- { |
|
183 |
- static TypeId tid = TypeId ("ns3::QuaggaConfig") |
|
184 |
- .SetParent<Object> () |
|
185 |
- .AddConstructor<QuaggaConfig> () |
|
186 |
- ; |
|
187 |
- return tid; |
|
188 |
- } |
|
189 |
- TypeId |
|
190 |
- GetInstanceTypeId (void) const |
|
191 |
- { |
|
192 |
- return GetTypeId (); |
|
193 |
- } |
|
194 |
- |
|
195 |
- void |
|
196 |
- SetFilename (const std::string &filename) |
|
197 |
- { |
|
198 |
- m_filename = filename; |
|
199 |
- } |
|
200 |
- |
|
201 |
- std::string |
|
202 |
- GetFilename () const |
|
203 |
- { |
|
204 |
- return m_filename; |
|
205 |
- } |
|
206 |
- |
|
207 |
- bool m_tdpenable; |
|
208 |
- bool m_zebradebug; |
|
209 |
- bool m_usemanualconf; |
|
210 |
- std::vector<std::string> *m_radvd_if; |
|
211 |
- std::vector<std::string> *m_egress_if; |
|
212 |
- std::vector<std::string> *m_haflag_if; |
|
213 |
- |
|
214 |
- std::string m_filename; |
|
215 |
- |
|
216 |
- std::vector<uint32_t> iflist; |
|
217 |
- |
|
218 |
- virtual void |
|
219 |
- Print (std::ostream& os) const |
|
220 |
- { |
|
221 |
- os << "hostname zebra" << std::endl |
|
222 |
- << "password zebra" << std::endl |
|
223 |
- << "log stdout" << std::endl; |
|
224 |
- } |
|
225 |
-}; |
|
226 |
-std::ostream& operator << (std::ostream& os, QuaggaConfig const& config) |
|
227 |
-{ |
|
228 |
- config.Print (os); |
|
229 |
- return os; |
|
230 |
-} |
|
231 |
- |
|
232 |
-class OspfConfig : public Object |
|
233 |
-{ |
|
234 |
-private: |
|
235 |
- std::map<std::string, uint32_t> *networks; |
|
236 |
-public: |
|
237 |
- OspfConfig () |
|
238 |
- : m_ospfdebug (false) |
|
239 |
- { |
|
240 |
- networks = new std::map<std::string, uint32_t> (); |
|
241 |
- iflist = new std::vector<uint32_t> (); |
|
242 |
- } |
|
243 |
- ~OspfConfig () |
|
244 |
- { |
|
245 |
- delete networks; |
|
246 |
- delete iflist; |
|
247 |
- } |
|
248 |
- |
|
249 |
- bool m_ospfdebug; |
|
250 |
- |
|
251 |
- static TypeId |
|
252 |
- GetTypeId (void) |
|
253 |
- { |
|
254 |
- static TypeId tid = TypeId ("ns3::OspfConfig") |
|
255 |
- .SetParent<Object> () |
|
256 |
- .AddConstructor<OspfConfig> () |
|
257 |
- ; |
|
258 |
- return tid; |
|
259 |
- } |
|
260 |
- TypeId |
|
261 |
- GetInstanceTypeId (void) const |
|
262 |
- { |
|
263 |
- return GetTypeId (); |
|
264 |
- } |
|
265 |
- |
|
266 |
- void |
|
267 |
- addNetwork (Ipv4Address prefix, uint32_t plen, uint32_t area) |
|
268 |
- { |
|
269 |
- std::stringstream net; |
|
270 |
- net << prefix << "/" << plen; |
|
271 |
- networks->insert (std::map<std::string, uint32_t>::value_type (net.str (), area)); |
|
272 |
- } |
|
273 |
- |
|
274 |
- void |
|
275 |
- SetFilename (const std::string &filename) |
|
276 |
- { |
|
277 |
- m_filename = filename; |
|
278 |
- } |
|
279 |
- |
|
280 |
- std::string |
|
281 |
- GetFilename () const |
|
282 |
- { |
|
283 |
- return m_filename; |
|
284 |
- } |
|
285 |
- |
|
286 |
- virtual void |
|
287 |
- Print (std::ostream& os) const |
|
288 |
- { |
|
289 |
- os << "hostname zebra" << std::endl |
|
290 |
- << "password zebra" << std::endl |
|
291 |
- << "log stdout" << std::endl; |
|
292 |
- if (m_ospfdebug) |
|
293 |
- { |
|
294 |
- //os << "log trap errors" << std::endl; |
|
295 |
- os << "debug ospf event " << std::endl; |
|
296 |
- os << "debug ospf nsm " << std::endl; |
|
297 |
- os << "debug ospf ism " << std::endl; |
|
298 |
- os << "debug ospf packet all " << std::endl; |
|
299 |
- } |
|
300 |
- |
|
301 |
- for (std::vector<uint32_t>::iterator i = iflist->begin (); |
|
302 |
- i != iflist->end (); ++i) |
|
303 |
- { |
|
304 |
- os << "interface ns3-device" << (*i) << std::endl; |
|
305 |
- } |
|
306 |
- |
|
307 |
- os << "router ospf " << std::endl; |
|
308 |
- // os << " ospf router-id " << m_routerId << std::endl; |
|
309 |
- for (std::map<std::string, uint32_t>::iterator i = networks->begin (); |
|
310 |
- i != networks->end (); ++i) |
|
311 |
- { |
|
312 |
- os << " network " << (*i).first << " area " << (*i).second << std::endl; |
|
313 |
- } |
|
314 |
- os << "!" << std::endl; |
|
315 |
- } |
|
316 |
- std::vector<uint32_t> *iflist; |
|
317 |
- std::string m_filename; |
|
318 |
- uint32_t m_routerId; |
|
319 |
-}; |
|
320 |
- |
|
321 |
- |
|
322 |
-QuaggaHelper::QuaggaHelper () |
|
323 |
-{ |
|
324 |
-} |
|
325 |
- |
|
326 |
-void |
|
327 |
-QuaggaHelper::SetAttribute (std::string name, const AttributeValue &value) |
|
328 |
-{ |
|
329 |
-} |
|
330 |
- |
|
331 |
-// OSPF |
|
332 |
-void |
|
333 |
-QuaggaHelper::EnableOspf (NodeContainer nodes) |
|
334 |
-{ |
|
335 |
- // for (uint32_t i = 0; i < nodes.GetN (); i++) |
|
336 |
- for (uint32_t i = 0; i < nodes.GetN (); i ++) |
|
337 |
- { |
|
338 |
- Ptr<OspfConfig> ospf_conf = CreateObject<OspfConfig> (); |
|
339 |
- nodes.Get (i)->AggregateObject (ospf_conf); |
|
340 |
- |
|
341 |
- for (uint32_t j = 0; j < nodes.Get (i)->GetNDevices (); j ++) |
|
342 |
- { |
|
343 |
- // Use primary address, if multiple |
|
344 |
- // Ipv4Address addr = interfaces->GetAddress (i, 0).GetLocal (); |
|
345 |
- // uint32_t ifindex = interfaces.Get (i).second; |
|
346 |
- // g_ospf_conf->iflist->insert (std::map<Ptr<Node>, uint32_t>::value_type (nodes.Get (i), ifindex)); |
|
347 |
- } |
|
348 |
- } |
|
349 |
- |
|
350 |
- return; |
|
351 |
-} |
|
352 |
- |
|
353 |
-void |
|
354 |
-QuaggaHelper::EnableOspfDebug (NodeContainer nodes) |
|
355 |
-{ |
|
356 |
- for (uint32_t i = 0; i < nodes.GetN (); i ++) |
|
357 |
- { |
|
358 |
- Ptr<OspfConfig> ospf_conf = nodes.Get (i)->GetObject<OspfConfig>(); |
|
359 |
- if (!ospf_conf) |
|
360 |
- { |
|
361 |
- ospf_conf = new OspfConfig (); |
|
362 |
- nodes.Get (i)->AggregateObject (ospf_conf); |
|
363 |
- } |
|
364 |
- ospf_conf->m_ospfdebug = true; |
|
365 |
- } |
|
366 |
- return; |
|
367 |
-} |
|
368 |
- |
|
369 |
-void |
|
370 |
-QuaggaHelper::EnableTdpNina (NodeContainer nodes) |
|
371 |
-{ |
|
372 |
- for (uint32_t i = 0; i < nodes.GetN (); i ++) |
|
373 |
- { |
|
374 |
- Ptr<QuaggaConfig> zebra_conf = nodes.Get (i)->GetObject<QuaggaConfig>(); |
|
375 |
- if (!zebra_conf) |
|
376 |
- { |
|
377 |
- zebra_conf = new QuaggaConfig (); |
|
378 |
- nodes.Get (i)->AggregateObject (zebra_conf); |
|
379 |
- } |
|
380 |
- zebra_conf->m_tdpenable = true; |
|
381 |
- } |
|
382 |
- return; |
|
383 |
-} |
|
384 |
- |
|
385 |
-void |
|
386 |
-QuaggaHelper::EnableZebraDebug (NodeContainer nodes) |
|
387 |
-{ |
|
388 |
- for (uint32_t i = 0; i < nodes.GetN (); i ++) |
|
389 |
- { |
|
390 |
- Ptr<QuaggaConfig> zebra_conf = nodes.Get (i)->GetObject<QuaggaConfig>(); |
|
391 |
- if (!zebra_conf) |
|
392 |
- { |
|
393 |
- zebra_conf = new QuaggaConfig (); |
|
394 |
- nodes.Get (i)->AggregateObject (zebra_conf); |
|
395 |
- } |
|
396 |
- zebra_conf->m_zebradebug = true; |
|
397 |
- } |
|
398 |
- return; |
|
399 |
-} |
|
400 |
- |
|
401 |
-void |
|
402 |
-QuaggaHelper::EnableRadvd (Ptr<Node> node, const char *ifname) |
|
403 |
-{ |
|
404 |
- Ptr<QuaggaConfig> zebra_conf = node->GetObject<QuaggaConfig>(); |
|
405 |
- if (!zebra_conf) |
|
406 |
- { |
|
407 |
- zebra_conf = new QuaggaConfig (); |
|
408 |
- node->AggregateObject (zebra_conf); |
|
409 |
- } |
|
410 |
- |
|
411 |
- zebra_conf->m_radvd_if->push_back (std::string(ifname)); |
|
412 |
- |
|
413 |
- return; |
|
414 |
-} |
|
415 |
- |
|
416 |
-void |
|
417 |
-QuaggaHelper::EnableEgressIF (Ptr<Node> node, const char *ifname) |
|
418 |
-{ |
|
419 |
- Ptr<QuaggaConfig> zebra_conf = node->GetObject<QuaggaConfig>(); |
|
420 |
- if (!zebra_conf) |
|
421 |
- { |
|
422 |
- zebra_conf = new QuaggaConfig (); |
|
423 |
- node->AggregateObject (zebra_conf); |
|
424 |
- } |
|
425 |
- |
|
426 |
- zebra_conf->m_egress_if->push_back (std::string(ifname)); |
|
427 |
- |
|
428 |
- return; |
|
429 |
-} |
|
430 |
- |
|
431 |
-void |
|
432 |
-QuaggaHelper::EnableHomeAgentFlag (Ptr<Node> node, const char *ifname) |
|
433 |
-{ |
|
434 |
- Ptr<QuaggaConfig> zebra_conf = node->GetObject<QuaggaConfig>(); |
|
435 |
- if (!zebra_conf) |
|
436 |
- { |
|
437 |
- zebra_conf = new QuaggaConfig (); |
|
438 |
- node->AggregateObject (zebra_conf); |
|
439 |
- } |
|
440 |
- |
|
441 |
- zebra_conf->m_haflag_if->push_back (std::string(ifname)); |
|
442 |
- |
|
443 |
- return; |
|
444 |
-} |
|
445 |
- |
|
446 |
-void |
|
447 |
-QuaggaHelper::UseManualConfig (NodeContainer nodes) |
|
448 |
-{ |
|
449 |
- for (uint32_t i = 0; i < nodes.GetN (); i ++) |
|
450 |
- { |
|
451 |
- Ptr<QuaggaConfig> zebra_conf = nodes.Get (i)->GetObject<QuaggaConfig>(); |
|
452 |
- if (!zebra_conf) |
|
453 |
- { |
|
454 |
- zebra_conf = new QuaggaConfig (); |
|
455 |
- nodes.Get (i)->AggregateObject (zebra_conf); |
|
456 |
- } |
|
457 |
- zebra_conf->m_usemanualconf = true; |
|
458 |
- } |
|
459 |
- return; |
|
460 |
-} |
|
461 |
- |
|
462 |
- |
|
463 |
-void |
|
464 |
-QuaggaHelper::GenerateConfigZebra (Ptr<Node> node) |
|
465 |
-{ |
|
466 |
- Ptr<QuaggaConfig> zebra_conf = node->GetObject<QuaggaConfig>(); |
|
467 |
- Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
|
468 |
- |
|
469 |
- if (zebra_conf->m_usemanualconf) |
|
470 |
- { |
|
471 |
- return; |
|
472 |
- } |
|
473 |
- |
|
474 |
- NS_LOG_DEBUG ("ipv4->GetNInterfaces () = " << ipv4->GetNInterfaces ()); |
|
475 |
- |
|
476 |
-// for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i ++) |
|
477 |
-// { |
|
478 |
-// Ipv4Address addr = ipv4->GetAddress (i, 0).GetLocal (); |
|
479 |
-// Ipv4Mask mask = ipv4->GetAddress (i, 0).GetMask (); |
|
480 |
-// Ipv4Address prefix = addr.CombineMask (mask); |
|
481 |
-// |
|
482 |
-// NS_LOG_DEBUG ("address: " << addr); |
|
483 |
-// |
|
484 |
-// if (addr.IsEqual (Ipv4Address::GetLoopback())) |
|
485 |
-// { |
|
486 |
-// continue; |
|
487 |
-// } |
|
488 |
-// |
|
489 |
-// zebra_conf->iflist.push_back (i); |
|
490 |
-// } |
|
491 |
- |
|
492 |
- // config generation |
|
493 |
- std::stringstream conf_dir, conf_file; |
|
494 |
- // FIXME XXX |
|
495 |
- conf_dir << "files-" << node->GetId () << ""; |
|
496 |
- ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG); |
|
497 |
- conf_dir << "/usr/"; |
|
498 |
- ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG); |
|
499 |
- conf_dir << "/local/"; |
|
500 |
- ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG); |
|
501 |
- conf_dir << "/etc/"; |
|
502 |
- ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG); |
|
503 |
- |
|
504 |
- conf_file << conf_dir.str() << "/zebra.conf"; |
|
505 |
- zebra_conf->SetFilename ("/usr/local/etc/zebra.conf"); |
|
506 |
- |
|
507 |
- std::ofstream conf; |
|
508 |
- conf.open (conf_file.str ().c_str ()); |
|
509 |
- conf << *zebra_conf; |
|
510 |
- if (zebra_conf->m_zebradebug) |
|
511 |
- { |
|
512 |
- conf << "debug zebra kernel" << std::endl; |
|
513 |
- conf << "debug zebra events" << std::endl; |
|
514 |
- // conf << "debug zebra route" << std::endl; |
|
515 |
- conf << "debug zebra packet" << std::endl; |
|
516 |
- } |
|
517 |
- |
|
518 |
- // radvd |
|
519 |
- for (std::vector<std::string>::iterator i = zebra_conf->m_radvd_if->begin (); |
|
520 |
- i != zebra_conf->m_radvd_if->end (); ++i) |
|
521 |
- { |
|
522 |
- conf << "interface " << (*i) << std::endl; |
|
523 |
- conf << " ipv6 nd ra-interval 5" << std::endl; |
|
524 |
- conf << " ipv6 nd prefix-advertisement" << std::endl; |
|
525 |
- conf << " no ipv6 nd suppress-ra" << std::endl; |
|
526 |
- conf << "!" << std::endl; |
|
527 |
- } |
|
528 |
- |
|
529 |
- // ha flag |
|
530 |
- for (std::vector<std::string>::iterator i = zebra_conf->m_haflag_if->begin (); |
|
531 |
- i != zebra_conf->m_haflag_if->end (); ++i) |
|
532 |
- { |
|
533 |
- conf << "interface " << (*i) << std::endl; |
|
534 |
- conf << " ipv6 nd home-agent-config-flag" << std::endl; |
|
535 |
- conf << "!" << std::endl; |
|
536 |
- } |
|
537 |
- |
|
538 |
- // egress IF |
|
539 |
- for (std::vector<std::string>::iterator i = zebra_conf->m_egress_if->begin (); |
|
540 |
- i != zebra_conf->m_egress_if->end (); ++i) |
|
541 |
- { |
|
542 |
- conf << "interface " << (*i) << std::endl; |
|
543 |
- conf << " ipv6 nd td egress" << std::endl; |
|
544 |
- conf << "!" << std::endl; |
|
545 |
- } |
|
546 |
- |
|
547 |
- for (std::vector<uint32_t>::iterator i = zebra_conf->iflist.begin (); |
|
548 |
- i != zebra_conf->iflist.end (); |
|
549 |
- i++) |
|
550 |
- { |
|
551 |
- conf << "interface eth" << *i << std::endl; |
|
552 |
- } |
|
553 |
- |
|
554 |
-#if 0 |
|
555 |
- if (zebra_conf->m_tdpenable) |
|
556 |
- { |
|
557 |
- conf << "interface sim0" << std::endl; |
|
558 |
- conf << " ipv6 nd ra-interval 5" << std::endl; |
|
559 |
- conf << " ipv6 nd prefix-advertisement" << std::endl; |
|
560 |
- conf << " no ipv6 nd suppress-ra" << std::endl; |
|
561 |
- conf << " ipv6 nd home-agent-config-flag" << std::endl; |
|
562 |
- conf << "!" << std::endl; |
|
563 |
- |
|
564 |
- conf << "interface sim1" << std::endl; |
|
565 |
- // conf << " ipv6 nd td ingress" << std::endl; |
|
566 |
- conf << " ipv6 nd ra-interval 5" << std::endl; |
|
567 |
- conf << " ipv6 nd prefix-advertisement" << std::endl; |
|
568 |
- conf << " no ipv6 nd suppress-ra" << std::endl; |
|
569 |
- conf << " ipv6 nd home-agent-config-flag" << std::endl; |
|
570 |
- conf << "!" << std::endl; |
|
571 |
- |
|
572 |
- conf << "interface sim2" << std::endl; |
|
573 |
- // conf << " ipv6 nd td ingress" << std::endl; |
|
574 |
- conf << " ipv6 nd ra-interval 5" << std::endl; |
|
575 |
- conf << " ipv6 nd prefix-advertisement" << std::endl; |
|
576 |
- conf << " no ipv6 nd suppress-ra" << std::endl; |
|
577 |
- conf << " ipv6 nd home-agent-config-flag" << std::endl; |
|
578 |
- conf << "!" << std::endl; |
|
579 |
- |
|
580 |
- conf << "interface sim3" << std::endl; |
|
581 |
- conf << " ipv6 nd ra-interval 5" << std::endl; |
|
582 |
- conf << " ipv6 nd prefix-advertisement" << std::endl; |
|
583 |
- conf << " no ipv6 nd suppress-ra" << std::endl; |
|
584 |
- conf << " ipv6 nd home-agent-config-flag" << std::endl; |
|
585 |
- conf << "!" << std::endl; |
|
586 |
- |
|
587 |
- conf << "interface sim4" << std::endl; |
|
588 |
- conf << " ipv6 nd ra-interval 5" << std::endl; |
|
589 |
- conf << " ipv6 nd prefix-advertisement" << std::endl; |
|
590 |
- conf << " no ipv6 nd suppress-ra" << std::endl; |
|
591 |
- conf << "!" << std::endl; |
|
592 |
- |
|
593 |
- conf << "interface sim5" << std::endl; |
|
594 |
- conf << " ipv6 nd ra-interval 5" << std::endl; |
|
595 |
- conf << " ipv6 nd prefix-advertisement" << std::endl; |
|
596 |
- conf << " no ipv6 nd suppress-ra" << std::endl; |
|
597 |
- conf << "!" << std::endl; |
|
598 |
- } |
|
599 |
-#endif |
|
600 |
- |
|
601 |
- conf.close (); |
|
602 |
- |
|
603 |
-} |
|
604 |
- |
|
605 |
-void |
|
606 |
-QuaggaHelper::GenerateConfigOspf (Ptr<Node> node) |
|
607 |
-{ |
|
608 |
- NS_LOG_FUNCTION (node); |
|
609 |
- |
|
610 |
- Ptr<OspfConfig> ospf_conf = node->GetObject<OspfConfig>(); |
|
611 |
- Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
|
612 |
- |
|
613 |
- ospf_conf->m_routerId = 1+node->GetId (); |
|
614 |
- |
|
615 |
- NS_LOG_DEBUG ("ipv4->GetNInterfaces () = " << ipv4->GetNInterfaces ()); |
|
616 |
- |
|
617 |
- for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i ++) |
|
618 |
- { |
|
619 |
- Ipv4Address addr = ipv4->GetAddress (i, 0).GetLocal (); |
|
620 |
- Ipv4Mask mask = ipv4->GetAddress (i, 0).GetMask (); |
|
621 |
- Ipv4Address prefix = addr.CombineMask (mask); |
|
622 |
- |
|
623 |
- NS_LOG_DEBUG ("address: " << addr); |
|
624 |
- |
|
625 |
- if (addr.IsEqual (Ipv4Address::GetLoopback())) |
|
626 |
- { |
|
627 |
- continue; |
|
628 |
- } |
|
629 |
- |
|
630 |
- ospf_conf->iflist->push_back (i); |
|
631 |
- ospf_conf->addNetwork (prefix, mask.GetPrefixLength (), 0); |
|
632 |
- } |
|
633 |
- |
|
634 |
- // config generation |
|
635 |
- std::stringstream conf_dir, conf_file; |
|
636 |
- // FIXME XXX |
|
637 |
- conf_dir << "files-" << node->GetId () << ""; |
|
638 |
- ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG); |
|
639 |
- conf_dir << "/usr/"; |
|
640 |
- ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG); |
|
641 |
- conf_dir << "/local/"; |
|
642 |
- ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG); |
|
643 |
- conf_dir << "/etc/"; |
|
644 |
- ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG); |
|
645 |
- |
|
646 |
- conf_file << conf_dir.str() << "/ospfd.conf"; |
|
647 |
- ospf_conf->SetFilename ("/usr/local/etc/ospfd.conf"); |
|
648 |
- |
|
649 |
- std::ofstream conf; |
|
650 |
- conf.open (conf_file.str ().c_str ()); |
|
651 |
- ospf_conf->Print (conf); |
|
652 |
- conf.close (); |
|
653 |
- |
|
654 |
-} |
|
655 |
- |
|
656 |
- |
|
657 |
-ApplicationContainer |
|
658 |
-QuaggaHelper::Install (Ptr<Node> node) |
|
659 |
-{ |
|
660 |
- return ApplicationContainer (InstallPriv (node)); |
|
661 |
-} |
|
662 |
- |
|
663 |
-ApplicationContainer |
|
664 |
-QuaggaHelper::Install (std::string nodeName) |
|
665 |
-{ |
|
666 |
- Ptr<Node> node = Names::Find<Node> (nodeName); |
|
667 |
- return ApplicationContainer (InstallPriv (node)); |
|
668 |
-} |
|
669 |
- |
|
670 |
-ApplicationContainer |
|
671 |
-QuaggaHelper::Install (NodeContainer c) |
|
672 |
-{ |
|
673 |
- ApplicationContainer apps; |
|
674 |
- for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) |
|
675 |
- { |
|
676 |
- apps.Add (InstallPriv (*i)); |
|
677 |
- } |
|
678 |
- |
|
679 |
- return apps; |
|
680 |
-} |
|
681 |
- |
|
682 |
-ApplicationContainer |
|
683 |
-QuaggaHelper::InstallPriv (Ptr<Node> node) |
|
684 |
-{ |
|
685 |
- DceApplicationHelper process; |
|
686 |
- ApplicationContainer apps; |
|
687 |
- |
|
688 |
- Ptr<QuaggaConfig> zebra_conf = node->GetObject<QuaggaConfig>(); |
|
689 |
- if (!zebra_conf) |
|
690 |
- { |
|
691 |
- zebra_conf = new QuaggaConfig (); |
|
692 |
- node->AggregateObject (zebra_conf); |
|
693 |
- } |
|
694 |
- GenerateConfigZebra (node); |
|
695 |
- process.SetBinary ("zebra"); |
|
696 |
- process.AddArguments ("-f", zebra_conf->GetFilename ()); |
|
697 |
- process.AddArguments ("-i", "/usr/local/etc/zebra.pid"); |
|
698 |
- process.SetStackSize (1<<16); |
|
699 |
- apps.Add (process.Install (node)); |
|
700 |
- apps.Get(0)->SetStartTime (Seconds (1.0 + 0.01 * node->GetId ())); |
|
701 |
- node->AddApplication (apps.Get (0)); |
|
702 |
- |
|
703 |
- Ptr<OspfConfig> ospf_conf = node->GetObject<OspfConfig>(); |
|
704 |
- // OSPF |
|
705 |
- if (ospf_conf) |
|
706 |
- { |
|
707 |
- GenerateConfigOspf (node); |
|
708 |
- process.ResetArguments (); |
|
709 |
- |
|
710 |
- process.SetBinary ("ospfd"); |
|
711 |
- process.AddArguments ("-f", ospf_conf->GetFilename ()); |
|
712 |
- process.AddArguments ("-i", "/usr/local/etc/ospfd.pid"); |
|
713 |
- apps.Add (process.Install (node)); |
|
714 |
- apps.Get(1)->SetStartTime (Seconds (2.0 + 0.1 * node->GetId ())); |
|
715 |
- node->AddApplication (apps.Get (1)); |
|
716 |
- } |
|
717 |
- |
|
718 |
- return apps; |
|
719 |
-} |
|
720 |
- |
|
721 |
-} // namespace ns3 |
|
722 |
diff -r 28c0c7f781c1 helper/quagga-helper.h |
|
723 |
--- a/helper/quagga-helper.h Thu Mar 29 17:00:46 2012 +0200 |
|
724 |
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
725 |
@@ -1,100 +0,0 @@ |
|
726 |
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
|
727 |
-/* |
|
728 |
- * Copyright (c) 2010 Hajime Tazaki |
|
729 |
- * |
|
730 |
- * This program is free software; you can redistribute it and/or modify |
|
731 |
- * it under the terms of the GNU General Public License version 2 as |
|
732 |
- * published by the Free Software Foundation; |
|
733 |
- * |
|
734 |
- * This program is distributed in the hope that it will be useful, |
|
735 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
736 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
737 |
- * GNU General Public License for more details. |
|
738 |
- * |
|
739 |
- * You should have received a copy of the GNU General Public License |
|
740 |
- * along with this program; if not, write to the Free Software |
|
741 |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
742 |
- * |
|
743 |
- * Author: Hajime Tazaki <tazaki@sfc.wide.ad.jp> |
|
744 |
- */ |
|
745 |
-#ifndef QUAGGA_HELPER_H |
|
746 |
-#define QUAGGA_HELPER_H |
|
747 |
- |
|
748 |
-#include "dce-manager-helper.h" |
|
749 |
-#include "dce-application-helper.h" |
|
750 |
- |
|
751 |
-namespace ns3 { |
|
752 |
- |
|
753 |
-/** |
|
754 |
- * \brief create a quagga routing daemon as an application and associate it to a node |
|
755 |
- * |
|
756 |
- * This class creates one or multiple instances of ns3::Quagga and associates |
|
757 |
- * it/them to one/multiple node(s). |
|
758 |
- */ |
|
759 |
-class QuaggaHelper |
|
760 |
-{ |
|
761 |
-public: |
|
762 |
- /** |
|
763 |
- * Create a QuaggaHelper which is used to make life easier for people wanting |
|
764 |
- * to use quagga Applications. |
|
765 |
- * |
|
766 |
- */ |
|
767 |
- QuaggaHelper (); |
|
768 |
- /** |
|
769 |
- * Install a quagga application on each Node in the provided NodeContainer. |
|
770 |
- * |
|
771 |
- * \param nodes The NodeContainer containing all of the nodes to get a quagga |
|
772 |
- * application via ProcessManager. |
|
773 |
- * |
|
774 |
- * \returns A list of quagga applications, one for each input node |
|
775 |
- */ |
|
776 |
- ApplicationContainer Install (NodeContainer nodes); |
|
777 |
- |
|
778 |
- /** |
|
779 |
- * Install a quagga application on the provided Node. The Node is specified |
|
780 |
- * directly by a Ptr<Node> |
|
781 |
- * |
|
782 |
- * \param node The node to install the QuaggaApplication on. |
|
783 |
- * |
|
784 |
- * \returns An ApplicationContainer holding the quagga application created. |
|
785 |
- */ |
|
786 |
- ApplicationContainer Install (Ptr<Node> node); |
|
787 |
- |
|
788 |
- /** |
|
789 |
- * Install a quagga application on the provided Node. The Node is specified |
|
790 |
- * by a string that must have previosly been associated with a Node using the |
|
791 |
- * Object Name Service. |
|
792 |
- * |
|
793 |
- * \param nodeName The node to install the ProcessApplication on. |
|
794 |
- * |
|
795 |
- * \returns An ApplicationContainer holding the quagga application created. |
|
796 |
- */ |
|
797 |
- ApplicationContainer Install (std::string nodeName); |
|
798 |
- |
|
799 |
- /** |
|
800 |
- * \brief Configure ping applications attribute |
|
801 |
- * \param name attribute's name |
|
802 |
- * \param value attribute's value |
|
803 |
- */ |
|
804 |
- void SetAttribute (std::string name, const AttributeValue &value); |
|
805 |
- |
|
806 |
- void EnableOspf (NodeContainer nodes); |
|
807 |
- void EnableOspfDebug (NodeContainer nodes); |
|
808 |
- void EnableTdpNina (NodeContainer nodes); |
|
809 |
- void EnableZebraDebug (NodeContainer nodes); |
|
810 |
- void EnableRadvd (Ptr<Node> node, const char *ifname); |
|
811 |
- void EnableEgressIF (Ptr<Node> node, const char *ifname); |
|
812 |
- void EnableHomeAgentFlag (Ptr<Node> node, const char *ifname); |
|
813 |
- void UseManualConfig (NodeContainer nodes); |
|
814 |
-private: |
|
815 |
- /** |
|
816 |
- * \internal |
|
817 |
- */ |
|
818 |
- ApplicationContainer InstallPriv (Ptr<Node> node); |
|
819 |
- void GenerateConfigZebra (Ptr<Node> node); |
|
820 |
- void GenerateConfigOspf (Ptr<Node> node); |
|
821 |
-}; |
|
822 |
- |
|
823 |
-} // namespace ns3 |
|
824 |
- |
|
825 |
-#endif /* QUAGGA_HELPER_H */ |
|
13 | 826 |
diff -r 28c0c7f781c1 model/dce-fd.cc |
827 |
--- a/model/dce-fd.cc Thu Mar 29 17:00:46 2012 +0200 |
|
18 | 828 |
+++ b/model/dce-fd.cc Wed Apr 11 10:56:47 2012 +0900 |
13 | 829 |
@@ -345,12 +345,6 @@ |
830 |
||
831 |
Ptr<SocketFdFactory> factory = 0; |
|
832 |
||
833 |
- if ( domain == AF_INET6 ) |
|
834 |
- { |
|
835 |
- current->err = EAFNOSUPPORT; |
|
836 |
- return -1; |
|
837 |
- } |
|
838 |
- |
|
839 |
if (domain != AF_UNIX) |
|
840 |
{ |
|
841 |
factory = manager->GetObject<SocketFdFactory> (); |
|
12 | 842 |
diff -r 28c0c7f781c1 model/libc-ns3.h |
843 |
--- a/model/libc-ns3.h Thu Mar 29 17:00:46 2012 +0200 |
|
18 | 844 |
+++ b/model/libc-ns3.h Wed Apr 11 10:56:47 2012 +0900 |
1 | 845 |
@@ -412,7 +412,7 @@ |
846 |
DCE (ftruncate) |
|
847 |
||
848 |
// pwd.h |
|
849 |
-//NATIVE (getpwnam) |
|
850 |
+NATIVE (getpwnam) |
|
851 |
// grp.h |
|
852 |
NATIVE (getgrnam) |
|
853 |
||
854 |
@@ -461,7 +461,7 @@ |
|
855 |
NATIVE (__ctype_get_mb_cur_max) |
|
856 |
||
857 |
// pwd.h |
|
858 |
-DCE (getpwnam) |
|
859 |
+//DCE (getpwnam) |
|
860 |
DCE (getpwuid) |
|
861 |
DCE (endpwent) |
|
862 |
||
12 | 863 |
diff -r 28c0c7f781c1 model/linux-socket-fd-factory.cc |
864 |
--- a/model/linux-socket-fd-factory.cc Thu Mar 29 17:00:46 2012 +0200 |
|
18 | 865 |
+++ b/model/linux-socket-fd-factory.cc Wed Apr 11 10:56:47 2012 +0900 |
12 | 866 |
@@ -254,6 +254,10 @@ |
867 |
{ |
|
868 |
LinuxSocketFdFactory *self = (LinuxSocketFdFactory *)kernel; |
|
869 |
TaskManager *manager = TaskManager::Current (); |
|
870 |
+ if (!manager) |
|
871 |
+ { |
|
872 |
+ return 1; |
|
873 |
+ } |
|
874 |
Task *other = (Task *)self->m_exported->task_get_private (task); |
|
875 |
bool isBlocked = other->IsBlocked (); |
|
876 |
manager->Wakeup (other); |
|
877 |
@@ -403,6 +407,10 @@ |
|
878 |
{ |
|
879 |
flags |= SIM_DEV_BROADCAST; |
|
880 |
} |
|
881 |
+ if (!device->NeedsArp ()) |
|
882 |
+ { |
|
883 |
+ flags |= SIM_DEV_NOARP; |
|
884 |
+ } |
|
885 |
struct SimDevice *dev = m_exported->dev_create (PeekPointer (device), (enum SimDevFlags)flags); |
|
886 |
||
887 |
Ptr<LinuxDeviceStateListener> listener = Create <LinuxDeviceStateListener> (device, this); |
|
888 |
diff -r 28c0c7f781c1 model/utils.cc |
|
889 |
--- a/model/utils.cc Thu Mar 29 17:00:46 2012 +0200 |
|
18 | 890 |
+++ b/model/utils.cc Wed Apr 11 10:56:47 2012 +0900 |
12 | 891 |
@@ -191,6 +191,11 @@ |
892 |
void UtilsDoSignal (void) |
|
893 |
{ |
|
894 |
Thread *current = Current (); |
|
895 |
+ if (!current) |
|
896 |
+ { |
|
897 |
+ return; |
|
898 |
+ } |
|
899 |
+ |
|
900 |
// we try to check if we |
|
901 |
// have pending signals and we deliver them if we have any. |
|
902 |
for (std::vector<SignalHandler>::iterator i = current->process->signalHandlers.begin (); |
|
13 | 903 |
diff -r 28c0c7f781c1 test/dce-manager-test.cc |
904 |
--- a/test/dce-manager-test.cc Thu Mar 29 17:00:46 2012 +0200 |
|
18 | 905 |
+++ b/test/dce-manager-test.cc Wed Apr 11 10:56:47 2012 +0900 |
13 | 906 |
@@ -161,13 +161,15 @@ |
907 |
{ "test-random", 0, "", false }, |
|
908 |
{ "test-local-socket", 0, "", false }, |
|
909 |
{ "test-poll", 3200, "", true }, |
|
910 |
- { "test-tcp-socket", 320, "", true }, |
|
911 |
+ // { "test-tcp-socket", 320, "", true }, |
|
912 |
{ "test-exec", 0, "" , false}, |
|
913 |
/* { "test-raw-socket", 320, "", true },*/ |
|
914 |
{ "test-iperf", 0, "" , false}, |
|
915 |
{ "test-name", 0, "" , false}, |
|
916 |
{ "test-pipe", 0, "" , false}, |
|
917 |
{ "test-dirent", 0, "" , false}, |
|
18 | 918 |
+ { "test-socket", 30, "" , true}, |
919 |
+ { "test-bug-multi-select", 30, "" , true}, |
|
13 | 920 |
}; |
921 |
||
922 |
// Prepare directories and files for test-stdio |
|
12 | 923 |
diff -r 28c0c7f781c1 test/test-bug-multi-select.cc |
0 | 924 |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
18 | 925 |
+++ b/test/test-bug-multi-select.cc Wed Apr 11 10:56:47 2012 +0900 |
12 | 926 |
@@ -0,0 +1,199 @@ |
927 |
+#include <stdio.h> |
|
928 |
+#include <sys/select.h> |
|
929 |
+#include <sys/types.h> |
|
930 |
+#include <sys/socket.h> |
|
931 |
+#include <netinet/ip.h> |
|
932 |
+#include <string.h> |
|
933 |
+#include <unistd.h> |
|
934 |
+#include <fcntl.h> |
|
935 |
+#include <errno.h> |
|
936 |
+ |
|
937 |
+#define SND_CNT 50 |
|
938 |
+ |
|
939 |
+static int |
|
940 |
+sv () |
|
941 |
+{ |
|
942 |
+ int ret; |
|
943 |
+ int accept_sock, sock; |
|
944 |
+ struct sockaddr_in addr, client; |
|
945 |
+ fd_set readfd; |
|
946 |
+ int val; |
|
947 |
+ socklen_t len = sizeof (client); |
|
948 |
+ char buf[1024]; |
|
949 |
+ int i = 0; |
|
950 |
+ |
|
951 |
+#ifdef DEBUG |
|
952 |
+ printf ("Server Start \n"); |
|
953 |
+#endif |
|
954 |
+ |
|
955 |
+ accept_sock = socket (AF_INET, SOCK_STREAM, 0); |
|
956 |
+ if (accept_sock < 0) |
|
957 |
+ { |
|
958 |
+ perror ("socket"); |
|
959 |
+ return -1; |
|
960 |
+ } |
|
961 |
+ |
|
962 |
+ memset (&addr, 0, sizeof (struct sockaddr_in)); |
|
963 |
+ addr.sin_family = AF_INET; |
|
964 |
+ addr.sin_port = htons (10001); |
|
965 |
+ addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
|
966 |
+ |
|
967 |
+ ret = bind (accept_sock, (struct sockaddr *)&addr, |
|
968 |
+ sizeof (struct sockaddr_in)); |
|
969 |
+ if (ret < 0) |
|
970 |
+ { |
|
971 |
+ perror ("bind"); |
|
972 |
+ return -1; |
|
973 |
+ } |
|
974 |
+ |
|
975 |
+ ret = listen (accept_sock, 1); |
|
976 |
+ if (ret < 0) |
|
977 |
+ { |
|
978 |
+ perror ("listen"); |
|
979 |
+ return -1; |
|
980 |
+ } |
|
981 |
+ |
|
982 |
+ sock = accept (accept_sock, (struct sockaddr *) &client, &len); |
|
983 |
+ if (sock < 0) |
|
984 |
+ { |
|
985 |
+ perror ("accept"); |
|
986 |
+ return -1; |
|
987 |
+ } |
|
988 |
+ |
|
989 |
+#ifdef DEBUG |
|
990 |
+ printf ("accept\n"); |
|
991 |
+#endif |
|
992 |
+ val = fcntl (sock, F_GETFL, 0); |
|
993 |
+ fcntl (sock, F_SETFL, (val | O_NONBLOCK)); |
|
994 |
+ |
|
995 |
+ while (1) |
|
996 |
+ { |
|
997 |
+ struct timeval tv; |
|
998 |
+ memset (&tv, 0, sizeof(tv)); |
|
999 |
+ tv.tv_sec = 1; |
|
1000 |
+ tv.tv_usec = 0; |
|
1001 |
+ |
|
1002 |
+ i++; |
|
1003 |
+ if (i > SND_CNT * 3) |
|
1004 |
+ { |
|
1005 |
+ printf ("ERR: Giving up to recv data (try=%d)", i); |
|
1006 |
+ return -1; |
|
1007 |
+ } |
|
1008 |
+ |
|
1009 |
+ // printf ("select\n"); |
|
1010 |
+ FD_ZERO (&readfd); |
|
1011 |
+ FD_SET (sock, &readfd); |
|
1012 |
+ // Multiple fds in readfd |
|
1013 |
+ FD_SET (accept_sock, &readfd); |
|
1014 |
+ ret = select (FD_SETSIZE, &readfd, NULL, NULL, &tv); |
|
1015 |
+ if (ret == 0) |
|
1016 |
+ { |
|
1017 |
+#ifdef DEBUG |
|
1018 |
+ printf ("timeout\n"); |
|
1019 |
+#endif |
|
1020 |
+ continue; |
|
1021 |
+ } |
|
1022 |
+ |
|
1023 |
+ if (ret < 0) |
|
1024 |
+ { |
|
1025 |
+ if (errno == EINTR || errno == EAGAIN) |
|
1026 |
+ continue; |
|
1027 |
+ |
|
1028 |
+ perror ("select"); |
|
1029 |
+ return -1; |
|
1030 |
+ } |
|
1031 |
+ |
|
1032 |
+ // To increase read buffer |
|
1033 |
+ if (i%3 == 0) |
|
1034 |
+ { |
|
1035 |
+ i++; |
|
1036 |
+ continue; |
|
1037 |
+ } |
|
1038 |
+ |
|
1039 |
+ ret = read (sock, buf, sizeof(buf)); |
|
1040 |
+ if (ret == 0) |
|
1041 |
+ return 0; |
|
1042 |
+ else if (ret < 0) |
|
1043 |
+ { |
|
1044 |
+ perror ("read, exit"); |
|
1045 |
+ return -1; |
|
1046 |
+ } |
|
1047 |
+#ifdef DEBUG |
|
1048 |
+ printf ("recv[%d]: %s\n", i, buf); |
|
1049 |
+#endif |
|
1050 |
+ } |
|
1051 |
+ |
|
1052 |
+ |
|
1053 |
+#ifdef DEBUG |
|
1054 |
+ printf ("Server Stop \n"); |
|
1055 |
+#endif |
|
1056 |
+ return 0; |
|
1057 |
+} |
|
1058 |
+ |
|
1059 |
+ |
|
1060 |
+static int |
|
1061 |
+cl () |
|
1062 |
+{ |
|
1063 |
+ int ret; |
|
1064 |
+ int sock; |
|
1065 |
+ struct sockaddr_in addr; |
|
1066 |
+ const char buf[512] = "01234567890123456789012345678901234567890123456789\0"; // 50 chars |
|
1067 |
+ int i = 0, sndcnt = SND_CNT; |
|
1068 |
+ |
|
1069 |
+#ifdef DEBUG |
|
1070 |
+ printf ("Client Start \n"); |
|
1071 |
+#endif |
|
1072 |
+ |
|
1073 |
+ sock = socket (AF_INET, SOCK_STREAM, 0); |
|
1074 |
+ if (sock < 0) |
|
1075 |
+ { |
|
1076 |
+ perror ("socket"); |
|
1077 |
+ return -1; |
|
1078 |
+ } |
|
1079 |
+ |
|
1080 |
+ memset (&addr, 0, sizeof (struct sockaddr_in)); |
|
1081 |
+ addr.sin_family = AF_INET; |
|
1082 |
+ addr.sin_port = htons (10001); |
|
1083 |
+ addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
|
1084 |
+ |
|
1085 |
+ ret = connect (sock, (struct sockaddr *)&addr, |
|
1086 |
+ sizeof (struct sockaddr_in)); |
|
1087 |
+ if (ret < 0) |
|
1088 |
+ { |
|
1089 |
+ perror ("connect"); |
|
1090 |
+ return -1; |
|
1091 |
+ } |
|
1092 |
+ |
|
1093 |
+ while (i < sndcnt) |
|
1094 |
+ { |
|
1095 |
+ ret = write (sock, buf, sizeof(buf)); |
|
1096 |
+ if (ret < 0) |
|
1097 |
+ { |
|
1098 |
+ perror ("write"); |
|
1099 |
+ return -1; |
|
1100 |
+ } |
|
1101 |
+ // printf ("write [%d] \n", i); |
|
1102 |
+ i++; |
|
1103 |
+ } |
|
1104 |
+ |
|
1105 |
+ |
|
1106 |
+#ifdef DEBUG |
|
1107 |
+ printf ("Client Stop \n"); |
|
1108 |
+#endif |
|
1109 |
+ return 0; |
|
1110 |
+} |
|
1111 |
+ |
|
1112 |
+int |
|
1113 |
+main (int argc, char *argv[]) |
|
1114 |
+{ |
|
1115 |
+ if (argc == 1) |
|
1116 |
+ { |
|
1117 |
+ return sv (); |
|
1118 |
+ } |
|
1119 |
+ else |
|
1120 |
+ { |
|
1121 |
+ return cl (); |
|
1122 |
+ } |
|
1123 |
+ |
|
1124 |
+ return 0; |
|
1125 |
+} |
|
1126 |
diff -r 28c0c7f781c1 test/test-socket.cc |
|
1127 |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
18 | 1128 |
+++ b/test/test-socket.cc Wed Apr 11 10:56:47 2012 +0900 |
12 | 1129 |
@@ -0,0 +1,395 @@ |
1130 |
+#define _GNU_SOURCE 1 |
|
1131 |
+#include <sys/types.h> |
|
1132 |
+#include <sys/socket.h> |
|
1133 |
+#include <netinet/in.h> |
|
1134 |
+#include <linux/netlink.h> |
|
1135 |
+#include <linux/rtnetlink.h> |
|
1136 |
+#include <errno.h> |
|
1137 |
+#include <sys/select.h> |
|
1138 |
+#include <pthread.h> |
|
1139 |
+#include <netinet/ip.h> |
|
1140 |
+#include "test-macros.h" |
|
1141 |
+ |
|
1142 |
+#undef OUTPUT |
|
1143 |
+#define OUTPUT(s) (std::cout << s << std::endl) |
|
1144 |
+ |
|
1145 |
+void test_raw (void) |
|
1146 |
+{ |
|
1147 |
+ int sock; |
|
1148 |
+ const char buf[12] = "0123456789\0"; |
|
1149 |
+ struct msghdr msg; |
|
1150 |
+ struct iovec iov[2]; |
|
1151 |
+ static struct sockaddr_in dst; |
|
1152 |
+ int ret; |
|
1153 |
+ int on = 1; |
|
1154 |
+ |
|
1155 |
+ // ICMP Raw sock |
|
1156 |
+ sock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP); |
|
1157 |
+ TEST_ASSERT_UNEQUAL (sock, -1); |
|
1158 |
+ |
|
1159 |
+ // sockopt IP_PKTINFO |
|
1160 |
+ ret = setsockopt (sock, IPPROTO_IP, IP_PKTINFO, &on, sizeof (on)); |
|
1161 |
+ TEST_ASSERT_UNEQUAL (sock, -1); |
|
1162 |
+ |
|
1163 |
+ // sendmsg |
|
1164 |
+ memset (&dst, 0, sizeof (dst)); |
|
1165 |
+ dst.sin_family = AF_INET; |
|
1166 |
+ dst.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
|
1167 |
+ |
|
1168 |
+ iov[0].iov_base = (void *) buf; |
|
1169 |
+ iov[0].iov_len = sizeof (buf); |
|
1170 |
+ msg.msg_name = &dst; |
|
1171 |
+ msg.msg_namelen = sizeof (dst); |
|
1172 |
+ msg.msg_iov = &iov[0]; |
|
1173 |
+ msg.msg_iovlen = 1; |
|
1174 |
+ msg.msg_control = NULL; |
|
1175 |
+ msg.msg_controllen = 0; |
|
1176 |
+ |
|
1177 |
+ ret = sendmsg (sock, &msg, 0); |
|
1178 |
+ TEST_ASSERT_EQUAL (ret, sizeof (buf)); |
|
1179 |
+ OUTPUT ("RAW send ret = " << ret); |
|
1180 |
+ |
|
1181 |
+ // recvmsg with MSG_PEEK |
|
1182 |
+ iov[0].iov_base = (void *) buf; |
|
1183 |
+ iov[0].iov_len = 2; |
|
1184 |
+ ret = recvmsg (sock, &msg, MSG_PEEK); |
|
1185 |
+ TEST_ASSERT_EQUAL (ret, 2); |
|
1186 |
+ OUTPUT ("RAW recv PEEK ret = " << ret); |
|
1187 |
+ |
|
1188 |
+ // recvmsg |
|
1189 |
+ struct in_pktinfo *pktinfo; |
|
1190 |
+ struct cmsghdr *cmsg; |
|
1191 |
+ char cbuff [sizeof (*cmsg) + sizeof (*pktinfo)]; |
|
1192 |
+ char buf2[32]; |
|
1193 |
+ iov[0].iov_base = (void *) buf2; |
|
1194 |
+ iov[0].iov_len = sizeof (buf2); |
|
1195 |
+ msg.msg_name = NULL; |
|
1196 |
+ msg.msg_namelen = 0; |
|
1197 |
+ msg.msg_iov = &iov[0]; |
|
1198 |
+ msg.msg_iovlen = 1; |
|
1199 |
+ msg.msg_control = cbuff; |
|
1200 |
+ msg.msg_controllen = CMSG_SPACE(sizeof (struct in_pktinfo)); |
|
1201 |
+ ret = recvmsg (sock, &msg, 0); |
|
1202 |
+ TEST_ASSERT_EQUAL (ret, sizeof (buf2)); |
|
1203 |
+ OUTPUT ("RAW recv ret = " << ret); |
|
1204 |
+ // std::cout << "RAW recv ret = " << ret << std::endl; |
|
1205 |
+ |
|
1206 |
+ // RECV interface via PKTINFO |
|
1207 |
+ cmsg = CMSG_FIRSTHDR (&msg); |
|
1208 |
+ pktinfo = (struct in_pktinfo *)CMSG_DATA(cmsg); |
|
18 | 1209 |
+ TEST_ASSERT_EQUAL (pktinfo->ipi_ifindex, 1); // Loopback Interface |
0 | 1210 |
+ |
1211 |
+ |
|
12 | 1212 |
+ // sockopt IP_HDRINCL |
1213 |
+ ret = setsockopt (sock, IPPROTO_IP, IP_HDRINCL, &on, sizeof (on)); |
|
1214 |
+ TEST_ASSERT_UNEQUAL (sock, -1); |
|
0 | 1215 |
+ |
12 | 1216 |
+ // sendmsg with IP_HDRINCL |
1217 |
+ struct ip iph; |
|
1218 |
+ memset (&iph, 0, sizeof (iph)); |
|
1219 |
+ iph.ip_hl = sizeof (struct ip) >> 2; |
|
1220 |
+ iph.ip_src = dst.sin_addr; |
|
1221 |
+ iph.ip_dst = dst.sin_addr; |
|
1222 |
+ iph.ip_p = IPPROTO_ICMP; |
|
1223 |
+ iph.ip_len = iph.ip_hl*4 + sizeof (buf); |
|
1224 |
+ iov[0].iov_base = (char*)&iph; |
|
1225 |
+ iov[0].iov_len = iph.ip_hl * 4; |
|
1226 |
+ iov[1].iov_base = (void *) buf; |
|
1227 |
+ iov[1].iov_len = sizeof (buf); |
|
1228 |
+ msg.msg_name = &dst; |
|
1229 |
+ msg.msg_namelen = sizeof (dst); |
|
1230 |
+ msg.msg_iov = iov; |
|
1231 |
+ msg.msg_iovlen = 2; |
|
1232 |
+ msg.msg_control = NULL; |
|
1233 |
+ msg.msg_controllen = 0; |
|
1234 |
+ |
|
1235 |
+ ret = sendmsg (sock, &msg, 0); |
|
1236 |
+ // XXX: FIXME to handle header size |
|
1237 |
+ TEST_ASSERT_EQUAL (ret, (int)sizeof (buf) + iph.ip_hl * 4); |
|
1238 |
+ // TEST_ASSERT_EQUAL (ret, (int)sizeof (buf) + ); |
|
1239 |
+ OUTPUT ("RAW send ret = " << ret); |
|
1240 |
+ |
|
1241 |
+ // recvmsg with long buf |
|
1242 |
+ char recvbuf[512]; |
|
1243 |
+ iov[0].iov_base = (void *) recvbuf; |
|
1244 |
+ iov[0].iov_len = sizeof (recvbuf); |
|
1245 |
+ ret = recvmsg (sock, &msg, 0); |
|
1246 |
+ TEST_ASSERT_EQUAL (ret, sizeof (buf) + 20); |
|
1247 |
+ OUTPUT ("RAW recv ret = " << ret); |
|
1248 |
+ |
|
1249 |
+ // close |
|
1250 |
+ // FIXME!! close () cause WakeupSend and died cause non-context switching |
|
1251 |
+ // close (sock); |
|
1252 |
+ // TEST_ASSERT_UNEQUAL (sock, -1); |
|
1253 |
+} |
|
1254 |
+ |
|
1255 |
+void test_udp (void) |
|
1256 |
+{ |
|
1257 |
+ int sock; |
|
1258 |
+ const char buf[12] = "0123456789\0"; |
|
1259 |
+ struct msghdr msg; |
|
1260 |
+ struct iovec iov; |
|
1261 |
+ static struct sockaddr_in dst; |
|
1262 |
+ int ret; |
|
1263 |
+ |
|
1264 |
+ // UDP Sock |
|
1265 |
+ sock = socket (AF_INET, SOCK_DGRAM, 0); |
|
1266 |
+ TEST_ASSERT_UNEQUAL (sock, -1); |
|
1267 |
+ |
|
1268 |
+ memset (&dst, 0, sizeof (dst)); |
|
1269 |
+ dst.sin_family = AF_INET; |
|
1270 |
+ dst.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
|
1271 |
+ dst.sin_port = htons (30); |
|
1272 |
+ |
|
1273 |
+ // bind |
|
1274 |
+ ret = bind (sock, (struct sockaddr *)&dst, sizeof (dst)); |
|
1275 |
+ TEST_ASSERT_UNEQUAL (ret, -1); |
|
1276 |
+ |
|
1277 |
+ // sendmsg |
|
1278 |
+ iov.iov_base = (void *) buf; |
|
1279 |
+ iov.iov_len = sizeof (buf); |
|
1280 |
+ msg.msg_name = &dst; |
|
1281 |
+ msg.msg_namelen = sizeof (dst); |
|
1282 |
+ msg.msg_iov = &iov; |
|
1283 |
+ msg.msg_iovlen = 1; |
|
1284 |
+ msg.msg_control = NULL; |
|
1285 |
+ msg.msg_controllen = 0; |
|
1286 |
+ |
|
1287 |
+ ret = sendmsg (sock, &msg, 0); |
|
1288 |
+ TEST_ASSERT_EQUAL (ret, sizeof (buf)); |
|
1289 |
+ OUTPUT ("UDP send ret = " << ret); |
|
1290 |
+ |
|
1291 |
+ // recvmsg |
|
1292 |
+ iov.iov_base = (void *) buf; |
|
1293 |
+ iov.iov_len = sizeof (buf); |
|
1294 |
+ ret = recvmsg (sock, &msg, 0); |
|
1295 |
+ TEST_ASSERT_EQUAL (ret, sizeof (buf)); |
|
1296 |
+ OUTPUT ("UDP recv ret = " << ret); |
|
1297 |
+ |
|
1298 |
+ // close |
|
1299 |
+ close (sock); |
|
1300 |
+ TEST_ASSERT_UNEQUAL (sock, -1); |
|
1301 |
+} |
|
1302 |
+ |
|
1303 |
+static void * |
|
1304 |
+thread_recv (void *arg) |
|
1305 |
+{ |
|
1306 |
+ int accept_sock = -1; |
|
1307 |
+ int sock = *(int *)arg; |
|
1308 |
+ int ret; |
|
1309 |
+ char buf[12]; |
|
1310 |
+ |
|
1311 |
+ while (1) |
|
1312 |
+ { |
|
1313 |
+ fd_set readfd; |
|
1314 |
+ struct timeval wait; |
|
1315 |
+ FD_ZERO (&readfd); |
|
1316 |
+ if (accept_sock == -1) |
|
1317 |
+ { |
|
1318 |
+ FD_SET (sock, &readfd); |
|
1319 |
+ } |
|
1320 |
+ else |
|
1321 |
+ { |
|
1322 |
+ FD_SET (accept_sock, &readfd); |
|
1323 |
+ } |
|
1324 |
+ wait.tv_sec = 1; |
|
1325 |
+ |
|
1326 |
+ ret = select (FD_SETSIZE, &readfd, NULL, NULL, &wait); |
|
1327 |
+ TEST_ASSERT_UNEQUAL (ret, 0); |
|
1328 |
+ if (errno == EINTR || errno == EAGAIN) |
|
1329 |
+ { |
|
1330 |
+ continue; |
|
1331 |
+ } |
|
1332 |
+ TEST_ASSERT_UNEQUAL (ret, -1); |
|
1333 |
+ |
|
1334 |
+ // accept |
|
1335 |
+ if (accept_sock == -1) |
|
1336 |
+ { |
|
1337 |
+ accept_sock = accept (sock, NULL, 0); |
|
1338 |
+ TEST_ASSERT_UNEQUAL (ret, -1); |
|
1339 |
+ OUTPUT ("TCP accepted ret = " << ret); |
|
1340 |
+ } |
|
1341 |
+ else |
|
1342 |
+ { |
|
1343 |
+ break; |
|
1344 |
+ } |
|
1345 |
+ } |
|
1346 |
+ |
|
1347 |
+ // recv |
|
1348 |
+ ret = recv (accept_sock, &buf, sizeof (buf), 0); |
|
1349 |
+ TEST_ASSERT_EQUAL (ret, sizeof (buf)); |
|
1350 |
+ OUTPUT ("TCP recv ret = " << ret); |
|
1351 |
+ |
|
1352 |
+ pthread_exit (arg); |
|
1353 |
+ // never reached. |
|
1354 |
+ TEST_ASSERT (false); |
|
1355 |
+ return arg; |
|
1356 |
+} |
|
1357 |
+ |
|
1358 |
+void test_tcp (void) |
|
1359 |
+{ |
|
1360 |
+ int sock, tx_sock; |
|
1361 |
+ const char buf[12] = "0123456789\0"; |
|
1362 |
+ static struct sockaddr_in dst; |
|
1363 |
+ int ret; |
|
1364 |
+ pthread_t thread; |
|
1365 |
+ |
|
1366 |
+ // TCP Sock |
|
1367 |
+ sock = socket (AF_INET, SOCK_STREAM, 0); |
|
1368 |
+ TEST_ASSERT_UNEQUAL (sock, -1); |
|
1369 |
+ |
|
1370 |
+ memset (&dst, 0, sizeof (dst)); |
|
1371 |
+ dst.sin_family = AF_INET; |
|
1372 |
+ dst.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
|
1373 |
+ dst.sin_port = htons (30); |
|
1374 |
+ |
|
1375 |
+ // bind |
|
1376 |
+ ret = bind (sock, (struct sockaddr *)&dst, sizeof (dst)); |
|
1377 |
+ TEST_ASSERT_UNEQUAL (ret, -1); |
|
1378 |
+ |
|
1379 |
+ // listen |
|
1380 |
+ ret = listen (sock, 5); |
|
1381 |
+ TEST_ASSERT_UNEQUAL (ret, -1); |
|
1382 |
+ |
|
1383 |
+ // recv thread |
|
1384 |
+ ret = pthread_create (&thread, NULL, |
|
1385 |
+ &thread_recv, |
|
1386 |
+ (void*)&sock); |
|
1387 |
+ |
|
1388 |
+ // tx sock |
|
1389 |
+ tx_sock = socket (AF_INET, SOCK_STREAM, 0); |
|
1390 |
+ TEST_ASSERT_UNEQUAL (tx_sock, -1); |
|
1391 |
+ // connect |
|
1392 |
+ ret = connect (tx_sock, (struct sockaddr *)&dst, sizeof (dst)); |
|
1393 |
+ TEST_ASSERT_UNEQUAL (ret, -1); |
|
0 | 1394 |
+ |
12 | 1395 |
+ // send |
1396 |
+ ret = send (tx_sock, &buf, sizeof (buf), 0); |
|
1397 |
+ TEST_ASSERT_EQUAL (ret, sizeof (buf)); |
|
1398 |
+ OUTPUT ("TCP send ret = " << ret); |
|
0 | 1399 |
+ |
12 | 1400 |
+ void *return_value; |
1401 |
+ ret = pthread_join (thread, &return_value); |
|
1402 |
+ |
|
1403 |
+ // close |
|
1404 |
+ close (sock); |
|
1405 |
+ TEST_ASSERT_UNEQUAL (sock, -1); |
|
1406 |
+ close (tx_sock); |
|
1407 |
+ TEST_ASSERT_UNEQUAL (tx_sock, -1); |
|
1408 |
+} |
|
1409 |
+ |
|
1410 |
+void test_netlink (void) |
|
1411 |
+{ |
|
1412 |
+ int sock; |
|
1413 |
+ int ret; |
|
1414 |
+ struct sockaddr_nl snl; |
|
1415 |
+ socklen_t namelen; |
|
1416 |
+ int seq = 0; |
|
1417 |
+ char buf[4096]; |
|
1418 |
+ struct iovec iov; |
|
1419 |
+ struct msghdr msg; |
|
1420 |
+ struct nlmsghdr *h; |
|
1421 |
+ struct ifaddrmsg *ifa; |
|
1422 |
+ |
|
1423 |
+ // Netlink sock |
|
1424 |
+ sock = socket (AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); |
|
1425 |
+ TEST_ASSERT_UNEQUAL (sock, -1); |
|
1426 |
+ |
|
1427 |
+ // Bind |
|
1428 |
+ memset (&snl, 0, sizeof snl); |
|
1429 |
+ snl.nl_family = AF_NETLINK; |
|
1430 |
+ snl.nl_groups = RTMGRP_LINK|RTMGRP_IPV4_ROUTE|RTMGRP_IPV4_IFADDR; |
|
1431 |
+ ret = bind (sock, (struct sockaddr *) &snl, sizeof snl); |
|
1432 |
+ TEST_ASSERT_UNEQUAL (sock, -1); |
|
1433 |
+ |
|
1434 |
+ // getsockname |
|
1435 |
+ namelen = sizeof (snl); |
|
1436 |
+ ret = getsockname (sock, (struct sockaddr *) &snl, &namelen); |
|
1437 |
+ TEST_ASSERT_UNEQUAL (ret, -1); |
|
1438 |
+ TEST_ASSERT_EQUAL (namelen, sizeof (snl)); |
|
1439 |
+ |
|
1440 |
+ // sendto |
|
1441 |
+ struct |
|
1442 |
+ { |
|
1443 |
+ struct nlmsghdr nlh; |
|
1444 |
+ struct rtgenmsg g; |
|
1445 |
+ } req; |
|
1446 |
+ |
|
1447 |
+ memset (&snl, 0, sizeof snl); |
|
1448 |
+ snl.nl_family = AF_NETLINK; |
|
1449 |
+ |
|
1450 |
+ // Get IPv4 Address |
|
1451 |
+ req.nlh.nlmsg_len = sizeof (req); |
|
1452 |
+ req.nlh.nlmsg_type = RTM_GETADDR; |
|
1453 |
+ req.nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST; |
|
1454 |
+ req.nlh.nlmsg_pid = 0; |
|
1455 |
+ req.nlh.nlmsg_seq = ++seq; |
|
1456 |
+ req.g.rtgen_family = AF_INET; |
|
1457 |
+ |
|
1458 |
+ ret = sendto (sock, (void *) &req, sizeof (req), 0, |
|
1459 |
+ (struct sockaddr *) &snl, sizeof (snl)); |
|
1460 |
+ TEST_ASSERT_EQUAL (ret, sizeof (req)); |
|
1461 |
+ |
|
1462 |
+ // recvmsg |
|
1463 |
+ iov.iov_base = (void *) buf; |
|
1464 |
+ iov.iov_len = sizeof (buf); |
|
1465 |
+ msg.msg_name = (void *)&snl; |
|
1466 |
+ msg.msg_namelen = sizeof (snl); |
|
1467 |
+ msg.msg_iov = &iov; |
|
1468 |
+ msg.msg_iovlen = 1; |
|
1469 |
+ msg.msg_control = NULL; |
|
1470 |
+ msg.msg_controllen = 0; |
|
1471 |
+ |
|
1472 |
+ ret = recvmsg (sock, &msg, 0); |
|
1473 |
+ TEST_ASSERT_UNEQUAL (ret, -1); |
|
1474 |
+ TEST_ASSERT_EQUAL (msg.msg_namelen, sizeof (snl)); |
|
1475 |
+ |
|
1476 |
+ // Code from zebra/rt_netlink.c |
|
1477 |
+ for (h = (struct nlmsghdr *) buf; NLMSG_OK (h, (uint32_t) ret); |
|
1478 |
+ h = NLMSG_NEXT (h, ret)) |
|
1479 |
+ { |
|
1480 |
+ if (h->nlmsg_type == NLMSG_DONE) |
|
1481 |
+ break; |
|
1482 |
+ |
|
1483 |
+ /* Error handling. */ |
|
1484 |
+ if (h->nlmsg_type == NLMSG_ERROR) |
|
1485 |
+ { |
|
1486 |
+ struct nlmsgerr *err = (struct nlmsgerr *) NLMSG_DATA (h); |
|
1487 |
+ /* If the error field is zero, then this is an ACK */ |
|
1488 |
+ if (err->error == 0) |
|
1489 |
+ { |
|
1490 |
+ // ACK |
|
1491 |
+ /* return if not a multipart message, otherwise continue */ |
|
1492 |
+ if (!(h->nlmsg_flags & NLM_F_MULTI)) |
|
1493 |
+ { |
|
1494 |
+ break; |
|
1495 |
+ } |
|
1496 |
+ continue; |
|
1497 |
+ } |
|
1498 |
+ |
|
1499 |
+ TEST_ASSERT (h->nlmsg_len >= NLMSG_LENGTH (sizeof (struct nlmsgerr))); |
|
1500 |
+ } |
|
1501 |
+ |
|
1502 |
+ ifa = (struct ifaddrmsg *) NLMSG_DATA (h); |
|
1503 |
+ TEST_ASSERT (ifa->ifa_family == AF_INET || ifa->ifa_family == AF_INET6); |
|
1504 |
+ OUTPUT ("NL: family = " << (int)ifa->ifa_family); |
|
1505 |
+ |
|
1506 |
+ TEST_ASSERT (h->nlmsg_type == RTM_NEWADDR || h->nlmsg_type == RTM_DELADDR); |
|
1507 |
+ TEST_ASSERT (h->nlmsg_len - NLMSG_LENGTH(sizeof (struct ifaddrmsg) >= 0)); |
|
1508 |
+ |
|
1509 |
+ // We didn't get into detail to parse attribute |
|
1510 |
+ } |
|
1511 |
+ |
|
1512 |
+ close (sock); |
|
1513 |
+ TEST_ASSERT_UNEQUAL (sock, -1); |
|
1514 |
+ |
|
1515 |
+} |
|
1516 |
+ |
|
1517 |
+int main (int argc, char *argv[]) |
|
1518 |
+{ |
|
1519 |
+ test_raw (); |
|
1520 |
+ test_udp (); |
|
1521 |
+ test_tcp (); |
|
1522 |
+ test_netlink (); |
|
1523 |
+ return 0; |
|
1524 |
+} |
|
1525 |
diff -r 28c0c7f781c1 test/wscript |
|
1526 |
--- a/test/wscript Thu Mar 29 17:00:46 2012 +0200 |
|
18 | 1527 |
+++ b/test/wscript Wed Apr 11 10:56:47 2012 +0900 |
12 | 1528 |
@@ -31,6 +31,8 @@ |
1529 |
new_test(bld, 'test-netdb', '') |
|
1530 |
new_test(bld, 'test-env', '') |
|
1531 |
new_test(bld, 'test-cond', 'PTHREAD') |
|
1532 |
+ new_test(bld, 'test-socket', 'PTHREAD') |
|
1533 |
+ new_test(bld, 'test-bug-multi-select', 'PTHREAD') |
|
1534 |
new_test(bld, 'test-timer-fd', '') |
|
1535 |
new_test(bld, 'test-stdlib', '') |
|
1536 |
new_test(bld, 'test-select', 'PTHREAD') |
|
1537 |
diff -r 28c0c7f781c1 utils/setenv.sh |
|
1538 |
--- a/utils/setenv.sh Thu Mar 29 17:00:46 2012 +0200 |
|
18 | 1539 |
+++ b/utils/setenv.sh Wed Apr 11 10:56:47 2012 +0900 |
12 | 1540 |
@@ -1,6 +1,6 @@ |
1541 |
#!/bin/bash |
|
1542 |
# Set environnement for ns3 dce |
|
1543 |
-cd `dirname $BASH_SOURCE`/../ |
|
1544 |
+cd `dirname ${BASH_SOURCE:-$0}`/../ |
|
1545 |
BASEDCE=$PWD |
|
1546 |
cd .. |
|
1547 |
BASE=$PWD |
|
1548 |
diff -r 28c0c7f781c1 wscript |
|
1549 |
--- a/wscript Thu Mar 29 17:00:46 2012 +0200 |
|
18 | 1550 |
+++ b/wscript Wed Apr 11 10:56:47 2012 +0900 |
12 | 1551 |
@@ -26,6 +26,7 @@ |
1552 |
ns3waf.check_modules(conf, ['point-to-point', 'tap-bridge', 'netanim'], mandatory = False) |
|
1553 |
ns3waf.check_modules(conf, ['wifi', 'point-to-point', 'csma', 'mobility'], mandatory = False) |
|
1554 |
ns3waf.check_modules(conf, ['point-to-point-layout'], mandatory = False) |
|
1555 |
+ ns3waf.check_modules(conf, ['topology-read', 'applications'], mandatory = False) |
|
1556 |
conf.check_tool('compiler_cc') |
|
1557 |
conf.check(header_name='stdint.h', define_name='HAVE_STDINT_H', mandatory=False) |
|
1558 |
conf.check(header_name='inttypes.h', define_name='HAVE_INTTYPES_H', mandatory=False) |
|
13 | 1559 |
@@ -163,7 +164,9 @@ |
1560 |
['test-iperf', []], |
|
1561 |
['test-name', []], |
|
1562 |
['test-pipe', []], |
|
1563 |
- ['test-dirent', []] |
|
1564 |
+ ['test-dirent', []], |
|
1565 |
+ ['test-socket', []], |
|
1566 |
+ ['test-bug-multi-select', []], |
|
1567 |
] |
|
1568 |
for name,uselib in tests: |
|
1569 |
module.add_test(**dce_kw(target='bin_dce/' + name, source = ['test/' + name + '.cc'], |
|
1570 |
@@ -235,10 +238,6 @@ |
|
12 | 1571 |
target='bin/dce-iperf', |
1572 |
source=['example/dce-iperf.cc', 'example/ccnx/misc-tools.cc']) |
|
1573 |
||
1574 |
- module.add_example(needed = ['core', 'internet', 'dce', 'point-to-point', 'point-to-point-layout'], |
|
1575 |
- target='bin/dce-zebra-simple', |
|
1576 |
- source=['example/dce-zebra-simple.cc']) |
|
1577 |
- |
|
1578 |
module.add_example(needed = ['core', 'internet', 'dce' ], |
|
1579 |
target='bin/dce-bash-simple', |
|
1580 |
source=['example/bash/dce-bash-simple.cc']) |
|
13 | 1581 |
@@ -380,7 +379,6 @@ |
12 | 1582 |
'helper/ipv4-dce-routing-helper.cc', |
1583 |
'helper/dce-manager-helper.cc', |
|
1584 |
'helper/dce-application-helper.cc', |
|
1585 |
- 'helper/quagga-helper.cc', |
|
1586 |
'helper/ccn-client-helper.cc' |
|
1587 |
] |
|
1588 |
module_headers = [ |
|
14
6f4976897048
add ipv4-dce-routing-helper to install
Hajime Tazaki <tazaki@nict.go.jp>
parents:
13
diff
changeset
|
1589 |
@@ -393,8 +391,8 @@ |
12 | 1590 |
'model/ipv4-dce-routing.h', |
1591 |
'helper/dce-manager-helper.h', |
|
1592 |
'helper/dce-application-helper.h', |
|
1593 |
- 'helper/quagga-helper.h', |
|
1594 |
'helper/ccn-client-helper.h', |
|
14
6f4976897048
add ipv4-dce-routing-helper to install
Hajime Tazaki <tazaki@nict.go.jp>
parents:
13
diff
changeset
|
1595 |
+ 'helper/ipv4-dce-routing-helper.h', |
12 | 1596 |
] |
1597 |
module_source = module_source + kernel_source |
|
14
6f4976897048
add ipv4-dce-routing-helper to install
Hajime Tazaki <tazaki@nict.go.jp>
parents:
13
diff
changeset
|
1598 |
module_headers = module_headers + kernel_headers |