A Discrete-Event Network Simulator
API
ipv4-static-routing.cc
Go to the documentation of this file.
1 // -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*-
2 //
3 // Copyright (c) 2006 Georgia Tech Research Corporation
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: George F. Riley<riley@ece.gatech.edu>
19 // Gustavo Carneiro <gjc@inescporto.pt>
20 
21 #define NS_LOG_APPEND_CONTEXT \
22  if (m_ipv4 && m_ipv4->GetObject<Node> ()) { \
23  std::clog << Simulator::Now ().GetSeconds () \
24  << " [node " << m_ipv4->GetObject<Node> ()->GetId () << "] "; }
25 
26 #include <iomanip>
27 #include "ns3/log.h"
28 #include "ns3/names.h"
29 #include "ns3/packet.h"
30 #include "ns3/node.h"
31 #include "ns3/simulator.h"
32 #include "ns3/ipv4-route.h"
33 #include "ns3/output-stream-wrapper.h"
34 #include "ipv4-static-routing.h"
36 
37 using std::make_pair;
38 
39 namespace ns3 {
40 
41 NS_LOG_COMPONENT_DEFINE ("Ipv4StaticRouting");
42 
43 NS_OBJECT_ENSURE_REGISTERED (Ipv4StaticRouting);
44 
45 TypeId
47 {
48  static TypeId tid = TypeId ("ns3::Ipv4StaticRouting")
50  .SetGroupName ("Internet")
51  .AddConstructor<Ipv4StaticRouting> ()
52  ;
53  return tid;
54 }
55 
57  : m_ipv4 (0)
58 {
59  NS_LOG_FUNCTION (this);
60 }
61 
62 void
64  Ipv4Mask networkMask,
65  Ipv4Address nextHop,
66  uint32_t interface,
67  uint32_t metric)
68 {
69  NS_LOG_FUNCTION (this << network << " " << networkMask << " " << nextHop << " " << interface << " " << metric);
72  networkMask,
73  nextHop,
74  interface);
75  m_networkRoutes.push_back (make_pair (route,metric));
76 }
77 
78 void
80  Ipv4Mask networkMask,
81  uint32_t interface,
82  uint32_t metric)
83 {
84  NS_LOG_FUNCTION (this << network << " " << networkMask << " " << interface << " " << metric);
87  networkMask,
88  interface);
89  m_networkRoutes.push_back (make_pair (route,metric));
90 }
91 
92 void
94  Ipv4Address nextHop,
95  uint32_t interface,
96  uint32_t metric)
97 {
98  NS_LOG_FUNCTION (this << dest << " " << nextHop << " " << interface << " " << metric);
99  AddNetworkRouteTo (dest, Ipv4Mask::GetOnes (), nextHop, interface, metric);
100 }
101 
102 void
104  uint32_t interface,
105  uint32_t metric)
106 {
107  NS_LOG_FUNCTION (this << dest << " " << interface << " " << metric);
108  AddNetworkRouteTo (dest, Ipv4Mask::GetOnes (), interface, metric);
109 }
110 
111 void
113  uint32_t interface,
114  uint32_t metric)
115 {
116  NS_LOG_FUNCTION (this << nextHop << " " << interface << " " << metric);
117  AddNetworkRouteTo (Ipv4Address ("0.0.0.0"), Ipv4Mask::GetZero (), nextHop, interface, metric);
118 }
119 
120 void
122  Ipv4Address group,
123  uint32_t inputInterface,
124  std::vector<uint32_t> outputInterfaces)
125 {
126  NS_LOG_FUNCTION (this << origin << " " << group << " " << inputInterface << " " << &outputInterfaces);
129  inputInterface, outputInterfaces);
130  m_multicastRoutes.push_back (route);
131 }
132 
133 // default multicast routes are stored as a network route
134 // these routes are _not_ consulted in the forwarding process-- only
135 // for originating packets
136 void
138 {
139  NS_LOG_FUNCTION (this << outputInterface);
141  Ipv4Address network = Ipv4Address ("224.0.0.0");
142  Ipv4Mask networkMask = Ipv4Mask ("240.0.0.0");
144  networkMask,
145  outputInterface);
146  m_networkRoutes.push_back (make_pair (route,0));
147 }
148 
149 uint32_t
151 {
152  NS_LOG_FUNCTION (this);
153  return m_multicastRoutes.size ();
154 }
155 
158 {
159  NS_LOG_FUNCTION (this << index);
160  NS_ASSERT_MSG (index < m_multicastRoutes.size (),
161  "Ipv4StaticRouting::GetMulticastRoute (): Index out of range");
162 
163  if (index < m_multicastRoutes.size ())
164  {
165  uint32_t tmp = 0;
166  for (MulticastRoutesCI i = m_multicastRoutes.begin ();
167  i != m_multicastRoutes.end ();
168  i++)
169  {
170  if (tmp == index)
171  {
172  return *i;
173  }
174  tmp++;
175  }
176  }
177  return 0;
178 }
179 
180 bool
182  Ipv4Address group,
183  uint32_t inputInterface)
184 {
185  NS_LOG_FUNCTION (this << origin << " " << group << " " << inputInterface);
186  for (MulticastRoutesI i = m_multicastRoutes.begin ();
187  i != m_multicastRoutes.end ();
188  i++)
189  {
190  Ipv4MulticastRoutingTableEntry *route = *i;
191  if (origin == route->GetOrigin () &&
192  group == route->GetGroup () &&
193  inputInterface == route->GetInputInterface ())
194  {
195  delete *i;
196  m_multicastRoutes.erase (i);
197  return true;
198  }
199  }
200  return false;
201 }
202 
203 void
205 {
206  NS_LOG_FUNCTION (this << index);
207  uint32_t tmp = 0;
208  for (MulticastRoutesI i = m_multicastRoutes.begin ();
209  i != m_multicastRoutes.end ();
210  i++)
211  {
212  if (tmp == index)
213  {
214  delete *i;
215  m_multicastRoutes.erase (i);
216  return;
217  }
218  tmp++;
219  }
220 }
221 
224 {
225  NS_LOG_FUNCTION (this << dest << " " << oif);
226  Ptr<Ipv4Route> rtentry = 0;
227  uint16_t longest_mask = 0;
228  uint32_t shortest_metric = 0xffffffff;
229  /* when sending on local multicast, there have to be interface specified */
230  if (dest.IsLocalMulticast ())
231  {
232  NS_ASSERT_MSG (oif, "Try to send on link-local multicast address, and no interface index is given!");
233 
234  rtentry = Create<Ipv4Route> ();
235  rtentry->SetDestination (dest);
236  rtentry->SetGateway (Ipv4Address::GetZero ());
237  rtentry->SetOutputDevice (oif);
238  rtentry->SetSource (m_ipv4->GetAddress (m_ipv4->GetInterfaceForDevice (oif), 0).GetLocal ());
239  return rtentry;
240  }
241 
242 
243  for (NetworkRoutesI i = m_networkRoutes.begin ();
244  i != m_networkRoutes.end ();
245  i++)
246  {
247  Ipv4RoutingTableEntry *j=i->first;
248  uint32_t metric =i->second;
249  Ipv4Mask mask = (j)->GetDestNetworkMask ();
250  uint16_t masklen = mask.GetPrefixLength ();
251  Ipv4Address entry = (j)->GetDestNetwork ();
252  NS_LOG_LOGIC ("Searching for route to " << dest << ", checking against route to " << entry << "/" << masklen);
253  if (mask.IsMatch (dest, entry))
254  {
255  NS_LOG_LOGIC ("Found global network route " << j << ", mask length " << masklen << ", metric " << metric);
256  if (oif != 0)
257  {
258  if (oif != m_ipv4->GetNetDevice (j->GetInterface ()))
259  {
260  NS_LOG_LOGIC ("Not on requested interface, skipping");
261  continue;
262  }
263  }
264  if (masklen < longest_mask) // Not interested if got shorter mask
265  {
266  NS_LOG_LOGIC ("Previous match longer, skipping");
267  continue;
268  }
269  if (masklen > longest_mask) // Reset metric if longer masklen
270  {
271  shortest_metric = 0xffffffff;
272  }
273  longest_mask = masklen;
274  if (metric > shortest_metric)
275  {
276  NS_LOG_LOGIC ("Equal mask length, but previous metric shorter, skipping");
277  continue;
278  }
279  shortest_metric = metric;
280  Ipv4RoutingTableEntry* route = (j);
281  uint32_t interfaceIdx = route->GetInterface ();
282  rtentry = Create<Ipv4Route> ();
283  rtentry->SetDestination (route->GetDest ());
284  rtentry->SetSource (m_ipv4->SourceAddressSelection (interfaceIdx, route->GetDest ()));
285  rtentry->SetGateway (route->GetGateway ());
286  rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIdx));
287  if (masklen == 32)
288  {
289  break;
290  }
291  }
292  }
293  if (rtentry != 0)
294  {
295  NS_LOG_LOGIC ("Matching route via " << rtentry->GetGateway () << " at the end");
296  }
297  else
298  {
299  NS_LOG_LOGIC ("No matching route to " << dest << " found");
300  }
301  return rtentry;
302 }
303 
306  Ipv4Address origin,
307  Ipv4Address group,
308  uint32_t interface)
309 {
310  NS_LOG_FUNCTION (this << origin << " " << group << " " << interface);
311  Ptr<Ipv4MulticastRoute> mrtentry = 0;
312 
313  for (MulticastRoutesI i = m_multicastRoutes.begin ();
314  i != m_multicastRoutes.end ();
315  i++)
316  {
317  Ipv4MulticastRoutingTableEntry *route = *i;
318 //
319 // We've been passed an origin address, a multicast group address and an
320 // interface index. We have to decide if the current route in the list is
321 // a match.
322 //
323 // The first case is the restrictive case where the origin, group and index
324 // matches.
325 //
326  if (origin == route->GetOrigin () && group == route->GetGroup ())
327  {
328  // Skipping this case (SSM) for now
329  NS_LOG_LOGIC ("Found multicast source specific route" << *i);
330  }
331  if (group == route->GetGroup ())
332  {
333  if (interface == Ipv4::IF_ANY ||
334  interface == route->GetInputInterface ())
335  {
336  NS_LOG_LOGIC ("Found multicast route" << *i);
337  mrtentry = Create<Ipv4MulticastRoute> ();
338  mrtentry->SetGroup (route->GetGroup ());
339  mrtentry->SetOrigin (route->GetOrigin ());
340  mrtentry->SetParent (route->GetInputInterface ());
341  for (uint32_t j = 0; j < route->GetNOutputInterfaces (); j++)
342  {
343  if (route->GetOutputInterface (j))
344  {
345  NS_LOG_LOGIC ("Setting output interface index " << route->GetOutputInterface (j));
346  mrtentry->SetOutputTtl (route->GetOutputInterface (j), Ipv4MulticastRoute::MAX_TTL - 1);
347  }
348  }
349  return mrtentry;
350  }
351  }
352  }
353  return mrtentry;
354 }
355 
356 uint32_t
358 {
359  NS_LOG_FUNCTION (this);
360  return m_networkRoutes.size ();;
361 }
362 
365 {
366  NS_LOG_FUNCTION (this);
367  // Basically a repeat of LookupStatic, retained for backward compatibility
368  Ipv4Address dest ("0.0.0.0");
369  uint32_t shortest_metric = 0xffffffff;
370  Ipv4RoutingTableEntry *result = 0;
371  for (NetworkRoutesI i = m_networkRoutes.begin ();
372  i != m_networkRoutes.end ();
373  i++)
374  {
375  Ipv4RoutingTableEntry *j = i->first;
376  uint32_t metric = i->second;
377  Ipv4Mask mask = (j)->GetDestNetworkMask ();
378  uint16_t masklen = mask.GetPrefixLength ();
379  if (masklen != 0)
380  {
381  continue;
382  }
383  if (metric > shortest_metric)
384  {
385  continue;
386  }
387  shortest_metric = metric;
388  result = j;
389  }
390  if (result)
391  {
392  return result;
393  }
394  else
395  {
396  return Ipv4RoutingTableEntry ();
397  }
398 }
399 
401 Ipv4StaticRouting::GetRoute (uint32_t index) const
402 {
403  NS_LOG_FUNCTION (this << index);
404  uint32_t tmp = 0;
405  for (NetworkRoutesCI j = m_networkRoutes.begin ();
406  j != m_networkRoutes.end ();
407  j++)
408  {
409  if (tmp == index)
410  {
411  return j->first;
412  }
413  tmp++;
414  }
415  NS_ASSERT (false);
416  // quiet compiler.
417  return 0;
418 }
419 
420 uint32_t
421 Ipv4StaticRouting::GetMetric (uint32_t index) const
422 {
423  NS_LOG_FUNCTION (this << index);
424  uint32_t tmp = 0;
425  for (NetworkRoutesCI j = m_networkRoutes.begin ();
426  j != m_networkRoutes.end ();
427  j++)
428  {
429  if (tmp == index)
430  {
431  return j->second;
432  }
433  tmp++;
434  }
435  NS_ASSERT (false);
436  // quiet compiler.
437  return 0;
438 }
439 void
441 {
442  NS_LOG_FUNCTION (this << index);
443  uint32_t tmp = 0;
444  for (NetworkRoutesI j = m_networkRoutes.begin ();
445  j != m_networkRoutes.end ();
446  j++)
447  {
448  if (tmp == index)
449  {
450  delete j->first;
451  m_networkRoutes.erase (j);
452  return;
453  }
454  tmp++;
455  }
456  NS_ASSERT (false);
457 }
458 
461 {
462  NS_LOG_FUNCTION (this << p<< header << oif << sockerr);
463  Ipv4Address destination = header.GetDestination ();
464  Ptr<Ipv4Route> rtentry = 0;
465 
466  // Multicast goes here
467  if (destination.IsMulticast ())
468  {
469  // Note: Multicast routes for outbound packets are stored in the
470  // normal unicast table. An implication of this is that it is not
471  // possible to source multicast datagrams on multiple interfaces.
472  // This is a well-known property of sockets implementation on
473  // many Unix variants.
474  // So, we just log it and fall through to LookupStatic ()
475  NS_LOG_LOGIC ("RouteOutput()::Multicast destination");
476  }
477  rtentry = LookupStatic (destination, oif);
478  if (rtentry)
479  {
480  sockerr = Socket::ERROR_NOTERROR;
481  }
482  else
483  {
484  sockerr = Socket::ERROR_NOROUTETOHOST;
485  }
486  return rtentry;
487 }
488 
489 bool
493 {
494  NS_LOG_FUNCTION (this << p << ipHeader << ipHeader.GetSource () << ipHeader.GetDestination () << idev << &ucb << &mcb << &lcb << &ecb);
495 
496  NS_ASSERT (m_ipv4 != 0);
497  // Check if input device supports IP
498  NS_ASSERT (m_ipv4->GetInterfaceForDevice (idev) >= 0);
499  uint32_t iif = m_ipv4->GetInterfaceForDevice (idev);
500 
501  // Multicast recognition; handle local delivery here
502 
503  if (ipHeader.GetDestination ().IsMulticast ())
504  {
505  NS_LOG_LOGIC ("Multicast destination");
506  Ptr<Ipv4MulticastRoute> mrtentry = LookupStatic (ipHeader.GetSource (),
507  ipHeader.GetDestination (), m_ipv4->GetInterfaceForDevice (idev));
508 
509  if (mrtentry)
510  {
511  NS_LOG_LOGIC ("Multicast route found");
512  mcb (mrtentry, p, ipHeader); // multicast forwarding callback
513  return true;
514  }
515  else
516  {
517  NS_LOG_LOGIC ("Multicast route not found");
518  return false; // Let other routing protocols try to handle this
519  }
520  }
521 
522  if (m_ipv4->IsDestinationAddress (ipHeader.GetDestination (), iif))
523  {
524  if (!lcb.IsNull ())
525  {
526  NS_LOG_LOGIC ("Local delivery to " << ipHeader.GetDestination ());
527  lcb (p, ipHeader, iif);
528  return true;
529  }
530  else
531  {
532  // The local delivery callback is null. This may be a multicast
533  // or broadcast packet, so return false so that another
534  // multicast routing protocol can handle it. It should be possible
535  // to extend this to explicitly check whether it is a unicast
536  // packet, and invoke the error callback if so
537  return false;
538  }
539  }
540 
541  // Check if input device supports IP forwarding
542  if (m_ipv4->IsForwarding (iif) == false)
543  {
544  NS_LOG_LOGIC ("Forwarding disabled for this interface");
545  ecb (p, ipHeader, Socket::ERROR_NOROUTETOHOST);
546  return true;
547  }
548  // Next, try to find a route
549  Ptr<Ipv4Route> rtentry = LookupStatic (ipHeader.GetDestination ());
550  if (rtentry != 0)
551  {
552  NS_LOG_LOGIC ("Found unicast destination- calling unicast callback");
553  ucb (rtentry, p, ipHeader); // unicast forwarding callback
554  return true;
555  }
556  else
557  {
558  NS_LOG_LOGIC ("Did not find unicast destination- returning false");
559  return false; // Let other routing protocols try to handle this
560  }
561 }
562 
564 {
565  NS_LOG_FUNCTION (this);
566 }
567 
568 void
570 {
571  NS_LOG_FUNCTION (this);
572  for (NetworkRoutesI j = m_networkRoutes.begin ();
573  j != m_networkRoutes.end ();
574  j = m_networkRoutes.erase (j))
575  {
576  delete (j->first);
577  }
578  for (MulticastRoutesI i = m_multicastRoutes.begin ();
579  i != m_multicastRoutes.end ();
580  i = m_multicastRoutes.erase (i))
581  {
582  delete (*i);
583  }
584  m_ipv4 = 0;
586 }
587 
588 void
590 {
591  NS_LOG_FUNCTION (this << i);
592  // If interface address and network mask have been set, add a route
593  // to the network of the interface (like e.g. ifconfig does on a
594  // Linux box)
595  for (uint32_t j = 0; j < m_ipv4->GetNAddresses (i); j++)
596  {
597  if (m_ipv4->GetAddress (i,j).GetLocal () != Ipv4Address () &&
598  m_ipv4->GetAddress (i,j).GetMask () != Ipv4Mask () &&
599  m_ipv4->GetAddress (i,j).GetMask () != Ipv4Mask::GetOnes ())
600  {
601  AddNetworkRouteTo (m_ipv4->GetAddress (i,j).GetLocal ().CombineMask (m_ipv4->GetAddress (i,j).GetMask ()),
602  m_ipv4->GetAddress (i,j).GetMask (), i);
603  }
604  }
605 }
606 
607 void
609 {
610  NS_LOG_FUNCTION (this << i);
611  // Remove all static routes that are going through this interface
612  for (NetworkRoutesI it = m_networkRoutes.begin (); it != m_networkRoutes.end (); )
613  {
614  if (it->first->GetInterface () == i)
615  {
616  delete it->first;
617  it = m_networkRoutes.erase (it);
618  }
619  else
620  {
621  it++;
622  }
623  }
624 }
625 
626 void
628 {
629  NS_LOG_FUNCTION (this << interface << " " << address.GetLocal ());
630  if (!m_ipv4->IsUp (interface))
631  {
632  return;
633  }
634 
635  Ipv4Address networkAddress = address.GetLocal ().CombineMask (address.GetMask ());
636  Ipv4Mask networkMask = address.GetMask ();
637  if (address.GetLocal () != Ipv4Address () &&
638  address.GetMask () != Ipv4Mask ())
639  {
640  AddNetworkRouteTo (networkAddress,
641  networkMask, interface);
642  }
643 }
644 void
646 {
647  NS_LOG_FUNCTION (this << interface << " " << address.GetLocal ());
648  if (!m_ipv4->IsUp (interface))
649  {
650  return;
651  }
652  Ipv4Address networkAddress = address.GetLocal ().CombineMask (address.GetMask ());
653  Ipv4Mask networkMask = address.GetMask ();
654  // Remove all static routes that are going through this interface
655  // which reference this network
656  for (NetworkRoutesI it = m_networkRoutes.begin (); it != m_networkRoutes.end (); )
657  {
658  if (it->first->GetInterface () == interface
659  && it->first->IsNetwork ()
660  && it->first->GetDestNetwork () == networkAddress
661  && it->first->GetDestNetworkMask () == networkMask)
662  {
663  delete it->first;
664  it = m_networkRoutes.erase (it);
665  }
666  else
667  {
668  it++;
669  }
670  }
671 }
672 
673 void
675 {
676  NS_LOG_FUNCTION (this << ipv4);
677  NS_ASSERT (m_ipv4 == 0 && ipv4 != 0);
678  m_ipv4 = ipv4;
679  for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
680  {
681  if (m_ipv4->IsUp (i))
682  {
683  NotifyInterfaceUp (i);
684  }
685  else
686  {
688  }
689  }
690 }
691 // Formatted like output of "route -n" command
692 void
694 {
695  NS_LOG_FUNCTION (this << stream);
696  std::ostream* os = stream->GetStream ();
697 
698  *os << "Node: " << m_ipv4->GetObject<Node> ()->GetId ()
699  << ", Time: " << Now().As (unit)
700  << ", Local time: " << GetObject<Node> ()->GetLocalTime ().As (unit)
701  << ", Ipv4StaticRouting table" << std::endl;
702 
703  if (GetNRoutes () > 0)
704  {
705  *os << "Destination Gateway Genmask Flags Metric Ref Use Iface" << std::endl;
706  for (uint32_t j = 0; j < GetNRoutes (); j++)
707  {
708  std::ostringstream dest, gw, mask, flags;
709  Ipv4RoutingTableEntry route = GetRoute (j);
710  dest << route.GetDest ();
711  *os << std::setiosflags (std::ios::left) << std::setw (16) << dest.str ();
712  gw << route.GetGateway ();
713  *os << std::setiosflags (std::ios::left) << std::setw (16) << gw.str ();
714  mask << route.GetDestNetworkMask ();
715  *os << std::setiosflags (std::ios::left) << std::setw (16) << mask.str ();
716  flags << "U";
717  if (route.IsHost ())
718  {
719  flags << "HS";
720  }
721  else if (route.IsGateway ())
722  {
723  flags << "GS";
724  }
725  *os << std::setiosflags (std::ios::left) << std::setw (6) << flags.str ();
726  *os << std::setiosflags (std::ios::left) << std::setw (7) << GetMetric (j);
727  // Ref ct not implemented
728  *os << "-" << " ";
729  // Use not implemented
730  *os << "-" << " ";
731  if (Names::FindName (m_ipv4->GetNetDevice (route.GetInterface ())) != "")
732  {
733  *os << Names::FindName (m_ipv4->GetNetDevice (route.GetInterface ()));
734  }
735  else
736  {
737  *os << route.GetInterface ();
738  }
739  *os << std::endl;
740  }
741  }
742  *os << std::endl;
743 }
744 
745 } // namespace ns3
uint32_t GetOutputInterface(uint32_t n) const
static Ipv4Mask GetOnes(void)
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Callback template class.
Definition: callback.h:1176
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
bool IsMatch(Ipv4Address a, Ipv4Address b) const
void SetDefaultRoute(Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a default route to the static routing table.
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
static TypeId GetTypeId(void)
The interface Id associated with this class.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:258
void RemoveRoute(uint32_t i)
Remove a route from the static unicast routing table.
Ipv4Address GetSource(void) const
Definition: ipv4-header.cc:291
Ipv4RoutingTableEntry GetDefaultRoute(void)
Get the default route with lowest metric from the static routing table.
std::list< std::pair< Ipv4RoutingTableEntry *, uint32_t > >::iterator NetworkRoutesI
Iterator for container for the network routes.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Ipv4Address GetDest(void) const
uint32_t GetNRoutes(void) const
Get the number of individual unicast routes that have been added to the routing table.
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
TimeWithUnit As(const enum Unit unit) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:388
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
Ipv4Address GetGateway(void) const
void AddHostRouteTo(Ipv4Address dest, Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a host route to the static routing table.
static Ipv4MulticastRoutingTableEntry CreateMulticastRoute(Ipv4Address origin, Ipv4Address group, uint32_t inputInterface, std::vector< uint32_t > outputInterfaces)
Ptr< Ipv4Route > LookupStatic(Ipv4Address dest, Ptr< NetDevice > oif=0)
Lookup in the forwarding table for destination.
void SetSource(Ipv4Address src)
Definition: ipv4-route.cc:49
Packet header for IPv4.
Definition: ipv4-header.h:33
bool IsMulticast(void) const
virtual void NotifyInterfaceDown(uint32_t interface)
Ipv4Mask GetDestNetworkMask(void) const
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
bool RemoveMulticastRoute(Ipv4Address origin, Ipv4Address group, uint32_t inputInterface)
Remove a route from the static multicast routing table.
Ipv4Address GetGroup(void) const
Ipv4RoutingTableEntry GetRoute(uint32_t i) const
Get a route from the static unicast routing table.
bool IsHost(void) const
void SetGateway(Ipv4Address gw)
Definition: ipv4-route.cc:63
static Ipv4RoutingTableEntry CreateNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface)
static Ipv4Mask GetZero(void)
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:108
MulticastRoutes m_multicastRoutes
the forwarding table for multicast.
std::list< Ipv4MulticastRoutingTableEntry * >::iterator MulticastRoutesI
Iterator for container for the multicast routes.
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print the Routing Table entries.
virtual bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb)
Route an input packet (to be forwarded or locally delivered)
bool IsLocalMulticast(void) const
Ptr< Ipv4 > m_ipv4
Ipv4 reference.
uint32_t GetInputInterface(void) const
uint32_t GetNOutputInterfaces(void) const
Ipv4MulticastRoutingTableEntry GetMulticastRoute(uint32_t i) const
Get a route from the static multicast routing table.
std::list< Ipv4MulticastRoutingTableEntry * >::const_iterator MulticastRoutesCI
Const Iterator for container for the multicast routes.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Static routing protocol for IP version 4 stacks.
uint32_t GetInterface(void) const
address
Definition: first.py:37
std::list< std::pair< Ipv4RoutingTableEntry *, uint32_t > >::const_iterator NetworkRoutesCI
Const Iterator for container for the network routes.
static Ipv4Address GetZero(void)
void SetOutputDevice(Ptr< NetDevice > outputDevice)
Equivalent in Linux to dst_entry.dev.
Definition: ipv4-route.cc:77
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
A record of an IPv4 multicast route for Ipv4GlobalRouting and Ipv4StaticRouting.
Ipv4Address GetGateway(void) const
Definition: ipv4-route.cc:70
Ipv4Address GetDestination(void) const
Definition: ipv4-header.cc:304
uint32_t GetMetric(uint32_t index) const
Get a metric for route from the static unicast routing table.
void AddNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a network route to the static routing table.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
uint32_t GetNMulticastRoutes(void) const
Get the number of individual multicast routes that have been added to the routing table...
virtual void DoDispose(void)
Destructor implementation.
Ipv4Address GetOrigin(void) const
a class to store IPv4 address information on an interface
virtual void NotifyInterfaceUp(uint32_t interface)
NetworkRoutes m_networkRoutes
the forwarding table for network.
A network Node.
Definition: node.h:56
virtual void SetIpv4(Ptr< Ipv4 > ipv4)
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
bool IsGateway(void) const
static const uint32_t IF_ANY
interface wildcard, meaning any interface
Definition: ipv4.h:437
static std::string FindName(Ptr< Object > object)
Given a pointer to an object, look to see if that object has a name associated with it and...
Definition: names.cc:819
Abstract base class for IPv4 routing protocols.
uint16_t GetPrefixLength(void) const
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:365
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1270
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
static const uint32_t MAX_TTL
Maximum time-to-live (TTL)
Definition: ipv4-route.h:158
void SetDestination(Ipv4Address dest)
Definition: ipv4-route.cc:35
void SetDefaultMulticastRoute(uint32_t outputInterface)
Add a default multicast route to the static routing table.
void AddMulticastRoute(Ipv4Address origin, Ipv4Address group, uint32_t inputInterface, std::vector< uint32_t > outputInterfaces)
Add a multicast route to the static routing table.
virtual Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr)
Query routing cache for an existing route, for an outbound packet.