BroadcastIdCache methods and SendRequest() added

This commit is contained in:
Borovkova Elena
2009-07-09 19:52:34 +04:00
parent 1042689880
commit 3fa9b9df05
4 changed files with 144 additions and 42 deletions

View File

@@ -49,15 +49,6 @@ enum MessageType
class TypeHeader : public Header
{
public:
enum MessageType
{
AODVTYPE_RREQ = 0x02, //!< AODVTYPE_RREQ
AODVTYPE_RREP = 0x04, //!< AODVTYPE_RREP
AODVTYPE_RERR = 0x08, //!< AODVTYPE_RERR
AODVTYPE_RREP_ACK = 0x10//!< AODVTYPE_RREP_ACK
};
TypeHeader(uint8_t t);
///\name Header serialization/deserialization

View File

@@ -48,9 +48,33 @@ namespace aodv
{
NS_OBJECT_ENSURE_REGISTERED (RoutingProtocol);
void
RoutingProtocol::InsertBroadcastId (Ipv4Address id, uint32_t bid)
{
if(LookupBroadcastId(id, bid) )
return;
struct BroadcastId broadcastId = {id, bid,BCAST_ID_SAVE + Simulator::Now()};
bi.push_back(broadcastId);
}
bool
RoutingProtocol::LookupBroadcastId (Ipv4Address id, uint32_t bid)
{
std::vector<BroadcastId>::const_iterator i;
for(i = bi.begin(); i != bi.end(); ++i)
if(i->src == id && i->id == bid)
return true;
return false;
}
void
RoutingProtocol::PurgeBroadcastId ()
{
std::vector<BroadcastId>::iterator i = remove_if(bi.begin(), bi.end(), IsExpired());
bi.erase(i, bi.end());
}
RoutingProtocol::RoutingProtocol() :
BCAST_ID_SAVE (Seconds (6)),
HELLO_INTERVAL (Seconds (1)),
ALLOWED_HELLO_LOSS (2),
BAD_LINK_LIFETIME (Seconds (3)),
FREQUENCY (Seconds (0.5)),
@@ -60,6 +84,7 @@ RoutingProtocol::RoutingProtocol() :
ntimer(Timer::REMOVE_ON_DESTROY),
rtimer(Timer::REMOVE_ON_DESTROY),
lrtimer(Timer::REMOVE_ON_DESTROY)
{
MaxHelloInterval = Scalar(1.25) * HELLO_INTERVAL;
MinHelloInterval = Scalar(0.75) * HELLO_INTERVAL;
@@ -69,9 +94,18 @@ TypeId
RoutingProtocol::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::aodv::RoutingProtocol")
.SetParent<Ipv4RoutingProtocol> ()
.AddConstructor<RoutingProtocol> ()
;
.SetParent<Ipv4RoutingProtocol> ()
.AddConstructor<RoutingProtocol> ()
.AddAttribute ("HelloInterval", "HELLO messages emission interval.",
TimeValue (Seconds (1)),
MakeTimeAccessor (&RoutingProtocol::HELLO_INTERVAL),
MakeTimeChecker ())
.AddAttribute ("Broadcast id save", "Broadcast id save interval.",
TimeValue (Seconds (6)),
MakeTimeAccessor (&RoutingProtocol::BCAST_ID_SAVE),
MakeTimeChecker ())
;
return tid;
}
@@ -120,8 +154,8 @@ RoutingProtocol::SetIpv4 (Ptr<Ipv4> ipv4)
ntimer.SetFunction (& RoutingProtocol::NeighborTimerExpire, this);
rtimer.SetFunction (& RoutingProtocol::RouteCacheTimerExpire, this);
lrtimer.SetFunction (& RoutingProtocol::LocalRepairTimerExpire, this);
htimer.SetFunction (& RoutingProtocol::HelloTimerExpire, this);
htimer.SetFunction (& RoutingProtocol::LocalRepairTimerExpire, this);
m_ipv4 = ipv4;
Simulator::ScheduleNow (&RoutingProtocol::Start, this);
}
@@ -249,10 +283,71 @@ RoutingProtocol::SendHello ()
// TODO send hello packet from interfaces
}
// TODO add use an expanding ring search technique
void
RoutingProtocol::SendRequest (Ipv4Address dst)
RoutingProtocol::SendRequest (Ipv4Address dst, bool G, bool D)
{
// TODO
TypeHeader tHeader(AODVTYPE_RREQ);
Ipv4Header ipv4Header;
ipv4Header.SetTtl(NETWORK_DIAMETER);
ipv4Header.SetDestination(dst);
//ipv4Header.SetProtocol( ? );
RreqHeader h;
h.SetDst(dst);
aodv_rt_entry rt;
if(rtable.rt_lookup(dst, rt))
h.SetHopCount(rt.GetLastValidHopCount());
else
h.SetUnknownSeqno(true);
if(G)
h.SetGratiousRrep(true);
if(D)
h.SetDestinationOnly(true);
seqno++;
h.SetSrcSeqno(seqno);
bid++;
h.SetId(bid);
h.SetHopCount(0);
Ipv4Address loopback ("127.0.0.1");
std::map<Ipv4Address, Timer>::const_iterator i;
for (uint32_t k = 0; k < m_ipv4->GetNInterfaces (); k++)
{
Ipv4Address addr = m_ipv4->GetAddress (k, 0).GetLocal ();
if (addr != loopback)
{
ipv4Header.SetSource(addr);
h.SetSrc(addr);
InsertBroadcastId(addr, bid);
Ptr<Packet> packet = Create<Packet> ();
packet->AddHeader(ipv4Header);
packet->AddHeader(tHeader);
packet->AddHeader(h);
// i = htimer.find(addr);
// if(i == htimer.end())
// {
// Timer t;
// t.SetDelay(HELLO_INTERVAL);
// t.Schedule();
// htimer.insert(std::make_pair(addr, t));
// }
// else
// {
// i->second.SetDelay(HELLO_INTERVAL);
// t.Schedule();
// }
std::map< Ipv4Address, Ptr<Socket> >::const_iterator j = m_addressSocket.find(addr);
j->second->Send(packet);
}
}
btimer.SetDelay(BCAST_ID_SAVE);
btimer.Schedule();
htimer.SetDelay(HELLO_INTERVAL);
htimer.Schedule();
}
void

