NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
network-interface.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2018 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  *
21  * @author Davide Pesavento <davide.pesavento@lip6.fr>
22  */
23 
24 #ifndef NDN_NET_NETWORK_INTERFACE_HPP
25 #define NDN_NET_NETWORK_INTERFACE_HPP
26 
27 #include "ndn-cxx/net/ethernet.hpp"
29 #include "ndn-cxx/util/signal.hpp"
30 
31 #include <set>
32 
33 namespace ndn {
34 namespace net {
35 
38 enum class InterfaceType {
39  UNKNOWN,
40  LOOPBACK,
41  ETHERNET,
42  // we do not support anything else for now
43 };
44 
45 std::ostream&
46 operator<<(std::ostream& os, InterfaceType type);
47 
50 enum class InterfaceState {
51  UNKNOWN,
52  DOWN,
53  NO_CARRIER,
54  DORMANT,
55  RUNNING,
56 };
57 
58 std::ostream&
59 operator<<(std::ostream& os, InterfaceState state);
60 
70 {
71 public: // signals, marked 'mutable' so they can be connected on 'const NetworkInterface'
75 
78  mutable util::Signal<NetworkInterface, uint32_t /*old*/, uint32_t /*new*/> onMtuChanged;
79 
83 
87 
88 public: // getters
91  int
92  getIndex() const
93  {
94  return m_index;
95  }
96 
99  std::string
100  getName() const
101  {
102  return m_name;
103  }
104 
108  getType() const
109  {
110  return m_type;
111  }
112 
115  uint32_t
116  getFlags() const
117  {
118  return m_flags;
119  }
120 
124  getState() const
125  {
126  return m_state;
127  }
128 
131  uint32_t
132  getMtu() const
133  {
134  return m_mtu;
135  }
136 
141  {
142  return m_etherAddress;
143  }
144 
149  {
150  return m_etherBrdAddress;
151  }
152 
155  const std::set<NetworkAddress>&
157  {
158  return m_netAddresses;
159  }
160 
163  bool
164  isLoopback() const
165  {
166  return (m_flags & IFF_LOOPBACK) != 0;
167  }
168 
171  bool
173  {
174  return (m_flags & IFF_POINTOPOINT) != 0;
175  }
176 
179  bool
180  canBroadcast() const
181  {
182  return (m_flags & IFF_BROADCAST) != 0;
183  }
184 
187  bool
188  canMulticast() const
189  {
190  return (m_flags & IFF_MULTICAST) != 0;
191  }
192 
195  bool
196  isUp() const
197  {
198  return (m_flags & IFF_UP) != 0;
199  }
200 
201 public: // modifiers: they update information on this instance, but do not change netif in the OS
202  bool
203  addNetworkAddress(const NetworkAddress& address);
204 
205  bool
206  removeNetworkAddress(const NetworkAddress& address);
207 
208  void
209  setIndex(int index);
210 
211  void
212  setName(const std::string& name);
213 
214  void
215  setType(InterfaceType type);
216 
217  void
218  setFlags(uint32_t flags);
219 
220  void
221  setState(InterfaceState state);
222 
223  void
224  setMtu(uint32_t mtu);
225 
226  void
227  setEthernetAddress(const ethernet::Address& address);
228 
229  void
231 
232 private: // constructor
233  NetworkInterface(); // accessible through NetworkMonitorImpl::makeNetworkInterface
234 
235 private:
236  int m_index;
237  std::string m_name;
238  InterfaceType m_type;
239  uint32_t m_flags; // IFF_* in <net/if.h>
240  InterfaceState m_state;
241  uint32_t m_mtu;
242  ethernet::Address m_etherAddress;
243  ethernet::Address m_etherBrdAddress;
244  std::set<NetworkAddress> m_netAddresses;
245 
246  friend class NetworkMonitorImpl;
247 };
248 
249 std::ostream&
250 operator<<(std::ostream& os, const NetworkInterface& interface);
251 
252 } // namespace net
253 } // namespace ndn
254 
255 #endif // NDN_NET_NETWORK_INTERFACE_HPP
ndn::net::NetworkInterface::setState
void setState(InterfaceState state)
Definition: network-interface.cpp:99
ndn::net::NetworkMonitorImpl
Definition: network-monitor.hpp:132
signal.hpp
ndn::net::NetworkInterface::getIndex
int getIndex() const
Returns an opaque ID that uniquely identifies the interface on the system.
Definition: network-interface.hpp:92
ndn::net::NetworkInterface
Represents one network interface attached to the host.
Definition: network-interface.hpp:70
ndn::net::NetworkInterface::addNetworkAddress
bool addNetworkAddress(const NetworkAddress &address)
Definition: network-interface.cpp:46
ndn::net::NetworkInterface::setEthernetAddress
void setEthernetAddress(const ethernet::Address &address)
Definition: network-interface.cpp:117
ndn::net::NetworkInterface::removeNetworkAddress
bool removeNetworkAddress(const NetworkAddress &address)
Definition: network-interface.cpp:63
ndn::net::NetworkInterface::getType
InterfaceType getType() const
Returns the hardware type of the interface.
Definition: network-interface.hpp:108
ndn::ethernet::Address
represents an Ethernet hardware address
Definition: ethernet.hpp:53
ndn::net::InterfaceType::LOOPBACK
@ LOOPBACK
ndn::net::InterfaceState::UNKNOWN
@ UNKNOWN
interface is in an unknown state
ndn::net::InterfaceState::NO_CARRIER
@ NO_CARRIER
interface is administratively up but has no carrier
ndn::net::NetworkInterface::setFlags
void setFlags(uint32_t flags)
Definition: network-interface.cpp:93
ndn::net::NetworkAddress
Stores one IP address supported by a network interface.
Definition: network-address.hpp:54
ndn::util::signal::Signal
provides a lightweight signal / event system
Definition: signal.hpp:52
network-address.hpp
ndn::net::NetworkInterface::canMulticast
bool canMulticast() const
Returns true if the interface supports multicast communication.
Definition: network-interface.hpp:188
ndn::net::NetworkInterface::setMtu
void setMtu(uint32_t mtu)
Definition: network-interface.cpp:108
ndn::net::NetworkInterface::onStateChanged
util::Signal< NetworkInterface, InterfaceState, InterfaceState > onStateChanged
Fires when interface state changes.
Definition: network-interface.hpp:74
ndn::net::InterfaceType::ETHERNET
@ ETHERNET
ndn::net::NetworkInterface::getFlags
uint32_t getFlags() const
Returns a bitset of platform-specific flags enabled on the interface.
Definition: network-interface.hpp:116
ndn::net::NetworkInterface::canBroadcast
bool canBroadcast() const
Returns true if the interface supports broadcast communication.
Definition: network-interface.hpp:180
ndn::net::operator<<
std::ostream & operator<<(std::ostream &os, AddressScope scope)
Definition: network-address.cpp:30
ndn::net::NetworkInterface::isUp
bool isUp() const
Returns true if the interface is administratively up.
Definition: network-interface.hpp:196
ndn::net::InterfaceType
InterfaceType
Indicates the hardware type of a network interface.
Definition: network-interface.hpp:38
ndn::net::NetworkInterface::getNetworkAddresses
const std::set< NetworkAddress > & getNetworkAddresses() const
Returns a list of all network-layer addresses present on the interface.
Definition: network-interface.hpp:156
ndn::net::NetworkInterface::onAddressRemoved
util::Signal< NetworkInterface, NetworkAddress > onAddressRemoved
Fires when a network-layer address is removed from the interface.
Definition: network-interface.hpp:86
ndn::net::NetworkInterface::getEthernetAddress
ethernet::Address getEthernetAddress() const
Returns the link-layer (Ethernet) address of the interface.
Definition: network-interface.hpp:140
ndn::net::NetworkInterface::isLoopback
bool isLoopback() const
Returns true if the interface is a loopback interface.
Definition: network-interface.hpp:164
ndn::net::InterfaceState
InterfaceState
Indicates the state of a network interface.
Definition: network-interface.hpp:50
ndn::net::NetworkInterface::setIndex
void setIndex(int index)
Definition: network-interface.cpp:74
ndn::net::NetworkInterface::getState
InterfaceState getState() const
Returns the current state of the interface.
Definition: network-interface.hpp:124
ndn::net::NetworkInterface::getMtu
uint32_t getMtu() const
Returns the MTU (maximum transmission unit) of the interface.
Definition: network-interface.hpp:132
ndn::net::NetworkInterface::onAddressAdded
util::Signal< NetworkInterface, NetworkAddress > onAddressAdded
Fires when a network-layer address is added to the interface.
Definition: network-interface.hpp:82
ndn::net::NetworkInterface::isPointToPoint
bool isPointToPoint() const
Returns true if the interface is a point-to-point interface.
Definition: network-interface.hpp:172
ndn::net::NetworkInterface::setType
void setType(InterfaceType type)
Definition: network-interface.cpp:87
ndn::net::NetworkInterface::onMtuChanged
util::Signal< NetworkInterface, uint32_t, uint32_t > onMtuChanged
Fires when interface mtu changes.
Definition: network-interface.hpp:78
ndn::name
Definition: name-component-types.hpp:33
ndn::net
Definition: link-type-helper.cpp:30
ndn::net::NetworkInterface::getName
std::string getName() const
Returns the name of the interface, unique on the system.
Definition: network-interface.hpp:100
ndn::net::InterfaceState::DORMANT
@ DORMANT
interface has a carrier but it cannot send or receive normal user traffic yet
ndn::net::InterfaceState::DOWN
@ DOWN
interface is administratively down
ndn::net::NetworkInterface::getEthernetBroadcastAddress
ethernet::Address getEthernetBroadcastAddress() const
Returns the link-layer (Ethernet) broadcast address of the interface.
Definition: network-interface.hpp:148
ndn::net::NetworkInterface::setEthernetBroadcastAddress
void setEthernetBroadcastAddress(const ethernet::Address &address)
Definition: network-interface.cpp:123
ethernet.hpp
ndn::net::InterfaceState::RUNNING
@ RUNNING
interface can be used to send and receive packets
ndn::net::InterfaceType::UNKNOWN
@ UNKNOWN
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34
ndn::net::NetworkInterface::setName
void setName(const std::string &name)
Definition: network-interface.cpp:80