00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00029 #ifndef PROXY_INSTANCE_HPP
00030 #define PROXY_INSTANCE_HPP
00031
00032 #include "include/utils/addr_storage.hpp"
00033 #include "include/proxy/message_queue.hpp"
00034 #include "include/proxy/message_format.hpp"
00035 #include "include/proxy/worker.hpp"
00036 #include "include/proxy/routing.hpp"
00037 #include "include/proxy/sender.hpp"
00038 #include "include/proxy/igmp_sender.hpp"
00039 #include "include/proxy/mld_sender.hpp"
00040 #include "include/proxy/receiver.hpp"
00041 #include "include/proxy/timing.hpp"
00042 #include "include/proxy/check_source.hpp"
00043
00044 #include <vector>
00045 using namespace std;
00046
00050 #define PROXY_INSTANCE_MSG_QUEUE_SIZE 1000
00051
00055 #define PROXY_INSTANCE_DEL_IMMEDIATELY 0
00056
00060 struct src_state {
00064 enum state {
00065 INIT ,
00066 RUNNING ,
00067 RESPONSE_STATE ,
00068 WAIT_FOR_DEL ,
00069 UNUSED_SRC ,
00070 CACHED_SRC
00071 };
00072
00076 std::string state_type_to_string(){
00077 HC_LOG_TRACE("");
00078 switch(flag){
00079 case INIT: return "INIT";
00080 case RUNNING: return "RUNNING";
00081 case RESPONSE_STATE: return "RESPONSE_STATE";
00082 case WAIT_FOR_DEL: return "WAIT_FOR_DEL";
00083 case UNUSED_SRC: return "UNUSED_SRC";
00084 case CACHED_SRC: return "CACHED_SRC";
00085 default: return "ERROR";
00086 }
00087 }
00088
00092 src_state(): robustness_counter(0), flag(INIT) {}
00093
00097 src_state(int counter, state flag): robustness_counter(counter), flag(flag) {}
00098
00102 int robustness_counter;
00103
00107 state flag;
00108 };
00109
00110
00116 typedef map<int, int> vif_map;
00117
00123 typedef pair<int, int> vif_pair;
00124
00125
00131 typedef map<addr_storage, struct src_state> src_state_map;
00132
00138 typedef pair<addr_storage, struct src_state> src_state_pair;
00139
00140
00146 typedef map<addr_storage, src_state_map> upstream_src_state_map;
00147
00153 typedef pair<addr_storage, src_state_map> upstream_src_state_pair;
00154
00155
00161 typedef pair<src_state_map, struct src_state> src_group_state_pair;
00162
00163
00169 typedef map<addr_storage, src_group_state_pair > g_state_map;
00170
00176 typedef pair<addr_storage, src_group_state_pair > g_state_pair;
00177
00178
00179
00185 typedef map< int, g_state_map > state_table_map;
00186
00192 typedef pair< int, g_state_map > state_tabel_pair;
00193
00197 class proxy_instance: public worker{
00198 private:
00199
00200 int m_upstream;
00201 upstream_src_state_map m_upstream_state;
00202
00203
00204 state_table_map m_state_table;
00205
00206
00207 vif_map m_vif_map;
00208
00209 int m_addr_family;
00210 int m_version;
00211
00212 check_source m_check_source;
00213
00214 routing* m_routing;
00215 sender* m_sender;
00216 receiver* m_receiver;
00217 timing* m_timing;
00218
00219
00220 void worker_thread();
00221
00222
00223 void registrate_if(int if_index);
00224 void unregistrate_if(int if_index);
00225
00226
00227
00228 bool send_gq_to_all();
00229
00230
00231 void handle_igmp(struct receiver_msg* r);
00232
00233
00234 void handle_clock(struct clock_msg* c);
00235
00236
00237 void handle_debug_msg(struct debug_msg* db);
00238
00239
00240 void handle_config(struct config_msg* c);
00241
00242
00243 bool is_group_joined(int without_if_index, const addr_storage& g_addr);
00244
00245
00246
00247 bool split_traffic(int if_index, const addr_storage& g_addr, const addr_storage& src_addr);
00248 bool del_route(int if_index, const addr_storage& g_addr, const addr_storage& src_addr);
00249
00250
00251 void refresh_all_traffic(int if_index, const addr_storage& g_addr);
00252
00253
00254
00255 void add_all_group_vifs_to_list(std::list<int>* vif_list, int without_if_index, addr_storage g_addr);
00256
00257
00258 void close();
00259 public:
00263 proxy_instance();
00264
00268 ~proxy_instance();
00269
00270
00281 bool init(int addr_family, int version, int upstream_index, int upstream_vif, int downstream_index, int downstram_vif,receiver* r);
00282 };
00283
00284 #endif // PROXY_INSTANCE_HPP
00285