quality: Add test cases for openflow actions
This commit is contained in:
parent
462905a13d
commit
2c0a283932
4 changed files with 136 additions and 3 deletions
|
|
@ -14,6 +14,32 @@ defmodule Openflow.Action.NxBundle do
|
||||||
alias __MODULE__
|
alias __MODULE__
|
||||||
alias Openflow.Action.Experimenter
|
alias Openflow.Action.Experimenter
|
||||||
|
|
||||||
|
@type algorithm :: :active_backup | :highest_random_weight
|
||||||
|
@type hash_field ::
|
||||||
|
:eth_src
|
||||||
|
| :symmetric_l4
|
||||||
|
| :symmetric_l3l4
|
||||||
|
| :symmetric_l3l4_udp
|
||||||
|
| :nw_src
|
||||||
|
| :nw_dst
|
||||||
|
|
||||||
|
@type t :: %NxBundle{
|
||||||
|
algorithm: algorithm(),
|
||||||
|
hash_field: hash_field(),
|
||||||
|
basis: non_neg_integer(),
|
||||||
|
slave_type: :nx_in_port,
|
||||||
|
n_slaves: non_neg_integer(),
|
||||||
|
slaves: [pos_integer()]
|
||||||
|
}
|
||||||
|
|
||||||
|
@spec new(
|
||||||
|
algorithm: algorithm(),
|
||||||
|
hash_field: hash_field(),
|
||||||
|
basis: non_neg_integer(),
|
||||||
|
slave_type: :nx_in_port,
|
||||||
|
n_slaves: non_neg_integer(),
|
||||||
|
slaves: [pos_integer()]
|
||||||
|
) :: t()
|
||||||
def new(options \\ []) do
|
def new(options \\ []) do
|
||||||
slaves = options[:slaves] || []
|
slaves = options[:slaves] || []
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,38 @@ defmodule Openflow.Action.NxBundleLoad do
|
||||||
alias __MODULE__
|
alias __MODULE__
|
||||||
alias Openflow.Action.Experimenter
|
alias Openflow.Action.Experimenter
|
||||||
|
|
||||||
|
@type algorithm :: :active_backup | :highest_random_weight
|
||||||
|
@type hash_field ::
|
||||||
|
:eth_src
|
||||||
|
| :symmetric_l4
|
||||||
|
| :symmetric_l3l4
|
||||||
|
| :symmetric_l3l4_udp
|
||||||
|
| :nw_src
|
||||||
|
| :nw_dst
|
||||||
|
|
||||||
|
@type t :: %NxBundleLoad{
|
||||||
|
algorithm: algorithm(),
|
||||||
|
hash_field: hash_field(),
|
||||||
|
basis: non_neg_integer(),
|
||||||
|
slave_type: :nx_in_port,
|
||||||
|
n_slaves: non_neg_integer(),
|
||||||
|
slaves: [pos_integer()],
|
||||||
|
offset: non_neg_integer(),
|
||||||
|
n_bits: pos_integer(),
|
||||||
|
dst_field: atom()
|
||||||
|
}
|
||||||
|
|
||||||
|
@spec new(
|
||||||
|
algorithm: algorithm(),
|
||||||
|
hash_field: hash_field(),
|
||||||
|
basis: non_neg_integer(),
|
||||||
|
slave_type: :nx_in_port,
|
||||||
|
n_slaves: non_neg_integer(),
|
||||||
|
slaves: [pos_integer()],
|
||||||
|
offset: non_neg_integer(),
|
||||||
|
n_bits: pos_integer(),
|
||||||
|
dst_field: atom()
|
||||||
|
) :: t()
|
||||||
def new(options \\ []) do
|
def new(options \\ []) do
|
||||||
dst_field = options[:dst_field] || raise "dst_field must be specified"
|
dst_field = options[:dst_field] || raise "dst_field must be specified"
|
||||||
default_n_bits = Openflow.Match.Field.n_bits_of(dst_field)
|
default_n_bits = Openflow.Match.Field.n_bits_of(dst_field)
|
||||||
|
|
@ -32,7 +64,7 @@ defmodule Openflow.Action.NxBundleLoad do
|
||||||
slaves: slaves,
|
slaves: slaves,
|
||||||
offset: options[:offset] || 0,
|
offset: options[:offset] || 0,
|
||||||
n_bits: options[:n_bits] || default_n_bits,
|
n_bits: options[:n_bits] || default_n_bits,
|
||||||
dst_field: options[:dst_field]
|
dst_field: dst_field
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,28 @@ defmodule Openflow.Action.NxFlowSpecLoad do
|
||||||
|
|
||||||
alias __MODULE__
|
alias __MODULE__
|
||||||
|
|
||||||
|
@type t :: %NxFlowSpecLoad{
|
||||||
|
src: atom(),
|
||||||
|
dst: atom(),
|
||||||
|
n_bits: non_neg_integer(),
|
||||||
|
src_offset: non_neg_integer(),
|
||||||
|
dst_offset: non_neg_integer()
|
||||||
|
}
|
||||||
|
|
||||||
|
@spec new(
|
||||||
|
src: atom(),
|
||||||
|
dst: atom(),
|
||||||
|
n_bits: non_neg_integer(),
|
||||||
|
src_offset: non_neg_integer(),
|
||||||
|
dst_offset: non_neg_integer()
|
||||||
|
) :: t()
|
||||||
def new(options) do
|
def new(options) do
|
||||||
dst = options[:dst]
|
dst = options[:dst] || raise(":dst must be specified")
|
||||||
|
src = options[:src] || raise(":src must be specified")
|
||||||
n_bits = options[:n_bits] || Openflow.Match.Field.n_bits_of(dst)
|
n_bits = options[:n_bits] || Openflow.Match.Field.n_bits_of(dst)
|
||||||
|
|
||||||
%NxFlowSpecLoad{
|
%NxFlowSpecLoad{
|
||||||
src: options[:src],
|
src: src,
|
||||||
dst: dst,
|
dst: dst,
|
||||||
n_bits: n_bits,
|
n_bits: n_bits,
|
||||||
src_offset: options[:src_offset] || 0,
|
src_offset: options[:src_offset] || 0,
|
||||||
|
|
|
||||||
|
|
@ -178,6 +178,8 @@ defmodule OfpActionTest do
|
||||||
bundle =
|
bundle =
|
||||||
Openflow.Action.NxBundle.new(
|
Openflow.Action.NxBundle.new(
|
||||||
algorithm: :highest_random_weight,
|
algorithm: :highest_random_weight,
|
||||||
|
hash_field: :eth_src,
|
||||||
|
basis: 0,
|
||||||
slaves: [4, 8]
|
slaves: [4, 8]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -185,6 +187,15 @@ defmodule OfpActionTest do
|
||||||
assert actions_bin == packet
|
assert actions_bin == packet
|
||||||
assert actions == [bundle]
|
assert actions == [bundle]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "with no option" do
|
||||||
|
bundle = Openflow.Action.NxBundle.new()
|
||||||
|
assert bundle.algorithm == :active_backup
|
||||||
|
assert bundle.hash_field == :eth_src
|
||||||
|
assert bundle.basis == 0
|
||||||
|
assert bundle.n_slaves == 0
|
||||||
|
assert bundle.slaves == []
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "Openflow.Action.NxBundleLoad" do
|
describe "Openflow.Action.NxBundleLoad" do
|
||||||
|
|
@ -196,7 +207,10 @@ defmodule OfpActionTest do
|
||||||
bundle_load =
|
bundle_load =
|
||||||
Openflow.Action.NxBundleLoad.new(
|
Openflow.Action.NxBundleLoad.new(
|
||||||
algorithm: :highest_random_weight,
|
algorithm: :highest_random_weight,
|
||||||
|
hash_field: :eth_src,
|
||||||
|
basis: 0,
|
||||||
slaves: [4, 8],
|
slaves: [4, 8],
|
||||||
|
offset: 0,
|
||||||
dst_field: :reg0
|
dst_field: :reg0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -769,6 +783,8 @@ defmodule OfpActionTest do
|
||||||
Openflow.Action.NxFlowSpecMatch.new(
|
Openflow.Action.NxFlowSpecMatch.new(
|
||||||
src: :in_port,
|
src: :in_port,
|
||||||
dst: :reg0,
|
dst: :reg0,
|
||||||
|
src_offset: 0,
|
||||||
|
dst_offset: 0,
|
||||||
n_bits: 16
|
n_bits: 16
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -799,6 +815,49 @@ defmodule OfpActionTest do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "Openflow.Action.NxFlowSpecLoad" do
|
||||||
|
test "with src = 0xdeadbeef and dst: :reg0" do
|
||||||
|
flow_spec = Openflow.Action.NxFlowSpecLoad.new(src: 0xDEADBEEF, dst: :reg0)
|
||||||
|
|
||||||
|
flow_spec
|
||||||
|
|> Openflow.Action.NxFlowSpec.to_binary()
|
||||||
|
|> Openflow.Action.NxFlowSpec.read()
|
||||||
|
|> Enum.at(0)
|
||||||
|
|> Kernel.==(flow_spec)
|
||||||
|
|> assert()
|
||||||
|
end
|
||||||
|
|
||||||
|
test "with src = :in_port and dst: :reg0" do
|
||||||
|
flow_spec =
|
||||||
|
Openflow.Action.NxFlowSpecLoad.new(
|
||||||
|
src: :in_port,
|
||||||
|
dst: :reg0,
|
||||||
|
src_offset: 0,
|
||||||
|
dst_offset: 0,
|
||||||
|
n_bits: 16
|
||||||
|
)
|
||||||
|
|
||||||
|
flow_spec
|
||||||
|
|> Openflow.Action.NxFlowSpec.to_binary()
|
||||||
|
|> Openflow.Action.NxFlowSpec.read()
|
||||||
|
|> Enum.at(0)
|
||||||
|
|> Kernel.==(flow_spec)
|
||||||
|
|> assert()
|
||||||
|
end
|
||||||
|
|
||||||
|
test "with no dst option" do
|
||||||
|
assert_raise RuntimeError, ":dst must be specified", fn ->
|
||||||
|
Openflow.Action.NxFlowSpecLoad.new(src: :in_port)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "with no src option" do
|
||||||
|
assert_raise RuntimeError, ":src must be specified", fn ->
|
||||||
|
Openflow.Action.NxFlowSpecLoad.new(dst: :reg0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "Openflow.Action.NxMultipath" do
|
describe "Openflow.Action.NxMultipath" do
|
||||||
test "with multipath" do
|
test "with multipath" do
|
||||||
test_file = "test/packet_data/nx_multipath.raw"
|
test_file = "test/packet_data/nx_multipath.raw"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue