quality: Add test cases for openflow actions

This commit is contained in:
Eishun Kondoh 2019-04-22 15:55:06 +09:00
parent 641d803c53
commit a5eddffb8c
4 changed files with 136 additions and 3 deletions

View file

@ -14,6 +14,32 @@ defmodule Openflow.Action.NxBundle do
alias __MODULE__
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
slaves = options[:slaves] || []

View file

@ -19,6 +19,38 @@ defmodule Openflow.Action.NxBundleLoad do
alias __MODULE__
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
dst_field = options[:dst_field] || raise "dst_field must be specified"
default_n_bits = Openflow.Match.Field.n_bits_of(dst_field)
@ -32,7 +64,7 @@ defmodule Openflow.Action.NxBundleLoad do
slaves: slaves,
offset: options[:offset] || 0,
n_bits: options[:n_bits] || default_n_bits,
dst_field: options[:dst_field]
dst_field: dst_field
}
end

View file

@ -13,12 +13,28 @@ defmodule Openflow.Action.NxFlowSpecLoad do
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
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)
%NxFlowSpecLoad{
src: options[:src],
src: src,
dst: dst,
n_bits: n_bits,
src_offset: options[:src_offset] || 0,