A Discrete-Event Network Simulator
API
address.h
Go to the documentation of this file.
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 
21 #ifndef ADDRESS_H
22 #define ADDRESS_H
23 
24 #include <stdint.h>
25 #include <ostream>
26 #include "ns3/attribute.h"
27 #include "ns3/attribute-helper.h"
28 #include "ns3/tag-buffer.h"
29 
30 namespace ns3 {
31 
90 class Address
91 {
92 public:
97  enum MaxSize_e {
98  MAX_SIZE = 20
99  };
100 
104  Address ();
118  Address (uint8_t type, const uint8_t *buffer, uint8_t len);
123  Address (const Address & address);
130 
138  bool IsInvalid (void) const;
143  uint8_t GetLength (void) const;
149  uint32_t CopyTo (uint8_t buffer[MAX_SIZE]) const;
160  uint32_t CopyAllTo (uint8_t *buffer, uint8_t len) const;
171  uint32_t CopyFrom (const uint8_t *buffer, uint8_t len);
182  uint32_t CopyAllFrom (const uint8_t *buffer, uint8_t len);
190  bool CheckCompatible (uint8_t type, uint8_t len) const;
201  bool IsMatchingType (uint8_t type) const;
206  static uint8_t Register (void);
213  uint32_t GetSerializedSize (void) const;
219  void Serialize (TagBuffer buffer) const;
225  void Deserialize (TagBuffer buffer);
226 
227 private:
235  friend bool operator == (const Address &a, const Address &b);
236 
244  friend bool operator != (const Address &a, const Address &b);
245 
253  friend bool operator < (const Address &a, const Address &b);
254 
262  friend std::ostream& operator<< (std::ostream& os, const Address & address);
263 
271  friend std::istream& operator>> (std::istream& is, Address & address);
272 
273  uint8_t m_type;
274  uint8_t m_len;
275  uint8_t m_data[MAX_SIZE];
276 };
277 
279 
280 bool operator == (const Address &a, const Address &b);
281 bool operator != (const Address &a, const Address &b);
282 bool operator < (const Address &a, const Address &b);
283 std::ostream& operator<< (std::ostream& os, const Address & address);
284 std::istream& operator>> (std::istream& is, Address & address);
285 
286 
287 } // namespace ns3
288 
289 #endif /* ADDRESS_H */
uint8_t m_len
Length of the address.
Definition: address.h:274
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:48
bool IsInvalid(void) const
Definition: address.cc:68
friend std::ostream & operator<<(std::ostream &os, const Address &address)
Stream insertion operator.
Definition: address.cc:235
uint8_t GetLength(void) const
Get the length of the underlying address.
Definition: address.cc:75
bool CheckCompatible(uint8_t type, uint8_t len) const
Definition: address.cc:122
uint32_t CopyAllTo(uint8_t *buffer, uint8_t len) const
Definition: address.cc:90
Address()
Create an invalid address.
Definition: address.cc:32
friend bool operator<(const Address &a, const Address &b)
Less than operator.
Definition: address.cc:202
a polymophic address class
Definition: address.h:90
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:155
uint32_t GetSerializedSize(void) const
Get the number of bytes needed to serialize the underlying Address Typically, this is GetLength () + ...
Definition: address.cc:147
Address & operator=(const Address &address)
Basic assignment operator.
Definition: address.cc:57
uint8_t m_type
Type of the address.
Definition: address.h:273
uint32_t CopyAllFrom(const uint8_t *buffer, uint8_t len)
Definition: address.cc:110
void Deserialize(TagBuffer buffer)
Definition: address.cc:163
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
void Serialize(TagBuffer buffer) const
Serialize this address in host byte order to a byte buffer.
Definition: address.cc:154
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:1592
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t CopyFrom(const uint8_t *buffer, uint8_t len)
Definition: address.cc:101
address
Definition: first.py:44
bool IsMatchingType(uint8_t type) const
Definition: address.cc:131
uint8_t m_data[MAX_SIZE]
The address value.
Definition: address.h:275
read and write tag data
Definition: tag-buffer.h:51
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:137
friend bool operator!=(const Address &a, const Address &b)
Not equal to operator.
Definition: address.cc:198
friend bool operator==(const Address &a, const Address &b)
Equal to operator.
Definition: address.cc:175
#define ATTRIBUTE_HELPER_HEADER(type)
Declare the attribute value, accessor and checkers for class type.
static uint8_t Register(void)
Allocate a new type id for a new type of address.
Definition: address.cc:138
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Definition: address.cc:82
friend std::istream & operator>>(std::istream &is, Address &address)
Stream extraction operator.
Definition: address.cc:251
MaxSize_e
The maximum size of a byte buffer which can be stored in an Address instance.
Definition: address.h:97