Changes between Version 4 and Version 5 of GEC19Agenda/GIMI/Procedure/Execute


Ignore:
Timestamp:
03/18/14 11:36:35 (9 years ago)
Author:
divyashri.bhat@gmail.com
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • GEC19Agenda/GIMI/Procedure/Execute

    v4 v5  
    8585== 2. Write your Parser ==
    8686
    87 {{{
     87=== 2.1 Write your OML Parser ===
     88{{{
     89
     90def process_output(row)
     91  if not (parse= /RQ:'(?<pktsnt1>\d*)\+(?<pktsnt2>\d*)' to (?<host>[a-f0-9:]*)/.match(row)).nil?
     92  puts "ReturnQual #{parse[:pktsnt1]}\n"
     93  MPrt.inject(parse[:pktsnt1], parse[:pktsnt2],parse[:host])
     94
     95  elsif not (parse= /RL:(?<numofpkt1>\d*)\+(?<numofpkt2>\d*)=(?<totpktrec>\d*) from (?<dest_hw_addr>[a-f0-9:]*)/.match(row)).nil?
     96  puts "ReturnLength\n"
     97  p parse
     98  p MPrl.inject(parse[:numofpkt1],parse[:numofpkt2],parse[:totpktrec],parse[:dest_hw_addr])
     99
     100  elsif not (parse = /RTT = (?<rtt>[0-9.]*)/.match(row)).nil?
     101  puts "RoundTripTime #{parse[:rtt]}\n"
     102  p parse
     103  p MPrtt.inject(parse[:rtt])
     104  end
     105end
     106
     107}}}
     108
     109{{{
     110
     111#!/usr/bin/ruby1.9.1
     112require 'rubygems'
     113require 'oml4r'
     114
     115class MPrt < OML4R::MPBase
     116   name :pingrt
     117   param :pktsnt1, :type => :uint64
     118   param :pktsnt2, :type => :uint64
     119   param :host, :type => :string
     120end
     121
     122class MPrl < OML4R::MPBase
     123   name :pingrl
     124   param :totpktrec, :type => :uint64
     125   param :numofpkt1, :type => :uint64
     126   param :numofpkt2, :type => :uint64
     127   param :dest_hw_addr, :type => :string
     128end
     129
     130class MPrtt < OML4R::MPBase
     131   name :pingrtt
     132   param :rtt, :type => :double
     133end
     134
     135class Pingl2Wrapper
     136
     137  def initialize(args)
     138     @addr = nil
     139     @if_num = ''
     140     @eth = nil
     141     @verbose = true
     142     @numeric = ''
     143
     144     leftover = OML4R::init(args, :appName => 'pingl2') do |argParser|
     145       argParser.banner = "Runs layer 2 ping and reports measurements via OML\n\n"
     146       argParser.on("-a" , "--dest_hw_addr ADDRESS", "Hardware address to ping (the -a switch is optional)"){ |address| @addr = address.to_s() }
     147       argParser.on("-i","--interface IFNUM","Interface number"){ |if_num| @if_num ="#{if_num.to_i()}" }
     148       argParser.on("-e", "--eth ETHTYPE","Ethernet Type") { |ethtype| @eth = ethtype.to_s() }
     149       argParser.on("-c","--count NUMBER","Number of pings (default: infinite)"){ |count| @count = "#{count.to_i()}"}
     150       argParser.on("-q", "--no-quiet ","Don't show layer 2 ping output on console"){ @verbose = false }
     151       argParser.on("-n", "--[no]-numeric ", "No attempt twill be made to look up symbolic names for host addresses"){ @numeric ='-n' }
     152    end
     153
     154    if @addr.nil?
     155      if leftover.length > 0
     156        @addr = leftover [0]
     157      else
     158        raise "You did not specify an address to ping!"
     159      end
     160    end
     161
     162end
     163
     164def process_output(row)
     165  if not (parse= /RQ:'(?<pktsnt1>\d*)\+(?<pktsnt2>\d*)' to (?<host>[a-f0-9:]*)/.match(row)).nil?
     166  puts "ReturnQual #{parse[:pktsnt1]}\n"
     167  MPrt.inject(parse[:pktsnt1], parse[:pktsnt2],parse[:host])
     168
     169  elsif not (parse= /RL:(?<numofpkt1>\d*)\+(?<numofpkt2>\d*)=(?<totpktrec>\d*) from (?<dest_hw_addr>[a-f0-9:]*)/.match(row)).nil?
     170  puts "ReturnLength\n"
     171  p parse
     172  p MPrl.inject(parse[:numofpkt1],parse[:numofpkt2],parse[:totpktrec],parse[:dest_hw_addr])
     173
     174  elsif not (parse = /RTT = (?<rtt>[0-9.]*)/.match(row)).nil?
     175  puts "RoundTripTime #{parse[:rtt]}\n"
     176  p parse
     177  p MPrtt.inject(parse[:rtt])
     178  end
     179end
     180
     181def pingl2()
     182   @pingio = IO.popen("/bin/pingPlus #{@addr} #{@eth} #{@if_num} #{@count}")
     183   while true
     184    row = @pingio.readline
     185    puts row if @verbose
     186    process_output(row)
     187    end
     188end
     189
     190def start()
     191    return if not @pingio.nil?
     192
     193    # handle for OMF's exit command
     194    a = Thread.new do
     195      $stdin.each do |line|
     196    if /^exit/ =~ line
     197      Process.kill("INT",0)   
     198    end
     199      end
     200    end
    88201
    89202}}}