openflow/actions: Add nx_check_pkt_larger (#17)

this action available since post-2.11
This commit is contained in:
Eishun Kondoh 2019-07-22 20:14:42 +09:00 committed by GitHub
parent ccb420cbce
commit 6ce014ea91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 94 additions and 0 deletions

View file

@ -0,0 +1,46 @@
defmodule Openflow.Action.NxCheckPktLarger do
defstruct(
pkt_len: 0,
offset: 0,
dst_field: nil
)
@experimenter 0x00002320
@nxast 49
alias __MODULE__
alias Openflow.Action.Experimenter
@type t :: %NxCheckPktLarger{dst_field: atom(), pkt_len: 0..0xFFFF, offset: 0..0xFFFF}
@spec new(dst_field: atom(), pkt_len: 0..0xFFFF, offset: 0..0xFFFF) :: t()
def new(options \\ []) do
dst_field = options[:dst_field] || raise "dst_field must be specified"
pkt_len = options[:pkt_len] || raise "pkt_len must be specified"
ofs = Keyword.get(options, :offset, 0)
%NxCheckPktLarger{dst_field: dst_field, pkt_len: pkt_len, offset: ofs}
end
@spec to_binary(t()) :: binary()
def to_binary(%NxCheckPktLarger{} = pkt_larger) do
dst_field_bin = Openflow.Match.codec_header(pkt_larger.dst_field)
pkt_len = pkt_larger.pkt_len
ofs = pkt_larger.offset
Experimenter.pack_exp_header(<<
@experimenter::32,
@nxast::16,
pkt_len::16,
ofs::16,
dst_field_bin::4-bytes,
0::size(10)-unit(8)
>>)
end
@spec read(binary()) :: t()
def read(<<@experimenter::32, @nxast::16, body::bytes>>) do
<<pkt_len::16, ofs::16, dst_field_bin::4-bytes, _::bytes>> = body
dst_field = Openflow.Match.codec_header(dst_field_bin)
%NxCheckPktLarger{dst_field: dst_field, pkt_len: pkt_len, offset: ofs}
end
end

View file

@ -4417,6 +4417,12 @@ defmodule Openflow.Enums do
_class, _reason -> Openflow.Action.NxDecap _class, _reason -> Openflow.Action.NxDecap
end end
def to_int(Openflow.Action.NxCheckPktLarger, :nicira_ext_action) do
nicira_ext_action_to_int(Openflow.Action.NxCheckPktLarger)
catch
_class, _reason -> Openflow.Action.NxCheckPktLarger
end
def to_int(Openflow.Action.NxDebugRecirc, :nicira_ext_action) do def to_int(Openflow.Action.NxDebugRecirc, :nicira_ext_action) do
nicira_ext_action_to_int(Openflow.Action.NxDebugRecirc) nicira_ext_action_to_int(Openflow.Action.NxDebugRecirc)
catch catch
@ -9619,6 +9625,12 @@ defmodule Openflow.Enums do
_class, _reason -> 47 _class, _reason -> 47
end end
def to_atom(0x31, :nicira_ext_action) do
nicira_ext_action_to_atom(0x31)
catch
_class, _reason -> 49
end
def to_atom(0xFF, :nicira_ext_action) do def to_atom(0xFF, :nicira_ext_action) do
nicira_ext_action_to_atom(0xFF) nicira_ext_action_to_atom(0xFF)
catch catch
@ -11888,6 +11900,7 @@ defmodule Openflow.Enums do
def nicira_ext_action_to_int(Openflow.Action.NxLearn2), do: 0x2D def nicira_ext_action_to_int(Openflow.Action.NxLearn2), do: 0x2D
def nicira_ext_action_to_int(Openflow.Action.NxEncap), do: 0x2E def nicira_ext_action_to_int(Openflow.Action.NxEncap), do: 0x2E
def nicira_ext_action_to_int(Openflow.Action.NxDecap), do: 0x2F def nicira_ext_action_to_int(Openflow.Action.NxDecap), do: 0x2F
def nicira_ext_action_to_int(Openflow.Action.NxCheckPktLarger), do: 0x31
def nicira_ext_action_to_int(Openflow.Action.NxDebugRecirc), do: 0xFF def nicira_ext_action_to_int(Openflow.Action.NxDebugRecirc), do: 0xFF
def nicira_ext_action_to_int(_), do: throw(:bad_enum) def nicira_ext_action_to_int(_), do: throw(:bad_enum)
def nicira_ext_action_to_atom(0x1), do: Openflow.Action.NxResubmit def nicira_ext_action_to_atom(0x1), do: Openflow.Action.NxResubmit
@ -11927,6 +11940,7 @@ defmodule Openflow.Enums do
def nicira_ext_action_to_atom(0x2D), do: Openflow.Action.NxLearn2 def nicira_ext_action_to_atom(0x2D), do: Openflow.Action.NxLearn2
def nicira_ext_action_to_atom(0x2E), do: Openflow.Action.NxEncap def nicira_ext_action_to_atom(0x2E), do: Openflow.Action.NxEncap
def nicira_ext_action_to_atom(0x2F), do: Openflow.Action.NxDecap def nicira_ext_action_to_atom(0x2F), do: Openflow.Action.NxDecap
def nicira_ext_action_to_atom(0x31), do: Openflow.Action.NxCheckPktLarger
def nicira_ext_action_to_atom(0xFF), do: Openflow.Action.NxDebugRecirc def nicira_ext_action_to_atom(0xFF), do: Openflow.Action.NxDebugRecirc
def nicira_ext_action_to_atom(_), do: throw(:bad_enum) def nicira_ext_action_to_atom(_), do: throw(:bad_enum)
def nx_mp_algorithm_to_int(:modulo_n), do: 0x0 def nx_mp_algorithm_to_int(:modulo_n), do: 0x0
@ -13742,6 +13756,7 @@ defmodule Openflow.Enums do
{Openflow.Action.NxLearn2, 45}, {Openflow.Action.NxLearn2, 45},
{Openflow.Action.NxEncap, 46}, {Openflow.Action.NxEncap, 46},
{Openflow.Action.NxDecap, 47}, {Openflow.Action.NxDecap, 47},
{Openflow.Action.NxCheckPktLarger, 49},
{Openflow.Action.NxDebugRecirc, 255} {Openflow.Action.NxDebugRecirc, 255}
] ]

