Add testcases for Openflow13 standard actions
This commit is contained in:
parent
ffcba91395
commit
44670cfbce
4 changed files with 177 additions and 4 deletions
|
|
@ -8,13 +8,15 @@ defmodule Openflow.Action.Output do
|
||||||
|
|
||||||
def ofpat, do: 0
|
def ofpat, do: 0
|
||||||
|
|
||||||
|
def new(options \\ [])
|
||||||
|
|
||||||
def new(port) when not is_list(port) do
|
def new(port) when not is_list(port) do
|
||||||
new(port_number: port)
|
new(port_number: port)
|
||||||
end
|
end
|
||||||
|
|
||||||
def new(options) when is_list(options) do
|
def new(options) when is_list(options) do
|
||||||
port_no = Keyword.get(options, :port_number)
|
port_no = options[:port_number] || raise "port_number must be specified"
|
||||||
max_len = Keyword.get(options, :max_len, :no_buffer)
|
max_len = options[:max_len] || :no_buffer
|
||||||
%Output{port_number: port_no, max_len: max_len}
|
%Output{port_number: port_no, max_len: max_len}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,11 @@ defmodule Openflow.Action.PopMpls do
|
||||||
|
|
||||||
alias __MODULE__
|
alias __MODULE__
|
||||||
|
|
||||||
|
@eth_p_mpls_uc 0x8847
|
||||||
|
|
||||||
def ofpat, do: 20
|
def ofpat, do: 20
|
||||||
|
|
||||||
def new(ethertype) do
|
def new(ethertype \\ @eth_p_mpls_uc) do
|
||||||
%PopMpls{ethertype: ethertype}
|
%PopMpls{ethertype: ethertype}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
defmodule Openflow.Action.PushMpls do
|
defmodule Openflow.Action.PushMpls do
|
||||||
defstruct(ethertype: 0x8847)
|
defstruct(ethertype: 0x8847)
|
||||||
|
|
||||||
|
@eth_p_mpls_uc 0x8847
|
||||||
|
|
||||||
alias __MODULE__
|
alias __MODULE__
|
||||||
|
|
||||||
def ofpat, do: 19
|
def ofpat, do: 19
|
||||||
|
|
||||||
def new(ethertype) do
|
def new(ethertype \\ @eth_p_mpls_uc) do
|
||||||
%PushMpls{ethertype: ethertype}
|
%PushMpls{ethertype: ethertype}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,173 @@ defmodule OfpActionTest do
|
||||||
use ExUnit.Case
|
use ExUnit.Case
|
||||||
doctest Openflow
|
doctest Openflow
|
||||||
|
|
||||||
|
describe "Openflow.Action.Output" do
|
||||||
|
test "with output:1" do
|
||||||
|
output = Openflow.Action.Output.new(1)
|
||||||
|
|
||||||
|
output
|
||||||
|
|> Openflow.Action.to_binary()
|
||||||
|
|> Openflow.Action.read()
|
||||||
|
|> Enum.at(0)
|
||||||
|
|> Kernel.==(output)
|
||||||
|
|> assert()
|
||||||
|
end
|
||||||
|
|
||||||
|
test "with CONTROLLER:65509" do
|
||||||
|
output = Openflow.Action.Output.new(port_number: :controller, max_len: :max)
|
||||||
|
|
||||||
|
output
|
||||||
|
|> Openflow.Action.to_binary()
|
||||||
|
|> Openflow.Action.read()
|
||||||
|
|> Enum.at(0)
|
||||||
|
|> Kernel.==(output)
|
||||||
|
|> assert()
|
||||||
|
end
|
||||||
|
|
||||||
|
test "with no port_number option" do
|
||||||
|
assert_raise RuntimeError, "port_number must be specified", fn ->
|
||||||
|
Openflow.Action.Output.new()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "Openflow.Action.DecMplsTtl" do
|
||||||
|
test "with no options" do
|
||||||
|
dec_mpls_ttl = Openflow.Action.DecMplsTtl.new()
|
||||||
|
|
||||||
|
dec_mpls_ttl
|
||||||
|
|> Openflow.Action.to_binary()
|
||||||
|
|> Openflow.Action.read()
|
||||||
|
|> Enum.at(0)
|
||||||
|
|> Kernel.==(dec_mpls_ttl)
|
||||||
|
|> assert()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "Openflow.Action.PushVlan" do
|
||||||
|
test "with no options" do
|
||||||
|
push_vlan = Openflow.Action.PushVlan.new()
|
||||||
|
|
||||||
|
push_vlan
|
||||||
|
|> Openflow.Action.to_binary()
|
||||||
|
|> Openflow.Action.read()
|
||||||
|
|> Enum.at(0)
|
||||||
|
|> Kernel.==(push_vlan)
|
||||||
|
|> assert()
|
||||||
|
end
|
||||||
|
|
||||||
|
test "with an ethertype" do
|
||||||
|
push_vlan = Openflow.Action.PushVlan.new(0x8100)
|
||||||
|
|
||||||
|
push_vlan
|
||||||
|
|> Openflow.Action.to_binary()
|
||||||
|
|> Openflow.Action.read()
|
||||||
|
|> Enum.at(0)
|
||||||
|
|> Kernel.==(push_vlan)
|
||||||
|
|> assert()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "Openflow.Action.PopVlan" do
|
||||||
|
test "with no options" do
|
||||||
|
pop_vlan = Openflow.Action.PopVlan.new()
|
||||||
|
|
||||||
|
pop_vlan
|
||||||
|
|> Openflow.Action.to_binary()
|
||||||
|
|> Openflow.Action.read()
|
||||||
|
|> Enum.at(0)
|
||||||
|
|> Kernel.==(pop_vlan)
|
||||||
|
|> assert()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "Openflow.Action.PushMpls" do
|
||||||
|
test "with no options" do
|
||||||
|
push_vlan = Openflow.Action.PushMpls.new()
|
||||||
|
|
||||||
|
push_vlan
|
||||||
|
|> Openflow.Action.to_binary()
|
||||||
|
|> Openflow.Action.read()
|
||||||
|
|> Enum.at(0)
|
||||||
|
|> Kernel.==(push_vlan)
|
||||||
|
|> assert()
|
||||||
|
end
|
||||||
|
|
||||||
|
test "with an ethertype" do
|
||||||
|
push_vlan = Openflow.Action.PushMpls.new(0x8847)
|
||||||
|
|
||||||
|
push_vlan
|
||||||
|
|> Openflow.Action.to_binary()
|
||||||
|
|> Openflow.Action.read()
|
||||||
|
|> Enum.at(0)
|
||||||
|
|> Kernel.==(push_vlan)
|
||||||
|
|> assert()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "Openflow.Action.PopMpls" do
|
||||||
|
test "with no options" do
|
||||||
|
pop_mpls = Openflow.Action.PopMpls.new()
|
||||||
|
|
||||||
|
pop_mpls
|
||||||
|
|> Openflow.Action.to_binary()
|
||||||
|
|> Openflow.Action.read()
|
||||||
|
|> Enum.at(0)
|
||||||
|
|> Kernel.==(pop_mpls)
|
||||||
|
|> assert()
|
||||||
|
end
|
||||||
|
|
||||||
|
test "with an ethertype" do
|
||||||
|
pop_mpls = Openflow.Action.PopMpls.new(0x8847)
|
||||||
|
|
||||||
|
pop_mpls
|
||||||
|
|> Openflow.Action.to_binary()
|
||||||
|
|> Openflow.Action.read()
|
||||||
|
|> Enum.at(0)
|
||||||
|
|> Kernel.==(pop_mpls)
|
||||||
|
|> assert()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "Openflow.Action.SetQueue" do
|
||||||
|
test "with set_queue:1" do
|
||||||
|
set_queue = Openflow.Action.SetQueue.new(1)
|
||||||
|
|
||||||
|
set_queue
|
||||||
|
|> Openflow.Action.to_binary()
|
||||||
|
|> Openflow.Action.read()
|
||||||
|
|> Enum.at(0)
|
||||||
|
|> Kernel.==(set_queue)
|
||||||
|
|> assert()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "Openflow.Action.Group" do
|
||||||
|
test "with group:1" do
|
||||||
|
group = Openflow.Action.Group.new(1)
|
||||||
|
|
||||||
|
group
|
||||||
|
|> Openflow.Action.to_binary()
|
||||||
|
|> Openflow.Action.read()
|
||||||
|
|> Enum.at(0)
|
||||||
|
|> Kernel.==(group)
|
||||||
|
|> assert()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "Openflow.Action.DecNwTtl" do
|
||||||
|
test "with dec_ttl" do
|
||||||
|
dec_nw_ttl = Openflow.Action.DecNwTtl.new()
|
||||||
|
|
||||||
|
dec_nw_ttl
|
||||||
|
|> Openflow.Action.to_binary()
|
||||||
|
|> Openflow.Action.read()
|
||||||
|
|> Enum.at(0)
|
||||||
|
|> Kernel.==(dec_nw_ttl)
|
||||||
|
|> assert()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "Openflow.Action.NxBundle" do
|
describe "Openflow.Action.NxBundle" do
|
||||||
test "with a binary" do
|
test "with a binary" do
|
||||||
test_file = "test/packet_data/nx_bundle.raw"
|
test_file = "test/packet_data/nx_bundle.raw"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue