class Aio::Module::Cmd::Maipu::ShowIpRoute

Public Class Methods

new() click to toggle source
Calls superclass method Aio::Module::Cmd::new
# File lib/modules/cmd/maipu/show_ip_route.rb, line 8
def initialize
        super({
                :cmd_full                    => "show ip route",
                :cmd_short           => "sh ip rou",
                :author                              => "Elin",
                :ranking                     => Ranking_2,
                :description => "This is Maipu Command# show ip route",
                :platform                    => "all",
                :benchmark           => {}
        })
end

Public Instance Methods

parse() click to toggle source
# File lib/modules/cmd/maipu/show_ip_route.rb, line 20
def parse
        cont = self.context.dup
        routing = {}
        useful[:routing] = routing

        cont.readline_match_block(reg_blank) {|b|b}
        cont.readline_match_block(reg_blank) {|b|b}

        cont.readline_range_if_loop(/^\w/, /^\s+/) do |cont_layer|
                parse_routing(cont_layer)
        end
end
parse_routing(context) click to toggle source
# File lib/modules/cmd/maipu/show_ip_route.rb, line 33
def parse_routing(context)
        
        router = nil

        if context[0] =~ /^C/
                context.readline_match_block(/C (?<dest>.*) is directly connected, .*, (?<iface>.*)/) do |block|
                        route = {}
                        router = block[:dest]
                        useful[:routing][router] = {}
                        useful[:routing][router][:first] = route
                        block.update(useful[:routing][router], :dest)
                        block.update(route, :proto, "C")
                        block.update(route, :iface)
                end
                return
        end

        context.readline_match_block(/(?<proto>.*) (?<dest>.*) \[(?<metric>\d+)\/(?<ad>\d+)\] via (?<next_hop>.*), (?<time>.*), (?<iface>.*)/) do |block|
                route = {}
                router = block[:dest]
                useful[:routing][router] = {}
                useful[:routing][router][:first] = route
                block.update(useful[:routing][router], :dest)
                block.update(route, :proto)
                block.update(route, :metric)
                block.update(route, :ad)
                block.update(route, :next_hop)
                block.update(route, :iface)
        end

        if context.size == 2
                context.readline_match_block(/\[(?<metric>\d+)\/(?<ad>\d+)\] via (?<next_hop>.*), (?<time>.*), (?<iface>.*)/) do |block|
                        route = {}
                        useful[:routing][router][:secend] = route
                        block.update(route, :metric)
                        block.update(route, :ad)
                        block.update(route, :next_hop)
                        block.update(route, :iface)
                end
        end
end