From ca07b47575973d1e412a65770ebfb4f4dba2440d Mon Sep 17 00:00:00 2001 From: Eishun Kondoh Date: Sun, 28 Apr 2019 14:18:51 +0900 Subject: [PATCH] quality: Add test cases for get_config messages --- lib/openflow/get_config.ex | 2 -- lib/openflow/get_config/reply.ex | 13 +++++++++++++ lib/openflow/get_config/request.ex | 23 ++++++++++++++--------- mix.exs | 3 +-- test/ofp_get_config_test.exs | 5 +---- 5 files changed, 29 insertions(+), 17 deletions(-) delete mode 100644 lib/openflow/get_config.ex diff --git a/lib/openflow/get_config.ex b/lib/openflow/get_config.ex deleted file mode 100644 index ceb38e2..0000000 --- a/lib/openflow/get_config.ex +++ /dev/null @@ -1,2 +0,0 @@ -defmodule Openflow.GetConfig do -end diff --git a/lib/openflow/get_config/reply.ex b/lib/openflow/get_config/reply.ex index 55f08ff..12712b5 100644 --- a/lib/openflow/get_config/reply.ex +++ b/lib/openflow/get_config/reply.ex @@ -11,6 +11,19 @@ defmodule Openflow.GetConfig.Reply do alias __MODULE__ + @type flags :: [:drop | :reasm] + @type max_len :: :max | :no_buffer | 0..0xFFFF + + @type t :: %Reply{ + version: 4, + xid: 0..0xFFFFFFFF, + datapath_id: String.t() | nil, + aux_id: 0..0xF | nil, + flags: flags(), + miss_send_len: max_len() + } + + @spec ofp_type() :: t() def ofp_type, do: 8 def read(<>) do diff --git a/lib/openflow/get_config/request.ex b/lib/openflow/get_config/request.ex index f5ec984..bccd0cb 100644 --- a/lib/openflow/get_config/request.ex +++ b/lib/openflow/get_config/request.ex @@ -10,17 +10,22 @@ defmodule Openflow.GetConfig.Request do alias __MODULE__ + @type t :: %Request{ + version: 4, + xid: 0..0xFFFFFFFF, + datapath_id: String.t() | nil, + aux_id: non_neg_integer() | nil + } + + @spec ofp_type() :: 7 def ofp_type, do: 7 - def new(xid \\ 0) do - %Request{xid: xid} - end + @spec new(xid :: 0..0xFFFFFFFF) :: t() + def new(xid \\ 0), do: %Request{xid: xid} - def read(_) do - %Request{} - end + @spec read(any()) :: t() + def read(_), do: %Request{} - def to_binary(%Request{}) do - <<>> - end + @spec to_binary(t()) :: <<>> + def to_binary(%Request{}), do: <<>> end diff --git a/mix.exs b/mix.exs index ed99616..4def777 100644 --- a/mix.exs +++ b/mix.exs @@ -11,10 +11,9 @@ defmodule Tres.Mixfile do deps: deps(), aliases: [ test: [ - "compile", "test --no-start" ], - compile: [ + generate_enum: [ "run priv/openflow_enum_gen.exs" ] ], diff --git a/test/ofp_get_config_test.exs b/test/ofp_get_config_test.exs index 9c51812..720ebe1 100644 --- a/test/ofp_get_config_test.exs +++ b/test/ofp_get_config_test.exs @@ -28,10 +28,7 @@ defmodule OfpGetConfigTest do describe "Openflow.to_binary/1" do test "with %Openflow.GetConfig.Request{}" do - config = %Openflow.GetConfig.Request{ - version: 4, - xid: 0 - } + config = Openflow.GetConfig.Request.new(0) expect = "test/packet_data/ofp_get_config_request.raw"