diff --git a/examples/simple-p2p.cc b/examples/simple-p2p.cc index 60462099d..4cd3a39d8 100644 --- a/examples/simple-p2p.cc +++ b/examples/simple-p2p.cc @@ -45,6 +45,7 @@ #include "ns3/simulator.h" #include "ns3/nstime.h" +#include "ns3/data-rate.h" #include "ns3/trace-writer.h" #include "ns3/internet-node.h" @@ -236,13 +237,13 @@ int main (int argc, char *argv[]) ch2 = PointToPointTopology::AddPointToPointLink ( n1, Ipv4Address("10.1.2.1"), n2, Ipv4Address("10.1.2.2"), - 5000000, MilliSeconds(2)); + DataRate(5000000), MilliSeconds(2)); PointToPointChannel* ch3; ch3 = PointToPointTopology::AddPointToPointLink ( n2, Ipv4Address("10.1.3.1"), n3, Ipv4Address("10.1.3.2"), - 1500000, MilliSeconds(10)); + DataRate(1500000), MilliSeconds(10)); // To Do: // avoid "new" calls, instead use application list diff --git a/src/common/data-rate.cc b/src/common/data-rate.cc index 1ff938d6c..fe61c0b6c 100644 --- a/src/common/data-rate.cc +++ b/src/common/data-rate.cc @@ -80,7 +80,7 @@ uint64_t DataRate::Parse(const std::string s) double DataRate::CalculateTxTime(uint32_t bytes) const { - return bytes*8/m_bps; + return static_cast(bytes)*8/m_bps; } uint64_t DataRate::GetBitRate() const diff --git a/src/common/data-rate.h b/src/common/data-rate.h index 87609146b..c6006a747 100644 --- a/src/common/data-rate.h +++ b/src/common/data-rate.h @@ -19,6 +19,9 @@ // Author: Rajib Bhattacharjea // +#ifndef DATA_RATE_H +#define DATA_RATE_H + #include "ns3/fatal-error.h" #include #include @@ -95,3 +98,5 @@ double operator*(const DataRate& lhs, const TimeUnit<1>& rhs); double operator*(const TimeUnit<1>& lhs, const DataRate& rhs); };//namespace ns3 + +#endif /* DATA_RATE_H */ diff --git a/src/devices/p2p/p2p-channel.cc b/src/devices/p2p/p2p-channel.cc index 5106faa79..92d8e7d76 100644 --- a/src/devices/p2p/p2p-channel.cc +++ b/src/devices/p2p/p2p-channel.cc @@ -36,7 +36,7 @@ namespace ns3 { PointToPointChannel::PointToPointChannel() : Channel ("PointToPoint Channel"), - m_bps (0xffffffff), + m_bps (DataRate(0xffffffff)), m_delay (Seconds(0)), m_nDevices(0) { @@ -48,12 +48,12 @@ PointToPointChannel::PointToPointChannel( const Time& delay) : Channel ("PointToPoint Channel"), - m_bps (bps), + m_bps (bps), m_delay (delay), m_nDevices(0) { NS_DEBUG("PointToPointChannel::PointToPointChannel (" << Channel::GetName() - << ", " << bps << ", " << delay << ")"); + << ", " << bps.GetBitRate() << ", " << delay << ")"); } PointToPointChannel::PointToPointChannel( @@ -67,7 +67,7 @@ PointToPointChannel::PointToPointChannel( m_nDevices(0) { NS_DEBUG("PointToPointChannel::PointToPointChannel (" << name << ", " << - bps << ", " << delay << ")"); + bps.GetBitRate() << ", " << delay << ")"); } void @@ -128,14 +128,12 @@ PointToPointChannel::Propagate(Packet& p, PointToPointPhy* src) m_link[wire].m_state = TRANSMITTING; -// -// I believe Raj has a method in the DataRate class to do this. Should use -// it when it is available. -// - Time tEvent = Seconds (static_cast (p.GetSize() * 8) / - static_cast (m_bps)) + m_delay; + Time txTime = Seconds (m_bps.CalculateTxTime(p.GetSize())); + Time tEvent = txTime + m_delay; - NS_DEBUG("PointToPointChannel::DoSend (): Schedule Receive delay " << tEvent); + NS_DEBUG("PointToPointChannel::DoSend (): Schedule bps " << + m_bps.GetBitRate() << " txTime " << m_bps.CalculateTxTime(p.GetSize()) << + " prop delay " << m_delay << " Recv. delay " << tEvent); Simulator::Schedule (tEvent, &PointToPointChannel::TransmitCompleteEvent, this, p, src); diff --git a/src/devices/p2p/p2p-channel.h b/src/devices/p2p/p2p-channel.h index 43cac9807..445fa61e4 100644 --- a/src/devices/p2p/p2p-channel.h +++ b/src/devices/p2p/p2p-channel.h @@ -23,11 +23,10 @@ #include "ns3/channel.h" #include "ns3/packet.h" #include "ns3/nstime.h" +#include "ns3/data-rate.h" namespace ns3 { -// temporary until Raj's code makes it into the dev tree -typedef uint64_t DataRate; class PointToPointPhy; class NetDevice; diff --git a/src/devices/p2p/p2p-topology.cc b/src/devices/p2p/p2p-topology.cc index 440c67546..0ca2dd5b8 100644 --- a/src/devices/p2p/p2p-topology.cc +++ b/src/devices/p2p/p2p-topology.cc @@ -47,7 +47,7 @@ PointToPointTopology::AddPointToPointLink( const Ipv4Address& addra, Node* b, const Ipv4Address& addrb, - uint64_t bps, + const DataRate& bps, const Time& delay) { PointToPointChannel* channel = new PointToPointChannel(bps, delay); diff --git a/src/devices/p2p/p2p-topology.h b/src/devices/p2p/p2p-topology.h index e6f47f70e..d5e7b1f4e 100644 --- a/src/devices/p2p/p2p-topology.h +++ b/src/devices/p2p/p2p-topology.h @@ -31,9 +31,9 @@ namespace ns3 { class PointToPointChannel; class Node; class IPAddr; +class DataRate; //class PointToPointNetDevice; //class Queue; -//class Rate; //class Time; class PointToPointTopology { @@ -46,8 +46,7 @@ public: static PointToPointChannel* AddPointToPointLink( Node*, const Ipv4Address&, Node*, const Ipv4Address&, - // const Rate&, - uint64_t, + const DataRate&, const Time&); // Get the connecting node n1 to node n2