From 8a32b1e36932c141e29d11a6f7cc31eb7be8ea4b Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 14 Apr 2008 17:12:52 -0700 Subject: [PATCH 01/10] fix bug reported by Gustavo Carneiro: AP does not reply to ARP request. --- src/devices/wifi/dca-txop.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/devices/wifi/dca-txop.cc b/src/devices/wifi/dca-txop.cc index 170b4b3c5..d22d97b1f 100644 --- a/src/devices/wifi/dca-txop.cc +++ b/src/devices/wifi/dca-txop.cc @@ -383,6 +383,7 @@ DcaTxop::NotifyAccessGranted (void) m_currentPacket = 0; m_dcf->ResetCw (); m_dcf->StartBackoffNow (m_rng->GetNext (0, m_dcf->GetCw ())); + StartAccessIfNeeded (); MY_DEBUG ("tx broadcast"); } else From 61375f8ef58bb2c326e50dcd591d11c0ce21e9b1 Mon Sep 17 00:00:00 2001 From: Liu Jian Date: Tue, 15 Apr 2008 09:41:58 -0700 Subject: [PATCH 02/10] Fix bug 168: Socket::SendTo does not return the number of bytes sent for udp sockets. --- src/internet-node/udp-socket.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index 383870c34..935a05f67 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -300,6 +300,7 @@ UdpSocket::DoSendTo (Ptr p, Ipv4Address dest, uint16_t port) NotifyDataSent (p->GetSize ()); } NS_LOG_LOGIC ("Limited broadcast end."); + return p->GetSize(); } else if (ipv4->GetIfIndexForDestination(dest, localIfIndex)) { @@ -307,7 +308,7 @@ UdpSocket::DoSendTo (Ptr p, Ipv4Address dest, uint16_t port) m_udp->Send (p, ipv4->GetAddress (localIfIndex), dest, m_endPoint->GetLocalPort (), port); NotifyDataSent (p->GetSize ()); - return 0; + return p->GetSize();; } else { From 6fd8b6c572dd4e735a6a6ca763f29dba15b9dee8 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 15 Apr 2008 10:09:42 -0700 Subject: [PATCH 03/10] bug 143: rename scheduler files --- .../{scheduler-heap.cc => heap-scheduler.cc} | 44 +++++++++---------- .../{scheduler-heap.h => heap-scheduler.h} | 6 +-- .../{scheduler-list.cc => list-scheduler.cc} | 18 ++++---- .../{scheduler-list.h => list-scheduler.h} | 6 +-- .../{scheduler-map.cc => map-scheduler.cc} | 18 ++++---- .../{scheduler-map.h => map-scheduler.h} | 12 ++--- src/simulator/simulator.cc | 14 +++--- src/simulator/wscript | 12 ++--- utils/bench-simulator.cc | 13 +++--- utils/replay-simulation.cc | 14 +++--- 10 files changed, 75 insertions(+), 82 deletions(-) rename src/simulator/{scheduler-heap.cc => heap-scheduler.cc} (84%) rename src/simulator/{scheduler-heap.h => heap-scheduler.h} (95%) rename src/simulator/{scheduler-list.cc => list-scheduler.cc} (87%) rename src/simulator/{scheduler-list.h => list-scheduler.h} (94%) rename src/simulator/{scheduler-map.cc => map-scheduler.cc} (88%) rename src/simulator/{scheduler-map.h => map-scheduler.h} (84%) diff --git a/src/simulator/scheduler-heap.cc b/src/simulator/heap-scheduler.cc similarity index 84% rename from src/simulator/scheduler-heap.cc rename to src/simulator/heap-scheduler.cc index d26f8a959..41f174d39 100644 --- a/src/simulator/scheduler-heap.cc +++ b/src/simulator/heap-scheduler.cc @@ -31,7 +31,7 @@ * to move one if statement out of the loop. */ -#include "scheduler-heap.h" +#include "heap-scheduler.h" #include "event-impl.h" #include "ns3/assert.h" @@ -52,7 +52,7 @@ std::cout << "HEAP TRACE " << x << std::endl; namespace ns3 { -SchedulerHeap::SchedulerHeap () +HeapScheduler::HeapScheduler () { // we purposedly waste an item at the start of // the array to make sure the indexes in the @@ -61,57 +61,57 @@ SchedulerHeap::SchedulerHeap () m_heap.push_back (std::make_pair (static_cast(0), emptyKey)); } -SchedulerHeap::~SchedulerHeap () +HeapScheduler::~HeapScheduler () {} uint32_t -SchedulerHeap::Parent (uint32_t id) const +HeapScheduler::Parent (uint32_t id) const { return id / 2; } uint32_t -SchedulerHeap::Sibling (uint32_t id) const +HeapScheduler::Sibling (uint32_t id) const { return id + 1; } uint32_t -SchedulerHeap::LeftChild (uint32_t id) const +HeapScheduler::LeftChild (uint32_t id) const { return id * 2; } uint32_t -SchedulerHeap::RightChild (uint32_t id) const +HeapScheduler::RightChild (uint32_t id) const { return id * 2 + 1; } uint32_t -SchedulerHeap::Root (void) const +HeapScheduler::Root (void) const { return 1; } bool -SchedulerHeap::IsRoot (uint32_t id) const +HeapScheduler::IsRoot (uint32_t id) const { return (id == Root ())?true:false; } uint32_t -SchedulerHeap::Last (void) const +HeapScheduler::Last (void) const { return m_heap.size () - 1; } bool -SchedulerHeap::IsBottom (uint32_t id) const +HeapScheduler::IsBottom (uint32_t id) const { return (id >= m_heap.size ())?true:false; } void -SchedulerHeap::Exch (uint32_t a, uint32_t b) +HeapScheduler::Exch (uint32_t a, uint32_t b) { NS_ASSERT (b < m_heap.size () && a < m_heap.size ()); TRACE ("Exch " << a << ", " << b); @@ -121,7 +121,7 @@ SchedulerHeap::Exch (uint32_t a, uint32_t b) } bool -SchedulerHeap::IsLowerStrictly (Scheduler::EventKey const*a, Scheduler::EventKey const*b) const +HeapScheduler::IsLowerStrictly (Scheduler::EventKey const*a, Scheduler::EventKey const*b) const { if (a->m_ts < b->m_ts) { @@ -142,25 +142,25 @@ SchedulerHeap::IsLowerStrictly (Scheduler::EventKey const*a, Scheduler::EventKey } bool -SchedulerHeap::IsLessStrictly (uint32_t a, uint32_t b) const +HeapScheduler::IsLessStrictly (uint32_t a, uint32_t b) const { return IsLowerStrictly (&m_heap[a].second, &m_heap[b].second); } uint32_t -SchedulerHeap::Smallest (uint32_t a, uint32_t b) const +HeapScheduler::Smallest (uint32_t a, uint32_t b) const { return IsLessStrictly (a,b)?a:b; } bool -SchedulerHeap::IsEmpty (void) const +HeapScheduler::IsEmpty (void) const { return (m_heap.size () == 1)?true:false; } void -SchedulerHeap::BottomUp (void) +HeapScheduler::BottomUp (void) { uint32_t index = Last (); while (!IsRoot (index) && @@ -172,7 +172,7 @@ SchedulerHeap::BottomUp (void) } void -SchedulerHeap::TopDown (uint32_t start) +HeapScheduler::TopDown (uint32_t start) { uint32_t index = start; uint32_t right = RightChild (index); @@ -207,7 +207,7 @@ SchedulerHeap::TopDown (uint32_t start) void -SchedulerHeap::Insert (const EventId &id) +HeapScheduler::Insert (const EventId &id) { // acquire single ref EventImpl *event = id.PeekEventImpl (); @@ -220,13 +220,13 @@ SchedulerHeap::Insert (const EventId &id) } EventId -SchedulerHeap::PeekNext (void) const +HeapScheduler::PeekNext (void) const { std::pair next = m_heap[Root ()]; return EventId (next.first, next.second.m_ts, next.second.m_uid); } EventId -SchedulerHeap::RemoveNext (void) +HeapScheduler::RemoveNext (void) { std::pair next = m_heap[Root ()]; Exch (Root (), Last ()); @@ -237,7 +237,7 @@ SchedulerHeap::RemoveNext (void) bool -SchedulerHeap::Remove (const EventId &id) +HeapScheduler::Remove (const EventId &id) { uint32_t uid = id.GetUid (); for (uint32_t i = 1; i < m_heap.size (); i++) diff --git a/src/simulator/scheduler-heap.h b/src/simulator/heap-scheduler.h similarity index 95% rename from src/simulator/scheduler-heap.h rename to src/simulator/heap-scheduler.h index 3b2f74f32..20e8165e7 100644 --- a/src/simulator/scheduler-heap.h +++ b/src/simulator/heap-scheduler.h @@ -29,10 +29,10 @@ namespace ns3 { class EventHolder; -class SchedulerHeap : public Scheduler { +class HeapScheduler : public Scheduler { public: - SchedulerHeap (); - virtual ~SchedulerHeap (); + HeapScheduler (); + virtual ~HeapScheduler (); virtual void Insert (const EventId &id); virtual bool IsEmpty (void) const; diff --git a/src/simulator/scheduler-list.cc b/src/simulator/list-scheduler.cc similarity index 87% rename from src/simulator/scheduler-list.cc rename to src/simulator/list-scheduler.cc index 3514b2519..78459434a 100644 --- a/src/simulator/scheduler-list.cc +++ b/src/simulator/list-scheduler.cc @@ -18,7 +18,7 @@ * Author: Mathieu Lacage */ -#include "scheduler-list.h" +#include "list-scheduler.h" #include "event-impl.h" #include #include @@ -27,13 +27,13 @@ namespace ns3 { -SchedulerList::SchedulerList () +ListScheduler::ListScheduler () {} -SchedulerList::~SchedulerList () +ListScheduler::~ListScheduler () {} bool -SchedulerList::IsLower (Scheduler::EventKey const*a, Scheduler::EventKey const*b) const +ListScheduler::IsLower (Scheduler::EventKey const*a, Scheduler::EventKey const*b) const { if (a->m_ts < b->m_ts) { @@ -51,7 +51,7 @@ SchedulerList::IsLower (Scheduler::EventKey const*a, Scheduler::EventKey const*b } void -SchedulerList::Insert (const EventId &id) +ListScheduler::Insert (const EventId &id) { Scheduler::EventKey key; // acquire refcount on EventImpl @@ -70,19 +70,19 @@ SchedulerList::Insert (const EventId &id) m_events.push_back (std::make_pair (event, key)); } bool -SchedulerList::IsEmpty (void) const +ListScheduler::IsEmpty (void) const { return m_events.empty (); } EventId -SchedulerList::PeekNext (void) const +ListScheduler::PeekNext (void) const { std::pair next = m_events.front (); return EventId (next.first, next.second.m_ts, next.second.m_uid); } EventId -SchedulerList::RemoveNext (void) +ListScheduler::RemoveNext (void) { std::pair next = m_events.front (); m_events.pop_front (); @@ -90,7 +90,7 @@ SchedulerList::RemoveNext (void) } bool -SchedulerList::Remove (const EventId &id) +ListScheduler::Remove (const EventId &id) { for (EventsI i = m_events.begin (); i != m_events.end (); i++) { diff --git a/src/simulator/scheduler-list.h b/src/simulator/list-scheduler.h similarity index 94% rename from src/simulator/scheduler-list.h rename to src/simulator/list-scheduler.h index 86dfc991f..c4e70398b 100644 --- a/src/simulator/scheduler-list.h +++ b/src/simulator/list-scheduler.h @@ -31,10 +31,10 @@ namespace ns3 { class EventImpl; -class SchedulerList : public Scheduler { +class ListScheduler : public Scheduler { public: - SchedulerList (); - virtual ~SchedulerList (); + ListScheduler (); + virtual ~ListScheduler (); virtual void Insert (const EventId &id); virtual bool IsEmpty (void) const; diff --git a/src/simulator/scheduler-map.cc b/src/simulator/map-scheduler.cc similarity index 88% rename from src/simulator/scheduler-map.cc rename to src/simulator/map-scheduler.cc index 0c5024c9b..9726c4b66 100644 --- a/src/simulator/scheduler-map.cc +++ b/src/simulator/map-scheduler.cc @@ -19,7 +19,7 @@ * The idea to use a std c++ map came from GTNetS */ -#include "scheduler-map.h" +#include "map-scheduler.h" #include "event-impl.h" #include "ns3/assert.h" #include @@ -37,9 +37,9 @@ std::cout << "MAP TRACE " << x << std::endl; namespace ns3 { -SchedulerMap::SchedulerMap () +MapScheduler::MapScheduler () {} -SchedulerMap::~SchedulerMap () +MapScheduler::~MapScheduler () {} /* Note the invariants which this function must provide: @@ -48,7 +48,7 @@ SchedulerMap::~SchedulerMap () * - transitivity: f(x,y) and f(y,z) => f(x,z) */ bool -SchedulerMap::EventKeyCompare::operator () (struct EventKey const&a, struct EventKey const&b) +MapScheduler::EventKeyCompare::operator () (struct EventKey const&a, struct EventKey const&b) { if (a.m_ts < b.m_ts) { @@ -71,7 +71,7 @@ SchedulerMap::EventKeyCompare::operator () (struct EventKey const&a, struct Even void -SchedulerMap::Insert (const EventId &id) +MapScheduler::Insert (const EventId &id) { // acquire a single ref EventImpl *event = id.PeekEventImpl (); @@ -85,13 +85,13 @@ SchedulerMap::Insert (const EventId &id) } bool -SchedulerMap::IsEmpty (void) const +MapScheduler::IsEmpty (void) const { return m_list.empty (); } EventId -SchedulerMap::PeekNext (void) const +MapScheduler::PeekNext (void) const { EventMapCI i = m_list.begin (); NS_ASSERT (i != m_list.end ()); @@ -99,7 +99,7 @@ SchedulerMap::PeekNext (void) const return EventId (i->second, i->first.m_ts, i->first.m_uid); } EventId -SchedulerMap::RemoveNext (void) +MapScheduler::RemoveNext (void) { EventMapI i = m_list.begin (); std::pair next = *i; @@ -108,7 +108,7 @@ SchedulerMap::RemoveNext (void) } bool -SchedulerMap::Remove (const EventId &id) +MapScheduler::Remove (const EventId &id) { Scheduler::EventKey key; key.m_ts = id.GetTs (); diff --git a/src/simulator/scheduler-map.h b/src/simulator/map-scheduler.h similarity index 84% rename from src/simulator/scheduler-map.h rename to src/simulator/map-scheduler.h index 56e3587d0..cc49ecd34 100644 --- a/src/simulator/scheduler-map.h +++ b/src/simulator/map-scheduler.h @@ -30,10 +30,10 @@ namespace ns3 { class EventImpl; -class SchedulerMap : public Scheduler { +class MapScheduler : public Scheduler { public: - SchedulerMap (); - virtual ~SchedulerMap (); + MapScheduler (); + virtual ~MapScheduler (); virtual void Insert (const EventId &id); virtual bool IsEmpty (void) const; @@ -47,9 +47,9 @@ private: bool operator () (struct EventKey const&a, struct EventKey const&b); }; - typedef std::map EventMap; - typedef std::map::iterator EventMapI; - typedef std::map::const_iterator EventMapCI; + typedef std::map EventMap; + typedef std::map::iterator EventMapI; + typedef std::map::const_iterator EventMapCI; EventMap m_list; diff --git a/src/simulator/simulator.cc b/src/simulator/simulator.cc index aa2a0be93..e2cf1f113 100644 --- a/src/simulator/simulator.cc +++ b/src/simulator/simulator.cc @@ -393,9 +393,7 @@ SimulatorPrivate::GetMaximumSimulationTime (void) const }; // namespace ns3 -#include "scheduler-list.h" -#include "scheduler-heap.h" -#include "scheduler-map.h" +#include "map-scheduler.h" namespace ns3 { @@ -418,7 +416,7 @@ Simulator::GetPriv (void) if (m_priv == 0) { m_priv = CreateObject (); - Ptr scheduler = CreateObject (); + Ptr scheduler = CreateObject (); m_priv->SetScheduler (scheduler); } TRACE_S ("priv " << m_priv); @@ -564,6 +562,8 @@ Simulator::GetMaximumSimulationTime (void) #include "ns3/test.h" #include "ns3/ptr.h" +#include "list-scheduler.h" +#include "heap-scheduler.h" namespace ns3 { @@ -934,19 +934,19 @@ SimulatorTests::RunTests (void) bool result = true; Simulator::Destroy (); - Simulator::SetScheduler (CreateObject ()); + Simulator::SetScheduler (CreateObject ()); if (!RunOneTest ()) { result = false; } Simulator::Destroy (); - Simulator::SetScheduler (CreateObject ()); + Simulator::SetScheduler (CreateObject ()); if (!RunOneTest ()) { result = false; } Simulator::Destroy (); - Simulator::SetScheduler (CreateObject ()); + Simulator::SetScheduler (CreateObject ()); if (!RunOneTest ()) { result = false; diff --git a/src/simulator/wscript b/src/simulator/wscript index 5d6963394..d41c5a356 100644 --- a/src/simulator/wscript +++ b/src/simulator/wscript @@ -53,9 +53,9 @@ def build(bld): 'time.cc', 'event-id.cc', 'scheduler.cc', - 'scheduler-list.cc', - 'scheduler-heap.cc', - 'scheduler-map.cc', + 'list-scheduler.cc', + 'map-scheduler.cc', + 'heap-scheduler.cc', 'event-impl.cc', 'simulator.cc', 'timer.cc', @@ -71,9 +71,9 @@ def build(bld): 'event-impl.h', 'simulator.h', 'scheduler.h', - 'scheduler-list.h', - 'scheduler-map.h', - 'scheduler-heap.h', + 'list-scheduler.h', + 'map-scheduler.h', + 'heap-scheduler.h', 'simulation-singleton.h', 'timer.h', 'timer-impl.h', diff --git a/utils/bench-simulator.cc b/utils/bench-simulator.cc index 2bfdd686f..6b9eb2c2b 100644 --- a/utils/bench-simulator.cc +++ b/utils/bench-simulator.cc @@ -18,11 +18,8 @@ * Author: Mathieu Lacage */ -#include "ns3/simulator.h" -#include "ns3/scheduler-list.h" -#include "ns3/scheduler-map.h" -#include "ns3/scheduler-heap.h" -#include "ns3/system-wall-clock-ms.h" +#include "ns3/simulator-module.h" +#include "ns3/core-module.h" #include #include #include @@ -161,15 +158,15 @@ int main (int argc, char *argv[]) { if (strcmp ("--list", argv[0]) == 0) { - Simulator::SetScheduler (CreateObject ()); + Simulator::SetScheduler (CreateObject ()); } else if (strcmp ("--heap", argv[0]) == 0) { - Simulator::SetScheduler (CreateObject ()); + Simulator::SetScheduler (CreateObject ()); } else if (strcmp ("--map", argv[0]) == 0) { - Simulator::SetScheduler (CreateObject ()); + Simulator::SetScheduler (CreateObject ()); } else if (strcmp ("--debug", argv[0]) == 0) { diff --git a/utils/replay-simulation.cc b/utils/replay-simulation.cc index 00fb6d1d3..1ce94dab9 100644 --- a/utils/replay-simulation.cc +++ b/utils/replay-simulation.cc @@ -18,12 +18,8 @@ * Author: Mathieu Lacage */ -#include "ns3/simulator.h" -#include "ns3/scheduler-list.h" -#include "ns3/scheduler-map.h" -#include "ns3/scheduler-heap.h" -#include "ns3/nstime.h" -#include "ns3/system-wall-clock-ms.h" +#include "ns3/simulator-module.h" +#include "ns3/core-module.h" #include #include #include @@ -317,15 +313,15 @@ int main (int argc, char *argv[]) { if (is_map) { - Simulator::SetScheduler (CreateObject ()); + Simulator::SetScheduler (CreateObject ()); } else if (is_list) { - Simulator::SetScheduler (CreateObject ()); + Simulator::SetScheduler (CreateObject ()); } else if (is_heap) { - Simulator::SetScheduler (CreateObject ()); + Simulator::SetScheduler (CreateObject ()); } log.Run (); Simulator::Destroy (); From 53be11fe6ff4c31a50ec02ee8c0d4969b835758b Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 15 Apr 2008 10:49:09 -0700 Subject: [PATCH 04/10] update testcase to deal with the return value of Socket::Send. Make sure udp packets are copied before going down the ip stack. --- src/internet-node/udp-socket.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index 935a05f67..33ceac8fc 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -305,7 +305,7 @@ UdpSocket::DoSendTo (Ptr p, Ipv4Address dest, uint16_t port) else if (ipv4->GetIfIndexForDestination(dest, localIfIndex)) { NS_LOG_LOGIC ("Route exists"); - m_udp->Send (p, ipv4->GetAddress (localIfIndex), dest, + m_udp->Send (p->Copy (), ipv4->GetAddress (localIfIndex), dest, m_endPoint->GetLocalPort (), port); NotifyDataSent (p->GetSize ()); return p->GetSize();; @@ -479,7 +479,7 @@ UdpSocketTest::RunTests (void) m_receivedPacket = Create (); m_receivedPacket2 = Create (); NS_TEST_ASSERT_EQUAL (txSocket->SendTo (InetSocketAddress (Ipv4Address("10.0.0.1"), 1234), - Create (123)), 0); + Create (123)), 123); Simulator::Run (); NS_TEST_ASSERT_EQUAL (m_receivedPacket->GetSize (), 123); NS_TEST_ASSERT_EQUAL (m_receivedPacket2->GetSize (), 0); // second interface should receive it @@ -490,7 +490,7 @@ UdpSocketTest::RunTests (void) m_receivedPacket = Create (); m_receivedPacket2 = Create (); NS_TEST_ASSERT_EQUAL (txSocket->SendTo (InetSocketAddress (Ipv4Address("255.255.255.255"), 1234), - Create (123)), 0); + Create (123)), 123); Simulator::Run (); NS_TEST_ASSERT_EQUAL (m_receivedPacket->GetSize (), 123); // second socket should not receive it (it is bound specifically to the second interface's address @@ -510,7 +510,7 @@ UdpSocketTest::RunTests (void) m_receivedPacket = Create (); m_receivedPacket2 = Create (); NS_TEST_ASSERT_EQUAL (txSocket->SendTo (InetSocketAddress (Ipv4Address("255.255.255.255"), 1234), - Create (123)), 0); + Create (123)), 123); Simulator::Run (); NS_TEST_ASSERT_EQUAL (m_receivedPacket->GetSize (), 123); NS_TEST_ASSERT_EQUAL (m_receivedPacket2->GetSize (), 123); From 5c5ab1f1f0c8d37c49ab024e27738a2e375210bb Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 15 Apr 2008 11:01:13 -0700 Subject: [PATCH 05/10] bug 150: CommandLine::Parse argc parameter should not be a reference --- src/core/command-line.cc | 2 +- src/core/command-line.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/command-line.cc b/src/core/command-line.cc index eb2852623..17f1b55ee 100644 --- a/src/core/command-line.cc +++ b/src/core/command-line.cc @@ -41,7 +41,7 @@ CommandLine::Item::~Item () {} void -CommandLine::Parse (int &iargc, char *argv[]) const +CommandLine::Parse (int iargc, char *argv[]) const { int argc = iargc; for (argc--, argv++; argc > 0; argc--, argv++) diff --git a/src/core/command-line.h b/src/core/command-line.h index 0d6039d7f..2a5948361 100644 --- a/src/core/command-line.h +++ b/src/core/command-line.h @@ -64,7 +64,7 @@ public: * Obviously, this method will parse the input command-line arguments and * will attempt to handle them all. */ - void Parse (int &argc, char *argv[]) const; + void Parse (int argc, char *argv[]) const; private: class Item { From edb480ad29a3dc2c477b3e567f4ab6bdb36cc260 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Wed, 16 Apr 2008 11:32:55 +0100 Subject: [PATCH 06/10] Fix bad usage of std container iteration and erase () all over OLSR code; closes #171; thanks to Liu Jian for spotting and submitting an initial patch. --- src/routing/olsr/olsr-agent-impl.cc | 21 +++++++++++----- src/routing/olsr/olsr-state.cc | 37 +++++++++++++++++++---------- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/routing/olsr/olsr-agent-impl.cc b/src/routing/olsr/olsr-agent-impl.cc index 79b5ae02c..614bf5dff 100644 --- a/src/routing/olsr/olsr-agent-impl.cc +++ b/src/routing/olsr/olsr-agent-impl.cc @@ -572,12 +572,15 @@ AgentImpl::MprComputation() // (not in RFC but I think is needed: remove the 2-hop // neighbors reachable by the MPR from N2) for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin (); - twoHopNeigh != N2.end (); twoHopNeigh++) + twoHopNeigh != N2.end (); ) { if (twoHopNeigh->neighborMainAddr == neighbor->neighborMainAddr) { twoHopNeigh = N2.erase (twoHopNeigh); - twoHopNeigh--; + } + else + { + twoHopNeigh++; } } } @@ -617,12 +620,15 @@ AgentImpl::MprComputation() } // Remove the nodes from N2 which are now covered by a node in the MPR set. for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin (); - twoHopNeigh != N2.end (); twoHopNeigh++) + twoHopNeigh != N2.end (); ) { if (coveredTwoHopNeighbors.find (twoHopNeigh->twoHopNeighborAddr) != coveredTwoHopNeighbors.end ()) { twoHopNeigh = N2.erase (twoHopNeigh); - twoHopNeigh--; + } + else + { + twoHopNeigh++; } } @@ -699,12 +705,15 @@ AgentImpl::MprComputation() { mprSet.insert (max->neighborMainAddr); for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin (); - twoHopNeigh != N2.end (); twoHopNeigh++) + twoHopNeigh != N2.end (); ) { if (twoHopNeigh->neighborMainAddr == max->neighborMainAddr) { twoHopNeigh = N2.erase (twoHopNeigh); - twoHopNeigh--; + } + else + { + twoHopNeigh++; } } } diff --git a/src/routing/olsr/olsr-state.cc b/src/routing/olsr/olsr-state.cc index 545407a4b..ad4cb8723 100644 --- a/src/routing/olsr/olsr-state.cc +++ b/src/routing/olsr/olsr-state.cc @@ -64,12 +64,15 @@ void OlsrState::EraseMprSelectorTuples (const Ipv4Address &mainAddr) { for (MprSelectorSet::iterator it = m_mprSelectorSet.begin (); - it != m_mprSelectorSet.end (); it++) + it != m_mprSelectorSet.end ();) { if (it->mainAddr == mainAddr) { it = m_mprSelectorSet.erase (it); - it--; + } + else + { + it++; } } } @@ -203,15 +206,18 @@ OlsrState::EraseTwoHopNeighborTuples (const Ipv4Address &neighborMainAddr, const Ipv4Address &twoHopNeighborAddr) { for (TwoHopNeighborSet::iterator it = m_twoHopNeighborSet.begin (); - it != m_twoHopNeighborSet.end (); it++) + it != m_twoHopNeighborSet.end ();) { if (it->neighborMainAddr == neighborMainAddr && it->twoHopNeighborAddr == twoHopNeighborAddr) { it = m_twoHopNeighborSet.erase (it); - it--; // FIXME: is this correct in the case 'it' pointed to the first element? m_modified = true; } + else + { + it++; + } } } @@ -219,13 +225,17 @@ void OlsrState::EraseTwoHopNeighborTuples (const Ipv4Address &neighborMainAddr) { for (TwoHopNeighborSet::iterator it = m_twoHopNeighborSet.begin (); - it != m_twoHopNeighborSet.end (); it++) + it != m_twoHopNeighborSet.end ();) { - if (it->neighborMainAddr == neighborMainAddr) { - it = m_twoHopNeighborSet.erase (it); - it--; - m_modified = true; - } + if (it->neighborMainAddr == neighborMainAddr) + { + it = m_twoHopNeighborSet.erase (it); + m_modified = true; + } + else + { + it++; + } } } @@ -385,14 +395,17 @@ void OlsrState::EraseOlderTopologyTuples (const Ipv4Address &lastAddr, uint16_t ansn) { for (TopologySet::iterator it = m_topologySet.begin(); - it != m_topologySet.end(); it++) + it != m_topologySet.end();) { if (it->lastAddr == lastAddr && it->sequenceNumber < ansn) { it = m_topologySet.erase (it); - it--; m_modified = true; } + else + { + it++; + } } } From bb10734d66849bc4edc18352566cc13c5ac8324b Mon Sep 17 00:00:00 2001 From: Raj Bhattacharjea Date: Wed, 16 Apr 2008 12:40:46 -0400 Subject: [PATCH 07/10] Fix for bug 166 --- src/internet-node/tcp-socket.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/internet-node/tcp-socket.cc b/src/internet-node/tcp-socket.cc index 58495f5bf..c199bf40d 100644 --- a/src/internet-node/tcp-socket.cc +++ b/src/internet-node/tcp-socket.cc @@ -695,6 +695,7 @@ bool TcpSocket::ProcessPacketAction (Actions_t a, Ptr p, // TCP SYN consumes one byte m_nextRxSequence = tcpHeader.GetSequenceNumber() + SequenceNumber(1); m_nextTxSequence = tcpHeader.GetAckNumber (); + m_firstPendingSequence = m_nextTxSequence; //bug 166 NS_LOG_DEBUG ("TcpSocket " << this << " ACK_TX_1" << " nextRxSeq " << m_nextRxSequence); SendEmptyPacket (TcpHeader::ACK); From 505de0c6854821ef7c5cba4533bdbb908c2fcfc7 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Wed, 16 Apr 2008 18:37:20 +0100 Subject: [PATCH 08/10] Address instances of different m_type's should compare differently; closes #173. --- src/node/address.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/node/address.cc b/src/node/address.cc index c27e0608b..3566c353c 100644 --- a/src/node/address.cc +++ b/src/node/address.cc @@ -111,9 +111,10 @@ ATTRIBUTE_HELPER_CPP (Address); bool operator == (const Address &a, const Address &b) { - NS_ASSERT (a.m_type == b.m_type || - a.m_type == 0 || - b.m_type == 0); + if (a.m_type != b.m_type) + { + return false; + } NS_ASSERT (a.GetLength() == b.GetLength()); return memcmp (a.m_data, b.m_data, a.m_len) == 0; } From 39ef17d6a498fd894f47a8201a1aed8d31aa3fc9 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 16 Apr 2008 10:52:26 -0700 Subject: [PATCH 09/10] bug 107 --- src/internet-node/arp-l3-protocol.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/internet-node/arp-l3-protocol.cc b/src/internet-node/arp-l3-protocol.cc index 6dc017623..42509bc2a 100644 --- a/src/internet-node/arp-l3-protocol.cc +++ b/src/internet-node/arp-l3-protocol.cc @@ -108,6 +108,11 @@ ArpL3Protocol::Receive(Ptr device, Ptr packet, uint16_t proto arp.GetDestinationIpv4Address () << "; we have address " << cache->GetInterface ()->GetAddress ()); + /** + * Note: we do not update the ARP cache when we receive an ARP request + * from an unknown node. See bug #107 + */ + if (arp.IsRequest () && arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress ()) { From 254057bd807778268933271304adf9b2b93ee36a Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Thu, 17 Apr 2008 17:19:24 +0100 Subject: [PATCH 10/10] Add assertion to detect TimeUnit divide by zero (if not detected, it creates an infinite loop) --- src/simulator/nstime.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/simulator/nstime.h b/src/simulator/nstime.h index d679790db..10a1e5169 100644 --- a/src/simulator/nstime.h +++ b/src/simulator/nstime.h @@ -274,6 +274,7 @@ TimeUnit operator * (TimeUnit const &lhs, TimeUnit const &rhs) template TimeUnit operator / (TimeUnit const &lhs, TimeUnit const &rhs) { + NS_ASSERT (rhs.GetHighPrecision ().GetDouble () != 0); HighPrecision retval = lhs.GetHighPrecision (); retval.Div (rhs.GetHighPrecision ()); return TimeUnit (retval);