quality: Add testcases for table_mod, set_controller_id and resume message handlers

This commit is contained in:
Eishun Kondoh 2019-05-08 22:29:44 +09:00
parent 27cfce26b3
commit db8aa3561b
4 changed files with 40 additions and 14 deletions

11
coveralls.json Normal file
View file

@ -0,0 +1,11 @@
{
"skip_files": [
"lib/openflow/enums.ex"
],
"coverage_options": {
"output_dir": "cover/",
"template_path": "lib/templates/html/htmlcov/",
"minimum_coverage": 0
}
}

View file

@ -16,10 +16,6 @@ defmodule Openflow.NxSetControllerId do
%NxSetControllerId{id: controller_id} %NxSetControllerId{id: controller_id}
end end
def read(<<@experimenter::32, @nx_type::32, _::size(6)-unit(8), controller_id::16>>) do
%NxSetControllerId{id: controller_id}
end
def to_binary(%NxSetControllerId{id: controller_id}) do def to_binary(%NxSetControllerId{id: controller_id}) do
<<@experimenter::32, @nx_type::32, 0::size(6)-unit(8), controller_id::16>> <<@experimenter::32, @nx_type::32, 0::size(6)-unit(8), controller_id::16>>
end end

View file

@ -14,15 +14,11 @@ defmodule Openflow.TableMod do
def new(options) when is_list(options) do def new(options) when is_list(options) do
%TableMod{ %TableMod{
xid: options[:xid] || 0, xid: Keyword.get(options, :xid, 0),
table_id: options[:table_id] || 0 table_id: Keyword.get(options, :table_id, 0)
} }
end end
def new(table_id) when is_integer(table_id) or is_atom(table_id) do
%TableMod{table_id: table_id}
end
def read(<<table_id_int::8, _::size(3)-unit(8), config::32>>) do def read(<<table_id_int::8, _::size(3)-unit(8), config::32>>) do
table_id = Openflow.Utils.get_enum(table_id_int, :table_id) table_id = Openflow.Utils.get_enum(table_id_int, :table_id)
%TableMod{table_id: table_id, config: config} %TableMod{table_id: table_id, config: config}

View file

@ -1,5 +1,5 @@
defmodule Tres.HanderTest do defmodule Tres.HanderTest do
use ExUnit.Case use ExUnit.Case, async: false
@datapath_id "0000000000000001" @datapath_id "0000000000000001"
@ -16,6 +16,18 @@ defmodule Tres.HanderTest do
end end
end end
describe "Openflow TableMod message" do
test "with table_id" do
{:ok, :noreply} = sync_send_message(Openflow.TableMod.new(table_id: :all))
end
end
describe "Openflow NxSetControllerId message" do
test "with controller_id" do
{:ok, :noreply} = sync_send_message(Openflow.NxSetControllerId.new(0))
end
end
describe "Openflow Error message" do describe "Openflow Error message" do
test "with a flow" do test "with a flow" do
send_message(Openflow.FlowMod.new(match: Openflow.Match.new(arp_tpa: {10, 10, 10, 10}))) send_message(Openflow.FlowMod.new(match: Openflow.Match.new(arp_tpa: {10, 10, 10, 10})))
@ -68,20 +80,31 @@ defmodule Tres.HanderTest do
send_message( send_message(
Openflow.FlowMod.new( Openflow.FlowMod.new(
instructions: Openflow.Instruction.ApplyActions.new(Openflow.Action.NxController2.new()) priority: 0xFFFF,
match: Openflow.Match.new(in_port: 0xF, reg0: 99, eth_type: 0x0806),
instructions: Openflow.Instruction.ApplyActions.new([
Openflow.Action.NxController2.new(pause: true),
Openflow.Action.NxResubmitTable.new()
])
) )
) )
send_message( send_message(
Openflow.PacketOut.new( Openflow.PacketOut.new(
buffer_id: :no_buffer, buffer_id: :no_buffer,
in_port: :controller, in_port: 0xF,
actions: [Openflow.Action.Output.new(:controller)], actions: [
Openflow.Action.SetField.new(reg0: 99),
Openflow.Action.Output.new(:table)
],
data: File.read!("test/packet_data/arp_packet.raw") data: File.read!("test/packet_data/arp_packet.raw")
) )
) )
%Openflow.NxPacketIn2{} = packet_in2 = get_message()
{:ok, :noreply} = sync_send_message(Openflow.NxResume.new(packet_in: packet_in2))
%Openflow.NxPacketIn2{} = get_message() %Openflow.NxPacketIn2{} = get_message()
send_message(Openflow.NxSetPacketInFormat.new(:standard))
end end
end end