From 922d5a4de9176c59b07f904c6fd53d56e113906f Mon Sep 17 00:00:00 2001 From: "Kirill V. Andreev" Date: Thu, 23 Oct 2008 21:27:28 +0200 Subject: [PATCH 01/13] bug 389: Beacon is sent after DIFS+Backoff instead of PIFS --- src/devices/wifi/nqap-wifi-mac.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/devices/wifi/nqap-wifi-mac.cc b/src/devices/wifi/nqap-wifi-mac.cc index 8d4f61c4c..f5f6c5016 100644 --- a/src/devices/wifi/nqap-wifi-mac.cc +++ b/src/devices/wifi/nqap-wifi-mac.cc @@ -76,6 +76,9 @@ NqapWifiMac::NqapWifiMac () m_dca->SetTxFailedCallback (MakeCallback (&NqapWifiMac::TxFailed, this)); m_beaconDca = CreateObject (); + m_beaconDca->SetAifsn(1); + m_beaconDca->SetMinCw(0); + m_beaconDca->SetMaxCw(0); m_beaconDca->SetLow (m_low); m_beaconDca->SetManager (m_dcfManager); } From b4947df5d0a753d8a18cb2ae6da4423e35dbe283 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Thu, 23 Oct 2008 15:59:48 -0700 Subject: [PATCH 02/13] Liu's GetSockName patch --- src/internet-stack/nsc-tcp-socket-impl.cc | 10 +++++++++ src/internet-stack/nsc-tcp-socket-impl.h | 1 + src/internet-stack/tcp-socket-impl.cc | 10 +++++++++ src/internet-stack/tcp-socket-impl.h | 1 + src/internet-stack/udp-socket-impl.cc | 15 ++++++++++++++ src/internet-stack/udp-socket-impl.h | 1 + src/node/packet-socket.cc | 25 +++++++++++++++++++++++ src/node/packet-socket.h | 1 + src/node/socket.h | 4 ++++ 9 files changed, 68 insertions(+) diff --git a/src/internet-stack/nsc-tcp-socket-impl.cc b/src/internet-stack/nsc-tcp-socket-impl.cc index e3020d630..3e76d66c8 100644 --- a/src/internet-stack/nsc-tcp-socket-impl.cc +++ b/src/internet-stack/nsc-tcp-socket-impl.cc @@ -64,6 +64,8 @@ NscTcpSocketImpl::GetTypeId () : m_endPoint (0), m_node (0), m_tcp (0), + m_localAddress (Ipv4Address::GetZero ()), + m_localPort (0), m_peerAddress ("0.0.0.0", 0), m_errno (ERROR_NOTERROR), m_shutdownSend (false), @@ -466,6 +468,14 @@ NscTcpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags, return packet; } +int +NscTcpSocketImpl::GetSockName (Address &address) const +{ + NS_LOG_FUNCTION_NOARGS (); + address = InetSocketAddress(m_localAddress, m_localPort); + return 0; +} + uint32_t NscTcpSocketImpl::GetRxAvailable (void) const { diff --git a/src/internet-stack/nsc-tcp-socket-impl.h b/src/internet-stack/nsc-tcp-socket-impl.h index cc0c8e684..fa142615c 100644 --- a/src/internet-stack/nsc-tcp-socket-impl.h +++ b/src/internet-stack/nsc-tcp-socket-impl.h @@ -81,6 +81,7 @@ public: virtual Ptr Recv (uint32_t maxSize, uint32_t flags); virtual Ptr RecvFrom (uint32_t maxSize, uint32_t flags, Address &fromAddress); + virtual int GetSockName (Address &address) const; private: void NSCWakeup(void); diff --git a/src/internet-stack/tcp-socket-impl.cc b/src/internet-stack/tcp-socket-impl.cc index 35184ff00..bf058bc3f 100644 --- a/src/internet-stack/tcp-socket-impl.cc +++ b/src/internet-stack/tcp-socket-impl.cc @@ -62,6 +62,8 @@ TcpSocketImpl::GetTypeId () m_endPoint (0), m_node (0), m_tcp (0), + m_localAddress (Ipv4Address::GetZero ()), + m_localPort (0), m_errno (ERROR_NOTERROR), m_shutdownSend (false), m_shutdownRecv (false), @@ -553,6 +555,14 @@ TcpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags, return packet; } +int +TcpSocketImpl::GetSockName (Address &address) const +{ + NS_LOG_FUNCTION_NOARGS (); + address = InetSocketAddress(m_localAddress, m_localPort); + return 0; +} + void TcpSocketImpl::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) { diff --git a/src/internet-stack/tcp-socket-impl.h b/src/internet-stack/tcp-socket-impl.h index 8298cc84a..81d75fce6 100644 --- a/src/internet-stack/tcp-socket-impl.h +++ b/src/internet-stack/tcp-socket-impl.h @@ -94,6 +94,7 @@ public: virtual Ptr Recv (uint32_t maxSize, uint32_t flags); virtual Ptr RecvFrom (uint32_t maxSize, uint32_t flags, Address &fromAddress); + virtual int GetSockName (Address &address) const; private: friend class Tcp; diff --git a/src/internet-stack/udp-socket-impl.cc b/src/internet-stack/udp-socket-impl.cc index c0fb33256..3feb6b3f5 100644 --- a/src/internet-stack/udp-socket-impl.cc +++ b/src/internet-stack/udp-socket-impl.cc @@ -437,6 +437,21 @@ UdpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags, return packet; } +int +UdpSocketImpl::GetSockName (Address &address) const +{ + NS_LOG_FUNCTION_NOARGS (); + if (m_endPoint != 0) + { + address = InetSocketAddress (m_endPoint->GetLocalAddress (), m_endPoint->GetLocalPort()); + } + else + { + address = InetSocketAddress(Ipv4Address::GetZero(), 0); + } + return 0; +} + void UdpSocketImpl::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) { diff --git a/src/internet-stack/udp-socket-impl.h b/src/internet-stack/udp-socket-impl.h index 0a20a384f..03fae2e56 100644 --- a/src/internet-stack/udp-socket-impl.h +++ b/src/internet-stack/udp-socket-impl.h @@ -73,6 +73,7 @@ public: virtual Ptr Recv (uint32_t maxSize, uint32_t flags); virtual Ptr RecvFrom (uint32_t maxSize, uint32_t flags, Address &fromAddress); + virtual int GetSockName (Address &address) const; private: // Attributes set through UdpSocket base class diff --git a/src/node/packet-socket.cc b/src/node/packet-socket.cc index 43b23be38..6aef802e6 100644 --- a/src/node/packet-socket.cc +++ b/src/node/packet-socket.cc @@ -57,6 +57,8 @@ PacketSocket::PacketSocket () : m_rxAvailable (0) m_shutdownSend = false; m_shutdownRecv = false; m_errno = ERROR_NOTERROR; + m_isSingleDevice = false; + m_device = 0; } void @@ -429,4 +431,27 @@ PacketSocket::RecvFrom (uint32_t maxSize, uint32_t flags, Address &fromAddress) return packet; } +int +PacketSocket::GetSockName (Address &address) const +{ + NS_LOG_FUNCTION_NOARGS (); + PacketSocketAddress ad = PacketSocketAddress::ConvertFrom(address); + + ad.SetProtocol (m_protocol); + if (m_isSingleDevice) + { + Ptr device = m_node->GetDevice (ad.GetSingleDevice ()); + ad.SetPhysicalAddress(device->GetAddress()); + ad.SetSingleDevice (m_device); + } + else + { + ad.SetPhysicalAddress(Address()); + ad.SetAllDevices (); + } + address = ad; + + return 0; +} + }//namespace ns3 diff --git a/src/node/packet-socket.h b/src/node/packet-socket.h index a0db81040..3835a7132 100644 --- a/src/node/packet-socket.h +++ b/src/node/packet-socket.h @@ -101,6 +101,7 @@ public: virtual Ptr Recv (uint32_t maxSize, uint32_t flags); virtual Ptr RecvFrom (uint32_t maxSize, uint32_t flags, Address &fromAddress); + virtual int GetSockName (Address &address) const; private: void ForwardUp (Ptr device, Ptr packet, diff --git a/src/node/socket.h b/src/node/socket.h index 1c4a20ddf..6287895a4 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -487,6 +487,10 @@ public: */ int RecvFrom (uint8_t* buf, uint32_t size, uint32_t flags, Address &fromAddress); + /** + * \returns the address name this socket is associated with. + */ + virtual int GetSockName (Address &address) const = 0; protected: void NotifyConnectionSucceeded (void); From 6041ad024c779513ab634bdc6daa09a02b787a97 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Thu, 23 Oct 2008 16:08:13 -0700 Subject: [PATCH 03/13] rescan for bug 283 --- bindings/python/ns3_module_node.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bindings/python/ns3_module_node.py b/bindings/python/ns3_module_node.py index 236787028..ca8fb12b0 100644 --- a/bindings/python/ns3_module_node.py +++ b/bindings/python/ns3_module_node.py @@ -1356,6 +1356,11 @@ def register_Ns3Socket_methods(root_module, cls): cls.add_method('RecvFrom', 'int', [param('uint8_t *', 'buf'), param('uint32_t', 'size'), param('uint32_t', 'flags'), param('ns3::Address &', 'fromAddress')]) + ## socket.h: int ns3::Socket::GetSockName(ns3::Address & address) const [member function] + cls.add_method('GetSockName', + 'int', + [param('ns3::Address &', 'address')], + is_pure_virtual=True, is_const=True, is_virtual=True) ## socket.h: void ns3::Socket::NotifyConnectionSucceeded() [member function] cls.add_method('NotifyConnectionSucceeded', 'void', From 26aa64c03347816c52c6f92bfa4f5c98556f4708 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 24 Oct 2008 09:22:50 +0200 Subject: [PATCH 04/13] bug 386: make sure errno is not set incorrectly and don't access stale packets. --- src/internet-stack/nsc-tcp-socket-impl.cc | 36 ++++++----------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/src/internet-stack/nsc-tcp-socket-impl.cc b/src/internet-stack/nsc-tcp-socket-impl.cc index 3e76d66c8..cbb4d777a 100644 --- a/src/internet-stack/nsc-tcp-socket-impl.cc +++ b/src/internet-stack/nsc-tcp-socket-impl.cc @@ -330,34 +330,19 @@ NscTcpSocketImpl::Send (const Ptr p, uint32_t flags) return -1; } - bool txEmpty = m_txBuffer.empty(); + uint32_t sent = p->GetSize (); if (m_state == ESTABLISHED) { - if (txEmpty) - { - m_txBuffer.push(p); - m_txBufferSize += p->GetSize (); - } - if (!SendPendingData()) - { - if (m_errno == ERROR_AGAIN) - { - return txEmpty ? p->GetSize () : -1; - } - if (txEmpty) - { - m_txBuffer.pop (); - m_txBufferSize = 0; - } - return -1; - } + m_txBuffer.push(p); + m_txBufferSize += sent; + SendPendingData(); } else { // SYN_SET -- Queue Data m_txBuffer.push(p); - m_txBufferSize += p->GetSize (); + m_txBufferSize += sent; } - return p->GetSize (); + return sent; } else { @@ -436,6 +421,7 @@ NscTcpSocketImpl::Recv (uint32_t maxSize, uint32_t flags) NS_LOG_FUNCTION_NOARGS (); if (m_deliveryQueue.empty() ) { + m_errno = ERROR_AGAIN; return 0; } Ptr p = m_deliveryQueue.front (); @@ -446,6 +432,7 @@ NscTcpSocketImpl::Recv (uint32_t maxSize, uint32_t flags) } else { + m_errno = ERROR_AGAIN; p = 0; } return p; @@ -637,6 +624,7 @@ bool NscTcpSocketImpl::SendPendingData (void) size_t size, written = 0; do { + NS_ASSERT (!m_txBuffer.empty ()); Ptr &p = m_txBuffer.front (); size = p->GetSize (); NS_ASSERT (size > 0); @@ -645,12 +633,6 @@ bool NscTcpSocketImpl::SendPendingData (void) ret = m_nscTcpSocket->send_data((const char *)p->PeekData (), size); if (ret <= 0) { - m_errno = GetNativeNs3Errno(ret); - if (m_errno != ERROR_AGAIN) - { - NS_LOG_WARN ("Error (" << ret << ") " << - "during send_data, ns-3 errno set to" << m_errno); - } break; } written += ret; From 3af636f969fc1ff00f604f6764d66d6418cfeb0e Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 24 Oct 2008 10:29:06 +0200 Subject: [PATCH 05/13] bug 339: unconditional assert API. --- src/core/abort.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ src/core/wscript | 3 ++- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/core/abort.h diff --git a/src/core/abort.h b/src/core/abort.h new file mode 100644 index 000000000..306058df3 --- /dev/null +++ b/src/core/abort.h @@ -0,0 +1,54 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2008 INRIA + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +#ifndef NS3_ABORT_H +#define NS3_ABORT_H + +#include "fatal-error.h" + +#define NS_ABORT_IF(cond) \ + do { \ + if (cond) \ + { \ + std::cerr << "file=" << __FILE__ << \ + ", line=" << __LINE__ << ", abort on=\""#cond << \ + "\"" << std::endl; \ + int *a = 0; \ + *a = 0; \ + } \ + } while (false) + +#define NS_ABORT_MSG_IF(cond, msg) \ + do { \ + if (cond) \ + { \ + std::cerr << "file=" << __FILE__ << \ + ", line=" << __LINE__ << ", abort on=\""#cond << \ + "\", msg=\"" << msg << "\"" << std::endl; \ + int *a = 0; \ + *a = 0; \ + } \ + } while (false) + +#define NS_ABORT_UNLESS(cond) \ + NS_ABORT_IF(!(cond)) + +#define NS_ABORT_MSG_UNLESS(cond, msg) \ + NS_ABORT_MSG_IF(!(cond),msg) + +#endif /* NS3_ABORT_H */ diff --git a/src/core/wscript b/src/core/wscript index de13762a6..586b0ee95 100644 --- a/src/core/wscript +++ b/src/core/wscript @@ -116,7 +116,8 @@ def build(bld): 'trace-source-accessor.h', 'config.h', 'object-vector.h', - 'deprecated.h' + 'deprecated.h', + 'abort.h', ] if sys.platform == 'win32': From 4d380ed25736b68f5e749132d65062a9df9e6f41 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 24 Oct 2008 12:27:47 +0200 Subject: [PATCH 06/13] rework StaticSpeedHelper API --- .../random-direction-2d-mobility-model.cc | 17 ++++-- src/mobility/random-walk-2d-mobility-model.cc | 15 +++-- .../random-waypoint-mobility-model.cc | 11 ++-- src/mobility/static-speed-helper.cc | 57 ++++++------------- src/mobility/static-speed-helper.h | 14 ++--- src/mobility/static-speed-mobility-model.cc | 9 ++- src/mobility/static-speed-mobility-model.h | 2 +- 7 files changed, 58 insertions(+), 67 deletions(-) diff --git a/src/mobility/random-direction-2d-mobility-model.cc b/src/mobility/random-direction-2d-mobility-model.cc index 3ae572073..221118cf7 100644 --- a/src/mobility/random-direction-2d-mobility-model.cc +++ b/src/mobility/random-direction-2d-mobility-model.cc @@ -76,8 +76,9 @@ RandomDirection2dMobilityModel::Start (void) void RandomDirection2dMobilityModel::BeginPause (void) { - Time pause = Seconds (m_pause.GetValue ()); + m_helper.Update (); m_helper.Pause (); + Time pause = Seconds (m_pause.GetValue ()); m_event = Simulator::Schedule (pause, &RandomDirection2dMobilityModel::ResetDirectionAndSpeed, this); NotifyCourseChange (); } @@ -86,12 +87,14 @@ void RandomDirection2dMobilityModel::SetDirectionAndSpeed (double direction) { NS_LOG_FUNCTION_NOARGS (); + m_helper.UpdateWithBounds (m_bounds); + Vector position = m_helper.GetCurrentPosition (); double speed = m_speed.GetValue (); const Vector vector (std::cos (direction) * speed, std::sin (direction) * speed, 0.0); - Vector position = m_helper.GetCurrentPosition (m_bounds); - m_helper.Reset (vector); + m_helper.SetVelocity (vector); + m_helper.Unpause (); Vector next = m_bounds.CalculateIntersection (position, vector); Time delay = Seconds (CalculateDistance (position, next) / speed); m_event = Simulator::Schedule (delay, @@ -103,7 +106,8 @@ RandomDirection2dMobilityModel::ResetDirectionAndSpeed (void) { double direction = UniformVariable::GetSingleValue (0, PI); - Vector position = m_helper.GetCurrentPosition (m_bounds); + m_helper.UpdateWithBounds (m_bounds); + Vector position = m_helper.GetCurrentPosition (); switch (m_bounds.GetClosestSide (position)) { case Rectangle::RIGHT: @@ -124,12 +128,13 @@ RandomDirection2dMobilityModel::ResetDirectionAndSpeed (void) Vector RandomDirection2dMobilityModel::DoGetPosition (void) const { - return m_helper.GetCurrentPosition (m_bounds); + m_helper.UpdateWithBounds (m_bounds); + return m_helper.GetCurrentPosition (); } void RandomDirection2dMobilityModel::DoSetPosition (const Vector &position) { - m_helper.InitializePosition (position); + m_helper.SetPosition (position); Simulator::Remove (m_event); m_event = Simulator::ScheduleNow (&RandomDirection2dMobilityModel::Start, this); } diff --git a/src/mobility/random-walk-2d-mobility-model.cc b/src/mobility/random-walk-2d-mobility-model.cc index 59824a4f1..e426a6575 100644 --- a/src/mobility/random-walk-2d-mobility-model.cc +++ b/src/mobility/random-walk-2d-mobility-model.cc @@ -80,12 +80,14 @@ RandomWalk2dMobilityModel::RandomWalk2dMobilityModel () void RandomWalk2dMobilityModel::Start (void) { + m_helper.Update (); double speed = m_speed.GetValue (); double direction = m_direction.GetValue (); Vector vector (std::cos (direction) * speed, std::sin (direction) * speed, 0.0); - m_helper.Reset (vector); + m_helper.SetVelocity (vector); + m_helper.Unpause (); Time delayLeft; if (m_mode == RandomWalk2dMobilityModel::MODE_TIME) @@ -124,7 +126,8 @@ RandomWalk2dMobilityModel::DoWalk (Time delayLeft) void RandomWalk2dMobilityModel::Rebound (Time delayLeft) { - Vector position = m_helper.GetCurrentPosition (m_bounds); + m_helper.UpdateWithBounds (m_bounds); + Vector position = m_helper.GetCurrentPosition (); Vector speed = m_helper.GetVelocity (); switch (m_bounds.GetClosestSide (position)) { @@ -137,7 +140,8 @@ RandomWalk2dMobilityModel::Rebound (Time delayLeft) speed.y = - speed.y; break; } - m_helper.Reset (speed); + m_helper.SetVelocity (speed); + m_helper.Unpause (); DoWalk (delayLeft); } @@ -150,13 +154,14 @@ RandomWalk2dMobilityModel::DoDispose (void) Vector RandomWalk2dMobilityModel::DoGetPosition (void) const { - return m_helper.GetCurrentPosition (m_bounds); + m_helper.UpdateWithBounds (m_bounds); + return m_helper.GetCurrentPosition (); } void RandomWalk2dMobilityModel::DoSetPosition (const Vector &position) { NS_ASSERT (m_bounds.IsInside (position)); - m_helper.InitializePosition (position); + m_helper.SetPosition (position); Simulator::Remove (m_event); m_event = Simulator::ScheduleNow (&RandomWalk2dMobilityModel::Start, this); } diff --git a/src/mobility/random-waypoint-mobility-model.cc b/src/mobility/random-waypoint-mobility-model.cc index fd29f82e9..a7c6e1537 100644 --- a/src/mobility/random-waypoint-mobility-model.cc +++ b/src/mobility/random-waypoint-mobility-model.cc @@ -62,6 +62,7 @@ RandomWaypointMobilityModel::RandomWaypointMobilityModel () void RandomWaypointMobilityModel::BeginWalk (void) { + m_helper.Update (); Vector m_current = m_helper.GetCurrentPosition (); Vector destination = m_position->GetNext (); double speed = m_speed.GetValue (); @@ -70,7 +71,7 @@ RandomWaypointMobilityModel::BeginWalk (void) double dz = (destination.z - m_current.z); double k = speed / std::sqrt (dx*dx + dy*dy + dz*dz); - m_helper.Reset (Vector (k*dx, k*dy, k*dz)); + m_helper.SetVelocity (Vector (k*dx, k*dy, k*dz)); Time travelDelay = Seconds (CalculateDistance (destination, m_current) / speed); m_event = Simulator::Schedule (travelDelay, &RandomWaypointMobilityModel::Start, this); @@ -80,21 +81,23 @@ RandomWaypointMobilityModel::BeginWalk (void) void RandomWaypointMobilityModel::Start (void) { - Time pause = Seconds (m_pause.GetValue ()); + m_helper.Update (); m_helper.Pause (); - NotifyCourseChange (); + Time pause = Seconds (m_pause.GetValue ()); m_event = Simulator::Schedule (pause, &RandomWaypointMobilityModel::BeginWalk, this); + NotifyCourseChange (); } Vector RandomWaypointMobilityModel::DoGetPosition (void) const { + m_helper.Update (); return m_helper.GetCurrentPosition (); } void RandomWaypointMobilityModel::DoSetPosition (const Vector &position) { - m_helper.InitializePosition (position); + m_helper.SetPosition (position); Simulator::Remove (m_event); Simulator::ScheduleNow (&RandomWaypointMobilityModel::Start, this); } diff --git a/src/mobility/static-speed-helper.cc b/src/mobility/static-speed-helper.cc index d781494f6..0a207b77b 100644 --- a/src/mobility/static-speed-helper.cc +++ b/src/mobility/static-speed-helper.cc @@ -29,67 +29,56 @@ StaticSpeedHelper::StaticSpeedHelper (const Vector &position) : m_position (position) {} StaticSpeedHelper::StaticSpeedHelper (const Vector &position, - const Vector &speed) + const Vector &vel) : m_position (position), - m_speed (speed), + m_velocity (vel), m_paused (true) {} void -StaticSpeedHelper::InitializePosition (const Vector &position) +StaticSpeedHelper::SetPosition (const Vector &position) { m_position = position; - m_speed.x = 0.0; - m_speed.y = 0.0; - m_speed.z = 0.0; + m_velocity = Vector (0.0, 0.0, 0.0); m_lastUpdate = Simulator::Now (); - m_paused = true; } Vector StaticSpeedHelper::GetCurrentPosition (void) const { - Update (); return m_position; } Vector StaticSpeedHelper::GetVelocity (void) const { - return m_paused? Vector (0.0, 0.0, 0.0) : m_speed; + return m_paused? Vector (0.0, 0.0, 0.0) : m_velocity; } void -StaticSpeedHelper::SetSpeed (const Vector &speed) +StaticSpeedHelper::SetVelocity (const Vector &vel) { - Update (); - m_speed = speed; + m_velocity = vel; + m_lastUpdate = Simulator::Now (); } void StaticSpeedHelper::Update (void) const { - if (m_paused) - { - return; - } Time now = Simulator::Now (); NS_ASSERT (m_lastUpdate <= now); Time deltaTime = now - m_lastUpdate; m_lastUpdate = now; + if (m_paused) + { + return; + } double deltaS = deltaTime.GetSeconds (); - m_position.x += m_speed.x * deltaS; - m_position.y += m_speed.y * deltaS; - m_position.z += m_speed.z * deltaS; + m_position.x += m_velocity.x * deltaS; + m_position.y += m_velocity.y * deltaS; + m_position.z += m_velocity.z * deltaS; } -void -StaticSpeedHelper::Reset (const Vector &speed) -{ - Update (); - m_speed = speed; - Unpause (); -} void -StaticSpeedHelper::UpdateFull (const Rectangle &bounds) const +StaticSpeedHelper::UpdateWithBounds (const Rectangle &bounds) const { Update (); m_position.x = std::min (bounds.xMax, m_position.x); @@ -98,28 +87,16 @@ StaticSpeedHelper::UpdateFull (const Rectangle &bounds) const m_position.y = std::max (bounds.yMin, m_position.y); } -Vector -StaticSpeedHelper::GetCurrentPosition (const Rectangle &bounds) const -{ - UpdateFull (bounds); - return m_position; -} - void StaticSpeedHelper::Pause (void) { - Update (); m_paused = true; } void StaticSpeedHelper::Unpause (void) { - if (m_paused) - { - m_lastUpdate = Simulator::Now (); - m_paused = false; - } + m_paused = false; } } // namespace ns3 diff --git a/src/mobility/static-speed-helper.h b/src/mobility/static-speed-helper.h index d743460f4..e2c149231 100644 --- a/src/mobility/static-speed-helper.h +++ b/src/mobility/static-speed-helper.h @@ -33,23 +33,21 @@ class StaticSpeedHelper StaticSpeedHelper (); StaticSpeedHelper (const Vector &position); StaticSpeedHelper (const Vector &position, - const Vector &speed); - void InitializePosition (const Vector &position); + const Vector &vel); - void Reset (const Vector &speed); - Vector GetCurrentPosition (const Rectangle &bounds) const; + void SetPosition (const Vector &position); Vector GetCurrentPosition (void) const; Vector GetVelocity (void) const; - void SetSpeed (const Vector &speed); + void SetVelocity (const Vector &vel); void Pause (void); void Unpause (void); - private: + void UpdateWithBounds (const Rectangle &rectangle) const; void Update (void) const; - void UpdateFull (const Rectangle &rectangle) const; + private: mutable Time m_lastUpdate; mutable Vector m_position; - Vector m_speed; + Vector m_velocity; bool m_paused; }; diff --git a/src/mobility/static-speed-mobility-model.cc b/src/mobility/static-speed-mobility-model.cc index 4dcc77012..50e153328 100644 --- a/src/mobility/static-speed-mobility-model.cc +++ b/src/mobility/static-speed-mobility-model.cc @@ -39,9 +39,11 @@ StaticSpeedMobilityModel::~StaticSpeedMobilityModel () {} void -StaticSpeedMobilityModel::SetSpeed (const Vector &speed) +StaticSpeedMobilityModel::SetVelocity (const Vector &speed) { - m_helper.SetSpeed (speed); + m_helper.Update (); + m_helper.SetVelocity (speed); + m_helper.Unpause (); NotifyCourseChange (); } @@ -49,12 +51,13 @@ StaticSpeedMobilityModel::SetSpeed (const Vector &speed) Vector StaticSpeedMobilityModel::DoGetPosition (void) const { + m_helper.Update (); return m_helper.GetCurrentPosition (); } void StaticSpeedMobilityModel::DoSetPosition (const Vector &position) { - m_helper.InitializePosition (position); + m_helper.SetPosition (position); NotifyCourseChange (); } Vector diff --git a/src/mobility/static-speed-mobility-model.h b/src/mobility/static-speed-mobility-model.h index 3da5b466e..b222f1268 100644 --- a/src/mobility/static-speed-mobility-model.h +++ b/src/mobility/static-speed-mobility-model.h @@ -49,7 +49,7 @@ public: * Set the current speed now to (dx,dy,dz) * Unit is meters/s */ - void SetSpeed (const Vector &speed); + void SetVelocity (const Vector &speed); private: virtual Vector DoGetPosition (void) const; virtual void DoSetPosition (const Vector &position); From b839e400a91002076cd0e14dea043b695125879d Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 24 Oct 2008 12:29:02 +0200 Subject: [PATCH 07/13] Read correctly fractional seconds. Reported by Ramon Bauza --- src/helper/ns2-mobility-helper.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/helper/ns2-mobility-helper.cc b/src/helper/ns2-mobility-helper.cc index 563287b05..ed692c72b 100644 --- a/src/helper/ns2-mobility-helper.cc +++ b/src/helper/ns2-mobility-helper.cc @@ -120,14 +120,17 @@ Ns2MobilityHelper::LayoutObjectStore (const ObjectStore &store) const } else { - double at = ReadDouble (line.substr (8, startNodeId - 17)); + std::string::size_type atEnd = line.find_first_of (" ", 8); + std::string atStr = line.substr (8, atEnd-8); + NS_LOG_DEBUG (atStr); + double at = ReadDouble (atStr); std::string::size_type xSpeedEnd = line.find_first_of (" ", endNodeId + 10); std::string::size_type ySpeedEnd = line.find_first_of (" ", xSpeedEnd + 1); double xSpeed = ReadDouble (line.substr (endNodeId + 10, xSpeedEnd - endNodeId - 10)); double ySpeed = ReadDouble (line.substr (xSpeedEnd + 1, ySpeedEnd - xSpeedEnd - 1)); double zSpeed = ReadDouble (line.substr (ySpeedEnd + 1, std::string::npos)); NS_LOG_DEBUG ("at=" << at << "xSpeed=" << xSpeed << ", ySpeed=" << ySpeed << ", zSpeed=" << zSpeed); - Simulator::Schedule (Seconds (at), &StaticSpeedMobilityModel::SetSpeed, model, + Simulator::Schedule (Seconds (at), &StaticSpeedMobilityModel::SetVelocity, model, Vector (xSpeed, ySpeed, zSpeed)); } } From 7a923ef2bd13c9d0f94c478c306de92caf91bca4 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 24 Oct 2008 12:29:15 +0200 Subject: [PATCH 08/13] rescan python --- bindings/python/ns3_module_mobility.py | 37 +++++++++++++------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/bindings/python/ns3_module_mobility.py b/bindings/python/ns3_module_mobility.py index 6b44567f4..0b3cbb75e 100644 --- a/bindings/python/ns3_module_mobility.py +++ b/bindings/python/ns3_module_mobility.py @@ -150,21 +150,12 @@ def register_Ns3StaticSpeedHelper_methods(root_module, cls): cls.add_constructor([]) ## static-speed-helper.h: ns3::StaticSpeedHelper::StaticSpeedHelper(ns3::Vector const & position) [constructor] cls.add_constructor([param('ns3::Vector const &', 'position')]) - ## static-speed-helper.h: ns3::StaticSpeedHelper::StaticSpeedHelper(ns3::Vector const & position, ns3::Vector const & speed) [constructor] - cls.add_constructor([param('ns3::Vector const &', 'position'), param('ns3::Vector const &', 'speed')]) - ## static-speed-helper.h: void ns3::StaticSpeedHelper::InitializePosition(ns3::Vector const & position) [member function] - cls.add_method('InitializePosition', + ## static-speed-helper.h: ns3::StaticSpeedHelper::StaticSpeedHelper(ns3::Vector const & position, ns3::Vector const & vel) [constructor] + cls.add_constructor([param('ns3::Vector const &', 'position'), param('ns3::Vector const &', 'vel')]) + ## static-speed-helper.h: void ns3::StaticSpeedHelper::SetPosition(ns3::Vector const & position) [member function] + cls.add_method('SetPosition', 'void', [param('ns3::Vector const &', 'position')]) - ## static-speed-helper.h: void ns3::StaticSpeedHelper::Reset(ns3::Vector const & speed) [member function] - cls.add_method('Reset', - 'void', - [param('ns3::Vector const &', 'speed')]) - ## static-speed-helper.h: ns3::Vector ns3::StaticSpeedHelper::GetCurrentPosition(ns3::Rectangle const & bounds) const [member function] - cls.add_method('GetCurrentPosition', - 'ns3::Vector', - [param('ns3::Rectangle const &', 'bounds')], - is_const=True) ## static-speed-helper.h: ns3::Vector ns3::StaticSpeedHelper::GetCurrentPosition() const [member function] cls.add_method('GetCurrentPosition', 'ns3::Vector', @@ -175,10 +166,10 @@ def register_Ns3StaticSpeedHelper_methods(root_module, cls): 'ns3::Vector', [], is_const=True) - ## static-speed-helper.h: void ns3::StaticSpeedHelper::SetSpeed(ns3::Vector const & speed) [member function] - cls.add_method('SetSpeed', + ## static-speed-helper.h: void ns3::StaticSpeedHelper::SetVelocity(ns3::Vector const & vel) [member function] + cls.add_method('SetVelocity', 'void', - [param('ns3::Vector const &', 'speed')]) + [param('ns3::Vector const &', 'vel')]) ## static-speed-helper.h: void ns3::StaticSpeedHelper::Pause() [member function] cls.add_method('Pause', 'void', @@ -187,6 +178,16 @@ def register_Ns3StaticSpeedHelper_methods(root_module, cls): cls.add_method('Unpause', 'void', []) + ## static-speed-helper.h: void ns3::StaticSpeedHelper::UpdateWithBounds(ns3::Rectangle const & rectangle) const [member function] + cls.add_method('UpdateWithBounds', + 'void', + [param('ns3::Rectangle const &', 'rectangle')], + is_const=True) + ## static-speed-helper.h: void ns3::StaticSpeedHelper::Update() const [member function] + cls.add_method('Update', + 'void', + [], + is_const=True) return def register_Ns3Vector_methods(root_module, cls): @@ -631,8 +632,8 @@ def register_Ns3StaticSpeedMobilityModel_methods(root_module, cls): is_static=True) ## static-speed-mobility-model.h: ns3::StaticSpeedMobilityModel::StaticSpeedMobilityModel() [constructor] cls.add_constructor([]) - ## static-speed-mobility-model.h: void ns3::StaticSpeedMobilityModel::SetSpeed(ns3::Vector const & speed) [member function] - cls.add_method('SetSpeed', + ## static-speed-mobility-model.h: void ns3::StaticSpeedMobilityModel::SetVelocity(ns3::Vector const & speed) [member function] + cls.add_method('SetVelocity', 'void', [param('ns3::Vector const &', 'speed')]) ## static-speed-mobility-model.h: ns3::Vector ns3::StaticSpeedMobilityModel::DoGetPosition() const [member function] From d8dad149da0bb6d252f83fbabb5267d93fbd0592 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 24 Oct 2008 12:29:39 +0200 Subject: [PATCH 09/13] add ns2 mobility sample. --- samples/main-ns2-mob.cc | 37 +++++++++++++++++++++++++++++++++++++ samples/ns2-mob.tr | 7 +++++++ 2 files changed, 44 insertions(+) create mode 100644 samples/main-ns2-mob.cc create mode 100644 samples/ns2-mob.tr diff --git a/samples/main-ns2-mob.cc b/samples/main-ns2-mob.cc new file mode 100644 index 000000000..349e42f79 --- /dev/null +++ b/samples/main-ns2-mob.cc @@ -0,0 +1,37 @@ +#include "ns3/core-module.h" +#include "ns3/mobility-module.h" +#include "ns3/simulator-module.h" +#include "ns3/helper-module.h" +#include "ns3/mobility-module.h" +#include + +using namespace ns3; + +static void +CourseChange (std::ostream *os, std::string foo, Ptr mobility) +{ + Vector pos = mobility->GetPosition (); + Vector vel = mobility->GetVelocity (); + *os << Simulator::Now () << " POS: x=" << pos.x << ", y=" << pos.y + << ", z=" << pos.z << "; VEL:" << vel.x << ", y=" << vel.y + << ", z=" << vel.z << std::endl; +} + +int main (int argc, char *argv[]) +{ + Ns2MobilityHelper mobility(argv[1]); + std::ofstream os; + os.open (argv[2]); + NodeContainer stas; + stas.Create (1); + + mobility.Install (); + + Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange", + MakeBoundCallback (&CourseChange, &os)); + + Simulator::Stop (Seconds (10.0)); + Simulator::Run (); + Simulator::Destroy (); + return 0; +} diff --git a/samples/ns2-mob.tr b/samples/ns2-mob.tr new file mode 100644 index 000000000..b45e39cb2 --- /dev/null +++ b/samples/ns2-mob.tr @@ -0,0 +1,7 @@ + +$node_(0) set X_ 0.0 +$node_(0) set Y_ 25.0 +$node_(0) set Z_ 0.0 +$ns_ at 3.0 "$node_(0) setdest 25 0 0" +$ns_ at 4.8 "$node_(0) setdest 0 0 0" +$ns_ at 5.0 "$node_(0) setdest 25 0 0" From 24d3e0317abdde0e55e4f608eff1d69a2f0ca701 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 24 Oct 2008 12:31:57 +0200 Subject: [PATCH 10/13] replace \t with 8 spaces. --- src/helper/csma-helper.cc | 20 +++--- src/helper/csma-helper.h | 8 +-- src/helper/mobility-helper.cc | 82 ++++++++++++------------- src/helper/mobility-helper.h | 36 +++++------ src/helper/node-container.cc | 4 +- src/helper/ns2-mobility-helper.cc | 94 ++++++++++++++--------------- src/helper/ns2-mobility-helper.h | 8 +-- src/helper/olsr-helper.cc | 16 ++--- src/helper/olsr-helper.h | 16 ++--- src/helper/point-to-point-helper.cc | 20 +++--- src/helper/point-to-point-helper.h | 8 +-- src/helper/wifi-helper.cc | 78 ++++++++++++------------ src/helper/wifi-helper.h | 48 +++++++-------- 13 files changed, 219 insertions(+), 219 deletions(-) diff --git a/src/helper/csma-helper.cc b/src/helper/csma-helper.cc index d5d2b379b..78a1645fc 100644 --- a/src/helper/csma-helper.cc +++ b/src/helper/csma-helper.cc @@ -39,10 +39,10 @@ CsmaHelper::CsmaHelper () void CsmaHelper::SetQueue (std::string type, - std::string n1, const AttributeValue &v1, - std::string n2, const AttributeValue &v2, - std::string n3, const AttributeValue &v3, - std::string n4, const AttributeValue &v4) + std::string n1, const AttributeValue &v1, + std::string n2, const AttributeValue &v2, + std::string n3, const AttributeValue &v3, + std::string n4, const AttributeValue &v4) { m_queueFactory.SetTypeId (type); m_queueFactory.Set (n1, v1); @@ -106,9 +106,9 @@ CsmaHelper::EnablePcap (std::string filename, NodeContainer n) { Ptr node = *i; for (uint32_t j = 0; j < node->GetNDevices (); ++j) - { - devs.Add (node->GetDevice (j)); - } + { + devs.Add (node->GetDevice (j)); + } } EnablePcap (filename, devs); } @@ -153,9 +153,9 @@ CsmaHelper::EnableAscii (std::ostream &os, NodeContainer n) { Ptr node = *i; for (uint32_t j = 0; j < node->GetNDevices (); ++j) - { - devs.Add (node->GetDevice (j)); - } + { + devs.Add (node->GetDevice (j)); + } } EnableAscii (os, devs); } diff --git a/src/helper/csma-helper.h b/src/helper/csma-helper.h index 89cb7f138..9733e8236 100644 --- a/src/helper/csma-helper.h +++ b/src/helper/csma-helper.h @@ -57,10 +57,10 @@ public: * CsmaNetDevice created through CsmaHelper::Install. */ void SetQueue (std::string type, - std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), - std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), - std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), - std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue ()); + std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), + std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), + std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), + std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue ()); /** * \param n1 the name of the attribute to set diff --git a/src/helper/mobility-helper.cc b/src/helper/mobility-helper.cc index 9c0bb22fa..ad595f4d2 100644 --- a/src/helper/mobility-helper.cc +++ b/src/helper/mobility-helper.cc @@ -47,15 +47,15 @@ MobilityHelper::SetPositionAllocator (Ptr allocator) } void MobilityHelper::SetPositionAllocator (std::string type, - std::string n1, const AttributeValue &v1, - std::string n2, const AttributeValue &v2, - std::string n3, const AttributeValue &v3, - std::string n4, const AttributeValue &v4, - std::string n5, const AttributeValue &v5, - std::string n6, const AttributeValue &v6, - std::string n7, const AttributeValue &v7, - std::string n8, const AttributeValue &v8, - std::string n9, const AttributeValue &v9) + std::string n1, const AttributeValue &v1, + std::string n2, const AttributeValue &v2, + std::string n3, const AttributeValue &v3, + std::string n4, const AttributeValue &v4, + std::string n5, const AttributeValue &v5, + std::string n6, const AttributeValue &v6, + std::string n7, const AttributeValue &v7, + std::string n8, const AttributeValue &v8, + std::string n9, const AttributeValue &v9) { ObjectFactory pos; pos.SetTypeId (type); @@ -73,15 +73,15 @@ MobilityHelper::SetPositionAllocator (std::string type, void MobilityHelper::SetMobilityModel (std::string type, - std::string n1, const AttributeValue &v1, - std::string n2, const AttributeValue &v2, - std::string n3, const AttributeValue &v3, - std::string n4, const AttributeValue &v4, - std::string n5, const AttributeValue &v5, - std::string n6, const AttributeValue &v6, - std::string n7, const AttributeValue &v7, - std::string n8, const AttributeValue &v8, - std::string n9, const AttributeValue &v9) + std::string n1, const AttributeValue &v1, + std::string n2, const AttributeValue &v2, + std::string n3, const AttributeValue &v3, + std::string n4, const AttributeValue &v4, + std::string n5, const AttributeValue &v5, + std::string n6, const AttributeValue &v6, + std::string n7, const AttributeValue &v7, + std::string n8, const AttributeValue &v8, + std::string n9, const AttributeValue &v9) { m_mobility.SetTypeId (type); m_mobility.Set (n1, v1); @@ -122,29 +122,29 @@ MobilityHelper::Install (NodeContainer c) Ptr object = *i; Ptr model = object->GetObject (); if (model == 0) - { - model = m_mobility.Create ()->GetObject (); - if (model == 0) - { - NS_FATAL_ERROR ("The requested mobility model is not a mobility model: \""<< - m_mobility.GetTypeId ().GetName ()<<"\""); - } - if (m_mobilityStack.empty ()) - { - NS_LOG_DEBUG ("node="<AggregateObject (hierarchical); - NS_LOG_DEBUG ("node="<AggregateObject (hierarchical); + NS_LOG_DEBUG ("node="< model = GetMobilityModel (line.substr (startNodeId + 1, - endNodeId - startNodeId), - store); - if (model == 0) - { - continue; - } - if (startNodeId == 6) - { - double value = ReadDouble (line.substr (endNodeId + 9, std::string::npos)); - std::string coordinate = line.substr (endNodeId + 6, 1); + { + std::string line; + getline (file, line); + std::string::size_type startNodeId = line.find_first_of ("("); + std::string::size_type endNodeId = line.find_first_of (")"); + if (startNodeId == std::string::npos || + endNodeId == std::string::npos) + { + continue; + } + Ptr model = GetMobilityModel (line.substr (startNodeId + 1, + endNodeId - startNodeId), + store); + if (model == 0) + { + continue; + } + if (startNodeId == 6) + { + double value = ReadDouble (line.substr (endNodeId + 9, std::string::npos)); + std::string coordinate = line.substr (endNodeId + 6, 1); Vector position = model->GetPosition (); - if (coordinate == "X") - { + if (coordinate == "X") + { position.x = value; - NS_LOG_DEBUG ("X=" << value); - } - else if (coordinate == "Y") - { + NS_LOG_DEBUG ("X=" << value); + } + else if (coordinate == "Y") + { position.y = value; - NS_LOG_DEBUG ("Y=" << value); - } - else if (coordinate == "Z") - { + NS_LOG_DEBUG ("Y=" << value); + } + else if (coordinate == "Z") + { position.z = value; - NS_LOG_DEBUG ("Z=" << value); - } + NS_LOG_DEBUG ("Z=" << value); + } else { continue; } model->SetPosition (position); - } - else - { + } + else + { std::string::size_type atEnd = line.find_first_of (" ", 8); std::string atStr = line.substr (8, atEnd-8); NS_LOG_DEBUG (atStr); - double at = ReadDouble (atStr); - std::string::size_type xSpeedEnd = line.find_first_of (" ", endNodeId + 10); - std::string::size_type ySpeedEnd = line.find_first_of (" ", xSpeedEnd + 1); - double xSpeed = ReadDouble (line.substr (endNodeId + 10, xSpeedEnd - endNodeId - 10)); - double ySpeed = ReadDouble (line.substr (xSpeedEnd + 1, ySpeedEnd - xSpeedEnd - 1)); - double zSpeed = ReadDouble (line.substr (ySpeedEnd + 1, std::string::npos)); - NS_LOG_DEBUG ("at=" << at << "xSpeed=" << xSpeed << ", ySpeed=" << ySpeed << ", zSpeed=" << zSpeed); - Simulator::Schedule (Seconds (at), &StaticSpeedMobilityModel::SetVelocity, model, - Vector (xSpeed, ySpeed, zSpeed)); - } - } + double at = ReadDouble (atStr); + std::string::size_type xSpeedEnd = line.find_first_of (" ", endNodeId + 10); + std::string::size_type ySpeedEnd = line.find_first_of (" ", xSpeedEnd + 1); + double xSpeed = ReadDouble (line.substr (endNodeId + 10, xSpeedEnd - endNodeId - 10)); + double ySpeed = ReadDouble (line.substr (xSpeedEnd + 1, ySpeedEnd - xSpeedEnd - 1)); + double zSpeed = ReadDouble (line.substr (ySpeedEnd + 1, std::string::npos)); + NS_LOG_DEBUG ("at=" << at << "xSpeed=" << xSpeed << ", ySpeed=" << ySpeed << ", zSpeed=" << zSpeed); + Simulator::Schedule (Seconds (at), &StaticSpeedMobilityModel::SetVelocity, model, + Vector (xSpeed, ySpeed, zSpeed)); + } + } file.close(); } } diff --git a/src/helper/ns2-mobility-helper.h b/src/helper/ns2-mobility-helper.h index 809a51125..795f16392 100644 --- a/src/helper/ns2-mobility-helper.h +++ b/src/helper/ns2-mobility-helper.h @@ -90,14 +90,14 @@ Ns2MobilityHelper::Install (T begin, T end) const MyObjectStore (T begin, T end) : m_begin (begin), m_end (end) - {} + {} virtual Ptr Get (uint32_t i) const { T iterator = m_begin; iterator += i; if (iterator >= m_end) - { - return 0; - } + { + return 0; + } return *iterator; } private: diff --git a/src/helper/olsr-helper.cc b/src/helper/olsr-helper.cc index 656e276ca..86f85ffd3 100644 --- a/src/helper/olsr-helper.cc +++ b/src/helper/olsr-helper.cc @@ -30,14 +30,14 @@ OlsrHelper::OlsrHelper () void OlsrHelper::SetAgent (std::string tid, - std::string n0, const AttributeValue &v0, - std::string n1, const AttributeValue &v1, - std::string n2, const AttributeValue &v2, - std::string n3, const AttributeValue &v3, - std::string n4, const AttributeValue &v4, - std::string n5, const AttributeValue &v5, - std::string n6, const AttributeValue &v6, - std::string n7, const AttributeValue &v7) + std::string n0, const AttributeValue &v0, + std::string n1, const AttributeValue &v1, + std::string n2, const AttributeValue &v2, + std::string n3, const AttributeValue &v3, + std::string n4, const AttributeValue &v4, + std::string n5, const AttributeValue &v5, + std::string n6, const AttributeValue &v6, + std::string n7, const AttributeValue &v7) { m_agentFactory.SetTypeId (tid); m_agentFactory.Set (n0, v0); diff --git a/src/helper/olsr-helper.h b/src/helper/olsr-helper.h index d2eaea80d..3a37167e5 100644 --- a/src/helper/olsr-helper.h +++ b/src/helper/olsr-helper.h @@ -38,14 +38,14 @@ public: * \brief Set default OLSR routing agent attributes */ void SetAgent (std::string tid, - std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (), - std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), - std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), - std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), - std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), - std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), - std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), - std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ()); + std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (), + std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), + std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), + std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), + std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), + std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), + std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), + std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ()); /** * \brief Enable OLSR routing for a set of nodes diff --git a/src/helper/point-to-point-helper.cc b/src/helper/point-to-point-helper.cc index ed951b56e..ff99b6499 100644 --- a/src/helper/point-to-point-helper.cc +++ b/src/helper/point-to-point-helper.cc @@ -39,10 +39,10 @@ PointToPointHelper::PointToPointHelper () void PointToPointHelper::SetQueue (std::string type, - std::string n1, const AttributeValue &v1, - std::string n2, const AttributeValue &v2, - std::string n3, const AttributeValue &v3, - std::string n4, const AttributeValue &v4) + std::string n1, const AttributeValue &v1, + std::string n2, const AttributeValue &v2, + std::string n3, const AttributeValue &v3, + std::string n4, const AttributeValue &v4) { m_queueFactory.SetTypeId (type); m_queueFactory.Set (n1, v1); @@ -106,9 +106,9 @@ PointToPointHelper::EnablePcap (std::string filename, NodeContainer n) { Ptr node = *i; for (uint32_t j = 0; j < node->GetNDevices (); ++j) - { - devs.Add (node->GetDevice (j)); - } + { + devs.Add (node->GetDevice (j)); + } } EnablePcap (filename, devs); } @@ -153,9 +153,9 @@ PointToPointHelper::EnableAscii (std::ostream &os, NodeContainer n) { Ptr node = *i; for (uint32_t j = 0; j < node->GetNDevices (); ++j) - { - devs.Add (node->GetDevice (j)); - } + { + devs.Add (node->GetDevice (j)); + } } EnableAscii (os, devs); } diff --git a/src/helper/point-to-point-helper.h b/src/helper/point-to-point-helper.h index a86daf52a..a7fe785b7 100644 --- a/src/helper/point-to-point-helper.h +++ b/src/helper/point-to-point-helper.h @@ -57,10 +57,10 @@ public: * PointToPointNetDevice created through PointToPointHelper::Install. */ void SetQueue (std::string type, - std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), - std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), - std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), - std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue ()); + std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), + std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), + std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), + std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue ()); /** * \param name the name of the attribute to set diff --git a/src/helper/wifi-helper.cc b/src/helper/wifi-helper.cc index dd4a122c3..8e8e958ef 100644 --- a/src/helper/wifi-helper.cc +++ b/src/helper/wifi-helper.cc @@ -40,30 +40,30 @@ NS_LOG_COMPONENT_DEFINE ("WifiHelper"); namespace ns3 { static void PcapPhyTxEvent (Ptr writer, Ptr packet, - WifiMode mode, WifiPreamble preamble, - uint8_t txLevel) + WifiMode mode, WifiPreamble preamble, + uint8_t txLevel) { writer->WritePacket (packet); } static void PcapPhyRxEvent (Ptr writer, - Ptr packet, double snr, WifiMode mode, - enum WifiPreamble preamble) + Ptr packet, double snr, WifiMode mode, + enum WifiPreamble preamble) { writer->WritePacket (packet); } static void AsciiPhyTxEvent (std::ostream *os, std::string context, - Ptr packet, - WifiMode mode, WifiPreamble preamble, - uint8_t txLevel) + Ptr packet, + WifiMode mode, WifiPreamble preamble, + uint8_t txLevel) { *os << "+ " << Simulator::Now () << " " << context << " " << *packet << std::endl; } static void AsciiPhyRxOkEvent (std::ostream *os, std::string context, - Ptr packet, double snr, WifiMode mode, - enum WifiPreamble preamble) + Ptr packet, double snr, WifiMode mode, + enum WifiPreamble preamble) { *os << "r " << Simulator::Now () << " " << context << " " << *packet << std::endl; } @@ -78,14 +78,14 @@ WifiHelper::WifiHelper () void WifiHelper::SetRemoteStationManager (std::string type, - std::string n0, const AttributeValue &v0, - std::string n1, const AttributeValue &v1, - std::string n2, const AttributeValue &v2, - std::string n3, const AttributeValue &v3, - std::string n4, const AttributeValue &v4, - std::string n5, const AttributeValue &v5, - std::string n6, const AttributeValue &v6, - std::string n7, const AttributeValue &v7) + std::string n0, const AttributeValue &v0, + std::string n1, const AttributeValue &v1, + std::string n2, const AttributeValue &v2, + std::string n3, const AttributeValue &v3, + std::string n4, const AttributeValue &v4, + std::string n5, const AttributeValue &v5, + std::string n6, const AttributeValue &v6, + std::string n7, const AttributeValue &v7) { m_stationManager = ObjectFactory (); m_stationManager.SetTypeId (type); @@ -101,14 +101,14 @@ WifiHelper::SetRemoteStationManager (std::string type, void WifiHelper::SetMac (std::string type, - std::string n0, const AttributeValue &v0, - std::string n1, const AttributeValue &v1, - std::string n2, const AttributeValue &v2, - std::string n3, const AttributeValue &v3, - std::string n4, const AttributeValue &v4, - std::string n5, const AttributeValue &v5, - std::string n6, const AttributeValue &v6, - std::string n7, const AttributeValue &v7) + std::string n0, const AttributeValue &v0, + std::string n1, const AttributeValue &v1, + std::string n2, const AttributeValue &v2, + std::string n3, const AttributeValue &v3, + std::string n4, const AttributeValue &v4, + std::string n5, const AttributeValue &v5, + std::string n6, const AttributeValue &v6, + std::string n7, const AttributeValue &v7) { m_mac = ObjectFactory (); m_mac.SetTypeId (type); @@ -124,14 +124,14 @@ WifiHelper::SetMac (std::string type, void WifiHelper::SetPhy (std::string type, - std::string n0, const AttributeValue &v0, - std::string n1, const AttributeValue &v1, - std::string n2, const AttributeValue &v2, - std::string n3, const AttributeValue &v3, - std::string n4, const AttributeValue &v4, - std::string n5, const AttributeValue &v5, - std::string n6, const AttributeValue &v6, - std::string n7, const AttributeValue &v7) + std::string n0, const AttributeValue &v0, + std::string n1, const AttributeValue &v1, + std::string n2, const AttributeValue &v2, + std::string n3, const AttributeValue &v3, + std::string n4, const AttributeValue &v4, + std::string n5, const AttributeValue &v5, + std::string n6, const AttributeValue &v6, + std::string n7, const AttributeValue &v7) { m_phy = ObjectFactory (); m_phy.SetTypeId (type); @@ -177,9 +177,9 @@ WifiHelper::EnablePcap (std::string filename, NodeContainer n) { Ptr node = *i; for (uint32_t j = 0; j < node->GetNDevices (); ++j) - { - devs.Add (node->GetDevice (j)); - } + { + devs.Add (node->GetDevice (j)); + } } EnablePcap (filename, devs); } @@ -218,9 +218,9 @@ WifiHelper::EnableAscii (std::ostream &os, NodeContainer n) { Ptr node = *i; for (uint32_t j = 0; j < node->GetNDevices (); ++j) - { - devs.Add (node->GetDevice (j)); - } + { + devs.Add (node->GetDevice (j)); + } } EnableAscii (os, devs); } diff --git a/src/helper/wifi-helper.h b/src/helper/wifi-helper.h index 72cc4a198..271563462 100644 --- a/src/helper/wifi-helper.h +++ b/src/helper/wifi-helper.h @@ -65,14 +65,14 @@ public: * in the requested station manager. */ void SetRemoteStationManager (std::string type, - std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (), - std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), - std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), - std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), - std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), - std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), - std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), - std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ()); + std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (), + std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), + std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), + std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), + std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), + std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), + std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), + std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ()); /** * \param type the type of ns3::WifiMac to create. @@ -97,14 +97,14 @@ public: * in the requested mac. */ void SetMac (std::string type, - std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (), - std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), - std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), - std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), - std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), - std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), - std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), - std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ()); + std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (), + std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), + std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), + std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), + std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), + std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), + std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), + std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ()); /** * \param phyType the type of ns3::WifiPhy to create. @@ -129,14 +129,14 @@ public: * in the requested phy. */ void SetPhy (std::string phyType, - std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (), - std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), - std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), - std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), - std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), - std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), - std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), - std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ()); + std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (), + std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), + std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), + std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), + std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), + std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), + std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), + std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ()); From 9002d0d27c011586911351ff55eb286f6a5f2833 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 24 Oct 2008 12:35:28 +0200 Subject: [PATCH 11/13] bug 284: cannot use config paths to get a handle on an object. --- src/core/config.cc | 301 +++++++++++++++++++++++++++++---------------- src/core/config.h | 30 +++++ 2 files changed, 223 insertions(+), 108 deletions(-) diff --git a/src/core/config.cc b/src/core/config.cc index db12d72a4..0b42ad0b9 100644 --- a/src/core/config.cc +++ b/src/core/config.cc @@ -30,6 +30,100 @@ NS_LOG_COMPONENT_DEFINE ("Config"); namespace ns3 { +namespace Config { + +MatchContainer::MatchContainer () +{} +MatchContainer::MatchContainer (const std::vector > &objects, + const std::vector &contexts, + std::string path) + : m_objects (objects), + m_contexts (contexts), + m_path (path) +{} +MatchContainer::Iterator +MatchContainer::Begin (void) const +{ + return m_objects.begin (); +} +MatchContainer::Iterator +MatchContainer::End (void) const +{ + return m_objects.end (); +} +uint32_t +MatchContainer::GetN (void) const +{ + return m_objects.size (); +} +Ptr +MatchContainer::Get (uint32_t i) const +{ + return m_objects[i]; +} +std::string +MatchContainer::GetMatchedPath (uint32_t i) const +{ + return m_contexts[i]; +} +std::string +MatchContainer::GetPath (void) const +{ + return m_path; +} + +void +MatchContainer::Set (std::string name, const AttributeValue &value) +{ + for (Iterator tmp = Begin (); tmp != End (); ++tmp) + { + Ptr object = *tmp; + object->SetAttribute (name, value); + } +} +void +MatchContainer::Connect (std::string name, const CallbackBase &cb) +{ + NS_ASSERT (m_objects.size () == m_contexts.size ()); + for (uint32_t i = 0; i < m_objects.size (); ++i) + { + Ptr object = m_objects[i]; + std::string ctx = m_contexts[i] + name; + object->TraceConnect (name, ctx, cb); + } +} +void +MatchContainer::ConnectWithoutContext (std::string name, const CallbackBase &cb) +{ + for (Iterator tmp = Begin (); tmp != End (); ++tmp) + { + Ptr object = *tmp; + object->TraceConnectWithoutContext (name, cb); + } +} +void +MatchContainer::Disconnect (std::string name, const CallbackBase &cb) +{ + NS_ASSERT (m_objects.size () == m_contexts.size ()); + for (uint32_t i = 0; i < m_objects.size (); ++i) + { + Ptr object = m_objects[i]; + std::string ctx = m_contexts[i] + name; + object->TraceDisconnect (name, ctx, cb); + } +} +void +MatchContainer::DisconnectWithoutContext (std::string name, const CallbackBase &cb) +{ + for (Iterator tmp = Begin (); tmp != End (); ++tmp) + { + Ptr object = *tmp; + object->TraceDisconnectWithoutContext (name, cb); + } +} + +} // namespace Config + class ArrayMatcher { public: @@ -125,20 +219,40 @@ public: void Resolve (Ptr root); private: + void Canonicalize (void); void DoResolve (std::string path, Ptr root); void DoArrayResolve (std::string path, const ObjectVectorValue &vector); - void DoResolveOne (Ptr object, std::string name); - std::string GetResolvedPath (std::string name) const; - virtual void DoOne (Ptr object, std::string path, std::string name) = 0; + void DoResolveOne (Ptr object); + std::string GetResolvedPath (void) const; + virtual void DoOne (Ptr object, std::string path) = 0; std::vector m_workStack; std::string m_path; }; Resolver::Resolver (std::string path) : m_path (path) -{} +{ + Canonicalize (); +} Resolver::~Resolver () {} +void +Resolver::Canonicalize (void) +{ + // ensure that we start and end with a '/' + std::string::size_type tmp = m_path.find ("/"); + if (tmp != 0) + { + // no slash at start + m_path = "/" + m_path; + } + tmp = m_path.find_last_of ("/"); + if (tmp != (m_path.size () - 1)) + { + // no slash at end + m_path = m_path + "/"; + } +} void Resolver::Resolve (Ptr root) @@ -147,40 +261,34 @@ Resolver::Resolve (Ptr root) } std::string -Resolver::GetResolvedPath (std::string name) const +Resolver::GetResolvedPath (void) const { - std::string fullPath = ""; + std::string fullPath = "/"; for (std::vector::const_iterator i = m_workStack.begin (); i != m_workStack.end (); i++) { - fullPath += "/" + *i; + fullPath += *i + "/"; } - fullPath += "/" + name; return fullPath; } void -Resolver::DoResolveOne (Ptr object, std::string name) +Resolver::DoResolveOne (Ptr object) { - NS_LOG_DEBUG ("resolved="< root) const ObjectVectorChecker *vectorChecker = dynamic_cast (PeekPointer (info.checker)); if (vectorChecker != 0) { - NS_LOG_DEBUG ("GetAttribute(vector)="< obj); void UnregisterRootNamespaceObject (Ptr obj); @@ -298,110 +403,86 @@ public: Ptr GetRootNamespaceObject (uint32_t i) const; private: + void ParsePath (std::string path, std::string *root, std::string *leaf) const; typedef std::vector > Roots; Roots m_roots; }; +void +ConfigImpl::ParsePath (std::string path, std::string *root, std::string *leaf) const +{ + std::string::size_type slash = path.find_last_of ("/"); + NS_ASSERT (slash != std::string::npos); + *root = path.substr (0, slash); + *leaf = path.substr (slash+1, path.size ()-(slash+1)); + NS_LOG_FUNCTION (path << *root << *leaf); +} + void ConfigImpl::Set (std::string path, const AttributeValue &value) { - class SetResolver : public Resolver - { - public: - SetResolver (std::string path, const AttributeValue &value) - : Resolver (path), - m_value (value.Copy ()) {} - private: - virtual void DoOne (Ptr object, std::string path, std::string name) { - object->SetAttribute (name, *m_value); - } - Ptr m_value; - } resolver = SetResolver (path, value); - for (Roots::const_iterator i = m_roots.begin (); i != m_roots.end (); i++) - { - resolver.Resolve (*i); - } + std::string root, leaf; + ParsePath (path, &root, &leaf); + Config::MatchContainer container = LookupMatches (root); + container.Set (leaf, value); } void ConfigImpl::ConnectWithoutContext (std::string path, const CallbackBase &cb) { - class ConnectResolver : public Resolver - { - public: - ConnectResolver (std::string path, const CallbackBase &cb) - : Resolver (path), - m_cb (cb) {} - private: - virtual void DoOne (Ptr object, std::string path, std::string name) { - object->TraceConnectWithoutContext (name, m_cb); - } - CallbackBase m_cb; - } resolver = ConnectResolver (path, cb); - for (Roots::const_iterator i = m_roots.begin (); i != m_roots.end (); i++) - { - resolver.Resolve (*i); - } + std::string root, leaf; + ParsePath (path, &root, &leaf); + Config::MatchContainer container = LookupMatches (root); + container.ConnectWithoutContext (leaf, cb); } void ConfigImpl::DisconnectWithoutContext (std::string path, const CallbackBase &cb) { - class DisconnectResolver : public Resolver - { - public: - DisconnectResolver (std::string path, const CallbackBase &cb) - : Resolver (path), - m_cb (cb) {} - private: - virtual void DoOne (Ptr object, std::string path, std::string name) { - object->TraceDisconnectWithoutContext (name, m_cb); - } - CallbackBase m_cb; - } resolver = DisconnectResolver (path, cb); - for (Roots::const_iterator i = m_roots.begin (); i != m_roots.end (); i++) - { - resolver.Resolve (*i); - } + std::string root, leaf; + ParsePath (path, &root, &leaf); + Config::MatchContainer container = LookupMatches (root); + container.DisconnectWithoutContext (leaf, cb); } void ConfigImpl::Connect (std::string path, const CallbackBase &cb) { - class ConnectWithContextResolver : public Resolver - { - public: - ConnectWithContextResolver (std::string path, const CallbackBase &cb) - : Resolver (path), - m_cb (cb) {} - private: - virtual void DoOne (Ptr object, std::string path, std::string name) { - object->TraceConnect (name, path, m_cb); - } - CallbackBase m_cb; - } resolver = ConnectWithContextResolver (path, cb); - for (Roots::const_iterator i = m_roots.begin (); i != m_roots.end (); i++) - { - resolver.Resolve (*i); - } + std::string root, leaf; + ParsePath (path, &root, &leaf); + Config::MatchContainer container = LookupMatches (root); + container.Connect (leaf, cb); } void ConfigImpl::Disconnect (std::string path, const CallbackBase &cb) { - class DisconnectWithContextResolver : public Resolver + std::string root, leaf; + ParsePath (path, &root, &leaf); + Config::MatchContainer container = LookupMatches (root); + container.Disconnect (leaf, cb); +} + +Config::MatchContainer +ConfigImpl::LookupMatches (std::string path) +{ + NS_LOG_FUNCTION (path); + class LookupMatchesResolver : public Resolver { public: - DisconnectWithContextResolver (std::string path, const CallbackBase &cb) - : Resolver (path), - m_cb (cb) {} - private: - virtual void DoOne (Ptr object, std::string path, std::string name) { - object->TraceDisconnect (name, path, m_cb); + LookupMatchesResolver (std::string path) + : Resolver (path) + {} + virtual void DoOne (Ptr object, std::string path) { + m_objects.push_back (object); + m_contexts.push_back (path); } - CallbackBase m_cb; - } resolver = DisconnectWithContextResolver (path, cb); + std::vector > m_objects; + std::vector m_contexts; + } resolver = LookupMatchesResolver (path); for (Roots::const_iterator i = m_roots.begin (); i != m_roots.end (); i++) { resolver.Resolve (*i); } + return Config::MatchContainer (resolver.m_objects, resolver.m_contexts, path); } + void ConfigImpl::RegisterRootNamespaceObject (Ptr obj) { @@ -472,6 +553,10 @@ Disconnect (std::string path, const CallbackBase &cb) { Singleton::Get ()->Disconnect (path, cb); } +Config::MatchContainer LookupMatches (std::string path) +{ + return Singleton::Get ()->LookupMatches (path); +} void RegisterRootNamespaceObject (Ptr obj) { diff --git a/src/core/config.h b/src/core/config.h index 256b491ef..9da9b03b9 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -22,6 +22,7 @@ #include "ptr.h" #include +#include namespace ns3 { @@ -110,6 +111,35 @@ void Connect (std::string path, const CallbackBase &cb); */ void Disconnect (std::string path, const CallbackBase &cb); +class MatchContainer +{ +public: + typedef std::vector >::const_iterator Iterator; + MatchContainer (); + MatchContainer (const std::vector > &objects, + const std::vector &contexts, + std::string path); + + MatchContainer::Iterator Begin (void) const; + MatchContainer::Iterator End (void) const; + uint32_t GetN (void) const; + Ptr Get (uint32_t i) const; + std::string GetMatchedPath (uint32_t i) const; + std::string GetPath (void) const; + + void Set (std::string name, const AttributeValue &value); + void Connect (std::string name, const CallbackBase &cb); + void ConnectWithoutContext (std::string name, const CallbackBase &cb); + void Disconnect (std::string name, const CallbackBase &cb); + void DisconnectWithoutContext (std::string name, const CallbackBase &cb); +private: + std::vector > m_objects; + std::vector m_contexts; + std::string m_path; +}; + +MatchContainer LookupMatches (std::string path); + /** * \param obj a new root object * From c164d111bd7c065652425d818ec9007a79e33be5 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 24 Oct 2008 12:39:53 +0200 Subject: [PATCH 12/13] forgot to build ns2 mobility sample --- samples/wscript | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/samples/wscript b/samples/wscript index 8215128a9..5e4c91d7f 100644 --- a/samples/wscript +++ b/samples/wscript @@ -39,4 +39,8 @@ def build(bld): ['core', 'simulator', 'mobility', 'wifi']) obj.source = 'main-propagation-loss.cc' + obj = bld.create_ns3_program('main-ns2-mob', + ['core', 'simulator', 'mobility', 'wifi']) + obj.source = 'main-ns2-mob.cc' + From 3ec1d2f640e7986cc0a8e97643f8ca324b5cc215 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 24 Oct 2008 13:22:16 +0200 Subject: [PATCH 13/13] bug 280: trace helpers too inclusive --- src/helper/csma-helper.cc | 7 +++++++ src/helper/point-to-point-helper.cc | 7 +++++++ src/helper/wifi-helper.cc | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/src/helper/csma-helper.cc b/src/helper/csma-helper.cc index 78a1645fc..3b3164658 100644 --- a/src/helper/csma-helper.cc +++ b/src/helper/csma-helper.cc @@ -78,6 +78,13 @@ void CsmaHelper::EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid) { std::ostringstream oss; + oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/"; + Config::MatchContainer matches = Config::LookupMatches (oss.str ()); + if (matches.GetN () == 0) + { + return; + } + oss.str (""); oss << filename << "-" << nodeid << "-" << deviceid << ".pcap"; Ptr pcap = Create (); pcap->Open (oss.str ()); diff --git a/src/helper/point-to-point-helper.cc b/src/helper/point-to-point-helper.cc index ff99b6499..52a539ee0 100644 --- a/src/helper/point-to-point-helper.cc +++ b/src/helper/point-to-point-helper.cc @@ -78,6 +78,13 @@ void PointToPointHelper::EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid) { std::ostringstream oss; + oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/"; + Config::MatchContainer matches = Config::LookupMatches (oss.str ()); + if (matches.GetN () == 0) + { + return; + } + oss.str (""); oss << filename << "-" << nodeid << "-" << deviceid << ".pcap"; Ptr pcap = Create (); pcap->Open (oss.str ()); diff --git a/src/helper/wifi-helper.cc b/src/helper/wifi-helper.cc index 8e8e958ef..ce5f07701 100644 --- a/src/helper/wifi-helper.cc +++ b/src/helper/wifi-helper.cc @@ -149,6 +149,13 @@ void WifiHelper::EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid) { std::ostringstream oss; + oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/"; + Config::MatchContainer matches = Config::LookupMatches (oss.str ()); + if (matches.GetN () == 0) + { + return; + } + oss.str (""); oss << filename << "-" << nodeid << "-" << deviceid << ".pcap"; Ptr pcap = Create (); pcap->Open (oss.str ());