blob: fc36a6e8bdcadf7040881e9cb5721e04f5a25b35 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
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
|