src/devices/point-to-point/point-to-point-channel.h
author Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
Fri, 27 Jul 2007 20:26:36 +0200
changeset 973 2aea9e9f698c
parent 972 src/devices/point-to-point/p2p-channel.h@6946c8237a73
child 1792 bca29198a7dd
child 1866 e7dbcc4df546
permissions -rw-r--r--
src/devices/point-to-point/p2p-* -> src/devices/point-to-point/point-to-point-*
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
     2
/*
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
     3
 * Copyright (c) 2007 University of Washington
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
     4
 *
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
     7
 * published by the Free Software Foundation;
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
     8
 *
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    12
 * GNU General Public License for more details.
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    13
 *
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    14
 * You should have received a copy of the GNU General Public License
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    15
 * along with this program; if not, write to the Free Software
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    17
 */
245
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
369
29ea5d1a83c8 Rename classes from Serial to PointToPoint
Tom Henderson <tomh@tomh.org>
parents: 368
diff changeset
    19
#ifndef POINT_TO_POINT_CHANNEL_H
29ea5d1a83c8 Rename classes from Serial to PointToPoint
Tom Henderson <tomh@tomh.org>
parents: 368
diff changeset
    20
#define POINT_TO_POINT_CHANNEL_H
245
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    22
#include <list>
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    23
#include "ns3/channel.h"
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 378
diff changeset
    24
#include "ns3/ptr.h"
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    25
#include "ns3/packet.h"
245
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
#include "ns3/nstime.h"
373
960c8e8721de Move simple-p2p.cc to DataRate; fix small bug in DataRate and add include guards
Tom Henderson <tomh@tomh.org>
parents: 369
diff changeset
    27
