Class: OsCtld::Routing::Table::Version
- Inherits:
-
Object
- Object
- OsCtld::Routing::Table::Version
show all
- Includes:
- Lockable
- Defined in:
- lib/osctld/routing/table.rb
Overview
Routing table for specific IP version
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Lockable
#exclusively, included, #inclusively, #init_lock, #lock, #unlock
Constructor Details
#initialize(addrs: nil) ⇒ Version
Returns a new instance of Version.
15
16
17
18
|
# File 'lib/osctld/routing/table.rb', line 15
def initialize(addrs: nil)
@routes = addrs || []
init_lock
end
|
Instance Attribute Details
#routes ⇒ Object
Returns the value of attribute routes.
97
98
99
|
# File 'lib/osctld/routing/table.rb', line 97
def routes
@routes
end
|
Class Method Details
.load(cfg) ⇒ Object
11
12
13
|
# File 'lib/osctld/routing/table.rb', line 11
def self.load(cfg)
new(addrs: cfg.map { |route| Routing::Route.load(route) })
end
|
Instance Method Details
#<<(addr) ⇒ Object
21
22
23
24
|
# File 'lib/osctld/routing/table.rb', line 21
def <<(addr)
add(addr)
self
end
|
29
30
31
32
33
34
35
|
# File 'lib/osctld/routing/table.rb', line 29
def add(addr, via: nil)
exclusively do
r = Routing::Route.new(addr, via:)
routes << r
r
end
end
|
#any? ⇒ Boolean
71
72
73
|
# File 'lib/osctld/routing/table.rb', line 71
def any?
!empty?
end
|
#clear ⇒ Object
75
76
77
|
# File 'lib/osctld/routing/table.rb', line 75
def clear
exclusively { routes.clear }
end
|
#contains?(addr) ⇒ Boolean
61
62
63
64
65
|
# File 'lib/osctld/routing/table.rb', line 61
def contains?(addr)
exclusively do
routes.detect { |r| r.addr == addr } ? true : false
end
end
|
#dump ⇒ Array<String>
91
92
93
|
# File 'lib/osctld/routing/table.rb', line 91
def dump
exclusively { routes.map(&:dump) }
end
|
#empty? ⇒ Boolean
67
68
69
|
# File 'lib/osctld/routing/table.rb', line 67
def empty?
exclusively { routes.empty? }
end
|
#export ⇒ Array<String>
86
87
88
|
# File 'lib/osctld/routing/table.rb', line 86
def export
exclusively { routes.map(&:export) }
end
|
#get ⇒ Array
81
82
83
|
# File 'lib/osctld/routing/table.rb', line 81
def get
exclusively { routes.clone }
end
|
39
40
41
42
43
44
45
|
# File 'lib/osctld/routing/table.rb', line 39
def remove(addr)
exclusively do
route = routes.detect { |r| r.addr == addr }
routes.delete(route) if route
route
end
end
|
#remove_if(&block) ⇒ Object
47
48
49
|
# File 'lib/osctld/routing/table.rb', line 47
def remove_if(&block)
exclusively { routes.delete_if(&block) }
end
|
#route?(addr) ⇒ Boolean
52
53
54
55
56
57
58
|
# File 'lib/osctld/routing/table.rb', line 52
def route?(addr)
ret = exclusively do
routes.detect { |r| r.route?(addr) }
end
ret ? true : false
end
|