quality: Add test cases for openflow actions

This commit is contained in:
Eishun Kondoh 2019-04-09 23:51:24 +09:00
parent 1cb687433c
commit d7439b435f
2 changed files with 40 additions and 3 deletions

View file

@ -20,7 +20,7 @@ defmodule Openflow.Action.NxLearn2 do
alias __MODULE__ alias __MODULE__
alias Openflow.Action.Experimenter alias Openflow.Action.Experimenter
def new(options) do def new(options \\ []) do
%NxLearn2{ %NxLearn2{
idle_timeout: options[:idle_timeout] || 0, idle_timeout: options[:idle_timeout] || 0,
hard_timeout: options[:hard_timeout] || 0, hard_timeout: options[:hard_timeout] || 0,

View file

@ -691,7 +691,7 @@ defmodule OfpActionTest do
end end
describe "Openflow.Action.NxLearn2" do describe "Openflow.Action.NxLearn2" do
test "with learn2" do test "with learn2 packet" do
test_file = "test/packet_data/nx_learn2.raw" test_file = "test/packet_data/nx_learn2.raw"
packet = File.read!(test_file) packet = File.read!(test_file)
actions = Openflow.Action.read(packet) actions = Openflow.Action.read(packet)
@ -720,6 +720,17 @@ defmodule OfpActionTest do
assert actions_bin == packet assert actions_bin == packet
assert actions == [learn2] assert actions == [learn2]
end end
test "with no options" do
learn2 = Openflow.Action.NxLearn2.new()
learn2
|> Openflow.Action.to_binary()
|> Openflow.Action.read()
|> Enum.at(0)
|> Kernel.==(learn2)
|> assert()
end
end end
describe "Openflow.Action.NxMultipath" do describe "Openflow.Action.NxMultipath" do
@ -800,6 +811,12 @@ defmodule OfpActionTest do
assert actions_bin == packet assert actions_bin == packet
assert actions == [reg_load] assert actions == [reg_load]
end end
test "with no options" do
assert_raise RuntimeError, "dst_field must be specified", fn ->
Openflow.Action.NxRegLoad.new()
end
end
end end
describe "Openflow.Action.NxRegMove" do describe "Openflow.Action.NxRegMove" do
@ -807,11 +824,31 @@ defmodule OfpActionTest do
test_file = "test/packet_data/nx_reg_move.raw" test_file = "test/packet_data/nx_reg_move.raw"
packet = File.read!(test_file) packet = File.read!(test_file)
actions = Openflow.Action.read(packet) actions = Openflow.Action.read(packet)
reg_move = Openflow.Action.NxRegMove.new(src_field: :nx_in_port, dst_field: :nx_vlan_tci)
reg_move =
Openflow.Action.NxRegMove.new(
src_field: :nx_in_port,
dst_field: :nx_vlan_tci,
src_offset: 0,
dst_offset: 0
)
actions_bin = Openflow.Action.to_binary(reg_move) actions_bin = Openflow.Action.to_binary(reg_move)
assert actions_bin == packet assert actions_bin == packet
assert actions == [reg_move] assert actions == [reg_move]
end end
test "with no options" do
assert_raise RuntimeError, "src_field must be specified", fn ->
Openflow.Action.NxRegMove.new()
end
end
test "with no dst_field options" do
assert_raise RuntimeError, "dst_field must be specified", fn ->
Openflow.Action.NxRegMove.new(src_field: :reg0)
end
end
end end
describe "Openflow.Action.NxResubmit" do describe "Openflow.Action.NxResubmit" do