A Discrete-Event Network Simulator
API
simple-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 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #ifndef SIMPLE_NET_DEVICE_H
21 #define SIMPLE_NET_DEVICE_H
22 
23 #include <stdint.h>
24 #include <string>
25 
26 #include "ns3/traced-callback.h"
27 #include "ns3/net-device.h"
28 #include "ns3/data-rate.h"
29 #include "ns3/event-id.h"
30 
31 #include "mac48-address.h"
32 
33 namespace ns3 {
34 
35 template <typename Item> class Queue;
36 class SimpleChannel;
37 class Node;
38 class ErrorModel;
39 
54 class SimpleNetDevice : public NetDevice
55 {
56 public:
61  static TypeId GetTypeId (void);
62  SimpleNetDevice ();
63 
74  void Receive (Ptr<Packet> packet, uint16_t protocol, Mac48Address to, Mac48Address from);
75 
84 
90  void SetQueue (Ptr<Queue<Packet> > queue);
91 
97  Ptr<Queue<Packet> > GetQueue (void) const;
98 
109 
110  // inherited from NetDevice base class.
111  virtual void SetIfIndex (const uint32_t index);
112  virtual uint32_t GetIfIndex (void) const;
113  virtual Ptr<Channel> GetChannel (void) const;
114  virtual void SetAddress (Address address);
115  virtual Address GetAddress (void) const;
116  virtual bool SetMtu (const uint16_t mtu);
117  virtual uint16_t GetMtu (void) const;
118  virtual bool IsLinkUp (void) const;
119  virtual void AddLinkChangeCallback (Callback<void> callback);
120  virtual bool IsBroadcast (void) const;
121  virtual Address GetBroadcast (void) const;
122  virtual bool IsMulticast (void) const;
123  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
124  virtual bool IsPointToPoint (void) const;
125  virtual bool IsBridge (void) const;
126  virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
127  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
128  virtual Ptr<Node> GetNode (void) const;
129  virtual void SetNode (Ptr<Node> node);
130  virtual bool NeedsArp (void) const;
132 
133  virtual Address GetMulticast (Ipv6Address addr) const;
134 
136  virtual bool SupportsSendFrom (void) const;
137 
138 protected:
139  virtual void DoDispose (void);
140 
141 private:
146  uint16_t m_mtu;
147  uint32_t m_ifIndex;
150 
160 
167  void StartTransmission (void);
168 
174  void FinishTransmission (Ptr<Packet> packet);
175 
176  bool m_linkUp;
177 
183 
187 
192 };
193 
194 } // namespace ns3
195 
196 #endif /* SIMPLE_NET_DEVICE_H */
a polymophic address class
Definition: address.h:91
Class for representing data rates.
Definition: data-rate.h:89
An identifier for simulation events.
Definition: event-id.h:54
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
Describes an IPv6 address.
Definition: ipv6-address.h:50
an EUI-48 address
Definition: mac48-address.h:44
Network layer to device interface.
Definition: net-device.h:96
This device assumes 48-bit mac addressing; there is also the possibility to add an ErrorModel if you ...
virtual bool IsMulticast(void) const
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
virtual bool IsBroadcast(void) const
virtual bool IsLinkUp(void) const
virtual Ptr< Node > GetNode(void) const
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received due to the error model being...
TracedCallback m_linkChangeCallbacks
List of callbacks to fire if the link changes state (up or down).
virtual Address GetAddress(void) const
virtual bool NeedsArp(void) const
virtual Ptr< Channel > GetChannel(void) const
void SetQueue(Ptr< Queue< Packet > > queue)
Attach a queue to the SimpleNetDevice.
NetDevice::ReceiveCallback m_rxCallback
Receive callback.
Ptr< Queue< Packet > > GetQueue(void) const
Get a copy of the attached Queue.
DataRate m_bps
The device nominal Data rate.
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
Ptr< Queue< Packet > > m_queue
The Queue for outgoing packets.
static TypeId GetTypeId(void)
Get the type ID.
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
virtual void SetNode(Ptr< Node > node)
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
virtual Address GetBroadcast(void) const
virtual void AddLinkChangeCallback(Callback< void > callback)
void SetReceiveErrorModel(Ptr< ErrorModel > em)
Attach a receive ErrorModel to the SimpleNetDevice.
void StartTransmission(void)
The StartTransmission method is used internally to start the process of sending a packet out on the c...
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
EventId FinishTransmissionEvent
the Tx Complete event
bool m_linkUp
Flag indicating whether or not the link is up.
virtual void SetAddress(Address address)
Set the address of this interface.
bool m_pointToPointMode
Flag indicating whether or not the NetDevice is a Point to Point model.
void FinishTransmission(Ptr< Packet > packet)
The FinishTransmission method is used internally to finish the process of sending a packet out on the...
Ptr< ErrorModel > m_receiveErrorModel
Receive error model.
Ptr< SimpleChannel > m_channel
the channel the device is connected to
virtual bool SetMtu(const uint16_t mtu)
Ptr< Node > m_node
Node this netDevice is associated to.
virtual void SetIfIndex(const uint32_t index)
uint32_t m_ifIndex
Interface index.
Mac48Address m_address
MAC address.
NetDevice::PromiscReceiveCallback m_promiscCallback
Promiscuous receive callback.
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
virtual void DoDispose(void)
Destructor implementation.
virtual bool SupportsSendFrom(void) const
virtual uint16_t GetMtu(void) const
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
virtual uint32_t GetIfIndex(void) const
void Receive(Ptr< Packet > packet, uint16_t protocol, Mac48Address to, Mac48Address from)
Receive a packet from a connected SimpleChannel.
void SetChannel(Ptr< SimpleChannel > channel)
Attach a channel to this net device.
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
address
Definition: first.py:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.
channel
Definition: third.py:92