author | Tom Henderson <tomh@tomh.org> |
Sat, 15 Dec 2007 14:01:36 -0800 | |
changeset 2192 | 4db981a0d9eb |
parent 1838 | 25d76cec436b |
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" |
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
22 |
#include "ipv4-address-generator.h" |
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
23 |
|
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
24 |
NS_LOG_COMPONENT_DEFINE("Ipv4AddressGenerator"); |
1835
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 |
|
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
28 |
class Ipv4NetworkGeneratorImpl |
1835
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: |
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
31 |
Ipv4NetworkGeneratorImpl (); |
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
32 |
virtual ~Ipv4NetworkGeneratorImpl (); |
1835
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 |
|
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
48 |
Ipv4NetworkGeneratorImpl::Ipv4NetworkGeneratorImpl () |
1835
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 |
|
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
66 |
Ipv4NetworkGeneratorImpl::~Ipv4NetworkGeneratorImpl () |
1835
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 |
|
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
71 |
void |
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
72 |
Ipv4NetworkGeneratorImpl::Seed ( |
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
73 |
const Ipv4Mask mask, |
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
74 |
const Ipv4Address network) |
1836 | 75 |
{ |
76 |
NS_LOG_FUNCTION; |
|
77 |
||
78 |
uint32_t maskBits = mask.GetHostOrder (); |
|
79 |
uint32_t networkBits = network.GetHostOrder (); |
|
80 |
||
81 |
for (uint32_t i = 0; i < N_BITS; ++i) |
|
82 |
{ |
|
83 |
if (maskBits & 1) |
|
84 |
{ |
|
85 |
uint32_t nMaskBits = N_BITS - i; |
|
86 |
NS_ASSERT(nMaskBits >= 0 && nMaskBits < N_BITS); |
|
87 |
m_state[nMaskBits].network = networkBits >> (N_BITS - i); |
|
88 |
return; |
|
89 |
} |
|
90 |
maskBits >>= 1; |
|
91 |
} |
|
92 |
NS_ASSERT_MSG(false, "Impossible"); |
|
93 |
return; |
|
94 |
} |
|
95 |
||
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
96 |
Ipv4Address |
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
97 |
Ipv4NetworkGeneratorImpl::Allocate (const Ipv4Mask mask) |
1835
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 |
NS_LOG_FUNCTION; |
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 |
uint32_t bits = mask.GetHostOrder (); |
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 |
for (uint32_t i = 0; i < N_BITS; ++i) |
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 |
if (bits & 1) |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
106 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
107 |
uint32_t nBits = N_BITS - i; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
108 |
NS_ASSERT(nBits >= 0 && nBits < N_BITS); |
1836 | 109 |
Ipv4Address addr (m_state[nBits].network << i); |
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
110 |
++m_state[nBits].network; |
1836 | 111 |
return addr; |
1835
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 |
bits >>= 1; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
114 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
115 |
NS_ASSERT_MSG(false, "Impossible"); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
116 |
return Ipv4Address (bits); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
117 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
118 |
|
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
119 |
class Ipv4AddressGeneratorImpl |
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
120 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
121 |
public: |
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
122 |
Ipv4AddressGeneratorImpl (); |
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
123 |
virtual ~Ipv4AddressGeneratorImpl (); |
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
124 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
125 |
Ipv4Address Allocate (const Ipv4Mask mask, const Ipv4Address network); |
1836 | 126 |
void Seed (const Ipv4Mask mask, const Ipv4Address address); |
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
127 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
128 |
private: |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
129 |
static const uint32_t N_BITS = 32; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
130 |
class State |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
131 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
132 |
public: |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
133 |
uint32_t mask; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
134 |
uint32_t address; |
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 |
State m_state[N_BITS]; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
137 |
}; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
138 |
|
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
139 |
Ipv4AddressGeneratorImpl::Ipv4AddressGeneratorImpl () |
1835
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 |
NS_LOG_FUNCTION; |
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 |
uint32_t mask = 0; |
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 |
for (uint32_t i = 0; i < N_BITS; ++i) |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
146 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
147 |
m_state[i].mask = mask; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
148 |
mask >>= 1; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
149 |
mask |= 0x80000000; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
150 |
m_state[i].address = 0; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
151 |
NS_LOG_LOGIC ("m_state[" << i << "]"); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
152 |
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
|
153 |
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
|
154 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
155 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
156 |
|
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
157 |
Ipv4AddressGeneratorImpl::~Ipv4AddressGeneratorImpl () |
1835
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 |
NS_LOG_FUNCTION; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
160 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
161 |
|
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
162 |
void |
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
163 |
Ipv4AddressGeneratorImpl::Seed ( |
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
164 |
const Ipv4Mask mask, |
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
165 |
const Ipv4Address address) |
1836 | 166 |
{ |
167 |
NS_LOG_FUNCTION; |
|
168 |
||
169 |
uint32_t maskBits = mask.GetHostOrder (); |
|
170 |
uint32_t addressBits = address.GetHostOrder (); |
|
171 |
||
172 |
for (uint32_t i = 0; i < N_BITS; ++i) |
|
173 |
{ |
|
174 |
if (maskBits & 1) |
|
175 |
{ |
|
176 |
uint32_t nMaskBits = N_BITS - i; |
|
177 |
NS_ASSERT(nMaskBits >= 0 && nMaskBits < N_BITS); |
|
178 |
m_state[nMaskBits].address = addressBits; |
|
179 |
return; |
|
180 |
} |
|
181 |
maskBits >>= 1; |
|
182 |
} |
|
183 |
NS_ASSERT_MSG(false, "Impossible"); |
|
184 |
return; |
|
185 |
} |
|
186 |
||
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
187 |
Ipv4Address |
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
188 |
Ipv4AddressGeneratorImpl::Allocate ( |
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
189 |
const Ipv4Mask mask, |
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
190 |
const Ipv4Address network) |
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
191 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
192 |
NS_LOG_FUNCTION; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
193 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
194 |
uint32_t bits = mask.GetHostOrder (); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
195 |
uint32_t net = network.GetHostOrder (); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
196 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
197 |
for (uint32_t i = 0; i < N_BITS; ++i) |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
198 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
199 |
if (bits & 1) |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
200 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
201 |
uint32_t nBits = N_BITS - i; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
202 |
NS_ASSERT(nBits >= 0 && nBits < N_BITS); |
1836 | 203 |
Ipv4Address addr (net | m_state[nBits].address); |
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
204 |
++m_state[nBits].address; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
205 |
NS_ASSERT_MSG((m_state[nBits].mask & m_state[nBits].address) == 0, |
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
206 |
"Ipv4AddressGeneratorImpl::Allocate(): Overflow"); |
1836 | 207 |
return addr; |
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
208 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
209 |
bits >>= 1; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
210 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
211 |
NS_ASSERT_MSG(false, "Impossible"); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
212 |
return Ipv4Address (bits); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
213 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
214 |
|
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
215 |
void |
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
216 |
Ipv4AddressGenerator::SeedAddress ( |
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
217 |
const Ipv4Mask mask, |
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
218 |
const Ipv4Address address) |
1836 | 219 |
{ |
220 |
NS_LOG_FUNCTION; |
|
221 |
||
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
222 |
SimulationSingleton<Ipv4AddressGeneratorImpl>::Get ()->Seed (mask, address); |
1836 | 223 |
} |
224 |
||
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
225 |
Ipv4Address |
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
226 |
Ipv4AddressGenerator::AllocateAddress ( |
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
227 |
const Ipv4Mask mask, |
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
228 |
const Ipv4Address network) |
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
229 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
230 |
NS_LOG_FUNCTION; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
231 |
|
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
232 |
return SimulationSingleton<Ipv4AddressGeneratorImpl>::Get ()-> |
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
233 |
Allocate (mask, network); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
234 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
235 |
|
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
236 |
void |
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
237 |
Ipv4AddressGenerator::SeedNetwork ( |
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
238 |
const Ipv4Mask mask, |
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
239 |
const Ipv4Address address) |
1836 | 240 |
{ |
241 |
NS_LOG_FUNCTION; |
|
242 |
||
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
243 |
SimulationSingleton<Ipv4NetworkGeneratorImpl>::Get ()->Seed (mask, address); |
1836 | 244 |
} |
245 |
||
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
246 |
Ipv4Address |
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
247 |
Ipv4AddressGenerator::AllocateNetwork (const Ipv4Mask mask) |
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
248 |
{ |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
249 |
NS_LOG_FUNCTION; |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
250 |
|
1838
25d76cec436b
more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents:
1836
diff
changeset
|
251 |
return SimulationSingleton<Ipv4NetworkGeneratorImpl>::Get ()-> |
1835
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
252 |
Allocate (mask); |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
253 |
} |
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
254 |
|
ccd0fc4d9bf8
prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
255 |
}; // namespace ns3 |