+function convert_data($value, $data_type) {
+
+ //print "converting ".$value." as ".$data_type;
+
+ if ($value == "" || $value == null || $value == "n/a" || $value == "None")
+ return "n/a";
+
+ if ($data_type == "string")
+ return $value;
+
+ if ($data_type == "date")
+ return date("Y-m-d", $value);
+
+ if ($data_type == "uptime")
+ return (int)((int) $value / 86400);
+
+ if (is_numeric($value))
+ return ((int) ($value * 10))/10;
+
+ return $value;
+
+}
+
+function getTopHatAgents() {
+
+ $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest@top-hat.info', 'AuthString' => 'guest');
+ $tophat_api = new TopHatAPI($tophat_auth);
+
+ //print ("Requesting tophat agents...");
+ //print_r($r);
+
+ $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'));
+
+ $result = array();
+
+ if ($values) foreach ($values as $t) {
+ //print_r($t);
+ //print("<hr>");
+ $result[$t['hostname']] = "";
+ foreach ($t['colocated'] as $ll) {
+
+ if (strpos($result[$t['hostname']]['all'],$ll['platform_name']) === false) {
+ if ($result[$t['hostname']]['all'] != "")
+ $result[$t['hostname']]['all'] .= ",";
+ $result[$t['hostname']]['all'] .= $ll['platform_name'];
+ }
+
+ if ($ll['platform_name'] == 'SONoMA') {
+ if (strpos($result[$t['hostname']]['sonoma'],$ll['peer_name']) === false) {
+ if ($result[$t['hostname']]['sonoma'] != "")
+ $result[$t['hostname']]['sonoma'] .= ",";
+ $result[$t['hostname']]['sonoma'] .= $ll['peer_name'];
+ }
+ }
+
+ if ($ll['platform_name'] == 'TDMI') {
+ if (strpos($result[$t['hostname']]['tdmi'],$ll['peer_name']) === false) {
+ if ($result[$t['hostname']]['tdmi'] != "")
+ $result[$t['hostname']]['tdmi'] .= ",";
+ $result[$t['hostname']]['tdmi'] .= $ll['peer_name'];
+ }
+ }
+ }
+ }
+
+ $this->TopHatAgents = $result;
+
+ //print_r($this->TopHatAgents);
+
+ return $result;
+}
+
+function getTopHatData($data, $planetlab_nodes) {
+
+ $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest@top-hat.info', 'AuthString' => 'guest');
+ $tophat_api = new TopHatAPI($tophat_auth);
+
+ $requested_data = explode(",", $data);
+
+ $r = array ('hostname');
+
+ foreach ($requested_data as $rd)
+ if ($rd) $r[] = $rd;
+
+ //print ("Requesting data from TopHat ...");
+ //print_r($r);
+
+ $values = $tophat_api->Get('ips', 'latest', array('hostname' => $planetlab_nodes), $r );
+
+ $result = array();
+
+ if ($values) foreach ($values as $t)
+ foreach ($requested_data as $rd)
+ if ($rd) $result[$t['hostname']][$rd] = $t[$rd];
+
+ //print_r($result);
+
+ return $result;
+}
+
+function getTopHatRefNodes() {
+
+ $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest@top-hat.info', 'AuthString' => 'guest');
+ $tophat_api = new TopHatAPI($tophat_auth);
+
+ //print "calling tophat for agents";
+
+ $agents = $tophat_api->Get('agents', 'latest', array('peer_name'=>array('PLC', 'PLE'), 'agent_status'=> 'OK'), array('hostname'));
+
+ //print_r($agents);
+
+ return $agents;
+
+}
+
+function getPairwise($ref_node, $planetlab_nodes, $command, $data) {
+
+ $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest@top-hat.info', 'AuthString' => 'guest');
+ $tophat_api = new TopHatAPI($tophat_auth);
+
+ $traceroute = $tophat_api->Get($command, 'latest', array('src_hostname' => $ref_node, 'dst_hostname' => $planetlab_nodes), array('dst_hostname', $data) );
+
+ print "Got result: ".$traceroute;
+
+ $hopcount = array();
+
+ if ($traceroute)
+ {
+ foreach ($traceroute as $t)
+ {
+ $hopcount[$t['dst_hostname']]=$t[$data];
+ //print " current: ".$t['dst_hostname'].":".$t['hop_count'];
+ }
+
+ return $hopcount;
+ }
+ else
+ return "";
+}
+
+function comon_query_nodes($requested_data) {
+
+ $base_url = "http://comon.cs.princeton.edu/status/tabulator.cgi?table=table_nodeviewshort&format=formatcsv&dumpcols='name";