Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 43 additions & 11 deletions src/point-to-point/model/point-to-point-channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ PointToPointChannel::GetTypeId (void)
.SetParent<Channel> ()
.SetGroupName ("PointToPoint")
.AddConstructor<PointToPointChannel> ()
.AddAttribute ("Delay", "Transmission delay through the channel",
.AddAttribute ("AlternateDelay",
"Transmission delay through the channel in the other direction: has to be set after Delay",
TimeValue (Seconds (42)),
MakeTimeAccessor (&PointToPointChannel::m_alternateDelay),
MakeTimeChecker ())
.AddAttribute ("Delay", "Transmission delay through the channel in one direction",
TimeValue (Seconds (0)),
MakeTimeAccessor (&PointToPointChannel::m_delay),
MakeTimeAccessor ( (Time (PointToPointChannel::*)() const)&PointToPointChannel::GetDelay, &PointToPointChannel::SetDelay),
MakeTimeChecker ())
.AddTraceSource ("TxRxPointToPoint",
"Trace source indicating transmission of packet "
Expand All @@ -57,6 +62,7 @@ PointToPointChannel::PointToPointChannel()
:
Channel (),
m_delay (Seconds (0.)),
m_alternateDelay (Seconds (0.)),
m_nDevices (0)
{
NS_LOG_FUNCTION_NOARGS ();
Expand All @@ -80,6 +86,8 @@ PointToPointChannel::Attach (Ptr<PointToPointNetDevice> device)
m_link[1].m_dst = m_link[0].m_src;
m_link[0].m_state = IDLE;
m_link[1].m_state = IDLE;
m_link[0].m_delay = m_delay;
m_link[1].m_delay = m_alternateDelay;
}
}

Expand All @@ -97,12 +105,13 @@ PointToPointChannel::TransmitStart (

uint32_t wire = src == m_link[0].m_src ? 0 : 1;

Simulator::ScheduleWithContext (m_link[wire].m_dst->GetNode ()->GetId (),
txTime + m_delay, &PointToPointNetDevice::Receive,
m_link[wire].m_dst, p);
Simulator::ScheduleWithContext (GetDestination(wire)->GetNode ()->GetId (),
txTime + GetDelay(wire),
&PointToPointNetDevice::Receive,
GetDestination(wire), p);

// Call the tx anim callback on the net device
m_txrxPointToPoint (p, src, m_link[wire].m_dst, txTime, txTime + m_delay);
m_txrxPointToPoint (p, src, GetDestination(wire), txTime, txTime + GetDelay(wire));
return true;
}

Expand All @@ -125,33 +134,56 @@ Ptr<NetDevice>
PointToPointChannel::GetDevice (uint32_t i) const
{
NS_LOG_FUNCTION_NOARGS ();
NS_ASSERT (i < 2);
return GetPointToPointDevice (i);
}

Time
PointToPointChannel::GetDelay (void) const
PointToPointChannel::GetDelay () const
{
return GetDelay(0);
}


Time
PointToPointChannel::GetDelay (uint32_t i) const
{
return m_delay;
NS_ASSERT (i < 2);
return m_link[i].m_delay;
}

void
PointToPointChannel::SetDelay (Time owd)
{
NS_ASSERT(!IsInitialized());
m_delay = owd;

/* if m_alternateDelay set to its default value than we update it */
struct TypeId::AttributeInformation info;
if(GetTypeId().LookupAttributeByName("AlternateDelay", &info) && info.originalInitialValue == info.initialValue) {
m_alternateDelay = owd;
}

}

Ptr<PointToPointNetDevice>
PointToPointChannel::GetSource (uint32_t i) const
{
NS_ASSERT (i < 2);
return m_link[i].m_src;
}

Ptr<PointToPointNetDevice>
PointToPointChannel::GetDestination (uint32_t i) const
{
NS_ASSERT (i < 2);
return m_link[i].m_dst;
}

bool
PointToPointChannel::IsInitialized (void) const
{
NS_ASSERT (m_link[0].m_state != INITIALIZING);
NS_ASSERT (m_link[1].m_state != INITIALIZING);
return true;
return (m_link[0].m_state != INITIALIZING && m_link[1].m_state != INITIALIZING);
}

} // namespace ns3
28 changes: 19 additions & 9 deletions src/point-to-point/model/point-to-point-channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,22 @@ class PointToPointChannel : public Channel
*/
virtual Ptr<NetDevice> GetDevice (uint32_t i) const;

