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
mathieu@1181
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
mathieu@1181
     2
/*
mathieu@1181
     3
 * Copyright (c) 2007 INRIA
mathieu@1181
     4
 *
mathieu@1181
     5
 * This program is free software; you can redistribute it and/or modify
mathieu@1181
     6
 * it under the terms of the GNU General Public License version 2 as
mathieu@1181
     7
 * published by the Free Software Foundation;
mathieu@1181
     8
 *
mathieu@1181
     9
 * This program is distributed in the hope that it will be useful,
mathieu@1181
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
mathieu@1181
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
mathieu@1181
    12
 * GNU General Public License for more details.
mathieu@1181
    13
 *
mathieu@1181
    14
 * You should have received a copy of the GNU General Public License
mathieu@1181
    15
 * along with this program; if not, write to the Free Software
mathieu@1181
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
mathieu@1181
    17
 *
mathieu@1181
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
mathieu@1181
    19
 */
mathieu@2414
    20
#ifndef MAC48_ADDRESS_H
mathieu@2414
    21
#define MAC48_ADDRESS_H
mathieu@1158
    22
mathieu@1158
    23
#include <stdint.h>
mathieu@1167
    24
#include <ostream>
mathieu@2438
    25
#include "ns3/attribute.h"
mathieu@2451
    26
#include "ns3/attribute-helper.h"
mathieu@3549
    27
#include "ipv4-address.h"
vincent@3852
    28
#include "ipv6-address.h"
mathieu@1158
    29
mathieu@1158
    30