View File

@@ -41,6 +41,15 @@ namespace ns3
{
namespace aodv
{
/// Various constants used for the expanding ring search
//\{
#define TTL_START 5 /// (?) in RFC 1
#define TTL_THRESHOLD 7
#define TTL_INCREMENT 2
#define NETWORK_DIAMETER 30 /// Should be set by the user
//\}
/// List of neighbors TODO document & move inside protocol
class NeighborList
{
@@ -61,23 +70,7 @@ private:
std::vector<Neighbor> nb;
};
/// Known broadcast ID cache. TODO document & move inside protocol
class BroadcastIdCache
{
public:
void Insert (Ipv4Address id, u_int32_t bid);
bool Lookup (Ipv4Address id, u_int32_t bid);
void Purge ();
private:
struct BroadcastId
{
Ipv4Address src;
uint32_t id;
Time expire;
};
std::vector<BroadcastId> bi;
};
/**
* \ingroup aodv
@@ -106,6 +99,7 @@ public:
//\}
private:
///\name Protocol parameters. TODO document
//\{
Time BCAST_ID_SAVE;
@@ -116,25 +110,47 @@ private:
Time MinHelloInterval; // (0.75 * HELLO_INTERVAL)
Time FREQUENCY;
//\}
/// \name Handle Broadcast sequence number cache
//\{
void InsertBroadcastId (Ipv4Address id, uint32_t bid);
bool LookupBroadcastId (Ipv4Address id, uint32_t bid);
void PurgeBroadcastId ();
struct BroadcastId
{
Ipv4Address src;
uint32_t id;
Time expire;
};
struct IsExpired
{
bool operator()(const struct BroadcastId & b) const
{
return (b.expire < Simulator::Now());
}
};
std::vector<BroadcastId> bi;
//\}
/// IP protocol
Ptr<Ipv4> m_ipv4;
/// UDP socket per each IP interface, map socket -> iface
std::map< Ptr<Socket>, Ipv4Address > m_socketAddresses;
std::map< Ipv4Address, Ptr<Socket> > m_addressSocket;
/// Routing table
aodv_rtable rtable;
/// A "drop-front" queue used by the routing layer to buffer packets to which it does not have a route.
aodv_rqueue rqueue;
/// List of neighbors (aka neighbors cache). TODO: separate list for each interface???
NeighborList nbhead;
/// Broadcast sequence numbers cache
BroadcastIdCache bihead;
/// Preq broadcast ID
/// Rreq broadcast ID
uint32_t bid;
/// Sequence Number (???)
uint32_t seqno;
private:
/// Start protocol operation
void Start ();
/// Start local route repair procedure
@@ -161,7 +177,7 @@ private:
/// Send hello. TODO send independent hello per interface
void SendHello ();
/// Send RREQ
void SendRequest (Ipv4Address dst);
void SendRequest (Ipv4Address dst, bool G, bool D);
/// Send RREP
void SendReply (Ipv4Address ipdst, uint32_t hop_count,
Ipv4Address rpdst, uint32_t rpseq, Time lifetime);

View File

@@ -78,7 +78,8 @@ public:
*/
bool pc_empty() const;
//\}
/// Return last valid hop count
uint16_t GetLastValidHopCount() { return rt_last_hop_count; }
/// Mark entry as "down" (i.e. disable it)
void Down ();
@@ -98,7 +99,6 @@ public:
private:
friend class aodv_rtable;
friend class RoutingProtocol;
/// Destination address
Ipv4Address rt_dst;