3 require_once 'tophat_api.php';
6 <script type="text/javascript" src="/plekit/table/columns.js"></script>
11 var $column_configuration = "";
12 var $reference_node = "";
13 var $first_time = false;
15 var $all_headers = array();
16 var $this_table_headers = array();
17 var $visible_headers = array();
19 var $all_columns = array();
20 var $fix_columns = array();
21 var $tag_columns = array();
22 var $extra_columns = array();
26 var $HopCount = array();
28 function PlekitColumns ($column_configuration, $fix_columns, $tag_columns, $extra_columns=NULL, $this_table_headers=NULL) {
30 $this->fix_columns = $fix_columns;
31 $this->tag_columns = $tag_columns;
32 $this->extra_columns = $extra_columns;
35 //print_r($this->fix_columns);
37 //print_r($this->tag_columns);
38 //print("<p>EXTRA<p>");
39 //print_r($this->extra_columns);
41 $this->prepare_headers();
42 $this->parse_configuration($column_configuration);
44 $this->visible_headers = $this->get_visible();
46 //print("<p>VISIBLE<p>");
47 //print_r($this->visible_headers);
49 $this->all_columns = array_merge($fix_columns, $tag_columns, $extra_columns);
60 function prepare_headers() {
62 foreach ($this->fix_columns as $column) {
63 $this->all_headers[$column['header']]=array('header'=>$column['header'],'type'=>$column['type'],'tagname'=>$column['tagname'],'title'=>$column['title'], 'description'=>$column['title'], 'label'=>$column['header'], 'fixed'=>true, 'visible'=>false);
66 foreach ($this->tag_columns as $column) {
67 $this->all_headers[$column['header']]=array('header'=>$column['header'],'type'=>$column['type'],'tagname'=>$column['tagname'],'title'=>$column['tagname'], 'description'=>$column['title'], 'label'=>$this->removeDuration($column['header']),'visible'=>false);
70 foreach ($this->extra_columns as $column) {
71 $this->all_headers[$column['header']]=array('header'=>$column['header'],'type'=>$column['type'],'tagname'=>$column['tagname'],'title'=>$column['tagname'], 'description'=>$column['title'], 'label'=>$this->removeDuration($column['header']),'visible'=>false);
74 return $this->all_headers;
79 function get_headers() {
81 return $this->all_headers;
85 function node_tags() {
87 $fetched_tags = array('node_id');
89 foreach ($this->all_headers as $h)
91 if ($h['visible'] == true)
92 $fetched_tags[] = $h['tagname'];
98 function print_headers() {
102 foreach ($this->all_headers as $h)
104 $headers.="<br>".$h['header'].":".$h['label'].":".$h['tagname'];
109 function get_visible() {
111 $visibleHeaders = array();
113 foreach ($this->all_headers as $h)
115 if ($h['visible'] == true)
116 $visibleHeaders[] = $h['header'];
118 return $visibleHeaders;
121 function headerIsVisible($header_name) {
123 $headersToShow = $this->visible_headers;
126 if ($this->inTypeC($header_name."w") || $this->inTypeC($header_name."m") || $this->inTypeC($header_name."y"))
127 return (in_array($header_name."w", $headersToShow) || in_array($header_name."m", $headersToShow) || in_array($header_name."y", $headersToShow));
129 return in_array($header_name, $headersToShow);
142 function parse_configuration($column_configuration) {
144 $this->column_configuration = $column_configuration;
145 //$this->default_configuration = $default_configuration;
147 $columns_conf = explode("|", $column_configuration);
148 foreach ($columns_conf as $c)
150 $conf = explode(":",$c);
152 $this->all_headers[$conf[0]]['visible']=true;
153 //print("<p>".$conf[0]."should be visible now");
154 //print_r($this->all_headers[$conf[0]]);
159 else if ($this->inTypeC($conf[0]))
161 $this->all_headers[$conf[0]]['duration']= substr($conf[0], strlen($conf[0])-1, strlen($conf[0]));
162 $threshold = explode(",",$conf[1]);
163 $this->all_headers[$conf[0]]['threshold']=$threshold;
165 else if ($this->inTypeD($conf[0]))
167 $this->reference_node = $conf[1];
168 $this->reference_node = "planetlab-europe-07.ipv6.lip6.fr";
169 $this->all_headers[$conf[0]]['refnode']=$this->reference_node;
170 $threshold = explode(",",$conf[1]);
171 $this->all_headers[$conf[0]]['threshold']=$threshold;
173 else if ($this->inTypeA($conf[0]))
175 $exclude_list = explode(",",$conf[1]);
176 $this->all_headers[$conf[0]]['exclude_list']=$exclude_list;
180 $threshold = explode(",",$conf[1]);
181 $this->all_headers[$conf[0]]['threshold']=$threshold;
196 function getHopCount($ref_node, $planetlab_nodes)
199 $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest', 'AuthString' => 'guest');
200 $tophat_api = new TopHatAPI($tophat_auth);
202 $traceroute = $tophat_api->Get('traceroute', 'latest', array('src_hostname' => $ref_node, 'dst_hostname' => $planetlab_nodes), array('dst_hostname', 'hop_count') );
206 if ($traceroute) foreach ($traceroute as $t)
207 $hopcount[$t['dst_hostname']]=$t['hop_count'];
212 //Depending on the columns selected more data might need to be fetched from
215 function fetch_data($nodes) {
217 //TopHat pairwise data
219 if ($this->reference_node != "")
223 if ($nodes) foreach ($nodes as $n)
224 $dd[] = $n['hostname'];
226 if ($potential_nodes) foreach ($potential_nodes as $n)
227 $dd[] = $n['hostname'];
229 print("Calling tophat api for reference node = ".$this->reference_node);
230 $st = time() + microtime();
231 $HopCount = $this->getHopCount($this->reference_node, $dd);
232 printf(" (%.2f ms)<br/>", (time() + microtime()-$st)*100);
233 //print_r($HopCount);
239 function excludeItems($value, $exclude_list, $hh) {
245 if (in_array($value, $exclude_list))
246 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
248 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
250 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
253 function checkThreshold($value, $threshold, $hh) {
256 return array("n/a", array('name'=>$hh, 'display'=>'table-cell'));
259 if ((float) $value >= (float) $threshold[0] && (float) $value <= (float) $threshold[1])
260 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
262 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
264 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
268 function cells($table, $node) {
271 foreach ($this->all_headers as $h)
274 if (!$h['fixed'] && $h['visible'])
276 if ($this->inTypeC($h['header']))
278 $tagname = $h['tagname'];
279 $value = $node[$tagname];
280 $v = $this->checkThreshold($value, $h['threshold'], $h['header']);
281 $table->cell($v[0],$v[1]);
283 else if ($this->inTypeB($h['header']))
285 $value = $node[$h['tagname']];
286 $v = $this->checkThreshold($value, $h['threshold'], $h['header']);
287 $table->cell($v[0],$v[1]);
289 else if ($this->inTypeD($h['header']))
291 $value = $this->HopCount[$node['hostname']];
292 $v = $this->excludeItems($value, $h['threshold'], $h['header']);
293 $table->cell($v[0],$v[1]);
295 else if ($this->inTypeA($h['header']))
297 $value = $node[$h['tagname']];
298 $v = $this->excludeItems($value, $h['exclude_list'], $h['header']);
299 $table->cell($v[0],$v[1]);
303 $value = $node[$h['tagname']];
304 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
308 $table->cell("??", array('name'=>$h['header'], 'display'=>'none'));
322 function javascript_vars() {
324 print("<input type='hidden' id='reference_node' value='".$this->reference_node."' />");
326 $all_columns_string = "";
327 foreach ($this->all_headers as $h)
328 $all_columns_string.= $h['header'].",";
330 print("<script type='text/javascript'>");
332 print("var column_table = new Array();");
333 print ("var column_index=0;");
334 print("var column_table2 = new Array();");
335 print("var column_headers = new Array();");
336 print("var columns_to_fetch = new Array();");
337 //document.onkeyup = scrollList('test');
338 foreach ($this->all_headers as $h)
341 print("column_table2[column_index] = new Array();");
342 print("column_table2[column_index]['header'] = ".$h['header'].";");
343 print("column_table2[column_index]['label'] = ".$h['label'].";");
346 print("column_table2[column_index]['visible'] = true;");
347 print("column_table2[column_index]['fetched'] = true;");
351 print("column_table2[column_index]['visible'] = false;");
352 print("column_table2[column_index]]['fetch'] = false;");
354 print("column_table2[column_index]['tagname'] = '".$h['tagname']."';");
355 print("column_table2[column_index]['description'] = '".$h['description']."';");
358 print("column_table[\"".$h['header']."\"] = new Array();");
361 print("column_table['".$h['header']."']['visible'] = true;");
362 print("column_table['".$h['header']."']['fetched'] = true;");
366 print("column_table['".$h['header']."']['visible'] = false;");
367 print("column_table['".$h['header']."']['fetch'] = false;");
370 print("column_table['".$h['header']."']['tagname'] = '".$h['tagname']."';");
371 print("column_table['".$h['header']."']['description'] = '".$h['description']."';");
374 foreach ($this->all_headers as $h)
375 print("column_headers['".$h['label']."'] = '0';");
377 print("var all_columns_string = '".substr($all_columns_string,0,strlen($all_columns_string)-1)."';");
379 //if ($first_time == true)
380 //print("resetConfiguration();");
381 //print("debugfilter('vars are OK');");
387 function configuration_panel_html($showDescription) {
390 if ($showDescription)
395 print("<table align=center cellpadding=10 width=".$table_width.">");
396 print("<tr><th>Add/delete columns</th>");
398 if ($showDescription)
399 print("<th>Column description and configuration</th>");
401 print("</tr><tr><td valign=top width=300>");
403 print('<div id="scrolldiv" onFocusOut="debugfilter(this.id);" style="border : solid 2px grey; padding:4px; width:300px; height:180px; overflow:auto;">');
406 $optionclass = "out";
407 foreach ($this->all_headers as $h)
409 if ($h['header'] == "hostname")
413 $disabled = "disabled=true";
417 if ($this->headerIsVisible($h['label']))
419 $selected = "checked=true";
420 //print("header ".$h['label']." checked!");
427 if ($prev_label == $h['label'])
430 $prev_label = $h['label'];
432 print ("<tr><td><div id='".$h['label']."' class='".$optionclass."' onkeyup='debugfilter(this.id)' onclick='highlightOption(this.id)'><table width=280 id='table".$h['label']."'><tr><td align=left width=30>".$h['label']."</td><td align=left> <span style='height:10px' id ='htitle".$h['label']."'>".$h['title']."</span> </td><td align=right width=20><input id='check".$h['label']."' type='checkbox' ".$selected." ".$disabled." autocomplete='off' value='".$h['label']."' onclick='changeCheckStatus(this.id)'></input></td></tr></table></div></td></tr>");
435 print("</table> </div></td>");
437 if ($showDescription)
439 print("<td valign=top width=400>");
440 print("<div class='myslice' id='selectdescr'> </div></td>");
443 print("</tr><tr><td align=center>");
444 //print("<input type='button' value='Reset' onclick=resetCols('previousConf') />");
445 //print("<input type='button' value='Default' onclick=saveConfiguration('defaultConf') />");
446 print("<input type='button' value='Reset table' onclick=\"resetConfiguration('defaultConf')\" />");
447 print(" <input type='button' value='Save configuration' onclick=saveConfiguration('column_configuration') />");
448 print(" <input type='button' id='fetchbutton' onclick='fetchData()' value='Fetch data' disabled=true /> </td>");
450 if ($showDescription)
453 print(" </tr> </table>");
456 function column_filter () {
460 Highlight <select onChange="filterByType(this.value)">
461 <option value="none">None</option>
462 <option value="capabilities">Capabilities</option>
463 <option value="statistics">Statistics</option>
464 <option value="network">Network</option>
465 <option value="pairwise">Pairwise</option>
466 <option value="other">Other</option>
473 function column_html ($colHeader, $colName, $colId, $fulldesc, $visible) {
476 $display = 'display:table-cell';
478 $display = 'color:red;display:none';
481 <th class='sample plekit_table' name='confheader".$colHeader."' id='testid' style='".$display."'>
482 <div id=\"".$colId."\" onclick=\"showDescription('".$colHeader."')\" onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div>
487 function column_fix_html ($colHeader, $colName, $colId) {
489 $display = 'display:table-cell';
491 $res="<th name='confheader".$colHeader."' class='fix plekit_table' style='$display'>";
492 $res.= "<div id='$colId' onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div></th>";
498 function graph_html($colHeader) {
500 return "<p><img src='/planetlab/slices/graph.png' width='20' align='BOTTOM'><input type='checkbox' id='graph".$colHeader."'></input> Show details on mouse over";
504 function threshold_html($colHeader) {
506 $updatecall = "updateColumnThreshold('".$colHeader."',window.document.getElementById('min".$colHeader."').value,window.document.getElementById('max".$colHeader."').value);";
508 $bubble="<b>Grey-out values between</b> <input type='text' id='min".$colHeader."' size='2' value='5'> (low) and <input type='text' id='max".$colHeader."' size='2' value='90'> (high) <input type='submit' value='Update' onclick=".$updatecall."> </input>";
521 function inTypeA($header_name) {
522 $typeA = array('ST','SN','RES','OS','NRR','NTP','NSR','NSF','NDS','NTH','NEC','LRN','LCY','LPR','LCN','LAT','LON','IP','ASN','AST');
523 return in_array($header_name, $typeA);
527 function inTypeB($header_name) {
528 $typeB = array('BW','DS','MS','CC','CR','AS','DU','CN');
529 return in_array($header_name, $typeB);
533 function inTypeC($header_name) {
534 $typeC = array('Rw','Rm','Ry','Lw','Lm','Ly','Sw','Sm','Sy','CFw','CFm','CFy','BUw','BUm','BUy','MUw','MUm','MUy','SSHw','SSHm','SSHy');
535 return in_array($header_name, $typeC);
539 function inTypeD($header_name) {
540 $typeD = array('HC');
541 return in_array($header_name, $typeD);
545 function removeDuration($header)
547 if ($this->inTypeC($header))
548 return substr($header, 0, strlen($header)-1);