MKCommModel
|
00001 #ifndef MKCOMMMODEL_H 00002 #define MKCOMMMODEL_H 00003 00004 #include <semaphore.h> 00005 00006 #include <vector> 00007 #include <stdint.h> 00008 #include <map> 00009 00010 #include "include/bson/bson.h" 00011 00012 #include "include/commmodel.hpp" 00013 #include "MKConfig.h" 00014 #include "MKLib.h" 00015 #include "MKNode.h" 00016 #include "MKPacket.h" 00017 #include "HeartBeatListener.h" 00018 #include "MKControl.h" 00019 00023 class MKCommModel : public CommModel { 00024 public: 00025 00026 friend class HeartBeatListenerTests; 00027 friend class MKControlTests; 00028 friend class MKCommModelTests; 00029 00030 MKCommModel(); 00031 ~MKCommModel(); 00032 00038 virtual node* get_node(mac_t tar_mac_addr); 00039 00041 virtual node* get_node(ip4_t tar_ip_addr); 00042 00051 virtual throughput_t get_throughput(node* n1, node* n2); 00052 00061 virtual latency_t get_latency(node* n1, node* n2); 00062 00071 virtual signal_strength_t get_signal_strength(node* n1, node* n2); 00072 00081 virtual weight_t get_weight(node* n1, node* n2); 00082 00091 virtual inactive_t get_inactive_time(node *n1, node *n2); 00092 00097 virtual std::vector<node *> get_all_nodes(); 00098 00105 virtual std::vector<node *> get_neighbors(node*); 00106 00108 virtual bool set_target(node*); 00109 00111 virtual bool set_ocu_machine(node*); 00112 00114 virtual std::vector<node *> get_preferred_path(); 00115 00120 virtual int size(); 00121 00127 void update(HeartBeatPacket *packet); 00128 00134 void update(mongo::BSONObj *, MKRequest *req); 00135 00140 static std::ostream &log() { return *logh; } 00141 00142 private: 00143 00145 struct MKCommModelInit { MKCommModelInit() { MKCommModel::staticInit(); } }; 00146 static MKCommModelInit init; 00147 static void staticInit(); 00148 00155 MKNode *find(mac_t addr); 00156 MKNode *find(node* node); 00157 00163 MKNode *findByIP(ip4_t addr); 00164 00166 node *ocu, *target; 00167 00169 int count; 00171 std::map<MacAddr, MKNode *> *nodes; 00172 00173 sem_t sem1; 00174 00176 std::map<ip4_t, mac_t> *ipTable; 00177 00179 pthread_t heartBeatThread; 00180 00182 MKControl *control; 00183 00185 static std::ostream *logh; 00186 }; 00187 00188 #endif