View file

@ -117,6 +117,7 @@ defmodule Tres.Messages do
alias Openflow.Action.NxEncap alias Openflow.Action.NxEncap
alias Openflow.Action.NxDecap alias Openflow.Action.NxDecap
alias Openflow.Action.NxDebugRecirc alias Openflow.Action.NxDebugRecirc
alias Openflow.Action.NxCheckPktLarger
alias Openflow.Action.NxFlowSpecMatch alias Openflow.Action.NxFlowSpecMatch
alias Openflow.Action.NxFlowSpecLoad alias Openflow.Action.NxFlowSpecLoad

View file

@ -861,6 +861,7 @@ enums = [
{Openflow.Action.NxLearn2, 45}, {Openflow.Action.NxLearn2, 45},
{Openflow.Action.NxEncap, 46}, {Openflow.Action.NxEncap, 46},
{Openflow.Action.NxDecap, 47}, {Openflow.Action.NxDecap, 47},
{Openflow.Action.NxCheckPktLarger, 49},
{Openflow.Action.NxDebugRecirc, 0xFF} {Openflow.Action.NxDebugRecirc, 0xFF}
], ],
nx_mp_algorithm: [ nx_mp_algorithm: [

View file

@ -1017,6 +1017,37 @@ defmodule OfpActionTest do
end end
end end
describe "Openflow.Action.NxCheckPktLarger" do
test "with options: if the packet larger than 100 bytes, set mark to reg1" do
test_file = "test/packet_data/nx_check_pkt_larger.raw"
packet = File.read!(test_file)
actions = Openflow.Action.read(packet)
check_pkt_larger =
Openflow.Action.NxCheckPktLarger.new(
dst_field: :reg1,
offset: 0,
pkt_len: 100
)
actions_bin = Openflow.Action.to_binary(check_pkt_larger)
assert actions_bin == packet
assert actions == [check_pkt_larger]
end
test "with no dst_field option" do
assert_raise RuntimeError, "dst_field must be specified", fn ->
Openflow.Action.NxCheckPktLarger.new(pkt_len: 100)
end
end
test "with no pkt_len option" do
assert_raise RuntimeError, "pkt_len must be specified", fn ->
Openflow.Action.NxCheckPktLarger.new(dst_field: :reg1)
end
end
end
describe "Openflow.Action.NxRegMove" do describe "Openflow.Action.NxRegMove" do
test "with options: move in_port value to vlan_tci field" do test "with options: move in_port value to vlan_tci field" do
test_file = "test/packet_data/nx_reg_move.raw" test_file = "test/packet_data/nx_reg_move.raw"

Binary file not shown.