src/devices/point-to-point/point-to-point-channel.h
author Craig Dowell <craigdo@ee.washington.edu>
Thu, 29 May 2008 19:09:56 -0700
changeset 3181 26e7f865c548
parent 2720 3c7d9f8c9034
child 4263 fec2f830d015
permissions -rw-r--r--
point-to-point cleanup
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"
245
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
#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
    26
#include "ns3/data-rate.h"
245
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
namespace ns3 {
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
378
32bd402ea5ea remove unused files, remove notion of PHY, make more realistic p2p-net-device and p2p-channel
Craig Dowell
parents: 373
diff changeset
    30
class PointToPointNetDevice;
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 973
diff changeset
    31
class Packet;
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 
3181
26e7f865c548 point-to-point cleanup
Craig Dowell <craigdo@ee.washington.edu>
parents: 2720
diff changeset
    39
 * point-to-point net devices connected.
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    40
 *
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    41
 * 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
    42
 * [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
    43
 * state (IDLE, TRANSMITTING) associated with each wire.
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    44
 */
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1867
diff changeset
    45
class PointToPointChannel : public Channel 
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1867
diff changeset
    46
{
245
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    47
public:
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1867
diff changeset
    48
  static TypeId GetTypeId (void);
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1867
diff changeset
    49
624
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    50
  /**
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    51
   * \brief Create a PointToPointChannel
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    52
   *
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    53
   * By default, you get a channel with the name "PointToPoint Channel" that
3181
26e7f865c548 point-to-point cleanup
Craig Dowell <craigdo@ee.washington.edu>
parents: 2720
diff changeset
    54
   * has zero transmission delay.
624
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    55
   */
369
29ea5d1a83c8 Rename classes from Serial to PointToPoint
Tom Henderson <tomh@tomh.org>
parents: 368
diff changeset
    56
  PointToPointChannel ();
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    57
624
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
   * \brief Attach a given netdevice to this channel
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 568
diff changeset
    60
   * \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
    61
   */
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 378
diff changeset
    62
  void Attach (Ptr<PointToPointNetDevice> device);
1794
1e3a6022bcb1 miscellaneous point-to-point-channel.h cleanups
Tom Henderson <tomh@tomh.org>
parents: 1792
diff changeset
    63
1e3a6022bcb1 miscellaneous point-to-point-channel.h cleanups
Tom Henderson <tomh@tomh.org>
parents: 1792
diff changeset
    64
  /**
1e3a6022bcb1 miscellaneous point-to-point-channel.h cleanups
Tom Henderson <tomh@tomh.org>
parents: 1792
diff changeset
    65
   * \brief Attach a given netdevice to this channel
1e3a6022bcb1 miscellaneous point-to-point-channel.h cleanups
Tom Henderson <tomh@tomh.org>
parents: 1792
diff changeset
    66
   * \param p Packet to transmit
1e3a6022bcb1 miscellaneous point-to-point-channel.h cleanups
Tom Henderson <tomh@tomh.org>
parents: 1792
diff changeset
    67
   * \param src Source PointToPointNetDevice
1e3a6022bcb1 miscellaneous point-to-point-channel.h cleanups
Tom Henderson <tomh@tomh.org>
parents: 1792
diff changeset
    68
   * \param txTime Transmit time to apply
1e3a6022bcb1 miscellaneous point-to-point-channel.h cleanups
Tom Henderson <tomh@tomh.org>
parents: 1792
diff changeset
    69
   */
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 973
diff changeset
    70
  bool TransmitStart (Ptr<Packet> p, Ptr<PointToPointNetDevice> src,
3181
26e7f865c548 point-to-point cleanup
Craig Dowell <craigdo@ee.washington.edu>
parents: 2720
diff changeset
    71
    Time txTime);
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    72
1794
1e3a6022bcb1 miscellaneous point-to-point-channel.h cleanups
Tom Henderson <tomh@tomh.org>
parents: 1792
diff changeset
    73
  /**
1e3a6022bcb1 miscellaneous point-to-point-channel.h cleanups
Tom Henderson <tomh@tomh.org>
parents: 1792
diff changeset
    74
   * \brief Get number of devices on this channel
1e3a6022bcb1 miscellaneous point-to-point-channel.h cleanups
Tom Henderson <tomh@tomh.org>
parents: 1792
diff changeset
    75
   * \returns number of devices on this channel
1e3a6022bcb1 miscellaneous point-to-point-channel.h cleanups
Tom Henderson <tomh@tomh.org>
parents: 1792
diff changeset
    76
   */
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    77
  virtual uint32_t GetNDevices (void) const;
3181
26e7f865c548 point-to-point cleanup
Craig Dowell <craigdo@ee.washington.edu>
parents: 2720
diff changeset
    78
1792
bca29198a7dd Make GetDevice return pointer to appropriately subclassed NetDevice
Tom Henderson <tomh@tomh.org>
parents: 973
diff changeset
    79
  /*
1794
1e3a6022bcb1 miscellaneous point-to-point-channel.h cleanups
Tom Henderson <tomh@tomh.org>
parents: 1792
diff changeset
    80
   * \brief Get PointToPointNetDevice corresponding to index i on this channel
1e3a6022bcb1 miscellaneous point-to-point-channel.h cleanups
Tom Henderson <tomh@tomh.org>
parents: 1792
diff changeset
    81
   * \param i Index number of the device requested
1e3a6022bcb1 miscellaneous point-to-point-channel.h cleanups
Tom Henderson <tomh@tomh.org>
parents: 1792
diff changeset
    82
   * \returns Ptr to PointToPointNetDevice requested
1792
bca29198a7dd Make GetDevice return pointer to appropriately subclassed NetDevice
Tom Henderson <tomh@tomh.org>
parents: 973
diff changeset
    83
   */
2720
3c7d9f8c9034 make ns3::Channel wholy pure.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2592
diff changeset
    84
  Ptr<PointToPointNetDevice> GetPointToPointDevice (uint32_t i) const;
3181
26e7f865c548 point-to-point cleanup
Craig Dowell <craigdo@ee.washington.edu>
parents: 2720
diff changeset
    85
1794
1e3a6022bcb1 miscellaneous point-to-point-channel.h cleanups
Tom Henderson <tomh@tomh.org>
parents: 1792
diff changeset
    86
  /*
3181
26e7f865c548 point-to-point cleanup
Craig Dowell <craigdo@ee.washington.edu>
parents: 2720
diff changeset
    87
   * \brief Get NetDevice corresponding to index i on this channel
26e7f865c548 point-to-point cleanup
Craig Dowell <craigdo@ee.washington.edu>
parents: 2720
diff changeset
    88
   * \param i Index number of the device requested
26e7f865c548 point-to-point cleanup
Craig Dowell <craigdo@ee.washington.edu>
parents: 2720
diff changeset
    89
   * \returns Ptr to NetDevice requested
1794
1e3a6022bcb1 miscellaneous point-to-point-channel.h cleanups
Tom Henderson <tomh@tomh.org>
parents: 1792
diff changeset
    90
   */
3181
26e7f865c548 point-to-point cleanup
Craig Dowell <craigdo@ee.washington.edu>
parents: 2720
diff changeset
    91
  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
    92
245
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    93
private:
1794
1e3a6022bcb1 miscellaneous point-to-point-channel.h cleanups
Tom Henderson <tomh@tomh.org>
parents: 1792
diff changeset
    94
  // Each point to point link has exactly two net devices
1e3a6022bcb1 miscellaneous point-to-point-channel.h cleanups
Tom Henderson <tomh@tomh.org>
parents: 1792
diff changeset
    95
  static const int N_DEVICES = 2;
1e3a6022bcb1 miscellaneous point-to-point-channel.h cleanups
Tom Henderson <tomh@tomh.org>
parents: 1792
diff changeset
    96
245
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    97
  Time          m_delay;
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    98
  int32_t       m_nDevices;
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
    99
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   100
  enum WireState
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   101
    {
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   102
      INITIALIZING,
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   103
      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
   104
      TRANSMITTING,
32bd402ea5ea remove unused files, remove notion of PHY, make more realistic p2p-net-device and p2p-channel
Craig Dowell
parents: 373
diff changeset
   105
      PROPAGATING
368
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
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   108
  class Link
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   109
  {
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   110
  public:
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   111
    Link() : m_state (INITIALIZING), m_src (0), m_dst (0) {}
3181
26e7f865c548 point-to-point cleanup
Craig Dowell <craigdo@ee.washington.edu>
parents: 2720
diff changeset
   112
    WireState                  m_state;
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 378
diff changeset
   113
    Ptr<PointToPointNetDevice> m_src;
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 378
diff changeset
   114
    Ptr<PointToPointNetDevice> m_dst;
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   115
  };
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   116
    
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   117
  Link    m_link[N_DEVICES];
245
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   118
};
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   119
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents: 331
diff changeset
   120
} // namespace ns3
245
28ba3a5cdff8 add p2p netdevice and channel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   121
369
29ea5d1a83c8 Rename classes from Serial to PointToPoint
Tom Henderson <tomh@tomh.org>
parents: 368
diff changeset
   122
#endif /* POINT_TO_POINT_CHANNEL_H */