quality/tres: Add handler testcases

This commit is contained in:
Eishun Kondoh 2019-05-08 01:31:27 +09:00
parent 0a6d7f31d6
commit 4965bc60ec
9 changed files with 273 additions and 98 deletions

View file

@ -43,29 +43,4 @@ defmodule Openflow.PacketIn do
data: data
}
end
def to_binary(%PacketIn{} = packet_in) do
%PacketIn{
buffer_id: buffer_id,
total_len: total_len,
reason: reason,
table_id: table_id,
cookie: cookie,
in_port: in_port,
match: match_fields,
data: data
} = packet_in
buffer_id_int = Openflow.Utils.get_enum(buffer_id, :buffer_id)
reason_int = Openflow.Utils.get_enum(reason, :packet_in_reason)
table_id_int = Openflow.Utils.get_enum(table_id, :table_id)
match_fields_bin =
[{:in_port, in_port} | match_fields]
|> Openflow.Match.new()
|> Openflow.Match.to_binary()
<<buffer_id_int::32, total_len::16, reason_int::8, table_id_int::8, cookie::64,
match_fields_bin::bytes, 0::size(2)-unit(8), data::bytes>>
end
end

View file

@ -14,19 +14,8 @@ defmodule Openflow.Role.Reply do
def ofp_type, do: 25
def new(options \\ []) do
role = Keyword.get(options, :role, :nochange)
generation_id = Keyword.get(options, :generation_id, 0)
%Reply{role: role, generation_id: generation_id}
end
def read(<<role_int::32, 0::size(4)-unit(8), generation_id::64>>) do
role = Openflow.Enums.to_atom(role_int, :controller_role)
%Reply{role: role, generation_id: generation_id}
end
def to_binary(%Reply{role: role, generation_id: generation_id}) do
role_int = Openflow.Enums.to_int(role, :controller_role)
<<role_int::32, 0::size(4)-unit(8), generation_id::64>>
end
end

View file

@ -21,11 +21,6 @@ defmodule Openflow.Role.Request do
%Request{xid: xid, role: role, generation_id: generation_id}
end
def read(<<role_int::32, 0::size(4)-unit(8), generation_id::64>>) do
role = Openflow.Enums.to_atom(role_int, :controller_role)
%Request{role: role, generation_id: generation_id}
end
def to_binary(%Request{role: role, generation_id: generation_id}) do
role_int = Openflow.Enums.to_int(role, :controller_role)
<<role_int::32, 0::size(4)-unit(8), generation_id::64>>