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();
23 var $comon_live_data = "";
24 var $tophat_live_data = "";
25 var $live_data = array();
29 var $HopCount = array();
31 function PlekitColumns ($column_configuration, $fix_columns, $tag_columns, $extra_columns=NULL, $this_table_headers=NULL) {
33 if ($column_configuration != NULL) {
34 $this->fix_columns = $fix_columns;
35 $this->tag_columns = $tag_columns;
36 $this->extra_columns = $extra_columns;
39 //print_r($this->fix_columns);
41 //print_r($this->tag_columns);
42 //print("<p>EXTRA<p>");
43 //print_r($this->extra_columns);
45 $this->prepare_headers();
46 $this->parse_configuration($column_configuration);
48 $this->visible_headers = $this->get_visible();
51 //print("<p>VISIBLE<p>");
52 //print_r($this->visible_headers);
64 function prepare_headers() {
66 foreach ($this->fix_columns as $column) {
67 $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, 'source'=>'myplc');
70 $tmp_headers = array();
72 if ($this->extra_columns)
73 foreach ($this->extra_columns as $column) {
74 $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, 'source'=>$column['source']);
78 if ($this->tag_columns)
79 foreach ($this->tag_columns as $column) {
81 if ($column['headerId'] != "")
82 $headerId = $column['headerId'];
84 $headerId = $column['header'];
86 $tmp_headers[$headerId]=array('header'=>$headerId,'type'=>$column['type'],'tagname'=>$column['tagname'],'title'=>$column['title'], 'description'=>$column['title'], 'label'=>$column['header'],'visible'=>false, 'source'=>'myplc');
89 usort ($tmp_headers, create_function('$col1,$col2','return strcmp($col1["label"],$col2["label"]);'));
91 foreach ($tmp_headers as $t)
92 $this->all_headers[$t['header']] = $t;
94 //$this->all_headers = array_merge($this->all_headers, $tmp_headers);
96 //print($this->print_headers());
98 return $this->all_headers;
103 function get_headers() {
105 return $this->all_headers;
109 function get_selected_period($label) {
111 if ($this->all_headers[$label."w"]['visible'])
113 else if ($this->all_headers[$label."m"]['visible'])
115 else if ($this->all_headers[$label."y"]['visible'])
117 else if ($this->all_headers[$label]['visible'])
123 function node_tags() {
125 $fetched_tags = array('node_id','hostname');
127 foreach ($this->all_headers as $h)
129 if ($h['visible'] == true && $h['tagname'] != "" && !$h['fetched'] && $h['source']=="myplc")
130 $fetched_tags[] = $h['tagname'];
133 return $fetched_tags;
136 function print_headers() {
140 foreach ($this->all_headers as $l => $h)
142 $headers.="<br>[".$l."]=".$h['header'].":".$h['label'].":".$h['tagname'].":".$h['visible'];
147 function get_visible() {
149 $visibleHeaders = array();
151 foreach ($this->all_headers as $h)
153 if ($h['visible'] == true)
154 $visibleHeaders[] = $h['header'];
156 return $visibleHeaders;
159 function headerIsVisible($header_name) {
161 $headersToShow = $this->visible_headers;
163 if (in_array($header_name, $headersToShow))
166 if ($this->inTypeC($header_name."w"))
167 return (in_array($header_name."w", $headersToShow) || in_array($header_name."m", $headersToShow) || in_array($header_name."y", $headersToShow));
180 function parse_configuration($column_configuration) {
182 $this->column_configuration = $column_configuration;
183 //$this->default_configuration = $default_configuration;
185 //print($this->print_headers());
187 $columns_conf = explode("|", $column_configuration);
190 foreach ($columns_conf as $c)
192 $conf = explode(":",$c);
194 if ($conf[0] == "default")
197 if (!$this->all_headers[$conf[0]])
200 $this->all_headers[$conf[0]]['visible']=true;
202 if ($this->all_headers[$conf[0]]['source'] == "comon")
203 $this->comon_live_data.=",".$this->all_headers[$conf[0]]['tagname'];
205 if ($this->all_headers[$conf[0]]['source'] == "tophat")
207 $this->reference_node = $conf[1];
208 print ("ref node in configuration = ".$conf[1]);
209 $this->reference_node = "planetlab-europe-07.ipv6.lip6.fr";
210 $this->all_headers[$conf[0]]['refnode']=$this->reference_node;
211 //$threshold = explode(",",$conf[1]);
212 //$this->all_headers[$conf[0]]['threshold']=$threshold;
215 //print("<p>-".$conf[0]."-should be visible now - ".$this->all_headers[$conf[0]]['visible']);
216 //print_r($this->all_headers[$conf[0]]);
222 else if ($this->inTypeC($conf[0]))
224 $this->all_headers[$conf[0]]['duration']= substr($conf[0], strlen($conf[0])-1, strlen($conf[0]));
225 $threshold = explode(",",$conf[1]);
226 $this->all_headers[$conf[0]]['threshold']=$threshold;
228 else if ($this->inTypeA($conf[0]))
230 $exclude_list = explode(",",$conf[1]);
231 $this->all_headers[$conf[0]]['exclude_list']=$exclude_list;
235 $threshold = explode(",",$conf[1]);
236 $this->all_headers[$conf[0]]['threshold']=$threshold;
253 function convert_data($value, $data_type) {
255 if ($value == "" || $value == null || $value == "n/a" || $value == "None")
258 if ($data_type == "string")
261 if ($data_type == "date")
262 return date("Y-m-d", $value);
264 if ($data_type == "uptime")
265 return (int)((int) $value / 86400);
267 return ((int) ($value * 10))/10;
271 function getHopCount($ref_node, $planetlab_nodes) {
273 $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest', 'AuthString' => 'guest');
274 $tophat_api = new TopHatAPI($tophat_auth);
276 $traceroute = $tophat_api->Get('traceroute', 'latest', array('src_hostname' => $ref_node, 'dst_hostname' => $planetlab_nodes), array('dst_hostname', 'hop_count') );
280 if ($traceroute) foreach ($traceroute as $t)
281 $hopcount[$t['dst_hostname']]=$t['hop_count'];
286 function comon_query_nodes($requested_data) {
287 //$base_url = 'http://comon.cs.princeton.edu/status/tabulator.cgi?forma=nameonly&';
288 $base_url = "http://comon.cs.princeton.edu/status/tabulator.cgi?table=table_nodeviewshort&format=formatcsv&dumpcols='name";
290 $url = $base_url.$requested_data."'";
292 //print ("retriecing comon data for url ".$url);
294 $sPattern = '\', \'';
297 if( false == ($str=file_get_contents($url)))
300 $result=preg_replace( $sPattern, $sReplace, $str );
303 $result=preg_replace( $sPattern, $sReplace, $result );
305 $comon_data = explode(";", $result);
307 $comon_values = array();
309 foreach ($comon_data as $cd) {
310 $cc = explode("|", $cd);
311 if ($cc[0] == "name") {
314 $comon_values[$cc[0]] = array();
316 foreach ($cl as $cltag) {
317 if ($cltag != "name")
318 $comon_values[$cc[0]][$cltag] = $cc[$cindex++];
322 return $comon_values;
326 //Depending on the columns selected more data might need to be fetched from
329 function fetch_live_data($all_nodes) {
331 //print("<p>fetching live data<p>");
334 if ($this->comon_live_data != "") {
336 //print ("live data to be fetched =".$this->comon_live_data);
337 $this->live_data = $this->comon_query_nodes($this->comon_live_data);
338 //print_r($this->live_data);
342 //TopHat pairwise data
343 //if ($this->tophat_live_data != "")
344 if ($this->reference_node != "")
348 if ($all_nodes) foreach ($all_nodes as $n)
349 $dd[] = $n['hostname'];
351 print("Calling tophat api for reference node = ".$this->reference_node);
352 $st = time() + microtime();
353 $HopCount = $this->getHopCount($this->reference_node, $dd);
354 printf(" (%.2f ms)<br/>", (time() + microtime()-$st)*100);
360 function excludeItems($value, $exclude_list, $hh) {
366 if (in_array($value, $exclude_list))
367 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
369 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
371 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
375 function checkThreshold($value, $threshold, $hh) {
378 return array("n/a", array('name'=>$hh, 'display'=>'table-cell'));
381 if ((float) $value >= (float) $threshold[0] && (float) $value <= (float) $threshold[1])
382 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
384 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
386 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
390 function cells($table, $node) {
392 foreach ($this->all_headers as $h)
396 if ($h['visible'] != "")
400 if ($this->inTypeC($h['header']))
402 $tagname = $h['tagname'];
403 $value = $node[$tagname];
404 $v = $this->checkThreshold($value, $h['threshold'], $h['header']);
405 $table->cell($v[0],$v[1]);
407 else if ($this->inTypeB($h['header']))
409 $value = $node[$h['tagname']];
410 $v = $this->checkThreshold($value, $h['threshold'], $h['header']);
411 $table->cell($v[0],$v[1]);
413 else if ($this->inTypeD($h['header']))
415 $value = $this->HopCount[$node['hostname']];
416 $v = $this->excludeItems($value, $h['threshold'], $h['header']);
417 $table->cell($v[0],$v[1]);
419 else if ($this->inTypeA($h['header']))
421 $value = $node[$h['tagname']];
422 $v = $this->excludeItems($value, $h['exclude_list'], $h['header']);
423 $table->cell($v[0],$v[1]);
426 if ($h['type'] == "date")
428 $value = $this->convert_data($node[$h['tagname']], $h['type']);
429 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
431 else if ($h['source'] == "comon")
433 //print("<br>Searching for ".$h['tagname']."at ".$node);
434 $value = $this->convert_data($this->live_data[$node['hostname']][$h['tagname']], $h['tagname']);
436 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
440 //$value = $node[$h['tagname']];
441 $value = $this->convert_data($node[$h['tagname']], $h['type']);
442 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
446 if ($node[$h['tagname']])
448 $value = $this->convert_data($node[$h['tagname']], $h['type']);
449 $table->cell($value, array('name'=>$h['header'], 'display'=>'none'));
452 if ($node[$h['fetched']])
453 $table->cell("n/a", array('name'=>$h['header'], 'display'=>'none'));
455 $table->cell("??", array('name'=>$h['header'], 'display'=>'none'));
469 function javascript_init() {
471 print("<input type='hidden' id='selected_reference_node' value='".$this->reference_node."' />");
473 print("<script type='text/javascript'>");
474 print("highlightOption('AU');");
475 print("overrideTitles();");
480 function quickselect_html() {
482 //return '<p>This link uses the onclick event handler.<br><a href="#" onclick="setVisible(\'quicklist\');return false" target="_self">Open popup</a></p>';
485 $quickselection = "<select id='quicklist' onChange=changeSelectStatus(this.value)><option value='0'>Short column descriptions and quick add/remove</option>";
486 //$quickselection = "<select id='quicklist'><option value='0'>Short column descriptions and quick add/remove</option>";
488 $optionclass = "out";
489 foreach ($this->all_headers as $h)
491 if ($h['header'] == "hostname" || $h['header'] == "ID")
495 $disabled = "disabled=true";
499 if ($this->headerIsVisible($h['label']))
502 //$selected = "selected=selected";
506 $optionclass = "out";
510 if ($prev_label == $h['label'])
513 $prev_label = $h['label'];
516 //$quickselection.="<option onclick=\"debugfilter('here2');removeSelectHandler(this);\" id='option'".$h['label']." class='".$optionclass."' value='".$h['label']."'><b>".$h['label']."</b>: ".$h['title']."</option>";
517 $quickselection.="<option id='option'".$h['label']." class='".$optionclass."' value='".$h['label']."'><b>".$h['label']."</b>: ".$h['title']."</option>";
521 $quickselection.="</select>";
523 return $quickselection;
528 function configuration_panel_html($showDescription) {
530 if ($showDescription)
535 print("<table align=center cellpadding=10 width=".$table_width.">");
536 print("<tr><th>Add/remove columns</th>");
538 if ($showDescription)
539 print("<th>Column description and configuration</th>");
541 print("</tr><tr><td valign=top width=300>");
543 print('<div id="scrolldiv" style="border : solid 2px grey; padding:4px; width:300px; height:180px; overflow:auto;">');
546 $optionclass = "out";
547 foreach ($this->all_headers as $h)
549 if ($h['header'] == "hostname" || $h['header'] == "ID")
553 $disabled = "disabled=true";
557 if ($this->headerIsVisible($h['label']))
559 $selected = "checked=true";
561 //print("header ".$h['label']." checked!");
572 print("<input type='hidden' id='tagname".$h['header']."' value='".$h['tagname']."'></input>");
574 if ($prev_label == $h['label'])
577 $prev_label = $h['label'];
578 $period = $this->get_selected_period($h['label']);
580 //<input type='hidden' id='fdesc".$h['label']."' value='".$h['description']."'></input>
582 <input type='hidden' id='fetched".$h['label']."' value=',".$period.",".$fetch."'></input>
583 <input type='hidden' id='period".$h['label']."' value='".$period."'></input>
584 <input type='hidden' id='type".$h['label']."' value='".$h['type']."'></input>
585 <input type='hidden' id='source".$h['label']."' value='".$h['source']."'></input>
586 <div id='".$h['label']."' name='columnlist' class='".$optionclass."' onclick='highlightOption(this.id)'>
587 <table width=280 id='table".$h['label']."'><tr>
588 <td bgcolor=#CAE8EA align=center width=30><b><span style='color:#3399CC'>".$h['label']."</span></b></td>
589 <td align=left> <span style='height:10px' id ='htitle".$h['label']."'>".$h['title']."</span> </td>
590 <td align=right width=20> <span style='height:10px' id ='loading".$h['label']."'></span> </td>
591 <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>
592 </tr></table></div></td></tr>");
595 print("</table> </div></td>");
597 if ($showDescription)
599 print("<td valign=top width=400>");
600 print("<div class='myslice' id='selectdescr'> </div></td>");
604 //print("<tr><td align=center>");
605 //print("<input type='button' value='Reset' onclick=resetCols('previousConf') />");
606 //print("<input type='button' value='Default' onclick=saveConfiguration('defaultConf') />");
607 //print("<input type='button' value='Reset table' onclick=\"resetConfiguration()\" />");
609 //print(" <input type='button' value='Save configuration' onclick=saveConfiguration('column_configuration') />");
610 //print(" <input type='button' id='fetchbutton' onclick='fetchData()' value='Fetch data' disabled=true /> </td>");
612 if ($showDescription)
615 print(" </tr> </table>");
620 function column_filter () {
624 Highlight <select onChange="filterByType(this.value)">
625 <option value="none">None</option>
626 <option value="capabilities">Capabilities</option>
627 <option value="statistics">Statistics</option>
628 <option value="network">Network</option>
629 <option value="pairwise">Pairwise</option>
630 <option value="other">Other</option>
637 function column_html ($colHeader, $colName, $colId, $fulldesc, $visible) {
640 $display = 'display:table-cell';
642 $display = 'color:red;display:none';
645 <th class='sample plekit_table' name='confheader".$colHeader."' id='testid' style='".$display."'>
646 <div id=\"".$colId."\" onclick=\"showDescription('".$colHeader."')\" onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div>
651 function column_fix_html ($colHeader, $colName, $colId) {
653 $display = 'display:table-cell';
655 $res="<th name='confheader".$colHeader."' class='fix plekit_table' style='$display'>";
656 $res.= "<div id='$colId' onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div></th>";
662 function graph_html($colHeader) {
664 return "<p><img src='/planetlab/slices/graph.png' width='20' align='BOTTOM'><input type='checkbox' id='graph".$colHeader."'></input> Show details on mouse over";
668 function threshold_html($colHeader) {
670 $updatecall = "updateColumnThreshold('".$colHeader."',window.document.getElementById('min".$colHeader."').value,window.document.getElementById('max".$colHeader."').value);";
672 $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>";
685 function inTypeA($header_name) {
686 $typeA = array('ST','SN','RES','OS','NRR','NTP','NSR','NSF','NDS','NTH','NEC','LRN','LCY','LPR','LCN','LAT','LON','IP','ASN','AST');
687 return in_array($header_name, $typeA);
691 function inTypeB($header_name) {
692 $typeB = array('BW','DS','MS','CC','CR','AS','DU','CN');
693 return in_array($header_name, $typeB);
697 function inTypeC($header_name) {
698 $typeC = array('Rw','Rm','Ry','Lw','Lm','Ly','Sw','Sm','Sy','CFw','CFm','CFy','BUw','BUm','BUy','MUw','MUm','MUy','SSHw','SSHm','SSHy');
699 return in_array($header_name, $typeC);
703 function inTypeD($header_name) {
704 $typeD = array('HC');
705 return in_array($header_name, $typeD);
709 function removeDuration($header)
711 if ($this->inTypeC($header))
712 return substr($header, 0, strlen($header)-1);