quality: Add test cases for openflow actions
This commit is contained in:
parent
92bce907c0
commit
b8255f3f81
3 changed files with 113 additions and 10 deletions
|
|
@ -13,12 +13,28 @@ defmodule Openflow.Action.NxFlowSpecMatch do
|
|||
|
||||
alias __MODULE__
|
||||
|
||||
def new(options) do
|
||||
dst = options[:dst]
|
||||
@type t :: %NxFlowSpecMatch{
|
||||
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] || 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)
|
||||
|
||||
%NxFlowSpecMatch{
|
||||
src: options[:src],
|
||||
src: src,
|
||||
dst: dst,
|
||||
n_bits: n_bits,
|
||||
src_offset: options[:src_offset] || 0,
|
||||
|
|
@ -26,6 +42,7 @@ defmodule Openflow.Action.NxFlowSpecMatch do
|
|||
}
|
||||
end
|
||||
|
||||
@spec to_binary(t()) :: binary()
|
||||
def to_binary(%NxFlowSpecMatch{} = fsm) do
|
||||
%NxFlowSpecMatch{
|
||||
dst: dst_field,
|
||||
|
|
@ -48,6 +65,7 @@ defmodule Openflow.Action.NxFlowSpecMatch do
|
|||
end
|
||||
end
|
||||
|
||||
@spec read(binary()) :: {t(), binary()}
|
||||
def read(
|
||||
<<_::2, @learn_src_field::1, @learn_dst::2, n_bits::11, src_bin::4-bytes, src_ofs::16,
|
||||
dst_bin::4-bytes, dst_ofs::16, rest::bitstring>>
|
||||
|
|
|
|||
|
|
@ -10,23 +10,42 @@ defmodule Openflow.Action.NxFlowSpecOutput do
|
|||
|
||||
alias __MODULE__
|
||||
|
||||
def new(options) do
|
||||
src = options[:src]
|
||||
@type t :: %NxFlowSpecOutput{
|
||||
n_bits: non_neg_integer(),
|
||||
src: atom(),
|
||||
src_offset: non_neg_integer()
|
||||
}
|
||||
|
||||
@spec new(src: atom(), n_bits: non_neg_integer(), src_offset: non_neg_integer()) :: t()
|
||||
def new(options \\ []) do
|
||||
src = options[:src] || raise ":src must be specified"
|
||||
n_bits = options[:n_bits] || Openflow.Match.Field.n_bits_of(src)
|
||||
%NxFlowSpecOutput{n_bits: n_bits, src: src, src_offset: options[:src_offset] || 0}
|
||||
end
|
||||
|
||||
def to_binary(%NxFlowSpecOutput{n_bits: n_bits, src: src, src_offset: src_ofs}) do
|
||||
src_bin = Openflow.Match.codec_header(src)
|
||||
<<0::2, @learn_src_field::1, @learn_dst::2, n_bits::11, src_bin::4-bytes, src_ofs::16>>
|
||||
@spec to_binary(t()) :: binary()
|
||||
def to_binary(%NxFlowSpecOutput{} = flow_spec) do
|
||||
<<
|
||||
0::2,
|
||||
@learn_src_field::1,
|
||||
@learn_dst::2,
|
||||
flow_spec.n_bits::11,
|
||||
Openflow.Match.codec_header(flow_spec.src)::4-bytes,
|
||||
flow_spec.src_offset::16
|
||||
>>
|
||||
end
|
||||
|
||||
@spec read(binary()) :: {t(), binary()}
|
||||
def read(
|
||||
<<0::2, @learn_src_field::1, @learn_dst::2, n_bits::11, src_bin::4-bytes, src_ofs::16,
|
||||
rest::bitstring>>
|
||||
) do
|
||||
src = Openflow.Match.codec_header(src_bin)
|
||||
flow_spec = %NxFlowSpecOutput{n_bits: n_bits, src: src, src_offset: src_ofs}
|
||||
flow_spec = %NxFlowSpecOutput{
|
||||
n_bits: n_bits,
|
||||
src: Openflow.Match.codec_header(src_bin),
|
||||
src_offset: src_ofs
|
||||
}
|
||||
|
||||
{flow_spec, rest}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue