A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
point-to-point-net-device.h
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 class Queue;
37 class PointToPointChannel;
38 class ErrorModel;
39 
59 {
60 public:
61  static TypeId GetTypeId (void);
62 
71 
77  virtual ~PointToPointNetDevice ();
78 
87  void SetDataRate (DataRate bps);
88 
95  void SetInterframeGap (Time t);
96 
103 
114  void SetQueue (Ptr<Queue> queue);
115 
121  Ptr<Queue> GetQueue (void) const;
122 
133 
145  void Receive (Ptr<Packet> p);
146 
147  // The remaining methods are documented in ns3::NetDevice*
148 
149  virtual void SetIfIndex (const uint32_t index);
150  virtual uint32_t GetIfIndex (void) const;
151 
152  virtual Ptr<Channel> GetChannel (void) const;
153 
154  virtual void SetAddress (Address address);
155  virtual Address GetAddress (void) const;
156 
157  virtual bool SetMtu (const uint16_t mtu);
158  virtual uint16_t GetMtu (void) const;
159 
160  virtual bool IsLinkUp (void) const;
161 
162  virtual void AddLinkChangeCallback (Callback<void> callback);
163 
164  virtual bool IsBroadcast (void) const;
165  virtual Address GetBroadcast (void) const;
166 
167  virtual bool IsMulticast (void) const;
168  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
169 
170  virtual bool IsPointToPoint (void) const;
171  virtual bool IsBridge (void) const;
172 
173  virtual bool Send (Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber);
174  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
175 
176  virtual Ptr<Node> GetNode (void) const;
177  virtual void SetNode (Ptr<Node> node);
178 
179  virtual bool NeedsArp (void) const;
180 
182 
183  virtual Address GetMulticast (Ipv6Address addr) const;
184 
186  virtual bool SupportsSendFrom (void) const;
187 
188 protected:
189  void DoMpiReceive (Ptr<Packet> p);
190 
191 private:
192 
193  PointToPointNetDevice& operator = (const PointToPointNetDevice &);
195 
196  virtual void DoDispose (void);
197 
198 private:
199 
204  Address GetRemote (void) const;
205 
212  void AddHeader (Ptr<Packet> p, uint16_t protocolNumber);
213 
222  bool ProcessHeader (Ptr<Packet> p, uint16_t& param);
223 
239  bool TransmitStart (Ptr<Packet> p);
240 
247  void TransmitComplete (void);
248 
249  void NotifyLinkUp (void);
250 
255  {
258  };
264 
271 
278 
285 
294 
299 
307 
315 
325 
335 
344 
352 
360 
368 
376 
384 
393 
413 
433 
434  Ptr<Node> m_node;
435  Mac48Address m_address;
436  NetDevice::ReceiveCallback m_rxCallback;
437  NetDevice::PromiscReceiveCallback m_promiscCallback;
438  uint32_t m_ifIndex;
439  bool m_linkUp;
440  TracedCallback<> m_linkChangeCallbacks;
441 
442  static const uint16_t DEFAULT_MTU = 1500;
443 
450  uint32_t m_mtu;
451 
452  Ptr<Packet> m_currentPkt;
453 
459  static uint16_t PppToEther (uint16_t protocol);
460 
466  static uint16_t EtherToPpp (uint16_t protocol);
467 };
468 
469 } // namespace ns3
470 
471 #endif /* POINT_TO_POINT_NET_DEVICE_H */
void SetReceiveErrorModel(Ptr< ErrorModel > em)
keep track of time unit.
Definition: nstime.h:149
virtual bool IsLinkUp(void) const
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
Ptr< Queue > GetQueue(void) const
TracedCallback< Ptr< const Packet > > m_phyTxDropTrace
virtual bool SupportsSendFrom(void) const
TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
forward calls to a chain of CallbackAn ns3::TracedCallback has almost exactly the same API as a norma...
TracedCallback< Ptr< const Packet > > m_phyTxBeginTrace
static uint16_t EtherToPpp(uint16_t protocol)
Ethernet to PPP protocol number mapping.
virtual Ptr< Node > GetNode(void) const
TracedCallback< Ptr< const Packet > > m_macRxTrace
bool ProcessHeader(Ptr< Packet > p, uint16_t &param)
a polymophic address class
Definition: address.h:86
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
static uint16_t PppToEther(uint16_t protocol)
PPP to Ethernet protocol number mapping.
Class for representing data rates.
Definition: data-rate.h:71
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)
TracedCallback< Ptr< const Packet > > m_snifferTrace
A Device for a Point to Point Network Link.
virtual void AddLinkChangeCallback(Callback< void > callback)
virtual bool NeedsArp(void) const
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
virtual uint32_t GetIfIndex(void) const
virtual Ptr< Channel > GetChannel(void) const
virtual Address GetAddress(void) const
an EUI-48 address
Definition: mac48-address.h:41
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
Ptr< PointToPointChannel > m_channel
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
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:44
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
TracedCallback< Ptr< const Packet > > m_phyRxBeginTrace
TracedCallback< Ptr< const Packet > > m_macTxDropTrace
Network layer to device interface.
Definition: net-device.h:75
virtual bool SetMtu(const uint16_t mtu)
virtual void SetIfIndex(const uint32_t index)
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
virtual bool IsBroadcast(void) const
bool Attach(Ptr< PointToPointChannel > ch)
virtual void SetNode(Ptr< Node > node)
void AddHeader(Ptr< Packet > p, uint16_t protocolNumber)
virtual uint16_t GetMtu(void) const
virtual bool IsMulticast(void) const
a unique identifier for an interface.
Definition: type-id.h:44
TracedCallback< Ptr< const Packet > > m_macTxTrace
virtual Address GetBroadcast(void) const
TracedCallback< Ptr< const Packet > > m_phyTxEndTrace