ndn-cxx: NDN C++ Library 0.9.0-33-g832ea91d
Loading...
Searching...
No Matches
ethernet.hpp
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2023 Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
12 *
13 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
14 * terms of the GNU Lesser General Public License as published by the Free Software
15 * Foundation, either version 3 of the License, or (at your option) any later version.
16 *
17 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
18 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
19 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
20 *
21 * You should have received copies of the GNU General Public License and GNU Lesser
22 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
23 * <http://www.gnu.org/licenses/>.
24 *
25 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
26 */
27
28#ifndef NDN_CXX_NET_ETHERNET_HPP
29#define NDN_CXX_NET_ETHERNET_HPP
30
31#include <array>
32#include <cstdint>
33#include <functional>
34#include <string>
35
36namespace ndn::ethernet {
37
38inline constexpr uint16_t ETHERTYPE_NDN = 0x8624;
39
40inline constexpr size_t ADDR_LEN = 6;
41inline constexpr size_t TYPE_LEN = 2;
42inline constexpr size_t HDR_LEN = 14;
43inline constexpr size_t TAG_LEN = 4;
44inline constexpr size_t MIN_DATA_LEN = 46;
45inline constexpr size_t MAX_DATA_LEN = 1500;
46inline constexpr size_t CRC_LEN = 4;
47
51class Address : public std::array<uint8_t, ADDR_LEN>
52{
53public:
55 Address();
56
58 Address(uint8_t a1, uint8_t a2, uint8_t a3,
59 uint8_t a4, uint8_t a5, uint8_t a6);
60
62 explicit
63 Address(const uint8_t octets[ADDR_LEN]);
64
66 bool
67 isBroadcast() const;
68
70 bool
71 isMulticast() const;
72
74 bool
75 isNull() const;
76
83 std::string
84 toString(char sep = ':') const;
85
93 static Address
94 fromString(const std::string& str);
95};
96
102
108
109std::ostream&
110operator<<(std::ostream& o, const Address& a);
111
112} // namespace ndn::ethernet
113
114namespace std {
115
116// specialize std::hash<> for ethernet::Address
117template<>
118struct hash<ndn::ethernet::Address>
119{
120 size_t
121 operator()(const ndn::ethernet::Address& a) const noexcept;
122};
123
124} // namespace std
125
126#endif // NDN_CXX_NET_ETHERNET_HPP
Represents an Ethernet hardware address.
Definition ethernet.hpp:52
Address()
Constructs a null Ethernet address (00:00:00:00:00:00).
Definition ethernet.cpp:39
std::string toString(char sep=':') const
Converts the address to a human-readable string.
Definition ethernet.cpp:78
bool isMulticast() const
True if this is a multicast address.
Definition ethernet.cpp:66
bool isBroadcast() const
True if this is a broadcast address (ff:ff:ff:ff:ff:ff).
Definition ethernet.cpp:60
bool isNull() const
True if this is a null address (00:00:00:00:00:00).
Definition ethernet.cpp:72
static Address fromString(const std::string &str)
Creates an Address from a string containing an Ethernet address in hexadecimal notation,...
Definition ethernet.cpp:90
constexpr size_t MIN_DATA_LEN
Min octets in Ethernet payload (assuming no 802.1Q tag)
Definition ethernet.hpp:44
constexpr size_t CRC_LEN
Octets in Ethernet frame check sequence.
Definition ethernet.hpp:46
Address getDefaultMulticastAddress()
Returns the default Ethernet multicast address for NDN.
Definition ethernet.cpp:121
constexpr size_t ADDR_LEN
Octets in one Ethernet address.
Definition ethernet.hpp:40
constexpr size_t TAG_LEN
Octets in 802.1Q tag (TPID + priority + VLAN)
Definition ethernet.hpp:43
constexpr size_t MAX_DATA_LEN
Max octets in Ethernet payload.
Definition ethernet.hpp:45
constexpr size_t TYPE_LEN
Octets in Ethertype field.
Definition ethernet.hpp:41
constexpr size_t HDR_LEN
Total octets in Ethernet header (without 802.1Q tag)
Definition ethernet.hpp:42
constexpr uint16_t ETHERTYPE_NDN
The NDN Ethertype.
Definition ethernet.hpp:38
Address getBroadcastAddress()
Returns the Ethernet broadcast address (ff:ff:ff:ff:ff:ff).
Definition ethernet.cpp:115
std::ostream & operator<<(std::ostream &o, const Address &a)
Definition ethernet.cpp:127
Definition data.cpp:25
STL namespace.