diff --git a/examples/aodv.cc b/examples/aodv.cc index 8be2da09f..224c038f4 100644 --- a/examples/aodv.cc +++ b/examples/aodv.cc @@ -34,6 +34,13 @@ using namespace ns3; +enum TrafficType +{ + PING = 1, + UDP = 2, + TCP = 3 +}; + /** * \brief Test script. * @@ -65,6 +72,8 @@ private: double totalTime; /// Write per-device PCAP traces if true bool pcap; + /// Traffic type + uint16_t type; //\} ///\name network @@ -94,10 +103,11 @@ int main (int argc, char **argv) //----------------------------------------------------------------------------- AodvExample::AodvExample () : - size (4), + size (10), step (120), totalTime (10), - pcap (true) + pcap (true), + type (PING) { } @@ -111,6 +121,7 @@ AodvExample::Configure (int argc, char **argv) CommandLine cmd; cmd.AddValue ("pcap", "Write PCAP traces.", pcap); + cmd.AddValue ("type", "Traffic type.", type); cmd.AddValue ("size", "Number of nodes.", size); cmd.AddValue ("time", "Simulation time, s.", totalTime); cmd.AddValue ("step", "Grid step, m", step); @@ -199,11 +210,44 @@ AodvExample::InstallInternetStack () void AodvExample::InstallApplications () { - V4PingHelper ping (interfaces.GetAddress(size - 1)); - ping.SetAttribute ("Verbose", BooleanValue (true)); - - ApplicationContainer p = ping.Install (nodes.Get (0)); - p.Start (Seconds (0)); - p.Stop (Seconds (totalTime)); + switch (type) + { + case PING: + { + V4PingHelper ping (interfaces.GetAddress(size - 1)); + ping.SetAttribute ("Verbose", BooleanValue (true)); + + ApplicationContainer p = ping.Install (nodes.Get (0)); + p.Start (Seconds (0)); + p.Stop (Seconds (totalTime)); + break; + } + case UDP: + { + // Create the OnOff application to send UDP datagrams of size + // 210 bytes at a rate of 448 Kb/s + Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210)); + Config::SetDefault ("ns3::OnOffApplication::DataRate", DataRateValue (DataRate ("448kb/s"))); + uint16_t port = 9; // Discard port (RFC 863) + + OnOffHelper onoff ("ns3::UdpSocketFactory", + Address (InetSocketAddress (interfaces.GetAddress(size - 1), port))); + onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable(totalTime))); + onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable(0))); + + ApplicationContainer apps = onoff.Install (nodes.Get (0)); + apps.Start(Seconds(0)); + apps.Stop (Seconds(totalTime)); + + // Create an optional packet sink to receive these packets + PacketSinkHelper sink ("ns3::UdpSocketFactory", + Address (InetSocketAddress (Ipv4Address::GetAny (), port))); + apps = sink.Install (nodes.Get (size-1)); + apps.Start (Seconds (0)); + apps.Stop (Seconds (totalTime)); + break; + } + }; + } diff --git a/src/routing/aodv/aodv-routing-protocol.cc b/src/routing/aodv/aodv-routing-protocol.cc index 125309d6a..0bdb7f688 100644 --- a/src/routing/aodv/aodv-routing-protocol.cc +++ b/src/routing/aodv/aodv-routing-protocol.cc @@ -188,7 +188,7 @@ RoutingProtocol::Start () Ptr RoutingProtocol::RouteOutput (Ptr p, const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr ) { - NS_LOG_FUNCTION (this << header.GetDestination()); + NS_LOG_FUNCTION (this << header.GetDestination ()); if (m_socketAddresses.empty ()) { sockerr = Socket::ERROR_NOROUTETOHOST; @@ -291,6 +291,10 @@ RoutingProtocol::RouteInput (Ptr p, const Ipv4Header &header, Ptr< NS_LOG_LOGIC ("Forward broadcast"); ucb (route, packet, header); } + else + { + NS_LOG_WARN ("TTL exceeded. Drop packet " << p->GetUid ()); + } return true; } } @@ -412,6 +416,9 @@ RoutingProtocol::NotifyInterfaceUp (uint32_t i ) RoutingTableEntry rt (/*device=*/dev, /*dst=*/iface.GetBroadcast (), /*know seqno=*/true, /*seqno=*/0, /*iface=*/iface, /*hops=*/1, /*next hop=*/iface.GetBroadcast (), /*lifetime=*/Seconds (1e9)); // TODO use infty m_routingTable.AddRoute (rt); + RoutingTableEntry rt2 (/*device=*/dev, /*dst=*/Ipv4Address::GetBroadcast(), /*know seqno=*/true, /*seqno=*/0, /*iface=*/iface, + /*hops=*/1, /*next hop=*/Ipv4Address::GetBroadcast(), /*lifetime=*/Seconds (1e9)); // TODO use infty + m_routingTable.AddRoute (rt); // Allow neighbor manager use this interface for layer 2 feedback if possible Ptr wifi = dev->GetObject (); @@ -1198,7 +1205,6 @@ RoutingProtocol::HelloTimerExpire () { NS_LOG_FUNCTION(this); SendHello (); - // TODO select random time for the next hello htimer.Cancel (); Time t = Scalar(0.01)*MilliSeconds(UniformVariable().GetValue (0.0, 100.0)); htimer.Schedule (HelloInterval - t); diff --git a/src/routing/aodv/aodv-rqueue.cc b/src/routing/aodv/aodv-rqueue.cc index 7faee2aba..50d549a36 100644 --- a/src/routing/aodv/aodv-rqueue.cc +++ b/src/routing/aodv/aodv-rqueue.cc @@ -122,12 +122,14 @@ RequestQueue::DropPacketWithDst (Ipv4Address dst ) NS_LOG_FUNCTION (this << dst); Purge (); const Ipv4Address addr = dst; - std::vector::iterator i = std::remove_if (m_queue.begin (), m_queue.end (), std::bind2nd (std::ptr_fun (RequestQueue::IsEqual), dst)); - for (std::vector::iterator j = i; j != m_queue.end (); ++j) + for (std::vector::iterator i = m_queue.begin (); i != m_queue.end (); ++i) { - Drop (*j, "DropPacketWithDst "); + if (IsEqual (*i, dst)) + { + Drop (*i, "DropPacketWithDst "); + } } - m_queue.erase (i, m_queue.end ()); + m_queue.erase (std::remove_if (m_queue.begin (), m_queue.end (), std::bind2nd (std::ptr_fun (RequestQueue::IsEqual), dst)), m_queue.end ()); } bool @@ -165,12 +167,15 @@ struct IsExpired void RequestQueue::Purge () { - std::vector::iterator i = std::remove_if (m_queue.begin (), m_queue.end (), IsExpired ()); - for (std::vector::iterator j = i; j < m_queue.end (); ++j) + IsExpired pred; + for (std::vector::iterator i = m_queue.begin (); i != m_queue.end (); ++i) { - Drop (*j, "Drop outdated packet "); + if (pred (*i)) + { + Drop (*i, "Drop outdated packet "); + } } - m_queue.erase (i, m_queue.end ()); + m_queue.erase (std::remove_if (m_queue.begin (), m_queue.end (), pred), m_queue.end ()); } void diff --git a/src/routing/aodv/aodv-rqueue.h b/src/routing/aodv/aodv-rqueue.h index e6f270fcb..ef060304a 100644 --- a/src/routing/aodv/aodv-rqueue.h +++ b/src/routing/aodv/aodv-rqueue.h @@ -122,7 +122,7 @@ private: uint32_t m_maxLen; /// The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds. Time m_queueTimeout; - static bool IsEqual(QueueEntry en, const Ipv4Address dst) { return (en.GetIpv4Header ().GetDestination () == dst); } + static bool IsEqual(QueueEntry en, const Ipv4Address dst) { return (en.GetIpv4Header ().GetDestination () == dst); } }; diff --git a/src/routing/aodv/id-cache.cc b/src/routing/aodv/id-cache.cc index a554d4ebf..8b7aa218d 100644 --- a/src/routing/aodv/id-cache.cc +++ b/src/routing/aodv/id-cache.cc @@ -54,8 +54,7 @@ IdCache::LookupId (Ipv4Address addr, uint32_t id ) void IdCache::Purge () { - std::vector::iterator i = remove_if (m_idCache.begin (), m_idCache.end (), IsExpired ()); - m_idCache.erase (i, m_idCache.end ()); + m_idCache.erase (remove_if (m_idCache.begin (), m_idCache.end (), IsExpired ()), m_idCache.end ()); } uint32_t