udp traffic added into aodv script + problem with remove fixed

This commit is contained in:
Borovkova Elena
2009-08-19 11:51:09 +04:00
parent e18dc41f07
commit 870daaf4c3
5 changed files with 75 additions and 21 deletions

View File

@@ -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;
}
};
}

View File

@@ -188,7 +188,7 @@ RoutingProtocol::Start ()
Ptr<Ipv4Route>
RoutingProtocol::RouteOutput (Ptr<Packet> 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<const Packet> 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<WifiNetDevice> wifi = dev->GetObject<WifiNetDevice> ();
@@ -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);

View File

@@ -122,12 +122,14 @@ RequestQueue::DropPacketWithDst (Ipv4Address dst )
NS_LOG_FUNCTION (this << dst);
Purge ();
const Ipv4Address addr = dst;
std::vector<QueueEntry>::iterator i = std::remove_if (m_queue.begin (), m_queue.end (), std::bind2nd (std::ptr_fun (RequestQueue::IsEqual), dst));
for (std::vector<QueueEntry>::iterator j = i; j != m_queue.end (); ++j)
for (std::vector<QueueEntry>::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<QueueEntry>::iterator i = std::remove_if (m_queue.begin (), m_queue.end (), IsExpired ());
for (std::vector<QueueEntry>::iterator j = i; j < m_queue.end (); ++j)
IsExpired pred;
for (std::vector<QueueEntry>::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

View File

@@ -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); }
};

View File

@@ -54,8 +54,7 @@ IdCache::LookupId (Ipv4Address addr, uint32_t id )
void
IdCache::Purge ()
{
std::vector<UniqueId>::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