From 07cff2c920c871233e983e30a17166f6465a90ae Mon Sep 17 00:00:00 2001 From: Tim Schubert Date: Sun, 21 Jun 2020 13:01:32 +0200 Subject: [PATCH] fixup: multiple devices per channel --- examples/isl-example.cc | 30 ++++++++++++++++-------------- helper/leo-helper.cc | 1 - helper/leo-helper.h | 1 - model/isl-channel.cc | 3 ++- model/isl-net-device.cc | 26 ++++++++------------------ model/isl-net-device.h | 6 +++--- 6 files changed, 29 insertions(+), 38 deletions(-) diff --git a/examples/isl-example.cc b/examples/isl-example.cc index 76f70f9..f550b33 100644 --- a/examples/isl-example.cc +++ b/examples/isl-example.cc @@ -21,11 +21,10 @@ main (int argc, char *argv[]) Time::SetResolution (Time::NS); LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO); LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO); - LogComponentEnable ("UdpClient", LOG_LEVEL_DEBUG); - LogComponentEnable ("IslChannel", LOG_LEVEL_LOGIC); + LogComponentEnable ("UdpClient", LOG_LEVEL_INFO); NodeContainer nodes; - nodes.Create (2); + nodes.Create (300); IslHelper isl; isl.SetDeviceAttribute ("DataRate", StringValue ("5Gbps")); @@ -45,19 +44,22 @@ main (int argc, char *argv[]) UdpEchoServerHelper echoServer (9); - ApplicationContainer serverApps = echoServer.Install (nodes.Get (1)); - serverApps.Start (Seconds (1.0)); - serverApps.Stop (Seconds (10.0)); + for (uint32_t i = 1; i < nodes.GetN (); i++) + { + ApplicationContainer serverApps = echoServer.Install (nodes.Get (i)); + serverApps.Start (Seconds (1.0)); + serverApps.Stop (Seconds (10.0)); - Address destAddress = interfaces.GetAddress (1, 0); - UdpEchoClientHelper echoClient (destAddress, 9); - echoClient.SetAttribute ("MaxPackets", UintegerValue (10)); - echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0))); - echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); + Address destAddress = interfaces.GetAddress (i, 0); + UdpEchoClientHelper echoClient (destAddress, 9); + echoClient.SetAttribute ("MaxPackets", UintegerValue (10)); + echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0))); + echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); - ApplicationContainer clientApps = echoClient.Install (nodes.Get (0)); - clientApps.Start (Seconds (2.0)); - clientApps.Stop (Seconds (10.0)); + ApplicationContainer clientApps = echoClient.Install (nodes.Get (0)); + clientApps.Start (Seconds (2.0)); + clientApps.Stop (Seconds (10.0)); + } Simulator::Run (); Simulator::Destroy (); diff --git a/helper/leo-helper.cc b/helper/leo-helper.cc index e8bf307..2a67f76 100644 --- a/helper/leo-helper.cc +++ b/helper/leo-helper.cc @@ -8,4 +8,3 @@ namespace ns3 { } - diff --git a/helper/leo-helper.h b/helper/leo-helper.h index c2cfe88..f07787b 100644 --- a/helper/leo-helper.h +++ b/helper/leo-helper.h @@ -11,4 +11,3 @@ namespace ns3 { } #endif /* LEO_HELPER_H */ - diff --git a/model/isl-channel.cc b/model/isl-channel.cc index 71ceb6b..6708e0b 100644 --- a/model/isl-channel.cc +++ b/model/isl-channel.cc @@ -127,7 +127,8 @@ bool IslChannel::Deliver ( delay, &IslNetDevice::Receive, dst, - p->Copy ()); + p->Copy (), + src); // Call the tx anim callback on the net device m_txrxIsl (p, src, dst, txTime, delay); diff --git a/model/isl-net-device.cc b/model/isl-net-device.cc index 00399e9..e8bf87d 100644 --- a/model/isl-net-device.cc +++ b/model/isl-net-device.cc @@ -368,7 +368,7 @@ IslNetDevice::SetReceiveErrorModel (Ptr em) } void -IslNetDevice::Receive (Ptr packet) +IslNetDevice::Receive (Ptr packet, Ptr senderDevice) { NS_LOG_FUNCTION (this << packet); uint16_t protocol = 0; @@ -406,14 +406,15 @@ IslNetDevice::Receive (Ptr packet) // ProcessHeader (packet, protocol); + Address remote = GetRemote (senderDevice); if (!m_promiscCallback.IsNull ()) { m_macPromiscRxTrace (originalPacket); - m_promiscCallback (this, packet, protocol, GetRemote (), GetAddress (), NetDevice::PACKET_HOST); + m_promiscCallback (this, packet, protocol, remote, GetAddress (), NetDevice::PACKET_HOST); } m_macRxTrace (originalPacket); - m_rxCallback (this, packet, protocol, GetRemote ()); + m_rxCallback (this, packet, protocol, remote); } } @@ -653,28 +654,17 @@ IslNetDevice::SupportsSendFrom (void) const } void -IslNetDevice::DoMpiReceive (Ptr p) +IslNetDevice::DoMpiReceive (Ptr p, Ptr senderDevice) { NS_LOG_FUNCTION (this << p); - Receive (p); + Receive (p, senderDevice); } Address -IslNetDevice::GetRemote (void) const +IslNetDevice::GetRemote (Ptr senderDevice) const { NS_LOG_FUNCTION (this); - NS_ASSERT (m_channel->GetNDevices () == 2); - for (std::size_t i = 0; i < m_channel->GetNDevices (); ++i) - { - Ptr tmp = m_channel->GetDevice (i); - if (tmp != this) - { - return tmp->GetAddress (); - } - } - NS_ASSERT (false); - // quiet compiler. - return Address (); + return senderDevice->GetAddress (); } bool diff --git a/model/isl-net-device.h b/model/isl-net-device.h index a87619f..01289f1 100644 --- a/model/isl-net-device.h +++ b/model/isl-net-device.h @@ -150,7 +150,7 @@ public: * * \param p Ptr to the received packet. */ - void Receive (Ptr p); + void Receive (Ptr p, Ptr senderDevice); // The remaining methods are documented in ns3::NetDevice* @@ -205,7 +205,7 @@ protected: * * \param p Packet received */ - void DoMpiReceive (Ptr p); + void DoMpiReceive (Ptr p, Ptr sender); virtual void DoInitialize (void); virtual void NotifyNewAggregate (void); @@ -242,7 +242,7 @@ private: * \returns the address of the remote device connected to this device * through the point to point channel. */ - Address GetRemote (void) const; + Address GetRemote (Ptr senderDevice) const; /** * Adds the necessary headers and trailers to a packet of data in order to