Class: Distem::Resource::Latency
- Inherits:
-
VIface::VTraffic::Property
- Object
- VIface::VTraffic::Property
- Distem::Resource::Latency
- Defined in:
- lib/distem/resource/latency.rb
Overview
Abstract representation of Network Latency resource
Instance Attribute Summary (collapse)
-
- (Object) delay
readonly
The delay (String at 'tc' form such as “3ms”).
Class Method Summary (collapse)
- + (Object) is_valid(latency)
-
+ (Object) to_secs(delay)
converts the latency/delay to seconds (floating point) returns nil if not set.
Instance Method Summary (collapse)
-
- (Latency) initialize(paramshash = {})
constructor
Create a new Bandwidth ==== Attributes *
paramshash
The Hash of the parameters to set (in the form “paramname” => value). -
- (Object) limit_from_bandwidth(bandwidth)
adjust 'limit' parameter to netem so that it works sensibly bandwidth is the rate that this link will emulate (in bytes/s) it can be nil, then we assume it is 1Gbit/s.
-
- (Object) parse_params(paramshash)
Parameters parsing method.
- - (Object) tc_params(bandwidth)
- - (Object) to_secs
Methods inherited from VIface::VTraffic::Property
Constructor Details
- (Latency) initialize(paramshash = {})
Create a new Bandwidth
Attributes
-
paramshash
The Hash of the parameters to set (in the form “paramname” => value)
13 14 15 16 17 |
# File 'lib/distem/resource/latency.rb', line 13 def initialize(paramshash={}) super() @delay = nil parse_params(paramshash) end |
Instance Attribute Details
- (Object) delay (readonly)
The delay (String at 'tc' form such as “3ms”)
8 9 10 |
# File 'lib/distem/resource/latency.rb', line 8 def delay @delay end |
Class Method Details
+ (Object) is_valid(latency)
[ ]
65 66 67 68 69 70 71 72 |
# File 'lib/distem/resource/latency.rb', line 65 def self.is_valid(latency) begin self.to_secs(latency) return true rescue ArgumentError return false end end |
+ (Object) to_secs(delay)
converts the latency/delay to seconds (floating point) returns nil if not set
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/distem/resource/latency.rb', line 46 def self.to_secs(delay) return nil if delay.nil? m = /^(\d+)(\w*)$/.match(delay) raise ArgumentError if m.nil? digits, units = m.captures mult = case units when 's', 'sec', 'secs' then 1.0 # seconds when 'ms', 'msec', 'msecs' then 0.001 # milliseconds when 'us', 'usec', 'usecs', '' then 0.000001 # microseconds else nil end raise ArgumentError if mult.nil? return (digits.to_i * mult) end |
Instance Method Details
- (Object) limit_from_bandwidth(bandwidth)
adjust 'limit' parameter to netem so that it works sensibly bandwidth is the rate that this link will emulate (in bytes/s) it can be nil, then we assume it is 1Gbit/s
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/distem/resource/latency.rb', line 28 def limit_from_bandwidth(bandwidth) bandwidth = (1024 ** 3) if bandwidth.nil? capacity = bandwidth * to_secs() # on average the packet has ~ 1500 bytes (Ethernet MTU?) packets = capacity / 1500.0 # we give additional space (10%), just in case limit = (packets * 1.1).to_i limit = 1000 if limit < 1000 return limit end |
- (Object) parse_params(paramshash)
Parameters parsing method
20 21 22 23 |
# File 'lib/distem/resource/latency.rb', line 20 def parse_params(paramshash) super(paramshash) @delay = paramshash['delay'] end |
- (Object) tc_params(bandwidth)
[ ]
39 40 41 42 |
# File 'lib/distem/resource/latency.rb', line 39 def tc_params(bandwidth) return { 'delay' => @delay } if @delay.nil? return { 'delay' => @delay, 'limit' => limit_from_bandwidth(bandwidth) } end |
- (Object) to_secs
[ ]
61 62 63 |
# File 'lib/distem/resource/latency.rb', line 61 def to_secs Latency.to_secs(@delay) end |