author | Craig Dowell <craigdo@ee.washington.edu> |
Fri, 05 Oct 2007 18:17:18 -0700 | |
changeset 1836 | 618a749157e3 |
parent 1835 | ccd0fc4d9bf8 |
permissions | -rw-r--r-- |
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
2 |
/* |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
3 |
* Copyright (c) 2007 University of Washington |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
4 |
* |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
8 |
* |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
13 |
* |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
17 |
*/ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
18 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
19 |
#include "ns3/assert.h" |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
20 |
#include "ns3/log.h" |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
21 |
#include "ns3/simulation-singleton.h" |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
22 |
#include "ipv4-address-extended.h" |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
23 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
24 |
NS_LOG_COMPONENT_DEFINE("Ipv4AddressEx"); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
25 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
26 |
namespace ns3 { |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
27 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
28 |
class Ipv4NetworkManager |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
29 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
30 |
public: |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
31 |
Ipv4NetworkManager (); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
32 |
virtual ~Ipv4NetworkManager (); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
33 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
34 |
Ipv4Address Allocate (const Ipv4Mask mask); |
1836 | 35 |
void Seed (const Ipv4Mask mask, const Ipv4Address network); |
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
36 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
37 |
private: |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
38 |
static const uint32_t N_BITS = 32; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
39 |
class State |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
40 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
41 |
public: |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
42 |
uint32_t mask; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
43 |
uint32_t network; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
44 |
}; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
45 |
State m_state[N_BITS]; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
46 |
}; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
47 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
48 |
Ipv4NetworkManager::Ipv4NetworkManager () |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
49 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
50 |
NS_LOG_FUNCTION; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
51 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
52 |
uint32_t mask = 0; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
53 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
54 |
for (uint32_t i = 0; i < N_BITS; ++i) |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
55 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
56 |
m_state[i].mask = mask; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
57 |
mask >>= 1; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
58 |
mask |= 0x80000000; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
59 |
m_state[i].network = 0; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
60 |
NS_LOG_LOGIC ("m_state[" << i << "]"); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
61 |
NS_LOG_LOGIC ("mask = " << std::hex << m_state[i].mask); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
62 |
NS_LOG_LOGIC ("network = " << std::hex << m_state[i].network); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
63 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
64 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
65 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
66 |
Ipv4NetworkManager::~Ipv4NetworkManager () |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
67 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
68 |
NS_LOG_FUNCTION; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
69 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
70 |
|
1836 | 71 |
void |
72 |
Ipv4NetworkManager::Seed (const Ipv4Mask mask, const Ipv4Address network) |
|
73 |
{ |
|
74 |
NS_LOG_FUNCTION; |
|
75 |
||
76 |
uint32_t maskBits = mask.GetHostOrder (); |
|
77 |
uint32_t networkBits = network.GetHostOrder (); |
|
78 |
||
79 |
for (uint32_t i = 0; i < N_BITS; ++i) |
|
80 |
{ |
|
81 |
if (maskBits & 1) |
|
82 |
{ |
|
83 |
uint32_t nMaskBits = N_BITS - i; |
|
84 |
NS_ASSERT(nMaskBits >= 0 && nMaskBits < N_BITS); |
|
85 |
m_state[nMaskBits].network = networkBits >> (N_BITS - i); |
|
86 |
return; |
|
87 |
} |
|
88 |
maskBits >>= 1; |
|
89 |
} |
|
90 |
NS_ASSERT_MSG(false, "Impossible"); |
|
91 |
return; |
|
92 |
} |
|
93 |
||
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
94 |
Ipv4Address |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
95 |
Ipv4NetworkManager::Allocate (const Ipv4Mask mask) |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
96 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
97 |
NS_LOG_FUNCTION; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
98 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
99 |
uint32_t bits = mask.GetHostOrder (); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
100 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
101 |
for (uint32_t i = 0; i < N_BITS; ++i) |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
102 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
103 |
if (bits & 1) |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
104 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
105 |
uint32_t nBits = N_BITS - i; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
106 |
NS_ASSERT(nBits >= 0 && nBits < N_BITS); |
1836 | 107 |
Ipv4Address addr (m_state[nBits].network << i); |
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
108 |
++m_state[nBits].network; |
1836 | 109 |
return addr; |
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
110 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
111 |
bits >>= 1; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
112 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
113 |
NS_ASSERT_MSG(false, "Impossible"); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
114 |
return Ipv4Address (bits); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
115 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
116 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
117 |
class Ipv4AddressManager |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
118 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
119 |
public: |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
120 |
Ipv4AddressManager (); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
121 |
virtual ~Ipv4AddressManager (); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
122 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
123 |
Ipv4Address Allocate (const Ipv4Mask mask, const Ipv4Address network); |
1836 | 124 |
void Seed (const Ipv4Mask mask, const Ipv4Address address); |
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
125 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
126 |
private: |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
127 |
static const uint32_t N_BITS = 32; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
128 |
class State |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
129 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
130 |
public: |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
131 |
uint32_t mask; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
132 |
uint32_t address; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
133 |
}; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
134 |
State m_state[N_BITS]; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
135 |
}; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
136 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
137 |
Ipv4AddressManager::Ipv4AddressManager () |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
138 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
139 |
NS_LOG_FUNCTION; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
140 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
141 |
uint32_t mask = 0; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
142 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
143 |
for (uint32_t i = 0; i < N_BITS; ++i) |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
144 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
145 |
m_state[i].mask = mask; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
146 |
mask >>= 1; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
147 |
mask |= 0x80000000; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
148 |
m_state[i].address = 0; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
149 |
NS_LOG_LOGIC ("m_state[" << i << "]"); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
150 |
NS_LOG_LOGIC ("mask = " << std::hex << m_state[i].mask); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
151 |
NS_LOG_LOGIC ("address = " << std::hex << m_state[i].address); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
152 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
153 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
154 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
155 |
Ipv4AddressManager::~Ipv4AddressManager () |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
156 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
157 |
NS_LOG_FUNCTION; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
158 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
159 |
|
1836 | 160 |
void |
161 |
Ipv4AddressManager::Seed (const Ipv4Mask mask, const Ipv4Address address) |
|
162 |
{ |
|
163 |
NS_LOG_FUNCTION; |
|
164 |
||
165 |
uint32_t maskBits = mask.GetHostOrder (); |
|
166 |
uint32_t addressBits = address.GetHostOrder (); |
|
167 |
||
168 |
for (uint32_t i = 0; i < N_BITS; ++i) |
|
169 |
{ |
|
170 |
if (maskBits & 1) |
|
171 |
{ |
|
172 |
uint32_t nMaskBits = N_BITS - i; |
|
173 |
NS_ASSERT(nMaskBits >= 0 && nMaskBits < N_BITS); |
|
174 |
m_state[nMaskBits].address = addressBits; |
|
175 |
return; |
|
176 |
} |
|
177 |
maskBits >>= 1; |
|
178 |
} |
|
179 |
NS_ASSERT_MSG(false, "Impossible"); |
|
180 |
return; |
|
181 |
} |
|
182 |
||
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
183 |
Ipv4Address |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
184 |
Ipv4AddressManager::Allocate (const Ipv4Mask mask, const Ipv4Address network) |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
185 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
186 |
NS_LOG_FUNCTION; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
187 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
188 |
uint32_t bits = mask.GetHostOrder (); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
189 |
uint32_t net = network.GetHostOrder (); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
190 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
191 |
for (uint32_t i = 0; i < N_BITS; ++i) |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
192 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
193 |
if (bits & 1) |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
194 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
195 |
uint32_t nBits = N_BITS - i; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
196 |
NS_ASSERT(nBits >= 0 && nBits < N_BITS); |
1836 | 197 |
Ipv4Address addr (net | m_state[nBits].address); |
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
198 |
++m_state[nBits].address; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
199 |
NS_ASSERT_MSG((m_state[nBits].mask & m_state[nBits].address) == 0, |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
200 |
"Ipv4AddressManager::Allocate(): Overflow"); |
1836 | 201 |
return addr; |
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
202 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
203 |
bits >>= 1; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
204 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
205 |
NS_ASSERT_MSG(false, "Impossible"); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
206 |
return Ipv4Address (bits); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
207 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
208 |
|
1836 | 209 |
void |
210 |
Ipv4AddressEx::SeedAddress (const Ipv4Mask mask, const Ipv4Address address) |
|
211 |
{ |
|
212 |
NS_LOG_FUNCTION; |
|
213 |
||
214 |
SimulationSingleton<Ipv4AddressManager>::Get ()->Seed (mask, address); |
|
215 |
} |
|
216 |
||
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
217 |
Ipv4Address |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
218 |
Ipv4AddressEx::AllocateAddress (const Ipv4Mask mask, const Ipv4Address network) |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
219 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
220 |
NS_LOG_FUNCTION; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
221 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
222 |
return SimulationSingleton<Ipv4AddressManager>::Get ()-> |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
223 |
Allocate (mask, network); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
224 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
225 |
|
1836 | 226 |
void |
227 |
Ipv4AddressEx::SeedNetwork (const Ipv4Mask mask, const Ipv4Address address) |
|
228 |
{ |
|
229 |
NS_LOG_FUNCTION; |
|
230 |
||
231 |
SimulationSingleton<Ipv4NetworkManager>::Get ()->Seed (mask, address); |
|
232 |
} |
|
233 |
||
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
234 |
Ipv4Address |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
235 |
Ipv4AddressEx::AllocateNetwork (const Ipv4Mask mask) |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
236 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
237 |
NS_LOG_FUNCTION; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
238 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
239 |
return SimulationSingleton<Ipv4NetworkManager>::Get ()-> |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
240 |
Allocate (mask); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
241 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
242 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
243 |
}; // namespace ns3 |