A Discrete-Event Network Simulator
API
point-to-point-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) 2007, 2008 University of Washington
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 
19 #ifndef POINT_TO_POINT_NET_DEVICE_H
20 #define POINT_TO_POINT_NET_DEVICE_H
21 
22 #include <cstring>
23 #include "ns3/address.h"
24 #include "ns3/node.h"
25 #include "ns3/net-device.h"
26 #include "ns3/callback.h"
27 #include "ns3/packet.h"
28 #include "ns3/traced-callback.h"
29 #include "ns3/nstime.h"
30 #include "ns3/data-rate.h"
31 #include "ns3/ptr.h"
32 #include "ns3/mac48-address.h"
33 
34 namespace ns3 {
35 
36 template <typename Item> class Queue;
37 class NetDeviceQueueInterface;
38 class PointToPointChannel;
39 class ErrorModel;
40 
64 {
65 public:
71  static TypeId GetTypeId (void);
72 
81 
87  virtual ~PointToPointNetDevice ();
88 
96  void SetDataRate (DataRate bps);
97 
104  void SetInterframeGap (Time t);
105 
113 
122  void SetQueue (Ptr<Queue<Packet> > queue);
123 
129  Ptr<Queue<Packet> > GetQueue (void) const;
130 
140 
151  void Receive (Ptr<Packet> p);
152 
153  // The remaining methods are documented in ns3::NetDevice*
154 
155  virtual void SetIfIndex (const uint32_t index);
156  virtual uint32_t GetIfIndex (void) const;
157 
158  virtual Ptr<Channel> GetChannel (void) const;
159 
160  virtual void SetAddress (Address address);
161  virtual Address GetAddress (void) const;
162 
163  virtual bool SetMtu (const uint16_t mtu);
164  virtual uint16_t GetMtu (void) const;
165 
166  virtual bool IsLinkUp (void) const;
167 
168  virtual void AddLinkChangeCallback (Callback<void> callback);
169 
170  virtual bool IsBroadcast (void) const;
171  virtual Address GetBroadcast (void) const;
172 
173  virtual bool IsMulticast (void) const;
174  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
175 
176  virtual bool IsPointToPoint (void) const;
177  virtual bool IsBridge (void) const;
178 
179  virtual bool Send (Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber);
180  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
181 
182  virtual Ptr<Node> GetNode (void) const;
183  virtual void SetNode (Ptr<Node> node);
184 
185  virtual bool NeedsArp (void) const;
186 
188 
189  virtual Address GetMulticast (Ipv6Address addr) const;
190 
192  virtual bool SupportsSendFrom (void) const;
193 
194 protected:
200  void DoMpiReceive (Ptr<Packet> p);
201 
202  virtual void DoInitialize (void);
203  virtual void NotifyNewAggregate (void);
204 
205 private:
206 
216 
225 
229  virtual void DoDispose (void);
230 
231 private:
232 
237  Address GetRemote (void) const;
238 
245  void AddHeader (Ptr<Packet> p, uint16_t protocolNumber);
246 
255  bool ProcessHeader (Ptr<Packet> p, uint16_t& param);
256 
272  bool TransmitStart (Ptr<Packet> p);
273 
280  void TransmitComplete (void);
281 
287  void NotifyLinkUp (void);
288 
293  {
296  };
301 
307 
313 
319 
327 
332 
338 
344 
352 
360 
367 
373 
379 
385 
391 
397 
404 
422 
440 
446  // (promisc data)
447  uint32_t m_ifIndex;
448  bool m_linkUp;
450 
451  static const uint16_t DEFAULT_MTU = 1500;
452 
461  uint32_t m_mtu;
462 
464 
470  static uint16_t PppToEther (uint16_t protocol);
471 
477  static uint16_t EtherToPpp (uint16_t protocol);
478 };
479 
480 } // namespace ns3
481 
482 #endif /* POINT_TO_POINT_NET_DEVICE_H */
virtual uint16_t GetMtu(void) const
void SetReceiveErrorModel(Ptr< ErrorModel > em)
Attach a receive ErrorModel to the PointToPointNetDevice.
PointToPointNetDevice()
Construct a PointToPointNetDevice.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
NetDevice::ReceiveCallback m_rxCallback
Receive callback.
void NotifyLinkUp(void)
Make the link up and running.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
static TypeId GetTypeId(void)
Get the TypeId.
The transmitter is busy transmitting a packet.
virtual uint32_t GetIfIndex(void) const
TracedCallback< Ptr< const Packet > > m_phyTxDropTrace
The trace source fired when the phy layer drops a packet before it tries to transmit it...
uint32_t m_mtu
The Maximum Transmission Unit.
virtual ~PointToPointNetDevice()
Destroy a PointToPointNetDevice.
static const uint16_t DEFAULT_MTU
Default MTU.
TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
The trace source fired when a packet ends the reception process from the medium.
Ptr< Node > m_node
Node owning this NetDevice.
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received.
Forward calls to a chain of Callback.
virtual Ptr< Channel > GetChannel(void) const
TracedCallback< Ptr< const Packet > > m_phyTxBeginTrace
The trace source fired when a packet begins the transmission process on the medium.
Ptr< Packet > m_currentPkt
Current packet processed.
virtual Ptr< Node > GetNode(void) const
static uint16_t EtherToPpp(uint16_t protocol)
Ethernet to PPP protocol number mapping.
virtual Address GetBroadcast(void) const
Ptr< Queue< Packet > > m_queue
The Queue which this PointToPointNetDevice uses as a packet source.
TracedCallback< Ptr< const Packet > > m_macRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
The transmitter is ready to begin transmission of a packet.
bool ProcessHeader(Ptr< Packet > p, uint16_t &param)
Removes, from a packet of data, all headers and trailers that relate to the protocol implemented by t...
a polymophic address class
Definition: address.h:90
static uint16_t PppToEther(uint16_t protocol)
PPP to Ethernet protocol number mapping.
Class for representing data rates.
Definition: data-rate.h:88
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
virtual void SetAddress(Address address)
Set the address of this interface.
void TransmitComplete(void)
Stop Sending a Packet Down the Wire and Begin the Interframe Gap.
TracedCallback m_linkChangeCallbacks
Callback for the link change event.
TracedCallback< Ptr< const Packet > > m_snifferTrace
A trace source that emulates a non-promiscuous protocol sniffer connected to the device.
Ptr< NetDeviceQueueInterface > m_queueInterface
NetDevice queue interface.
bool TransmitStart(Ptr< Packet > p)
Start Sending a Packet Down the Wire.
void SetInterframeGap(Time t)
Set the interframe gap used to separate packets.
NetDevice::PromiscReceiveCallback m_promiscCallback
Receive callback.
Mac48Address m_address
Mac48Address of this NetDevice.
Time m_tInterframeGap
The interframe gap that the Net Device uses to throttle packet transmission.
virtual void AddLinkChangeCallback(Callback< void > callback)
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
TxMachineState
Enumeration of the states of the transmit machine of the net device.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< Queue< Packet > > GetQueue(void) const
Get a copy of the attached Queue.
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
address
Definition: first.py:37
virtual void DoInitialize(void)
Initialize() implementation.
an EUI-48 address
Definition: mac48-address.h:43
void DoMpiReceive(Ptr< Packet > p)
Handler for MPI receive event.
DataRate m_bps
The data rate that the Net Device uses to simulate packet transmission timing.
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
Ptr< PointToPointChannel > m_channel
The PointToPointChannel to which this PointToPointNetDevice has been attached.
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
A trace source that emulates a promiscuous mode protocol sniffer connected to the device...
Ptr< ErrorModel > m_receiveErrorModel
Error model for receive packet events.
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Describes an IPv6 address.
Definition: ipv6-address.h:49
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
uint32_t m_ifIndex
Index of the interface.
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
virtual bool IsBroadcast(void) const
TracedCallback< Ptr< const Packet > > m_phyRxBeginTrace
The trace source fired when a packet begins the reception process from the medium – when the simulat...
TxMachineState m_txMachineState
The state of the Net Device transmit state machine.
PointToPointNetDevice & operator=(const PointToPointNetDevice &o)
Assign operator.
TracedCallback< Ptr< const Packet > > m_macTxDropTrace
The trace source fired when packets coming into the "top" of the device at the L3/L2 transition are d...
Network layer to device interface.
Definition: net-device.h:95
virtual bool SetMtu(const uint16_t mtu)
virtual void SetIfIndex(const uint32_t index)
virtual Address GetAddress(void) const
void SetDataRate(DataRate bps)
Set the Data Rate used for transmission of packets.
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
The trace source fired for packets successfully received by the device but are dropped before being f...
void Receive(Ptr< Packet > p)
Receive a packet from a connected PointToPointChannel.
virtual bool IsMulticast(void) const
bool Attach(Ptr< PointToPointChannel > ch)
Attach the device to a channel.
virtual void DoDispose(void)
Dispose of the object.
virtual void SetNode(Ptr< Node > node)
virtual void NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
bool m_linkUp
Identify if the link is up or not.
virtual bool SupportsSendFrom(void) const
void AddHeader(Ptr< Packet > p, uint16_t protocolNumber)
Adds the necessary headers and trailers to a packet of data in order to respect the protocol implemen...
a unique identifier for an interface.
Definition: type-id.h:58
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition...
void SetQueue(Ptr< Queue< Packet > > queue)
Attach a queue to the PointToPointNetDevice.
TracedCallback< Ptr< const Packet > > m_phyTxEndTrace
The trace source fired when a packet ends the transmission process on the medium. ...