NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
ethernet.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
28 #ifndef NDN_UTIL_ETHERNET_HPP
29 #define NDN_UTIL_ETHERNET_HPP
30 
31 #include <array>
32 #include <cstdint>
33 #include <functional>
34 #include <string>
35 
36 namespace ndn {
37 namespace util {
38 namespace ethernet {
39 
40 const uint16_t ETHERTYPE_NDN = 0x8624;
41 
42 const size_t ADDR_LEN = 6;
43 const size_t TYPE_LEN = 2;
44 const size_t HDR_LEN = 14;
45 const size_t TAG_LEN = 4;
46 const size_t MIN_DATA_LEN = 46;
47 const size_t MAX_DATA_LEN = 1500;
48 const size_t CRC_LEN = 4;
49 
50 
53 class Address : public std::array<uint8_t, ADDR_LEN>
54 {
55 public:
57  Address();
58 
60  Address(uint8_t a1, uint8_t a2, uint8_t a3,
61  uint8_t a4, uint8_t a5, uint8_t a6);
62 
64  explicit
65  Address(const uint8_t octets[ADDR_LEN]);
66 
68  bool
69  isBroadcast() const;
70 
72  bool
73  isMulticast() const;
74 
76  bool
77  isNull() const;
78 
85  std::string
86  toString(char sep = ':') const;
87 
96  static Address
97  fromString(const std::string& str);
98 };
99 
101 Address
103 
105 Address
107 
108 std::ostream&
109 operator<<(std::ostream& o, const Address& a);
110 
111 } // namespace ethernet
112 } // namespace util
113 } // namespace ndn
114 
115 
116 namespace std {
117 
118 // specialize std::hash<> for ethernet::Address
119 template<>
120 struct hash<ndn::util::ethernet::Address>
121 {
122  size_t
123  operator()(const ndn::util::ethernet::Address& a) const noexcept;
124 };
125 
126 } // namespace std
127 
128 #endif // NDN_UTIL_ETHERNET_HPP
Copyright (c) 2011-2015 Regents of the University of California.
const size_t TAG_LEN
Octets in 802.1Q tag (TPID + priority + VLAN)
Definition: ethernet.hpp:45
const size_t ADDR_LEN
Octets in one Ethernet address.
Definition: ethernet.hpp:42
represents an Ethernet hardware address
Definition: ethernet.hpp:53
static Address fromString(const std::string &str)
Creates an Address from a string containing an Ethernet address in hexadecimal notation, with colons or hyphens as separators.
Definition: ethernet.cpp:86
Address getBroadcastAddress()
Returns the Ethernet broadcast address (ff:ff:ff:ff:ff:ff)
Definition: ethernet.cpp:118
Address getDefaultMulticastAddress()
Returns the default Ethernet multicast address for NDN.
Definition: ethernet.cpp:124
STL namespace.
const size_t TYPE_LEN
Octets in Ethertype field.
Definition: ethernet.hpp:43
const size_t MIN_DATA_LEN
Min octets in Ethernet payload (assuming no 802.1Q tag)
Definition: ethernet.hpp:46
Address()
Constructs a null Ethernet address (00:00:00:00:00:00)
Definition: ethernet.cpp:33
const size_t MAX_DATA_LEN
Max octets in Ethernet payload.
Definition: ethernet.hpp:47
bool isBroadcast() const
True if this is a broadcast address (ff:ff:ff:ff:ff:ff)
Definition: ethernet.cpp:54
const size_t HDR_LEN
Total octets in Ethernet header (without 802.1Q tag)
Definition: ethernet.hpp:44
std::ostream & operator<<(std::ostream &o, const Address &a)
Definition: ethernet.cpp:130
const size_t CRC_LEN
Octets in Ethernet frame check sequence.
Definition: ethernet.hpp:48
bool isNull() const
True if this is a null address (00:00:00:00:00:00)
Definition: ethernet.cpp:66
const uint16_t ETHERTYPE_NDN
Definition: ethernet.hpp:40
bool isMulticast() const
True if this is a multicast address.
Definition: ethernet.cpp:60
std::string toString(char sep=':') const
Converts the address to a human-readable string.
Definition: ethernet.cpp:72