mcproxy/mcproxy/include/utils/mc_tables.hpp
Go to the documentation of this file.00001 /* 00002 * This file is part of mcproxy. 00003 * 00004 * mcproxy is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU Lesser General Public License as published by 00006 * the Free Software Foundation; either version 3 of the License, or (at your 00007 * option) any later version. 00008 * 00009 * mcproxy is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00011 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00012 * License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public License 00015 * along with mcproxy; see the file COPYING.LESSER. 00016 * 00017 * written by Sebastian Woelke, in cooperation with: 00018 * INET group, Hamburg University of Applied Sciences, 00019 * Website: http://mcproxy.realmv6.org/ 00020 */ 00021 00022 00023 #ifndef MC_TABLES_HPP 00024 #define MC_TABLES_HPP 00025 00026 #include "include/utils/addr_storage.hpp" 00027 00028 #include <netinet/in.h> 00029 #include <map> 00030 #include <vector> 00031 #include <iostream> 00032 #include <linux/mroute.h> 00033 #include <linux/mroute6.h> 00034 using namespace std; 00035 00036 #define MAX_N_LINE_LENGTH 200 00037 #define JOINED_GROUP_PATH_V6 "/proc/net/igmp6" 00038 #define JOINED_GROUP_PATH_V4 "/proc/net/igmp" 00039 #define VIF_PATH_V4 "/proc/net/ip_mr_vif" 00040 #define VIF_PATH_V6 "/proc/net/ip6_mr_vif" 00041 #define MR_CACHE_PATH_V4 "/proc/net/ip_mr_cache" 00042 #define MR_CACHE_PATH_V6 "/proc/net/ip6_mr_cache" 00043 #define SNMP6_PATH "/proc/net/dev_snmp6" 00044 00045 typedef vector<addr_storage> MGroup_value; 00046 typedef map<string, MGroup_value > MGroup_map; 00047 typedef pair<string, MGroup_value > MGroup_pair; 00048 00049 typedef struct snmp6 SNMP6_value; 00050 typedef map<string, SNMP6_value > SNMP6_map; 00051 typedef pair<string, SNMP6_value > SNMP6_pair; 00052 00056 struct mr_vif{ 00057 int addr_family; 00058 int vifi; //virutuell interface index 00059 string ifname; 00060 int bytesIn; 00061 int pktsIn; 00062 int bytesOut; 00063 int pktsOut; 00064 int flags; 00065 int lcl_index; //use for AF_INET 00066 addr_storage lcl_addr; //only for AF_INET 00067 addr_storage remote; //only for AF_INET 00068 }; 00069 00073 struct mr_cache{ 00074 int addr_family; 00075 addr_storage group; 00076 addr_storage origin; 00077 int i_if; 00078 int pkts; 00079 int bytes; 00080 int wrong; 00081 vector<int> o_if; 00082 }; 00083 00087 struct snmp6 { 00088 int Icmp6InGroupMembQueries; 00089 int Icmp6InGroupMembResponses; 00090 int Icmp6OutGroupMembQueries; 00091 int Icmp6OutGroupMembResponses; 00092 00093 int Icmp6InMLDv2Reports; 00094 int Icmp6OutMLDv2Reports; 00095 }; 00096 00100 struct igmp_dev{ 00101 int index; //inteface index 00102 string if_name; //interface name 00103 int g_count; //count joined groups on this interface 00104 int querier_version; //querier version (default V3) 00105 vector<struct igmp_group> groups; 00106 }; 00107 00111 struct igmp_group{ 00112 addr_storage group; //joined group 00113 int users; //number of user on this pc joined this group 00114 bool timer_run; 00115 int timer; //current respons time 00116 bool reporter; //i am the reporter of this group only V2 00117 }; 00118 00122 class mc_tables 00123 { 00124 private: 00125 int m_addr_family; 00126 //--filesystem access-- 00127 MGroup_map m_mgroup_map; 00128 00129 vector<struct mr_vif> m_mr_vif; 00130 vector<struct mr_cache> m_mr_cache; 00131 00132 SNMP6_map m_snmp6_map; 00133 00134 vector<struct igmp_dev> m_igmp_table; 00135 00136 //--general-- 00137 string int2str(int x); 00138 addr_storage hexCharAddr_To_ipFormart(string& ipAddr, int addrFamily); 00139 int str2int(string x); 00140 int hexChar_To_int(char x); 00141 00142 //trim fist and last white_spaces 00143 00144 public: 00145 00151 static void trim(char* str, unsigned int size); 00152 00156 mc_tables(); 00157 00161 void init_tables(int addrFamily); 00162 00163 //####################### 00164 //##-- joined groups --## 00165 //####################### 00170 bool refresh_joined_groups(); 00171 00176 unsigned int get_joined_groups_count(string& ifName); 00177 00183 addr_storage get_joined_group(string& ifName, unsigned int index); 00184 00188 void print_all_joined_groups(); 00189 00190 //############### 00191 //##-- vifs -- ## 00192 //############### 00196 bool refresh_vifs(); 00197 00201 unsigned int get_vifs_count(); 00202 00207 const struct mr_vif& get_vif(unsigned int index); 00208 00213 void print_vif_info(struct mr_vif& t); 00214 00218 void print_all_vif_infos(); 00219 00220 //################ 00221 //##-- routes --## 00222 //################ 00227 bool refresh_routes(); 00228 00232 unsigned int get_routes_count(); 00233 00238 const struct mr_cache& get_route(unsigned int index); 00239 00244 void print_route_info(struct mr_cache& t); 00245 00249 void print_all_route_infos(); 00250 00251 //############### 00252 //##-- snmp6 --## 00253 //############### 00258 bool refresh_snmp6(); 00259 00265 struct snmp6 get_snmp6(string if_name); 00266 00270 struct snmp6 get_snmp6_empty_struct(); 00271 00275 vector<string> get_snmp6_all_interfaces(); 00276 00281 void print_snmp6_infos(const struct snmp6* s); 00282 00286 void print_all_snmp6_infos(); 00287 00288 //#################### 00289 //##-- igmp table --## 00290 //#################### 00295 bool refresh_igmp_table(); 00296 00300 struct igmp_dev get_igmp_table_empty_dev(); 00301 00307 struct igmp_dev get_igmp_table_dev(string if_name); 00308 00312 vector<struct igmp_dev> get_igmp_table_all(); 00313 00317 vector<string> get_igmp_table_all_interfaces(); 00318 00323 void print_igmp_table_dev(const struct igmp_dev* s); 00324 00328 void print_all_igmp_table(); 00329 00330 //################ 00331 //##-- tests -- ## 00332 //################ 00336 static void test_joined_groups(int addrFamily); 00337 00341 static void test_vifs(int addrFamily); 00342 00346 static void test_mr_cache(int addrFamily); 00347 00351 static void test_snmp6(); 00352 00356 static void test_igmp_table(); 00357 00358 }; 00359 00360 #endif // MC_TABLES_HPP