'); class PlekitColumns { var $column_configuration = ""; var $reference_node = ""; var $first_time = false; var $all_headers = array(); var $this_table_headers = array(); var $visible_headers = array(); var $fix_columns = array(); var $tag_columns = array(); var $extra_columns = array(); var $table_ids; var $HopCount = array(); function PlekitColumns ($column_configuration, $fix_columns, $tag_columns, $extra_columns=NULL, $this_table_headers=NULL) { $this->fix_columns = $fix_columns; $this->tag_columns = $tag_columns; $this->extra_columns = $extra_columns; //print("

FIX

"); //print_r($this->fix_columns); //print("

TAG

"); //print_r($this->tag_columns); //print("

EXTRA

"); //print_r($this->extra_columns); $this->prepare_headers(); $this->parse_configuration($column_configuration); $this->visible_headers = $this->get_visible(); //print("

VISIBLE

"); //print_r($this->visible_headers); } /* INFO */ function prepare_headers() { foreach ($this->fix_columns as $column) { $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); } $tmp_headers = array(); foreach ($this->tag_columns as $column) { if ($column['headerId'] != "") $headerId = $column['headerId']; else $headerId = $column['header']; //$this->all_headers[$headerId]=array('header'=>$headerId,'type'=>$column['type'],'tagname'=>$column['tagname'],'title'=>$column['title'], 'description'=>$column['title'], 'label'=>$column['header'],'visible'=>false); $tmp_headers[$headerId]=array('header'=>$headerId,'type'=>$column['type'],'tagname'=>$column['tagname'],'title'=>$column['title'], 'description'=>$column['title'], 'label'=>$column['header'],'visible'=>false); } if ($this->extra_columns) foreach ($this->extra_columns as $column) { //$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); $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); usort ($tmp_headers, create_function('$col1,$col2','return strcmp($col1["label"],$col2["label"]);')); } foreach ($tmp_headers as $t) $this->all_headers[$t['header']] = $t; //$this->all_headers = array_merge($this->all_headers, $tmp_headers); //print($this->print_headers()); return $this->all_headers; } function get_headers() { return $this->all_headers; } function get_selected_period($label) { if ($this->all_headers[$label."w"]['visible']) return "w"; else if ($this->all_headers[$label."m"]['visible']) return "m"; else if ($this->all_headers[$label."y"]['visible']) return "y"; else if ($this->all_headers[$label]['visible']) return ""; return ""; } function node_tags() { $fetched_tags = array('node_id'); foreach ($this->all_headers as $h) { if ($h['visible'] == true && $h['tagname'] != "" && !$h['fetched']) $fetched_tags[] = $h['tagname']; } return $fetched_tags; } function print_headers() { $headers = ""; foreach ($this->all_headers as $l => $h) { $headers.="
[".$l."]=".$h['header'].":".$h['label'].":".$h['tagname'].":".$h['visible']; } return $headers; } function get_visible() { $visibleHeaders = array(); foreach ($this->all_headers as $h) { if ($h['visible'] == true) $visibleHeaders[] = $h['header']; } return $visibleHeaders; } function headerIsVisible($header_name) { $headersToShow = $this->visible_headers; if (in_array($header_name, $headersToShow)) return true; if ($this->inTypeC($header_name."w")) return (in_array($header_name."w", $headersToShow) || in_array($header_name."m", $headersToShow) || in_array($header_name."y", $headersToShow)); } /* CONFIGURATION */ function parse_configuration($column_configuration) { $this->column_configuration = $column_configuration; //$this->default_configuration = $default_configuration; //print($this->print_headers()); $columns_conf = explode("|", $column_configuration); foreach ($columns_conf as $c) { $conf = explode(":",$c); if ($conf[0] == "default") continue; $this->all_headers[$conf[0]]['visible']=true; //print("

