author | Lalith Suresh <suresh.lalith@gmail.com> |
Sun, 18 Jul 2010 13:29:13 +0530 | |
changeset 6339 | 366418369bda |
parent 4563 | 55948d1baa64 |
permissions | -rw-r--r-- |
4373
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
2 |
/* |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
3 |
* Copyright (c) 2008 University of Washington |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
4 |
* |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
8 |
* |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
13 |
* |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
17 |
* |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
18 |
*/ |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
19 |
|
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
20 |
#ifndef IPV4_INTERFACE_ADDRESS_H |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
21 |
#define IPV4_INTERFACE_ADDRESS_H |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
22 |
|
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
23 |
#include <stdint.h> |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
24 |
#include <ostream> |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
25 |
#include "ipv4-address.h" |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
26 |
|
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
27 |
namespace ns3 { |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
28 |
|
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
29 |
/** |
4381
3e6c3e4b55bd
Remove m_peer from Ipv4InterfaceAddress class (unused member)
Tom Henderson <tomh@tomh.org>
parents:
4373
diff
changeset
|
30 |
* \ingroup address |
3e6c3e4b55bd
Remove m_peer from Ipv4InterfaceAddress class (unused member)
Tom Henderson <tomh@tomh.org>
parents:
4373
diff
changeset
|
31 |
* |
4373
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
32 |
* \brief a class to store IPv4 address information on an interface |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
33 |
* |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
34 |
* Corresponds to Linux struct in_ifaddr. A list of these addresses |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
35 |
* is stored in Ipv4Interface. This class is modelled after how current |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
36 |
* Linux handles IP aliasing for IPv4. Notably, aliasing of IPv4 |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
37 |
* interfaces (e.g., "eth0:1") is not used, and instead an interface |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
38 |
* is assigned possibly multiple addresses, with each address being |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
39 |
* classified as being primary and secondary. See the iproute2 |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
40 |
* documentation for this distinction. |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
41 |
*/ |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
42 |
class Ipv4InterfaceAddress |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
43 |
{ |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
44 |
public: |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
45 |
enum InterfaceAddressScope_e { |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
46 |
HOST, |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
47 |
LINK, |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
48 |
GLOBAL |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
49 |
}; |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
50 |
|
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
51 |
Ipv4InterfaceAddress (); |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
52 |
// Configure m_local, m_mask, and m_broadcast from the below constructor |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
53 |
Ipv4InterfaceAddress (Ipv4Address local, Ipv4Mask mask); |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
54 |
Ipv4InterfaceAddress (const Ipv4InterfaceAddress &o); |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
55 |
|
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
56 |
void SetLocal (Ipv4Address local); |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
57 |
Ipv4Address GetLocal (void) const; |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
58 |
void SetMask (Ipv4Mask mask); |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
59 |
Ipv4Mask GetMask (void) const; |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
60 |
void SetBroadcast (Ipv4Address broadcast); |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
61 |
Ipv4Address GetBroadcast (void) const; |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
62 |
|
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
63 |
void SetScope (Ipv4InterfaceAddress::InterfaceAddressScope_e scope); |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
64 |
Ipv4InterfaceAddress::InterfaceAddressScope_e GetScope (void) const; |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
65 |
|
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
66 |
bool IsSecondary (void) const; |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
67 |
void SetSecondary (void); |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
68 |
void SetPrimary (void); |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
69 |
|
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
70 |
private: |
4381
3e6c3e4b55bd
Remove m_peer from Ipv4InterfaceAddress class (unused member)
Tom Henderson <tomh@tomh.org>
parents:
4373
diff
changeset
|
71 |
|
4373
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
72 |
Ipv4Address m_local; // Interface address |
4381
3e6c3e4b55bd
Remove m_peer from Ipv4InterfaceAddress class (unused member)
Tom Henderson <tomh@tomh.org>
parents:
4373
diff
changeset
|
73 |
// Note: m_peer may be added in future when necessary |
3e6c3e4b55bd
Remove m_peer from Ipv4InterfaceAddress class (unused member)
Tom Henderson <tomh@tomh.org>
parents:
4373
diff
changeset
|
74 |
// Ipv4Address m_peer; // Peer destination address (in Linux: m_address) |
4373
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
75 |
Ipv4Mask m_mask; // Network mask |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
76 |
Ipv4Address m_broadcast; // Broadcast address |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
77 |
|
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
78 |
InterfaceAddressScope_e m_scope; |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
79 |
bool m_secondary; // For use in multihoming |
4563 | 80 |
|
81 |
friend bool operator == (Ipv4InterfaceAddress const &a, Ipv4InterfaceAddress const &b); |
|
82 |
friend bool operator != (Ipv4InterfaceAddress const &a, Ipv4InterfaceAddress const &b); |
|
4373
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
83 |
}; |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
84 |
|
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
85 |
std::ostream& operator<< (std::ostream& os, const Ipv4InterfaceAddress &addr); |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
86 |
|
4563 | 87 |
inline bool operator == (const Ipv4InterfaceAddress &a, const Ipv4InterfaceAddress &b) |
88 |
{ |
|
89 |
return (a.m_local == b.m_local && a.m_mask == b.m_mask && |
|
90 |
a.m_broadcast == b.m_broadcast && a.m_scope == b.m_scope && a.m_secondary == b.m_secondary); |
|
91 |
} |
|
92 |
inline bool operator != (const Ipv4InterfaceAddress &a, const Ipv4InterfaceAddress &b) |
|
93 |
{ |
|
94 |
return (a.m_local != b.m_local || a.m_mask != b.m_mask || |
|
95 |
a.m_broadcast != b.m_broadcast || a.m_scope != b.m_scope || a.m_secondary != b.m_secondary); |
|
96 |
} |
|
97 |
||
98 |
||
4373
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
99 |
} // namespace ns3 |
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
100 |
|
e493e80274bd
implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
101 |
#endif /* IPV4_ADDRESS_H */ |