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 $base_url = "http://comon.cs.princeton.edu/status/tabulator.cgi?table=table_nodeviewshort&format=formatcsv&dumpcols='name";
379 $url = $base_url.$requested_data."'";
381 //print ("Retrieving comon data for url ".$url);
383 $sPattern = '\', \'';
386 $str=file_get_contents($url);
391 $result=preg_replace( $sPattern, $sReplace, $str );
394 $result=preg_replace( $sPattern, $sReplace, $result );
396 $comon_data = explode(";", $result);
398 $comon_values = array();
400 foreach ($comon_data as $cd) {
401 $cc = explode("|", $cd);
402 if ($cc[0] == "name") {
405 $comon_values[$cc[0]] = array();
407 foreach ($cl as $cltag) {
408 if ($cltag != "name")
409 $comon_values[$cc[0]][$cltag] = $cc[$cindex++];
413 return $comon_values;
417 //Depending on the columns selected more data might need to be fetched from
420 function fetch_live_data($all_nodes) {
422 //print("<p>fetching live data<p>");
425 if ($this->comon_live_data != "") {
427 //print ("live data to be fetched =".$this->comon_live_data);
428 $this->ComonData= $this->comon_query_nodes($this->comon_live_data);
429 //print_r($this->ComonData);
432 //TopHat per_node data
433 if ($this->tophat_live_data != "")
437 if ($all_nodes) foreach ($all_nodes as $n)
438 $dd[] = $n['hostname'];
440 //print("Calling tophat api for ".$this->tophat_live_data);
441 $st = time() + microtime();
442 $this->TopHatData = $this->getTopHatData($this->tophat_live_data, $dd);
443 //printf(" (%.2f ms)<br/>", (time() + microtime()-$st)*100);
444 //print_r($this->TopHatData);
447 //TopHat pairwise data
449 $this->HopCount = "";
452 if ($this->reference_nodes != "")
454 //print_r($this->reference_nodes);
458 if ($all_nodes) foreach ($all_nodes as $n)
459 $dd[] = $n['hostname'];
461 $st = time() + microtime();
462 if ($this->headerIsVisible("HC"))
464 print("[NEW] Calling tophat api for HopCount with reference node = ".$this->reference_nodes['hopcount']);
465 $this->HopCount = $this->getPairwise($this->reference_nodes['hopcount'], $dd, 'traceroute', 'hop_count');
469 if ($this->headerIsVisible("RTT"))
471 print("[NEW] Calling tophat api for RTT with reference node = ".$this->reference_nodes['rtt']);
472 $this->RTT = $this->getPairwise($this->reference_nodes['rtt'], $dd, 'rtt','rtt');
475 //printf(" (%.2f ms)<br/>", (time() + microtime()-$st)*100);
476 print_r($this->HopCount);
481 function excludeItems($value, $exclude_list, $hh) {
487 if (in_array($value, $exclude_list))
488 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
490 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
492 return array($value, array('name'=>$hh, 'display'=>'table-cell'));
496 function checkThreshold($value, $threshold, $hh) {
499 return array("n/a", array('name'=>$hh, 'display'=>'table-cell'));
502 if ((float) $value >= (float) $threshold[0] && (float) $value <= (float) $threshold[1])
503 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
505 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
507 return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell'));
511 function cells($table, $node) {
515 foreach ($this->all_headers as $h) {
519 if ($h['visible'] != "") {
522 if ($this->inTypeB($h['header']))
524 $value = $node[$h['tagname']];
525 $v = $this->checkThreshold($value, $h['threshold'], $h['header']);
526 $table->cell($v[0],$v[1]);
528 else if ($this->inTypeA($h['header']))
530 $value = $node[$h['tagname']];
531 $v = $this->excludeItems($value, $h['exclude_list'], $h['header']);
532 $table->cell($v[0],$v[1]);
535 if ($h['source'] == "comon")
537 //print("<br>Searching for ".$h['tagname']."at ".$node);
538 if ($this->ComonData != "")
539 $value = $this->convert_data($this->ComonData[$node['hostname']][$h['tagname']], $h['tagname']);
543 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
544 //$node_string.= "\"".$value."\",";
546 else if ($h['source'] == "tophat")
548 //print("<br>Searching for ".$h['tagname']."at ".$node);
549 if ($h['tagname'] == "hopcount")
551 //print "value = ".$this->HopCount[$node['hostname']];
553 if ($this->HopCount != "")
554 $value = $this->HopCount[$node['hostname']];
558 else if ($h['tagname'] == "rtt")
560 if ($this->RTT != "")
561 if ($this->RTT[$node['hostname']] != "")
562 $value = $this->RTT[$node['hostname']];
568 else if ($h['tagname'] == "agents")
570 if ($this->TopHatAgents != "")
571 if ($this->TopHatAgents[$node['hostname']] != "")
572 $value = $this->TopHatAgents[$node['hostname']]['all'];
578 else if ($h['tagname'] == "agents_tdmi")
580 if ($this->TopHatAgents != "")
581 if ($this->TopHatAgents[$node['hostname']] != "")
582 $value = $this->TopHatAgents[$node['hostname']]['tdmi'];
588 else if ($h['tagname'] == "agents_sonoma")
590 if ($this->TopHatAgents != "")
591 if ($this->TopHatAgents[$node['hostname']] != "")
592 $value = $this->TopHatAgents[$node['hostname']]['sonoma'];
600 if ($this->TopHatData != "")
601 $value = $this->convert_data($this->TopHatData[$node['hostname']][$h['tagname']], $h['type']);
606 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
607 //$node_string.= "\"".$value."\",";
611 //$value = $node[$h['tagname']];
612 $value = $this->convert_data($node[$h['tagname']], $h['type']);
613 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
614 //$node_string.= "\"".$value."\",";
618 if ($node[$h['tagname']])
620 $value = $this->convert_data($node[$h['tagname']], $h['type']);
621 $table->cell($value, array('name'=>$h['header'], 'display'=>'none'));
624 $table->cell("n/a", array('name'=>$h['header'], 'display'=>'none'));
628 //return $node_string;
640 function javascript_init() {
642 $refnodes = $this->getTopHatRefNodes();
643 //$tophat_agents = $this->getTopHatAgents();
645 foreach ($refnodes as $r)
647 if ($r['hostname'] == $this->reference_nodes['hopcount'])
648 $selected = "selected=selected";
652 $ref_nodes = $ref_nodes."<option value=".$r['hostname']." ".$selected.">".$r['hostname']."</option>";
655 print("<input type='hidden' id='selected_reference_node' value='".$this->reference_nodes['hopcount']."' />");
657 print("<script type='text/javascript'>");
658 print("highlightOption('AU');");
659 print("overrideTitles();");
660 print "var ref_nodes_select =\"Select reference node: <select id='refnodeHC' onChange='updateReferenceNode(this.id,this.value)'>".$ref_nodes."</select>\";";
665 function quickselect_html() {
667 $quickselection = "<select id='quicklist' onChange=changeSelectStatus(this.value)><option value='0'>Short column descriptions and quick add/remove</option>";
669 $optionclass = "out";
670 foreach ($this->all_headers as $h)
672 if ($h['header'] == "hostname" || $h['header'] == "ID")
676 $disabled = "disabled=true";
680 if ($this->headerIsVisible($h['label']))
683 $optionclass = "out";
685 if ($prev_label == $h['label'])
688 $prev_label = $h['label'];
690 $quickselection.="<option id='option'".$h['label']." class='".$optionclass."' value='".$h['label']."'><span class='bold'>".$h['label']."</span>: ".$h['title']."</option>";
694 $quickselection.="</select>";
696 return $quickselection;
701 function configuration_panel_html($showDescription) {
703 if ($showDescription)
708 print("<table class='center' width='".$table_width."px'>");
709 print("<tr><th class='top'>Add/remove columns</th>");
711 if ($showDescription)
712 print("<th class='top'>Column description and configuration</th>");
714 print("</tr><tr><td class='top' width='300px'>");
716 print('<div id="scrolldiv">');
719 $optionclass = "out";
720 foreach ($this->all_headers as $h)
722 if ($h['header'] == "hostname" || $h['header'] == "ID")
726 $disabled = "disabled=true";
730 if ($this->headerIsVisible($h['label']))
732 $selected = "checked=true";
734 //print("header ".$h['label']." checked!");
745 print("<input type='hidden' id='tagname".$h['header']."' value='".$h['tagname']."'></input>");
747 if ($prev_label == $h['label'])
750 $prev_label = $h['label'];
751 $period = $this->get_selected_period($h['label']);
753 //<input type='hidden' id='fdesc".$h['label']."' value='".$h['description']."'></input>
755 <input type='hidden' id='fetched".$h['label']."' value=',".$period.",".$fetch."'></input>
756 <input type='hidden' id='period".$h['label']."' value='".$period."'></input>
757 <input type='hidden' id='type".$h['label']."' value='".$h['type']."'></input>
758 <input type='hidden' id='source".$h['label']."' value='".$h['source']."'></input>
759 <div id='".$h['label']."' name='columnlist' class='".$optionclass."' onclick='highlightOption(this.id)'>
760 <table class='columnlist' id='table".$h['label']."'><tr>
761 <td class='header'><span class='header'>".$h['label']."</span></td>
762 <td align=left> <span class='short' id ='htitle".$h['label']."'>".$h['title']."</span> </td>
763 <td class='smallright'> <span class='short' id ='loading".$h['label']."'></span> </td>
764 <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>
765 </tr></table></div></td></tr>");
768 print("</table> </div></td>");
770 if ($showDescription)
772 print("<td class='top' width='400px'>");
773 print("<div id='selectdescr'> </div></td>");
777 //print("<tr><td align=center>");
778 //print("<input type='button' value='Reset' onclick=resetCols('previousConf') />");
779 //print("<input type='button' value='Default' onclick=saveConfiguration('defaultConf') />");
780 //print("<input type='button' value='Reset table' onclick=\"resetConfiguration()\" />");
782 //print(" <input type='button' value='Save configuration' onclick=saveConfiguration('column_configuration') />");
783 //print(" <input type='button' id='fetchbutton' onclick='fetchData()' value='Fetch data' disabled=true /> </td>");
785 if ($showDescription)
788 print(" </tr> </table>");
793 function column_filter () {
797 Highlight <select onChange="filterByType(this.value)">
798 <option value="none">None</option>
799 <option value="capabilities">Capabilities</option>
800 <option value="statistics">Statistics</option>
801 <option value="network">Network</option>
802 <option value="pairwise">Pairwise</option>
803 <option value="other">Other</option>
810 function column_html ($colHeader, $colName, $colId, $fulldesc, $visible) {
813 $display = 'display:table-cell';
815 $display = 'color:red;display:none';
818 <th class='sample plekit_table' name='confheader".$colHeader."' id='testid' style='".$display."'>
819 <div id=\"".$colId."\" onclick=\"showDescription('".$colHeader."')\" onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div>
824 function column_fix_html ($colHeader, $colName, $colId) {
826 $display = 'display:table-cell';
828 $res="<th name='confheader".$colHeader."' class='fix plekit_table' style='$display'>";
829 $res.= "<div id='$colId' onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div></th>";
835 function graph_html($colHeader) {
837 return "<p><img src='/planetlab/slices/graph.png' width='20' align='BOTTOM'><input type='checkbox' id='graph".$colHeader."'></input> Show details on mouse over";
841 function threshold_html($colHeader) {
843 $updatecall = "updateColumnThreshold('".$colHeader."',window.document.getElementById('min".$colHeader."').value,window.document.getElementById('max".$colHeader."').value);";
845 $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>";
858 function inTypeA($header_name) {
859 $typeA = array('ST','SN','RES','OS','NRR','NTP','NSR','NSF','NDS','NTH','NEC','LRN','LCY','LPR','LCN','LAT','LON','IP','ASN','AST');
860 return in_array($header_name, $typeA);
864 function inTypeB($header_name) {
865 $typeB = array('BW','DS','MS','CC','CR','AS','DU','CN');
866 return in_array($header_name, $typeB);
870 function inTypeC($header_name) {
871 $typeC = array('Rw','Rm','Ry','Lw','Lm','Ly','Sw','Sm','Sy','CFw','CFm','CFy','BUw','BUm','BUy','MUw','MUm','MUy','SSHw','SSHm','SSHy');
872 return in_array($header_name, $typeC);
876 function inTypeD($header_name) {
877 $typeD = array('HC');
878 return in_array($header_name, $typeD);
882 function removeDuration($header)
884 if ($this->inTypeC($header))
885 return substr($header, 0, strlen($header)-1);