⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swarm_rtable.h

📁 采用蚂蚁算法实现ad hoc网络路由协议,平台为ns2
💻 H
字号:
#ifndef __swarm_rtable_h__#define __swarm_rtable_h__#include <cmu-trace.h>#include <map>#include <list>#include <aodv/aodv_rqueue.h>class SWARM;class SwarmEnvironment;class swarm_nexthop{  public:    double lastAdvertised;    double lastAdvertisedTime;    swarm_nexthop();    double getCurrentEstimate();    void setLastAdvertised(double value);};// A COUNTER WHICH DISCARDS DATA AFTER AN AMOUNT OF TIMEclass timed_counter{  protected:    int numberSamples;    double historyToKeep;        list<int> data;    int currentCount;    double lastPushBack;    int totalCount;    int samplesStored;    void check();      public:    timed_counter(double historyToKeep, int numberSamples);    ~timed_counter()    {    }    void increment();    int getCurrentValue();    double getHistoryLength();};class swarm_neighbour{  public:    timed_counter numberAttemptedSend;    timed_counter numberFailedSend;    timed_counter numberReceived;    swarm_neighbour();    void onSuccessfulReceive() {numberReceived.increment();}    void onAttemptingSend() {numberAttemptedSend.increment();}    void onFailedSend() {numberFailedSend.increment();}    void onPromiscuousReceiveFrom() {numberReceived.increment();}    double getProbabilitySuccessfulUnicast();};class swarm_rt_entry{    friend class SwarmEnvironment;  protected:    map < nsaddr_t, swarm_nexthop > next_hops;    map < int, double > sequenceNumberBestValue;    int maxSequenceNumberSeen;    int minSequenceNumberSeen;    int numberReceiveBeforeProactiveResponse;  public:    SwarmEnvironment *env;    bool isThisNode;    double currentEstimate;    double lastAdvertised;    double lastAdvertisedTime;    double lastForwardedPacketTowards;    double getQValue(nsaddr_t hop);    void fixSeqnoMemory();    void update();  public:    nsaddr_t pickNextHop();    void onPromiscuousReceiveFrom(const Packet * p);    void onPromiscuousReceiveTo(const Packet * p);    void onNextHopSendFailed(nsaddr_t nextHop);    void onReceive(const Packet * p);    void onForwardingFrom(const Packet * p);    void removeNextHop(nsaddr_t address);    void onSendToDestination();    bool isProactiveResponseNeeded();    bool isNewOrImproved(const Packet * p);    bool hasSomeRoute();    swarm_rt_entry();     ~swarm_rt_entry()    {    }};class SwarmEnvironmentMaintenanceEvent: public Event{public:    nsaddr_t dest;};class SwarmEnvironment: public Handler{  private:    map < nsaddr_t, swarm_rt_entry > routingTable;    timed_counter packetsReceived;  public:    SwarmEnvironment();          SWARM * agent;    nsaddr_t networkId;         // IP Address of this node    u_int32_t seqno;            // Sequence Number    map < nsaddr_t, swarm_neighbour > neighbours;    aodv_rqueue rqueue;    swarm_rt_entry &getRoutingEntry(nsaddr_t dest);    void dump(nsaddr_t dest);    void drop(Packet * p, const char *reason);    void sendPacket(Packet * p, double delay);    void receivePacketLocally(Packet * p);    void log(string s);    void scheduleCallback(nsaddr_t address, double delay);    bool hasPacketsQueuedFor(nsaddr_t address);    void queuePacket(Packet *p);    void releasePacketsFor(nsaddr_t address);    void sendControlPacketTo(nsaddr_t address);    void handle(Event *);    void incrementPacketsReceived();    double getPacketReceiveRate();    double getCongestionRelatedSuccessProbability();};#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -