quality: Add test cases for get_config messages

This commit is contained in:
Eishun Kondoh 2019-04-28 14:18:51 +09:00
parent c592d9f7c5
commit ca07b47575
5 changed files with 29 additions and 17 deletions

View file

@ -1,2 +0,0 @@
defmodule Openflow.GetConfig do
end

View file

@ -11,6 +11,19 @@ defmodule Openflow.GetConfig.Reply do
alias __MODULE__ 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 ofp_type, do: 8
def read(<<flags_int::16, miss_send_len0::16>>) do def read(<<flags_int::16, miss_send_len0::16>>) do

View file

@ -10,17 +10,22 @@ defmodule Openflow.GetConfig.Request do
alias __MODULE__ 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 ofp_type, do: 7
def new(xid \\ 0) do @spec new(xid :: 0..0xFFFFFFFF) :: t()
%Request{xid: xid} def new(xid \\ 0), do: %Request{xid: xid}
end
def read(_) do @spec read(any()) :: t()
%Request{} def read(_), do: %Request{}
end
def to_binary(%Request{}) do @spec to_binary(t()) :: <<>>
<<>> def to_binary(%Request{}), do: <<>>
end
end end

View file

@ -11,10 +11,9 @@ defmodule Tres.Mixfile do
deps: deps(), deps: deps(),
aliases: [ aliases: [
test: [ test: [
"compile",
"test --no-start" "test --no-start"
], ],
compile: [ generate_enum: [
"run priv/openflow_enum_gen.exs" "run priv/openflow_enum_gen.exs"
] ]
], ],

View file

@ -28,10 +28,7 @@ defmodule OfpGetConfigTest do
describe "Openflow.to_binary/1" do describe "Openflow.to_binary/1" do
test "with %Openflow.GetConfig.Request{}" do test "with %Openflow.GetConfig.Request{}" do
config = %Openflow.GetConfig.Request{ config = Openflow.GetConfig.Request.new(0)
version: 4,
xid: 0
}
expect = expect =
"test/packet_data/ofp_get_config_request.raw" "test/packet_data/ofp_get_config_request.raw"