Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuhito committed Dec 11, 2015
1 parent 3c8b656 commit a34e8fb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
1 change: 0 additions & 1 deletion lib/port.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ def self.parse(port_id)

attr_reader :dpid
attr_reader :port_no
alias_method :number, :port_no

def initialize(attrs)
@attrs = attrs
Expand Down
32 changes: 15 additions & 17 deletions lib/slice_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,44 @@ def start
logger.info "#{name} started."
end

# rubocop:disable MethodLength
def packet_in(_dpid, packet_in)
slice = Slice.find do |each|
each.member?(packet_in.slice_source) &&
each.member?(packet_in.slice_destination(@graph))
end
ports = if slice
out_port(slice.name, packet_in)
path = maybe_create_shortest_path_in_slice(slice.name, packet_in)
path ? [path.out_port] : []
else
external_ports(packet_in)
end
packet_out(packet_in.raw_data, ports)
end
# rubocop:enable MethodLength

private

def packet_out(raw_data, ports)
ports.each do |each|
send_packet_out(each.dpid,
raw_data: packet_in.raw_data,
raw_data: raw_data,
actions: SendOutPort.new(each.port_no))
end
end

private

def maybe_create_shortest_path_in_slice(slice_name, packet_in)
path = maybe_create_shortest_path(packet_in)
return unless path
path.slice = slice_name
path
end

def out_port(slice_name, packet_in)
path = maybe_create_shortest_path_in_slice(slice_name, packet_in)
return [] unless path
[path.out_port]
end

def external_ports(packet_in)
Slice.all.map do |each|
if each.member?(packet_in.slice_source)
external_ports_in_slice(each, packet_in.source_mac)
else
[]
end
end.flatten
Slice.all.each_with_object([]) do |each, ports|
next unless each.member?(packet_in.slice_source)
ports.concat external_ports_in_slice(each, packet_in.source_mac)
end
end

def external_ports_in_slice(slice, packet_in_mac)
Expand Down

0 comments on commit a34e8fb

Please sign in to comment.