Fix def function order of enum macro, and more human readable disconnected handler
This commit is contained in:
parent
33d406a530
commit
fadfcd76bd
6 changed files with 39 additions and 41 deletions
|
|
@ -20,20 +20,13 @@ defmodule Tres.ExampleHandler do
|
|||
info("[#{__MODULE__}] Switch Ready: "
|
||||
<> "datapath_id: #{datapath_id} "
|
||||
<> "aux_id: #{aux_id} "
|
||||
<> "in #{inspect(self())}")
|
||||
_ = send_flows_for_test(datapath_id)
|
||||
_ = send_flow_stats_request(datapath_id)
|
||||
<> "on #{inspect(self())}")
|
||||
_ = send_desc_stats_request(datapath_id)
|
||||
_ = send_port_desc_stats_request(datapath_id)
|
||||
conn_ref = SwitchRegistry.monitor(datapath_id)
|
||||
state = %State{datapath_id: datapath_id, aux_id: aux_id, conn_ref: conn_ref}
|
||||
state = %State{datapath_id: datapath_id, aux_id: aux_id}
|
||||
{:ok, state}
|
||||
end
|
||||
|
||||
def handle_info(%Flow.Reply{datapath_id: datapath_id} = desc, state) do
|
||||
handle_flow_stats_reply(desc, datapath_id)
|
||||
{:noreply, state}
|
||||
end
|
||||
def handle_info(%PortDesc.Reply{datapath_id: datapath_id} = desc, state) do
|
||||
handle_port_desc_stats_reply(desc, datapath_id)
|
||||
{:noreply, state}
|
||||
|
|
@ -42,13 +35,14 @@ defmodule Tres.ExampleHandler do
|
|||
handle_desc_stats_reply(desc, datapath_id)
|
||||
{:noreply, state}
|
||||
end
|
||||
|
||||
# To prevent process leakage, following section is required.
|
||||
def handle_info({:'DOWN', ref, :process, _pid, _reason}, %State{conn_ref: ref} = state) do
|
||||
:ok = warn("[#{__MODULE__}] Switch Disconnected: datapath_id: #{state.datapath_id}")
|
||||
def handle_info({:switch_disconnected, reason}, state) do
|
||||
:ok = warn("[#{__MODULE__}] Switch Disconnected: datapath_id: #{state.datapath_id} by #{reason}")
|
||||
{:stop, :normal, state}
|
||||
end
|
||||
|
||||
def handle_info({:switch_hang, _datapath_id}, state) do
|
||||
:ok = warn("[#{__MODULE__}] Switch possible hang: datapath_id: #{state.datapath_id}")
|
||||
{:noreply, state}
|
||||
end
|
||||
# `Catch all` function is required.
|
||||
def handle_info(info, state) do
|
||||
:ok = warn("[#{__MODULE__}] unhandled message #{inspect(info)}: #{state.datapath_id}")
|
||||
|
|
@ -57,17 +51,6 @@ defmodule Tres.ExampleHandler do
|
|||
|
||||
# private functions
|
||||
|
||||
defp send_flows_for_test(datapath_id) do
|
||||
for count <- Range.new(1, 1024) do
|
||||
send_flow_mod_add(datapath_id, match: Match.new(metadata: count))
|
||||
end
|
||||
end
|
||||
|
||||
defp send_flow_stats_request(datapath_id) do
|
||||
Flow.Request.new
|
||||
|> send_message(datapath_id)
|
||||
end
|
||||
|
||||
defp send_desc_stats_request(datapath_id) do
|
||||
Desc.Request.new
|
||||
|> send_message(datapath_id)
|
||||
|
|
@ -78,10 +61,6 @@ defmodule Tres.ExampleHandler do
|
|||
|> send_message(datapath_id)
|
||||
end
|
||||
|
||||
defp handle_flow_stats_reply(desc, datapath_id) do
|
||||
info("[#{__MODULE__}] Switch #{length(desc.flows)} installed on #{datapath_id}")
|
||||
end
|
||||
|
||||
defp handle_desc_stats_reply(desc, datapath_id) do
|
||||
info(
|
||||
"[#{__MODULE__}] Switch Desc: "
|
||||
|
|
|
|||
|
|
@ -433,32 +433,46 @@ defmodule Tres.SecureChannel do
|
|||
warn("[#{__MODULE__}] connection terminated: Features handshake timed out")
|
||||
{:stop, :normal, %{state_data|socket: nil}}
|
||||
end
|
||||
defp close_connection(:handler_error, state_data) do
|
||||
defp close_connection(:handler_error = disconnected_reason, state_data) do
|
||||
warn("[#{__MODULE__}] connection terminated: Got handler error")
|
||||
%State{handler_pid: handler_pid} = state_data
|
||||
send(handler_pid, {:switch_disconnected, disconnected_reason})
|
||||
{:stop, :normal, %{state_data|socket: nil}}
|
||||
end
|
||||
defp close_connection(:ping_failed, state_data) do
|
||||
defp close_connection(:ping_failed = disconnected_reason, state_data) do
|
||||
warn("[#{__MODULE__}] connection terminated: Exceeded to max_ping_fail_count")
|
||||
%State{handler_pid: handler_pid} = state_data
|
||||
send(handler_pid, {:switch_disconnected, disconnected_reason})
|
||||
{:stop, :normal, %{state_data|socket: nil}}
|
||||
end
|
||||
defp close_connection({:main_closed, reason}, state_data) do
|
||||
defp close_connection({:main_closed = disconnected_reason, reason}, state_data) do
|
||||
warn("[#{__MODULE__}] connection terminated: Main connection down by #{reason}")
|
||||
%State{handler_pid: handler_pid} = state_data
|
||||
send(handler_pid, {:switch_disconnected, disconnected_reason})
|
||||
{:stop, :normal, %{state_data|socket: nil}}
|
||||
end
|
||||
defp close_connection({:handler_down, reason}, state_data) do
|
||||
defp close_connection({:handler_down = disconnected_reason, reason}, state_data) do
|
||||
warn("[#{__MODULE__}] connection terminated: Handler process down by #{reason}")
|
||||
%State{handler_pid: handler_pid} = state_data
|
||||
send(handler_pid, {:switch_disconnected, disconnected_reason})
|
||||
{:stop, :normal, %{state_data|socket: nil}}
|
||||
end
|
||||
defp close_connection({:trap_detected, reason}, state_data) do
|
||||
defp close_connection({:trap_detected = disconnected_reason, reason}, state_data) do
|
||||
warn("[#{__MODULE__}] connection terminated: Trapped by #{reason}")
|
||||
%State{handler_pid: handler_pid} = state_data
|
||||
send(handler_pid, {:switch_disconnected, disconnected_reason})
|
||||
{:stop, :normal, %{state_data|socket: nil}}
|
||||
end
|
||||
defp close_connection(:tcp_closed, state_data) do
|
||||
defp close_connection(:tcp_closed = disconnected_reason, state_data) do
|
||||
warn("[#{__MODULE__}] connection terminated: TCP Closed by peer")
|
||||
%State{handler_pid: handler_pid} = state_data
|
||||
send(handler_pid, {:switch_disconnected, disconnected_reason})
|
||||
{:stop, :normal, %{state_data|socket: nil}}
|
||||
end
|
||||
defp close_connection({:tcp_error, reason}, state_data) do
|
||||
defp close_connection({:tcp_error, reason} = disconnected_reason, state_data) do
|
||||
warn("[#{__MODULE__}] connection terminated: TCP Error occured: #{reason}")
|
||||
%State{handler_pid: handler_pid} = state_data
|
||||
send(handler_pid, {:switch_disconnected, disconnected_reason})
|
||||
{:stop, :normal, %{state_data|socket: nil}}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue