Class: OsCtld::Routing::Table
- Inherits:
-
Object
- Object
- OsCtld::Routing::Table
- Defined in:
- lib/osctld/routing/table.rb
Overview
Represents routing table for a network interface
Defined Under Namespace
Classes: Version
Instance Attribute Summary collapse
-
#tables ⇒ Object
readonly
protected
Returns the value of attribute tables.
Class Method Summary collapse
-
.load(cfg) ⇒ Object
Load the table from config.
Instance Method Summary collapse
- #<<(addr) ⇒ Object
- #add(addr, via: nil) ⇒ Routing::Route
-
#any?(v) ⇒ Boolean
Check if there are any routes for given IP version.
-
#contains?(addr) ⇒ Boolean
Check if there is an exact entry for `addr`.
-
#dump ⇒ Hash
Dump the table into config.
-
#each(ip_v) {|version, addr| ... } ⇒ Object
Iterate over all routes.
-
#each_version(ip_v) {|addr| ... } ⇒ Object
Iterate over all routes for IP version.
- #empty?(v) ⇒ Boolean
-
#export ⇒ Hash
Export the table to clients.
-
#initialize(tables: nil) ⇒ Table
constructor
A new instance of Table.
- #remove(addr) ⇒ Routing::Route?
- #remove_all(ip_v = nil) ⇒ Array<Routing::Route>
-
#remove_version_if(ip_v) {|addr| ... } ⇒ Object
Remove routes for which the block returns truthy value.
-
#route?(addr) ⇒ Boolean
Check if the table routes `addr`.
- #t(addr) ⇒ Object protected
Constructor Details
Instance Attribute Details
#tables ⇒ Object (readonly, protected)
Returns the value of attribute tables.
208 209 210 |
# File 'lib/osctld/routing/table.rb', line 208 def tables @tables end |
Class Method Details
Instance Method Details
#<<(addr) ⇒ Object
113 114 115 116 |
# File 'lib/osctld/routing/table.rb', line 113 def <<(addr) add(addr) self end |
#add(addr, via: nil) ⇒ Routing::Route
121 122 123 |
# File 'lib/osctld/routing/table.rb', line 121 def add(addr, via: nil) t(addr).add(addr, via: via) end |
#any?(v) ⇒ Boolean
Check if there are any routes for given IP version
158 159 160 |
# File 'lib/osctld/routing/table.rb', line 158 def any?(v) tables[v].any? end |
#contains?(addr) ⇒ Boolean
Check if there is an exact entry for `addr`
152 153 154 |
# File 'lib/osctld/routing/table.rb', line 152 def contains?(addr) t(addr).contains?(addr) end |
#dump ⇒ Hash
Dump the table into config
203 204 205 |
# File 'lib/osctld/routing/table.rb', line 203 def dump Hash[ tables.map { |version, table| ["v#{version}", table.dump] } ] end |
#each(ip_v) {|version, addr| ... } ⇒ Object
Iterate over all routes
170 171 172 173 174 175 176 177 178 |
# File 'lib/osctld/routing/table.rb', line 170 def each(ip_v, &block) ret = [] tables.each do |version, table| ret.concat(table.get.map { |route| [version, route] }) end Hash[ret].each(&block) end |
#each_version(ip_v) {|addr| ... } ⇒ Object
Iterate over all routes for IP version
183 184 185 |
# File 'lib/osctld/routing/table.rb', line 183 def each_version(ip_v, &block) tables[ip_v].get.each(&block) end |
#empty?(v) ⇒ Boolean
163 164 165 |
# File 'lib/osctld/routing/table.rb', line 163 def empty?(v) tables[v].empty? end |
#export ⇒ Hash
Export the table to clients
197 198 199 |
# File 'lib/osctld/routing/table.rb', line 197 def export Hash[ tables.map { |version, table| [version, table.export] } ] end |
#remove(addr) ⇒ Routing::Route?
127 128 129 |
# File 'lib/osctld/routing/table.rb', line 127 def remove(addr) t(addr).remove(addr) end |
#remove_all(ip_v = nil) ⇒ Array<Routing::Route>
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/osctld/routing/table.rb', line 133 def remove_all(ip_v = nil) ret = [] (ip_v ? [ip_v] : [4, 6]).each do |v| ret.concat(tables[v].get) tables[v].clear end ret end |
#remove_version_if(ip_v) {|addr| ... } ⇒ Object
Remove routes for which the block returns truthy value
191 192 193 |
# File 'lib/osctld/routing/table.rb', line 191 def remove_version_if(ip_v, &block) tables[ip_v].remove_if(&block) end |
#route?(addr) ⇒ Boolean
Check if the table routes `addr`
146 147 148 |
# File 'lib/osctld/routing/table.rb', line 146 def route?(addr) t(addr).route?(addr) end |
#t(addr) ⇒ Object (protected)
210 211 212 |
# File 'lib/osctld/routing/table.rb', line 210 def t(addr) addr.ipv4? ? tables[4] : tables[6] end |