A Discrete-Event Network Simulator
API
virtual-net-device.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008,2009 INESC Porto
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
18  */
19 
20 #ifndef VIRTUAL_NET_DEVICE_H
21 #define VIRTUAL_NET_DEVICE_H
22 
23 #include "ns3/address.h"
24 #include "ns3/callback.h"
25 #include "ns3/net-device.h"
26 #include "ns3/node.h"
27 #include "ns3/packet.h"
28 #include "ns3/ptr.h"
29 #include "ns3/traced-callback.h"
30 
31 namespace ns3
32 {
33 
58 {
59  public:
64  typedef Callback<bool, Ptr<Packet>, const Address&, const Address&, uint16_t> SendCallback;
65 
70  static TypeId GetTypeId();
72 
73  ~VirtualNetDevice() override;
74 
79  void SetSendCallback(SendCallback transmitCb);
80 
88  void SetNeedsArp(bool needsArp);
89 
96  void SetIsPointToPoint(bool isPointToPoint);
97 
102  void SetSupportsSendFrom(bool supportsSendFrom);
103 
109  bool SetMtu(const uint16_t mtu) override;
110 
122  bool Receive(Ptr<Packet> packet,
123  uint16_t protocol,
124  const Address& source,
125  const Address& destination,
126  PacketType packetType);
127 
128  // inherited from NetDevice base class.
129  void SetIfIndex(const uint32_t index) override;
130  uint32_t GetIfIndex() const override;
131  Ptr<Channel> GetChannel() const override;
132  void SetAddress(Address address) override;
133  Address GetAddress() const override;
134  uint16_t GetMtu() const override;
135  bool IsLinkUp() const override;
136  void AddLinkChangeCallback(Callback<void> callback) override;
137  bool IsBroadcast() const override;
138  Address GetBroadcast() const override;
139  bool IsMulticast() const override;
140  Address GetMulticast(Ipv4Address multicastGroup) const override;
141  Address GetMulticast(Ipv6Address addr) const override;
142  bool IsPointToPoint() const override;
143  bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) override;
144  bool SendFrom(Ptr<Packet> packet,
145  const Address& source,
146  const Address& dest,
147  uint16_t protocolNumber) override;
148  Ptr<Node> GetNode() const override;
149  void SetNode(Ptr<Node> node) override;
150  bool NeedsArp() const override;
153  bool SupportsSendFrom() const override;
154  bool IsBridge() const override;
155 
156  protected:
157  void DoDispose() override;
158 
159  private:
170  std::string m_name;
171  uint32_t m_index;
172  uint16_t m_mtu;
173  bool m_needsArp;
176 };
177 
178 } // namespace ns3
179 
180 #endif
a polymophic address class
Definition: address.h:101
Callback template class.
Definition: callback.h:438
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Describes an IPv6 address.
Definition: ipv6-address.h:49
Network layer to device interface.
Definition: net-device.h:98
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:300
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
A virtual device, similar to Linux TUN/TAP interfaces.
Address GetMulticast(Ipv4Address multicastGroup) const override
Make and return a MAC multicast address using the provided multicast group.
static TypeId GetTypeId()
Get the type ID.
Ptr< Node > m_node
Pointer to the node.
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
Promisc Sniffer trace.
uint32_t GetIfIndex() const override
bool SetMtu(const uint16_t mtu) override
Configure the reported MTU for the virtual device.
void SetReceiveCallback(NetDevice::ReceiveCallback cb) override
Address GetAddress() const override
uint32_t m_index
Device index.
bool SupportsSendFrom() const override
bool IsMulticast() const override
bool IsLinkUp() const override
void SetAddress(Address address) override
Set the address of this interface.
void AddLinkChangeCallback(Callback< void > callback) override
TracedCallback< Ptr< const Packet > > m_macRxTrace
Rx trace.
bool IsPointToPoint() const override
Return true if the net device is on a point-to-point link.
void SetSupportsSendFrom(bool supportsSendFrom)
Configure whether the virtual device supports SendFrom.
void SetNode(Ptr< Node > node) override
bool Receive(Ptr< Packet > packet, uint16_t protocol, const Address &source, const Address &destination, PacketType packetType)
TracedCallback< Ptr< const Packet > > m_snifferTrace
Sniffer trace.
bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber) override
void SetNeedsArp(bool needsArp)
Configure whether the virtual device needs ARP.
bool NeedsArp() const override
void DoDispose() override
Destructor implementation.
Ptr< Channel > GetChannel() const override
bool m_needsArp
True if the device needs ARP.
bool IsBroadcast() const override
void SetIfIndex(const uint32_t index) override
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
Promisc Rx trace.
bool m_supportsSendFrom
True if the device supports SendFrm.
void SetIsPointToPoint(bool isPointToPoint)
Configure whether the virtual device is point-to-point.
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
Ptr< Node > GetNode() const override
Address GetBroadcast() const override
Address m_myAddress
MAC address.
uint16_t GetMtu() const override
PromiscReceiveCallback m_promiscRxCallback
Promisc Rx callback.
std::string m_name
Name of the device.
ReceiveCallback m_rxCallback
Rx callback.
void SetSendCallback(SendCallback transmitCb)
Set the user callback to be called when a L2 packet is to be transmitted.
Callback< bool, Ptr< Packet >, const Address &, const Address &, uint16_t > SendCallback
Callback the be invoked when the VirtualNetDevice is asked to queue/transmit a packet.
bool IsBridge() const override
Return true if the net device is acting as a bridge.
bool m_isPointToPoint
True if the device is a PointToPoint type device.
SendCallback m_sendCb
send callback
TracedCallback< Ptr< const Packet > > m_macTxTrace
Tx trace.
void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb) override
address
Definition: first.py:47
Every class exported by the ns3 library is enclosed in the ns3 namespace.