7599
|
1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
|
2 |
/*
|
|
3 |
* Copyright (c) 2008 University of Washington
|
|
4 |
* Copyright (c) 2011 Atishay Jain
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License version 2 as
|
|
8 |
* published by the Free Software Foundation;
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
18 |
*/
|
|
19 |
|
|
20 |
#ifndef IPV6_ADDRESS_GENERATOR_H
|
|
21 |
#define IPV6_ADDRESS_GENERATOR_H
|
|
22 |
|
|
23 |
#include "ns3/ipv6-address.h"
|
|
24 |
|
|
25 |
namespace ns3 {
|
|
26 |
|
|
27 |
/**
|
|
28 |
* \ingroup address
|
|
29 |
*
|
|
30 |
* \brief This generator assigns addresses sequentially from a provided
|
|
31 |
* network address; used in topology code. It also keeps track of all
|
|
32 |
* addresses assigned to perform duplicate detection.
|
|
33 |
*
|
|
34 |
* Global unicast IPv6 addresses based on RFC 4291 definition:
|
|
35 |
*
|
|
36 |
* | n bits | m bits | 128-n-m bits |
|
|
37 |
* +-------------------------+-----------+----------------------------+
|
|
38 |
* | global routing prefix | subnet ID | interface ID |
|
|
39 |
* +-------------------------+-----------+----------------------------+
|
|
40 |
*
|
|
41 |
* In this class, the first two quantities (n + m) are what is called the
|
|
42 |
* 'net', and the 'prefix' defines the length in bits of (n + m).
|
|
43 |
*
|
|
44 |
* The way this is expected to be used is that, after initializing the
|
|
45 |
* network and interfaceId to a number, a user can call NextAddress ()
|
|
46 |
* repeatedly to obtain new interface IDs with the current network (for
|
|
47 |
* multiple addresses on the link) and can call NextNetwork () to increment
|
|
48 |
* the subnet ID.
|
|
49 |
*
|
|
50 |
* The interface ID is often an EUI-64 address derived from the MAC address,
|
|
51 |
* but can also be a pseudo-random value (RFC 3041). This implementation
|
|
52 |
* does not generate EUI-64-based interface IDs.
|
|
53 |
*/
|
|
54 |
class Ipv6AddressGenerator
|
|
55 |
{
|
|
56 |
public:
|
|
57 |
/**
|
|
58 |
* \brief Initialise the base network and interfaceId for the generator
|
|
59 |
*
|
|
60 |
* The first call to NextAddress() or GetAddress() will return the
|
|
61 |
* value passed in.
|
|
62 |
*
|
|
63 |
* \param net The network for the base Ipv6Address
|
|
64 |
* \param prefix The prefix of the base Ipv6Address
|
|
65 |
* \param interfaceId The base interface ID used for initialization
|
|
66 |
*/
|
|
67 |
static void Init (const Ipv6Address net, const Ipv6Prefix prefix,
|
|
68 |
const Ipv6Address interfaceId = "::1");
|
|
69 |
|
|
70 |
/**
|
|
71 |
* \brief Get the next network acoording to the given Ipv6Prefix
|
|
72 |
*
|
|
73 |
* This operation is a pre-increment, meaning that the internal state
|
|
74 |
* is changed before returning the new network address.
|
|
75 |
*
|
|
76 |
* This also resets the interface ID to the base interface ID that was
|
|
77 |
* used for initialization.
|
|
78 |
*
|
|
79 |
* \param prefix The Ipv6Prefix used to set the next network
|
|
80 |
*/
|
|
81 |
static Ipv6Address NextNetwork (const Ipv6Prefix prefix);
|
|
82 |
|
|
83 |
/**
|
|
84 |
* \brief Get the current network of the given Ipv6Prefix
|
|
85 |
*
|
|
86 |
* Does not change the internal state; this just peeks at the current
|
|
87 |
* network
|
|
88 |
*
|
|
89 |
* \param prefix The Ipv6Prefix for the current network
|
|
90 |
*/
|
|
91 |
static Ipv6Address GetNetwork (const Ipv6Prefix prefix);
|
|
92 |
|
|
93 |
/**
|
|
94 |
* \brief Set the interfaceId for the given Ipv6Prefix
|
|
95 |
*
|
|
96 |
* \param interfaceId The interfaceId to set for the current Ipv6Prefix
|
|
97 |
* \param prefix The Ipv6Prefix whose address is to be set
|
|
98 |
*/
|
|
99 |
static void InitAddress (const Ipv6Address interfaceId, const Ipv6Prefix prefix);
|
|
100 |
|
|
101 |
/**
|
|
102 |
* \brief Allocate the next Ipv6Address for the configured network and prefix
|
|
103 |
*
|
|
104 |
* This operation is a post-increment, meaning that the first address
|
|
105 |
* allocated will be the one that was initially configured.
|
|
106 |
* .
|
|
107 |
* \param prefix The Ipv6Prefix for the current network
|
|
108 |
*/
|
|
109 |
static Ipv6Address NextAddress (const Ipv6Prefix prefix);
|
|
110 |
|
|
111 |
/**
|
|
112 |
* \brief Get the Ipv6Address that will be allocated upon NextAddress()
|
|
113 |
*
|
|
114 |
* Does not change the internal state; just is used to peek the next
|
|
115 |
* address that will be allocated upon NextAddress ()
|
|
116 |
*
|
|
117 |
* \param prefix The Ipv6Prefix for the current network
|
|
118 |
*/
|
|
119 |
static Ipv6Address GetAddress (const Ipv6Prefix prefix);
|
|
120 |
|
|
121 |
/**
|
|
122 |
* \brief Reset the networks and Ipv6Address to zero
|
|
123 |
*/
|
|
124 |
static void Reset (void);
|
|
125 |
|
|
126 |
/**
|
|
127 |
* \brief Add the Ipv6Address to the list of IPv6 entries
|
|
128 |
*
|
|
129 |
* Typically, this is used by external address allocators that want
|
|
130 |
* to make use of this class's ability to track duplicates. AddAllocated
|
|
131 |
* is always called internally for any address generated by NextAddress()
|
|
132 |
*
|
|
133 |
* \param addr The Ipv6Address to be added to the list of Ipv6 entries
|
|
134 |
*/
|
|
135 |
static bool AddAllocated (const Ipv6Address addr);
|
|
136 |
|
|
137 |
/**
|
|
138 |
* \brief Used to turn off fatal errors and assertions, for testing
|
|
139 |
*/
|
|
140 |
static void TestMode (void);
|
|
141 |
};
|
|
142 |
|
|
143 |
}; // namespace ns3
|
|
144 |
|
|
145 |
#endif /* IPV6_ADDRESS_GENERATOR_H */
|