From efbdc35147ec39faf487146d0818e88d7ae2b392 Mon Sep 17 00:00:00 2001 From: Eishun Kondoh Date: Thu, 6 Jun 2019 15:20:30 +0900 Subject: [PATCH] tres/secure_channel: Fix the exception handler --- lib/tres/secure_channel.ex | 13 ++++++++++--- test/lib/openflow/ofp_set_config_test.exs | 9 ++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/tres/secure_channel.ex b/lib/tres/secure_channel.ex index 750ad5f..3074267 100644 --- a/lib/tres/secure_channel.ex +++ b/lib/tres/secure_channel.ex @@ -325,7 +325,12 @@ defmodule Tres.SecureChannel do {:keep_state, %{state_data | ping_fail_count: 0}, Enum.reverse(actions)} 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 = <> case Openflow.read(binary) do @@ -337,8 +342,10 @@ defmodule Tres.SecureChannel do {:error, :binary_too_small} -> handle_packet("", %{state_data | buffer: binary}, state, actions) - {:error, {:malformed_packet, {_reason, st}}} -> - :ok = debug("malformed packet received from #{state_data.datapath_id} stack_trace: #{st}") + {:error, {:malformed_packet, {reason, st}}} -> + :ok = + debug("malformed packet #{dpid} reason: #{inspect(reason)} stack_trace: #{inspect(st)}") + handle_packet("", %{state_data | buffer: ""}, state, actions) end end diff --git a/test/lib/openflow/ofp_set_config_test.exs b/test/lib/openflow/ofp_set_config_test.exs index 8eaaf68..d917ff6 100644 --- a/test/lib/openflow/ofp_set_config_test.exs +++ b/test/lib/openflow/ofp_set_config_test.exs @@ -16,7 +16,7 @@ defmodule OfpSetConfigTest do end 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 = binary @@ -47,8 +47,11 @@ defmodule OfpSetConfigTest do end test "with a flag option" do - 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) + 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) + ^binary = Openflow.to_binary(set_config) end end