diff --git a/lib/path.rb b/lib/path.rb index 8732c5e..d2a7442 100644 --- a/lib/path.rb +++ b/lib/path.rb @@ -37,6 +37,10 @@ def out_port path.last end + def length + path.length / 2 + end + private def flows @@ -44,6 +48,7 @@ def flows end def flow_mod_add_to_each_switch + return if path.length == 1 path.each_slice(2) do |in_port, out_port| send_flow_mod_add(out_port.dpid, hard_timeout: 60, @@ -53,6 +58,7 @@ def flow_mod_add_to_each_switch end def flow_mod_delete_to_each_switch + return if path.length == 1 path.each_slice(2) do |in_port, out_port| send_flow_mod_delete(out_port.dpid, match: exact_match(in_port.number), @@ -65,6 +71,6 @@ def exact_match(in_port) end def path - @full_path[1..-2] + @full_path.length > 1 ? @full_path[1..-2] : @full_path end end diff --git a/lib/path_manager.rb b/lib/path_manager.rb index d6d6fc9..d309e05 100644 --- a/lib/path_manager.rb +++ b/lib/path_manager.rb @@ -13,7 +13,13 @@ def start # This method smells of :reek:FeatureEnvy but ignores them def packet_in(_dpid, message) path = maybe_create_shortest_path(message) - ports = path ? [path.out_port] : external_ports + + unless path.nil? + ports = path.length >= 1 ? [path.out_port] : @graph[path.out_port] + else + ports = external_ports + end + ports.each do |each| send_packet_out(each.dpid, raw_data: message.raw_data,