00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2007 University of Washington 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 */ 00018 00019 #ifndef POINT_TO_POINT_CHANNEL_H 00020 #define POINT_TO_POINT_CHANNEL_H 00021 00022 #include <list> 00023 #include "ns3/channel.h" 00024 #include "ns3/ptr.h" 00025 #include "ns3/nstime.h" 00026 #include "ns3/data-rate.h" 00027 00028 namespace ns3 { 00029 00030 class PointToPointNetDevice; 00031 class Packet; 00032 00033 /** 00034 * \brief Simple Point To Point Channel. 00035 * 00036 * This class represents a very simple point to point channel. Think full 00037 * duplex RS-232 or RS-422 with null modem and no handshaking. There is no 00038 * multi-drop capability on this channel -- there can be a maximum of two 00039 * point-to-point net devices connected. 00040 * 00041 * There are two "wires" in the channel. The first device connected gets the 00042 * [0] wire to transmit on. The second device gets the [1] wire. There is a 00043 * state (IDLE, TRANSMITTING) associated with each wire. 00044 */ 00045 class PointToPointChannel : public Channel 00046 { 00047 public: 00048 static TypeId GetTypeId (void); 00049 00050 /** 00051 * \brief Create a PointToPointChannel 00052 * 00053 * By default, you get a channel with the name "PointToPoint Channel" that 00054 * has zero transmission delay. 00055 */ 00056 PointToPointChannel (); 00057 00058 /** 00059 * \brief Attach a given netdevice to this channel 00060 * \param device pointer to the netdevice to attach to the channel 00061 */ 00062 void Attach (Ptr<PointToPointNetDevice> device); 00063 00064 /** 00065 * \brief Attach a given netdevice to this channel 00066 * \param p Packet to transmit 00067 * \param src Source PointToPointNetDevice 00068 * \param txTime Transmit time to apply 00069 */ 00070 bool TransmitStart (Ptr<Packet> p, Ptr<PointToPointNetDevice> src, 00071 Time txTime); 00072 00073 /** 00074 * \brief Get number of devices on this channel 00075 * \returns number of devices on this channel 00076 */ 00077 virtual uint32_t GetNDevices (void) const; 00078 00079 /* 00080 * \brief Get PointToPointNetDevice corresponding to index i on this channel 00081 * \param i Index number of the device requested 00082 * \returns Ptr to PointToPointNetDevice requested 00083 */ 00084 Ptr<PointToPointNetDevice> GetPointToPointDevice (uint32_t i) const; 00085 00086 /* 00087 * \brief Get NetDevice corresponding to index i on this channel 00088 * \param i Index number of the device requested 00089 * \returns Ptr to NetDevice requested 00090 */ 00091 virtual Ptr<NetDevice> GetDevice (uint32_t i) const; 00092 00093 private: 00094 // Each point to point link has exactly two net devices 00095 static const int N_DEVICES = 2; 00096 00097 Time m_delay; 00098 int32_t m_nDevices; 00099 00100 enum WireState 00101 { 00102 INITIALIZING, 00103 IDLE, 00104 TRANSMITTING, 00105 PROPAGATING 00106 }; 00107 00108 class Link 00109 { 00110 public: 00111 Link() : m_state (INITIALIZING), m_src (0), m_dst (0) {} 00112 WireState m_state; 00113 Ptr<PointToPointNetDevice> m_src; 00114 Ptr<PointToPointNetDevice> m_dst; 00115 }; 00116 00117 Link m_link[N_DEVICES]; 00118 }; 00119 00120 } // namespace ns3 00121 00122 #endif /* POINT_TO_POINT_CHANNEL_H */