Class: OSPFv2::Input

Inherits:
Object show all
Includes:
Observable
Defined in:
lib/infra/ospf_io.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sock, neighbor, ev_handler) ⇒ Input

Returns a new instance of Input.



37
38
39
40
41
42
43
# File 'lib/infra/ospf_io.rb', line 37

def initialize(sock, neighbor, ev_handler)
  super()
  @sock=sock
  @neighbor=neighbor
  add_observer(ev_handler)
  @continue=true
end

Instance Attribute Details

#sockObject (readonly)

Returns the value of attribute sock.



35
36
37
# File 'lib/infra/ospf_io.rb', line 35

def sock
  @sock
end

#threadObject (readonly)

Returns the value of attribute thread.



45
46
47
# File 'lib/infra/ospf_io.rb', line 45

def thread
  @thread
end

Instance Method Details

#our_addressObject



47
48
49
# File 'lib/infra/ospf_io.rb', line 47

def our_address
  @neighbor.address
end

#startObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/infra/ospf_io.rb', line 57

def start

  @thread = Thread.new(@sock) do |s|
    Thread.current['name'] = self.class.to_s
    begin
      while @continue
        from, port, data = s.recv
        hdr = header(data)

        if hdr[:ip_proto] == 89 and (data[20] == 2 or data[20] == "\x02")
          if from != our_address
            changed and notify_observers(:ev_recv, data, from, port) # * @sock.recv ....
          end
        end
      end
    rescue Exception => e
      p e
    end
  end
end

#stopObject



51
52
53
54
55
# File 'lib/infra/ospf_io.rb', line 51

def stop
  @thread.exit
  @thread.join
rescue
end