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 class NetDeviceQueueInterface;
40 
55 class SimpleNetDevice : public NetDevice
56 {
57 public:
62  static TypeId GetTypeId (void);
63  SimpleNetDevice ();
64 
75  void Receive (Ptr<Packet> packet, uint16_t protocol, Mac48Address to, Mac48Address from);
76 
85 
91  void SetQueue (Ptr<Queue<Packet> > queue);
92 
98  Ptr<Queue<Packet> > GetQueue (void) const;
99 
110 
111  // inherited from NetDevice base class.
112  virtual void SetIfIndex (const uint32_t index);
113  virtual uint32_t GetIfIndex (void) const;
114  virtual Ptr<Channel> GetChannel (void) const;
115  virtual void SetAddress (Address address);
116  virtual Address GetAddress (void) const;
117  virtual bool SetMtu (const uint16_t mtu);
118  virtual uint16_t GetMtu (void) const;
119  virtual bool IsLinkUp (void) const;
120  virtual void AddLinkChangeCallback (Callback<void> callback);
121  virtual bool IsBroadcast (void) const;
122  virtual Address GetBroadcast (void) const;
123  virtual bool IsMulticast (void) const;
124  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
125  virtual bool IsPointToPoint (void) const;
126  virtual bool IsBridge (void) const;
127  virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
128  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
129  virtual Ptr<Node> GetNode (void) const;
130  virtual void SetNode (Ptr<Node> node);
131  virtual bool NeedsArp (void) const;
133 
134  virtual Address GetMulticast (Ipv6Address addr) const;
135 
137  virtual bool SupportsSendFrom (void) const;
138 
139 protected:
140  virtual void DoDispose (void);
141  virtual void DoInitialize (void);
142  virtual void NotifyNewAggregate (void);
143 
144 private:
150  uint16_t m_mtu;
151  uint32_t m_ifIndex;
154 
164 
169  void TransmitComplete (void);
170 
171  bool m_linkUp;
172 
178 
182 
187 };
188 
189 } // namespace ns3
190 
191 #endif /* SIMPLE_NET_DEVICE_H */
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
EventId TransmitCompleteEvent
the Tx Complete event
virtual void DoInitialize(void)
Initialize() implementation.
Ptr< Node > m_node
Node this netDevice is associated to.
TracedCallback m_linkChangeCallbacks
List of callbacks to fire if the link changes state (up or down).
Forward calls to a chain of Callback.
void Receive(Ptr< Packet > packet, uint16_t protocol, Mac48Address to, Mac48Address from)
Receive a packet from a connected SimpleChannel.
virtual void SetIfIndex(const uint32_t index)
virtual bool IsLinkUp(void) const
bool m_pointToPointMode
Flag indicating whether or not the NetDevice is a Point to Point model.
a polymophic address class
Definition: address.h:90
bool m_linkUp
Flag indicating whether or not the link is up.
channel
Definition: third.py:85
Class for representing data rates.
Definition: data-rate.h:88
virtual void SetNode(Ptr< Node > node)
virtual bool IsMulticast(void) const
virtual bool SupportsSendFrom(void) const
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
virtual bool SetMtu(const uint16_t mtu)
virtual bool NeedsArp(void) const
This device assumes 48-bit mac addressing; there is also the possibility to add an ErrorModel if you ...
Mac48Address m_address
MAC address.
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
virtual Address GetAddress(void) const
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
Ptr< Queue< Packet > > m_queue
The Queue for outgoing packets.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
address
Definition: first.py:37
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
an EUI-48 address
Definition: mac48-address.h:43
void SetReceiveErrorModel(Ptr< ErrorModel > em)
Attach a receive ErrorModel to the SimpleNetDevice.
NetDevice::PromiscReceiveCallback m_promiscCallback
Promiscuous receive callback.
virtual Ptr< Node > GetNode(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
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...
virtual void NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
An identifier for simulation events.
Definition: event-id.h:53
Network layer to device interface.
Definition: net-device.h:95
virtual void AddLinkChangeCallback(Callback< void > callback)
void SetQueue(Ptr< Queue< Packet > > queue)
Attach a queue to the SimpleNetDevice.
virtual void SetAddress(Address address)
Set the address of this interface.
Ptr< ErrorModel > m_receiveErrorModel
Receive error model.
virtual void DoDispose(void)
Destructor implementation.
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
virtual uint16_t GetMtu(void) const
NetDevice::ReceiveCallback m_rxCallback
Receive callback.
virtual Address GetBroadcast(void) const
Ptr< SimpleChannel > m_channel
the channel the device is connected to
virtual uint32_t GetIfIndex(void) const
void TransmitComplete(void)
The TransmitComplete method is used internally to finish the process of sending a packet out on the c...
virtual Ptr< Channel > GetChannel(void) const
Ptr< NetDeviceQueueInterface > m_queueInterface
NetDevice queue interface.
void SetChannel(Ptr< SimpleChannel > channel)
Attach a channel to this net device.
Ptr< Queue< Packet > > GetQueue(void) const
Get a copy of the attached Queue.
DataRate m_bps
The device nominal Data rate.
virtual bool IsBroadcast(void) const
a unique identifier for an interface.
Definition: type-id.h:58
static TypeId GetTypeId(void)
Get the type ID.
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
uint32_t m_ifIndex
Interface index.