tres/secure_channel: Fix the exception handler

This commit is contained in:
Eishun Kondoh 2019-06-06 15:20:30 +09:00
parent 79f08f992b
commit efbdc35147
2 changed files with 16 additions and 6 deletions

View file

@ -325,7 +325,12 @@ defmodule Tres.SecureChannel do
{:keep_state, %{state_data | ping_fail_count: 0}, Enum.reverse(actions)} {:keep_state, %{state_data | ping_fail_count: 0}, Enum.reverse(actions)}
end end
defp handle_packet(packet, %State{buffer: buffer} = state_data, state, actions) do defp handle_packet(
packet,
%State{buffer: buffer, datapath_id: dpid} = state_data,
state,
actions
) do
binary = <<buffer::bytes, packet::bytes>> binary = <<buffer::bytes, packet::bytes>>
case Openflow.read(binary) do case Openflow.read(binary) do
@ -337,8 +342,10 @@ defmodule Tres.SecureChannel do
{:error, :binary_too_small} -> {:error, :binary_too_small} ->
handle_packet("", %{state_data | buffer: binary}, state, actions) handle_packet("", %{state_data | buffer: binary}, state, actions)
{:error, {:malformed_packet, {_reason, st}}} -> {:error, {:malformed_packet, {reason, st}}} ->
:ok = debug("malformed packet received from #{state_data.datapath_id} stack_trace: #{st}") :ok =
debug("malformed packet #{dpid} reason: #{inspect(reason)} stack_trace: #{inspect(st)}")
handle_packet("", %{state_data | buffer: ""}, state, actions) handle_packet("", %{state_data | buffer: ""}, state, actions)
end end
end end

View file

@ -16,7 +16,7 @@ defmodule OfpSetConfigTest do
end end
test "with a flag option" do test "with a flag option" do
binary = <<0x04, 0x09, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x02, 0xff, 0xe5>> binary = <<0x04, 0x09, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x02, 0xFF, 0xE5>>
set_config = set_config =
binary binary
@ -47,8 +47,11 @@ defmodule OfpSetConfigTest do
end end
test "with a flag option" do test "with a flag option" do
binary = <<0x04, 0x09, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x02, 0xff, 0xe5>> binary = <<0x04, 0x09, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x02, 0xFF, 0xE5>>
set_config = Openflow.SetConfig.new(xid: 13, flags: [:fragment_reassemble], miss_send_len: :max)
set_config =
Openflow.SetConfig.new(xid: 13, flags: [:fragment_reassemble], miss_send_len: :max)
^binary = Openflow.to_binary(set_config) ^binary = Openflow.to_binary(set_config)
end end
end end