Move simple-p2p.cc to DataRate; fix small bug in DataRate and add include guards

Tom Henderson 2007-03-25 15:33:24 -07:00
parent 8a2cff0607
commit fd92794e43
7 changed files with 22 additions and 20 deletions

View File

@ -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

View File

@ -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<double>(bytes)*8/m_bps;
}
uint64_t DataRate::GetBitRate() const

View File

@ -19,6 +19,9 @@
// Author: Rajib Bhattacharjea<raj.b@gatech.edu>
//
#ifndef DATA_RATE_H
#define DATA_RATE_H
#include "ns3/fatal-error.h"
#include <string>
#include <iostream>
@ -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 */

View File

@ -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<double> (p.GetSize() * 8) /
static_cast<double> (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);

View File

@ -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;

View File

@ -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);

View File

@ -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