LEFT | RIGHT |
(no file at all) | |
1 <?php | 1 <?php |
2 include_once('config.php'); | 2 //this is the database thread which push data from the cache to the DB, to under
stand this part, you should study the different JSON object that we have. |
3 include_once('mem_connect.php'); | 3 include_once('config.php'); //connect to database |
4 ini_set('display_errors', 1); | 4 include_once('mem_connect.php');//connect to memcached |
5 | 5 |
| 6 //infinite loop for the thread |
6 while (1){ | 7 while (1){ |
| 8 //sleep for 30 seconds |
7 sleep(30); | 9 sleep(30); |
| 10 //get every key stored into the cache |
8 $keys = $memcache->getAllKeys(); | 11 $keys = $memcache->getAllKeys(); |
9 //» print_r($keys); | 12 » //start a timer in order to know how long does a request take (phase 3:
evaluation) |
| 13 » $time_pre = microtime(true); |
| 14 |
| 15 » //for each key stored into the cache· |
10 foreach ($keys as $item) { | 16 foreach ($keys as $item) { |
| 17 //we get the item linked to his key |
11 $j_data = $memcache->get($item); | 18 $j_data = $memcache->get($item); |
| 19 //and decode the JSON object in order to have an access to the d
ata |
12 $data = json_decode($j_data,true);······ | 20 $data = json_decode($j_data,true);······ |
13 | 21 |
| 22 //if it's from nfm module |
14 if (strcmp($data['module'], 'nfm') == 0) { | 23 if (strcmp($data['module'], 'nfm') == 0) { |
15 » » $object_index = $data['object_index']; | 24 » » //store the object index |
16 » » $switch_data = $data['switches']; | 25 » » » $object_index = $data['object_index']; |
| 26 » » » //go inside the nested JSON |
| 27 » » $nested_data = $data['switches']; |
| 28 » » //start to count where we are in the nested JSON· |
17 $switch_counter = 0; | 29 $switch_counter = 0; |
18 » » $number_switch = sizeof($switch_data); | 30 » » //number of switches |
| 31 » » $number_switch = sizeof($nested_data); |
| 32 » » //with this loop we go inside every switch which means the neste
d JSON in $nested_data |
19 while ($switch_counter <= $number_switch -1 ) { | 33 while ($switch_counter <= $number_switch -1 ) { |
20 » » » $current_switch = $switch_data[$switch_counter]; | 34 » » » $current_switch = $nested_data[$switch_counter]; |
21 $switch_dpid = $current_switch['switch_dpid']; | 35 $switch_dpid = $current_switch['switch_dpid']; |
| 36 //if we have a port_counters data |
22 if (isset($current_switch["port_counters"])) { | 37 if (isset($current_switch["port_counters"])) { |
23 $port_data= $current_switch['port_counters']; | 38 $port_data= $current_switch['port_counters']; |
24 $number_port = sizeof($port_data); | 39 $number_port = sizeof($port_data); |
25 $current_port=0; | 40 $current_port=0; |
| 41 //for every port we get the rx_bw and the tx_bw |
26 while ($current_port <= $number_port -1) { | 42 while ($current_port <= $number_port -1) { |
27 # DB code | |
28 $array_data = $port_data[$curren
t_port]; | 43 $array_data = $port_data[$curren
t_port]; |
29 // $tx_error= $array_data['tx-error
']; | |
30 // $tx_pkts = $array_data['tx-pkts'
]; | |
31 // $rx_error = $array_data['rx-erro
r']; | |
32 // $rx_bytes = $array_data['rx-byte
s']; | |
33 $tx_bw = $array_data['tx_bw']; | 44 $tx_bw = $array_data['tx_bw']; |
34 // $rx_eps = $array_data['rx_eps'];······································ | |
35 // $tx_bytes = $array_data['tx-byte
s']; | |
36 // $rx_pkts = $array_data['rx-pkts'
]; | |
37 $rx_bw = $array_data['rx_bw']; | 45 $rx_bw = $array_data['rx_bw']; |
38 // $tx_eps = $array_data['tx_eps']; | |
39 | 46 |
40 $port = $array_data['port']; | 47 $port = $array_data['port']; |
41 | 48 » » » » » » //we put every thing in the DB |
42 $req = $bdd->prepare('INSERT INT
O port_counters (object_index, switch_dpid, port, rx_bw, tx_bw) VALUES(:object_i
ndex, :switch_dpid, :port, :rx_bw, :tx_bw)'); | 49 $req = $bdd->prepare('INSERT INT
O port_counters (object_index, switch_dpid, port, rx_bw, tx_bw) VALUES(:object_i
ndex, :switch_dpid, :port, :rx_bw, :tx_bw)'); |
43 $req->execute(array( | 50 $req->execute(array( |
44 'object_index' => $object_index, | 51 'object_index' => $object_index, |
45 | 52 |
46 'switch_dpid' => $switch_dpid, | 53 'switch_dpid' => $switch_dpid, |
47 | 54 |
48 'port' => $port, | 55 'port' => $port, |
49 | 56 |
50 //'rx_pkts' => $rx_pkts, | |
51 | |
52 //'rx_bytes' => $rx_bytes, | |
53 | |
54 //'rx_error' => $rx_error, | |
55 | |
56 //'tx_pkts' => $tx_pkts, | |
57 | |
58 //'tx_bytes' => $tx_bytes, | |
59 | |
60 //'tx_error' => $tx_error, | |
61 | |
62 'rx_bw' => $rx_bw, | 57 'rx_bw' => $rx_bw, |
63 | 58 |
64 //'rx_eps' => $rx_eps, | |
65 | |
66 'tx_bw' => $tx_bw, | 59 'tx_bw' => $tx_bw, |
67 | |
68 //'tx_eps' => $tx_eps, | |
69 | 60 |
70 )); | 61 )); |
71 $req->closeCursor(); | 62 $req->closeCursor(); |
72 $current_port ++; | 63 $current_port ++; |
73 } | 64 } |
74 ································ | 65 ································ |
75 } | 66 } |
76 | 67 » » » //otherwise, we have flow_counters data |
77 else{ | 68 else{ |
78 $flow_data= $current_switch['flow_counters']; | 69 $flow_data= $current_switch['flow_counters']; |
79 $number_flow = sizeof($flow_data); | 70 $number_flow = sizeof($flow_data); |
80 $current_flow=0; | 71 $current_flow=0; |
| 72 |
| 73 //we go inside the nested and JSON and put every
thing in the DB |
81 while ($current_flow <= $number_flow -1) { | 74 while ($current_flow <= $number_flow -1) { |
82 $array_data = $flow_data[$current_flow]; | 75 $array_data = $flow_data[$current_flow]; |
83 $in_port= $array_data['in-port']
; | 76 $in_port= $array_data['in-port']
; |
84 $out_port = $array_data['out-por
t']; | 77 $out_port = $array_data['out-por
t']; |
85 $eth_dst = $array_data['eth-dst'
]; | 78 $eth_dst = $array_data['eth-dst'
]; |
86 $eth_src = $array_data['eth-src'
]; | 79 $eth_src = $array_data['eth-src'
]; |
87 $packets = $array_data['packets'
]; | 80 $packets = $array_data['packets'
]; |
88 $bytes = $array_data['bytes']; | 81 $bytes = $array_data['bytes']; |
89 $flow_bandwidth = $array_data['f
low_bandwidth'];········································ | 82 $flow_bandwidth = $array_data['f
low_bandwidth'];········································ |
90 $req = $bdd->prepare('INSERT INT
O flow_counters (object_index, switch_dpid, in_port, out_port, eth_dst, eth_src,
packets, bytes, flow_bandwidth) VALUES(:object_index, :switch_dpid, :in_port, :
out_port, :eth_dst, :eth_src, :packets, :bytes, :flow_bandwidth)'); | 83 $req = $bdd->prepare('INSERT INT
O flow_counters (object_index, switch_dpid, in_port, out_port, eth_dst, eth_src,
packets, bytes, flow_bandwidth) VALUES(:object_index, :switch_dpid, :in_port, :
out_port, :eth_dst, :eth_src, :packets, :bytes, :flow_bandwidth)'); |
(...skipping 23 matching lines...) Expand all Loading... |
114 $current_flow ++; | 107 $current_flow ++; |
115 } | 108 } |
116 | 109 |
117 } | 110 } |
118 | 111 |
119 $switch_counter++; | 112 $switch_counter++; |
120 } | 113 } |
121 | 114 |
122 } | 115 } |
123 | 116 |
124 » »······· | 117 » » //if we have a hum object |
125 | 118 |
126 elseif(strcmp($data['module'], 'hum') == 0){ | 119 elseif(strcmp($data['module'], 'hum') == 0){ |
127 $process_Mem= $data['process_Mem']; | 120 $process_Mem= $data['process_Mem']; |
128 $process_CPU= $data['process_CPU']; | 121 $process_CPU= $data['process_CPU']; |
129 $tool = $data['tool']; | 122 $tool = $data['tool']; |
130 | 123 » » » $object_index = $data['object_index']; |
131 » » » $req = $bdd->prepare('INSERT INTO hardware_utilization (
process_Mem, process_CPU, tool) VALUES(:process_Mem, :process_CPU, :tool)'); | 124 » » » $req = $bdd->prepare('INSERT INTO hardware_utilization (
process_Mem, process_CPU, tool, object_index) VALUES(:process_Mem, :process_CPU,
:tool, :object_index)'); |
132 $req->execute(array( | 125 $req->execute(array( |
133 | 126 |
134 'process_Mem' => $process_Mem, | 127 'process_Mem' => $process_Mem, |
135 | 128 |
136 'process_CPU' => $process_CPU, | 129 'process_CPU' => $process_CPU, |
137 | 130 |
138 'tool' => $tool, | 131 'tool' => $tool, |
| 132 ················ |
| 133 'object_index' => $object_index, |
139 | 134 |
140 )); | 135 )); |
141 // print_r($req->errorInfo()); | 136 // print_r($req->errorInfo()); |
142 $req->closeCursor(); | 137 $req->closeCursor(); |
143 ························ | 138 ························ |
144 } | 139 } |
145 | 140 |
| 141 //RPM object |
| 142 |
146 elseif(strcmp($data['module'], 'rpm') == 0) { | 143 elseif(strcmp($data['module'], 'rpm') == 0) { |
147 $switch_data = $data['switches']; | 144 $switch_data = $data['switches']; |
| 145 $object_index = $data['object_index']; |
148 $switch_counter = 0; | 146 $switch_counter = 0; |
149 $number_switch = sizeof($switch_data); | 147 $number_switch = sizeof($switch_data); |
150 while ($switch_counter <= $number_switch -1 ) { | 148 while ($switch_counter <= $number_switch -1 ) { |
151 $switch_rtt = $switch_data[$switch_counter]; | 149 $switch_rtt = $switch_data[$switch_counter]; |
152 $switch_dpid = $switch_rtt['switch_dpid']; | 150 $switch_dpid = $switch_rtt['switch_dpid']; |
153 $rtt = $switch_rtt['rtt']; | 151 $rtt = $switch_rtt['rtt']; |
154 » » » $req = $bdd->prepare('INSERT INTO ruleprobe (switch_dpid
, rtt) VALUES(:switch_dpid, :rtt)'); | 152 » » » $req = $bdd->prepare('INSERT INTO ruleprobe (switch_dpid
, rtt, object_index) VALUES(:switch_dpid, :rtt, :object_index)'); |
155 $req->execute(array( | 153 $req->execute(array( |
156 | 154 |
157 'switch_dpid' => $switch_dpid, | 155 'switch_dpid' => $switch_dpid, |
158 | 156 |
159 'rtt' => $rtt, | 157 'rtt' => $rtt, |
| 158 |
| 159 'object_index' => $object_index, |
160 )); | 160 )); |
161 // print_r($req->errorInfo()); | 161 // print_r($req->errorInfo()); |
162 $req->closeCursor(); | 162 $req->closeCursor(); |
163 $switch_counter ++; | 163 $switch_counter ++; |
164 | 164 |
165 } | 165 } |
166 | 166 |
167 ························ | 167 ························ |
168 } | 168 } |
169 | 169 |
| 170 //topology object |
170 | 171 |
171 elseif(strcmp($data['module'], 'topology') == 0) { | 172 elseif(strcmp($data['module'], 'topology') == 0) { |
172 | 173 |
173 if (strcmp($data['event'], 'link_up') == 0) { | 174 if (strcmp($data['event'], 'link_up') == 0) { |
174 # code... | |
175 $src_sw_port = $data['src_sw_port']; | 175 $src_sw_port = $data['src_sw_port']; |
176 $dst_sw_port = $data['dst_sw_port']; | 176 $dst_sw_port = $data['dst_sw_port']; |
177 $dst_switch = $data['dst_switch']; | 177 $dst_switch = $data['dst_switch']; |
178 $src_switch = $data['src_switch']; | 178 $src_switch = $data['src_switch']; |
179 $event = $data['event']; | 179 $event = $data['event']; |
180 $bandwidth = $data['bandwidth']; | 180 $bandwidth = $data['bandwidth']; |
181 | 181 |
182 $req = $bdd->prepare('INSERT INTO topology (src_sw_p
ort, dst_sw_port, dst_switch, src_switch, event, bandwidth) VALUES(:src_sw_port,
:dst_sw_port, :dst_switch, :src_switch, :event, :bandwidth)'); | 182 $req = $bdd->prepare('INSERT INTO topology (src_sw_p
ort, dst_sw_port, dst_switch, src_switch, event, bandwidth) VALUES(:src_sw_port,
:dst_sw_port, :dst_switch, :src_switch, :event, :bandwidth)'); |
183 $req->execute(array( | 183 $req->execute(array( |
184 | 184 |
185 'src_sw_port' => $src_sw_port, | 185 'src_sw_port' => $src_sw_port, |
186 | 186 |
187 'dst_sw_port' => $dst_sw_port, | 187 'dst_sw_port' => $dst_sw_port, |
188 | 188 |
189 'dst_switch' => $dst_switch, | 189 'dst_switch' => $dst_switch, |
190 | 190 |
191 'src_switch' => $src_switch, | 191 'src_switch' => $src_switch, |
192 | 192 |
193 'event' => $event, | 193 'event' => $event, |
194 | 194 |
195 'bandwidth' => $bandwidth, | 195 'bandwidth' => $bandwidth, |
196 | 196 |
197 )); | 197 )); |
198 // print_r($req->errorInfo()); | 198 // print_r($req->errorInfo()); |
199 $req->closeCursor(); | 199 $req->closeCursor(); |
| 200 |
| 201 //if we receive a new_topology object, we have to em
pty every table which is TRUNCAT command in SQL |
200 }elseif(strcmp($data['event'], 'new_topology') == 0){ | 202 }elseif(strcmp($data['event'], 'new_topology') == 0){ |
201 | 203 |
202 $drop=$bdd->query("DELETE FROM topology WHERE ti
me < DATE_SUB(NOW(), INTERVAL 1 MINUTE)"); | 204 $drop=$bdd->query("DELETE FROM topology WHERE ti
me < DATE_SUB(NOW(), INTERVAL 1 MINUTE)"); |
203 $drop1=$bdd->query("DELETE FROM port_counters WH
ERE time < DATE_SUB(NOW(), INTERVAL 1 MINUTE)"); | 205 $drop1=$bdd->query("DELETE FROM port_counters WH
ERE time < DATE_SUB(NOW(), INTERVAL 1 MINUTE)"); |
204 $drop2=$bdd->query("DELETE FROM ruleprobe WHERE
time < DATE_SUB(NOW(), INTERVAL 1 MINUTE)"); | 206 $drop2=$bdd->query("DELETE FROM ruleprobe WHERE
time < DATE_SUB(NOW(), INTERVAL 1 MINUTE)"); |
205 $drop3=$bdd->query("DELETE FROM flow_counters WH
ERE time < DATE_SUB(NOW(), INTERVAL 1 MINUTE)"); | 207 $drop3=$bdd->query("DELETE FROM flow_counters WH
ERE time < DATE_SUB(NOW(), INTERVAL 1 MINUTE)"); |
206 $drop4=$bdd->query("DELETE FROM hardware_utiliza
tion WHERE time < DATE_SUB(NOW(), INTERVAL 1 MINUTE)"); | 208 $drop4=$bdd->query("DELETE FROM hardware_utiliza
tion WHERE time < DATE_SUB(NOW(), INTERVAL 1 MINUTE)"); |
| 209 $drop5=$bdd->query("TRUNCATE TABLE Evaluation"); |
207 } | 210 } |
208 | 211 |
209 } | 212 } |
210 » //» break; | 213 » } |
211 » }» »······· | 214 » //end of the timer |
| 215 » $time_post = microtime(true); |
| 216 » $timer = $time_post - $time_pre; |
| 217 » //we put the time the request take into the database |
| 218 » $req = $bdd->prepare('INSERT INTO Evaluation (timer) VALUES(:timer)'); |
| 219 $req->execute(array( |
| 220 |
| 221 'timer' => $timer, |
| 222 |
| 223 )); |
| 224 // print_r($req->errorInfo()); |
| 225 $req->closeCursor(); |
| 226 » »······· |
212 } | 227 } |
213 ?> | 228 ?> |
214 | 229 |
215 | 230 |
216 | 231 |
LEFT | RIGHT |