Merge branch 'feature/minor_fixes' into develop

This commit is contained in:
Eishun Kondoh 2018-01-30 22:39:42 +09:00
commit 5fc01a9bec
6 changed files with 39 additions and 41 deletions

View file

@ -1071,6 +1071,7 @@ defmodule Openflow.Enums do
for {enum_name, enum_def} <- @enums do
enum_name = to_string(enum_name)
to_int_fn_name = String.to_atom(enum_name <> "_to_int")
to_atom_fn_name = String.to_atom(enum_name <> "_to_atom")
@ -1091,6 +1092,7 @@ defmodule Openflow.Enums do
end
end
end
def to_int(_int, unquote(String.to_atom(enum_name))) do
throw(:bad_enum)
end
@ -1101,9 +1103,14 @@ defmodule Openflow.Enums do
for {key, value} <- enum_def do
def unquote(to_int_fn_name)(unquote(key)), do: unquote(value)
end
def unquote(to_int_fn_name)(_), do: throw(:bad_enum)
for {key, value} <- enum_def do
def unquote(to_atom_fn_name)(unquote(value)), do: unquote(key)
end
def unquote(to_int_fn_name)(_), do: throw(:bad_enum)
def unquote(to_atom_fn_name)(_), do: throw(:bad_enum)
def int_to_flags(int, unquote(String.to_atom(enum_name))) do

View file

@ -6,7 +6,7 @@ defmodule Openflow.Features.Reply do
n_buffers: 0,
n_tables: 0,
aux_id: 0,
capabilities: [],
capabilities: []
)
alias __MODULE__

View file

@ -2,7 +2,7 @@ defmodule Openflow.MeterBand.Experimenter do
defstruct(
rate: 0,
burst_size: 0,
experimenter: 0,
experimenter: 0
)
alias __MODULE__

View file

@ -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: "

View file

@ -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

View file

@ -21,8 +21,6 @@ defmodule Tres.Mixfile do
defp deps do
[{:ranch, "~> 1.4.0"},
{:eovsdb, github: "shun159/eovsdb", branch: "master"},
{:binpp, github: "jtendo/binpp", branch: "master"},
{:pkt, github: "msantos/pkt", ref: "3afb196", only: :test, override: true},
{:epcap, github: "msantos/epcap", branch: "master", only: :test}]
end
end