Revision f61dc8e6
Added by Ermal LUÇI almost 14 years ago
etc/inc/shaper.inc | ||
---|---|---|
231 | 231 |
var $queues = array(); |
232 | 232 |
var $qenabled = false; |
233 | 233 |
var $link; |
234 |
var $default_present = false; /* if we have a default queue set */ |
|
235 | 234 |
var $available_bw; /* in b/s */ |
236 | 235 |
|
237 | 236 |
/* Accesor functions */ |
... | ... | |
241 | 240 |
function SetAvailableBandwidth($bw) { |
242 | 241 |
$this->available_bw = $bw; |
243 | 242 |
} |
244 |
function SetDefaultQueuePresent($value = false) { |
|
245 |
$this->default_present = $value; |
|
246 |
} |
|
247 | 243 |
function GetDefaultQueuePresent() { |
248 |
return $this->default_present; |
|
244 |
if (!empty($this->queues)) { |
|
245 |
foreach ($this->queues as $q) { |
|
246 |
if ($q->GetDefault()) |
|
247 |
return true; |
|
248 |
} |
|
249 |
} |
|
250 |
|
|
251 |
return false; |
|
249 | 252 |
} |
250 | 253 |
function SetLink($link) { |
251 | 254 |
$this->link = $link; |
... | ... | |
823 | 826 |
function SetBwscale($scale) { |
824 | 827 |
$this->qbandwidthtype = $scale; |
825 | 828 |
} |
829 |
function GetDefaultQueuePresent() { |
|
830 |
if ($this->GetDefault()) |
|
831 |
return true; |
|
832 |
if (!empty($this->subqueues)) { |
|
833 |
foreach ($this->subqueues as $q) { |
|
834 |
if ($q->GetDefault()) |
|
835 |
return true; |
|
836 |
} |
|
837 |
} |
|
838 |
|
|
839 |
return false; |
|
840 |
} |
|
826 | 841 |
function GetDefault() { |
827 | 842 |
return $this->qdefault; |
828 | 843 |
} |
829 | 844 |
function SetDefault($value = false) { |
830 | 845 |
$this->qdefault = $value; |
831 |
altq_set_default_queue($this->GetInterface(), $value); |
|
832 | 846 |
} |
833 | 847 |
function GetRed() { |
834 | 848 |
return $this->qred; |
... | ... | |
923 | 937 |
|
924 | 938 |
function delete_queue() { |
925 | 939 |
unref_on_altq_queue_list($this->GetQname()); |
926 |
if ($this->GetDefault()) |
|
927 |
altq_set_default_queue($this->GetInterface(), false); |
|
928 | 940 |
cleanup_queue_from_rules($this->GetQname()); |
929 | 941 |
unset_object_by_reference($this->GetLink()); |
930 | 942 |
} |
... | ... | |
973 | 985 |
$input_errors[] = gettext("Queue names must be alphanumeric and _ or - only."); |
974 | 986 |
if (!empty($data['name']) && !preg_match("/^[a-zA-Z0-9_-]*$/", $data['name'])) |
975 | 987 |
$input_errors[] = gettext("Queue names must be alphanumeric and _ or - only."); |
976 |
|
|
988 |
if (!empty($data['default']) && altq_get_default_queue($data['interface'])) |
|
989 |
$input_errors[] = gettext("Only one default queue per interface is allowed."); |
|
977 | 990 |
} |
978 | 991 |
|
979 | 992 |
function ReadConfig(&$q) { |
... | ... | |
984 | 997 |
} else if (isset($q['name'])) |
985 | 998 |
$this->SetQname($q['name']); |
986 | 999 |
if (isset($q['interface'])) |
987 |
$this->SetInterface($q['interface']);
|
|
1000 |
$this->SetInterface($q['interface']); |
|
988 | 1001 |
$this->SetBandwidth($q['bandwidth']); |
989 | 1002 |
if ($q['bandwidthtype'] <> "") |
990 | 1003 |
$this->SetBwscale($q['bandwidthtype']); |
... | ... | |
1140 | 1153 |
$form .= "<td width=\"22%\" valign=\"center\" class=\"vncell\">" . gettext("Scheduler options") . "</td>"; |
1141 | 1154 |
$form .= "<td width=\"78%\" class=\"vtable\">"; |
1142 | 1155 |
if (empty($this->subqueues)) { |
1143 |
$tmpvalue = $this->GetDefault(); |
|
1144 |
if (altq_get_default_queue($this->GetInterface()) == false || !empty($tmpvalue)) { |
|
1145 |
if (!empty($tmpvalue)) { |
|
1146 |
$form .= "<input type=\"checkbox\" id=\"default\" CHECKED name=\"default\" value=\"default\""; |
|
1147 |
$form .= "> " . gettext("Default queue") . "<br>"; |
|
1148 |
} else { |
|
1149 |
$form .= "<input type=\"checkbox\" id=\"default\" name=\"default\" value=\"default\""; |
|
1150 |
$form .= "> " . gettext("Default queue") . "<br>"; |
|
1151 |
} |
|
1156 |
if ($this->GetDefault()) { |
|
1157 |
$form .= "<input type=\"checkbox\" id=\"default\" CHECKED name=\"default\" value=\"default\""; |
|
1158 |
$form .= "> " . gettext("Default queue") . "<br>"; |
|
1159 |
} else { |
|
1160 |
$form .= "<input type=\"checkbox\" id=\"default\" name=\"default\" value=\"default\""; |
|
1161 |
$form .= "> " . gettext("Default queue") . "<br>"; |
|
1152 | 1162 |
} |
1153 | 1163 |
} |
1154 | 1164 |
$form .= "<input type=\"checkbox\" id=\"red\" name=\"red\" value=\"red\" "; |
... | ... | |
1494 | 1504 |
|
1495 | 1505 |
function delete_queue() { |
1496 | 1506 |
unref_on_altq_queue_list($this->GetQname()); |
1497 |
$tmpvalue = $this->GetDefault(); |
|
1498 |
if (!empty($tmpvalue)) |
|
1499 |
altq_set_default_queue($this->GetInterface(), false); |
|
1500 | 1507 |
cleanup_queue_from_rules($this->GetQname()); |
1501 | 1508 |
$parent =& $this->GetParent(); |
1502 | 1509 |
foreach ($this->subqueues as $q) { |
... | ... | |
1632 | 1639 |
$input_errors[] = ("realtime specification excedd 80% of allowable allocation."); |
1633 | 1640 |
} |
1634 | 1641 |
*/ |
1635 |
|
|
1636 | 1642 |
} |
1637 | 1643 |
|
1638 | 1644 |
function ReadConfig(&$cflink) { |
... | ... | |
2169 | 2175 |
|
2170 | 2176 |
function delete_queue() { |
2171 | 2177 |
unref_on_altq_queue_list($this->GetQname()); |
2172 |
if ($this->GetDefault()) |
|
2173 |
altq_set_default_queue($this->GetInterface(), false); |
|
2174 | 2178 |
cleanup_queue_from_rules($this->GetQname()); |
2175 | 2179 |
foreach ($this->subqueues as $q) { |
2176 | 2180 |
$this->SetAvailableBandwidth($this->GetAvailableBandwidth() + $q->GetAvailableBandwidth()); |
... | ... | |
2204 | 2208 |
} |
2205 | 2209 |
|
2206 | 2210 |
/* |
2207 |
$parent =& $this->GetParent(); |
|
2208 |
switch ($data['bandwidthtype']) { |
|
2209 |
case "%": |
|
2210 |
$myBw = $parent->GetAvailableBandwidth() * floatval($data['bandwidth']) / 100; |
|
2211 |
default: |
|
2212 |
$mybw = floatval($data['bandwidth']) * get_bandwidthtype_scale($data['bandwidthtype']); |
|
2213 |
break; |
|
2214 |
} |
|
2211 |
$parent =& $this->GetParent(); |
|
2212 |
switch ($data['bandwidthtype']) { |
|
2213 |
case "%": |
|
2214 |
$myBw = $parent->GetAvailableBandwidth() * floatval($data['bandwidth']) / 100; |
|
2215 |
break; |
|
2216 |
default: |
|
2217 |
$mybw = floatval($data['bandwidth']) * get_bandwidthtype_scale($data['bandwidthtype']); |
|
2218 |
break; |
|
2219 |
} |
|
2215 | 2220 |
if ($parent->GetAvailableBandwidth() < floatval($myBw)) |
2216 | 2221 |
$input_errors[] = "The sum of the children bandwidth exceeds that of the parent."; |
2217 | 2222 |
*/ |
... | ... | |
2449 | 2454 |
|
2450 | 2455 |
function delete_queue() { |
2451 | 2456 |
unref_on_altq_queue_list($this->GetQname()); |
2452 |
if ($this->GetDefault()) |
|
2453 |
altq_set_default_queue($this->GetInterface(), false); |
|
2454 | 2457 |
cleanup_queue_from_rules($this->GetQname()); |
2455 | 2458 |
unset_object_by_reference($this->GetLink()); |
2456 | 2459 |
} |
... | ... | |
3817 | 3820 |
* This is a layer violation but for now there is no way |
3818 | 3821 |
* i can find to properly do this with PHP. |
3819 | 3822 |
*/ |
3820 |
function altq_set_default_queue($interface, $value) { |
|
3821 |
global $altq_list_queues; |
|
3822 |
|
|
3823 |
$altq_tmp =& $altq_list_queues[$interface]; |
|
3824 |
if ($altq_tmp) |
|
3825 |
$altq_tmp->SetDefaultQueuePresent($value); |
|
3826 |
} |
|
3827 |
|
|
3828 | 3823 |
function altq_get_default_queue($interface) { |
3829 | 3824 |
global $altq_list_queues; |
3830 | 3825 |
|
Also available in: Unified diff
Resolves #1193. Properly warn about duplicate default queue