📄 coop-agent.h
字号:
/************************************************** * File: coop-agent.h Author: Suman Banerjee <suman@cs.umd.edu> Date: July 31, 2001 Terms: GPL NICE implementation in myns This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * **************************************************/#ifndef _COOP_AGENT_H_#define _COOP_AGENT_H_// #include <agent.h>#include "common-agent.h"#include <timer.h>#include "layerinfo.h"#include "nicenode.h"#define LOG_APP_RP#define LOG_APP_REFRESH#undef LOG_APP_REFRESH_OLD#define LOG_MESH_REFRESH#define PACKET_CACHE_SIZE 5enum CoopState { INIT, JOIN, ATTACHED, STATE_UNDEFINED};struct COOPLayerArray { LayerInfo * arr[MAX_LAYERS];}; struct PacketCache { AgentInfo ag; int seq_no; bool valid;};class coopAgent;class JoinQueryTimer : public Timer {public : coopAgent *ca; JoinQueryTimer (void) : Timer () { ca = NULL;}; JoinQueryTimer (coopAgent *CA) : Timer () { ca = CA;}; void EventHandler (void);};class HigherLayerPingIntervalTimer : public Timer {public : coopAgent *ca; HigherLayerPingIntervalTimer (void) : Timer () { ca = NULL;}; HigherLayerPingIntervalTimer (coopAgent *CA) : Timer () { ca = CA;}; void EventHandler (void);};class HigherLayerPingResponseTimer : public Timer {public : coopAgent *ca; HigherLayerPingResponseTimer (void) : Timer () { ca = NULL;}; HigherLayerPingResponseTimer (coopAgent *CA) : Timer () { ca = CA;}; void EventHandler (void);};class coopAgent : public commonAgent {private : CoopState state; /* During joins */ int curr_join_q_lid; /* The layer whose info I am currently seeking */ int target_join_q_lid; /* This is the layer I want to join */ /* I will basically get the dist info back for these members. Along * with it, I will get the cluster info of the immediate lower layer * cluster */ int m_join_resp_received; /* Used to keep track of how many more * responses are expected */ COOPLayerArray layers; JoinQueryTimer jqt; bool m_ping_in_progress; int m_ping_lid; int m_ping_resps_received; HigherLayerPingIntervalTimer m_hlpit; /* Period to do higher layer ping to find better point of attachment */ HigherLayerPingResponseTimer m_hlprt; /* How long to wait for ping resps */ int m_data_pkt_seq; /* Used to generate source data packet sequence numbers */ bool m_use_packet_cache; PacketCache m_pkt_cache_array[PACKET_CACHE_SIZE];public : // Statistics stuff double m_last_change[MAX_LAYERS]; // Last time there was a change to that // layerpublic : AgentInfo bse; // The bootstrap entity coopAgent (void); ~coopAgent (void); void start (void); void stop (void); void init (int Id, int Index, Node *N); inline void set_bse_agent(int agent_id, int node_id) { bse.agent_id = agent_id; bse.node_id = node_id; }; void specific_rx_pkt_handler (Packet *p); void specific_send_data_pkt (void); void handle_join_query_forward (AppPacket *ap); void handle_join_response (AppPacket *ap); void handle_cluster_refresh (AppPacket * ap); void handle_cluster_merge (AppPacket * ap); void handle_data_packet (AppPacket * ap); void handle_ping_query (AppPacket * ap); void handle_ping_response (AppPacket * ap); void handle_join_query_timeout (void); void handle_cluster_refresh_msg_timeout (int lid); void handle_cluster_refresh_check_timeout (int lid); void handle_higher_layer_ping_response_timeout (void); void handle_higher_layer_ping_interval_timeout (void);private : void init_layer_arr (void); bool valid_join_query_forward_packet (int qlid, bool attach); bool valid_join_response_packet (AppPacket *ap); bool valid_cluster_refresh_packet (AppPacket *ap); bool valid_cluster_merge_packet (AppPacket *ap); void send_join_query_to_cluster (int cluster_lid); void init_join_query (int dst_join_lid); void continue_join_query (int this_lid); void process_received_join_responses (void); void join_to_next_higher_layer (int lid); void delete_self_from_all_higher_layers (int lid); void delete_self_from_layer (LayerInfo *l); void split_cluster_using_two_partition (LayerInfo *l); void split_cluster_assuming_2k (LayerInfo * l); bool do_merge_to_peer (LayerInfo *l); void send_cluster_remove(LayerInfo *l, bool root_xfer); void send_root_challenge (LayerInfo *l, LayerAgentInfo *la); void do_cluster_merge_root_transfer (LayerInfo *l, AgentInfo *new_root); void do_internal_root_transfer (LayerInfo *l, LayerAgentInfo *la); void send_all_cluster_refresh_packet (LayerInfo *l, bool set_root_xfer, bool is_root, LayerAgentInfo * ignore_ag); void send_specific_cluster_refresh_packet (LayerInfo *l, LayerAgentInfo * la, bool set_root_xfer, bool is_root); double get_farthest_dist_of_member_to_agent (LayerInfo *l, LayerAgentInfo * la, bool ignore_self, bool use_only_members_known_to_self); LayerAgentInfo * find_farthest_agent_to_me_in_layer (LayerInfo * l); LayerAgentInfo * find_closest_agent_in_layer (LayerInfo * this_layer, AgentInfo * ignore_agent, bool match_join_resp); void flush_layer (int layer_id); void flush_lower_layers (LayerInfo *l); LayerAgentInfo * find_new_cluster_leader (LayerInfo *l, bool omit_self); int count_dist_known_members_for_agent (LayerAgentInfo *la, bool ignore_self); int count_dist_known_members_for_me (LayerInfo *l); bool are_agent_members_contained_in_mine (LayerInfo *l, LayerAgentInfo * la); bool are_my_members_contained_in_agent (LayerInfo *l, LayerAgentInfo * la); LayerAgentInfo * check_all_change_cluster_leader (LayerInfo *l); bool check_change_cluster_leader (LayerInfo *l, LayerAgentInfo *la_ag, double & la_dist); bool match_cluster_to_root_info (LayerInfo *l); void add_extra_members_from_alt_root_packet (AppPacket *ap, LayerInfo *l); void forward_data_packet (int src_aid, int src_nid, int src_seqno, int pred_aid, int pred_nid, bool is_source); int send_data_pkt_to_layer (LayerInfo * l, int src_aid, int src_nid, int src_seqno); void display_cluster_info (LayerInfo *l, int lid); void log_cluster_change_info (int lid); bool self_check (LayerAgentInfo * la); void cancel_higher_layer_ping_timers (void); void set_higher_layer_ping_timer (void); LayerInfo * highest_layer_self_present (void); void do_ping_higher_layer (LayerInfo *l); bool process_ping_responses (void); int get_ping_response_count_in_layer (LayerInfo * l); bool check_all_ping_responses_received (void); // Packet cache stuff void init_packet_cache (void); bool add_to_packet_cache (int src_aid, int src_nid, int seq_no);};#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -