00001 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2007 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 */ 00020 #ifndef MAC48_ADDRESS_H 00021 #define MAC48_ADDRESS_H 00022 00023 #include <stdint.h> 00024 #include <ostream> 00025 #include "ns3/attribute.h" 00026 #include "ns3/attribute-helper.h" 00027 #include "ipv4-address.h" 00028 #include "ipv6-address.h" 00029 00030 namespace ns3 { 00031 00032 class Address; 00033 00034 /** 00035 * \ingroup address 00036 * 00037 * \brief an EUI-48 address 00038 * 00039 * This class can contain 48 bit IEEE addresses. 00040 */ 00041 class Mac48Address 00042 { 00043 public: 00044 Mac48Address (); 00045 /** 00046 * \param str a string representing the new Mac48Address 00047 * 00048 * The format of the string is "xx:xx:xx:xx:xx:xx" 00049 */ 00050 Mac48Address (const char *str); 00051 00052 /** 00053 * \param buffer address in network order 00054 * 00055 * Copy the input address to our internal buffer. 00056 */ 00057 void CopyFrom (const uint8_t buffer[6]); 00058 /** 00059 * \param buffer address in network order 00060 * 00061 * Copy the internal address to the input buffer. 00062 */ 00063 void CopyTo (uint8_t buffer[6]) const; 00064 00065 /** 00066 * \returns a new Address instance 00067 * 00068 * Convert an instance of this class to a polymorphic Address instance. 00069 */ 00070 operator Address () const; 00071 /** 00072 * \param address a polymorphic address 00073 * \returns a new Mac48Address from the polymorphic address 00074 * 00075 * This function performs a type check and asserts if the 00076 * type of the input address is not compatible with an 00077 * Mac48Address. 00078 */ 00079 static Mac48Address ConvertFrom (const Address &address); 00080 /** 00081 * \returns true if the address matches, false otherwise. 00082 */ 00083 static bool IsMatchingType (const Address &address); 00084 /** 00085 * Allocate a new Mac48Address. 00086 */ 00087 static Mac48Address Allocate (void); 00088 00089 /** 00090 * \returns true if this is a broadcast address, false otherwise. 00091 */ 00092 bool IsBroadcast (void) const; 00093 /** 00094 * \returns true if this is a multicast address, false otherwise. 00095 */ 00096 bool IsMulticast (void) const; 00097 /** 00098 * \returns true if the group bit is set, false otherwise. 00099 */ 00100 bool IsGroup (void) const; 00101 00102 /** 00103 * \returns the broadcast address 00104 */ 00105 static Mac48Address GetBroadcast (void); 00106 00107 /** 00108 * \returns a multicast address 00109 */ 00110 static Mac48Address GetMulticast (Ipv4Address address); 00111 00112 /** 00113 * \brief Get multicast address from IPv6 address. 00114 * \returns a multicast address 00115 */ 00116 static Mac48Address GetMulticast (Ipv6Address address); 00117 00118 /** 00119 * \returns the multicast prefix (01:00:5e:00:00:00). 00120 */ 00121 static Mac48Address GetMulticastPrefix (void); 00122 00123 /** 00124 * \brief Get the multicast prefix for IPv6 (33:33:00:00:00:00). 00125 * \returns a multicast address. 00126 */ 00127 static Mac48Address GetMulticast6Prefix (void); 00128 private: 00129 /** 00130 * \returns a new Address instance 00131 * 00132 * Convert an instance of this class to a polymorphic Address instance. 00133 */ 00134 Address ConvertTo (void) const; 00135 static uint8_t GetType (void); 00136 friend bool operator < (const Mac48Address &a, const Mac48Address &b); 00137 friend bool operator == (const Mac48Address &a, const Mac48Address &b); 00138 friend std::istream& operator>> (std::istream& is, Mac48Address & address); 00139 00140 uint8_t m_address[6]; 00141 }; 00142 00143 /** 00144 * \class ns3::Mac48AddressValue 00145 * \brief hold objects of type ns3::Mac48Address 00146 */ 00147 00148 ATTRIBUTE_HELPER_HEADER (Mac48Address); 00149 00150 bool operator == (const Mac48Address &a, const Mac48Address &b); 00151 bool operator != (const Mac48Address &a, const Mac48Address &b); 00152 bool operator < (const Mac48Address &a, const Mac48Address &b); 00153 std::ostream& operator<< (std::ostream& os, const Mac48Address & address); 00154 std::istream& operator>> (std::istream& is, Mac48Address & address); 00155 00156 } // namespace ns3 00157 00158 #endif /* MAC48_ADDRESS_H */