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 (get_array2($this->all_headers, $label."w", 'visible'))
106 else if (get_array2($this->all_headers, $label."m", 'visible'))
108 else if (get_array2($this->all_headers, $label."y", 'visible'))
113 function node_tags() {
115 $fetched_tags = array('node_id','hostname');
117 foreach ($this->all_headers as $h)
119 if ($h['visible'] == true
120 && $h['tagname'] != ""
121 && !get_array($h, 'fetched')
122 && $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) {
393 foreach ($this->all_headers as $h) {
395 if (! get_array($h, 'fixed')) {
397 if ($h['visible'] != "") {
399 if ($h['source'] == "comon") {
400 //print("<br>Searching for ".$h['tagname']."at ".$node);
401 if ($this->ComonData != "")
402 $value = $this->convert_data($this->ComonData[$node['hostname']][$h['tagname']], $h['tagname']);
406 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
407 //$node_string.= "\"".$value."\",";
408 } else if ($h['source'] == "tophat") {
409 if ($this->TopHatData != "")
410 $value = $this->convert_data($this->TopHatData[$node['hostname']][$h['tagname']], $h['type']);
414 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
415 //$node_string.= "\"".$value."\",";
417 //$value = $node[$h['tagname']];
418 $value = $this->convert_data($node[$h['tagname']], $h['type']);
419 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
420 //$node_string.= "\"".$value."\",";
422 } else if (get_array($node, $h['tagname'])) {
423 $value = $this->convert_data($node[$h['tagname']], $h['type']);
424 $table->cell($value, array('name'=>$h['header'], 'display'=>'none'));
426 $table->cell("n/a", array('name'=>$h['header'], 'display'=>'none'));
441 function javascript_init() {
443 print("<script type='text/javascript'>");
444 print("highlightOption('AU');");
445 print("overrideTitles();");
450 function quickselect_html() {
452 $quickselection = "<select id='quicklist' onChange=changeSelectStatus(this.value)><option value='0'>Short column descriptions and quick add/remove</option>";
454 $optionclass = "out";
455 foreach ($this->all_headers as $h)
457 if ($h['header'] == "hostname" || $h['header'] == "ID")
461 $disabled = "disabled=true";
465 if ($this->headerIsVisible($h['label']))
468 $optionclass = "out";
470 if ($prev_label == $h['label'])
473 $prev_label = $h['label'];
475 $quickselection.="<option id='option'".$h['label']." class='".$optionclass."' value='".$h['label']."'><span class='bold'>".$h['label']."</span>: ".$h['title']."</option>";
479 $quickselection.="</select>";
481 return $quickselection;
486 function configuration_panel_html($showDescription) {
488 if ($showDescription)
493 print("<table class='center' width='".$table_width."px'>");
494 print("<tr><th class='top'>Add/remove columns</th>");
496 if ($showDescription)
497 print("<th class='top'>Column description and configuration</th>");
499 print("</tr><tr><td class='top' width='300px'>");
501 print('<div id="scrolldiv">');
504 $optionclass = "out";
505 foreach ($this->all_headers as $h) {
506 if ($h['header'] == "hostname" || $h['header'] == "ID")
509 if (get_array($h, 'fixed'))
510 $disabled = "disabled=true";
514 if ($this->headerIsVisible($h['label']))
516 $selected = "checked=true";
518 //print("header ".$h['label']." checked!");
529 print("<input type='hidden' id='tagname".$h['header']."' value='".$h['tagname']."'></input>");
531 if ($prev_label == $h['label'])
534 $prev_label = $h['label'];
535 $period = $this->get_selected_period($h['label']);
538 <input type='hidden' id='fetched".$h['label']."' value=',".$period.",".$fetch."'></input>
539 <input type='hidden' id='period".$h['label']."' value='".$period."'></input>
540 <input type='hidden' id='type".$h['label']."' value='".$h['type']."'></input>
541 <input type='hidden' id='source".$h['label']."' value='".$h['source']."'></input>
542 <div id='".$h['label']."' name='columnlist' class='".$optionclass."' onclick='highlightOption(this.id)'>
543 <table class='columnlist' id='table".$h['label']."'><tr>
544 <td class='header'><span class='header'>".$h['label']."</span></td>
545 <td align=left> <span class='short' id ='htitle".$h['label']."'>".$h['title']."</span> </td>
546 <td class='smallright'> <span class='short' id ='loading".$h['label']."'></span> </td>
547 <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>
548 </tr></table></div></td></tr>");
551 print("</table> </div></td>");
553 if ($showDescription)
555 print("<td class='top' width='400px'>");
556 print("<div id='selectdescr'> </div></td>");
561 if ($showDescription)
564 print(" </tr> </table>");
569 function column_filter () {
573 Highlight <select onChange="filterByType(this.value)">
574 <option value="none">None</option>
575 <option value="capabilities">Capabilities</option>
576 <option value="statistics">Statistics</option>
577 <option value="network">Network</option>
578 <option value="pairwise">Pairwise</option>
579 <option value="other">Other</option>
586 function column_html ($colHeader, $colName, $colId, $fulldesc, $visible) {
589 $display = 'display:table-cell';
591 $display = 'color:red;display:none';
594 <th class='sample plekit_table' name='confheader".$colHeader."' id='testid' style='".$display."'>
595 <div id=\"".$colId."\" onclick=\"showDescription('".$colHeader."')\" onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div>
600 function column_fix_html ($colHeader, $colName, $colId) {
602 $display = 'display:table-cell';
604 $res="<th name='confheader".$colHeader."' class='fix plekit_table' style='$display'>";
605 $res.= "<div id='$colId' onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div></th>";
619 function inTypeA($header_name) {
620 $typeA = array('ST','SN','RES','OS','NRR','NTP','NSR','NSF','NDS','NTH','NEC','LRN','LCY','LPR','LCN','LAT','LON','IP','ASN','AST');
621 return in_array($header_name, $typeA);
625 function inTypeB($header_name) {
626 $typeB = array('BW','DS','MS','CC','CR','AS','DU','CN');
627 return in_array($header_name, $typeB);
631 function inTypeC($header_name) {
632 $typeC = array('Rw','Rm','Ry','Lw','Lm','Ly','Sw','Sm','Sy','CFw','CFm','CFy','BUw','BUm','BUy','MUw','MUm','MUy','SSHw','SSHm','SSHy');
633 return in_array($header_name, $typeC);
637 function inTypeD($header_name) {
638 $typeD = array('HC');
639 return in_array($header_name, $typeD);
643 function removeDuration($header)
645 if ($this->inTypeC($header))
646 return substr($header, 0, strlen($header)-1);