Merge branch 'feature/minor_fixes' into develop
This commit is contained in:
commit
5fc01a9bec
6 changed files with 39 additions and 41 deletions
|
|
@ -1071,6 +1071,7 @@ defmodule Openflow.Enums do
|
||||||
|
|
||||||
for {enum_name, enum_def} <- @enums do
|
for {enum_name, enum_def} <- @enums do
|
||||||
enum_name = to_string(enum_name)
|
enum_name = to_string(enum_name)
|
||||||
|
|
||||||
to_int_fn_name = String.to_atom(enum_name <> "_to_int")
|
to_int_fn_name = String.to_atom(enum_name <> "_to_int")
|
||||||
to_atom_fn_name = String.to_atom(enum_name <> "_to_atom")
|
to_atom_fn_name = String.to_atom(enum_name <> "_to_atom")
|
||||||
|
|
||||||
|
|
@ -1091,6 +1092,7 @@ defmodule Openflow.Enums do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_int(_int, unquote(String.to_atom(enum_name))) do
|
def to_int(_int, unquote(String.to_atom(enum_name))) do
|
||||||
throw(:bad_enum)
|
throw(:bad_enum)
|
||||||
end
|
end
|
||||||
|
|
@ -1101,9 +1103,14 @@ defmodule Openflow.Enums do
|
||||||
|
|
||||||
for {key, value} <- enum_def do
|
for {key, value} <- enum_def do
|
||||||
def unquote(to_int_fn_name)(unquote(key)), do: unquote(value)
|
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)
|
def unquote(to_atom_fn_name)(unquote(value)), do: unquote(key)
|
||||||
end
|
end
|
||||||
def unquote(to_int_fn_name)(_), do: throw(:bad_enum)
|
|
||||||
def unquote(to_atom_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
|
def int_to_flags(int, unquote(String.to_atom(enum_name))) do
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ defmodule Openflow.Features.Reply do
|
||||||
n_buffers: 0,
|
n_buffers: 0,
|
||||||
n_tables: 0,
|
n_tables: 0,
|
||||||
aux_id: 0,
|
aux_id: 0,
|
||||||
capabilities: [],
|
capabilities: []
|
||||||
)
|
)
|
||||||
|
|
||||||
alias __MODULE__
|
alias __MODULE__
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ defmodule Openflow.MeterBand.Experimenter do
|
||||||
defstruct(
|
defstruct(
|
||||||
rate: 0,
|
rate: 0,
|
||||||
burst_size: 0,
|
burst_size: 0,
|
||||||
experimenter: 0,
|
experimenter: 0
|
||||||
)
|
)
|
||||||
|
|
||||||
alias __MODULE__
|
alias __MODULE__
|
||||||
|
|
|
||||||
|
|
@ -20,20 +20,13 @@ defmodule Tres.ExampleHandler do
|
||||||
info("[#{__MODULE__}] Switch Ready: "
|
info("[#{__MODULE__}] Switch Ready: "
|
||||||
<> "datapath_id: #{datapath_id} "
|
<> "datapath_id: #{datapath_id} "
|
||||||
<> "aux_id: #{aux_id} "
|
<> "aux_id: #{aux_id} "
|
||||||
<> "in #{inspect(self())}")
|
<> "on #{inspect(self())}")
|
||||||
_ = send_flows_for_test(datapath_id)
|
|
||||||
_ = send_flow_stats_request(datapath_id)
|
|
||||||
_ = send_desc_stats_request(datapath_id)
|
_ = send_desc_stats_request(datapath_id)
|
||||||
_ = send_port_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}
|
||||||
state = %State{datapath_id: datapath_id, aux_id: aux_id, conn_ref: conn_ref}
|
|
||||||
{:ok, state}
|
{:ok, state}
|
||||||
end
|
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
|
def handle_info(%PortDesc.Reply{datapath_id: datapath_id} = desc, state) do
|
||||||
handle_port_desc_stats_reply(desc, datapath_id)
|
handle_port_desc_stats_reply(desc, datapath_id)
|
||||||
{:noreply, state}
|
{:noreply, state}
|
||||||
|
|
@ -42,13 +35,14 @@ defmodule Tres.ExampleHandler do
|
||||||
handle_desc_stats_reply(desc, datapath_id)
|
handle_desc_stats_reply(desc, datapath_id)
|
||||||
{:noreply, state}
|
{:noreply, state}
|
||||||
end
|
end
|
||||||
|
def handle_info({:switch_disconnected, reason}, state) do
|
||||||
# To prevent process leakage, following section is required.
|
:ok = warn("[#{__MODULE__}] Switch Disconnected: datapath_id: #{state.datapath_id} by #{reason}")
|
||||||
def handle_info({:'DOWN', ref, :process, _pid, _reason}, %State{conn_ref: ref} = state) do
|
|
||||||
:ok = warn("[#{__MODULE__}] Switch Disconnected: datapath_id: #{state.datapath_id}")
|
|
||||||
{:stop, :normal, state}
|
{:stop, :normal, state}
|
||||||
end
|
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.
|
# `Catch all` function is required.
|
||||||
def handle_info(info, state) do
|
def handle_info(info, state) do
|
||||||
:ok = warn("[#{__MODULE__}] unhandled message #{inspect(info)}: #{state.datapath_id}")
|
:ok = warn("[#{__MODULE__}] unhandled message #{inspect(info)}: #{state.datapath_id}")
|
||||||
|
|
@ -57,17 +51,6 @@ defmodule Tres.ExampleHandler do
|
||||||
|
|
||||||
# private functions
|
# 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
|
defp send_desc_stats_request(datapath_id) do
|
||||||
Desc.Request.new
|
Desc.Request.new
|
||||||
|> send_message(datapath_id)
|
|> send_message(datapath_id)
|
||||||
|
|
@ -78,10 +61,6 @@ defmodule Tres.ExampleHandler do
|
||||||
|> send_message(datapath_id)
|
|> send_message(datapath_id)
|
||||||
end
|
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
|
defp handle_desc_stats_reply(desc, datapath_id) do
|
||||||
info(
|
info(
|
||||||
"[#{__MODULE__}] Switch Desc: "
|
"[#{__MODULE__}] Switch Desc: "
|
||||||
|
|
|
||||||
|
|
@ -433,32 +433,46 @@ defmodule Tres.SecureChannel do
|
||||||
warn("[#{__MODULE__}] connection terminated: Features handshake timed out")
|
warn("[#{__MODULE__}] connection terminated: Features handshake timed out")
|
||||||
{:stop, :normal, %{state_data|socket: nil}}
|
{:stop, :normal, %{state_data|socket: nil}}
|
||||||
end
|
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")
|
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}}
|
{:stop, :normal, %{state_data|socket: nil}}
|
||||||
end
|
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")
|
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}}
|
{:stop, :normal, %{state_data|socket: nil}}
|
||||||
end
|
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}")
|
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}}
|
{:stop, :normal, %{state_data|socket: nil}}
|
||||||
end
|
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}")
|
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}}
|
{:stop, :normal, %{state_data|socket: nil}}
|
||||||
end
|
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}")
|
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}}
|
{:stop, :normal, %{state_data|socket: nil}}
|
||||||
end
|
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")
|
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}}
|
{:stop, :normal, %{state_data|socket: nil}}
|
||||||
end
|
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}")
|
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}}
|
{:stop, :normal, %{state_data|socket: nil}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
2
mix.exs
2
mix.exs
|
|
@ -21,8 +21,6 @@ defmodule Tres.Mixfile do
|
||||||
defp deps do
|
defp deps do
|
||||||
[{:ranch, "~> 1.4.0"},
|
[{:ranch, "~> 1.4.0"},
|
||||||
{:eovsdb, github: "shun159/eovsdb", branch: "master"},
|
{: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}]
|
{:epcap, github: "msantos/epcap", branch: "master", only: :test}]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue