A Discrete-Event Network Simulator
API
mac8-address.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 University of Washington
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: Leonard Tracy <lentracy@gmail.com>
19  */
20 
21 #include "mac8-address.h"
22 #include "ns3/address.h"
23 
24 namespace ns3 {
25 
27 {
28  m_address = 255;
29 }
30 
32  : m_address (addr)
33 {
34 }
35 
37 {
38 }
39 
40 uint8_t
42 {
43  static uint8_t type = Address::Register ();
44  return type;
45 }
46 
47 Address
49 {
50  return Address (GetType (), &m_address, 1);
51 }
52 
55 {
57  Mac8Address uAddr;
58  address.CopyTo (&uAddr.m_address);
59  return uAddr;
60 }
61 
62 bool
64 {
65  return address.CheckCompatible (GetType (), 1);
66 }
67 
68 Mac8Address::operator Address () const
69 {
70  return ConvertTo ();
71 }
72 
73 void
74 Mac8Address::CopyFrom (const uint8_t *pBuffer)
75 {
76  m_address = *pBuffer;
77 }
78 
79 void
80 Mac8Address::CopyTo (uint8_t *pBuffer) const
81 {
82  *pBuffer = m_address;
83 
84 }
85 
88 {
89  return Mac8Address (255);
90 }
93 {
94  static uint8_t nextAllocated = 0;
95 
96  uint8_t address = nextAllocated++;
97  if (nextAllocated == 255)
98  {
99  nextAllocated = 0;
100  }
101 
102  return Mac8Address (address);
103 }
104 
105 bool
107 {
108  return a.m_address < b.m_address;
109 }
110 
111 bool
113 {
114  return a.m_address == b.m_address;
115 }
116 
117 bool
119 {
120  return !(a == b);
121 }
122 
123 std::ostream&
124 operator<< (std::ostream& os, const Mac8Address & address)
125 {
126  os << (int) address.m_address;
127  return os;
128 }
129 std::istream&
130 operator>> (std::istream& is, Mac8Address & address)
131 {
132  uint8_t x;
133  is >> x;
134  NS_ASSERT (0 <= x);
135  NS_ASSERT (x <= 255);
136  address.m_address = x;
137  return is;
138 }
139 
140 } // namespace ns3
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:48
static uint8_t GetType(void)
Get the Mac8Address type.
Definition: mac8-address.cc:41
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
static Mac8Address GetBroadcast(void)
Get the broadcast address (255).
Definition: mac8-address.cc:87
static bool IsMatchingType(const Address &address)
Check that a generic Address is compatible with Mac8Address.
Definition: mac8-address.cc:63
a polymophic address class
Definition: address.h:90
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:153
A class used for addressing MAC8 MAC&#39;s.
Definition: mac8-address.h:42
Mac8Address()
Constructor.
Definition: mac8-address.cc:26
void CopyFrom(const uint8_t *pBuffer)
Sets address to address stored in parameter.
Definition: mac8-address.cc:74
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
static Mac8Address Allocate()
Allocates Mac8Address from 0-254.
Definition: mac8-address.cc:92
bool operator!=(Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > a, Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > b)
Inequality test.
Definition: callback.h:1471
Every class exported by the ns3 library is enclosed in the ns3 namespace.
address
Definition: first.py:37
virtual ~Mac8Address()
Destructor.
Definition: mac8-address.cc:36
Address ConvertTo(void) const
Convert to a generic Address.
Definition: mac8-address.cc:48
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:135
static uint8_t Register(void)
Allocate a new type id for a new type of address.
Definition: address.cc:138
static Mac8Address ConvertFrom(const Address &address)
Convert a generic address to a Mac8Address.
Definition: mac8-address.cc:54
void CopyTo(uint8_t *pBuffer) const
Writes address to buffer parameter.
Definition: mac8-address.cc:80
uint8_t m_address
The address.
Definition: mac8-address.h:112