25 #include "ns3/ipv4-list-routing-helper.h"
26 #include "ns3/ipv4-static-routing-helper.h"
27 #include "ns3/ipv4-global-routing-helper.h"
28 #include "ns3/ipv4-interface.h"
29 #include "ns3/ipv4-global-routing.h"
30 #include "ns3/ipv4-routing-table-entry.h"
31 #include "../../helper/dce-application-helper.h"
44 RunIp (Ptr<Node> node, Time at, std::string str)
47 ApplicationContainer apps;
59 static TypeId tid = TypeId (
"ns3::Ipv4Linux")
61 .AddConstructor<Ipv4Linux> ();
69 NS_LOG_FUNCTION (
this);
74 NS_LOG_FUNCTION (
this);
80 NS_LOG_FUNCTION (
this);
85 Ptr<Ipv4RoutingProtocol>
88 NS_LOG_FUNCTION (
this);
95 NS_LOG_FUNCTION (
this << &device);
97 Ptr<Ipv4Interface>
interface = CreateObject<Ipv4Interface> ();
98 interface->SetDevice (device);
105 NS_LOG_FUNCTION (
this << interface);
114 NS_LOG_FUNCTION (
this);
121 NS_LOG_FUNCTION (
this);
123 int32_t
interface = 0;
124 for (Ipv4InterfaceList::const_iterator i =
m_interfaces.begin ();
128 for (uint32_t j = 0; j < (*i)->GetNAddresses (); j++)
130 if ((*i)->GetAddress (j).GetLocal () == address)
142 Ipv4Address destination, uint8_t protocol, Ptr<Ipv4Route> route)
144 NS_LOG_FUNCTION (
this <<
"empty method.");
150 NS_LOG_FUNCTION (
this <<
"empty method.");
156 NS_LOG_FUNCTION (
this <<
"empty method.");
165 Ipv4InterfaceAddress iaddr =
GetAddress (iif, i);
166 if (address == iaddr.GetLocal ())
168 NS_LOG_LOGIC (
"For me (destination " << address <<
" match)");
171 if (address == iaddr.GetBroadcast ())
173 NS_LOG_LOGIC (
"For me (interface broadcast address)");
178 if (address.IsMulticast ())
181 if (MulticastCheckGroup (iif, address))
185 NS_LOG_LOGIC (
"For me (Ipv4Addr multicast address");
190 if (address.IsBroadcast ())
192 NS_LOG_LOGIC (
"For me (Ipv4Addr broadcast address)");
200 if (j == uint32_t (iif))
206 Ipv4InterfaceAddress iaddr =
GetAddress (j, i);
207 if (address == iaddr.GetLocal ())
209 NS_LOG_LOGIC (
"For me (destination " << address <<
" match) on another interface");
213 if (address == iaddr.GetBroadcast ())
215 NS_LOG_LOGIC (
"For me (interface broadcast address on another interface)");
227 NS_LOG_FUNCTION (
this);
228 int32_t
interface = 0;
229 for (Ipv4InterfaceList::const_iterator i =
m_interfaces.begin ();
233 for (uint32_t j = 0; j < (*i)->GetNAddresses (); j++)
235 if ((*i)->GetAddress (j).GetLocal ().CombineMask (mask) == address.CombineMask (mask))
248 NS_LOG_FUNCTION (
this);
255 NS_LOG_FUNCTION (
this);
256 int32_t
interface = 0;
257 for (Ipv4InterfaceList::const_iterator i =
m_interfaces.begin ();
261 if ((*i)->GetDevice () == device)
273 NS_LOG_FUNCTION (
this << i << address);
275 bool retVal = interface->AddAddress (address);
281 std::ostringstream oss;
282 Ptr<Node> node = this->GetObject<Node> ();
283 oss <<
"-f inet addr add ";
284 address.GetLocal ().Print (oss);
285 oss <<
'/' << address.GetMask ().GetPrefixLength () <<
" dev sim" << i;
288 oss <<
"link set sim" << i <<
" up arp "
289 << ((interface->GetDevice ()->NeedsArp ()) ?
"on" :
"off");
299 return iface->GetNAddresses ();
305 NS_LOG_FUNCTION (
this);
306 Ptr<Ipv4Interface>
interface =
GetInterface (interfaceIndex);
307 return interface->GetAddress (addressIndex);
313 NS_LOG_FUNCTION (
this << i << addressIndex);
315 Ipv4InterfaceAddress address = interface->RemoveAddress (addressIndex);
316 if (address != Ipv4InterfaceAddress ())
330 NS_LOG_FUNCTION (
this << i << address);
332 if (address == Ipv4Address::GetLoopback())
334 NS_LOG_WARN (
"Cannot remove loopback address.");
338 Ipv4InterfaceAddress ifAddr = interface->RemoveAddress (address);
339 if (ifAddr != Ipv4InterfaceAddress ())
352 Ipv4Address dst, Ipv4InterfaceAddress::InterfaceAddressScope_e scope)
354 NS_LOG_FUNCTION (
this << device << dst << scope);
355 Ipv4Address addr (
"0.0.0.0");
356 Ipv4InterfaceAddress iaddr;
362 NS_ASSERT_MSG (i >= 0,
"No device found on node");
366 if (iaddr.IsSecondary ())
370 if (iaddr.GetScope () > scope)
374 if (dst.CombineMask (iaddr.GetMask ()) == iaddr.GetLocal ().CombineMask (iaddr.GetMask ()) )
376 return iaddr.GetLocal ();
380 addr = iaddr.GetLocal ();
396 if (iaddr.IsSecondary ())
400 if (iaddr.GetScope () != Ipv4InterfaceAddress::LINK
401 && iaddr.GetScope () <= scope)
403 return iaddr.GetLocal ();
407 NS_LOG_WARN (
"Could not find source address for " << dst <<
" and scope "
408 << scope <<
", returning 0");
415 NS_LOG_FUNCTION (
this << i << metric);
417 interface->SetMetric (metric);
424 return interface->GetMetric ();
431 return interface->GetDevice ()->GetMtu ();
438 return interface->IsUp ();
444 NS_LOG_FUNCTION (
this << i);
457 NS_LOG_FUNCTION (
this << ifaceIndex);
458 Ptr<Ipv4Interface>
interface =
GetInterface (ifaceIndex);
459 interface->SetDown ();
470 NS_LOG_FUNCTION (
this << i);
472 NS_LOG_LOGIC (
"Forwarding state: " << interface->IsForwarding ());
473 return interface->IsForwarding ();
479 NS_LOG_FUNCTION (
this << i);
481 interface->SetForwarding (val);
487 NS_LOG_FUNCTION (
this << forward);
491 (*i)->SetForwarding (forward);
516 ObjectFactory factory;
517 factory.SetTypeId (
"ns3::Ipv4Linux");
518 Ptr<Object> protocol = factory.Create <Object> ();
519 node->AggregateObject (protocol);
520 Ipv4GlobalRoutingHelper globalRouting;
522 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
523 Ptr<Ipv4RoutingProtocol> ipv4Routing = globalRouting.Create (node);
524 ipv4->SetRoutingProtocol (ipv4Routing);
526 Ptr<LinuxIpv4RawSocketFactoryImpl> ipv4rawFactory = CreateObject<LinuxIpv4RawSocketFactoryImpl> ();
527 node->AggregateObject (ipv4rawFactory);
528 Ptr<LinuxUdpSocketFactoryImpl> udpFactory = CreateObject<LinuxUdpSocketFactoryImpl> ();
529 node->AggregateObject (udpFactory);
530 Ptr<LinuxTcpSocketFactoryImpl> tcpFactory = CreateObject<LinuxTcpSocketFactoryImpl> ();
531 node->AggregateObject (tcpFactory);
532 Ptr<LinuxDccpSocketFactoryImpl> dccpFactory = CreateObject<LinuxDccpSocketFactoryImpl> ();
533 node->AggregateObject (dccpFactory);
570 Ptr<Node> node = this->GetObject<Node> ();
571 Ptr<Ipv4GlobalRouting> globalRouting = DynamicCast<Ipv4GlobalRouting> (
GetRoutingProtocol ());
572 NS_ASSERT_MSG (globalRouting,
"No global routing");
574 for (uint32_t i = 0; i < globalRouting->GetNRoutes (); i++)
576 Ipv4RoutingTableEntry route = globalRouting->GetRoute (i);
577 std::ostringstream oss;
578 oss <<
"route add to " << route.GetDest () <<
'/' << route.GetDestNetworkMask () <<
" via " << route.GetGateway ();