Class: Distem::Algorithm::Network::TCAlgorithm
- Inherits:
-
Algorithm
- Object
- Algorithm
- Distem::Algorithm::Network::TCAlgorithm
- Defined in:
- lib/distem/algorithm/network/tcalgorithm.rb
Overview
A common interface for TC based algorithms
Direct Known Subclasses
Constant Summary
- @@lock =
Mutex.new
- @@store =
{}
- @@ifballocator =
nil
Instance Method Summary (collapse)
-
- (Object) apply(viface)
:nodoc:.
-
- (Object) clean(viface)
Clean every previous run config.
-
- (TCAlgorithm) initialize
constructor
A new instance of TCAlgorithm.
Methods inherited from Algorithm
Constructor Details
- (TCAlgorithm) initialize
Returns a new instance of TCAlgorithm
13 14 15 16 17 18 19 20 21 |
# File 'lib/distem/algorithm/network/tcalgorithm.rb', line 13 def initialize() @limited_bw_output = false @limited_lat_output = false @limited_bw_input = false @limited_lat_input = false if @@ifballocator.nil? @@ifballocator = Node::IFBAllocator::new end end |
Instance Method Details
- (Object) apply(viface)
:nodoc:
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/distem/algorithm/network/tcalgorithm.rb', line 24 def apply(viface) @@lock.synchronize { @@store[viface] = {} if !@@store[viface] } bw_output = (viface.voutput != nil) && (viface.voutput.get_property(Resource::Bandwidth.name) != nil) && (viface.voutput.get_property(Resource::Bandwidth.name).rate != nil) lat_output = (viface.voutput != nil) && (viface.voutput.get_property(Resource::Latency.name) != nil) && (viface.voutput.get_property(Resource::Latency.name).delay != nil) bw_input = (viface.vinput != nil) && (viface.vinput.get_property(Resource::Bandwidth.name) != nil) && (viface.vinput.get_property(Resource::Bandwidth.name).rate != nil) lat_input = (viface.vinput != nil) && (viface.vinput.get_property(Resource::Latency.name) != nil) && (viface.vinput.get_property(Resource::Latency.name).delay != nil) clean(viface) if (bw_output != @limited_bw_output) || (lat_output != @limited_lat_output) || (bw_input != @limited_bw_input) || (lat_input != @limited_lat_input) || viface.latency_filters end |
- (Object) clean(viface)
Clean every previous run config
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/distem/algorithm/network/tcalgorithm.rb', line 42 def clean(viface) @limited_bw_output = false @limited_lat_output = false @limited_bw_input = false @limited_lat_input = false @@lock.synchronize { @@store[viface] = {} } iface = Lib::NetTools::get_iface_name(viface.vnode,viface) ifb = viface.ifb str = Lib::Shell.run("tc qdisc show || true").split(/\n/).grep(/ dev #{ifb} /) if not str.empty? and not str[0].include?('pfifo_fast') inputroot = TCWrapper::QdiscRoot.new(ifb) Lib::Shell.run(inputroot.get_cmd(TCWrapper::Action::DEL)) end str = Lib::Shell.run("tc qdisc show | grep #{iface} | grep ingress || true") if str and !str.empty? inputroot = TCWrapper::QdiscIngress.new(iface) Lib::Shell.run(inputroot.get_cmd(TCWrapper::Action::DEL)) end @@ifballocator.free_ifb(ifb) str = Lib::Shell.run("tc qdisc show | grep #{iface}") if str and !str.empty? and !str.include?('pfifo_fast') outputroot = TCWrapper::QdiscRoot.new(iface) Lib::Shell.run(outputroot.get_cmd(TCWrapper::Action::DEL)) end end |