A Discrete-Event Network Simulator
API
ipv4-route.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 University of Washington
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  */
18 
19 #include "ipv4-route.h"
20 
21 #include "ns3/assert.h"
22 #include "ns3/log.h"
23 #include "ns3/net-device.h"
24 
25 namespace ns3
26 {
27 
28 NS_LOG_COMPONENT_DEFINE("Ipv4Route");
29 
31 {
32  NS_LOG_FUNCTION(this);
33 }
34 
35 void
37 {
38  NS_LOG_FUNCTION(this << dest);
39  m_dest = dest;
40 }
41 
44 {
45  NS_LOG_FUNCTION(this);
46  return m_dest;
47 }
48 
49 void
51 {
52  NS_LOG_FUNCTION(this << src);
53  m_source = src;
54 }
55 
58 {
59  NS_LOG_FUNCTION(this);
60  return m_source;
61 }
62 
63 void
65 {
66  NS_LOG_FUNCTION(this << gw);
67  m_gateway = gw;
68 }
69 
72 {
73  NS_LOG_FUNCTION(this);
74  return m_gateway;
75 }
76 
77 void
79 {
80  NS_LOG_FUNCTION(this << outputDevice);
81  m_outputDevice = outputDevice;
82 }
83 
86 {
87  NS_LOG_FUNCTION(this);
88  return m_outputDevice;
89 }
90 
91 std::ostream&
92 operator<<(std::ostream& os, const Ipv4Route& route)
93 {
94  os << "source=" << route.GetSource() << " dest=" << route.GetDestination()
95  << " gw=" << route.GetGateway();
96  return os;
97 }
98 
100 {
101  NS_LOG_FUNCTION(this);
102  m_ttls.clear();
103 }
104 
105 void
107 {
108  NS_LOG_FUNCTION(this << group);
109  m_group = group;
110 }
111 
114 {
115  NS_LOG_FUNCTION(this);
116  return m_group;
117 }
118 
119 void
121 {
122  NS_LOG_FUNCTION(this << origin);
123  m_origin = origin;
124 }
125 
128 {
129  NS_LOG_FUNCTION(this);
130  return m_origin;
131 }
132 
133 void
135 {
136  NS_LOG_FUNCTION(this << parent);
137  m_parent = parent;
138 }
139 
140 uint32_t
142 {
143  NS_LOG_FUNCTION(this);
144  return m_parent;
145 }
146 
147 void
148 Ipv4MulticastRoute::SetOutputTtl(uint32_t oif, uint32_t ttl)
149 {
150  NS_LOG_FUNCTION(this << oif << ttl);
151  if (ttl >= MAX_TTL)
152  {
153  // This TTL value effectively disables the interface
154  auto iter = m_ttls.find(oif);
155  if (iter != m_ttls.end())
156  {
157  m_ttls.erase(iter);
158  }
159  }
160  else
161  {
162  m_ttls[oif] = ttl;
163  }
164 }
165 
166 std::map<uint32_t, uint32_t>
168 {
169  NS_LOG_FUNCTION(this);
170  return m_ttls;
171 }
172 
173 } // namespace ns3
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
uint32_t GetParent() const
Definition: ipv4-route.cc:141
Ipv4Address m_group
Group.
Definition: ipv4-route.h:162
Ipv4Address GetGroup() const
Definition: ipv4-route.cc:113
std::map< uint32_t, uint32_t > GetOutputTtlMap() const
Definition: ipv4-route.cc:167
Ipv4Address GetOrigin() const
Definition: ipv4-route.cc:127
void SetOrigin(const Ipv4Address origin)
Definition: ipv4-route.cc:120
Ipv4Address m_origin
Source of packet.
Definition: ipv4-route.h:163
void SetOutputTtl(uint32_t oif, uint32_t ttl)
Definition: ipv4-route.cc:148
void SetGroup(const Ipv4Address group)
Definition: ipv4-route.cc:106
uint32_t m_parent
Source interface.
Definition: ipv4-route.h:164
static const uint32_t MAX_TTL
Maximum time-to-live (TTL)
Definition: ipv4-route.h:159
std::map< uint32_t, uint32_t > m_ttls
Time to Live container.
Definition: ipv4-route.h:165
void SetParent(uint32_t iif)
Definition: ipv4-route.cc:134
IPv4 route cache entry (similar to Linux struct rtable)
Definition: ipv4-route.h:42
Ipv4Address m_source
Source address.
Definition: ipv4-route.h:92
void SetGateway(Ipv4Address gw)
Definition: ipv4-route.cc:64
Ptr< NetDevice > GetOutputDevice() const
Definition: ipv4-route.cc:85
Ipv4Address GetGateway() const
Definition: ipv4-route.cc:71
void SetDestination(Ipv4Address dest)
Definition: ipv4-route.cc:36
void SetSource(Ipv4Address src)
Definition: ipv4-route.cc:50
Ipv4Address GetSource() const
Definition: ipv4-route.cc:57
Ipv4Address m_gateway
Gateway address.
Definition: ipv4-route.h:93
void SetOutputDevice(Ptr< NetDevice > outputDevice)
Equivalent in Linux to dst_entry.dev.
Definition: ipv4-route.cc:78
Ipv4Address GetDestination() const
Definition: ipv4-route.cc:43
Ptr< NetDevice > m_outputDevice
Output device.
Definition: ipv4-route.h:94
Ipv4Address m_dest
Destination address.
Definition: ipv4-route.h:91
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159