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

📄 almah.h

📁 为NS2仿真中的一个overlay多播协议的协议模块
💻 H
字号:
/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef ns_almah_h
#define ns_almah_h

/**Claudio Loreti
  *@author
  */
#include "agent.h"  
#include "packet.h"
#include "tclcl.h"
#include "address.h"
#include "ip.h"
#include "obamp/obamp_rtable.h"
#include "almah-packet.h"
#include "basetrace.h"
#include "obamp/utility/Prim.h"


class ALMAH_Agent;


/*
  Timers (SendRequest, ....)
*/
class ALMAHSendRequestTimer : public Handler {
		friend class ALMAH_Agent;
public:
        ALMAHSendRequestTimer(ALMAH_Agent* a) : agent(a) {this->count=0;timeout1=0;timeout2=0;request_number=0;is_busy = false;}
        void	handle(Event*);
private:
        ALMAH_Agent    *agent;
	      Event	intr;
        int count;
        double timeout1;//timeout of SendRequest periodic
        double timeout2;//timeout of incremental
        int request_number;//number of requests in a SendRequest period: it is set to zero at the start of timeout1 period
		bool is_busy;
       
};


class ALMAHSendSwitchRequestTimer : public Handler {
public:
        ALMAHSendSwitchRequestTimer(ALMAH_Agent* a) : agent(a) {this->count=0;timeout1=0;timeout2=0;request_number=0;initialize=false;}
        void	handle(Event*);
private:
        ALMAH_Agent    *agent;
	      Event	intr;
        int count;
        double timeout1;//timeout of SendRequest periodic
        double timeout2;//timeout of incremental
        int request_number;//number of requests in a SendRequest period: it is set to zero at the start of timeout1 period
		//claudio broadcast avoidance
        bool initialize;
        //claudio end broadcast avoidance
        
};

class ALMAHPingTimer : public Handler {
public:
        ALMAHPingTimer(ALMAH_Agent* a) : agent(a) {}
        void	handle(Event*);
private:
        ALMAH_Agent    *agent;
	      Event	intr;
        

};

/*class PingDestination : public Event {
public :
	int dst;
};*/

class ALMAHSwitchEndTimer : public Handler {
public:
        ALMAHSwitchEndTimer(ALMAH_Agent* a) : agent(a) {}
        void	handle(Event*);
private:
        ALMAH_Agent    *agent;
	      Event	intr;

};


class ALMAH_LOOP_RESET : public Handler {
		friend class ALMAH_Agent;
public:
        ALMAH_LOOP_RESET(ALMAH_Agent* a) : agent(a) {}
        void	handle(Event*);
        
private:
        ALMAH_Agent    *agent;
	    Event	intr;        
};

class ALMAHSwitchStartTimer : public Handler {
public:
        ALMAHSwitchStartTimer(ALMAH_Agent* a) : o_agent(a) {}
        void	handle(Event*);

private:
        ALMAH_Agent    *o_agent;
        
};



class ALMAH_TOPOLOGY_REQUEST_TIMER : public Handler {
public:
        ALMAH_TOPOLOGY_REQUEST_TIMER(ALMAH_Agent* a) : agent(a) {}
        void	handle(Event*);
private:
        ALMAH_Agent    *agent;
	      Event	intr;
        

};


class ALMAHRefreshTopologyTimer : public Handler {
public:
        ALMAHRefreshTopologyTimer(ALMAH_Agent* a) : agent(a) {}
        void	handle(Event*);		

private:
        ALMAH_Agent    *agent;
	    Event	intr;
		
};

class ALMAHJoinACKNotifyTimer : public Handler {
public:
        ALMAHJoinACKNotifyTimer(ALMAH_Agent* a) : agent(a) {this->count=0;timeout1=0;timeout2=0;request_number=0;initialize=false;}
        void	handle(Event*);
private:
        ALMAH_Agent    *agent;
	      Event	intr;
        int count;
        double timeout1;//timeout of SendRequest periodic
        double timeout2;//timeout of incremental
        int request_number;//number of requests in a SendRequest period: it is set to zero at the start of timeout1 period
		//claudio broadcast avoidance
        bool initialize;
        //claudio end broadcast avoidance
        
};


class ALMAH_Agent : public Agent  {		
     
     friend class ALMAHSendRequestTimer;
     friend class ALMAH_TOPOLOGY_REQUEST_TIMER;
     friend class ALMAHPingTimer;
     friend class ALMAHSendSwitchRequestTimer;
     friend class ALMAH_LOOP_RESET;
     friend class ALMAHSwitchEndTimer;
     friend class ALMAHRefreshTopologyTimer;
     friend class ALMAHJoinACKNotifyTimer;
     friend class ALMAH_Tree_Analyzer;

public:
   
  ALMAH_Agent();
  int command(int argc, const char*const* argv);