protected:
/**
* \brief Get the delay associated with this channel
* \param i Between 0 and 1: select the link
* \returns Time delay
*/
Time GetDelay (void) const;
Time GetDelay (uint32_t i) const;

/**
* Must be called before link initialization
* \param t duration of packet transfer in both directions
*/
void SetDelay (Time t) ;

protected:


/**
* \brief Check to make sure the link is initialized
Expand Down Expand Up @@ -137,19 +147,18 @@ class PointToPointChannel : public Channel
* \param [in] rxDevice the Receiving NetDevice.
* \param [in] duration The amount of time to transmit the packet.
* \param [in] lastBitTime Last bit receive time (relative to now)
* \deprecated The non-const \c Ptr<NetDevice> argument is deprecated
* and will be changed to \c Ptr<const NetDevice> in a future release.
*/
typedef void (* TxRxAnimationCallback)
(Ptr<const Packet> packet,
Ptr<NetDevice> txDevice, Ptr<NetDevice> rxDevice,
Time duration, Time lastBitTime);
(const Ptr<const Packet> packet,
const Ptr<const NetDevice> txDevice, const Ptr<const NetDevice> rxDevice,
const Time duration, const Time lastBitTime);

private:
/** Each point to point link has exactly two net devices. */
static const int N_DEVICES = 2;

Time m_delay; //!< Propagation delay
Time m_delay; //!< Propagation delay
Time m_alternateDelay; //!< Propagation delay
int32_t m_nDevices; //!< Devices of this channel

/**
Expand Down Expand Up @@ -194,11 +203,12 @@ class PointToPointChannel : public Channel
/** \brief Create the link, it will be in INITIALIZING state
*
*/
Link() : m_state (INITIALIZING), m_src (0), m_dst (0) {}
Link() : m_state (INITIALIZING), m_src (0), m_dst (0), m_delay(0) {}

WireState m_state; //!< State of the link
Ptr<PointToPointNetDevice> m_src; //!< First NetDevice
Ptr<PointToPointNetDevice> m_dst; //!< Second NetDevice
Time m_delay; //!< Propagation delay
};

Link m_link[N_DEVICES]; //!< Link model
Expand Down
85 changes: 67 additions & 18 deletions src/point-to-point/test/point-to-point-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

using namespace ns3;

static const Time testStartTime = Seconds (1.0);
static const Time tolerance = MilliSeconds(5);

/**
* \brief Test class for PointToPoint model
*
Expand All @@ -38,24 +41,38 @@ class PointToPointTest : public TestCase
/**
* \brief Create the test
*/
PointToPointTest ();
PointToPointTest (Time forwardDelay, Time backwardDelay);

/**
* \brief Run the test
*/
virtual void DoRun (void);

private:


protected:

Time m_forwardDelay;
Time m_backwardDelay;

Time m_packetArrival[2];

Ptr<PointToPointNetDevice> m_devA;
Ptr<PointToPointNetDevice> m_devB;

/**
* \brief Send one packet to the device specified
*
* \param device NetDevice to send to
*/
void SendOnePacket (Ptr<PointToPointNetDevice> device);
bool RecvOnePacket ( Ptr<NetDevice> dev, Ptr<const Packet> p, uint16_t protocol, const Address & sender);
};

PointToPointTest::PointToPointTest ()
: TestCase ("PointToPoint")
PointToPointTest::PointToPointTest (Time forwardDelay, Time backwardDelay)
: TestCase ("PointToPoint"),
m_forwardDelay(forwardDelay),
m_backwardDelay(backwardDelay)
{
}

Expand All @@ -66,31 +83,63 @@ PointToPointTest::SendOnePacket (Ptr<PointToPointNetDevice> device)
device->Send (p, device->GetBroadcast (), 0x800);
}

bool
PointToPointTest::RecvOnePacket ( Ptr<NetDevice> dev, Ptr<const Packet> p, uint16_t protocol, const Address & sender)
{
// if(dev == this->de)
static int counter=0;
m_packetArrival[counter] = Simulator::Now();

if(counter==0) {
Simulator::ScheduleNow( &PointToPointTest::SendOnePacket, this, m_devB);
}

counter++;
return true;
}

void
PointToPointTest::DoRun (void)
{
Ptr<Node> a = CreateObject<Node> ();
Ptr<Node> b = CreateObject<Node> ();
Ptr<PointToPointNetDevice> devA = CreateObject<PointToPointNetDevice> ();
Ptr<PointToPointNetDevice> devB = CreateObject<PointToPointNetDevice> ();
Ptr<Node> nodeA = CreateObject<Node> ();
Ptr<Node> nodeB = CreateObject<Node> ();
m_devA = CreateObject<PointToPointNetDevice> ();
m_devB = CreateObject<PointToPointNetDevice> ();
Ptr<PointToPointChannel> channel = CreateObject<PointToPointChannel> ();
channel->SetAttribute("Delay", TimeValue(m_forwardDelay));
channel->SetAttribute("AlternateDelay", TimeValue(m_backwardDelay));

m_devA->Attach (channel);
m_devA->SetAddress (Mac48Address::Allocate ());
m_devA->SetQueue (CreateObject<DropTailQueue> ());
m_devB->Attach (channel);
m_devB->SetAddress (Mac48Address::Allocate ());
m_devB->SetQueue (CreateObject<DropTailQueue> ());

devA->Attach (channel);
devA->SetAddress (Mac48Address::Allocate ());
devA->SetQueue (CreateObject<DropTailQueue> ());
devB->Attach (channel);
devB->SetAddress (Mac48Address::Allocate ());
devB->SetQueue (CreateObject<DropTailQueue> ());

a->AddDevice (devA);
b->AddDevice (devB);
nodeA->AddDevice (m_devA);
nodeB->AddDevice (m_devB);

Simulator::Schedule (Seconds (1.0), &PointToPointTest::SendOnePacket, this, devA);
m_devA->SetReceiveCallback( MakeCallback(&PointToPointTest::RecvOnePacket, this) );
m_devB->SetReceiveCallback( MakeCallback(&PointToPointTest::RecvOnePacket, this) );

Simulator::Schedule (testStartTime, &PointToPointTest::SendOnePacket, this, m_devA);

// NS_TEST_ASSERT_MSG_EQ(true, false, "toto");
Simulator::Run ();

Simulator::Destroy ();

std::cout << "1st packet arrival=" << m_packetArrival[0].As(Time::MS)
<< " (=" << (testStartTime + m_forwardDelay).As(Time::MS) << " ?)"
<< std::endl;
std::cout << "2nd packet arrival=" << m_packetArrival[1].As(Time::MS)
<< " to compare with :" << testStartTime + m_forwardDelay + m_backwardDelay
<< std::endl;

NS_TEST_ASSERT_MSG_EQ_TOL( m_packetArrival[0], testStartTime + m_forwardDelay, tolerance, "Forward delay out of bounds");
NS_TEST_ASSERT_MSG_EQ_TOL( m_packetArrival[1], testStartTime + m_forwardDelay + m_backwardDelay, tolerance, "Backward delay out of bounds");

}

/**
Expand All @@ -108,7 +157,7 @@ class PointToPointTestSuite : public TestSuite
PointToPointTestSuite::PointToPointTestSuite ()
: TestSuite ("devices-point-to-point", UNIT)
{
AddTestCase (new PointToPointTest, TestCase::QUICK);
AddTestCase (new PointToPointTest(MilliSeconds(50), MilliSeconds(150)), TestCase::QUICK);
}

static PointToPointTestSuite g_pointToPointTestSuite; //!< The testsuite
3 changes: 1 addition & 2 deletions src/test/ns3tcp/ns3tcp-no-delay-test-suite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,12 @@ Ns3TcpNoDelayTestCase::DoRun (void)
if (m_noDelay)
{
oss << "tcp-no-delay-on-test-case";
pointToPoint.EnablePcapAll (oss.str ());
}
else
{
oss << "tcp-no-delay-off-test-case";
pointToPoint.EnablePcapAll (oss.str ());
}
pointToPoint.EnablePcapAll (oss.str ());
}

Simulator::Stop (simStopTimeObj);
Expand Down