src/node/mac48-address.h
author vincent@clarinet.u-strasbg.fr
Fri Nov 07 11:36:15 2008 -0800 (2008-11-07)
changeset 3852 9cf7ad0cac85
parent 3549 4eaf02702f17
child 4424 af26433b13bc
permissions -rw-r--r--
Initial IPv6 capability
     1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
     2 /*
     3  * Copyright (c) 2007 INRIA
     4  *
     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;
     8  *
     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.
    13  *
    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
    17  *
    18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
    19  */
    20 #ifndef MAC48_ADDRESS_H
    21 #define MAC48_ADDRESS_H
    22 
    23 #include <stdint.h>
    24 #include <ostream>
    25 #include "ns3/attribute.h"
    26 #include "ns3/attribute-helper.h"
    27 #include "ipv4-address.h"
    28 #include "ipv6-address.h"
    29 
    30 namespace ns3 {
    31 
    32 class Address;
    33 
    34 /**
    35  * \ingroup address
    36  * 
    37  * \brief an EUI-48 address
    38  *
    39  * This class can contain 48 bit IEEE addresses.
    40  */
    41 class Mac48Address
    42 {
    43 public:
    44   Mac48Address ();
    45   /**
    46    * \param str a string representing the new Mac48Address
    47    *
    48    * The format of the string is "xx:xx:xx:xx:xx:xx"
    49    */
    50   Mac48Address (const char *str);
    51 
    52   /**
    53    * \param buffer address in network order
    54    *
    55    * Copy the input address to our internal buffer.
    56    */
    57   void CopyFrom (const uint8_t buffer[6]);
    58   /**
    59    * \param buffer address in network order
    60    *
    61    * Copy the internal address to the input buffer.
    62    */
    63   void CopyTo (uint8_t buffer[6]) const;
    64 
    65   /**
    66    * \returns a new Address instance
    67    *
    68    * Convert an instance of this class to a polymorphic Address instance.
    69    */
    70   operator Address () const;
    71   /**
    72    * \param address a polymorphic address
    73    * \returns a new Mac48Address from the polymorphic address
    74    * 
    75    * This function performs a type check and asserts if the
    76    * type of the input address is not compatible with an
    77    * Mac48Address.
    78    */
    79   static Mac48Address ConvertFrom (const Address &address);
    80   /**
    81    * \returns true if the address matches, false otherwise.
    82    */
    83   static bool IsMatchingType (const Address &address);
    84   /**
    85    * Allocate a new Mac48Address.
    86    */
    87   static Mac48Address Allocate (void);
    88 
    89   /**
    90    * \returns true if this is a broadcast address, false otherwise.
    91    */
    92   bool IsBroadcast (void) const;
    93   /**
    94    * \returns true if this is a multicast address, false otherwise.
    95    */
    96   bool IsMulticast (void) const;
    97   /**
    98    * \returns true if the group bit is set, false otherwise.
    99    */
   100   bool IsGroup (void) const;
   101 
   102   /**
   103    * \returns the broadcast address
   104    */
   105   static Mac48Address GetBroadcast (void);
   106 
   107   /**
   108    * \returns a multicast address
   109    */
   110   static Mac48Address GetMulticast (Ipv4Address address);
   111 
   112   /**
   113    * \brief Get multicast address from IPv6 address.
   114    * \returns a multicast address
   115    */
   116   static Mac48Address GetMulticast (Ipv6Address address);
   117 
   118   /**
   119    * \returns the multicast prefix (01:00:5e:00:00:00).
   120    */
   121   static Mac48Address GetMulticastPrefix (void);
   122 
   123   /**
   124    * \brief Get the multicast prefix for IPv6 (33:33:00:00:00:00).
   125    * \returns a multicast address.
   126    */
   127   static Mac48Address GetMulticast6Prefix (void);
   128 private:
   129   /**
   130    * \returns a new Address instance
   131    *
   132    * Convert an instance of this class to a polymorphic Address instance.
   133    */
   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);
   139 
   140   uint8_t m_address[6];
   141 };
   142 
   143 /**
   144  * \class ns3::Mac48AddressValue
   145  * \brief hold objects of type ns3::Mac48Address
   146  */
   147 
   148 ATTRIBUTE_HELPER_HEADER (Mac48Address);
   149 
   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);
   155 
   156 } // namespace ns3
   157 
   158 #endif /* MAC48_ADDRESS_H */