3 require_once 'tophat_api.php';
6 <script type="text/javascript" src="/plekit/table/columns.js"></script>
11 var $column_configuration = "";
12 var $reference_nodes = array();
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 $ComonData = array();
26 var $TopHatData = array();
27 var $TopHatAgents = array();
31 var $HopCount = array();
34 function PlekitColumns ($column_configuration, $fix_columns, $tag_columns, $extra_columns=NULL, $this_table_headers=NULL) {
36 if ($column_configuration != NULL) {
37 $this->fix_columns = $fix_columns;
38 $this->tag_columns = $tag_columns;
39 $this->extra_columns = $extra_columns;
41 $this->prepare_headers();
42 $this->parse_configuration($column_configuration);
44 $this->visible_headers = $this->get_visible();
56 function prepare_headers() {
58 foreach ($this->fix_columns as $column) {
59 $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');
62 $tmp_headers = array();
64 if ($this->extra_columns)
65 foreach ($this->extra_columns as $column) {
66 $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']);
70 if ($this->tag_columns)
71 foreach ($this->tag_columns as $column) {
73 if ($column['headerId'] != "")
74 $headerId = $column['headerId'];
76 $headerId = $column['header'];
78 $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');
81 usort ($tmp_headers, create_function('$col1,$col2','return strcmp($col1["label"],$col2["label"]);'));
83 foreach ($tmp_headers as $t)
84 $this->all_headers[$t['header']] = $t;
86 //$this->all_headers = array_merge($this->all_headers, $tmp_headers);
88 //print($this->print_headers());
90 return $this->all_headers;
95 function get_headers() {
97 return $this->all_headers;
101 function get_selected_period($label) {
103 if ($this->all_headers[$label."w"]['visible'])
105 else if ($this->all_headers[$label."m"]['visible'])
107 else if ($this->all_headers[$label."y"]['visible'])
109 else if ($this->all_headers[$label]['visible'])
115 function node_tags() {
117 $fetched_tags = array('node_id','hostname');
119 foreach ($this->all_headers as $h)
121 if ($h['visible'] == true && $h['tagname'] != "" && !$h['fetched'] && $h['source']=="myplc")
122 $fetched_tags[] = $h['tagname'];
125 return $fetched_tags;
128 function print_headers() {
132 foreach ($this->all_headers as $l => $h)
134 $headers.="<br>[".$l."]=".$h['header'].":".$h['label'].":".$h['tagname'].":".$h['visible'];
139 function get_visible() {
141 $visibleHeaders = array();
143 foreach ($this->all_headers as $h)
145 if ($h['visible'] == true)
146 $visibleHeaders[] = $h['header'];
148 return $visibleHeaders;
151 function headerIsVisible($header_name) {
153 $headersToShow = $this->visible_headers;
155 if (in_array($header_name, $headersToShow))
158 if ($this->inTypeC($header_name."w"))
159 return (in_array($header_name."w", $headersToShow) || in_array($header_name."m", $headersToShow) || in_array($header_name."y", $headersToShow));
172 function parse_configuration($column_configuration) {
174 $this->column_configuration = $column_configuration;
175 $columns_conf = explode("|", $column_configuration);
178 foreach ($columns_conf as $c)
180 $conf = explode(":",$c);
182 if ($conf[0] == "default")
185 if (!$this->all_headers[$conf[0]])
188 $this->all_headers[$conf[0]]['visible']=true;
190 if ($this->all_headers[$conf[0]]['source'] == "comon")
191 $this->comon_live_data.=",".$this->all_headers[$conf[0]]['tagname'];
193 if ($this->all_headers[$conf[0]]['source'] == "tophat")
195 if ($this->all_headers[$conf[0]]['tagname'] == 'hopcount')
197 $this->reference_nodes['hopcount'] = $conf[1];
198 //print ("ref node in configuration = ".$conf[1]);
199 $this->all_headers[$conf[0]]['refnode']=$this->reference_nodes['hopcount'];
201 else if (strpos($this->all_headers[$conf[0]]['tagname'],"agents") === false)
202 $this->tophat_live_data.=",".$this->all_headers[$conf[0]]['tagname'];
203 //$threshold = explode(",",$conf[1]);
204 //$this->all_headers[$conf[0]]['threshold']=$threshold;
207 //print_r($this->all_headers[$conf[0]]);
210 else if ($this->inTypeC($conf[0]))
212 $threshold = explode(",",$conf[1]);
213 $this->all_headers[$conf[0]]['threshold']=$threshold;
215 else if ($this->inTypeA($conf[0]))
217 $exclude_list = explode(",",$conf[1]);
218 $this->all_headers[$conf[0]]['exclude_list']=$exclude_list;
235 function convert_data($value, $data_type) {
237 //print "converting ".$value." as ".$data_type;
239 if ($value == "" || $value == null || $value == "n/a" || $value == "None")
242 if ($data_type == "string")
245 if ($data_type == "date")
246 return date("Y-m-d", $value);
248 if ($data_type == "uptime")
249 return (int)((int) $value / 86400);
251 if (is_numeric($value))
252 return ((int) ($value * 10))/10;
258 function getTopHatAgents() {
260 $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest@top-hat.info', 'AuthString' => 'guest');
261 $tophat_api = new TopHatAPI($tophat_auth);
263 //print ("Requesting tophat agents...");
266 $values = $tophat_api->Get('agents', 'latest', array('colocated.platform_name' => array('SONoMA', 'DIMES', 'ETOMIC', 'TDMI'), 'platform_name'=> 'TDMI'), array('hostname', 'colocated.peer_name', 'colocated.platform_name'));
270 if ($values) foreach ($values as $t) {
273 $result[$t['hostname']] = "";
274 foreach ($t['colocated'] as $ll) {
276 if (strpos($result[$t['hostname']]['all'],$ll['platform_name']) === false) {
277 if ($result[$t['hostname']]['all'] != "")
278 $result[$t['hostname']]['all'] .= ",";
279 $result[$t['hostname']]['all'] .= $ll['platform_name'];
282 if ($ll['platform_name'] == 'SONoMA') {
283 if (strpos($result[$t['hostname']]['sonoma'],$ll['peer_name']) === false) {
284 if ($result[$t['hostname']]['sonoma'] != "")
285 $result[$t['hostname']]['sonoma'] .= ",";
286 $result[$t['hostname']]['sonoma'] .= $ll['peer_name'];
290 if ($ll['platform_name'] == 'TDMI') {
291 if (strpos($result[$t['hostname']]['tdmi'],$ll['peer_name']) === false) {
292 if ($result[$t['hostname']]['tdmi'] != "")
293 $result[$t['hostname']]['tdmi'] .= ",";
294 $result[$t['hostname']]['tdmi'] .= $ll['peer_name'];
300 $this->TopHatAgents = $result;
302 //print_r($this->TopHatAgents);
307 function getTopHatData($data, $planetlab_nodes) {
309 $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest@top-hat.info', 'AuthString' => 'guest');
310 $tophat_api = new TopHatAPI($tophat_auth);
312 $requested_data = explode(",", $data);
314 $r = array ('hostname');
316 foreach ($requested_data as $rd)
319 //print ("Requesting data from TopHat ...");
322 $values = $tophat_api->Get('ips', 'latest', array('hostname' => $planetlab_nodes), $r );
326 if ($values) foreach ($values as $t)
327 foreach ($requested_data as $rd)
328 if ($rd) $result[$t['hostname']][$rd] = $t[$rd];
335 function getTopHatRefNodes() {
337 $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest@top-hat.info', 'AuthString' => 'guest');
338 $tophat_api = new TopHatAPI($tophat_auth);
340 //print "calling tophat for agents";
342 $agents = $tophat_api->Get('agents', 'latest', array('peer_name'=>array('PLC', 'PLE'), 'agent_status'=> 'OK'), array('hostname'));
350 function getPairwise($ref_node, $planetlab_nodes, $command, $data) {
352 $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest@top-hat.info', 'AuthString' => 'guest');
353 $tophat_api = new TopHatAPI($tophat_auth);
355 $traceroute = $tophat_api->Get($command, 'latest', array('src_hostname' => $ref_node, 'dst_hostname' => $planetlab_nodes), array('dst_hostname', $data) );
357 print "Got result: ".$traceroute;
363 foreach ($traceroute as $t)
365 $hopcount[$t['dst_hostname']]=$t[$data];
366 //print " current: ".$t['dst_hostname'].":".$t['hop_count'];
375 function comon_query_nodes($requested_data) {
377 $comon_url = "http://comon.cs.princeton.edu";
378 $comon_api_url = "status/tabulator.cgi?table=table_nodeviewshort&format=formatcsv&dumpcols='name";
380 if (MYSLICE_COMON_URL != "")
381 $comon_url = MYSLICE_COMON_URL;
383 $url = $comon_url."/".$comon_api_url.$requested_data."'";
385 //print ("Retrieving comon data for url ".$url);
387 $sPattern = '\', \'';
390 $str=file_get_contents($url);
395 $result=preg_replace( $sPattern, $sReplace, $str );
398 $result=preg_replace( $sPattern, $sReplace, $result );
400 $comon_data = explode(";", $result);
402 $comon_values = array();
404 foreach ($comon_data as $cd) {
405 $cc = explode("|", $cd);
406 if ($cc[0] == "name") {
409 $comon_values[$cc[0]] = array();
411 foreach ($cl as $cltag) {
412 if ($cltag != "name")
413 $comon_values[$cc[0]][$cltag] = $cc[$cindex++];
417 return $comon_values;
421 //Depending on the columns selected more data might need to be fetched from
424 function fetch_live_data($all_nodes) {
426 //print("<p>fetching live data<p>");
429 if ($this->comon_live_data != "") {
431 //print ("live data to be fetched =".$this->comon_live_data);
432 $this->ComonData= $this->comon_query_nodes($this->comon_live_data);
433 //print_r($this->ComonData);
436 //TopHat per_node data
437 if ($this->tophat_live_data != "")
441 if ($all_nodes) foreach ($all_nodes as $n)
442 $dd[] = $n['hostname'];
444 //print("Calling tophat api for ".$this->tophat_live_data);
445 $st = time() + microtime();
446 $this->TopHatData = $this->getTopHatData($this->tophat_live_data, $dd);
447 //printf(" (%.2f ms)<br/>", (time() + microtime()-$st)*100);
448 //print_r($this->TopHatData);
451 //TopHat pairwise data
453 $this->HopCount = "";
456 if ($this->reference_nodes != "")
458 //print_r($this->reference_nodes);
462 if ($all_nodes) foreach ($all_nodes as $n)
463 $dd[] = $n['hostname'];
465 $st = time() + microtime();
466 if ($this->headerIsVisible("HC"))
468 print("[NEW] Calling tophat api for HopCount with reference node = ".$this->reference_nodes['hopcount']);
469 $this->HopCount = $this->getPairwise($this->reference_nodes['hopcount'], $dd, 'traceroute', 'hop_count');
473 if ($this->headerIsVisible("RTT"))
475 print("[NEW] Calling tophat api for RTT with reference node = ".$this->reference_nodes['rtt']);
476 $this->RTT = $this->getPairwise($this->reference_nodes['rtt'], $dd, 'rtt','rtt');
479 //printf(" (%.2f ms)<br/>", (time() + microtime()-$st)*100);
480 print_r($this->HopCount);
485 function excludeItems($value, $exclude_list, $hh) {
491 if (in_array($value, $exclude_list))
492 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
494 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
496 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
500 function checkThreshold($value, $threshold, $hh) {
503 return array("n/a", array('name'=>$hh, 'display'=>'table-cell'));
506 if ((float) $value >= (float) $threshold[0] && (float) $value <= (float) $threshold[1])
507 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
509 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
511 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
515 function cells($table, $node) {
519 foreach ($this->all_headers as $h) {
523 if ($h['visible'] != "") {
526 if ($this->inTypeB($h['header']))
528 $value = $node[$h['tagname']];
529 $v = $this->checkThreshold($value, $h['threshold'], $h['header']);
530 $table->cell($v[0],$v[1]);
532 else if ($this->inTypeA($h['header']))
534 $value = $node[$h['tagname']];
535 $v = $this->excludeItems($value, $h['exclude_list'], $h['header']);
536 $table->cell($v[0],$v[1]);
539 if ($h['source'] == "comon")
541 //print("<br>Searching for ".$h['tagname']."at ".$node);
542 if ($this->ComonData != "")
543 $value = $this->convert_data($this->ComonData[$node['hostname']][$h['tagname']], $h['tagname']);
547 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
548 //$node_string.= "\"".$value."\",";
550 else if ($h['source'] == "tophat")
552 //print("<br>Searching for ".$h['tagname']."at ".$node);
553 if ($h['tagname'] == "hopcount")
555 //print "value = ".$this->HopCount[$node['hostname']];
557 if ($this->HopCount != "")
558 $value = $this->HopCount[$node['hostname']];
562 else if ($h['tagname'] == "rtt")
564 if ($this->RTT != "")
565 if ($this->RTT[$node['hostname']] != "")
566 $value = $this->RTT[$node['hostname']];
572 else if ($h['tagname'] == "agents")
574 if ($this->TopHatAgents != "")
575 if ($this->TopHatAgents[$node['hostname']] != "")
576 $value = $this->TopHatAgents[$node['hostname']]['all'];
582 else if ($h['tagname'] == "agents_tdmi")
584 if ($this->TopHatAgents != "")
585 if ($this->TopHatAgents[$node['hostname']] != "")
586 $value = $this->TopHatAgents[$node['hostname']]['tdmi'];
592 else if ($h['tagname'] == "agents_sonoma")
594 if ($this->TopHatAgents != "")
595 if ($this->TopHatAgents[$node['hostname']] != "")
596 $value = $this->TopHatAgents[$node['hostname']]['sonoma'];
604 if ($this->TopHatData != "")
605 $value = $this->convert_data($this->TopHatData[$node['hostname']][$h['tagname']], $h['type']);
610 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
611 //$node_string.= "\"".$value."\",";
615 //$value = $node[$h['tagname']];
616 $value = $this->convert_data($node[$h['tagname']], $h['type']);
617 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
618 //$node_string.= "\"".$value."\",";
622 if ($node[$h['tagname']])
624 $value = $this->convert_data($node[$h['tagname']], $h['type']);
625 $table->cell($value, array('name'=>$h['header'], 'display'=>'none'));
628 $table->cell("n/a", array('name'=>$h['header'], 'display'=>'none'));
632 //return $node_string;
644 function javascript_init() {
646 $refnodes = $this->getTopHatRefNodes();
647 //$tophat_agents = $this->getTopHatAgents();
649 foreach ($refnodes as $r)
651 if ($r['hostname'] == $this->reference_nodes['hopcount'])
652 $selected = "selected=selected";
656 $ref_nodes = $ref_nodes."<option value=".$r['hostname']." ".$selected.">".$r['hostname']."</option>";
659 print("<input type='hidden' id='selected_reference_node' value='".$this->reference_nodes['hopcount']."' />");
661 print("<script type='text/javascript'>");
662 print("highlightOption('AU');");
663 print("overrideTitles();");
664 print "var ref_nodes_select =\"Select reference node: <select id='refnodeHC' onChange='updateReferenceNode(this.id,this.value)'>".$ref_nodes."</select>\";";
669 function quickselect_html() {
671 $quickselection = "<select id='quicklist' onChange=changeSelectStatus(this.value)><option value='0'>Short column descriptions and quick add/remove</option>";
673 $optionclass = "out";
674 foreach ($this->all_headers as $h)
676 if ($h['header'] == "hostname" || $h['header'] == "ID")
680 $disabled = "disabled=true";
684 if ($this->headerIsVisible($h['label']))
687 $optionclass = "out";
689 if ($prev_label == $h['label'])
692 $prev_label = $h['label'];
694 $quickselection.="<option id='option'".$h['label']." class='".$optionclass."' value='".$h['label']."'><span class='bold'>".$h['label']."</span>: ".$h['title']."</option>";
698 $quickselection.="</select>";
700 return $quickselection;
705 function configuration_panel_html($showDescription) {
707 if ($showDescription)
712 print("<table class='center' width='".$table_width."px'>");
713 print("<tr><th class='top'>Add/remove columns</th>");
715 if ($showDescription)
716 print("<th class='top'>Column description and configuration</th>");
718 print("</tr><tr><td class='top' width='300px'>");
720 print('<div id="scrolldiv">');
723 $optionclass = "out";
724 foreach ($this->all_headers as $h)
726 if ($h['header'] == "hostname" || $h['header'] == "ID")
730 $disabled = "disabled=true";
734 if ($this->headerIsVisible($h['label']))
736 $selected = "checked=true";
738 //print("header ".$h['label']." checked!");
749 print("<input type='hidden' id='tagname".$h['header']."' value='".$h['tagname']."'></input>");
751 if ($prev_label == $h['label'])
754 $prev_label = $h['label'];
755 $period = $this->get_selected_period($h['label']);
757 //<input type='hidden' id='fdesc".$h['label']."' value='".$h['description']."'></input>
759 <input type='hidden' id='fetched".$h['label']."' value=',".$period.",".$fetch."'></input>
760 <input type='hidden' id='period".$h['label']."' value='".$period."'></input>
761 <input type='hidden' id='type".$h['label']."' value='".$h['type']."'></input>
762 <input type='hidden' id='source".$h['label']."' value='".$h['source']."'></input>
763 <div id='".$h['label']."' name='columnlist' class='".$optionclass."' onclick='highlightOption(this.id)'>
764 <table class='columnlist' id='table".$h['label']."'><tr>
765 <td class='header'><span class='header'>".$h['label']."</span></td>
766 <td align=left> <span class='short' id ='htitle".$h['label']."'>".$h['title']."</span> </td>
767 <td class='smallright'> <span class='short' id ='loading".$h['label']."'></span> </td>
768 <td class='smallright'><input id='check".$h['label']."' name='".$h['tagname']."' type='checkbox' ".$selected." ".$disabled." autocomplete='off' value='".$h['label']."' onclick='changeCheckStatus(this.id)'></input></td>
769 </tr></table></div></td></tr>");
772 print("</table> </div></td>");
774 if ($showDescription)
776 print("<td class='top' width='400px'>");
777 print("<div id='selectdescr'> </div></td>");
781 //print("<tr><td align=center>");
782 //print("<input type='button' value='Reset' onclick=resetCols('previousConf') />");
783 //print("<input type='button' value='Default' onclick=saveConfiguration('defaultConf') />");
784 //print("<input type='button' value='Reset table' onclick=\"resetConfiguration()\" />");
786 //print(" <input type='button' value='Save configuration' onclick=saveConfiguration('column_configuration') />");
787 //print(" <input type='button' id='fetchbutton' onclick='fetchData()' value='Fetch data' disabled=true /> </td>");
789 if ($showDescription)
792 print(" </tr> </table>");
797 function column_filter () {
801 Highlight <select onChange="filterByType(this.value)">
802 <option value="none">None</option>
803 <option value="capabilities">Capabilities</option>
804 <option value="statistics">Statistics</option>
805 <option value="network">Network</option>
806 <option value="pairwise">Pairwise</option>
807 <option value="other">Other</option>
814 function column_html ($colHeader, $colName, $colId, $fulldesc, $visible) {
817 $display = 'display:table-cell';
819 $display = 'color:red;display:none';
822 <th class='sample plekit_table' name='confheader".$colHeader."' id='testid' style='".$display."'>
823 <div id=\"".$colId."\" onclick=\"showDescription('".$colHeader."')\" onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div>
828 function column_fix_html ($colHeader, $colName, $colId) {
830 $display = 'display:table-cell';
832 $res="<th name='confheader".$colHeader."' class='fix plekit_table' style='$display'>";
833 $res.= "<div id='$colId' onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div></th>";
839 function graph_html($colHeader) {
841 return "<p><img src='/planetlab/slices/graph.png' width='20' align='BOTTOM'><input type='checkbox' id='graph".$colHeader."'></input> Show details on mouse over";
845 function threshold_html($colHeader) {
847 $updatecall = "updateColumnThreshold('".$colHeader."',window.document.getElementById('min".$colHeader."').value,window.document.getElementById('max".$colHeader."').value);";
849 $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>";
862 function inTypeA($header_name) {
863 $typeA = array('ST','SN','RES','OS','NRR','NTP','NSR','NSF','NDS','NTH','NEC','LRN','LCY','LPR','LCN','LAT','LON','IP','ASN','AST');
864 return in_array($header_name, $typeA);
868 function inTypeB($header_name) {
869 $typeB = array('BW','DS','MS','CC','CR','AS','DU','CN');
870 return in_array($header_name, $typeB);
874 function inTypeC($header_name) {
875 $typeC = array('Rw','Rm','Ry','Lw','Lm','Ly','Sw','Sm','Sy','CFw','CFm','CFy','BUw','BUm','BUy','MUw','MUm','MUy','SSHw','SSHm','SSHy');
876 return in_array($header_name, $typeC);
880 function inTypeD($header_name) {
881 $typeD = array('HC');
882 return in_array($header_name, $typeD);
886 function removeDuration($header)
888 if ($this->inTypeC($header))
889 return substr($header, 0, strlen($header)-1);