A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("Ipv4StaticRouting");
38 
39 using std::make_pair;
40 
41 namespace ns3 {
42 
43 NS_OBJECT_ENSURE_REGISTERED (Ipv4StaticRouting)
44  ;
45 
46 TypeId
48 {
49  static TypeId tid = TypeId ("ns3::Ipv4StaticRouting")
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
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
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 (oif->GetIfIndex (), 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 (SourceAddressSelection (interfaceIdx, route->GetDest ()));
285  rtentry->SetGateway (route->GetGateway ());
286  rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIdx));
287  }
288  }
289  if (rtentry != 0)
290  {
291  NS_LOG_LOGIC ("Matching route via " << rtentry->GetGateway () << " at the end");
292  }
293  else
294  {
295  NS_LOG_LOGIC ("No matching route to " << dest << " found");
296  }
297  return rtentry;
298 }
299 
302  Ipv4Address origin,
304  uint32_t interface)
305 {
306  NS_LOG_FUNCTION (this << origin << " " << group << " " << interface);
307  Ptr<Ipv4MulticastRoute> mrtentry = 0;
308 
309  for (MulticastRoutesI i = m_multicastRoutes.begin ();
310  i != m_multicastRoutes.end ();
311  i++)
312  {
313  Ipv4MulticastRoutingTableEntry *route = *i;
314 //
315 // We've been passed an origin address, a multicast group address and an
316 // interface index. We have to decide if the current route in the list is
317 // a match.
318 //
319 // The first case is the restrictive case where the origin, group and index
320 // matches.
321 //
322  if (origin == route->GetOrigin () && group == route->GetGroup ())
323  {
324  // Skipping this case (SSM) for now
325  NS_LOG_LOGIC ("Found multicast source specific route" << *i);
326  }
327  if (group == route->GetGroup ())
328  {
329  if (interface == Ipv4::IF_ANY ||
330  interface == route->GetInputInterface ())
331  {
332  NS_LOG_LOGIC ("Found multicast route" << *i);
333  mrtentry = Create<Ipv4MulticastRoute> ();
334  mrtentry->SetGroup (route->GetGroup ());
335  mrtentry->SetOrigin (route->GetOrigin ());
336  mrtentry->SetParent (route->GetInputInterface ());
337  for (uint32_t j = 0; j < route->GetNOutputInterfaces (); j++)
338  {
339  if (route->GetOutputInterface (j))
340  {
341  NS_LOG_LOGIC ("Setting output interface index " << route->GetOutputInterface (j));
342  mrtentry->SetOutputTtl (route->GetOutputInterface (j), Ipv4MulticastRoute::MAX_TTL - 1);
343  }
344  }
345  return mrtentry;
346  }
347  }
348  }
349  return mrtentry;
350 }
351 
352 uint32_t
354 {
355  NS_LOG_FUNCTION (this);
356  return m_networkRoutes.size ();;
357 }
358 
361 {
362  NS_LOG_FUNCTION (this);
363  // Basically a repeat of LookupStatic, retained for backward compatibility
364  Ipv4Address dest ("0.0.0.0");
365  uint32_t shortest_metric = 0xffffffff;
366  Ipv4RoutingTableEntry *result = 0;
367  for (NetworkRoutesI i = m_networkRoutes.begin ();
368  i != m_networkRoutes.end ();
369  i++)
370  {
371  Ipv4RoutingTableEntry *j = i->first;
372  uint32_t metric = i->second;
373  Ipv4Mask mask = (j)->GetDestNetworkMask ();
374  uint16_t masklen = mask.GetPrefixLength ();
375  if (masklen != 0)
376  {
377  continue;
378  }
379  if (metric > shortest_metric)
380  {
381  continue;
382  }
383  shortest_metric = metric;
384  result = j;
385  }
386  if (result)
387  {
388  return result;
389  }
390  else
391  {
392  return Ipv4RoutingTableEntry ();
393  }
394 }
395 
397 Ipv4StaticRouting::GetRoute (uint32_t index) const
398 {
399  NS_LOG_FUNCTION (this << index);
400  uint32_t tmp = 0;
401  for (NetworkRoutesCI j = m_networkRoutes.begin ();
402  j != m_networkRoutes.end ();
403  j++)
404  {
405  if (tmp == index)
406  {
407  return j->first;
408  }
409  tmp++;
410  }
411  NS_ASSERT (false);
412  // quiet compiler.
413  return 0;
414 }
415 
416 uint32_t
417 Ipv4StaticRouting::GetMetric (uint32_t index) const
418 {
419  NS_LOG_FUNCTION (this << index);
420  uint32_t tmp = 0;
421  for (NetworkRoutesCI j = m_networkRoutes.begin ();
422  j != m_networkRoutes.end ();
423  j++)
424  {
425  if (tmp == index)
426  {
427  return j->second;
428  }
429  tmp++;
430  }
431  NS_ASSERT (false);
432  // quiet compiler.
433  return 0;
434 }
435 void
437 {
438  NS_LOG_FUNCTION (this << index);
439  uint32_t tmp = 0;
440  for (NetworkRoutesI j = m_networkRoutes.begin ();
441  j != m_networkRoutes.end ();
442  j++)
443  {
444  if (tmp == index)
445  {
446  delete j->first;
447  m_networkRoutes.erase (j);
448  return;
449  }
450  tmp++;
451  }
452  NS_ASSERT (false);
453 }
454 
457 {
458  NS_LOG_FUNCTION (this << p<< header << oif << sockerr);
459  Ipv4Address destination = header.GetDestination ();
460  Ptr<Ipv4Route> rtentry = 0;
461 
462  // Multicast goes here
463  if (destination.IsMulticast ())
464  {
465  // Note: Multicast routes for outbound packets are stored in the
466  // normal unicast table. An implication of this is that it is not
467  // possible to source multicast datagrams on multiple interfaces.
468  // This is a well-known property of sockets implementation on
469  // many Unix variants.
470  // So, we just log it and fall through to LookupStatic ()
471  NS_LOG_LOGIC ("RouteOutput()::Multicast destination");
472  }
473  rtentry = LookupStatic (destination, oif);
474  if (rtentry)
475  {
476  sockerr = Socket::ERROR_NOTERROR;
477  }
478  else
479  {
480  sockerr = Socket::ERROR_NOROUTETOHOST;
481  }
482  return rtentry;
483 }
484 
485 bool
489 {
490  NS_LOG_FUNCTION (this << p << ipHeader << ipHeader.GetSource () << ipHeader.GetDestination () << idev << &ucb << &mcb << &lcb << &ecb);
491 
492  NS_ASSERT (m_ipv4 != 0);
493  // Check if input device supports IP
494  NS_ASSERT (m_ipv4->GetInterfaceForDevice (idev) >= 0);
495  uint32_t iif = m_ipv4->GetInterfaceForDevice (idev);
496 
497  // Multicast recognition; handle local delivery here
498  //
499  if (ipHeader.GetDestination ().IsMulticast ())
500  {
501  NS_LOG_LOGIC ("Multicast destination");
502  Ptr<Ipv4MulticastRoute> mrtentry = LookupStatic (ipHeader.GetSource (),
503  ipHeader.GetDestination (), m_ipv4->GetInterfaceForDevice (idev));
504 
505  if (mrtentry)
506  {
507  NS_LOG_LOGIC ("Multicast route found");
508  mcb (mrtentry, p, ipHeader); // multicast forwarding callback
509  return true;
510  }
511  else
512  {
513  NS_LOG_LOGIC ("Multicast route not found");
514  return false; // Let other routing protocols try to handle this
515  }
516  }
517  if (ipHeader.GetDestination ().IsBroadcast ())
518  {
519  NS_LOG_LOGIC ("For me (Ipv4Addr broadcast address)");
522  }
523 
524  NS_LOG_LOGIC ("Unicast destination");
526  // Right now, we will be permissive and allow a source to send us
527  // a packet to one of our other interface addresses; that is, the
528  // destination unicast address does not match one of the iif addresses,
529  // but we check our other interfaces. This could be an option
530  // (to remove the outer loop immediately below and just check iif).
531  for (uint32_t j = 0; j < m_ipv4->GetNInterfaces (); j++)
532  {
533  for (uint32_t i = 0; i < m_ipv4->GetNAddresses (j); i++)
534  {
535  Ipv4InterfaceAddress iaddr = m_ipv4->GetAddress (j, i);
536  Ipv4Address addr = iaddr.GetLocal ();
537  if (addr.IsEqual (ipHeader.GetDestination ()))
538  {
539  if (j == iif)
540  {
541  NS_LOG_LOGIC ("For me (destination " << addr << " match)");
542  }
543  else
544  {
545  NS_LOG_LOGIC ("For me (destination " << addr << " match) on another interface " << ipHeader.GetDestination ());
546  }
547  lcb (p, ipHeader, iif);
548  return true;
549  }
550  if (ipHeader.GetDestination ().IsEqual (iaddr.GetBroadcast ()))
551  {
552  NS_LOG_LOGIC ("For me (interface broadcast address)");
553  lcb (p, ipHeader, iif);
554  return true;
555  }
556  NS_LOG_LOGIC ("Address "<< addr << " not a match");
557  }
558  }
559  // Check if input device supports IP forwarding
560  if (m_ipv4->IsForwarding (iif) == false)
561  {
562  NS_LOG_LOGIC ("Forwarding disabled for this interface");
563  ecb (p, ipHeader, Socket::ERROR_NOROUTETOHOST);
564  return false;
565  }
566  // Next, try to find a route
567  Ptr<Ipv4Route> rtentry = LookupStatic (ipHeader.GetDestination ());
568  if (rtentry != 0)
569  {
570  NS_LOG_LOGIC ("Found unicast destination- calling unicast callback");
571  ucb (rtentry, p, ipHeader); // unicast forwarding callback
572  return true;
573  }
574  else
575  {
576  NS_LOG_LOGIC ("Did not find unicast destination- returning false");
577  return false; // Let other routing protocols try to handle this
578  }
579 }
580 
582 {
583  NS_LOG_FUNCTION (this);
584 }
585 
586 void
588 {
589  NS_LOG_FUNCTION (this);
590  for (NetworkRoutesI j = m_networkRoutes.begin ();
591  j != m_networkRoutes.end ();
592  j = m_networkRoutes.erase (j))
593  {
594  delete (j->first);
595  }
596  for (MulticastRoutesI i = m_multicastRoutes.begin ();
597  i != m_multicastRoutes.end ();
598  i = m_multicastRoutes.erase (i))
599  {
600  delete (*i);
601  }
602  m_ipv4 = 0;
604 }
605 
606 void
608 {
609  NS_LOG_FUNCTION (this << i);
610  // If interface address and network mask have been set, add a route
611  // to the network of the interface (like e.g. ifconfig does on a
612  // Linux box)
613  for (uint32_t j = 0; j < m_ipv4->GetNAddresses (i); j++)
614  {
615  if (m_ipv4->GetAddress (i,j).GetLocal () != Ipv4Address () &&
616  m_ipv4->GetAddress (i,j).GetMask () != Ipv4Mask () &&
617  m_ipv4->GetAddress (i,j).GetMask () != Ipv4Mask::GetOnes ())
618  {
619  AddNetworkRouteTo (m_ipv4->GetAddress (i,j).GetLocal ().CombineMask (m_ipv4->GetAddress (i,j).GetMask ()),
620  m_ipv4->GetAddress (i,j).GetMask (), i);
621  }
622  }
623 }
624 
625 void
627 {
628  NS_LOG_FUNCTION (this << i);
629  // Remove all static routes that are going through this interface
630  uint32_t j = 0;
631  while (j < GetNRoutes ())
632  {
633  Ipv4RoutingTableEntry route = GetRoute (j);
634  if (route.GetInterface () == i)
635  {
636  RemoveRoute (j);
637  }
638  else
639  {
640  j++;
641  }
642  }
643 }
644 
645 void
647 {
648  NS_LOG_FUNCTION (this << interface << " " << address.GetLocal ());
649  if (!m_ipv4->IsUp (interface))
650  {
651  return;
652  }
653 
654  Ipv4Address networkAddress = address.GetLocal ().CombineMask (address.GetMask ());
655  Ipv4Mask networkMask = address.GetMask ();
656  if (address.GetLocal () != Ipv4Address () &&
657  address.GetMask () != Ipv4Mask ())
658  {
659  AddNetworkRouteTo (networkAddress,
660  networkMask, interface);
661  }
662 }
663 void
665 {
666  NS_LOG_FUNCTION (this << interface << " " << address.GetLocal ());
667  if (!m_ipv4->IsUp (interface))
668  {
669  return;
670  }
671  Ipv4Address networkAddress = address.GetLocal ().CombineMask (address.GetMask ());
672  Ipv4Mask networkMask = address.GetMask ();
673  // Remove all static routes that are going through this interface
674  // which reference this network
675  for (uint32_t j = 0; j < GetNRoutes (); j++)
676  {
677  Ipv4RoutingTableEntry route = GetRoute (j);
678  if (route.GetInterface () == interface &&
679  route.IsNetwork () &&
680  route.GetDestNetwork () == networkAddress &&
681  route.GetDestNetworkMask () == networkMask)
682  {
683  RemoveRoute (j);
684  }
685  }
686 }
687 
688 void
690 {
691  NS_LOG_FUNCTION (this << ipv4);
692  NS_ASSERT (m_ipv4 == 0 && ipv4 != 0);
693  m_ipv4 = ipv4;
694  for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
695  {
696  if (m_ipv4->IsUp (i))
697  {
698  NotifyInterfaceUp (i);
699  }
700  else
701  {
703  }
704  }
705 }
706 // Formatted like output of "route -n" command
707 void
709 {
710  NS_LOG_FUNCTION (this << stream);
711  std::ostream* os = stream->GetStream ();
712  if (GetNRoutes () > 0)
713  {
714  *os << "Destination Gateway Genmask Flags Metric Ref Use Iface" << std::endl;
715  for (uint32_t j = 0; j < GetNRoutes (); j++)
716  {
717  std::ostringstream dest, gw, mask, flags;
718  Ipv4RoutingTableEntry route = GetRoute (j);
719  dest << route.GetDest ();
720  *os << std::setiosflags (std::ios::left) << std::setw (16) << dest.str ();
721  gw << route.GetGateway ();
722  *os << std::setiosflags (std::ios::left) << std::setw (16) << gw.str ();
723  mask << route.GetDestNetworkMask ();
724  *os << std::setiosflags (std::ios::left) << std::setw (16) << mask.str ();
725  flags << "U";
726  if (route.IsHost ())
727  {
728  flags << "HS";
729  }
730  else if (route.IsGateway ())
731  {
732  flags << "GS";
733  }
734  *os << std::setiosflags (std::ios::left) << std::setw (6) << flags.str ();
735  *os << std::setiosflags (std::ios::left) << std::setw (7) << GetMetric (j);
736  // Ref ct not implemented
737  *os << "-" << " ";
738  // Use not implemented
739  *os << "-" << " ";
740  if (Names::FindName (m_ipv4->GetNetDevice (route.GetInterface ())) != "")
741  {
742  *os << Names::FindName (m_ipv4->GetNetDevice (route.GetInterface ()));
743  }
744  else
745  {
746  *os << route.GetInterface ();
747  }
748  *os << std::endl;
749  }
750  }
751 }
754 {
755  NS_LOG_FUNCTION (this << interfaceIdx << " " << dest);
756  if (m_ipv4->GetNAddresses (interfaceIdx) == 1) // common case
757  {
758  return m_ipv4->GetAddress (interfaceIdx, 0).GetLocal ();
759  }
760  // no way to determine the scope of the destination, so adopt the
761  // following rule: pick the first available address (index 0) unless
762  // a subsequent address is on link (in which case, pick the primary
763  // address if there are multiple)
764  Ipv4Address candidate = m_ipv4->GetAddress (interfaceIdx, 0).GetLocal ();
765  for (uint32_t i = 0; i < m_ipv4->GetNAddresses (interfaceIdx); i++)
766  {
767  Ipv4InterfaceAddress test = m_ipv4->GetAddress (interfaceIdx, i);
768  if (test.GetLocal ().CombineMask (test.GetMask ()) == dest.CombineMask (test.GetMask ()))
769  {
770  if (test.IsSecondary () == false)
771  {
772  return test.GetLocal ();
773  }
774  }
775  }
776  return candidate;
777 }
778 
779 } // namespace ns3
static Ipv4Mask GetOnes(void)
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
Ipv4Mask GetMask(void) const
Get the network mask.
Callback template class.
Definition: callback.h:920
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.
Ipv4Address GetLocal(void) const
Get the local address.
static TypeId GetTypeId(void)
The interface Id associated with this class.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:210
void RemoveRoute(uint32_t i)
Remove a route from the static unicast routing table.
Ipv4Address GetOrigin(void) const
Ipv4Address GetDestination(void) const
Definition: ipv4-header.cc:304
bool IsLocalMulticast(void) const
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)
Definition: assert.h:64
Ipv4Address GetDestNetwork(void) const
Ipv4MulticastRoutingTableEntry GetMulticastRoute(uint32_t i) const
Get a route from the static multicast routing table.
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
uint32_t GetInputInterface(void) const
bool IsMulticast(void) const
Ipv4Address CombineMask(Ipv4Mask const &mask) const
Combine this address with a network mask.
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: object.cc:336
Ipv4Address GetSource(void) const
Definition: ipv4-header.cc:291
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
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
uint32_t GetInterface(void) const
Packet header for IPv4.
Definition: ipv4-header.h:31
virtual void NotifyInterfaceDown(uint32_t interface)
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.
bool IsGateway(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)
MulticastRoutes m_multicastRoutes
the forwarding table for multicast.
std::list< Ipv4MulticastRoutingTableEntry * >::iterator MulticastRoutesI
Iterator for container for the multicast routes.
bool IsBroadcast(void) const
Ipv4RoutingTableEntry GetRoute(uint32_t i) const
Get a route from the static unicast routing table.
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)
Ptr< Ipv4 > m_ipv4
Ipv4 reference.
bool IsNetwork(void) const
#define NS_LOG_LOGIC(msg)
Definition: log.h:368
Ipv4Address GetGateway(void) const
Definition: ipv4-route.cc:70
bool IsSecondary(void) const
Check if the address is a secondary address.
std::list< Ipv4MulticastRoutingTableEntry * >::const_iterator MulticastRoutesCI
Const Iterator for container for the multicast routes.
uint32_t GetMetric(uint32_t index) const
Get a metric for route from the static unicast routing table.
uint32_t GetNRoutes(void) const
Get the number of individual unicast routes that have been added to the routing table.
uint32_t GetOutputInterface(uint32_t n) const
bool IsEqual(const Ipv4Address &other) const
Comparison operation between two Ipv4Addresses.
Definition: ipv4-address.h:81
std::list< std::pair< Ipv4RoutingTableEntry *, uint32_t > >::const_iterator NetworkRoutesCI
Const Iterator for container for the network routes.
Ipv4Address SourceAddressSelection(uint32_t interface, Ipv4Address dest)
Choose the source address to use with destination address.
Ipv4Address GetDest(void) const
static Ipv4Address GetZero(void)
void SetOutputDevice(Ptr< NetDevice > outputDevice)
Equivalent in Linux to dst_entry.dev.
Definition: ipv4-route.cc:77
A record of an IPv4 multicast route for Ipv4GlobalRouting and Ipv4StaticRouting.
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream) const
Print the Routing Table entries.
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
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:38
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Ipv4Address GetBroadcast(void) const
Get the broadcast address.
a class to store IPv4 address information on an interface
virtual void NotifyInterfaceUp(uint32_t interface)
NetworkRoutes m_networkRoutes
the forwarding table for network.
Ipv4Address GetGroup(void) const
Ipv4Address GetGateway(void) const
virtual void SetIpv4(Ptr< Ipv4 > ipv4)
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
static const uint32_t IF_ANY
interface wildcard, meaning any interface
Definition: ipv4.h:386
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:665
Abstract base class for IPv4 routing protocols.
NS_LOG_COMPONENT_DEFINE("Ipv4StaticRouting")
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
tuple address
Definition: first.py:37
uint32_t GetNOutputInterfaces(void) const
bool IsHost(void) const
uint32_t GetNMulticastRoutes(void) const
Get the number of individual multicast routes that have been added to the routing table...
Ipv4Mask GetDestNetworkMask(void) const
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
void test(void)
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
uint16_t GetPrefixLength(void) const
static const uint32_t MAX_TTL
Maximum time-to-live (TTL)
Definition: ipv4-route.h:165
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.