From 2999079c837c701fbc9eebe0b07fe1ca8d79f0cf Mon Sep 17 00:00:00 2001 From: Borovkova Elena Date: Tue, 18 Aug 2009 14:48:12 +0400 Subject: [PATCH] problem with protocol number fixed --- src/internet-stack/icmpv4-l4-protocol.cc | 1 + src/internet-stack/ipv4-raw-socket-impl.cc | 1 + src/internet-stack/tcp-l4-protocol.cc | 2 ++ src/internet-stack/udp-socket-impl.cc | 1 + src/routing/aodv/aodv-routing-protocol.cc | 34 ++++++++++++++++------ src/routing/aodv/aodv-routing-protocol.h | 2 +- src/routing/aodv/aodv-rqueue.cc | 8 +++-- src/routing/aodv/aodv-rqueue.h | 4 +-- 8 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/internet-stack/icmpv4-l4-protocol.cc b/src/internet-stack/icmpv4-l4-protocol.cc index 93bd54467..d62c8cd79 100644 --- a/src/internet-stack/icmpv4-l4-protocol.cc +++ b/src/internet-stack/icmpv4-l4-protocol.cc @@ -86,6 +86,7 @@ Icmpv4L4Protocol::SendMessage (Ptr packet, Ipv4Address dest, uint8_t typ NS_ASSERT (ipv4 != 0 && ipv4->GetRoutingProtocol () != 0); Ipv4Header header; header.SetDestination (dest); + header.SetProtocol (PROT_NUMBER); Socket::SocketErrno errno_; Ptr route; uint32_t oif = 0; //specify non-zero if bound to a source address diff --git a/src/internet-stack/ipv4-raw-socket-impl.cc b/src/internet-stack/ipv4-raw-socket-impl.cc index 45302d6e8..1a9777246 100644 --- a/src/internet-stack/ipv4-raw-socket-impl.cc +++ b/src/internet-stack/ipv4-raw-socket-impl.cc @@ -174,6 +174,7 @@ Ipv4RawSocketImpl::SendTo (Ptr p, uint32_t flags, { Ipv4Header header; header.SetDestination (dst); + header.SetProtocol (m_protocol); SocketErrno errno_ = ERROR_NOTERROR;//do not use errno as it is the standard C last error number Ptr route; uint32_t oif = 0; //specify non-zero if bound to a source address diff --git a/src/internet-stack/tcp-l4-protocol.cc b/src/internet-stack/tcp-l4-protocol.cc index 433ea7dbd..f8497f5d3 100644 --- a/src/internet-stack/tcp-l4-protocol.cc +++ b/src/internet-stack/tcp-l4-protocol.cc @@ -549,6 +549,7 @@ TcpL4Protocol::Send (Ptr packet, // should be cached. Ipv4Header header; header.SetDestination (daddr); + header.SetProtocol (PROT_NUMBER); Socket::SocketErrno errno_; Ptr route; uint32_t oif = 0; //specify non-zero if bound to a source address @@ -587,6 +588,7 @@ TcpL4Protocol::SendPacket (Ptr packet, TcpHeader outgoingHeader, // should be cached. Ipv4Header header; header.SetDestination (daddr); + header.SetProtocol (PROT_NUMBER); Socket::SocketErrno errno_; Ptr route; uint32_t oif = 0; //specify non-zero if bound to a source address diff --git a/src/internet-stack/udp-socket-impl.cc b/src/internet-stack/udp-socket-impl.cc index c2a52df43..bb003021d 100644 --- a/src/internet-stack/udp-socket-impl.cc +++ b/src/internet-stack/udp-socket-impl.cc @@ -403,6 +403,7 @@ UdpSocketImpl::DoSendTo (Ptr p, Ipv4Address dest, uint16_t port) { Ipv4Header header; header.SetDestination (dest); + header.SetProtocol (UdpL4Protocol::PROT_NUMBER); Socket::SocketErrno errno_; Ptr route; uint32_t oif = 0; //specify non-zero if bound to a source address diff --git a/src/routing/aodv/aodv-routing-protocol.cc b/src/routing/aodv/aodv-routing-protocol.cc index 8424a1fee..efc3aee2f 100644 --- a/src/routing/aodv/aodv-routing-protocol.cc +++ b/src/routing/aodv/aodv-routing-protocol.cc @@ -178,7 +178,7 @@ RoutingProtocol::Start () Ptr RoutingProtocol::RouteOutput (Ptr p, const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr ) { - NS_LOG_FUNCTION (this << p->GetUid() << header.GetDestination()); + NS_LOG_FUNCTION (this << header.GetDestination()); if (m_socketAddresses.empty ()) { sockerr = Socket::ERROR_NOROUTETOHOST; @@ -203,9 +203,17 @@ RoutingProtocol::RouteOutput (Ptr p, const Ipv4Header &header, uint32_t } else { - QueueEntry newEntry (p, header, m_scb, m_ecb); - m_queue.Enqueue (newEntry); - if (rt.GetFlag () == INVALID) + bool result = true; + // May be null pointer (e.g. tcp-socket give null pointer) + if (p != Ptr ()) + { + QueueEntry newEntry (p, header, m_scb, m_ecb); + result = m_queue.Enqueue (newEntry); + if (result) + NS_LOG_LOGIC ("Add packet " << p->GetUid() << " to queue"); + + } + if (rt.GetFlag () == INVALID && result) { m_routingTable.SetEntryState (dst, IN_SEARCH); SendRequest (dst); @@ -214,9 +222,17 @@ RoutingProtocol::RouteOutput (Ptr p, const Ipv4Header &header, uint32_t } else { - QueueEntry newEntry (p, header, m_scb, m_ecb); - m_queue.Enqueue (newEntry); - SendRequest (dst); + bool result = true; + if (p != Ptr ()) + { + QueueEntry newEntry (p, header, m_scb, m_ecb); + // Some protocols may ask route several times for a single packet. + result = m_queue.Enqueue (newEntry); + if (result) + NS_LOG_LOGIC ("Add packet " << p->GetUid() << " to queue"); + } + if (result) + SendRequest (dst); } return route; } @@ -1196,12 +1212,12 @@ RoutingProtocol::SendPacketFromQueue (Ipv4Address dst, Ptr route ) void RoutingProtocol::Send (Ptr route, Ptr packet, const Ipv4Header & header ) { - NS_LOG_FUNCTION(this << packet->GetUid() << (uint16_t) header.GetProtocol()); + NS_LOG_FUNCTION (this << packet->GetUid() << (uint16_t) header.GetProtocol()); Ptr l3 = m_ipv4->GetObject (); NS_ASSERT(l3 != 0); Ptr p = packet->Copy (); // TODO know protocol number - l3->Send (p, route->GetSource (), header.GetDestination (), 1, route); + l3->Send (p, route->GetSource (), header.GetDestination (), header.GetProtocol(), route); } void diff --git a/src/routing/aodv/aodv-routing-protocol.h b/src/routing/aodv/aodv-routing-protocol.h index 5dcb78ea6..f61cc0d20 100644 --- a/src/routing/aodv/aodv-routing-protocol.h +++ b/src/routing/aodv/aodv-routing-protocol.h @@ -182,7 +182,7 @@ private: /// Receive RREP void RecvReply (Ptr p, Ipv4Address my ,Ipv4Address src); /// Receive RREP_ACK - void RecvReplyAck(Ipv4Address neighbor); + void RecvReplyAck (Ipv4Address neighbor); /// Receive RERR from node with address src void RecvError (Ptr p, Ipv4Address src); //\} diff --git a/src/routing/aodv/aodv-rqueue.cc b/src/routing/aodv/aodv-rqueue.cc index dcdbad7d7..a314c3d6d 100644 --- a/src/routing/aodv/aodv-rqueue.cc +++ b/src/routing/aodv/aodv-rqueue.cc @@ -98,18 +98,22 @@ RequestQueue::GetSize () return m_queue.size (); } -void +bool RequestQueue::Enqueue (QueueEntry & entry ) { Purge (); + for (std::vector::const_iterator i = m_queue.begin (); i != m_queue.end (); ++i) + if ((i->GetPacket ()->GetUid () == entry.GetPacket ()->GetUid ()) && + (i->GetIpv4Header ().GetDestination () == entry.GetIpv4Header ().GetDestination ())) + return false; entry.SetExpireTime (m_queueTimeout); - if (m_queue.size () == m_maxLen) { Drop (m_queue.front (), "Drop the most aged packet"); // Drop the most aged packet m_queue.erase (m_queue.begin ()); } m_queue.push_back (entry); + return true; } void diff --git a/src/routing/aodv/aodv-rqueue.h b/src/routing/aodv/aodv-rqueue.h index 1d054294a..e6f270fcb 100644 --- a/src/routing/aodv/aodv-rqueue.h +++ b/src/routing/aodv/aodv-rqueue.h @@ -94,8 +94,8 @@ class RequestQueue public: /// Default c-tor RequestQueue (uint32_t maxLen, Time routeToQueueTimeout) : m_maxLen (maxLen), m_queueTimeout (routeToQueueTimeout) {} - /// Push entry in queue. - void Enqueue (QueueEntry & entry); + /// Push entry in queue, if there is no entry with the same packet and destination address in queue. + bool Enqueue (QueueEntry & entry); /// Return first found (the earliest) entry for given destination bool Dequeue (Ipv4Address dst, QueueEntry & entry); /// Remove all packets with destination IP address dst