Class: Throttle::Pipe
- Inherits:
-
Object
- Object
- Throttle::Pipe
- Extended by:
- Ipfw
- Includes:
- Ipfw
- Defined in:
- lib/throttle/pipe.rb
Instance Attribute Summary collapse
-
#bandwidth ⇒ Object
Returns the value of attribute bandwidth.
-
#id ⇒ Object
Returns the value of attribute id.
-
#rule_id ⇒ Object
Returns the value of attribute rule_id.
Class Method Summary collapse
Instance Method Summary collapse
- #delete ⇒ Object
- #delete_rule ⇒ Object
-
#initialize(options = {}) ⇒ Pipe
constructor
A new instance of Pipe.
- #set ⇒ Object
- #set_rule_id ⇒ Object
Methods included from Ipfw
Constructor Details
#initialize(options = {}) ⇒ Pipe
44 45 46 47 |
# File 'lib/throttle/pipe.rb', line 44 def initialize( = {}) @id = [:id] @bandwidth = [:bandwidth] end |
Instance Attribute Details
#bandwidth ⇒ Object
Returns the value of attribute bandwidth.
3 4 5 |
# File 'lib/throttle/pipe.rb', line 3 def bandwidth @bandwidth end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/throttle/pipe.rb', line 3 def id @id end |
#rule_id ⇒ Object
Returns the value of attribute rule_id.
3 4 5 |
# File 'lib/throttle/pipe.rb', line 3 def rule_id @rule_id end |
Class Method Details
.all ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/throttle/pipe.rb', line 5 def self.all pipes = [] pipe_lines = [] ipfw('list').split("\n").each do |line| if /^\d{5} pipe.*$/.match(line) pipe_lines << Regexp.last_match(0) end end pipe_lines.each do |line| id = parse_pipe_id(line) bandwidth = Pipe.bandwidth(id) pipes << Pipe.new({ :id => id, :bandwidth => bandwidth }) end return pipes end |
.bandwidth(id) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/throttle/pipe.rb', line 28 def self.bandwidth(id) output = ipfw("pipe #{id} show") if /^\d{5}:\W*(\d*\.\d* \S*).*$/.match(output) Regexp.last_match(1) else nil end end |
.reset ⇒ Object
38 39 40 41 42 |
# File 'lib/throttle/pipe.rb', line 38 def self.reset Pipe.all.each do |pipe| pipe.delete end end |
Instance Method Details
#delete ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/throttle/pipe.rb', line 73 def delete delete_rule unless @bandwidth.nil? ipfw("pipe #{@id} delete") end end |
#delete_rule ⇒ Object
81 82 83 84 85 |
# File 'lib/throttle/pipe.rb', line 81 def delete_rule if rule_id && rule_id != 0 ipfw("delete #{rule_id}") end end |
#set ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/throttle/pipe.rb', line 49 def set unless rule_id ipfw("add pipe #{self.id} ip from any to any") end ipfw("pipe #{id} config bw #{self.bandwidth}") end |
#set_rule_id ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/throttle/pipe.rb', line 65 def set_rule_id regex = "^(\d{5}) pipe #{self.id}.*$" if /^(\d{5}) pipe #{self.id}.*$/.match(ipfw("list")) Regexp.last_match(1) end end |