4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief EUI64 public header */
26 #ifndef HH_SENF_Socket_Protocols_Raw_EUI64_
27 #define HH_SENF_Socket_Protocols_Raw_EUI64_ 1
31 #include <boost/cstdint.hpp>
32 #include <boost/array.hpp>
33 #include <senf/Utils/Tags.hh>
34 #include <senf/Utils/safe_bool.hh>
36 //#include "EUI64.mpp"
37 ///////////////////////////////hh.p////////////////////////////////////////
43 /** \brief EUI-64 data type
45 An EUI-64 is a 64 bit (8 octet) id. The id is represented as an 8 byte sequence in network
46 byte order. An EUI64 can be converted from/to several other representations
49 <tr><td><tt>boost::uint64_t</tt></td>
50 <td><tt>senf::EUI64(0x1a2b3c4d5f607182ull)</tt><br/>
51 <i>eui64</i><tt>.uint64()</tt></td></tr>
52 <tr><td><tt>std::string</tt></td>
53 <td><tt>senf::EUI64::from_string("1a:2b:3c:4d-5f:60:71:82")</tt><br/>
54 <tt>senf::str(</tt><i>eui64</i><tt>)</tt></td></tr>
55 <tr><td><i>raw data</i><br/> (8 bytes)</td>
56 <td><tt>senf::EUI64::from_data(</tt><i>iterator</i><tt>)</tt><br/>
57 <i>eui64</i><tt>.begin()</tt></td></tr>
58 <tr><td>senf::MACAddress<br/> (aka EUI-48)</td>
59 <td><tt>senf::EUI64::from_mac(</tt><i>mac-address</i><tt>)</tt><br/>
60 <tt>senf::MACAddress::from_eui64(</tt><i>eui64</i><tt>)</tt></td></tr>
63 Since senf::EUI64 is based on \c boost::array, you can access the raw data bytes of the
64 address using \c begin(), \c end() or \c operator[]:
66 senf::EUI64 eui64 (...);
67 std::vector<char> data;
69 std::copy(eui64.begin(), eui64.end(), data.begin()); // Copy 8 bytes
72 \see <a href="http://tools.ietf.org/html/rfc4291">RFC 4291</a>
77 : public boost::array<boost::uint8_t,8>,
78 public senf::comparable_safe_bool<EUI64>
81 ///////////////////////////////////////////////////////////////////////////
82 ///\name Structors and default members
85 // default copy constructor
86 // default copy assignment
88 // no conversion constructors
90 explicit EUI64(boost::uint64_t v=0u); ///< Construct EUI-64
91 explicit EUI64(senf::NoInit_t); ///< Construct <em>uninitialized</em> EUI-64
93 static EUI64 from_mac(MACAddress const & mac);
94 ///< Construct EUI-64 from senf::MACAddress
95 static EUI64 from_string(std::string const & s);
96 ///< Construct EUI-64 from string representation
97 /**< The string representation consists of 8 octets in
98 hexadecimal notation spearated by ':' or '-'
99 \throws senf::AddressSyntaxException */
100 template <class InputIterator>
101 static EUI64 from_data(InputIterator i);
102 ///< Construct EUI-64 from 8 data octets
103 /**< The iterator \a i must point to a sequence of 8
104 octets in network byte order. */
107 ///////////////////////////////////////////////////////////////////////////
109 bool isMACCompatible() const; ///< \c true, if EUI64 is MAC compatible, \c false otherwise
110 /**< An EUI64 is MAC compatible if bytes 4th and 5th byte
111 (in network byte order) are 0xfffe. */
112 bool local() const; ///< \c true if the \e local bit is set, \c false otherwise
113 /**< The \e local bit is the second least significant bit of
114 the first octet (bit 6 in standard RFC bit numbering).
116 bool group() const; ///< \c true if the \e group bit is set, \c false otherwise
117 /**< The \e group bit is the least significant bit of the
118 first octed (bit 7 in standard RFC bit numbering). */
119 bool boolean_test() const; ///< \c true, if EUI64 is != 0, \c false otherwise
120 boost::uint64_t uint64() const; ///< Return EUI64 as integer number
123 /** \brief Write out EUI64 in it's string representation to stream
126 std::ostream & operator<<(std::ostream & os, EUI64 const & v);
128 /** \brief Read EUI64 string representation from stream
131 std::istream & operator>>(std::istream & is, EUI64 & v);
135 ///////////////////////////////hh.e////////////////////////////////////////
137 //#include "EUI64.ct"
145 // comment-column: 40
146 // c-file-style: "senf"
147 // indent-tabs-mode: nil
148 // ispell-local-dictionary: "american"
149 // compile-command: "scons -u test"