diff --git a/bin/enum_gen b/bin/enum_gen index 797cc6a..9686533 100755 Binary files a/bin/enum_gen and b/bin/enum_gen differ diff --git a/lib/tres/utils.ex b/lib/tres/utils.ex index 5bc6c12..21ed74e 100644 --- a/lib/tres/utils.ex +++ b/lib/tres/utils.ex @@ -13,21 +13,21 @@ defmodule Tres.Utils do end def start_openflow_listener do - max_connections = get_config(:max_connections, @default_max_connections) - num_acceptors = get_config(:num_acceptors, @default_num_acceptors) - port = get_config(:port, @default_openflow_port) - options = [max_connections: max_connections, num_acceptors: num_acceptors, port: port] - :ranch.start_listener(Tres, :ranch_tcp, options, @connection_manager, []) + :ranch.start_listener( + _ref = Tres, + _trasport = :ranch_tcp, + _transport_opts = transport_options(), + _protocol = @connection_manager, + _protocol_opts = [] + ) end def send_message(message, socket, transport) do - try do - packet = Openflow.to_binary(message) - transport.send(socket, packet) - catch - _class, _reason -> - error("[#{__MODULE__}] Unencodable error: #{inspect(message)}") - end + packet = Openflow.to_binary(message) + transport.send(socket, packet) + catch + _class, _reason -> + error("[#{__MODULE__}] Unencodable error: #{inspect(message)}") end def is_multipart?(message) do @@ -54,7 +54,32 @@ defmodule Tres.Utils do end # private functions + defp get_config(item, default) do Application.get_env(:tres, item, default) end + + defp transport_options do + %{ + max_connections: max_connections(), + num_acceptors: num_acceptors(), + logger: :logger, + socket_opts: socket_opts() + } + end + + defp socket_opts do + [ + port: port() + ] + end + + defp port, + do: get_config(:port, @default_openflow_port) + + defp max_connections, + do: get_config(:max_connections, @default_max_connections) + + defp num_acceptors, + do: get_config(:num_acceptors, @default_num_acceptors) end diff --git a/mix.exs b/mix.exs index 4a032a3..cd6f050 100644 --- a/mix.exs +++ b/mix.exs @@ -22,7 +22,7 @@ defmodule Tres.Mixfile do # Run "mix help deps" to learn about dependencies. defp deps do [ - {:ranch, "~> 1.4.0"}, + {:ranch, "~> 1.6.0"}, {:eovsdb, github: "shun159/eovsdb", branch: "master"}, {:jsone, github: "sile/jsone", tag: "1.4.6", override: true}, {:epcap, github: "msantos/epcap", branch: "master", only: :test} diff --git a/mix.lock b/mix.lock index 0f30620..0803ced 100644 --- a/mix.lock +++ b/mix.lock @@ -7,6 +7,6 @@ "gen_state_machine": {:hex, :gen_state_machine, "2.0.1", "85efd5a0376929c3a4246dd943e17564a2908c7ddd7acd242d84594e785d83f8", [], [], "hexpm"}, "jsone": {:git, "https://github.com/sile/jsone.git", "b23d312a5ed051ea7ad0989a9f2cb1a9c3f9a502", [tag: "1.4.6"]}, "pkt": {:git, "https://github.com/msantos/pkt.git", "ff0e9a7d28cdae941bce935602cd252cad1ea296", [branch: "master"]}, - "ranch": {:hex, :ranch, "1.4.0", "10272f95da79340fa7e8774ba7930b901713d272905d0012b06ca6d994f8826b", [:rebar3], [], "hexpm"}, + "ranch": {:hex, :ranch, "1.6.0", "92ac674645ec5dd23c6f0aeb9fff0aae1dd4e94a0af8407ff4d14f750a4cd7cf", [:rebar3], [], "hexpm"}, "uuid": {:git, "https://github.com/avtobiff/erlang-uuid.git", "585c2474afb4a597ae8c8bf6d21e5a9c73f18e0b", [tag: "v0.5.0"]}, }