Class: Y2Network::Routing

Inherits:
Object
  • Object
show all
Defined in:
src/lib/y2network/routing.rb

Overview

General routing configuration storage (routing tables, forwarding setup, ...)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tables: [], forward_ipv4: false, forward_ipv6: false) ⇒ Routing


30
31
32
33
34
# File 'src/lib/y2network/routing.rb', line 30

def initialize(tables: [], forward_ipv4: false, forward_ipv6: false)
  @tables = tables
  @forward_ipv4 = forward_ipv4
  @forward_ipv6 = forward_ipv6
end

Instance Attribute Details

#forward_ipv4Boolean


26
27
28
# File 'src/lib/y2network/routing.rb', line 26

def forward_ipv4
  @forward_ipv4
end

#forward_ipv6Boolean


28
29
30
# File 'src/lib/y2network/routing.rb', line 28

def forward_ipv6
  @forward_ipv6
end

#tablesArray<RoutingTable> (readonly)


24
25
26
# File 'src/lib/y2network/routing.rb', line 24

def tables
  @tables
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Determines whether two set of routing settings are equal


70
71
72
73
# File 'src/lib/y2network/routing.rb', line 70

def ==(other)
  forward_ipv4 == other.forward_ipv4 && forward_ipv6 == other.forward_ipv6 &&
    ((tables - other.tables) | (other.tables - tables)).empty?
end

#default_routeRoute

TODO:

Should we implement a default_routes which returns an array instead?

Returns the default route


50
51
52
# File 'src/lib/y2network/routing.rb', line 50

def default_route
  routes.find(&:default?)
end

#default_routesArray<Route>

Returns the default routes


57
58
59
# File 'src/lib/y2network/routing.rb', line 57

def default_routes
  routes.select(&:default?)
end

#remove_default_routesObject

Remove default routes from routing tables


62
63
64
# File 'src/lib/y2network/routing.rb', line 62

def remove_default_routes
  tables.each(&:remove_default_routes)
end

#routesArray<Route>

Routes in the configuration

Convenience method to iterate through the routes in all routing tables.


41
42
43
# File 'src/lib/y2network/routing.rb', line 41

def routes
  tables.flat_map(&:to_a)
end