author | Craig Dowell <craigdo@ee.washington.edu> |
Fri, 21 Mar 2008 17:26:01 -0700 | |
changeset 2711 | 83addb15f632 |
child 2712 | 02f089bd33f0 |
permissions | -rw-r--r-- |
2711
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
2 |
/* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
3 |
* Copyright (c) 2008 University of Washington |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
4 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
8 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
13 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
17 |
*/ |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
18 |
|
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
19 |
#ifndef IPV4_ADDRESS_HELPER_H |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
20 |
#define IPV4_ADDRESS_HELPER_H |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
21 |
|
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
22 |
#include "ns3/ipv4-address.h" |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
23 |
#include "ns3/net-device-container.h" |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
24 |
|
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
25 |
namespace ns3 { |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
26 |
|
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
27 |
/** |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
28 |
* @brief A helper class to make life easier while doing simple IPv4 address |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
29 |
* assignment in scripts. |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
30 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
31 |
* This class is a very simple IPv4 address generator. You can think of it |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
32 |
* as a simple local number incrementer. It has no notion that IP addresses |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
33 |
* are part of a global address space. If you have a complicated address |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
34 |
* assignment situation you may want to look at the Ipv4AddressGenerator which |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
35 |
* does recognize that IP address and netowrk number generation is part of a |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
36 |
* global problem. Ipv4AddressHelper is a simple class to make simple problems |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
37 |
* easy to handle. |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
38 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
39 |
* We do call into the global address generator to make sure that there are |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
40 |
* no duplicate addresses generated. |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
41 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
42 |
* @see Ipv4AddressGenerator |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
43 |
*/ |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
44 |
class Ipv4AddressHelper |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
45 |
{ |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
46 |
public: |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
47 |
/** |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
48 |
* @brief Construct a helper class to make life easier while doing simple IPv4 |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
49 |
* address assignment in scripts. |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
50 |
*/ |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
51 |
Ipv4AddressHelper (); |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
52 |
|
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
53 |
/** |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
54 |
* @brief Set the base network mumber, network mask and base address. |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
55 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
56 |
* The address helper allocates IP addresses based on a given network number |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
57 |
* and mask combination along with an initial IP address. |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
58 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
59 |
* For example, if you want to use a /24 prefix with an initial network number |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
60 |
* of 192.168.1 (corresponding to a mask of 255.255.255.0) and you want to |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
61 |
* start allocating IP addresses out of that network beginning at 192.168.1.3, |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
62 |
* you would call |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
63 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
64 |
* SetBase ("192.168.1.0", "255.255.255.0", "0.0.0.3"); |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
65 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
66 |
* If you don't care about the initial address it defaults to "0.0.0.0" in |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
67 |
* which case you can simply use, |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
68 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
69 |
* SetBase ("192.168.1.0", "255.255.255.0", "0.0.0.3"); |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
70 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
71 |
* @param network The Ipv4Address containing the initial network number to |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
72 |
* use during allocation. The bits outside the nework mask are not used. |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
73 |
* @param mask The Ipv4Mask containing one bits in each bit position of the |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
74 |
* network number. |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
75 |
* @param base An optional Ipv4Address containing the initial address used for |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
76 |
* IP address alloction. Will be combined (ORed) with the network number to |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
77 |
* generate the first IP address. Defaults to 0.0.0.0 |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
78 |
* @returns Nothing. |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
79 |
*/ |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
80 |
void SetBase (Ipv4Address network, Ipv4Mask mask, |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
81 |
Ipv4Address base = "0.0.0.0"); |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
82 |
|
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
83 |
/** |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
84 |
* @brief Increment the network number and reset the IP address counter to |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
85 |
* the base value provided in the SetBase method. |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
86 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
87 |
* The address helper allocates IP addresses based on a given network number |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
88 |
* and initial IP address. In order to separate the network number and IP |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
89 |
* address parts, SetBase was given an initial network number value, a network |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
90 |
* mask and an initial address base. |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
91 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
92 |
* This method increments the network number and resets the IP address |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
93 |
* counter to the last base value used. For example, if the network number was |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
94 |
* set to 192.168.0.0 with a mask of 255.255.255.0 and a base address of |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
95 |
* 0.0.0.3 in the SetBase call; a call to NewNetwork will increment the |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
96 |
* network number counter resulting in network numbers incrementing as |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
97 |
* 192.168.1.0, 192.168.2.0, etc. After each network number increment, the |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
98 |
* IP address counter is reset to the initial value specified in SetBase. In |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
99 |
* this case, that would be 0.0.0.3. so if you were to call NewAddress after |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
100 |
* the increment that resulted in a network numebr of 192.168.2.0, the |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
101 |
* allocated addresses returned by NewAddress would be 192.168.2.3, |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
102 |
* 192.168.2.4, etc. |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
103 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
104 |
* @returns The value of the incremented network number that will be used in |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
105 |
* following address allocations. |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
106 |
* @see SetBase |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
107 |
* @see NewAddress |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
108 |
*/ |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
109 |
Ipv4Address NewNetwork (void); |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
110 |
|
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
111 |
/** |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
112 |
* @brief Increment the IP address counter used to allocate IP addresses |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
113 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
114 |
* The address helper allocates IP addresses based on a given network number |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
115 |
* and initial IP address. In order to separate the network number and IP |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
116 |
* address parts, SetBase was given an initial network number value, a network |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
117 |
* mask and an initial address base. |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
118 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
119 |
* This method increments IP address counter. A check is made to ensure that |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
120 |
* the address returned will not overflow the number of bits allocated to IP |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
121 |
* addresses in SetBase (the number of address bits is defined by the number |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
122 |
* of mask bits that are not '1'). |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
123 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
124 |
* For example, if the network number was set to 192.168.0.0 with a mask of |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
125 |
* 255.255.255.0 and a base address of 0.0.0.3 in SetBase, the next call to |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
126 |
* NewAddress will return 192.168.1.3. The NewAddress method |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
127 |
* has post-increment semantics. A following NewAddress would return |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
128 |
* 192.168.0.4, etc., until the 256th call which would assert due to an address |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
129 |
* overflow. |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
130 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
131 |
* @returns The value of the newly allocated IP address. |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
132 |
* @see SetBase |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
133 |
* @see NewNetwork |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
134 |
*/ |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
135 |
Ipv4Address NewAddress (void); |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
136 |
|
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
137 |
/** |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
138 |
* @brief Assign IP addresses to the net devices specified in the container |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
139 |
* based on the current network prefix and address base. |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
140 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
141 |
* The address helper allocates IP addresses based on a given network number |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
142 |
* and initial IP address. In order to separate the network number and IP |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
143 |
* address parts, SetBase was given an initial value and a network mask. |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
144 |
* The one bits of this mask define the prefix category from which the helper |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
145 |
* will allocate new network numbers. An initial value for the network |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
146 |
* numbers was provided in the base parameter of the SetBase method in the |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
147 |
* bits corresponding to positions in the mask that were 1. An initial value |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
148 |
* for the IP address counter was also provided in the base parameter in the |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
149 |
* bits corresponding to positions in the mask that were 0. |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
150 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
151 |
* This method gets new addresses for each net device in the container. For |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
152 |
* each net device in the container, the helper finds the associated node and |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
153 |
* looks up the Ipv4 interface corresponding to the net device. It then sets |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
154 |
* the Ipv4Address and mask in the interface to the appropriate values. If |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
155 |
* the addresses overflow the number of bits allocated for them by the network |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
156 |
* mask in the SetBase method, the system will NS_ASSERT and halt. |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
157 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
158 |
* @param c The NetDeviceContainer holding the collection of net devices we |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
159 |
* are asked to assign Ipv4 addresses to. |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
160 |
* |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
161 |
* @returns Nothing |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
162 |
* @see SetBase |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
163 |
* @see NewNetwork |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
164 |
*/ |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
165 |
void Allocate (const NetDeviceContainer &c); |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
166 |
|
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
167 |
private: |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
168 |
uint32_t NumAddressBits (uint32_t maskbits) const; |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
169 |
|
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
170 |
uint32_t m_network; |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
171 |
uint32_t m_mask; |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
172 |
uint32_t m_address; |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
173 |
uint32_t m_base; |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
174 |
uint32_t m_shift; |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
175 |
uint32_t m_max; |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
176 |
}; |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
177 |
|
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
178 |
}; // namespace ns3 |
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
179 |
|
83addb15f632
ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
180 |
#endif /* IPV4_ADDRESS_HELPER_H */ |