A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
address.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 
20 #ifndef ADDRESS_H
21 #define ADDRESS_H
22 
23 #include "tag-buffer.h"
24 
25 #include "ns3/attribute-helper.h"
26 #include "ns3/attribute.h"
27 
28 #include <ostream>
29 #include <stdint.h>
30 
31 namespace ns3
32 {
33 
100 class Address
101 {
102  public:
107  static constexpr uint32_t MAX_SIZE{20};
108 
112  Address();
126  Address(uint8_t type, const uint8_t* buffer, uint8_t len);
131  Address(const Address& address);
137  Address& operator=(const Address& address);
138 
146  bool IsInvalid() const;
151  uint8_t GetLength() const;
157  uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const;
168  uint32_t CopyAllTo(uint8_t* buffer, uint8_t len) const;
179  uint32_t CopyFrom(const uint8_t* buffer, uint8_t len);
190  uint32_t CopyAllFrom(const uint8_t* buffer, uint8_t len);
198  bool CheckCompatible(uint8_t type, uint8_t len) const;
209  bool IsMatchingType(uint8_t type) const;
214  static uint8_t Register();
221  uint32_t GetSerializedSize() const;
227  void Serialize(TagBuffer buffer) const;
233  void Deserialize(TagBuffer buffer);
234 
235  private:
243  friend bool operator==(const Address& a, const Address& b);
244 
252  friend bool operator!=(const Address& a, const Address& b);
253 
261  friend bool operator<(const Address& a, const Address& b);
262 
270  friend std::ostream& operator<<(std::ostream& os, const Address& address);
271 
279  friend std::istream& operator>>(std::istream& is, Address& address);
280 
281  uint8_t m_type;
282  uint8_t m_len;
283  uint8_t m_data[MAX_SIZE];
284 };
285 
287 
288 bool operator==(const Address& a, const Address& b);
289 bool operator!=(const Address& a, const Address& b);
290 bool operator<(const Address& a, const Address& b);
291 std::ostream& operator<<(std::ostream& os, const Address& address);
292 std::istream& operator>>(std::istream& is, Address& address);
293 
294 } // namespace ns3
295 
296 #endif /* ADDRESS_H */
a polymophic address class
Definition: address.h:101
uint32_t GetSerializedSize() const
Get the number of bytes needed to serialize the underlying Address Typically, this is GetLength () + ...
Definition: address.cc:155
void Serialize(TagBuffer buffer) const
Serialize this address in host byte order to a byte buffer.
Definition: address.cc:162
friend std::ostream & operator<<(std::ostream &os, const Address &address)
Stream insertion operator.
Definition: address.cc:246
uint32_t CopyFrom(const uint8_t *buffer, uint8_t len)
Definition: address.cc:106
static constexpr uint32_t MAX_SIZE
The maximum size of a byte buffer which can be stored in an Address instance.
Definition: address.h:107
bool IsInvalid() const
Definition: address.cc:71
uint8_t m_len
Length of the address.
Definition: address.h:282
friend std::istream & operator>>(std::istream &is, Address &address)
Stream extraction operator.
Definition: address.cc:264
uint8_t m_data[MAX_SIZE]
The address value.
Definition: address.h:283
uint8_t m_type
Type of the address.
Definition: address.h:281
Address & operator=(const Address &address)
Basic assignment operator.
Definition: address.cc:60
Address()
Create an invalid address.
Definition: address.cc:34
friend bool operator!=(const Address &a, const Address &b)
Not equal to operator.
Definition: address.cc:206
uint32_t CopyAllFrom(const uint8_t *buffer, uint8_t len)
Definition: address.cc:116
bool CheckCompatible(uint8_t type, uint8_t len) const
Definition: address.cc:129
static uint8_t Register()
Allocate a new type id for a new type of address.
Definition: address.cc:146
uint8_t GetLength() const
Get the length of the underlying address.
Definition: address.cc:78
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Definition: address.cc:86
void Deserialize(TagBuffer buffer)
Definition: address.cc:171
friend bool operator<(const Address &a, const Address &b)
Less than operator.
Definition: address.cc:212
bool IsMatchingType(uint8_t type) const
Definition: address.cc:139
friend bool operator==(const Address &a, const Address &b)
Equal to operator.
Definition: address.cc:183
uint32_t CopyAllTo(uint8_t *buffer, uint8_t len) const
Definition: address.cc:95
read and write tag data
Definition: tag-buffer.h:52
address
Definition: first.py:47
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:678
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:157
ATTRIBUTE_HELPER_HEADER(ValueClassTest)
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:170
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:183
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159