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