A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
virtual-net-device.h
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 
155  Address m_myAddress;
156  SendCallback m_sendCb;
157  TracedCallback<Ptr<const Packet> > m_macRxTrace;
158  TracedCallback<Ptr<const Packet> > m_macTxTrace;
159  TracedCallback<Ptr<const Packet> > m_macPromiscRxTrace;
160  TracedCallback<Ptr<const Packet> > m_snifferTrace;
161  TracedCallback<Ptr<const Packet> > m_promiscSnifferTrace;
162  Ptr<Node> m_node;
163  ReceiveCallback m_rxCallback;
164  PromiscReceiveCallback m_promiscRxCallback;
165  std::string m_name;
166  uint32_t m_index;
167  uint16_t m_mtu;
168  bool m_needsArp;
169  bool m_supportsSendFrom;
170  bool m_isPointToPoint;
171 };
172 
173 } // namespace ns3
174 
175 #endif
176 
void SetNeedsArp(bool needsArp)
Configure whether the virtual device needs ARP.
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
Callback template class.
Definition: callback.h:369
virtual bool SupportsSendFrom() const
virtual void DoDispose(void)
forward calls to a chain of CallbackAn ns3::TracedCallback has almost exactly the same API as a norma...
Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address & > ReceiveCallback
Definition: net-device.h:292
bool SetMtu(const uint16_t mtu)
Configure the reported MTU for the virtual device.
bool Receive(Ptr< Packet > packet, uint16_t protocol, const Address &source, const Address &destination, PacketType packetType)
virtual bool NeedsArp(void) const
a polymophic address class
Definition: address.h:86
virtual bool IsBroadcast(void) const
virtual void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb)
virtual Address GetAddress(void) const
virtual uint16_t GetMtu(void) const
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
virtual bool IsMulticast(void) const
virtual Ptr< Channel > GetChannel(void) const
virtual void SetAddress(Address address)
virtual void SetIfIndex(const uint32_t index)
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
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.
Callback< bool, Ptr< Packet >, const Address &, const Address &, uint16_t > SendCallback
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)
Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address &, const Address &, enum PacketType > PromiscReceiveCallback
Definition: net-device.h:315
virtual void AddLinkChangeCallback(Callback< void > callback)
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
virtual Ptr< Node > GetNode(void) const
Describes an IPv6 address.
Definition: ipv6-address.h:44
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
Network layer to device interface.
Definition: net-device.h:75
A virtual device, similar to Linux TUN/TAP interfaces.
virtual uint32_t GetIfIndex(void) const
virtual bool IsLinkUp(void) const
void SetSendCallback(SendCallback transmitCb)
Set the user callback to be called when a L2 packet is to be transmitted.
virtual Address GetBroadcast(void) const
a unique identifier for an interface.
Definition: type-id.h:44