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 __construct ($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');
82 function($col1, $col2) {return strcmp($col1["label"], $col2["label"]);});
84 foreach ($tmp_headers as $t)
85 $this->all_headers[$t['header']] = $t;
87 //$this->all_headers = array_merge($this->all_headers, $tmp_headers);
89 //print($this->print_headers());
91 return $this->all_headers;
96 function get_headers() {
98 return $this->all_headers;
102 function get_selected_period($label) {
104 if ($this->all_headers[$label."w"]['visible'])
106 else if ($this->all_headers[$label."m"]['visible'])
108 else if ($this->all_headers[$label."y"]['visible'])
110 else if ($this->all_headers[$label]['visible'])
116 function node_tags() {
118 $fetched_tags = array('node_id','hostname');
120 foreach ($this->all_headers as $h)
122 if ($h['visible'] == true && $h['tagname'] != "" && !$h['fetched'] && $h['source']=="myplc")
123 $fetched_tags[] = $h['tagname'];
126 return $fetched_tags;
129 function print_headers() {
133 foreach ($this->all_headers as $l => $h)
135 $headers.="<br>[".$l."]=".$h['header'].":".$h['label'].":".$h['tagname'].":".$h['visible'];
140 function get_visible() {
142 $visibleHeaders = array();
144 foreach ($this->all_headers as $h)
146 if ($h['visible'] == true)
147 $visibleHeaders[] = $h['header'];
149 return $visibleHeaders;
152 function headerIsVisible($header_name) {
154 $headersToShow = $this->visible_headers;
156 if (in_array($header_name, $headersToShow))
159 if ($this->inTypeC($header_name."w"))
160 return (in_array($header_name."w", $headersToShow) || in_array($header_name."m", $headersToShow) || in_array($header_name."y", $headersToShow));
173 function parse_configuration($column_configuration) {
175 $this->column_configuration = $column_configuration;
176 $columns_conf = explode("|", $column_configuration);
179 foreach ($columns_conf as $c)
181 $conf = explode(":",$c);
183 if ($conf[0] == "default")
186 if (!$this->all_headers[$conf[0]])
189 $this->all_headers[$conf[0]]['visible']=true;
191 if ($this->all_headers[$conf[0]]['source'] == "comon")
192 $this->comon_live_data.=",".$this->all_headers[$conf[0]]['tagname'];
194 if ($this->all_headers[$conf[0]]['source'] == "tophat")
195 $this->tophat_live_data.=",".$this->all_headers[$conf[0]]['tagname'];
210 function convert_data($value, $data_type) {
212 //print "converting ".$value." as ".$data_type;
214 if ($value == "" || $value == null || $value == "n/a" || $value == "None")
217 if ($data_type == "string")
220 if ($data_type == "date")
221 return date("Y-m-d", $value);
223 if ($data_type == "uptime")
224 return (int)((int) $value / 86400);
226 if (is_numeric($value))
227 return ((int) ($value * 10))/10;
233 function getTopHatAgents() {
235 $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest@top-hat.info', 'AuthString' => 'guest');
236 $tophat_api = new TopHatAPI($tophat_auth);
238 //print ("Requesting tophat agents...");
241 $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'));
245 if ($values) foreach ($values as $t) {
248 $result[$t['hostname']] = "";
249 foreach ($t['colocated'] as $ll) {
251 if (strpos($result[$t['hostname']]['all'],$ll['platform_name']) === false) {
252 if ($result[$t['hostname']]['all'] != "")
253 $result[$t['hostname']]['all'] .= ",";
254 $result[$t['hostname']]['all'] .= $ll['platform_name'];
257 if ($ll['platform_name'] == 'SONoMA') {
258 if (strpos($result[$t['hostname']]['sonoma'],$ll['peer_name']) === false) {
259 if ($result[$t['hostname']]['sonoma'] != "")
260 $result[$t['hostname']]['sonoma'] .= ",";
261 $result[$t['hostname']]['sonoma'] .= $ll['peer_name'];
265 if ($ll['platform_name'] == 'TDMI') {
266 if (strpos($result[$t['hostname']]['tdmi'],$ll['peer_name']) === false) {
267 if ($result[$t['hostname']]['tdmi'] != "")
268 $result[$t['hostname']]['tdmi'] .= ",";
269 $result[$t['hostname']]['tdmi'] .= $ll['peer_name'];
275 $this->TopHatAgents = $result;
277 //print_r($this->TopHatAgents);
282 function getTopHatData($data, $planetlab_nodes) {
284 $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest@top-hat.info', 'AuthString' => 'guest');
285 $tophat_api = new TopHatAPI($tophat_auth);
287 $requested_data = explode(",", $data);
289 $r = array ('hostname');
291 foreach ($requested_data as $rd)
294 //print ("Requesting data from TopHat ...");
297 $values = $tophat_api->Get('ips', 'latest', array('hostname' => $planetlab_nodes), $r );
301 if ($values) foreach ($values as $t)
302 foreach ($requested_data as $rd)
303 if ($rd) $result[$t['hostname']][$rd] = $t[$rd];
311 function comon_query_nodes($requested_data) {
313 $comon_url = "http://comon.cs.princeton.edu";
314 $comon_api_url = "status/tabulator.cgi?table=table_nodeviewshort&format=formatcsv&dumpcols='name";
316 if (MYSLICE_COMON_URL != "")
317 $comon_url = MYSLICE_COMON_URL;
319 $url = $comon_url."/".$comon_api_url.$requested_data."'";
321 //print ("Retrieving comon data for url ".$url);
323 $sPattern = '\', \'';
326 $str=@file_get_contents($url);
331 $result=preg_replace( $sPattern, $sReplace, $str );
334 $result=preg_replace( $sPattern, $sReplace, $result );
336 $comon_data = explode(";", $result);
338 $comon_values = array();
340 foreach ($comon_data as $cd) {
341 $cc = explode("|", $cd);
342 if ($cc[0] == "name") {
345 $comon_values[$cc[0]] = array();
347 foreach ($cl as $cltag) {
348 if ($cltag != "name")
349 $comon_values[$cc[0]][$cltag] = $cc[$cindex++];
353 return $comon_values;
357 //Depending on the columns selected more data might need to be fetched from
360 function fetch_live_data($all_nodes) {
362 //print("<p>fetching live data<p>");
365 if ($this->comon_live_data != "") {
367 //print ("live data to be fetched =".$this->comon_live_data);
368 $this->ComonData= $this->comon_query_nodes($this->comon_live_data);
369 //print_r($this->ComonData);
372 //TopHat per_node data
373 if ($this->tophat_live_data != "")
377 if ($all_nodes) foreach ($all_nodes as $n)
378 $dd[] = $n['hostname'];
380 //print("Calling tophat api for ".$this->tophat_live_data);
381 $st = time() + microtime();
382 $this->TopHatData = $this->getTopHatData($this->tophat_live_data, $dd);
383 //printf(" (%.2f ms)<br/>", (time() + microtime()-$st)*100);
384 //print_r($this->TopHatData);
390 function cells($table, $node) {
394 foreach ($this->all_headers as $h) {
398 if ($h['visible'] != "") {
400 if ($h['source'] == "comon")
402 //print("<br>Searching for ".$h['tagname']."at ".$node);
403 if ($this->ComonData != "")
404 $value = $this->convert_data($this->ComonData[$node['hostname']][$h['tagname']], $h['tagname']);
408 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
409 //$node_string.= "\"".$value."\",";
411 else if ($h['source'] == "tophat")
413 if ($this->TopHatData != "")
414 $value = $this->convert_data($this->TopHatData[$node['hostname']][$h['tagname']], $h['type']);
418 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
419 //$node_string.= "\"".$value."\",";
423 //$value = $node[$h['tagname']];
424 $value = $this->convert_data($node[$h['tagname']], $h['type']);
425 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
426 //$node_string.= "\"".$value."\",";
430 if ($node[$h['tagname']])
432 $value = $this->convert_data($node[$h['tagname']], $h['type']);
433 $table->cell($value, array('name'=>$h['header'], 'display'=>'none'));
436 $table->cell("n/a", array('name'=>$h['header'], 'display'=>'none'));
440 //return $node_string;
452 function javascript_init() {
454 print("<script type='text/javascript'>");
455 print("highlightOption('AU');");
456 print("overrideTitles();");
461 function quickselect_html() {
463 $quickselection = "<select id='quicklist' onChange=changeSelectStatus(this.value)><option value='0'>Short column descriptions and quick add/remove</option>";
465 $optionclass = "out";
466 foreach ($this->all_headers as $h)
468 if ($h['header'] == "hostname" || $h['header'] == "ID")
472 $disabled = "disabled=true";
476 if ($this->headerIsVisible($h['label']))
479 $optionclass = "out";
481 if ($prev_label == $h['label'])
484 $prev_label = $h['label'];
486 $quickselection.="<option id='option'".$h['label']." class='".$optionclass."' value='".$h['label']."'><span class='bold'>".$h['label']."</span>: ".$h['title']."</option>";
490 $quickselection.="</select>";
492 return $quickselection;
497 function configuration_panel_html($showDescription) {
499 if ($showDescription)
504 print("<table class='center' width='".$table_width."px'>");
505 print("<tr><th class='top'>Add/remove columns</th>");
507 if ($showDescription)
508 print("<th class='top'>Column description and configuration</th>");
510 print("</tr><tr><td class='top' width='300px'>");
512 print('<div id="scrolldiv">');
515 $optionclass = "out";
516 foreach ($this->all_headers as $h)
518 if ($h['header'] == "hostname" || $h['header'] == "ID")
522 $disabled = "disabled=true";
526 if ($this->headerIsVisible($h['label']))
528 $selected = "checked=true";
530 //print("header ".$h['label']." checked!");
541 print("<input type='hidden' id='tagname".$h['header']."' value='".$h['tagname']."'></input>");
543 if ($prev_label == $h['label'])
546 $prev_label = $h['label'];
547 $period = $this->get_selected_period($h['label']);
550 <input type='hidden' id='fetched".$h['label']."' value=',".$period.",".$fetch."'></input>
551 <input type='hidden' id='period".$h['label']."' value='".$period."'></input>
552 <input type='hidden' id='type".$h['label']."' value='".$h['type']."'></input>
553 <input type='hidden' id='source".$h['label']."' value='".$h['source']."'></input>
554 <div id='".$h['label']."' name='columnlist' class='".$optionclass."' onclick='highlightOption(this.id)'>
555 <table class='columnlist' id='table".$h['label']."'><tr>
556 <td class='header'><span class='header'>".$h['label']."</span></td>
557 <td align=left> <span class='short' id ='htitle".$h['label']."'>".$h['title']."</span> </td>
558 <td class='smallright'> <span class='short' id ='loading".$h['label']."'></span> </td>
559 <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>
560 </tr></table></div></td></tr>");
563 print("</table> </div></td>");
565 if ($showDescription)
567 print("<td class='top' width='400px'>");
568 print("<div id='selectdescr'> </div></td>");
573 if ($showDescription)
576 print(" </tr> </table>");
581 function column_filter () {
585 Highlight <select onChange="filterByType(this.value)">
586 <option value="none">None</option>
587 <option value="capabilities">Capabilities</option>
588 <option value="statistics">Statistics</option>
589 <option value="network">Network</option>
590 <option value="pairwise">Pairwise</option>
591 <option value="other">Other</option>
598 function column_html ($colHeader, $colName, $colId, $fulldesc, $visible) {
601 $display = 'display:table-cell';
603 $display = 'color:red;display:none';
606 <th class='sample plekit_table' name='confheader".$colHeader."' id='testid' style='".$display."'>
607 <div id=\"".$colId."\" onclick=\"showDescription('".$colHeader."')\" onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div>
612 function column_fix_html ($colHeader, $colName, $colId) {
614 $display = 'display:table-cell';
616 $res="<th name='confheader".$colHeader."' class='fix plekit_table' style='$display'>";
617 $res.= "<div id='$colId' onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div></th>";
631 function inTypeA($header_name) {
632 $typeA = array('ST','SN','RES','OS','NRR','NTP','NSR','NSF','NDS','NTH','NEC','LRN','LCY','LPR','LCN','LAT','LON','IP','ASN','AST');
633 return in_array($header_name, $typeA);
637 function inTypeB($header_name) {
638 $typeB = array('BW','DS','MS','CC','CR','AS','DU','CN');
639 return in_array($header_name, $typeB);
643 function inTypeC($header_name) {
644 $typeC = array('Rw','Rm','Ry','Lw','Lm','Ly','Sw','Sm','Sy','CFw','CFm','CFy','BUw','BUm','BUy','MUw','MUm','MUy','SSHw','SSHm','SSHy');
645 return in_array($header_name, $typeC);
649 function inTypeD($header_name) {
650 $typeD = array('HC');
651 return in_array($header_name, $typeD);
655 function removeDuration($header)
657 if ($this->inTypeC($header))
658 return substr($header, 0, strlen($header)-1);