From 42f9fdc0b88dd819a61593ed053d6b0713c59e45 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Fri, 10 May 2024 10:31:08 +0100 Subject: One frame at a time --- 03-switch3.rb | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to '03-switch3.rb') diff --git a/03-switch3.rb b/03-switch3.rb index 7cbdc2f..f8809d7 100644 --- a/03-switch3.rb +++ b/03-switch3.rb @@ -33,25 +33,22 @@ $levels << Level.new do end def generate - frames = {} - @interfaces.each do |iface| - next if rand < 0.3 + iface = interfaces.sample - if rand < 0.4 || @fib[iface].nil? - src = Frame2.gen_addr - @next_fib[iface] = src - else - src = @fib[iface] - end + if rand < 0.4 || @fib[iface].nil? + src = Frame2.gen_addr + @next_fib[iface] = src + else + src = @fib[iface] + end - dst = nil - dst = (@fib.values.compact - [src]).sample if rand < 0.5 - dst = Frame2.gen_addr if dst.nil? + dst = nil + dst = (@fib.values.compact - [src]).sample if rand < 0.5 + dst = Frame2.gen_addr if dst.nil? - frames[@count.to_s] = Frame2.new(iface, src, dst) - @count += 1 - end - frames + frame = Frame2.new(iface, src, dst) + @count += 1 + frame end def click -- cgit v1.2.1