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#include "ns3/simulator.h"
24#include "ns3/log.h"
25
26namespace ns3 {
27
28NS_LOG_COMPONENT_DEFINE ("Mac8Address");
29
31
33{
34 m_address = 255;
35}
36
38 : m_address (addr)
39{
40}
41
43{
44}
45
46uint8_t
48{
49 static uint8_t type = Address::Register ();
50 return type;
51}
52
55{
56 return Address (GetType (), &m_address, 1);
57}
58
61{
63 Mac8Address uAddr;
64 address.CopyTo (&uAddr.m_address);
65 return uAddr;
66}
67
68bool
70{
71 return address.CheckCompatible (GetType (), 1);
72}
73
74Mac8Address::operator Address () const
75{
76 return ConvertTo ();
77}
78
79void
80Mac8Address::CopyFrom (const uint8_t *pBuffer)
81{
82 m_address = *pBuffer;
83}
84
85void
86Mac8Address::CopyTo (uint8_t *pBuffer) const
87{
88 *pBuffer = m_address;
89
90}
91
94{
95 return Mac8Address (255);
96}
97
100{
102
103 if (m_allocationIndex == 0)
104 {
106 }
107
108 uint8_t address = m_allocationIndex++;
109 if (m_allocationIndex == 255)
110 {
112 }
113
114 return Mac8Address (address);
115}
116
117void
119{
121
123}
124
125bool
126operator < (const Mac8Address &a, const Mac8Address &b)
127{
128 return a.m_address < b.m_address;
129}
130
131bool
133{
134 return a.m_address == b.m_address;
135}
136
137bool
139{
140 return !(a == b);
141}
142
143std::ostream&
144operator<< (std::ostream& os, const Mac8Address & address)
145{
146 os << (int) address.m_address;
147 return os;
148}
149std::istream&
150operator>> (std::istream& is, Mac8Address & address)
151{
152 uint8_t x;
153 is >> x;
154 NS_ASSERT (0 <= x);
155 NS_ASSERT (x <= 255);
156 address.m_address = x;
157 return is;
158}
159
160} // namespace ns3
a polymophic address class
Definition: address.h:91
static uint8_t Register(void)
Allocate a new type id for a new type of address.
Definition: address.cc:138
A class used for addressing MAC8 MAC's.
Definition: mac8-address.h:43
static Mac8Address GetBroadcast(void)
Get the broadcast address (255).
Definition: mac8-address.cc:93
Address ConvertTo(void) const
Convert to a generic Address.
Definition: mac8-address.cc:54
static Mac8Address ConvertFrom(const Address &address)
Convert a generic address to a Mac8Address.
Definition: mac8-address.cc:60
static void ResetAllocationIndex()
Reset the Mac8Address allocation index.
static bool IsMatchingType(const Address &address)
Check that a generic Address is compatible with Mac8Address.
Definition: mac8-address.cc:69
uint8_t m_address
The address.
Definition: mac8-address.h:127
static uint8_t m_allocationIndex
Address allocation index.
Definition: mac8-address.h:126
static uint8_t GetType(void)
Get the Mac8Address type.
Definition: mac8-address.cc:47
void CopyTo(uint8_t *pBuffer) const
Writes address to buffer parameter.
Definition: mac8-address.cc:86
static Mac8Address Allocate()
Allocates Mac8Address from 0-254.
Definition: mac8-address.cc:99
void CopyFrom(const uint8_t *pBuffer)
Sets address to address stored in parameter.
Definition: mac8-address.cc:80
virtual ~Mac8Address()
Destructor.
Definition: mac8-address.cc:42
Mac8Address()
Constructor.
Definition: mac8-address.cc:32
static EventId ScheduleDestroy(FUNC f, Ts &&... args)
Schedule an event to run at the end of the simulation, when Simulator::Destroy() is called.
Definition: simulator.h:604
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:206
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
address
Definition: first.py:40
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator!=(Callback< R, Args... > a, Callback< R, Args... > b)
Inequality test.
Definition: callback.h:636
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:158
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:139
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:162
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:176