require './01-hub2.rb' $level = L1_Hub2 puts $level.description def help puts <<~EOF Commands: f {frame} {iface}: forward a frame to iface h: this help c: click on d: show the level description i: show the interfaces a: show the click frames and actions q: quit EOF end $instructions = [] def forward(frame, iface) $instructions << [frame, $clickframes[frame].to(iface)] end def clickactions puts "Frames:" $clickframes.each do |i, frame| puts " #{i}: Interface #{frame.iface} -> #{frame.description}" end l = 1 puts "Actions:" $instructions.each do |instr| puts " #{l}: Forward frame #{instr[0]} to interface #{instr[1].iface}" end end def click end def handle(cmd) case cmd[0] when ?h help when ?f forward(*cmd.split[1..]) when ?d puts $level.description when ?i puts $level.interfaces when ?a clickactions when ?c click when :q exit 0 end end $clickframes = $level.generate pp $clickframes loop do print ">: " handle(gets.strip) end