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) {
68 //print("<br>".$column['header'].":".$column['headerId'].":".$column['tagname']);
70 if ($column['headerId'] != "")
71 $headerId = $column['headerId'];
73 $headerId = $column['header'];
75 $this->all_headers[$headerId]=array('header'=>$headerId,'type'=>$column['type'],'tagname'=>$column['tagname'],'title'=>$column['title'], 'description'=>$column['title'], 'label'=>$column['header'],'visible'=>false);
78 foreach ($this->extra_columns as $column) {
79 $this->all_headers[$column['header']]=array('header'=>$column['header'],'type'=>$column['type'],'tagname'=>$column['tagname'],'title'=>$column['title'], 'description'=>$column['title'], 'label'=>$column['header'],'visible'=>false);
82 return $this->all_headers;
87 function get_headers() {
89 return $this->all_headers;
93 function get_selected_period($label) {
95 if ($this->all_headers[$label."w"]['visible'])
97 else if ($this->all_headers[$label."m"]['visible'])
99 else if ($this->all_headers[$label."y"]['visible'])
101 else if ($this->all_headers[$label]['visible'])
107 function node_tags() {
109 $fetched_tags = array('node_id');
111 foreach ($this->all_headers as $h)
113 if ($h['visible'] == true)
114 $fetched_tags[] = $h['tagname'];
117 return $fetched_tags;
120 function print_headers() {
124 foreach ($this->all_headers as $h)
126 $headers.="<br>".$h['header'].":".$h['label'].":".$h['tagname'].":".$h['visible'];
131 function get_visible() {
133 $visibleHeaders = array();
135 foreach ($this->all_headers as $h)
137 if ($h['visible'] == true)
138 $visibleHeaders[] = $h['header'];
140 return $visibleHeaders;
143 function headerIsVisible($header_name) {
145 $headersToShow = $this->visible_headers;
147 if (in_array($header_name, $headersToShow))
150 if ($this->inTypeC($header_name."w"))
151 return (in_array($header_name."w", $headersToShow) || in_array($header_name."m", $headersToShow) || in_array($header_name."y", $headersToShow));
164 function parse_configuration($column_configuration) {
166 $this->column_configuration = $column_configuration;
167 //$this->default_configuration = $default_configuration;
169 $columns_conf = explode("|", $column_configuration);
170 foreach ($columns_conf as $c)
172 $conf = explode(":",$c);
174 $this->all_headers[$conf[0]]['visible']=true;
175 //print("<p>".$conf[0]."should be visible now");
176 //print_r($this->all_headers[$conf[0]]);
181 else if ($this->inTypeC($conf[0]))
183 $this->all_headers[$conf[0]]['duration']= substr($conf[0], strlen($conf[0])-1, strlen($conf[0]));
184 $threshold = explode(",",$conf[1]);
185 $this->all_headers[$conf[0]]['threshold']=$threshold;
187 else if ($this->inTypeD($conf[0]))
189 $this->reference_node = $conf[1];
190 $this->reference_node = "planetlab-europe-07.ipv6.lip6.fr";
191 $this->all_headers[$conf[0]]['refnode']=$this->reference_node;
192 $threshold = explode(",",$conf[1]);
193 $this->all_headers[$conf[0]]['threshold']=$threshold;
195 else if ($this->inTypeA($conf[0]))
197 $exclude_list = explode(",",$conf[1]);
198 $this->all_headers[$conf[0]]['exclude_list']=$exclude_list;
202 $threshold = explode(",",$conf[1]);
203 $this->all_headers[$conf[0]]['threshold']=$threshold;
218 function getHopCount($ref_node, $planetlab_nodes)
221 $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest', 'AuthString' => 'guest');
222 $tophat_api = new TopHatAPI($tophat_auth);
224 $traceroute = $tophat_api->Get('traceroute', 'latest', array('src_hostname' => $ref_node, 'dst_hostname' => $planetlab_nodes), array('dst_hostname', 'hop_count') );
228 if ($traceroute) foreach ($traceroute as $t)
229 $hopcount[$t['dst_hostname']]=$t['hop_count'];
234 //Depending on the columns selected more data might need to be fetched from
237 function fetch_data($nodes) {
239 //TopHat pairwise data
241 if ($this->reference_node != "")
245 if ($nodes) foreach ($nodes as $n)
246 $dd[] = $n['hostname'];
248 if ($potential_nodes) foreach ($potential_nodes as $n)
249 $dd[] = $n['hostname'];
251 print("Calling tophat api for reference node = ".$this->reference_node);
252 $st = time() + microtime();
253 $HopCount = $this->getHopCount($this->reference_node, $dd);
254 printf(" (%.2f ms)<br/>", (time() + microtime()-$st)*100);
255 //print_r($HopCount);
261 function excludeItems($value, $exclude_list, $hh) {
267 if (in_array($value, $exclude_list))
268 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
270 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
272 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
275 function checkThreshold($value, $threshold, $hh) {
278 return array("n/a", array('name'=>$hh, 'display'=>'table-cell'));
281 if ((float) $value >= (float) $threshold[0] && (float) $value <= (float) $threshold[1])
282 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
284 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
286 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
290 function cells($table, $node) {
292 $this->fetch_data($node);
294 foreach ($this->all_headers as $h)
298 if ($h['visible'] != "")
300 if ($this->inTypeC($h['header']))
302 $tagname = $h['tagname'];
303 $value = $node[$tagname];
304 $v = $this->checkThreshold($value, $h['threshold'], $h['header']);
305 $table->cell($v[0],$v[1]);
307 else if ($this->inTypeB($h['header']))
309 $value = $node[$h['tagname']];
310 $v = $this->checkThreshold($value, $h['threshold'], $h['header']);
311 $table->cell($v[0],$v[1]);
313 else if ($this->inTypeD($h['header']))
315 $value = $this->HopCount[$node['hostname']];
316 $v = $this->excludeItems($value, $h['threshold'], $h['header']);
317 $table->cell($v[0],$v[1]);
319 else if ($this->inTypeA($h['header']))
321 $value = $node[$h['tagname']];
322 $v = $this->excludeItems($value, $h['exclude_list'], $h['header']);
323 $table->cell($v[0],$v[1]);
327 $value = $node[$h['tagname']];
328 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
332 $table->cell("??", array('name'=>$h['header'], 'display'=>'none'));
346 function javascript_init() {
348 print("<input type='hidden' id='reference_node' value='".$this->reference_node."' />");
350 print("<script type='text/javascript'>");
351 print("highlightOption('AU');");
352 print("overrideTitles();");
359 function quickselect_html() {
361 //return '<p>This link uses the onclick event handler.<br><a href="#" onclick="setVisible(\'quicklist\');return false" target="_self">Open popup</a></p>';
364 $quickselection = "<select id='quicklist' multiple size=10 onChange=changeSelectStatus(this.value)><option value''>Add/remove columns</option>";
366 $optionclass = "out";
367 foreach ($this->all_headers as $h)
369 if ($h['header'] == "hostname")
373 $disabled = "disabled=true";
377 if ($this->headerIsVisible($h['label']))
380 //$selected = "selected=selected";
384 $optionclass = "out";
388 if ($prev_label == $h['label'])
391 $prev_label = $h['label'];
394 $quickselection.="<option id='option'".$h['label']." class='".$optionclass."' '".$selected."' value='".$h['label']."'>".$h['label'].": ".$h['title']."</option>";
398 $quickselection.="</select>";
399 $quickselection.=" <input type='button' id='fetchbutton' onclick='fetchData()' value='Fetch data' disabled=true />";
401 return $quickselection;
406 function quickselect_popup_html() {
408 print('<div id="quickdiv">');
409 print ("<select size='12' id='quicklist' onChange=changeSelectStatus(this.value)>");
412 $optionclass = "out";
413 foreach ($this->all_headers as $h)
415 if ($h['header'] == "hostname")
419 $disabled = "disabled=true";
423 if ($this->headerIsVisible($h['label']))
426 //$selected = "selected=selected";
430 $optionclass = "out";
434 if ($prev_label == $h['label'])
437 $prev_label = $h['label'];
440 print ("<option id='option'".$h['label']." class='".$optionclass."' '".$selected."' value='".$h['label']."'>".$h['label'].": ".$h['title']."</option>");
444 print("</select></div>");
445 print(" <input type='button' id='fetchbutton' onclick='fetchData()' value='Fetch data' disabled=true />");
449 function configuration_panel_html($showDescription) {
452 if ($showDescription)
457 print("<table align=center cellpadding=10 width=".$table_width.">");
458 print("<tr><th>Add/remove columns</th>");
460 if ($showDescription)
461 print("<th>Column description and configuration</th>");
463 print("</tr><tr><td valign=top width=300>");
465 print('<div id="scrolldiv" style="border : solid 2px grey; padding:4px; width:300px; height:180px; overflow:auto;">');
468 $optionclass = "out";
469 foreach ($this->all_headers as $h)
471 if ($h['header'] == "hostname")
475 $disabled = "disabled=true";
479 if ($this->headerIsVisible($h['label']))
481 $selected = "checked=true";
483 //print("header ".$h['label']." checked!");
491 print("<input type='hidden' id='tagname".$h['header']."' value='".$h['tagname']."'></input>");
493 if ($prev_label == $h['label'])
496 $prev_label = $h['label'];
497 $period = $this->get_selected_period($h['label']);
499 //<input type='hidden' id='fdesc".$h['label']."' value='".$h['description']."'></input>
501 <input type='hidden' id='fetched".$h['label']."' value=',".$period.",".$fetch."'></input>
502 <input type='hidden' id='period".$h['label']."' value='".$period."'></input>
503 <div id='".$h['label']."' name='columnlist' class='".$optionclass."' onclick='highlightOption(this.id)'>
504 <table width=280 id='table".$h['label']."'><tr>
505 <td bgcolor=#CAE8EA align=center width=30><b><span style='color:#3399CC'>".$h['label']."</span></b></td>
506 <td align=left> <span style='height:10px' id ='htitle".$h['label']."'>".$h['title']."</span> </td>
507 <td align=right width=20> <span style='height:10px' id ='loading".$h['label']."'></span> </td>
508 <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>
509 </tr></table></div></td></tr>");
512 print("</table> </div></td>");
514 if ($showDescription)
516 print("<td valign=top width=400>");
517 print("<div class='myslice' id='selectdescr'> </div></td>");
521 //print("<tr><td align=center>");
522 //print("<input type='button' value='Reset' onclick=resetCols('previousConf') />");
523 //print("<input type='button' value='Default' onclick=saveConfiguration('defaultConf') />");
524 //print("<input type='button' value='Reset table' onclick=\"resetConfiguration()\" />");
526 //print(" <input type='button' value='Save configuration' onclick=saveConfiguration('column_configuration') />");
527 //print(" <input type='button' id='fetchbutton' onclick='fetchData()' value='Fetch data' disabled=true /> </td>");
529 if ($showDescription)
532 print(" </tr> </table>");
537 function column_filter () {
541 Highlight <select onChange="filterByType(this.value)">
542 <option value="none">None</option>
543 <option value="capabilities">Capabilities</option>
544 <option value="statistics">Statistics</option>
545 <option value="network">Network</option>
546 <option value="pairwise">Pairwise</option>
547 <option value="other">Other</option>
554 function column_html ($colHeader, $colName, $colId, $fulldesc, $visible) {
557 $display = 'display:table-cell';
559 $display = 'color:red;display:none';
562 <th class='sample plekit_table' name='confheader".$colHeader."' id='testid' style='".$display."'>
563 <div id=\"".$colId."\" onclick=\"showDescription('".$colHeader."')\" onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div>
568 function column_fix_html ($colHeader, $colName, $colId) {
570 $display = 'display:table-cell';
572 $res="<th name='confheader".$colHeader."' class='fix plekit_table' style='$display'>";
573 $res.= "<div id='$colId' onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div></th>";
579 function graph_html($colHeader) {
581 return "<p><img src='/planetlab/slices/graph.png' width='20' align='BOTTOM'><input type='checkbox' id='graph".$colHeader."'></input> Show details on mouse over";
585 function threshold_html($colHeader) {
587 $updatecall = "updateColumnThreshold('".$colHeader."',window.document.getElementById('min".$colHeader."').value,window.document.getElementById('max".$colHeader."').value);";
589 $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>";
602 function inTypeA($header_name) {
603 $typeA = array('ST','SN','RES','OS','NRR','NTP','NSR','NSF','NDS','NTH','NEC','LRN','LCY','LPR','LCN','LAT','LON','IP','ASN','AST');
604 return in_array($header_name, $typeA);
608 function inTypeB($header_name) {
609 $typeB = array('BW','DS','MS','CC','CR','AS','DU','CN');
610 return in_array($header_name, $typeB);
614 function inTypeC($header_name) {
615 $typeC = array('Rw','Rm','Ry','Lw','Lm','Ly','Sw','Sm','Sy','CFw','CFm','CFy','BUw','BUm','BUy','MUw','MUm','MUy','SSHw','SSHm','SSHy');
616 return in_array($header_name, $typeC);
620 function inTypeD($header_name) {
621 $typeD = array('HC');
622 return in_array($header_name, $typeD);
626 function removeDuration($header)
628 if ($this->inTypeC($header))
629 return substr($header, 0, strlen($header)-1);