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 
32 namespace ns3 {
33 
34 
59 {
60 public:
65  typedef Callback<bool, Ptr<Packet>, const Address&, const Address&, uint16_t> SendCallback;
66 
67  static TypeId GetTypeId (void);
69 
70  virtual ~VirtualNetDevice ();
71 
76  void SetSendCallback (SendCallback transmitCb);
77 
85  void SetNeedsArp (bool needsArp);
86 
93  void SetIsPointToPoint (bool isPointToPoint);
94 
98  void SetSupportsSendFrom (bool supportsSendFrom);
99 
105  bool SetMtu (const uint16_t mtu);
106 
107 
119  bool Receive (Ptr<Packet> packet, uint16_t protocol,
120  const Address &source, const Address &destination,
121  PacketType packetType);
122 
123 
124  // inherited from NetDevice base class.
125  virtual void SetIfIndex (const uint32_t index);
126  virtual uint32_t GetIfIndex (void) const;
127  virtual Ptr<Channel> GetChannel (void) const;
128  virtual void SetAddress (Address address);
129  virtual Address GetAddress (void) const;
130  virtual uint16_t GetMtu (void) const;
131  virtual bool IsLinkUp (void) const;
132  virtual void AddLinkChangeCallback (Callback<void> callback);
133  virtual bool IsBroadcast (void) const;
134  virtual Address GetBroadcast (void) const;
135  virtual bool IsMulticast (void) const;
136  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
137  virtual Address GetMulticast (Ipv6Address addr) const;
138  virtual bool IsPointToPoint (void) const;
139  virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
140  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
141  virtual Ptr<Node> GetNode (void) const;
142  virtual void SetNode (Ptr<Node> node);
143  virtual bool NeedsArp (void) const;
146  virtual bool SupportsSendFrom () const;
147  virtual bool IsBridge (void) const;
148 
149 protected:
150 
151  virtual void DoDispose (void);
152 
153 private:
154 
165  std::string m_name;
166  uint32_t m_index;
167  uint16_t m_mtu;
171 };
172 
173 } // namespace ns3
174 
175 #endif
176 
void SetNeedsArp(bool needsArp)
Configure whether the virtual device needs ARP.
Callback template class.
Definition: callback.h:1176
Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address &> ReceiveCallback
Definition: net-device.h:318
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
virtual void DoDispose(void)
Destructor implementation.
Forward calls to a chain of Callback.
bool SetMtu(const uint16_t mtu)
Configure the reported MTU for the virtual device.
virtual Address GetBroadcast(void) const
bool Receive(Ptr< Packet > packet, uint16_t protocol, const Address &source, const Address &destination, PacketType packetType)
virtual Ptr< Channel > GetChannel(void) const
a polymophic address class
Definition: address.h:90
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
virtual bool IsMulticast(void) const
virtual void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb)
TracedCallback< Ptr< const Packet > > m_snifferTrace
virtual bool SupportsSendFrom() const
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
virtual Ptr< Node > GetNode(void) const
virtual bool IsLinkUp(void) const
virtual void SetAddress(Address address)
Set the address of this interface.
virtual void SetIfIndex(const uint32_t index)
virtual uint16_t GetMtu(void) const
void SetIsPointToPoint(bool isPointToPoint)
Configure whether the virtual device is point-to-point.
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.
virtual bool IsBroadcast(void) const
void SetSupportsSendFrom(bool supportsSendFrom)
Configure whether the virtual device supports SendFrom.
virtual void SetNode(Ptr< Node > node)
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address &, const Address &, enum PacketType > PromiscReceiveCallback
Definition: net-device.h:343
address
Definition: first.py:37
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
PromiscReceiveCallback m_promiscRxCallback
TracedCallback< Ptr< const Packet > > m_macRxTrace
virtual void AddLinkChangeCallback(Callback< void > callback)
TracedCallback< Ptr< const Packet > > m_macTxTrace
virtual Address GetAddress(void) const
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
virtual bool NeedsArp(void) const
Describes an IPv6 address.
Definition: ipv6-address.h:49
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
Network layer to device interface.
Definition: net-device.h:95
ReceiveCallback m_rxCallback
static TypeId GetTypeId(void)
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:296
void SetSendCallback(SendCallback transmitCb)
Set the user callback to be called when a L2 packet is to be transmitted.
a unique identifier for an interface.
Definition: type-id.h:58
virtual uint32_t GetIfIndex(void) const