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 $fix_columns = array();
20 var $tag_columns = array();
21 var $extra_columns = array();
25 var $HopCount = array();
27 function PlekitColumns ($column_configuration, $fix_columns, $tag_columns, $extra_columns=NULL, $this_table_headers=NULL) {
29 $this->fix_columns = $fix_columns;
30 $this->tag_columns = $tag_columns;
31 $this->extra_columns = $extra_columns;
34 //print_r($this->fix_columns);
36 //print_r($this->tag_columns);
37 //print("<p>EXTRA<p>");
38 //print_r($this->extra_columns);
40 $this->prepare_headers();
41 $this->parse_configuration($column_configuration);
43 $this->visible_headers = $this->get_visible();
45 //print("<p>VISIBLE<p>");
46 //print_r($this->visible_headers);
58 function prepare_headers() {
60 foreach ($this->fix_columns as $column) {
61 $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);
64 $tmp_headers = array();
65 foreach ($this->tag_columns as $column) {
67 if ($column['headerId'] != "")
68 $headerId = $column['headerId'];
70 $headerId = $column['header'];
72 //$this->all_headers[$headerId]=array('header'=>$headerId,'type'=>$column['type'],'tagname'=>$column['tagname'],'title'=>$column['title'], 'description'=>$column['title'], 'label'=>$column['header'],'visible'=>false);
73 $tmp_headers[$headerId]=array('header'=>$headerId,'type'=>$column['type'],'tagname'=>$column['tagname'],'title'=>$column['title'], 'description'=>$column['title'], 'label'=>$column['header'],'visible'=>false);
76 if ($this->extra_columns)
77 foreach ($this->extra_columns as $column) {
78 //$this->all_headers[$column['header']]=array('header'=>$column['header'],'type'=>$column['type'],'tagname'=>$column['tagname'],'title'=>$column['title'], 'description'=>$column['title'], 'label'=>$column['header'], 'fetched'=>$column['fetched'],'visible'=>false);
79 $tmp_headers[$column['header']]=array('header'=>$column['header'],'type'=>$column['type'],'tagname'=>$column['tagname'],'title'=>$column['title'], 'description'=>$column['title'], 'label'=>$column['header'], 'fetched'=>$column['fetched'], 'visible'=>false);
81 usort ($tmp_headers, create_function('$col1,$col2','return strcmp($col1["label"],$col2["label"]);'));
84 foreach ($tmp_headers as $t)
85 $this->all_headers[$t['header']] = $t;
87 //$this->all_headers = array_merge($this->all_headers, $tmp_headers);
89 //print($this->print_headers());
91 return $this->all_headers;
96 function get_headers() {
98 return $this->all_headers;
102 function get_selected_period($label) {
104 if ($this->all_headers[$label."w"]['visible'])
106 else if ($this->all_headers[$label."m"]['visible'])
108 else if ($this->all_headers[$label."y"]['visible'])
110 else if ($this->all_headers[$label]['visible'])
116 function node_tags() {
118 $fetched_tags = array('node_id');
120 foreach ($this->all_headers as $h)
122 if ($h['visible'] == true && $h['tagname'] != "" && !$h['fetched'])
123 $fetched_tags[] = $h['tagname'];
126 return $fetched_tags;
129 function print_headers() {
133 foreach ($this->all_headers as $l => $h)
135 $headers.="<br>[".$l."]=".$h['header'].":".$h['label'].":".$h['tagname'].":".$h['visible'];
140 function get_visible() {
142 $visibleHeaders = array();
144 foreach ($this->all_headers as $h)
146 if ($h['visible'] == true)
147 $visibleHeaders[] = $h['header'];
149 return $visibleHeaders;
152 function headerIsVisible($header_name) {
154 $headersToShow = $this->visible_headers;
156 if (in_array($header_name, $headersToShow))
159 if ($this->inTypeC($header_name."w"))
160 return (in_array($header_name."w", $headersToShow) || in_array($header_name."m", $headersToShow) || in_array($header_name."y", $headersToShow));
173 function parse_configuration($column_configuration) {
175 $this->column_configuration = $column_configuration;
176 //$this->default_configuration = $default_configuration;
178 //print($this->print_headers());
180 $columns_conf = explode("|", $column_configuration);
182 foreach ($columns_conf as $c)
184 $conf = explode(":",$c);
186 if ($conf[0] == "default")
189 $this->all_headers[$conf[0]]['visible']=true;
190 //print("<p>-".$conf[0]."-should be visible now - ".$this->all_headers[$conf[0]]['visible']);
191 //print_r($this->all_headers[$conf[0]]);
197 else if ($this->inTypeC($conf[0]))
199 $this->all_headers[$conf[0]]['duration']= substr($conf[0], strlen($conf[0])-1, strlen($conf[0]));
200 $threshold = explode(",",$conf[1]);
201 $this->all_headers[$conf[0]]['threshold']=$threshold;
203 else if ($this->inTypeD($conf[0]))
205 $this->reference_node = $conf[1];
206 $this->reference_node = "planetlab-europe-07.ipv6.lip6.fr";
207 $this->all_headers[$conf[0]]['refnode']=$this->reference_node;
208 $threshold = explode(",",$conf[1]);
209 $this->all_headers[$conf[0]]['threshold']=$threshold;
211 else if ($this->inTypeA($conf[0]))
213 $exclude_list = explode(",",$conf[1]);
214 $this->all_headers[$conf[0]]['exclude_list']=$exclude_list;
218 $threshold = explode(",",$conf[1]);
219 $this->all_headers[$conf[0]]['threshold']=$threshold;
235 function getHopCount($ref_node, $planetlab_nodes)
238 $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest', 'AuthString' => 'guest');
239 $tophat_api = new TopHatAPI($tophat_auth);
241 $traceroute = $tophat_api->Get('traceroute', 'latest', array('src_hostname' => $ref_node, 'dst_hostname' => $planetlab_nodes), array('dst_hostname', 'hop_count') );
245 if ($traceroute) foreach ($traceroute as $t)
246 $hopcount[$t['dst_hostname']]=$t['hop_count'];
251 //Depending on the columns selected more data might need to be fetched from
254 function fetch_data($nodes) {
256 //TopHat pairwise data
258 if ($this->reference_node != "")
262 if ($nodes) foreach ($nodes as $n)
263 $dd[] = $n['hostname'];
265 if ($potential_nodes) foreach ($potential_nodes as $n)
266 $dd[] = $n['hostname'];
268 print("Calling tophat api for reference node = ".$this->reference_node);
269 $st = time() + microtime();
270 $HopCount = $this->getHopCount($this->reference_node, $dd);
271 printf(" (%.2f ms)<br/>", (time() + microtime()-$st)*100);
272 //print_r($HopCount);
278 function excludeItems($value, $exclude_list, $hh) {
284 if (in_array($value, $exclude_list))
285 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
287 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
289 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
293 function checkThreshold($value, $threshold, $hh) {
296 return array("n/a", array('name'=>$hh, 'display'=>'table-cell'));
299 if ((float) $value >= (float) $threshold[0] && (float) $value <= (float) $threshold[1])
300 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
302 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
304 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
308 function cells($table, $node) {
310 $this->fetch_data($node);
312 foreach ($this->all_headers as $h)
316 if ($h['visible'] != "")
318 if ($this->inTypeC($h['header']))
320 $tagname = $h['tagname'];
321 $value = $node[$tagname];
322 $v = $this->checkThreshold($value, $h['threshold'], $h['header']);
323 $table->cell($v[0],$v[1]);
325 else if ($this->inTypeB($h['header']))
327 $value = $node[$h['tagname']];
328 $v = $this->checkThreshold($value, $h['threshold'], $h['header']);
329 $table->cell($v[0],$v[1]);
331 else if ($this->inTypeD($h['header']))
333 $value = $this->HopCount[$node['hostname']];
334 $v = $this->excludeItems($value, $h['threshold'], $h['header']);
335 $table->cell($v[0],$v[1]);
337 else if ($this->inTypeA($h['header']))
339 $value = $node[$h['tagname']];
340 $v = $this->excludeItems($value, $h['exclude_list'], $h['header']);
341 $table->cell($v[0],$v[1]);
345 $value = $node[$h['tagname']];
346 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
350 if ($node[$h['tagname']])
351 $table->cell($node[$h['tagname']], array('name'=>$h['header'], 'display'=>'none'));
353 $table->cell("??", array('name'=>$h['header'], 'display'=>'none'));
367 function javascript_init() {
369 print("<input type='hidden' id='reference_node' value='".$this->reference_node."' />");
371 print("<script type='text/javascript'>");
372 print("highlightOption('AU');");
373 print("overrideTitles();");
380 function quickselect_html() {
382 //return '<p>This link uses the onclick event handler.<br><a href="#" onclick="setVisible(\'quicklist\');return false" target="_self">Open popup</a></p>';
385 $quickselection = "<select id='quicklist' onChange=changeSelectStatus(this.value)><option value='0'>Short column descriptions and quick add/remove</option>";
386 //$quickselection = "<select id='quicklist'><option value='0'>Short column descriptions and quick add/remove</option>";
388 $optionclass = "out";
389 foreach ($this->all_headers as $h)
391 if ($h['header'] == "hostname" || $h['header'] == "ID")
395 $disabled = "disabled=true";
399 if ($this->headerIsVisible($h['label']))
402 //$selected = "selected=selected";
406 $optionclass = "out";
410 if ($prev_label == $h['label'])
413 $prev_label = $h['label'];
416 //$quickselection.="<option onclick=\"debugfilter('here2');removeSelectHandler(this);\" id='option'".$h['label']." class='".$optionclass."' value='".$h['label']."'><b>".$h['label']."</b>: ".$h['title']."</option>";
417 $quickselection.="<option id='option'".$h['label']." class='".$optionclass."' value='".$h['label']."'><b>".$h['label']."</b>: ".$h['title']."</option>";
421 $quickselection.="</select>";
423 return $quickselection;
428 function configuration_panel_html($showDescription) {
430 if ($showDescription)
435 print("<table align=center cellpadding=10 width=".$table_width.">");
436 print("<tr><th>Add/remove columns</th>");
438 if ($showDescription)
439 print("<th>Column description and configuration</th>");
441 print("</tr><tr><td valign=top width=300>");
443 print('<div id="scrolldiv" style="border : solid 2px grey; padding:4px; width:300px; height:180px; overflow:auto;">');
446 $optionclass = "out";
447 foreach ($this->all_headers as $h)
449 if ($h['header'] == "hostname" || $h['header'] == "ID")
453 $disabled = "disabled=true";
457 if ($this->headerIsVisible($h['label']))
459 $selected = "checked=true";
461 //print("header ".$h['label']." checked!");
472 print("<input type='hidden' id='tagname".$h['header']."' value='".$h['tagname']."'></input>");
474 if ($prev_label == $h['label'])
477 $prev_label = $h['label'];
478 $period = $this->get_selected_period($h['label']);
480 //<input type='hidden' id='fdesc".$h['label']."' value='".$h['description']."'></input>
482 <input type='hidden' id='fetched".$h['label']."' value=',".$period.",".$fetch."'></input>
483 <input type='hidden' id='period".$h['label']."' value='".$period."'></input>
484 <div id='".$h['label']."' name='columnlist' class='".$optionclass."' onclick='highlightOption(this.id)'>
485 <table width=280 id='table".$h['label']."'><tr>
486 <td bgcolor=#CAE8EA align=center width=30><b><span style='color:#3399CC'>".$h['label']."</span></b></td>
487 <td align=left> <span style='height:10px' id ='htitle".$h['label']."'>".$h['title']."</span> </td>
488 <td align=right width=20> <span style='height:10px' id ='loading".$h['label']."'></span> </td>
489 <td align=right width=20><input id='check".$h['label']."' name='".$h['tagname']."' type='checkbox' ".$selected." ".$disabled." autocomplete='off' value='".$h['label']."' onclick='changeCheckStatus(this.id)'></input></td>
490 </tr></table></div></td></tr>");
493 print("</table> </div></td>");
495 if ($showDescription)
497 print("<td valign=top width=400>");
498 print("<div class='myslice' id='selectdescr'> </div></td>");
502 //print("<tr><td align=center>");
503 //print("<input type='button' value='Reset' onclick=resetCols('previousConf') />");
504 //print("<input type='button' value='Default' onclick=saveConfiguration('defaultConf') />");
505 //print("<input type='button' value='Reset table' onclick=\"resetConfiguration()\" />");
507 //print(" <input type='button' value='Save configuration' onclick=saveConfiguration('column_configuration') />");
508 //print(" <input type='button' id='fetchbutton' onclick='fetchData()' value='Fetch data' disabled=true /> </td>");
510 if ($showDescription)
513 print(" </tr> </table>");
518 function column_filter () {
522 Highlight <select onChange="filterByType(this.value)">
523 <option value="none">None</option>
524 <option value="capabilities">Capabilities</option>
525 <option value="statistics">Statistics</option>
526 <option value="network">Network</option>
527 <option value="pairwise">Pairwise</option>
528 <option value="other">Other</option>
535 function column_html ($colHeader, $colName, $colId, $fulldesc, $visible) {
538 $display = 'display:table-cell';
540 $display = 'color:red;display:none';
543 <th class='sample plekit_table' name='confheader".$colHeader."' id='testid' style='".$display."'>
544 <div id=\"".$colId."\" onclick=\"showDescription('".$colHeader."')\" onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div>
549 function column_fix_html ($colHeader, $colName, $colId) {
551 $display = 'display:table-cell';
553 $res="<th name='confheader".$colHeader."' class='fix plekit_table' style='$display'>";
554 $res.= "<div id='$colId' onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div></th>";
560 function graph_html($colHeader) {
562 return "<p><img src='/planetlab/slices/graph.png' width='20' align='BOTTOM'><input type='checkbox' id='graph".$colHeader."'></input> Show details on mouse over";
566 function threshold_html($colHeader) {
568 $updatecall = "updateColumnThreshold('".$colHeader."',window.document.getElementById('min".$colHeader."').value,window.document.getElementById('max".$colHeader."').value);";
570 $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>";
583 function inTypeA($header_name) {
584 $typeA = array('ST','SN','RES','OS','NRR','NTP','NSR','NSF','NDS','NTH','NEC','LRN','LCY','LPR','LCN','LAT','LON','IP','ASN','AST');
585 return in_array($header_name, $typeA);
589 function inTypeB($header_name) {
590 $typeB = array('BW','DS','MS','CC','CR','AS','DU','CN');
591 return in_array($header_name, $typeB);
595 function inTypeC($header_name) {
596 $typeC = array('Rw','Rm','Ry','Lw','Lm','Ly','Sw','Sm','Sy','CFw','CFm','CFy','BUw','BUm','BUy','MUw','MUm','MUy','SSHw','SSHm','SSHy');
597 return in_array($header_name, $typeC);
601 function inTypeD($header_name) {
602 $typeD = array('HC');
603 return in_array($header_name, $typeD);
607 function removeDuration($header)
609 if ($this->inTypeC($header))
610 return substr($header, 0, strlen($header)-1);