#include "ns3/data-rate.h"
245
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
namespace ns3 {
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
378
32bd402ea5ea remove unused files, remove notion of PHY, make more realistic p2p-net-device and p2p-channel
Craig Dowell
parents: 373
diff changeset
    31
class PointToPointNetDevice;
245
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    33
/**
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    34
 * \brief Simple Point To Point Channel.
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    35
 *
378
32bd402ea5ea remove unused files, remove notion of PHY, make more realistic p2p-net-device and p2p-channel
Craig Dowell
parents: 373
diff changeset
    36
 * This class represents a very simple point to point channel.  Think full
32bd402ea5ea remove unused files, remove notion of PHY, make more realistic p2p-net-device and p2p-channel
Craig Dowell
parents: 373
diff changeset
    37
 * duplex RS-232 or RS-422 with null modem and no handshaking.  There is no
32bd402ea5ea remove unused files, remove notion of PHY, make more realistic p2p-net-device and p2p-channel
Craig Dowell
parents: 373
diff changeset
    38
 * multi-drop capability on this channel -- there can be a maximum of two 
32bd402ea5ea remove unused files, remove notion of PHY, make more realistic p2p-net-device and p2p-channel
Craig Dowell
parents: 373
diff changeset
    39
 * point-to-point net devices connected.  Once we start talking about multi-
32bd402ea5ea remove unused files, remove notion of PHY, make more realistic p2p-net-device and p2p-channel
Craig Dowell
parents: 373
diff changeset
    40
 * drop, or CSMA, or some other sharing mechanism, things begin getting 
32bd402ea5ea remove unused files, remove notion of PHY, make more realistic p2p-net-device and p2p-channel
Craig Dowell
parents: 373
diff changeset
    41
 * complicated quickly.  Rather than invent some ad-hoc mechanism, we just
32bd402ea5ea remove unused files, remove notion of PHY, make more realistic p2p-net-device and p2p-channel
Craig Dowell
parents: 373
diff changeset
    42
 * Keep It Simple everywhere.
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    43
 *
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    44
 * When the channel is instaniated, the constructor takes parameters for
378
32bd402ea5ea remove unused files, remove notion of PHY, make more realistic p2p-net-device and p2p-channel
Craig Dowell
parents: 373
diff changeset
    45
 * a single speed, in bits per second, and a speed-of-light delay time as a
32bd402ea5ea remove unused files, remove notion of PHY, make more realistic p2p-net-device and p2p-channel
Craig Dowell
parents: 373
diff changeset
    46
 * Time object.  Both directions use the same speed and delay time.
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    47
 *
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    48
 * There are two "wires" in the channel.  The first device connected gets the
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    49
 * [0] wire to transmit on.  The second device gets the [1] wire.  There is a
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    50
 * state (IDLE, TRANSMITTING) associated with each wire.
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    51
 */
369
29ea5d1a83c8 Rename classes from Serial to PointToPoint
Tom Henderson <tomh@tomh.org>
parents: 368
diff changeset
    52
class PointToPointChannel : public Channel {
245
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    53
public:
926
1fdec986d774 Simplifications to the point to point devices and channel
George F. Riley<riley@ece.gatech.edu>
parents: 624
diff changeset
    54
// Each point to point link has exactly two net devices
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    55
  static const int N_DEVICES = 2;
624
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    56
  /**
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    57
   * \brief Create a PointToPointChannel
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    58
   *
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    59
   * By default, you get a channel with the name "PointToPoint Channel" that
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    60
   * has an "infitely" fast transmission speed and zero delay.
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    61
   */
369
29ea5d1a83c8 Rename classes from Serial to PointToPoint
Tom Henderson <tomh@tomh.org>
parents: 368
diff changeset
    62
  PointToPointChannel ();
624
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    63
  
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    64
  /**
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    65
   * \brief Create a PointToPointChannel
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    66
   *
926
1fdec986d774 Simplifications to the point to point devices and channel
George F. Riley<riley@ece.gatech.edu>
parents: 624
diff changeset
    67
   * \param bps The maximum bitrate of the channel
624
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    68
   * \param delay Transmission delay through the channel
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    69
   */  
369
29ea5d1a83c8 Rename classes from Serial to PointToPoint
Tom Henderson <tomh@tomh.org>
parents: 368
diff changeset
    70
  PointToPointChannel (const DataRate& bps, const Time& delay);
624
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    71
  
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    72
  /**
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    73
   * \brief Create a PointToPointChannel
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    74
   *
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    75
   * \param name the name of the channel for identification purposes
926
1fdec986d774 Simplifications to the point to point devices and channel
George F. Riley<riley@ece.gatech.edu>
parents: 624
diff changeset
    76
   * \param bps The maximum bitrate of the channel
624
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    77
   * \param delay Transmission delay through the channel
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    78
   */
369
29ea5d1a83c8 Rename classes from Serial to PointToPoint
Tom Henderson <tomh@tomh.org>
parents: 368
diff changeset
    79
  PointToPointChannel (const std::string& name,
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    80
                 const DataRate& bps, const Time& delay);
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    81
624
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    82
  /**
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    83
   * \brief Attach a given netdevice to this channel
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    84
   * \param device pointer to the netdevice to attach to the channel
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    85
   */
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 378
diff changeset
    86
  void Attach (Ptr<PointToPointNetDevice> device);
926
1fdec986d774 Simplifications to the point to point devices and channel
George F. Riley<riley@ece.gatech.edu>
parents: 624
diff changeset
    87
  bool TransmitStart (Packet& p, Ptr<PointToPointNetDevice> src,
1fdec986d774 Simplifications to the point to point devices and channel
George F. Riley<riley@ece.gatech.edu>
parents: 624
diff changeset
    88
                      const Time& txTime);
1fdec986d774 Simplifications to the point to point devices and channel
George F. Riley<riley@ece.gatech.edu>
parents: 624
diff changeset
    89
  // Below two not needed
1fdec986d774 Simplifications to the point to point devices and channel
George F. Riley<riley@ece.gatech.edu>
parents: 624
diff changeset
    90
  //bool TransmitEnd (Packet &p, Ptr<PointToPointNetDevice> src);
1fdec986d774 Simplifications to the point to point devices and channel
George F. Riley<riley@ece.gatech.edu>
parents: 624
diff changeset
    91
  //void PropagationCompleteEvent(Packet p, Ptr<PointToPointNetDevice> src);
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    92
624
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    93
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    94
  virtual uint32_t GetNDevices (void) const;
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 378
diff changeset
    95
  virtual Ptr<NetDevice> GetDevice (uint32_t i) const;
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    96
926
1fdec986d774 Simplifications to the point to point devices and channel
George F. Riley<riley@ece.gatech.edu>
parents: 624
diff changeset
    97
  virtual const DataRate& GetDataRate (void);
1fdec986d774 Simplifications to the point to point devices and channel
George F. Riley<riley@ece.gatech.edu>
parents: 624
diff changeset
    98
  virtual const Time&     GetDelay (void);
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    99
245
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   100
private:
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   101
  DataRate      m_bps;
245
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   102
  Time          m_delay;
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   103
  int32_t       m_nDevices;
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   104
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   105
  enum WireState
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   106
    {
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   107
      INITIALIZING,
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   108
      IDLE,
378
32bd402ea5ea remove unused files, remove notion of PHY, make more realistic p2p-net-device and p2p-channel
Craig Dowell
parents: 373
diff changeset
   109
      TRANSMITTING,
32bd402ea5ea remove unused files, remove notion of PHY, make more realistic p2p-net-device and p2p-channel
Craig Dowell
parents: 373
diff changeset
   110
      PROPAGATING
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   111
    };
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   112
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   113
  class Link
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   114
  {
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   115
  public:
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   116
    Link() : m_state (INITIALIZING), m_src (0), m_dst (0) {}
378
32bd402ea5ea remove unused files, remove notion of PHY, make more realistic p2p-net-device and p2p-channel
Craig Dowell
parents: 373
diff changeset
   117
    WireState              m_state;
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 378
diff changeset
   118
    Ptr<PointToPointNetDevice> m_src;
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 378
diff changeset
   119
    Ptr<PointToPointNetDevice> m_dst;
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   120
  };
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   121
    
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   122
  Link    m_link[N_DEVICES];
245
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   123
};
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   124
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   125
} // namespace ns3
245
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   126
369
29ea5d1a83c8 Rename classes from Serial to PointToPoint
Tom Henderson <tomh@tomh.org>
parents: 368
diff changeset
   127
#endif /* POINT_TO_POINT_CHANNEL_H */