a35bdebb5fc005b6f496ecfc965b3795da9cb5cc
[nodeconfig.git] / PlanetLabConf / bwlimit.php
1 <?php
2 //
3 // Deprecated. Node Manager manages the node bandwidth limit.
4 //
5 // Mark Huang <mlhuang@cs.princeton.edu>
6 // Copyright (C) 2006 The Trustees of Princeton University
7 //
8 // $Id$
9 //
10
11 // Get admin API handle
12 require_once 'plc_api.php';
13 global $adm;
14
15 // Look up the node
16 // backwards compatibility with the old 4.2 API
17 global $__PLC_API_VERSION;
18 if ( ! method_exists ($adm,"GetInterfaces"))
19   $__PLC_API_VERSION = 4.2;
20 else
21   $__PLC_API_VERSION = 4.3;
22
23 if ($__PLC_API_VERSION==4.2)
24   $interfaces = $adm->GetNodeNetworks(array('ip' => $_SERVER['REMOTE_ADDR']));
25 else
26   $interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR']));
27
28 if (!empty($interfaces)) {
29   if ($interfaces[0]['bwlimit'] !== NULL) {
30     $rate = $interfaces[0]['bwlimit'];
31     if ($rate >= 1000000000 && ($rate % 1000000000) == 0) {
32       printf("%.0fgbit", ($rate / 1000000000.));
33     } elseif ($rate >= 1000000 && ($rate % 1000000) == 0) {
34       printf("%.0fmbit", ($rate / 1000000.));
35     } elseif ($rate >= 1000) {
36       printf("%.0fkbit", ($rate / 1000.));
37     } else {
38       printf("%.0fbit", $rate);
39     }
40   } else {
41     print "-1";
42   }
43 }
44
45 ?>