namespace ns3 {
mathieu@1158
    31
mathieu@1158
    32
class Address;
mathieu@1158
    33
mathieu@1166
    34
/**
tomh@3183
    35
 * \ingroup address
tomh@3183
    36
 * 
mathieu@1166
    37
 * \brief an EUI-48 address
mathieu@1166
    38
 *
mathieu@1166
    39
 * This class can contain 48 bit IEEE addresses.
mathieu@1166
    40
 */
mathieu@1494
    41
class Mac48Address
mathieu@1158
    42
{
mathieu@1158
    43
public:
mathieu@1494
    44
  Mac48Address ();
mathieu@1166
    45
  /**
mathieu@1494
    46
   * \param str a string representing the new Mac48Address
mathieu@1166
    47
   *
mathieu@1166
    48
   * The format of the string is "xx:xx:xx:xx:xx:xx"
mathieu@1166
    49
   */
mathieu@1494
    50
  Mac48Address (const char *str);
mathieu@1167
    51
mathieu@1167
    52
  /**
mathieu@1167
    53
   * \param buffer address in network order
mathieu@1167
    54
   *
mathieu@1167
    55
   * Copy the input address to our internal buffer.
mathieu@1167
    56
   */
mathieu@1167
    57
  void CopyFrom (const uint8_t buffer[6]);
mathieu@1167
    58
  /**
mathieu@1167
    59
   * \param buffer address in network order
mathieu@1167
    60
   *
mathieu@1167
    61
   * Copy the internal address to the input buffer.
mathieu@1167
    62
   */
mathieu@1167
    63
  void CopyTo (uint8_t buffer[6]) const;
mathieu@1205
    64
mathieu@1205
    65
  /**
mathieu@1205
    66
   * \returns a new Address instance
mathieu@1205
    67
   *
mathieu@1205
    68
   * Convert an instance of this class to a polymorphic Address instance.
mathieu@1205
    69
   */
mathieu@1705
    70
  operator Address () const;
mathieu@1205
    71
  /**
mathieu@1205
    72
   * \param address a polymorphic address
mathieu@1494
    73
   * \returns a new Mac48Address from the polymorphic address
mathieu@1207
    74
   * 
mathieu@1207
    75
   * This function performs a type check and asserts if the
mathieu@1207
    76
   * type of the input address is not compatible with an
mathieu@1494
    77
   * Mac48Address.
mathieu@1205
    78
   */
mathieu@1494
    79
  static Mac48Address ConvertFrom (const Address &address);
mathieu@1205
    80
  /**
mathieu@1205
    81
   * \returns true if the address matches, false otherwise.
mathieu@1205
    82
   */
mathieu@1205
    83
  static bool IsMatchingType (const Address &address);
mathieu@1205
    84
  /**
mathieu@1494
    85
   * Allocate a new Mac48Address.
mathieu@1205
    86
   */
mathieu@1494
    87
  static Mac48Address Allocate (void);
mathieu@1707
    88
mathieu@1707
    89
  /**
mathieu@1707
    90
   * \returns true if this is a broadcast address, false otherwise.
mathieu@1707
    91
   */
mathieu@1707
    92
  bool IsBroadcast (void) const;
mathieu@1707
    93
  /**
mathieu@1707
    94
   * \returns true if this is a multicast address, false otherwise.
mathieu@1707
    95
   */
mathieu@1707
    96
  bool IsMulticast (void) const;
mathieu@3549
    97
  /**
mathieu@3549
    98
   * \returns true if the group bit is set, false otherwise.
mathieu@3549
    99
   */
mathieu@3549
   100
  bool IsGroup (void) const;
mathieu@1707
   101
mathieu@1707
   102
  /**
mathieu@1707
   103
   * \returns the broadcast address
mathieu@1707
   104
   */
mathieu@1707
   105
  static Mac48Address GetBroadcast (void);
mathieu@2411
   106
mathieu@3549
   107
  /**
mathieu@3549
   108
   * \returns a multicast address
mathieu@3549
   109
   */
mathieu@3549
   110
  static Mac48Address GetMulticast (Ipv4Address address);
mathieu@3549
   111
mathieu@3549
   112
  /**
vincent@3852
   113
   * \brief Get multicast address from IPv6 address.
vincent@3852
   114
   * \returns a multicast address
vincent@3852
   115
   */
vincent@3852
   116
  static Mac48Address GetMulticast (Ipv6Address address);
vincent@3852
   117
vincent@3852
   118
  /**
mathieu@3549
   119
   * \returns the multicast prefix (01:00:5e:00:00:00).
mathieu@3549
   120
   */
mathieu@3549
   121
  static Mac48Address GetMulticastPrefix (void);
vincent@3852
   122
vincent@3852
   123
  /**
vincent@3852
   124
   * \brief Get the multicast prefix for IPv6 (33:33:00:00:00:00).
vincent@3852
   125
   * \returns a multicast address.
vincent@3852
   126
   */
vincent@3852
   127
  static Mac48Address GetMulticast6Prefix (void);
mathieu@1205
   128
private:
mathieu@1166
   129
  /**
mathieu@1166
   130
   * \returns a new Address instance
mathieu@1166
   131
   *
mathieu@1166
   132
   * Convert an instance of this class to a polymorphic Address instance.
mathieu@1166
   133
   */
mathieu@1158
   134
  Address ConvertTo (void) const;
mathieu@1158
   135
  static uint8_t GetType (void);
mathieu@1707
   136
  friend bool operator < (const Mac48Address &a, const Mac48Address &b);
mathieu@1707
   137
  friend bool operator == (const Mac48Address &a, const Mac48Address &b);
mathieu@2954
   138
  friend std::istream& operator>> (std::istream& is, Mac48Address & address);
mathieu@1707
   139
mathieu@1158
   140
  uint8_t m_address[6];
mathieu@1167
   141
};
mathieu@1158
   142
mathieu@2969
   143
/**
mathieu@2969
   144
 * \class ns3::Mac48AddressValue
mathieu@2969
   145
 * \brief hold objects of type ns3::Mac48Address
mathieu@2969
   146
 */
mathieu@2969
   147
mathieu@3094
   148
ATTRIBUTE_HELPER_HEADER (Mac48Address);
mathieu@2422
   149
mathieu@1494
   150
bool operator == (const Mac48Address &a, const Mac48Address &b);
mathieu@1494
   151
bool operator != (const Mac48Address &a, const Mac48Address &b);
mathieu@1707
   152
bool operator < (const Mac48Address &a, const Mac48Address &b);
mathieu@1494
   153
std::ostream& operator<< (std::ostream& os, const Mac48Address & address);
mathieu@2954
   154
std::istream& operator>> (std::istream& is, Mac48Address & address);
mathieu@2411
   155
mathieu@1158
   156
} // namespace ns3
mathieu@1158
   157
mathieu@2414
   158
#endif /* MAC48_ADDRESS_H */