quality: Add test cases for flow_mod message
This commit is contained in:
parent
c2f731d38a
commit
42dd435b63
2 changed files with 88 additions and 30 deletions
|
|
@ -21,39 +21,88 @@ defmodule Openflow.FlowMod do
|
||||||
|
|
||||||
alias __MODULE__
|
alias __MODULE__
|
||||||
|
|
||||||
|
@type buffer_id :: :no_buffer | 0..0xFFFFFFFF
|
||||||
|
|
||||||
|
@type command :: :add | :modify | :modify_strict | :delete | :delete_strict
|
||||||
|
|
||||||
|
@type out_port ::
|
||||||
|
0..0xFFFFFFFF | :max | :table | :normal | :flood | :all | :controller | :local | :any
|
||||||
|
|
||||||
|
@type out_group :: 0..0xFFFFFFFF | :max | :all | :any
|
||||||
|
|
||||||
|
@type flags :: [
|
||||||
|
:send_flow_rem | :check_overlap | :reset_counts | :no_packet_counts | :no_byte_counts
|
||||||
|
]
|
||||||
|
|
||||||
|
@type t :: %FlowMod{
|
||||||
|
version: 4,
|
||||||
|
xid: 0..0xFFFFFFFF,
|
||||||
|
datapath_id: String.t() | nil,
|
||||||
|
aux_id: 0..0xF | nil,
|
||||||
|
cookie: 0..0xFFFFFFFFFFFFFFFF,
|
||||||
|
cookie_mask: 0..0xFFFFFFFFFFFFFFFF,
|
||||||
|
table_id: 0..0xF,
|
||||||
|
command: command(),
|
||||||
|
idle_timeout: 0..0xFFFF,
|
||||||
|
hard_timeout: 0..0xFFFF,
|
||||||
|
priority: 0..0xFFFF,
|
||||||
|
buffer_id: buffer_id(),
|
||||||
|
out_port: out_port(),
|
||||||
|
out_group: out_group(),
|
||||||
|
flags: flags(),
|
||||||
|
match: %Openflow.Match{},
|
||||||
|
instructions: [
|
||||||
|
%Openflow.Instruction.ApplyActions{}
|
||||||
|
| %Openflow.Instruction.WriteActions{}
|
||||||
|
| %Openflow.Instruction.ClearActions{}
|
||||||
|
| %Openflow.Instruction.GotoTable{}
|
||||||
|
| %Openflow.Instruction.Meter{}
|
||||||
|
| %Openflow.Instruction.WriteMetadata{}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
@spec ofp_type() :: 14
|
||||||
def ofp_type, do: 14
|
def ofp_type, do: 14
|
||||||
|
|
||||||
|
@spec new(
|
||||||
|
xid: 0..0xFFFFFFFF,
|
||||||
|
cookie: 0..0xFFFFFFFFFFFFFFFF,
|
||||||
|
cookie_mask: 0..0xFFFFFFFFFFFFFFFF,
|
||||||
|
table_id: 0..0xF,
|
||||||
|
command: command(),
|
||||||
|
idle_timeout: 0..0xFFFF,
|
||||||
|
hard_timeout: 0..0xFFFF,
|
||||||
|
priority: 0..0xFFFF,
|
||||||
|
buffer_id: buffer_id(),
|
||||||
|
out_port: out_port(),
|
||||||
|
out_group: out_group(),
|
||||||
|
flags: flags(),
|
||||||
|
match: %Openflow.Match{},
|
||||||
|
instructions: [
|
||||||
|
%Openflow.Instruction.ApplyActions{}
|
||||||
|
| %Openflow.Instruction.WriteActions{}
|
||||||
|
| %Openflow.Instruction.ClearActions{}
|
||||||
|
| %Openflow.Instruction.GotoTable{}
|
||||||
|
| %Openflow.Instruction.Meter{}
|
||||||
|
| %Openflow.Instruction.WriteMetadata{}
|
||||||
|
]
|
||||||
|
) :: t()
|
||||||
def new(options \\ []) do
|
def new(options \\ []) do
|
||||||
xid = Keyword.get(options, :xid, 0)
|
|
||||||
cookie = Keyword.get(options, :cookie, 0)
|
|
||||||
cookie_mask = Keyword.get(options, :cookie_mask, 0)
|
|
||||||
table_id = Keyword.get(options, :table_id, 0)
|
|
||||||
command = Keyword.get(options, :command, :add)
|
|
||||||
idle = Keyword.get(options, :idle_timeout, 0)
|
|
||||||
hard = Keyword.get(options, :hard_timeout, 0)
|
|
||||||
priority = Keyword.get(options, :priority, 0)
|
|
||||||
buffer_id = Keyword.get(options, :buffer_id, :no_buffer)
|
|
||||||
out_port = Keyword.get(options, :out_port, :any)
|
|
||||||
out_group = Keyword.get(options, :out_group, :any)
|
|
||||||
flags = Keyword.get(options, :flags, [])
|
|
||||||
match = Keyword.get(options, :match, Openflow.Match.new())
|
|
||||||
instructions = Keyword.get(options, :instructions, [])
|
|
||||||
|
|
||||||
%FlowMod{
|
%FlowMod{
|
||||||
xid: xid,
|
xid: options[:xid] || 0,
|
||||||
cookie: cookie,
|
cookie: options[:cookie] || 0,
|
||||||
cookie_mask: cookie_mask,
|
cookie_mask: options[:cookie_mask] || 0,
|
||||||
priority: priority,
|
priority: options[:priority] || 0x8000,
|
||||||
table_id: table_id,
|
table_id: options[:table_id] || 0,
|
||||||
command: command,
|
command: options[:command] || :add,
|
||||||
idle_timeout: idle,
|
idle_timeout: options[:idle_timeout] || 0,
|
||||||
hard_timeout: hard,
|
hard_timeout: options[:hard_timeout] || 0,
|
||||||
buffer_id: buffer_id,
|
buffer_id: options[:buffer_id] || :no_buffer,
|
||||||
out_port: out_port,
|
out_port: options[:out_port] || :any,
|
||||||
out_group: out_group,
|
out_group: options[:out_group] || :any,
|
||||||
flags: flags,
|
flags: options[:flags] || [],
|
||||||
match: match,
|
match: options[:match] || Openflow.Match.new(),
|
||||||
instructions: instructions
|
instructions: options[:instructions] || []
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,16 @@ defmodule OfpFlowModTest do
|
||||||
describe "Openflow.read/1" do
|
describe "Openflow.read/1" do
|
||||||
test "with OFP_FLOW_MOD packet(1)" do
|
test "with OFP_FLOW_MOD packet(1)" do
|
||||||
binary = File.read!(@flow_mod1)
|
binary = File.read!(@flow_mod1)
|
||||||
{:ok, fm, ""} = Openflow.read(binary)
|
|
||||||
|
fm =
|
||||||
|
binary
|
||||||
|
|> Openflow.read()
|
||||||
|
|> elem(1)
|
||||||
|
|> Map.to_list()
|
||||||
|
|> Openflow.FlowMod.new()
|
||||||
|
|> Openflow.to_binary()
|
||||||
|
|> Openflow.read()
|
||||||
|
|> elem(1)
|
||||||
|
|
||||||
assert fm.cookie == 0
|
assert fm.cookie == 0
|
||||||
assert fm.cookie_mask == 0
|
assert fm.cookie_mask == 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue