network-interface.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
24 #ifndef NDN_NET_NETWORK_INTERFACE_HPP
25 #define NDN_NET_NETWORK_INTERFACE_HPP
26 
27 #include "ethernet.hpp"
28 #include "network-address.hpp"
29 #include "../util/signal.hpp"
30 #include <set>
31 
32 namespace ndn {
33 namespace net {
34 
37 enum class InterfaceType {
38  UNKNOWN,
39  LOOPBACK,
40  ETHERNET,
41  // we do not support anything else for now
42 };
43 
44 std::ostream&
45 operator<<(std::ostream& os, InterfaceType type);
46 
49 enum class InterfaceState {
50  UNKNOWN,
51  DOWN,
52  NO_CARRIER,
53  DORMANT,
54  RUNNING,
55 };
56 
57 std::ostream&
58 operator<<(std::ostream& os, InterfaceState state);
59 
69 {
70 public: // signals, marked 'mutable' so they can be connected on 'const NetworkInterface'
73  mutable util::Signal<NetworkInterface, InterfaceState /*old*/, InterfaceState /*new*/> onStateChanged;
74 
77  mutable util::Signal<NetworkInterface, uint32_t /*old*/, uint32_t /*new*/> onMtuChanged;
78 
81  mutable util::Signal<NetworkInterface, NetworkAddress> onAddressAdded;
82 
85  mutable util::Signal<NetworkInterface, NetworkAddress> onAddressRemoved;
86 
87 public: // getters
90  int
91  getIndex() const
92  {
93  return m_index;
94  }
95 
98  std::string
99  getName() const
100  {
101  return m_name;
102  }
103 
107  getType() const
108  {
109  return m_type;
110  }
111 
114  uint32_t
115  getFlags() const
116  {
117  return m_flags;
118  }
119 
122  InterfaceState
123  getState() const
124  {
125  return m_state;
126  }
127 
130  uint32_t
131  getMtu() const
132  {
133  return m_mtu;
134  }
135 
140  {
141  return m_etherAddress;
142  }
143 
148  {
149  return m_etherBrdAddress;
150  }
151 
154  const std::set<NetworkAddress>&
156  {
157  return m_netAddresses;
158  }
159 
162  bool
163  isLoopback() const
164  {
165  return (m_flags & IFF_LOOPBACK) != 0;
166  }
167 
170  bool
172  {
173  return (m_flags & IFF_POINTOPOINT) != 0;
174  }
175 
178  bool
179  canBroadcast() const
180  {
181  return (m_flags & IFF_BROADCAST) != 0;
182  }
183 
186  bool
187  canMulticast() const
188  {
189  return (m_flags & IFF_MULTICAST) != 0;
190  }
191 
194  bool
195  isUp() const
196  {
197  return (m_flags & IFF_UP) != 0;
198  }
199 
200 public: // modifiers: they update information on this instance, but do not change netif in the OS
201  bool
202  addNetworkAddress(const NetworkAddress& address);
203 
204  bool
205  removeNetworkAddress(const NetworkAddress& address);
206 
207  void
208  setIndex(int index);
209 
210  void
211  setName(const std::string& name);
212 
213  void
214  setType(InterfaceType type);
215 
216  void
217  setFlags(uint32_t flags);
218 
219  void
220  setState(InterfaceState state);
221 
222  void
223  setMtu(uint32_t mtu);
224 
225  void
226  setEthernetAddress(const ethernet::Address& address);
227 
228  void
229  setEthernetBroadcastAddress(const ethernet::Address& address);
230 
231 private: // constructor
232  NetworkInterface(); // accessible through NetworkMonitorImpl::makeNetworkInterface
233 
234 private:
235  int m_index;
236  std::string m_name;
237  InterfaceType m_type;
238  uint32_t m_flags; // IFF_* in <net/if.h>
239  InterfaceState m_state;
240  uint32_t m_mtu;
241  ethernet::Address m_etherAddress;
242  ethernet::Address m_etherBrdAddress;
243  std::set<NetworkAddress> m_netAddresses;
244 
245  friend class NetworkMonitorImpl;
246 };
247 
248 std::ostream&
249 operator<<(std::ostream& os, const NetworkInterface& interface);
250 
251 } // namespace net
252 } // namespace ndn
253 
254 #endif // NDN_NET_NETWORK_INTERFACE_HPP
interface is administratively down
Copyright (c) 2013-2017 Regents of the University of California.
Definition: common.hpp:66
interface can be used to send and receive packets
bool isLoopback() const
Returns true if the interface is a loopback interface.
interface is administratively up but has no carrier
bool canMulticast() const
Returns true if the interface supports multicast communication.
uint32_t getMtu() const
Returns the MTU (maximum transmission unit) of the interface.
util::Signal< NetworkInterface, InterfaceState, InterfaceState > onStateChanged
Fires when interface state changes.
InterfaceType
Indicates the hardware type of a network interface.
util::Signal< NetworkInterface, uint32_t, uint32_t > onMtuChanged
Fires when interface mtu changes.
InterfaceState
Indicates the state of a network interface.
util::Signal< NetworkInterface, NetworkAddress > onAddressRemoved
Fires when a network-layer address is removed from the interface.
ethernet::Address getEthernetBroadcastAddress() const
Returns the link-layer (Ethernet) broadcast address of the interface.
Represents one network interface attached to the host.
Stores one IP address supported by a network interface.
int getIndex() const
Returns an opaque ID that uniquely identifies the interface on the system.
InterfaceType getType() const
Returns the hardware type of the interface.
std::string getName() const
Returns the name of the interface, unique on the system.
const std::set< NetworkAddress > & getNetworkAddresses() const
Returns a list of all network-layer addresses present on the interface.
interface has a carrier but it cannot send or receive normal user traffic yet
represents an Ethernet hardware address
Definition: ethernet.hpp:52
uint32_t getFlags() const
Returns a bitset of platform-specific flags enabled on the interface.
bool isUp() const
Returns true if the interface is administratively up.
std::ostream & operator<<(std::ostream &os, AddressScope scope)
ethernet::Address getEthernetAddress() const
Returns the link-layer (Ethernet) address of the interface.
bool isPointToPoint() const
Returns true if the interface is a point-to-point interface.
InterfaceState getState() const
Returns the current state of the interface.
bool canBroadcast() const
Returns true if the interface supports broadcast communication.
util::Signal< NetworkInterface, NetworkAddress > onAddressAdded
Fires when a network-layer address is added to the interface.