00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "point-to-point-channel.h"
00020 #include "point-to-point-net-device.h"
00021 #include "ns3/packet.h"
00022 #include "ns3/simulator.h"
00023 #include "ns3/log.h"
00024
00025 NS_LOG_COMPONENT_DEFINE ("PointToPointChannel");
00026
00027 namespace ns3 {
00028
00029 NS_OBJECT_ENSURE_REGISTERED (PointToPointChannel);
00030
00031 TypeId
00032 PointToPointChannel::GetTypeId (void)
00033 {
00034 static TypeId tid = TypeId ("ns3::PointToPointChannel")
00035 .SetParent<Channel> ()
00036 .AddConstructor<PointToPointChannel> ()
00037 .AddAttribute ("Delay", "Transmission delay through the channel",
00038 TimeValue (Seconds (0)),
00039 MakeTimeAccessor (&PointToPointChannel::m_delay),
00040 MakeTimeChecker ())
00041 ;
00042 return tid;
00043 }
00044
00045
00046
00047
00048 PointToPointChannel::PointToPointChannel()
00049 :
00050 Channel ("PointToPoint Channel"),
00051 m_delay (Seconds (0.)),
00052 m_nDevices (0)
00053 {
00054 NS_LOG_FUNCTION_NOARGS ();
00055 }
00056
00057 void
00058 PointToPointChannel::Attach(Ptr<PointToPointNetDevice> device)
00059 {
00060 NS_LOG_FUNCTION (this << device);
00061 NS_ASSERT(m_nDevices < N_DEVICES && "Only two devices permitted");
00062 NS_ASSERT(device != 0);
00063
00064 m_link[m_nDevices++].m_src = device;
00065
00066
00067
00068
00069 if (m_nDevices == N_DEVICES)
00070 {
00071 m_link[0].m_dst = m_link[1].m_src;
00072 m_link[1].m_dst = m_link[0].m_src;
00073 m_link[0].m_state = IDLE;
00074 m_link[1].m_state = IDLE;
00075 }
00076 }
00077
00078 bool
00079 PointToPointChannel::TransmitStart(
00080 Ptr<Packet> p,
00081 Ptr<PointToPointNetDevice> src,
00082 Time txTime)
00083 {
00084 NS_LOG_FUNCTION (this << p << src);
00085 NS_LOG_LOGIC ("UID is " << p->GetUid () << ")");
00086
00087 NS_ASSERT(m_link[0].m_state != INITIALIZING);
00088 NS_ASSERT(m_link[1].m_state != INITIALIZING);
00089
00090 uint32_t wire = src == m_link[0].m_src ? 0 : 1;
00091
00092 Simulator::Schedule (txTime + m_delay, &PointToPointNetDevice::Receive,
00093 m_link[wire].m_dst, p);
00094 return true;
00095 }
00096
00097 uint32_t
00098 PointToPointChannel::GetNDevices (void) const
00099 {
00100 NS_LOG_FUNCTION_NOARGS ();
00101 return m_nDevices;
00102 }
00103
00104 Ptr<PointToPointNetDevice>
00105 PointToPointChannel::GetPointToPointDevice (uint32_t i) const
00106 {
00107 NS_LOG_FUNCTION_NOARGS ();
00108 NS_ASSERT(i < 2);
00109 return m_link[i].m_src;
00110 }
00111
00112 Ptr<NetDevice>
00113 PointToPointChannel::GetDevice (uint32_t i) const
00114 {
00115 NS_LOG_FUNCTION_NOARGS ();
00116 return GetPointToPointDevice (i);
00117 }
00118
00119 }