quality: Add test cases for openflow actions

This commit is contained in:
Eishun Kondoh 2019-04-22 20:47:52 +09:00
parent 84a827eea1
commit d2a6488f79
9 changed files with 112 additions and 22 deletions

View file

@ -11,7 +11,8 @@ defmodule Openflow.Action.NxConjunction do
alias __MODULE__
alias Openflow.Action.Experimenter
def new(options \\ []) do
@spec new(Keyword.t()) :: %NxConjunction{}
def new(options) do
n_clauses = options[:n_clauses] || raise "n_clauses must be specified"
n_clauses >= 2 || raise "n_clauses must be greater than 1"

View file

@ -11,6 +11,20 @@ defmodule Openflow.Action.NxController do
alias __MODULE__
alias Openflow.Action.Experimenter
@type max_len :: :max | :no_buffer | non_neg_integer()
@type packet_in_reason ::
:no_match | :action | :invalid_ttl | :action_set | :group | :packet_out
@type t :: %NxController{
max_len: max_len(),
id: non_neg_integer(),
reason: packet_in_reason()
}
@spec new(
max_len: max_len(),
id: non_neg_integer(),
reason: packet_in_reason()
) :: t()
def new(options \\ []) do
%NxController{
max_len: options[:max_len] || :no_buffer,

View file

@ -7,7 +7,10 @@ defmodule Openflow.Action.NxDecTtlCntIds do
alias __MODULE__
alias Openflow.Action.Experimenter
def new(ids \\ []) do
@type t :: %NxDecTtlCntIds{ids: [non_neg_integer()]}
@spec new(ids :: [non_neg_integer()]) :: t()
def new(ids) do
%NxDecTtlCntIds{ids: ids}
end

View file

@ -10,7 +10,8 @@ defmodule Openflow.Action.NxFinTimeout do
alias __MODULE__
alias Openflow.Action.Experimenter
def new(options \\ []) do
@spec new(Keyword.t()) :: %NxFinTimeout{}
def new(options) do
%NxFinTimeout{
idle_timeout: options[:idle_timeout] || 0,
hard_timeout: options[:hard_timeout] || 0

View file

@ -18,7 +18,8 @@ defmodule Openflow.Action.NxMultipath do
alias __MODULE__
alias Openflow.Action.Experimenter
def new(options \\ []) do
@spec new(Keyword.t()) :: %NxMultipath{}
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)

View file

@ -14,7 +14,21 @@ defmodule Openflow.Action.NxOutputReg do
alias __MODULE__
alias Openflow.Action.Experimenter
def new(options \\ []) do
@type max_len :: :no_buffer | :max | non_neg_integer()
@type t :: %NxOutputReg{
n_bits: pos_integer(),
offset: non_neg_integer(),
src_field: atom(),
max_len: max_len()
}
@spec new(
n_bits: pos_integer(),
offset: non_neg_integer(),
src_field: atom(),
max_len: max_len()
) :: t()
def new(options) do
src_field = options[:src_field] || raise "src_field must be specified"
default_n_bits = Openflow.Match.Field.n_bits_of(src_field)

View file

@ -14,7 +14,21 @@ defmodule Openflow.Action.NxOutputReg2 do
alias __MODULE__
alias Openflow.Action.Experimenter
def new(options \\ []) do
@type max_len :: :no_buffer | :max | non_neg_integer()
@type t :: %NxOutputReg2{
n_bits: pos_integer(),
offset: non_neg_integer(),
src_field: atom(),
max_len: max_len()
}
@spec new(
n_bits: pos_integer(),
offset: non_neg_integer(),
src_field: atom(),
max_len: max_len()
) :: t()
def new(options) do
src_field = options[:src_field] || raise "src_field must be specified"
default_n_bits = Openflow.Match.Field.n_bits_of(src_field)

View file

@ -10,7 +10,8 @@ defmodule Openflow.Action.NxOutputTrunc do
alias __MODULE__
alias Openflow.Action.Experimenter
def new(options \\ []) do
@spec new(Keyword.t()) :: %NxOutputTrunc{}
def new(options) do
port_no = options[:port_no] || raise "port_no must be specified"
max_len = options[:max_len] || raise "max_len must be specified"