Class: RaptorIO::Socket::SwitchBoard::Route

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/raptor-io/socket/switch_board/route.rb

Overview

A logical switch board route.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subnet, netmask, comm) ⇒ Route

Returns a new instance of Route.

Parameters:

  • subnet (String, IPAddr)

    The network associated with this route. If specified as a String, must be parseable by IPAddr.new

  • netmask (String, IPAddr)

    ‘subnet`’s netmask. If specified as a String, must be parseable by IPAddr.new

  • comm (Comm)

    The endpoint where sockets for this route should be created.



16
17
18
19
20
# File 'lib/raptor-io/socket/switch_board/route.rb', line 16

def initialize(subnet, netmask, comm)
  self.netmask = IPAddr.parse(netmask)
  self.subnet  = IPAddr.parse(subnet).mask netmask.to_s
  self.comm    = comm
end

Instance Attribute Details

#commObject

Returns the value of attribute comm.



39
40
41
# File 'lib/raptor-io/socket/switch_board/route.rb', line 39

def comm
  @comm
end

#netmaskObject

Returns the value of attribute netmask.



39
40
41
# File 'lib/raptor-io/socket/switch_board/route.rb', line 39

def netmask
  @netmask
end

#subnetObject

Returns the value of attribute subnet.



39
40
41
# File 'lib/raptor-io/socket/switch_board/route.rb', line 39

def subnet
  @subnet
end

Instance Method Details

#<=>(other) ⇒ Object

For comparison, sort according to netmask.

This allows routes to be ordered by specificity



35
36
37
# File 'lib/raptor-io/socket/switch_board/route.rb', line 35

def <=>(other)
  netmask <=> other.netmask
end

#==(other) ⇒ Object

For direct equality, make sure all the attributes are the same



25
26
27
28
# File 'lib/raptor-io/socket/switch_board/route.rb', line 25

def ==(other)
  return false unless other.kind_of? RaptorIO::Socket::SwitchBoard::Route
  netmask == other.netmask && subnet == other.subnet && comm == other.comm
end