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_NET_ETHERNET_HPP
29 #define NDN_NET_ETHERNET_HPP
30 
31 #include <array>
32 #include <cstdint>
33 #include <functional>
34 #include <string>
35 
36 namespace ndn {
37 namespace ethernet {
38 
39 const uint16_t ETHERTYPE_NDN = 0x8624;
40 
41 const size_t ADDR_LEN = 6;
42 const size_t TYPE_LEN = 2;
43 const size_t HDR_LEN = 14;
44 const size_t TAG_LEN = 4;
45 const size_t MIN_DATA_LEN = 46;
46 const size_t MAX_DATA_LEN = 1500;
47 const size_t CRC_LEN = 4;
48 
49 
52 class Address : public std::array<uint8_t, ADDR_LEN>
53 {
54 public:
56  Address();
57 
59  Address(uint8_t a1, uint8_t a2, uint8_t a3,
60  uint8_t a4, uint8_t a5, uint8_t a6);
61 
63  explicit
64  Address(const uint8_t octets[ADDR_LEN]);
65 
67  bool
68  isBroadcast() const;
69 
71  bool
72  isMulticast() const;
73 
75  bool
76  isNull() const;
77 
84  std::string
85  toString(char sep = ':') const;
86 
95  static Address
96  fromString(const std::string& str);
97 };
98 
100 Address
102 
104 Address
106 
107 std::ostream&
108 operator<<(std::ostream& o, const Address& a);
109 
110 } // namespace ethernet
111 } // namespace ndn
112 
113 namespace std {
114 
115 // specialize std::hash<> for ethernet::Address
116 template<>
117 struct hash<ndn::ethernet::Address>
118 {
119  size_t
120  operator()(const ndn::ethernet::Address& a) const noexcept;
121 };
122 
123 } // namespace std
124 
125 #endif // NDN_NET_ETHERNET_HPP
const size_t CRC_LEN
Octets in Ethernet frame check sequence.
Definition: ethernet.hpp:47
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:91
Copyright (c) 2011-2015 Regents of the University of California.
const size_t MIN_DATA_LEN
Min octets in Ethernet payload (assuming no 802.1Q tag)
Definition: ethernet.hpp:45
std::ostream & operator<<(std::ostream &o, const Address &a)
Definition: ethernet.cpp:135
const size_t TAG_LEN
Octets in 802.1Q tag (TPID + priority + VLAN)
Definition: ethernet.hpp:44
const size_t ADDR_LEN
Octets in one Ethernet address.
Definition: ethernet.hpp:41
bool isBroadcast() const
True if this is a broadcast address (ff:ff:ff:ff:ff:ff)
Definition: ethernet.cpp:59
STL namespace.
Address getDefaultMulticastAddress()
Returns the default Ethernet multicast address for NDN.
Definition: ethernet.cpp:129
Address getBroadcastAddress()
Returns the Ethernet broadcast address (ff:ff:ff:ff:ff:ff)
Definition: ethernet.cpp:123
const size_t HDR_LEN
Total octets in Ethernet header (without 802.1Q tag)
Definition: ethernet.hpp:43
bool isMulticast() const
True if this is a multicast address.
Definition: ethernet.cpp:65
std::string toString(char sep= ':') const
Converts the address to a human-readable string.
Definition: ethernet.cpp:77
const size_t TYPE_LEN
Octets in Ethertype field.
Definition: ethernet.hpp:42
const uint16_t ETHERTYPE_NDN
Definition: ethernet.hpp:39
represents an Ethernet hardware address
Definition: ethernet.hpp:52
Address()
Constructs a null Ethernet address (00:00:00:00:00:00)
Definition: ethernet.cpp:38
bool isNull() const
True if this is a null address (00:00:00:00:00:00)
Definition: ethernet.cpp:71
const size_t MAX_DATA_LEN
Max octets in Ethernet payload.
Definition: ethernet.hpp:46