ns-3 Direct Code Execution
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ipv4-dce-routing.h
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 
22 #ifndef IPV4_DCE_ROUTING_H
23 #define IPV4_DCE_ROUTING_H
24 
25 #include "ns3/ipv4-static-routing.h"
26 #include "ns3/ipv4-routing-helper.h"
27 #include "ns3/ipv4-list-routing.h"
28 #include "ns3/ptr.h"
29 
30 namespace ns3 {
31 
32 class NetlinkSocket;
33 
49 class Ipv4DceRouting : public Ipv4StaticRouting
50 {
51 public:
52  static TypeId GetTypeId (void);
53 
54  Ipv4DceRouting ();
55  virtual ~Ipv4DceRouting ();
56 
57  virtual void NotifyInterfaceUp (uint32_t interface);
58  virtual void NotifyInterfaceDown (uint32_t interface);
59  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
60  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
61 
62  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const;
63 
64  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
65 
66  template<class T>
67  static Ptr<T> GetRouting (Ptr<Ipv4RoutingProtocol> ipv4rp, T*);
68 
69 private:
70  Ptr<Ipv4> m_ipv4;
71  Ptr<NetlinkSocket> m_netlink;
72 };
73 // This function does a recursive search for a requested routing protocol.
74 // Strictly speaking this recursion is not necessary, but why not?
75 template<class T>
76 Ptr<T> Ipv4DceRouting::GetRouting (Ptr<Ipv4RoutingProtocol> ipv4rp, T* type)
77 {
78  if (ipv4rp == 0)
79  {
80  return 0;
81  }
82 
83  if (DynamicCast<T> (ipv4rp))
84  {
85  return DynamicCast<T> (ipv4rp);
86  }
87  else if (DynamicCast<Ipv4ListRouting> (ipv4rp))
88  {
89  Ptr<Ipv4ListRouting> lrp = DynamicCast<Ipv4ListRouting> (ipv4rp);
90  for (uint32_t i = 0; i < lrp->GetNRoutingProtocols (); i++)
91  {
92  int16_t priority;
93  Ptr<T> ret = GetRouting (lrp->GetRoutingProtocol (i, priority), type);
94  if (ret != 0)
95  {
96  return ret;
97  }
98  }
99  }
100  return 0;
101 }
102 } // Namespace ns3
103 
104 #endif /* IPV4_DCE_ROUTING_H */