aboutsummaryrefslogtreecommitdiff
path: root/01-hub2.rb
blob: 4ed0f6b85bbefb80380bf621600e44c279d0cfee (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
require './level'
require './frame'

class L1_Hub2 < Level
  interfaces %w(1 2)
  description <<~EOD
    You are a two-port hub. Your job is to forward frames from one interface to the other.
  EOD

  def self.target(frame)
    case frame.iface
    when 1
      [frame.to(2)]
    when 2
      [frame.to(1)]
    end
  end

  def self.generate
    frames = {}
    @@interfaces.each do |iface|
      next if rand < 0.4
      frames[@@count.to_s] = Frame.new(iface, "Frame #{@@count}")
      @@count += 1
    end
    frames
  end
end