diff --git a/src/routing/aodv/aodv-routing-protocol.cc b/src/routing/aodv/aodv-routing-protocol.cc index f9064d62a..3ffe65697 100644 --- a/src/routing/aodv/aodv-routing-protocol.cc +++ b/src/routing/aodv/aodv-routing-protocol.cc @@ -542,16 +542,12 @@ RoutingProtocol::SendReply (RreqHeader const & rreqHeader, aodv_rt_entry const & } void -RoutingProtocol::RecvReply (Ptr p, Ipv4Address my ,Ipv4Address src) +RoutingProtocol::RecvReply (Ptr p, Ipv4Address receiverIfaceAddr ,Ipv4Address senderIfaceAddr) { -#if 0 - TypeHeader tHeader(AODVTYPE_RREP); - p->RemoveHeader(tHeader); RrepHeader rrepHeader; p->RemoveHeader(rrepHeader); - uint8_t hop = rrepHeader.GetHopCount(); - hop++; + uint8_t hop = rrepHeader.GetHopCount() + 1; rrepHeader.SetHopCount(hop); aodv_rt_entry toDst; @@ -571,14 +567,9 @@ RoutingProtocol::RecvReply (Ptr p, Ipv4Address my ,Ipv4Address src) // The forward route for this destination is created if it does not already exist. if(!rtable.rt_lookup(rrepHeader.GetDst(), toDst)) { - toDst.SetDst(rrepHeader.GetDst()); - toDst.SetFlag(RTF_UP); - toDst.SetHop(hop); - toDst.SetInterface(my); - toDst.SetLifeTime(Simulator::Now() + rrepHeader.GetLifeTime()); - toDst.SetNextHop(src); - toDst.SetSeqNo(rrepHeader.GetDstSeqno()); - toDst.SetValidSeqNo(true); + aodv_rt_entry newEntry(/*dst=*/rrepHeader.GetDst(), /*validSeqNo=*/true, /*seqno=*/rrepHeader.GetDstSeqno(), /*iface=*/receiverIfaceAddr, + /*hop=*/hop, /*nextHop=*/senderIfaceAddr, /*lifeTime=*/Simulator::Now() + rrepHeader.GetLifeTime()); + rtable.rt_add(newEntry); } // The existing entry is updated only in the following circumstances: else @@ -590,9 +581,10 @@ RoutingProtocol::RecvReply (Ptr p, Ipv4Address my ,Ipv4Address src) toDst.SetSeqNo(rrepHeader.GetDstSeqno()); toDst.SetValidSeqNo(true); toDst.SetFlag(RTF_UP); - toDst.SetNextHop(src); + toDst.SetNextHop(senderIfaceAddr); toDst.SetLifeTime(Simulator::Now() + rrepHeader.GetLifeTime()); toDst.SetHop(hop); + rtable.Update(rrepHeader.GetDst(), toDst); } // (ii) the Destination Sequence Number in the RREP is greater than // the node's copy of the destination sequence number and the @@ -601,9 +593,10 @@ RoutingProtocol::RecvReply (Ptr p, Ipv4Address my ,Ipv4Address src) { toDst.SetSeqNo(rrepHeader.GetDstSeqno()); toDst.SetFlag(RTF_UP); - toDst.SetNextHop(src); + toDst.SetNextHop(senderIfaceAddr); toDst.SetLifeTime(Simulator::Now() + rrepHeader.GetLifeTime()); toDst.SetHop(hop); + rtable.Update(rrepHeader.GetDst(), toDst); } else { @@ -611,55 +604,67 @@ RoutingProtocol::RecvReply (Ptr p, Ipv4Address my ,Ipv4Address src) if( (rrepHeader.GetDstSeqno() == toDst.GetSeqNo()) && (toDst.GetFlag() != RTF_UP) ) { toDst.SetFlag(RTF_UP); - toDst.SetNextHop(src); + toDst.SetNextHop(senderIfaceAddr); toDst.SetLifeTime(Simulator::Now() + rrepHeader.GetLifeTime()); toDst.SetHop(hop); + rtable.Update(rrepHeader.GetDst(), toDst); } // (iv) the sequence numbers are the same, and the New Hop Count is // smaller than the hop count in route table entry. else if( (rrepHeader.GetDstSeqno() == toDst.GetSeqNo()) && (hop < toDst.GetHop()) ) { toDst.SetFlag(RTF_UP); - toDst.SetNextHop(src); + toDst.SetNextHop(senderIfaceAddr); toDst.SetLifeTime(Simulator::Now() + rrepHeader.GetLifeTime()); toDst.SetHop(hop); + rtable.Update(rrepHeader.GetDst(), toDst); } } - if(my == rrepHeader.GetOrigin()) - { + if(receiverIfaceAddr == rrepHeader.GetOrigin()) + { //TODO may be send messeges from queue return; - } + } else - { + { aodv_rt_entry toOrigin; if(!rtable.rt_lookup(rrepHeader.GetOrigin(), toOrigin)) - { -// imposible! -// drop(); + { + // imposible! + // drop(); return; - } + } + rtable.rt_lookup(rrepHeader.GetDst(), toDst); toDst.pc_insert(toOrigin.GetNextHop()); - if( toOrigin.GetLifeTime() < (Simulator::Now() + ACTIVE_ROUTE_TIMEOUT) ) - toOrigin.SetLifeTime(Simulator::Now() + ACTIVE_ROUTE_TIMEOUT); + rtable.Update(rrepHeader.GetDst(), toDst); + + if ( toOrigin.GetLifeTime() < (Simulator::Now() + ACTIVE_ROUTE_TIMEOUT) ) + { + toOrigin.SetLifeTime(Simulator::Now() + ACTIVE_ROUTE_TIMEOUT); + rtable.Update(toOrigin.GetDst(), toOrigin); + } aodv_rt_entry toNextHopToDst; - aodv_rt_entry toNextHopToOrigin; rtable.rt_lookup(toDst.GetNextHop(), toNextHopToDst); toNextHopToDst.pc_insert(toOrigin.GetNextHop()); + rtable.Update(toDst.GetNextHop(), toNextHopToDst); // TODO add operation over unidirctinal links p->AddHeader(rrepHeader); + TypeHeader tHeader(AODVTYPE_RREP); p->AddHeader(tHeader); - std::map< Ipv4Address, Ptr >::const_iterator j = m_addressSocket.find(toOrigin.GetInterface()); - j->second->Send(p); - } + for (std::map, Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin(); j != m_socketAddresses.end(); ++j) + { + if(j->second.GetLocal() == toOrigin.GetInterface()) + j->first->Send(p); + } + } } -#endif + } void diff --git a/src/routing/aodv/aodv-rtable.cc b/src/routing/aodv/aodv-rtable.cc index 3e50423f0..8889467db 100644 --- a/src/routing/aodv/aodv-rtable.cc +++ b/src/routing/aodv/aodv-rtable.cc @@ -144,7 +144,6 @@ aodv_rtable::Update(Ipv4Address dst, aodv_rt_entry & rt) return true; } - void aodv_rtable::SetEntryState (Ipv4Address id, uint8_t state) { @@ -152,6 +151,19 @@ aodv_rtable::SetEntryState (Ipv4Address id, uint8_t state) if (i != rthead.end()) (*i).second.rt_flags = state; } +void +aodv_rtable::Print(std::ostream &os) const +{ + os << "AODV Routing table\n" + << "Destination\tGateway\tInterface\tExpire\n"; + for (std::map::const_iterator i = rthead.begin(); i != rthead.end(); ++i) + { + os << i->first << "\t\t" << i->second.GetNextHop() << "\t\t" << i->second.GetInterface() << "\t\t" << i->second.GetLifeTime() << "\n"; + } + +} + + #ifdef RUN_SELF_TESTS /// Unit test for aodv_rqueue struct AodvRtableTest : public Test @@ -187,6 +199,7 @@ AodvRtableTest::RunTests () aodv_rtable rtable; rtable.rt_add(entry2); + rtable.Print(std::cout); entry2.SetLifeTime(Seconds(10)); NS_TEST_ASSERT(rtable.Update(entry2.GetDst(), entry2)); NS_TEST_ASSERT(rtable.rt_lookup(dst2, entry1)); diff --git a/src/routing/aodv/aodv-rtable.h b/src/routing/aodv/aodv-rtable.h index bb9fe682d..1725472fd 100644 --- a/src/routing/aodv/aodv-rtable.h +++ b/src/routing/aodv/aodv-rtable.h @@ -194,6 +194,8 @@ public: bool Update(Ipv4Address dst, aodv_rt_entry & rt); /// Set routing table entry flags void SetEntryState (Ipv4Address dst, uint8_t state /*TODO use enum*/); + /// Print routing table + void Print(std::ostream &os) const; private: std::map rthead;