OLD | NEW |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2008 University of Washington | 3 * Copyright (c) 2008 University of Washington |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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 | 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 | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 */ | 17 */ |
18 | 18 |
19 #include "ns3/assert.h" | 19 #include "ns3/assert.h" |
20 #include "ns3/log.h" | 20 #include "ns3/log.h" |
21 #include "ns3/ptr.h" | 21 #include "ns3/ptr.h" |
22 #include "ns3/node.h" | 22 #include "ns3/node.h" |
23 #include "ns3/net-device.h" | 23 #include "ns3/net-device.h" |
| 24 #include "ns3/loopback-net-device.h" |
24 #include "ns3/ipv4.h" | 25 #include "ns3/ipv4.h" |
25 #include "ns3/ipv4-address-generator.h" | 26 #include "ns3/ipv4-address-generator.h" |
26 #include "ns3/simulator.h" | 27 #include "ns3/simulator.h" |
| 28 #include "ns3/traffic-control-helper.h" |
| 29 #include "ns3/traffic-control-layer.h" |
27 #include "ipv4-address-helper.h" | 30 #include "ipv4-address-helper.h" |
28 | 31 |
29 namespace ns3 { | 32 namespace ns3 { |
30 | 33 |
31 NS_LOG_COMPONENT_DEFINE ("Ipv4AddressHelper"); | 34 NS_LOG_COMPONENT_DEFINE ("Ipv4AddressHelper"); |
32 | 35 |
33 Ipv4AddressHelper::Ipv4AddressHelper ()· | 36 Ipv4AddressHelper::Ipv4AddressHelper ()· |
34 { | 37 { |
35 NS_LOG_FUNCTION_NOARGS (); | 38 NS_LOG_FUNCTION_NOARGS (); |
36 | 39 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 interface = ipv4->AddInterface (device); | 153 interface = ipv4->AddInterface (device); |
151 } | 154 } |
152 NS_ASSERT_MSG (interface >= 0, "Ipv4AddressHelper::Assign(): " | 155 NS_ASSERT_MSG (interface >= 0, "Ipv4AddressHelper::Assign(): " |
153 "Interface index not found"); | 156 "Interface index not found"); |
154 | 157 |
155 Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (NewAddress (), m_mas
k); | 158 Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (NewAddress (), m_mas
k); |
156 ipv4->AddAddress (interface, ipv4Addr); | 159 ipv4->AddAddress (interface, ipv4Addr); |
157 ipv4->SetMetric (interface, 1); | 160 ipv4->SetMetric (interface, 1); |
158 ipv4->SetUp (interface); | 161 ipv4->SetUp (interface); |
159 retval.Add (ipv4, interface); | 162 retval.Add (ipv4, interface); |
| 163 |
| 164 Ptr<TrafficControlLayer> tc = node->GetObject<TrafficControlLayer> (); |
| 165 |
| 166 NS_ASSERT_MSG (tc, "Ipv4AddressHelper::Assign(): NetDevice is associated" |
| 167 "with a node without the Traffic Control layer installed"); |
| 168 |
| 169 // Install the default traffic control configuration, if this is not a loo
pback |
| 170 // interface and there is no queue disc installed already |
| 171 if (DynamicCast<LoopbackNetDevice> (device) == 0 && tc->GetRootQueueDiscOn
Device (device) == 0) |
| 172 { |
| 173 TrafficControlHelper tcHelper = TrafficControlHelper::Default (); |
| 174 tcHelper.Install (device); |
| 175 } |
160 } | 176 } |
161 return retval; | 177 return retval; |
162 } | 178 } |
163 | 179 |
164 const uint32_t N_BITS = 32; //!< number of bits in a IPv4 address | 180 const uint32_t N_BITS = 32; //!< number of bits in a IPv4 address |
165 | 181 |
166 uint32_t | 182 uint32_t |
167 Ipv4AddressHelper::NumAddressBits (uint32_t maskbits) const | 183 Ipv4AddressHelper::NumAddressBits (uint32_t maskbits) const |
168 { | 184 { |
169 NS_LOG_FUNCTION_NOARGS (); | 185 NS_LOG_FUNCTION_NOARGS (); |
170 for (uint32_t i = 0; i < N_BITS; ++i) | 186 for (uint32_t i = 0; i < N_BITS; ++i) |
171 { | 187 { |
172 if (maskbits & 1) | 188 if (maskbits & 1) |
173 { | 189 { |
174 NS_LOG_LOGIC ("NumAddressBits -> " << i); | 190 NS_LOG_LOGIC ("NumAddressBits -> " << i); |
175 return i; | 191 return i; |
176 } | 192 } |
177 maskbits >>= 1; | 193 maskbits >>= 1; |
178 } | 194 } |
179 | 195 |
180 NS_ASSERT_MSG (false, "Ipv4AddressHelper::NumAddressBits(): Bad Mask"); | 196 NS_ASSERT_MSG (false, "Ipv4AddressHelper::NumAddressBits(): Bad Mask"); |
181 return 0; | 197 return 0; |
182 } | 198 } |
183 | 199 |
184 } // namespace ns3 | 200 } // namespace ns3 |
185 | 201 |
OLD | NEW |