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();
71 foreach ($this->tag_columns as $column) {
73 if ($column['headerId'] != "")
74 $headerId = $column['headerId'];
76 $headerId = $column['header'];
78 //$this->all_headers[$headerId]=array('header'=>$headerId,'type'=>$column['type'],'tagname'=>$column['tagname'],'title'=>$column['title'], 'description'=>$column['title'], 'label'=>$column['header'],'visible'=>false);
79 $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');
82 if ($this->extra_columns)
83 foreach ($this->extra_columns as $column) {
84 //$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);
85 $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']);
87 usort ($tmp_headers, create_function('$col1,$col2','return strcmp($col1["label"],$col2["label"]);'));
90 foreach ($tmp_headers as $t)
91 $this->all_headers[$t['header']] = $t;
93 //$this->all_headers = array_merge($this->all_headers, $tmp_headers);
95 //print($this->print_headers());
97 return $this->all_headers;
102 function get_headers() {
104 return $this->all_headers;
108 function get_selected_period($label) {
110 if ($this->all_headers[$label."w"]['visible'])
112 else if ($this->all_headers[$label."m"]['visible'])
114 else if ($this->all_headers[$label."y"]['visible'])
116 else if ($this->all_headers[$label]['visible'])
122 function node_tags() {
124 $fetched_tags = array('node_id','hostname');
126 foreach ($this->all_headers as $h)
128 if ($h['visible'] == true && $h['tagname'] != "" && !$h['fetched'] && $h['source']=="myplc")
129 $fetched_tags[] = $h['tagname'];
132 return $fetched_tags;
135 function print_headers() {
139 foreach ($this->all_headers as $l => $h)
141 $headers.="<br>[".$l."]=".$h['header'].":".$h['label'].":".$h['tagname'].":".$h['visible'];
146 function get_visible() {
148 $visibleHeaders = array();
150 foreach ($this->all_headers as $h)
152 if ($h['visible'] == true)
153 $visibleHeaders[] = $h['header'];
155 return $visibleHeaders;
158 function headerIsVisible($header_name) {
160 $headersToShow = $this->visible_headers;
162 if (in_array($header_name, $headersToShow))
165 if ($this->inTypeC($header_name."w"))
166 return (in_array($header_name."w", $headersToShow) || in_array($header_name."m", $headersToShow) || in_array($header_name."y", $headersToShow));
179 function parse_configuration($column_configuration) {
181 $this->column_configuration = $column_configuration;
182 //$this->default_configuration = $default_configuration;
184 //print($this->print_headers());
186 $columns_conf = explode("|", $column_configuration);
189 foreach ($columns_conf as $c)
191 $conf = explode(":",$c);
193 if ($conf[0] == "default")
196 if (!$this->all_headers[$conf[0]])
199 $this->all_headers[$conf[0]]['visible']=true;
201 if ($this->all_headers[$conf[0]]['source'] == "comon")
202 $this->comon_live_data.=",".$this->all_headers[$conf[0]]['tagname'];
204 if ($this->all_headers[$conf[0]]['source'] == "tophat")
206 $this->reference_node = $conf[1];
207 print ("ref node in configuration = ".$conf[1]);
208 $this->reference_node = "planetlab-europe-07.ipv6.lip6.fr";
209 $this->all_headers[$conf[0]]['refnode']=$this->reference_node;
210 //$threshold = explode(",",$conf[1]);
211 //$this->all_headers[$conf[0]]['threshold']=$threshold;
214 //print("<p>-".$conf[0]."-should be visible now - ".$this->all_headers[$conf[0]]['visible']);
215 //print_r($this->all_headers[$conf[0]]);
221 else if ($this->inTypeC($conf[0]))
223 $this->all_headers[$conf[0]]['duration']= substr($conf[0], strlen($conf[0])-1, strlen($conf[0]));
224 $threshold = explode(",",$conf[1]);
225 $this->all_headers[$conf[0]]['threshold']=$threshold;
227 else if ($this->inTypeA($conf[0]))
229 $exclude_list = explode(",",$conf[1]);
230 $this->all_headers[$conf[0]]['exclude_list']=$exclude_list;
234 $threshold = explode(",",$conf[1]);
235 $this->all_headers[$conf[0]]['threshold']=$threshold;
252 function convert_data($value, $data_type) {
254 if ($value == "" || $value == null || $value == "n/a" || $value == "None")
257 if ($data_type == "string")
260 if ($data_type == "date")
261 return date("Y-m-d", $value);
263 if ($data_type == "uptime")
264 return (int)((int) $value / 86400);
266 return ((int) ($value * 10))/10;
270 function getHopCount($ref_node, $planetlab_nodes) {
272 $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest', 'AuthString' => 'guest');
273 $tophat_api = new TopHatAPI($tophat_auth);
275 $traceroute = $tophat_api->Get('traceroute', 'latest', array('src_hostname' => $ref_node, 'dst_hostname' => $planetlab_nodes), array('dst_hostname', 'hop_count') );
279 if ($traceroute) foreach ($traceroute as $t)
280 $hopcount[$t['dst_hostname']]=$t['hop_count'];
285 function comon_query_nodes($requested_data) {
286 //$base_url = 'http://comon.cs.princeton.edu/status/tabulator.cgi?forma=nameonly&';
287 $base_url = "http://comon.cs.princeton.edu/status/tabulator.cgi?table=table_nodeviewshort&format=formatcsv&dumpcols='name";
289 $url = $base_url.$requested_data."'";
291 //print ("retriecing comon data for url ".$url);
293 $sPattern = '\', \'';
296 if( false == ($str=file_get_contents($url)))
299 $result=preg_replace( $sPattern, $sReplace, $str );
302 $result=preg_replace( $sPattern, $sReplace, $result );
304 $comon_data = explode(";", $result);
306 $comon_values = array();
308 foreach ($comon_data as $cd) {
309 $cc = explode("|", $cd);
310 if ($cc[0] == "name") {
313 $comon_values[$cc[0]] = array();
315 foreach ($cl as $cltag) {
316 if ($cltag != "name")
317 $comon_values[$cc[0]][$cltag] = $cc[$cindex++];
321 return $comon_values;
325 //Depending on the columns selected more data might need to be fetched from
328 function fetch_live_data($all_nodes) {
330 //print("<p>fetching live data<p>");
333 if ($this->comon_live_data != "") {
335 //print ("live data to be fetched =".$this->comon_live_data);
336 $this->live_data = $this->comon_query_nodes($this->comon_live_data);
337 //print_r($this->live_data);
341 //TopHat pairwise data
342 //if ($this->tophat_live_data != "")
343 if ($this->reference_node != "")
347 if ($all_nodes) foreach ($all_nodes as $n)
348 $dd[] = $n['hostname'];
350 print("Calling tophat api for reference node = ".$this->reference_node);
351 $st = time() + microtime();
352 $HopCount = $this->getHopCount($this->reference_node, $dd);
353 printf(" (%.2f ms)<br/>", (time() + microtime()-$st)*100);
359 function excludeItems($value, $exclude_list, $hh) {
365 if (in_array($value, $exclude_list))
366 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
368 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
370 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
374 function checkThreshold($value, $threshold, $hh) {
377 return array("n/a", array('name'=>$hh, 'display'=>'table-cell'));
380 if ((float) $value >= (float) $threshold[0] && (float) $value <= (float) $threshold[1])
381 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
383 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
385 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
389 function cells($table, $node) {
391 foreach ($this->all_headers as $h)
395 if ($h['visible'] != "")
399 if ($this->inTypeC($h['header']))
401 $tagname = $h['tagname'];
402 $value = $node[$tagname];
403 $v = $this->checkThreshold($value, $h['threshold'], $h['header']);
404 $table->cell($v[0],$v[1]);
406 else if ($this->inTypeB($h['header']))
408 $value = $node[$h['tagname']];
409 $v = $this->checkThreshold($value, $h['threshold'], $h['header']);
410 $table->cell($v[0],$v[1]);
412 else if ($this->inTypeD($h['header']))
414 $value = $this->HopCount[$node['hostname']];
415 $v = $this->excludeItems($value, $h['threshold'], $h['header']);
416 $table->cell($v[0],$v[1]);
418 else if ($this->inTypeA($h['header']))
420 $value = $node[$h['tagname']];
421 $v = $this->excludeItems($value, $h['exclude_list'], $h['header']);
422 $table->cell($v[0],$v[1]);
425 if ($h['type'] == "date")
427 $value = $this->convert_data($node[$h['tagname']], $h['type']);
428 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
430 else if ($h['source'] == "comon")
432 //print("<br>Searching for ".$h['tagname']."at ".$node);
433 $value = $this->convert_data($this->live_data[$node['hostname']][$h['tagname']], $h['tagname']);
435 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
439 //$value = $node[$h['tagname']];
440 $value = $this->convert_data($node[$h['tagname']], $h['type']);
441 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
445 if ($node[$h['tagname']])
447 $value = $this->convert_data($node[$h['tagname']], $h['type']);
448 $table->cell($value, array('name'=>$h['header'], 'display'=>'none'));
451 if ($node[$h['fetched']])
452 $table->cell("n/a", array('name'=>$h['header'], 'display'=>'none'));
454 $table->cell("??", array('name'=>$h['header'], 'display'=>'none'));
468 function javascript_init() {
470 print("<input type='hidden' id='selected_reference_node' value='".$this->reference_node."' />");
472 print("<script type='text/javascript'>");
473 print("highlightOption('AU');");
474 print("overrideTitles();");
479 function quickselect_html() {
481 //return '<p>This link uses the onclick event handler.<br><a href="#" onclick="setVisible(\'quicklist\');return false" target="_self">Open popup</a></p>';
484 $quickselection = "<select id='quicklist' onChange=changeSelectStatus(this.value)><option value='0'>Short column descriptions and quick add/remove</option>";
485 //$quickselection = "<select id='quicklist'><option value='0'>Short column descriptions and quick add/remove</option>";
487 $optionclass = "out";
488 foreach ($this->all_headers as $h)
490 if ($h['header'] == "hostname" || $h['header'] == "ID")
494 $disabled = "disabled=true";
498 if ($this->headerIsVisible($h['label']))
501 //$selected = "selected=selected";
505 $optionclass = "out";
509 if ($prev_label == $h['label'])
512 $prev_label = $h['label'];
515 //$quickselection.="<option onclick=\"debugfilter('here2');removeSelectHandler(this);\" id='option'".$h['label']." class='".$optionclass."' value='".$h['label']."'><b>".$h['label']."</b>: ".$h['title']."</option>";
516 $quickselection.="<option id='option'".$h['label']." class='".$optionclass."' value='".$h['label']."'><b>".$h['label']."</b>: ".$h['title']."</option>";
520 $quickselection.="</select>";
522 return $quickselection;
527 function configuration_panel_html($showDescription) {
529 if ($showDescription)
534 print("<table align=center cellpadding=10 width=".$table_width.">");
535 print("<tr><th>Add/remove columns</th>");
537 if ($showDescription)
538 print("<th>Column description and configuration</th>");
540 print("</tr><tr><td valign=top width=300>");
542 print('<div id="scrolldiv" style="border : solid 2px grey; padding:4px; width:300px; height:180px; overflow:auto;">');
545 $optionclass = "out";
546 foreach ($this->all_headers as $h)
548 if ($h['header'] == "hostname" || $h['header'] == "ID")
552 $disabled = "disabled=true";
556 if ($this->headerIsVisible($h['label']))
558 $selected = "checked=true";
560 //print("header ".$h['label']." checked!");
571 print("<input type='hidden' id='tagname".$h['header']."' value='".$h['tagname']."'></input>");
573 if ($prev_label == $h['label'])
576 $prev_label = $h['label'];
577 $period = $this->get_selected_period($h['label']);
579 //<input type='hidden' id='fdesc".$h['label']."' value='".$h['description']."'></input>
581 <input type='hidden' id='fetched".$h['label']."' value=',".$period.",".$fetch."'></input>
582 <input type='hidden' id='period".$h['label']."' value='".$period."'></input>
583 <input type='hidden' id='type".$h['label']."' value='".$h['type']."'></input>
584 <input type='hidden' id='source".$h['label']."' value='".$h['source']."'></input>
585 <div id='".$h['label']."' name='columnlist' class='".$optionclass."' onclick='highlightOption(this.id)'>
586 <table width=280 id='table".$h['label']."'><tr>
587 <td bgcolor=#CAE8EA align=center width=30><b><span style='color:#3399CC'>".$h['label']."</span></b></td>
588 <td align=left> <span style='height:10px' id ='htitle".$h['label']."'>".$h['title']."</span> </td>
589 <td align=right width=20> <span style='height:10px' id ='loading".$h['label']."'></span> </td>
590 <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>
591 </tr></table></div></td></tr>");
594 print("</table> </div></td>");
596 if ($showDescription)
598 print("<td valign=top width=400>");
599 print("<div class='myslice' id='selectdescr'> </div></td>");
603 //print("<tr><td align=center>");
604 //print("<input type='button' value='Reset' onclick=resetCols('previousConf') />");
605 //print("<input type='button' value='Default' onclick=saveConfiguration('defaultConf') />");
606 //print("<input type='button' value='Reset table' onclick=\"resetConfiguration()\" />");
608 //print(" <input type='button' value='Save configuration' onclick=saveConfiguration('column_configuration') />");
609 //print(" <input type='button' id='fetchbutton' onclick='fetchData()' value='Fetch data' disabled=true /> </td>");
611 if ($showDescription)
614 print(" </tr> </table>");
619 function column_filter () {
623 Highlight <select onChange="filterByType(this.value)">
624 <option value="none">None</option>
625 <option value="capabilities">Capabilities</option>
626 <option value="statistics">Statistics</option>
627 <option value="network">Network</option>
628 <option value="pairwise">Pairwise</option>
629 <option value="other">Other</option>
636 function column_html ($colHeader, $colName, $colId, $fulldesc, $visible) {
639 $display = 'display:table-cell';
641 $display = 'color:red;display:none';
644 <th class='sample plekit_table' name='confheader".$colHeader."' id='testid' style='".$display."'>
645 <div id=\"".$colId."\" onclick=\"showDescription('".$colHeader."')\" onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div>
650 function column_fix_html ($colHeader, $colName, $colId) {
652 $display = 'display:table-cell';
654 $res="<th name='confheader".$colHeader."' class='fix plekit_table' style='$display'>";
655 $res.= "<div id='$colId' onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div></th>";
661 function graph_html($colHeader) {
663 return "<p><img src='/planetlab/slices/graph.png' width='20' align='BOTTOM'><input type='checkbox' id='graph".$colHeader."'></input> Show details on mouse over";
667 function threshold_html($colHeader) {
669 $updatecall = "updateColumnThreshold('".$colHeader."',window.document.getElementById('min".$colHeader."').value,window.document.getElementById('max".$colHeader."').value);";
671 $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>";
684 function inTypeA($header_name) {
685 $typeA = array('ST','SN','RES','OS','NRR','NTP','NSR','NSF','NDS','NTH','NEC','LRN','LCY','LPR','LCN','LAT','LON','IP','ASN','AST');
686 return in_array($header_name, $typeA);
690 function inTypeB($header_name) {
691 $typeB = array('BW','DS','MS','CC','CR','AS','DU','CN');
692 return in_array($header_name, $typeB);
696 function inTypeC($header_name) {
697 $typeC = array('Rw','Rm','Ry','Lw','Lm','Ly','Sw','Sm','Sy','CFw','CFm','CFy','BUw','BUm','BUy','MUw','MUm','MUy','SSHw','SSHm','SSHy');
698 return in_array($header_name, $typeC);
702 function inTypeD($header_name) {
703 $typeD = array('HC');
704 return in_array($header_name, $typeD);
708 function removeDuration($header)
710 if ($this->inTypeC($header))
711 return substr($header, 0, strlen($header)-1);