1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
3 * Copyright (c) 2007 INRIA
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20 #ifndef MAC48_ADDRESS_H
21 #define MAC48_ADDRESS_H
25 #include "ns3/attribute.h"
26 #include "ns3/attribute-helper.h"
27 #include "ipv4-address.h"
28 #include "ipv6-address.h"
37 * \brief an EUI-48 address
39 * This class can contain 48 bit IEEE addresses.
46 * \param str a string representing the new Mac48Address
48 * The format of the string is "xx:xx:xx:xx:xx:xx"
50 Mac48Address (const char *str);
53 * \param buffer address in network order
55 * Copy the input address to our internal buffer.
57 void CopyFrom (const uint8_t buffer[6]);
59 * \param buffer address in network order
61 * Copy the internal address to the input buffer.
63 void CopyTo (uint8_t buffer[6]) const;
66 * \returns a new Address instance
68 * Convert an instance of this class to a polymorphic Address instance.
70 operator Address () const;
72 * \param address a polymorphic address
73 * \returns a new Mac48Address from the polymorphic address
75 * This function performs a type check and asserts if the
76 * type of the input address is not compatible with an
79 static Mac48Address ConvertFrom (const Address &address);
81 * \returns true if the address matches, false otherwise.
83 static bool IsMatchingType (const Address &address);
85 * Allocate a new Mac48Address.
87 static Mac48Address Allocate (void);
90 * \returns true if this is a broadcast address, false otherwise.
92 bool IsBroadcast (void) const;
94 * \returns true if this is a multicast address, false otherwise.
96 bool IsMulticast (void) const;
98 * \returns true if the group bit is set, false otherwise.
100 bool IsGroup (void) const;
103 * \returns the broadcast address
105 static Mac48Address GetBroadcast (void);
108 * \returns a multicast address
110 static Mac48Address GetMulticast (Ipv4Address address);
113 * \brief Get multicast address from IPv6 address.
114 * \returns a multicast address
116 static Mac48Address GetMulticast (Ipv6Address address);
119 * \returns the multicast prefix (01:00:5e:00:00:00).
121 static Mac48Address GetMulticastPrefix (void);
124 * \brief Get the multicast prefix for IPv6 (33:33:00:00:00:00).
125 * \returns a multicast address.
127 static Mac48Address GetMulticast6Prefix (void);
130 * \returns a new Address instance
132 * Convert an instance of this class to a polymorphic Address instance.
134 Address ConvertTo (void) const;
135 static uint8_t GetType (void);
136 friend bool operator < (const Mac48Address &a, const Mac48Address &b);
137 friend bool operator == (const Mac48Address &a, const Mac48Address &b);
138 friend std::istream& operator>> (std::istream& is, Mac48Address & address);
140 uint8_t m_address[6];
144 * \class ns3::Mac48AddressValue
145 * \brief hold objects of type ns3::Mac48Address
148 ATTRIBUTE_HELPER_HEADER (Mac48Address);
150 bool operator == (const Mac48Address &a, const Mac48Address &b);
151 bool operator != (const Mac48Address &a, const Mac48Address &b);
152 bool operator < (const Mac48Address &a, const Mac48Address &b);
153 std::ostream& operator<< (std::ostream& os, const Mac48Address & address);
154 std::istream& operator>> (std::istream& is, Mac48Address & address);
158 #endif /* MAC48_ADDRESS_H */