26 #include "ns3/ipv4-static-routing-helper.h" |
26 #include "ns3/ipv4-static-routing-helper.h" |
27 #include "ns3/ipv4-global-routing-helper.h" |
27 #include "ns3/ipv4-global-routing-helper.h" |
28 #include "ns3/ipv4-interface.h" |
28 #include "ns3/ipv4-interface.h" |
29 #include "ns3/ipv4-global-routing.h" |
29 #include "ns3/ipv4-global-routing.h" |
30 #include "ns3/ipv4-routing-table-entry.h" |
30 #include "ns3/ipv4-routing-table-entry.h" |
31 #include "../../helper/dce-application-helper.h" |
31 #include "linux-stack-helper.h" |
32 #include "linux-ipv4-raw-socket-factory-impl.h" |
32 #include "linux-ipv4-raw-socket-factory-impl.h" |
33 #include "linux-udp-socket-factory-impl.h" |
33 #include "linux-udp-socket-factory-impl.h" |
34 #include "linux-tcp-socket-factory-impl.h" |
34 #include "linux-tcp-socket-factory-impl.h" |
35 #include "linux-dccp-socket-factory-impl.h" |
35 #include "linux-dccp-socket-factory-impl.h" |
36 |
36 |
37 NS_LOG_COMPONENT_DEFINE ("Ipv4Linux"); |
37 NS_LOG_COMPONENT_DEFINE ("Ipv4Linux"); |
38 |
38 |
39 namespace ns3 { |
39 namespace ns3 { |
40 |
40 |
41 NS_OBJECT_ENSURE_REGISTERED (Ipv4Linux); |
41 NS_OBJECT_ENSURE_REGISTERED (Ipv4Linux); |
42 |
|
43 static void |
|
44 RunIp (Ptr<Node> node, Time at, std::string str) |
|
45 { |
|
46 DceApplicationHelper process; |
|
47 ApplicationContainer apps; |
|
48 process.SetBinary ("ip"); |
|
49 process.SetStackSize (1 << 16); |
|
50 process.ResetArguments (); |
|
51 process.ParseArguments (str.c_str ()); |
|
52 apps = process.Install (node); |
|
53 apps.Start (at); |
|
54 } |
|
55 |
42 |
56 TypeId |
43 TypeId |
57 Ipv4Linux::GetTypeId (void) |
44 Ipv4Linux::GetTypeId (void) |
58 { |
45 { |
59 static TypeId tid = TypeId ("ns3::Ipv4Linux") |
46 static TypeId tid = TypeId ("ns3::Ipv4Linux") |
281 std::ostringstream oss; |
268 std::ostringstream oss; |
282 Ptr<Node> node = this->GetObject<Node> (); |
269 Ptr<Node> node = this->GetObject<Node> (); |
283 oss << "-f inet addr add "; |
270 oss << "-f inet addr add "; |
284 address.GetLocal ().Print (oss); |
271 address.GetLocal ().Print (oss); |
285 oss << '/' << address.GetMask ().GetPrefixLength () << " dev sim" << i; |
272 oss << '/' << address.GetMask ().GetPrefixLength () << " dev sim" << i; |
286 RunIp (node, NanoSeconds (++m_nanoSec), oss.str ()); |
273 LinuxStackHelper::RunIp (node, NanoSeconds (++m_nanoSec), oss.str ()); |
287 oss.str (""); |
274 oss.str (""); |
288 oss << "link set sim" << i << " up arp " |
275 oss << "link set sim" << i << " up arp " |
289 << ((interface->GetDevice ()->NeedsArp ()) ? "on" : "off"); |
276 << ((interface->GetDevice ()->NeedsArp ()) ? "on" : "off"); |
290 RunIp (node, NanoSeconds (++m_nanoSec), oss.str ()); |
277 LinuxStackHelper::RunIp (node, NanoSeconds (++m_nanoSec), oss.str ()); |
291 |
278 |
292 return retVal; |
279 return retVal; |
293 } |
280 } |
294 |
281 |
295 uint32_t |
282 uint32_t |
574 for (uint32_t i = 0; i < globalRouting->GetNRoutes (); i++) |
561 for (uint32_t i = 0; i < globalRouting->GetNRoutes (); i++) |
575 { |
562 { |
576 Ipv4RoutingTableEntry route = globalRouting->GetRoute (i); |
563 Ipv4RoutingTableEntry route = globalRouting->GetRoute (i); |
577 std::ostringstream oss; |
564 std::ostringstream oss; |
578 oss << "route add to " << route.GetDest () << '/' << route.GetDestNetworkMask () << " via " << route.GetGateway (); |
565 oss << "route add to " << route.GetDest () << '/' << route.GetDestNetworkMask () << " via " << route.GetGateway (); |
579 RunIp (node, NanoSeconds (++m_nanoSec), oss.str ()); |
566 LinuxStackHelper::RunIp (node, NanoSeconds (++m_nanoSec), oss.str ()); |
580 } |
567 } |
581 } |
568 } |
582 |
569 |
583 } |
570 } |