Add the IPv4 header before deciding whether to drop packets. Closes bug #135.
1 // -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
3 // Copyright (c) 2006 Georgia Tech Research Corporation
4 // All rights reserved.
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License version 2 as
8 // published by the Free Software Foundation;
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // Author: George F. Riley<riley@ece.gatech.edu>
22 #include "ns3/packet.h"
24 #include "ns3/composite-trace-resolver.h"
25 #include "ns3/callback.h"
26 #include "ns3/ipv4-address.h"
27 #include "ns3/ipv4-route.h"
29 #include "ns3/net-device.h"
31 #include "ipv4-l3-protocol.h"
32 #include "ipv4-l4-protocol.h"
33 #include "ipv4-header.h"
34 #include "ipv4-interface.h"
35 #include "ipv4-loopback-interface.h"
36 #include "arp-ipv4-interface.h"
37 #include "ipv4-l4-demux.h"
39 NS_LOG_COMPONENT_DEFINE ("Ipv4L3Protocol");
43 const uint16_t Ipv4L3Protocol::PROT_NUMBER = 0x0800;
45 NS_OBJECT_ENSURE_REGISTERED (Ipv4L3Protocol);
48 Ipv4L3Protocol::GetTypeId (void)
50 static TypeId tid = TypeId ("Ipv4L3Protocol")
51 .SetParent<Object> ();
55 Ipv4L3ProtocolTraceContextElement::Ipv4L3ProtocolTraceContextElement ()
61 Ipv4L3ProtocolTraceContextElement::Ipv4L3ProtocolTraceContextElement (enum Type type)
68 Ipv4L3ProtocolTraceContextElement::IsTx (void) const
75 Ipv4L3ProtocolTraceContextElement::IsRx (void) const
82 Ipv4L3ProtocolTraceContextElement::IsDrop (void) const
85 return m_type == DROP;
89 Ipv4L3ProtocolTraceContextElement::Print (std::ostream &os) const
108 Ipv4L3ProtocolTraceContextElement::GetUid (void)
111 static uint16_t uid = AllocateUid<Ipv4L3ProtocolTraceContextElement> ("Ipv4L3ProtocolTraceContextElement");
116 Ipv4L3ProtocolTraceContextElement::GetTypeName (void) const
119 return "ns3::Ipv4L3ProtocolTraceContextElement";
122 Ipv4L3ProtocolInterfaceIndex::Ipv4L3ProtocolInterfaceIndex ()
128 Ipv4L3ProtocolInterfaceIndex::Ipv4L3ProtocolInterfaceIndex (uint32_t index)
135 Ipv4L3ProtocolInterfaceIndex::Get (void) const
142 Ipv4L3ProtocolInterfaceIndex::Print (std::ostream &os) const
144 os << "ipv4-interface=" << m_index;
148 Ipv4L3ProtocolInterfaceIndex::GetUid (void)
151 static uint16_t uid = AllocateUid<Ipv4L3ProtocolInterfaceIndex> ("Ipv4L3ProtocolInterfaceIndex");
156 Ipv4L3ProtocolInterfaceIndex::GetTypeName (void) const
159 return "ns3::Ipv4L3ProtocolInterfaceIndex";
163 Ipv4L3Protocol::Ipv4L3Protocol(Ptr<Node> node)
166 m_identification (0),
170 m_staticRouting = CreateObject<Ipv4StaticRouting> ();
171 AddRoutingProtocol (m_staticRouting, 0);
175 Ipv4L3Protocol::~Ipv4L3Protocol ()
181 Ipv4L3Protocol::DoDispose (void)
184 m_interfaces.clear ();
186 m_staticRouting->Dispose ();
188 Object::DoDispose ();
192 Ipv4L3Protocol::SetupLoopback (void)
196 Ptr<Ipv4LoopbackInterface> interface = CreateObject<Ipv4LoopbackInterface> (m_node);
197 interface->SetAddress (Ipv4Address::GetLoopback ());
198 interface->SetNetworkMask (Ipv4Mask::GetLoopback ());
199 uint32_t index = AddIpv4Interface (interface);
200 AddHostRouteTo (Ipv4Address::GetLoopback (), index);
205 Ipv4L3Protocol::GetTraceResolver (void) const
209 Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
210 resolver->AddSource ("tx",
211 TraceDoc ("send ipv4 packet to outgoing interface",
212 "Ptr<const Packet>", "packet sent",
213 "uint32_t", "index of output ipv4 interface"),
214 m_txTrace, Ipv4L3ProtocolTraceContextElement(Ipv4L3ProtocolTraceContextElement::TX));
215 resolver->AddSource ("rx",
216 TraceDoc ("receive ipv4 packet from incoming interface",
217 "Ptr<const Packet>", "packet received",
218 "uint32_t", "index of input ipv4 interface"),
219 m_rxTrace, Ipv4L3ProtocolTraceContextElement(Ipv4L3ProtocolTraceContextElement::RX));
220 resolver->AddSource ("drop",
221 TraceDoc ("drop ipv4 packet",
222 "Ptr<const Packet>", "packet dropped"),
223 m_dropTrace, Ipv4L3ProtocolTraceContextElement (Ipv4L3ProtocolTraceContextElement::DROP));
224 resolver->AddArray ("interfaces",
225 m_interfaces.begin (), m_interfaces.end (),
226 Ipv4L3ProtocolInterfaceIndex ());
231 Ipv4L3Protocol::SetDefaultTtl (uint8_t ttl)
239 Ipv4L3Protocol::AddHostRouteTo (Ipv4Address dest,
244 NS_LOG_PARAMS (this << dest << nextHop << interface);
245 m_staticRouting->AddHostRouteTo (dest, nextHop, interface);
249 Ipv4L3Protocol::AddHostRouteTo (Ipv4Address dest,
253 NS_LOG_PARAMS (this << dest << interface);
254 m_staticRouting->AddHostRouteTo (dest, interface);
258 Ipv4L3Protocol::AddNetworkRouteTo (Ipv4Address network,
259 Ipv4Mask networkMask,
264 NS_LOG_PARAMS (this << network << networkMask << nextHop << interface);
265 m_staticRouting->AddNetworkRouteTo (network, networkMask, nextHop, interface);
269 Ipv4L3Protocol::AddNetworkRouteTo (Ipv4Address network,
270 Ipv4Mask networkMask,
274 NS_LOG_PARAMS (this << network << networkMask << interface);
275 m_staticRouting->AddNetworkRouteTo (network, networkMask, interface);
279 Ipv4L3Protocol::SetDefaultRoute (Ipv4Address nextHop,
283 NS_LOG_PARAMS (this << nextHop << interface);
284 m_staticRouting->SetDefaultRoute (nextHop, interface);
288 Ipv4L3Protocol::Lookup (
289 Ipv4Header const &ipHeader,
291 Ipv4RoutingProtocol::RouteReplyCallback routeReply)
294 NS_LOG_PARAMS (this << &ipHeader << packet << &routeReply);
296 Lookup (Ipv4RoutingProtocol::IF_INDEX_ANY, ipHeader, packet, routeReply);
300 Ipv4L3Protocol::Lookup (
302 Ipv4Header const &ipHeader,
304 Ipv4RoutingProtocol::RouteReplyCallback routeReply)
307 NS_LOG_PARAMS (this << ifIndex << &ipHeader << packet << &routeReply);
309 for (Ipv4RoutingProtocolList::const_iterator rprotoIter =
310 m_routingProtocols.begin ();
311 rprotoIter != m_routingProtocols.end ();
314 NS_LOG_LOGIC ("Requesting route");
315 if ((*rprotoIter).second->RequestRoute (ifIndex, ipHeader, packet,
320 if (ipHeader.GetDestination ().IsMulticast () &&
321 ifIndex == Ipv4RoutingProtocol::IF_INDEX_ANY)
323 NS_LOG_LOGIC ("Multicast destination with local source");
325 // We have a multicast packet originating from the current node and were not
326 // able to send it using the usual RequestRoute process. Since the usual
327 // process includes trying to use a default multicast route, this means that
328 // there was no specific route out of the node found, and there was no default
329 // multicast route set.
331 // The fallback position is to look for a default unicast route and use that
332 // to get the packet off the node if we have one.
334 Ipv4Route *route = m_staticRouting->GetDefaultRoute ();
338 NS_LOG_LOGIC ("Local source. Using unicast default route for "
341 routeReply (true, *route, packet, ipHeader);
348 routeReply (false, Ipv4Route (), packet, ipHeader);
352 Ipv4L3Protocol::AddRoutingProtocol (Ptr<Ipv4RoutingProtocol> routingProtocol,
356 NS_LOG_PARAMS (this << &routingProtocol << priority);
357 m_routingProtocols.push_back
358 (std::pair<int, Ptr<Ipv4RoutingProtocol> > (-priority, routingProtocol));
359 m_routingProtocols.sort ();
363 Ipv4L3Protocol::GetNRoutes (void)
366 return m_staticRouting->GetNRoutes ();
370 Ipv4L3Protocol::GetRoute (uint32_t index)
373 return m_staticRouting->GetRoute (index);
377 Ipv4L3Protocol::RemoveRoute (uint32_t index)
380 NS_LOG_PARAMS (this << index);
381 m_staticRouting->RemoveRoute (index);
385 Ipv4L3Protocol::AddMulticastRoute (Ipv4Address origin,
387 uint32_t inputInterface,
388 std::vector<uint32_t> outputInterfaces)
391 NS_LOG_PARAMS (this << origin << group << inputInterface << &outputInterfaces);
393 m_staticRouting->AddMulticastRoute (origin, group, inputInterface,
398 Ipv4L3Protocol::SetDefaultMulticastRoute (uint32_t outputInterface)
401 NS_LOG_PARAMS (this << outputInterface);
403 m_staticRouting->SetDefaultMulticastRoute (outputInterface);
407 Ipv4L3Protocol::GetNMulticastRoutes (void) const
410 return m_staticRouting->GetNMulticastRoutes ();
414 Ipv4L3Protocol::GetMulticastRoute (uint32_t index) const
417 NS_LOG_PARAMS (this << index);
418 return m_staticRouting->GetMulticastRoute (index);
422 Ipv4L3Protocol::RemoveMulticastRoute (Ipv4Address origin,
424 uint32_t inputInterface)
427 NS_LOG_PARAMS (this << origin << group << inputInterface);
428 m_staticRouting->RemoveMulticastRoute (origin, group, inputInterface);
432 Ipv4L3Protocol::RemoveMulticastRoute (uint32_t index)
435 NS_LOG_PARAMS (this << index);
436 m_staticRouting->RemoveMulticastRoute (index);
440 Ipv4L3Protocol::AddInterface (Ptr<NetDevice> device)
443 NS_LOG_PARAMS (this << &device);
444 Ptr<Ipv4Interface> interface = CreateObject<ArpIpv4Interface> (m_node, device);
445 return AddIpv4Interface (interface);
449 Ipv4L3Protocol::AddIpv4Interface (Ptr<Ipv4Interface>interface)
452 NS_LOG_PARAMS (this << interface);
453 uint32_t index = m_nInterfaces;
454 m_interfaces.push_back (interface);
460 Ipv4L3Protocol::GetInterface (uint32_t index) const
463 NS_LOG_PARAMS (this << index);
465 for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
477 Ipv4L3Protocol::GetNInterfaces (void) const
480 return m_nInterfaces;
484 Ipv4L3Protocol::FindInterfaceForAddr (Ipv4Address addr) const
487 NS_LOG_PARAMS (this << addr);
489 uint32_t ifIndex = 0;
490 for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
491 i != m_interfaces.end ();
494 if ((*i)->GetAddress () == addr)
500 NS_ASSERT_MSG(false, "Ipv4L3Protocol::FindInterfaceForAddr (): "
501 "Interface not found for IP address");
506 Ipv4L3Protocol::FindInterfaceForAddr (Ipv4Address addr, Ipv4Mask mask) const
509 NS_LOG_PARAMS (this << addr << mask);
511 uint32_t ifIndex = 0;
512 for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
513 i != m_interfaces.end ();
516 if ((*i)->GetAddress ().CombineMask (mask) == addr.CombineMask (mask))
522 NS_ASSERT_MSG(false, "Ipv4L3Protocol::FindInterfaceForAddr (): "
523 "Interface not found for masked IP address");
528 Ipv4L3Protocol::FindInterfaceForDevice (Ptr<const NetDevice> device)
531 NS_LOG_PARAMS (this << &device);
532 for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
534 if ((*i)->GetDevice () == device)
543 Ipv4L3Protocol::Receive( Ptr<NetDevice> device, Ptr<Packet> packet, uint16_t protocol, const Address &from)
546 NS_LOG_PARAMS (this << &device << packet << protocol << from);
548 NS_LOG_LOGIC ("Packet from " << from);
551 Ptr<Ipv4Interface> ipv4Interface;
552 for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
553 i != m_interfaces.end ();
557 if (ipv4Interface->GetDevice () == device)
559 m_rxTrace (packet, index);
565 packet->RemoveHeader (ipHeader);
567 if (!ipHeader.IsChecksumOk ())
572 if (Forwarding (index, packet, ipHeader, device))
577 NS_LOG_LOGIC ("Forward up");
578 ForwardUp (packet, ipHeader, ipv4Interface);
583 Ipv4L3Protocol::Send (Ptr<Packet> packet,
585 Ipv4Address destination,
589 NS_LOG_PARAMS (this << packet << source << destination << protocol);
593 ipHeader.SetSource (source);
594 ipHeader.SetDestination (destination);
595 ipHeader.SetProtocol (protocol);
596 ipHeader.SetPayloadSize (packet->GetSize ());
597 ipHeader.SetTtl (m_defaultTtl);
598 ipHeader.SetMayFragment ();
599 ipHeader.SetIdentification (m_identification);
603 if (destination.IsBroadcast ())
605 uint32_t ifaceIndex = 0;
606 for (Ipv4InterfaceList::iterator ifaceIter = m_interfaces.begin ();
607 ifaceIter != m_interfaces.end (); ifaceIter++, ifaceIndex++)
609 Ptr<Ipv4Interface> outInterface = *ifaceIter;
610 Ptr<Packet> packetCopy = packet->Copy ();
612 NS_ASSERT (packetCopy->GetSize () <= outInterface->GetMtu ());
613 packetCopy->AddHeader (ipHeader);
614 m_txTrace (packetCopy, ifaceIndex);
615 outInterface->Send (packetCopy, destination);
620 // XXX Note here that in most ipv4 stacks in the world,
621 // the route calculation for an outgoing packet is not
622 // done in the ip layer. It is done within the application
623 // socket when the first packet is sent to avoid this
624 // costly lookup on a per-packet basis.
625 // That would require us to get the route from the packet,
626 // most likely with a packet tag. The higher layers do not
627 // do this yet for us.
628 Lookup (ipHeader, packet,
629 MakeCallback (&Ipv4L3Protocol::SendRealOut, this));
634 Ipv4L3Protocol::SendRealOut (bool found,
635 Ipv4Route const &route,
637 Ipv4Header const &ipHeader)
640 NS_LOG_PARAMS (this << found << &route << packet << &ipHeader);
642 packet->AddHeader (ipHeader);
645 NS_LOG_WARN ("No route to host. Drop.");
646 m_dropTrace (packet);
650 NS_LOG_LOGIC ("Send via interface " << route.GetInterface ());
652 Ptr<Ipv4Interface> outInterface = GetInterface (route.GetInterface ());
653 NS_ASSERT (packet->GetSize () <= outInterface->GetMtu ());
654 m_txTrace (packet, route.GetInterface ());
655 if (route.IsGateway ())
657 NS_LOG_LOGIC ("Send to gateway " << route.GetGateway ());
658 outInterface->Send (packet, route.GetGateway ());
662 NS_LOG_LOGIC ("Send to destination " << ipHeader.GetDestination ());
663 outInterface->Send (packet, ipHeader.GetDestination ());
668 Ipv4L3Protocol::Forwarding (
671 Ipv4Header &ipHeader,
672 Ptr<NetDevice> device)
675 NS_LOG_PARAMS (ifIndex << packet << &ipHeader<< device);
677 for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
678 i != m_interfaces.end (); i++)
680 if ((*i)->GetAddress ().IsEqual (ipHeader.GetDestination ()))
682 NS_LOG_LOGIC ("For me (destination match)");
687 for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
688 i != m_interfaces.end (); i++)
690 Ptr<Ipv4Interface> interface = *i;
691 if (interface->GetDevice () == device)
693 if (ipHeader.GetDestination ().IsEqual (interface->GetBroadcast ()))
695 NS_LOG_LOGIC ("For me (interface broadcast address)");
702 if (ipHeader.GetDestination ().IsBroadcast ())
704 NS_LOG_LOGIC ("For me (Ipv4Addr broadcast address)");
708 if (ipHeader.GetDestination ().IsEqual (Ipv4Address::GetAny ()))
710 NS_LOG_LOGIC ("For me (Ipv4Addr any address)");
714 if (ipHeader.GetTtl () == 1)
716 // Should send ttl expired here
718 NS_LOG_LOGIC ("Not for me (TTL expired). Drop");
719 m_dropTrace (packet);
722 ipHeader.SetTtl (ipHeader.GetTtl () - 1);
724 NS_LOG_LOGIC ("Forwarding packet.");
725 Lookup (ifIndex, ipHeader, packet,
726 MakeCallback (&Ipv4L3Protocol::SendRealOut, this));
728 // If this is a to a multicast address and this node is a member of the
729 // indicated group we need to return false so the multicast is forwarded up.
730 // Note that we may have just forwarded this packet too.
732 for (Ipv4MulticastGroupList::const_iterator i = m_multicastGroups.begin ();
733 i != m_multicastGroups.end (); i++)
735 if ((*i).first.IsEqual (ipHeader.GetSource ()) &&
736 (*i).second.IsEqual (ipHeader.GetDestination ()))
738 NS_LOG_LOGIC ("For me (Joined multicast group)");
743 NS_LOG_LOGIC("Not for me.");
748 Ipv4L3Protocol::ForwardUp (Ptr<Packet> p, Ipv4Header const&ip,
749 Ptr<Ipv4Interface> incomingInterface)
752 NS_LOG_PARAMS (this << p << &ip);
754 Ptr<Ipv4L4Demux> demux = m_node->GetObject<Ipv4L4Demux> ();
755 Ptr<Ipv4L4Protocol> protocol = demux->GetProtocol (ip.GetProtocol ());
756 protocol->Receive (p, ip.GetSource (), ip.GetDestination (), incomingInterface);
760 Ipv4L3Protocol::JoinMulticastGroup (Ipv4Address origin, Ipv4Address group)
763 NS_LOG_PARAMS (this << origin << group);
764 m_multicastGroups.push_back(
765 std::pair<Ipv4Address, Ipv4Address> (origin, group));
769 Ipv4L3Protocol::LeaveMulticastGroup (Ipv4Address origin, Ipv4Address group)
772 NS_LOG_PARAMS (this << origin << group);
774 for (Ipv4MulticastGroupList::iterator i = m_multicastGroups.begin ();
775 i != m_multicastGroups.end ();
778 if ((*i).first.IsEqual(origin) && (*i).second.IsEqual(group))
780 m_multicastGroups.erase (i);
787 Ipv4L3Protocol::SetAddress (uint32_t i, Ipv4Address address)
790 NS_LOG_PARAMS (this << i << address);
791 Ptr<Ipv4Interface> interface = GetInterface (i);
792 interface->SetAddress (address);
796 Ipv4L3Protocol::SetNetworkMask (uint32_t i, Ipv4Mask mask)
799 NS_LOG_PARAMS (this << i << mask);
800 Ptr<Ipv4Interface> interface = GetInterface (i);
801 interface->SetNetworkMask (mask);
805 Ipv4L3Protocol::GetNetworkMask (uint32_t i) const
808 NS_LOG_PARAMS (this << i);
809 Ptr<Ipv4Interface> interface = GetInterface (i);
810 return interface->GetNetworkMask ();
814 Ipv4L3Protocol::GetAddress (uint32_t i) const
817 NS_LOG_PARAMS (this << i);
818 Ptr<Ipv4Interface> interface = GetInterface (i);
819 return interface->GetAddress ();
823 Ipv4L3Protocol::SetMetric (uint32_t i, uint16_t metric)
826 NS_LOG_PARAMS ("(" << i << ", " << metric << ")");
827 Ptr<Ipv4Interface> interface = GetInterface (i);
828 interface->SetMetric (metric);
832 Ipv4L3Protocol::GetMetric (uint32_t i) const
835 NS_LOG_PARAMS ("(" << i << ")");
836 Ptr<Ipv4Interface> interface = GetInterface (i);
837 return interface->GetMetric ();
841 Ipv4L3Protocol::GetIfIndexForDestination (
842 Ipv4Address destination, uint32_t& ifIndex) const
845 NS_LOG_PARAMS (this << destination << &ifIndex);
847 // The first thing we do in trying to determine a source address is to
848 // consult the routing protocols. These will also check for a default route
849 // if one has been set.
851 for (Ipv4RoutingProtocolList::const_iterator i = m_routingProtocols.begin ();
852 i != m_routingProtocols.end ();
855 NS_LOG_LOGIC ("Requesting Source Address");
858 if ((*i).second->RequestIfIndex (destination, ifIndexTmp))
860 NS_LOG_LOGIC ("Found ifIndex " << ifIndexTmp);
861 ifIndex = ifIndexTmp;
866 // If there's no routing table entry telling us what *single* interface will
867 // be used to send a packet to this destination, we'll have to just pick one.
868 // If there's only one interface on this node, a good answer isn't very hard
869 // to come up with. Before jumping to any conclusions, remember that the
870 // zeroth interface is the loopback interface, so what we actually want is
871 // a situation where there are exactly two interfaces on the node, in which
872 // case interface one is the "single" interface connected to the outside world.
874 if (GetNInterfaces () == 2)
876 NS_LOG_LOGIC ("One Interface. Using interface 1.");
881 // If we fall through to here, we have a node with multiple interfaces and
882 // no routes to guide us in determining what interface to choose. Either
883 // no default route was found (for unicast or multicast), or in the case of a
884 // multicast, the default route contained multiple outbound interfaces.
886 // The fallback position is to just get the unicast default route and use
887 // the outgoing interface specified there. We don't want to leave the source
888 // address unset, so we just assert here.
890 // N.B. that in the case of a multicast with a route containing multiple
891 // outgoing interfaces, the source address of packets from that node will be
892 // set to the IP address of the interface set in the default unicast route.
893 // Also, in the case of a broadcast, the same will be true.
895 NS_LOG_LOGIC ("Using default unicast route");
896 Ipv4Route *route = m_staticRouting->GetDefaultRoute ();
900 NS_LOG_LOGIC ("Ipv4L3Protocol::GetIfIndexForDestination (): "
901 "Unable to determine outbound interface. No default route set");
905 ifIndex = route->GetInterface ();
907 NS_LOG_LOGIC ("Default route specifies interface " << ifIndex);
912 Ipv4L3Protocol::GetMtu (uint32_t i) const
915 NS_LOG_PARAMS (this << i);
916 Ptr<Ipv4Interface> interface = GetInterface (i);
917 return interface->GetMtu ();
921 Ipv4L3Protocol::IsUp (uint32_t i) const
924 NS_LOG_PARAMS (this << i);
925 Ptr<Ipv4Interface> interface = GetInterface (i);
926 return interface->IsUp ();
930 Ipv4L3Protocol::SetUp (uint32_t i)
933 NS_LOG_PARAMS (this << i);
934 Ptr<Ipv4Interface> interface = GetInterface (i);
937 // If interface address and network mask have been set, add a route
938 // to the network of the interface (like e.g. ifconfig does on a
940 if ((interface->GetAddress ()) != (Ipv4Address ())
941 && (interface->GetNetworkMask ()) != (Ipv4Mask ()))
943 AddNetworkRouteTo (interface->GetAddress ().CombineMask (interface->GetNetworkMask ()),
944 interface->GetNetworkMask (), i);
949 Ipv4L3Protocol::SetDown (uint32_t ifaceIndex)
952 NS_LOG_PARAMS (this << ifaceIndex);
953 Ptr<Ipv4Interface> interface = GetInterface (ifaceIndex);
954 interface->SetDown ();
956 // Remove all routes that are going through this interface
957 bool modified = true;
961 for (uint32_t i = 0; i < GetNRoutes (); i++)
963 Ipv4Route *route = GetRoute (i);
964 if (route->GetInterface () == ifaceIndex)