-".$conf[0]."-should be visible now - ".$this->all_headers[$conf[0]]['visible']); //print_r($this->all_headers[$conf[0]]); /* if ($conf[1] == "f") continue; else if ($this->inTypeC($conf[0])) { $this->all_headers[$conf[0]]['duration']= substr($conf[0], strlen($conf[0])-1, strlen($conf[0])); $threshold = explode(",",$conf[1]); $this->all_headers[$conf[0]]['threshold']=$threshold; } else if ($this->inTypeD($conf[0])) { $this->reference_node = $conf[1]; $this->reference_node = "planetlab-europe-07.ipv6.lip6.fr"; $this->all_headers[$conf[0]]['refnode']=$this->reference_node; $threshold = explode(",",$conf[1]); $this->all_headers[$conf[0]]['threshold']=$threshold; } else if ($this->inTypeA($conf[0])) { $exclude_list = explode(",",$conf[1]); $this->all_headers[$conf[0]]['exclude_list']=$exclude_list; } else { $threshold = explode(",",$conf[1]); $this->all_headers[$conf[0]]['threshold']=$threshold; } */ } } /* CELLS */ function getHopCount($ref_node, $planetlab_nodes) { $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest', 'AuthString' => 'guest'); $tophat_api = new TopHatAPI($tophat_auth); $traceroute = $tophat_api->Get('traceroute', 'latest', array('src_hostname' => $ref_node, 'dst_hostname' => $planetlab_nodes), array('dst_hostname', 'hop_count') ); $hopcount = array(); if ($traceroute) foreach ($traceroute as $t) $hopcount[$t['dst_hostname']]=$t['hop_count']; return $hopcount; } //Depending on the columns selected more data might need to be fetched from //external sources function fetch_data($nodes) { //TopHat pairwise data if ($this->reference_node != "") { $dd = array(); if ($nodes) foreach ($nodes as $n) $dd[] = $n['hostname']; if ($potential_nodes) foreach ($potential_nodes as $n) $dd[] = $n['hostname']; print("Calling tophat api for reference node = ".$this->reference_node); $st = time() + microtime(); $HopCount = $this->getHopCount($this->reference_node, $dd); printf(" (%.2f ms)
", (time() + microtime()-$st)*100); //print_r($HopCount); } } function excludeItems($value, $exclude_list, $hh) { if ($value == "") $value = "n/a"; if ($exclude_list) if (in_array($value, $exclude_list)) return array($value, array('name'=>$hh, 'display'=>'table-cell')); else return array($value, array('name'=>$hh, 'display'=>'table-cell')); return array($value, array('name'=>$hh, 'display'=>'table-cell')); } function checkThreshold($value, $threshold, $hh) { if ($value == "") return array("n/a", array('name'=>$hh, 'display'=>'table-cell')); if ($threshold) if ((float) $value >= (float) $threshold[0] && (float) $value <= (float) $threshold[1]) return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell')); else return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell')); return array(round($value,1), array('name'=>$hh, 'display'=>'table-cell')); } function cells($table, $node) { $this->fetch_data($node); foreach ($this->all_headers as $h) { if (!$h['fixed']) { if ($h['visible'] != "") { if ($this->inTypeC($h['header'])) { $tagname = $h['tagname']; $value = $node[$tagname]; $v = $this->checkThreshold($value, $h['threshold'], $h['header']); $table->cell($v[0],$v[1]); } else if ($this->inTypeB($h['header'])) { $value = $node[$h['tagname']]; $v = $this->checkThreshold($value, $h['threshold'], $h['header']); $table->cell($v[0],$v[1]); } else if ($this->inTypeD($h['header'])) { $value = $this->HopCount[$node['hostname']]; $v = $this->excludeItems($value, $h['threshold'], $h['header']); $table->cell($v[0],$v[1]); } else if ($this->inTypeA($h['header'])) { $value = $node[$h['tagname']]; $v = $this->excludeItems($value, $h['exclude_list'], $h['header']); $table->cell($v[0],$v[1]); } else { $value = $node[$h['tagname']]; $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell')); } } else if ($node[$h['tagname']]) $table->cell($node[$h['tagname']], array('name'=>$h['header'], 'display'=>'none')); else $table->cell("??", array('name'=>$h['header'], 'display'=>'none')); } } } /* HTML */ function javascript_init() { print(""); print(""); } function quickselect_html() { //return '

This link uses the onclick event handler.
Open popup

'; $quickselection = ""; $quickselection.=" "; return $quickselection; } function quickselect_popup_html() { print('
'); print ("
"); print(" "); } function configuration_panel_html($showDescription) { if ($showDescription) $table_width = 700; else $table_width = 350; print(""); print(""); if ($showDescription) print(""); print(""); if ($showDescription) { print(""); } print(""); //print(""); //print(" "); //print(" "); if ($showDescription) print(""); print("
Add/remove columnsColumn description and configuration
"); print('
'); print (""); $prev_label=""; $optionclass = "out"; foreach ($this->all_headers as $h) { if ($h['header'] == "hostname" || $h['header'] == "ID") continue; if ($h['fixed']) $disabled = "disabled=true"; else $disabled = ""; if ($this->headerIsVisible($h['label'])) { $selected = "checked=true"; $fetch = "true"; //print("header ".$h['label']." checked!"); } else { $selected = ""; if ($h['fetched']) $fetch = "true"; else $fetch = "false"; } print(""); if ($prev_label == $h['label']) continue; $prev_label = $h['label']; $period = $this->get_selected_period($h['label']); // print (""); } print("
".$h['label']."  ".$h['title']."    
"); print("
            
"); //print(""); //print(""); //print(""); //print("
"); } function column_filter () { echo <<< EOF Highlight

EOF; } function column_html ($colHeader, $colName, $colId, $fulldesc, $visible) { if ($visible) $display = 'display:table-cell'; else $display = 'color:red;display:none'; return "

$colHeader
"; } function column_fix_html ($colHeader, $colName, $colId) { $display = 'display:table-cell'; $res=""; $res.= "
$colHeader
"; return $res; } function graph_html($colHeader) { return "

Show details on mouse over"; } function threshold_html($colHeader) { $updatecall = "updateColumnThreshold('".$colHeader."',window.document.getElementById('min".$colHeader."').value,window.document.getElementById('max".$colHeader."').value);"; $bubble="Grey-out values between (low) and (high)  "; return $bublle; } /* UTILS */ //simple strings function inTypeA($header_name) { $typeA = array('ST','SN','RES','OS','NRR','NTP','NSR','NSF','NDS','NTH','NEC','LRN','LCY','LPR','LCN','LAT','LON','IP','ASN','AST'); return in_array($header_name, $typeA); } //integers function inTypeB($header_name) { $typeB = array('BW','DS','MS','CC','CR','AS','DU','CN'); return in_array($header_name, $typeB); } //statistical values function inTypeC($header_name) { $typeC = array('Rw','Rm','Ry','Lw','Lm','Ly','Sw','Sm','Sy','CFw','CFm','CFy','BUw','BUm','BUy','MUw','MUm','MUy','SSHw','SSHm','SSHy'); return in_array($header_name, $typeC); } //tophat function inTypeD($header_name) { $typeD = array('HC'); return in_array($header_name, $typeD); } function removeDuration($header) { if ($this->inTypeC($header)) return substr($header, 0, strlen($header)-1); else return $header; } } ?>