  void recv(Packet*, Handler*);
  void recv_Broadcast(Packet*, Handler*);
  void recvDATA(Packet*);	
  void recvJOIN_REQ(Packet*, Handler*);
  void recvJOIN_ACK(Packet*, Handler*);
  void recv_NACK(Packet*, Handler*);
  void pong_(Packet*, Handler*);
  void print_nam(int src_,int dst_,char* color );
  char buffer[50];
  BaseTrace       *nam_trace;
  void sendJOIN_REQ();
  void sendPING(int node, double delay);
  void sendJOIN_ACK(Packet*);
  void send_NACK(int node);
   void sendLOOP_RESET();
  void recvLOOP_RESET(Packet* pkt);
  void sendLOOP_RESET_ACK(int node);
  void recvLOOP_RESET_ACK(Packet* pkt, Handler*);
  void sendDATA();  
   void forwardBroadcast(Packet*);
   void forwardData(Packet*);	// Andrea Data
  void nb_insert(nsaddr_t id);
  OBAMP_Overlay_Neighbor*  nb_lookup(nsaddr_t id);
  void nb_delete(nsaddr_t id);
  
    /*
         * Members Management
  */
  //claudio broadcast avoidance
  void            mb_insert(nsaddr_t id);
  OBAMP_Overlay_Neighbor*       mb_lookup(nsaddr_t id);
  void  mb_delete(nsaddr_t id);
  void  mb_purge(void);
  void mb_initialize();
  void sendHello(int node);
  void sendHelloReply(int node, double send_time);
  void recvHello(Packet* pkt, Handler*);
  void recvHelloReply(Packet* pkt, Handler*);
  void recvJOINACKNotify(Packet* pkt, Handler*);
  void sendJOINACKNotify(Packet* pkt);
  void sendJOINACKConf(Packet* pkt);
  void recvJOINACKConf(Packet* pkt);

  //claudio end broadcast avoidance 
  /*
         * Broadcast Management
  */
  void            b_insert(int src, int TTL_, int Uid_);
  OBAMP_Overlay_Broadcast_Cache*       b_lookup(int Uid_);
  void            b_delete(int Uid_);
  void            b_purge(void);

  /*
         * Data Management
  */
  void            d_insert(int src, int TTL_, int Uid_); // Andrea Data
  OBAMP_Overlay_Broadcast_Cache*       d_lookup(int Uid_);
  void            d_delete(int Uid_);
  void            d_purge(void);

	
	//real Alma new
	void sendParentIn(int RV_P);
	
	void sendRequestSwitch(int);
	void sendNACK_ACK(int node);
	void sendAckSwitch(int);
	void recvRequestSwitch(Packet* p, Handler* h);
	void recvAckSwitch(Packet* p, Handler* h);
	void recvNACK_ACK(Packet* pkt, Handler*);
	void recvParentIn(Packet* p, Handler* h);
	void recvRequestTopology(Packet* pkt, Handler*);
	void sendRequestTopology(int);
	void recvTopology(Packet* pkt, Handler*);
	void sendTopology(int);
	bool NeighborDist1(int node);
	bool NeighborDistN(int node, int N);
	bool NeighborDist();
	void mb_purge_all();
	void RefreshParent();
	void switch_parent();
	//end real Alma new


  /*
    variabili di stato
  */
  //definisce lo stato dell'agent: 0 core, 1 no core
  int is_member;

  // Nam tracing facility
        Tcl_Channel namChan_;
	// Single thread ns, so we can use one global storage for all
	// node objects
	static char nwrk_[256];
	
  
  int index;// indirizzo ip di questo agente
  
  
protected:

 
  obamp_ncache         nbhead;                 // Neighbor Cache
  obamp_mcache         mbhead;                 // Member Cache
  obamp_bcache         bhead;                 // Broadcast Cache
  obamp_dcache		 dhead;					// Data Cache
  
  static ALMAH_Agent* Agents[50];
  
  ALMAHSendRequestTimer htimer;
  ALMAHSendSwitchRequestTimer ttimer_2;
  ALMAH_LOOP_RESET loopr_timer;

  ALMAHSwitchEndTimer ptimer;
  ALMAHPingTimer pingtimer;
  ALMAHSwitchStartTimer dttimer;
  ALMAHRefreshTopologyTimer rttimer;
  ALMAH_TOPOLOGY_REQUEST_TIMER topreqtimer;
  ALMAHJoinACKNotifyTimer htimer_2;
  
	
  int ON_PRINT_NAM;//if it is 1 else it print my nam: to be setted from tcl
  int ON_SendRequestTimer;//if this variable is 1 else start
  int ON_PingTimer;//if this variable is 1 else start
    
  int req_last_ttl;
  int req_ttl_;
  int req_interval;
  bool loop_free;
  bool found_neighbour;
  int I_TTL; 
  int MAX_TTL;
  int INTERVAL_TTL;
  int TREE_INT;
  int M_cast;
  FILE* DT_FILE;
  int dsn;	
  int drc;
  int parent_in;
	double parent_in_rtt;
	int parent_in_distance;

	int parent_in_switch;
	double parent_in_rtt_switch;
	int parent_in_distance_switch;

	bool switch_time_on;
	
	double threshold_level1;
	double threshold_level2;
	double threshold_level3;
	double threshold_level4;
	
	int TH_DISTANCE_SETTED;

	bool SWITCHING;	
	bool NACKING;
	bool JOIN_ACKING;
	bool REQUEST_TOPOLOGY_STATUS;
	bool LOOP_RESET_;

	lista * topology_list;
	lista * path_list;
		
	double expiry_interval;
	double mdelay;
	
	int hop_based_mode;

};

//LIST_HEAD(Analizer_acache, Overlay_Agent);

#endif

⌨️ 快捷键说明

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