openflow: Fix aggregate request

This commit is contained in:
Eishun Kondoh 2019-05-01 23:54:40 +09:00
parent c5e38155e1
commit b32cfff395
22 changed files with 71 additions and 44 deletions

View file

@ -40,7 +40,7 @@ defmodule Openflow.FlowMod do
aux_id: 0..0xF | nil, aux_id: 0..0xF | nil,
cookie: 0..0xFFFFFFFFFFFFFFFF, cookie: 0..0xFFFFFFFFFFFFFFFF,
cookie_mask: 0..0xFFFFFFFFFFFFFFFF, cookie_mask: 0..0xFFFFFFFFFFFFFFFF,
table_id: 0..0xF, table_id: 0..0xFF,
command: command(), command: command(),
idle_timeout: 0..0xFFFF, idle_timeout: 0..0xFFFF,
hard_timeout: 0..0xFFFF, hard_timeout: 0..0xFFFF,

View file

@ -4,58 +4,85 @@ defmodule Openflow.Multipart.Aggregate.Request do
xid: 0, xid: 0,
# virtual field # virtual field
datapath_id: nil, datapath_id: nil,
aux_id: nil,
flags: [], flags: [],
table_id: :all, table_id: :all,
out_port: :any, out_port: :any,
out_group: :any, out_group: :any,
cookie: 0, cookie: 0,
cookie_mask: 0, cookie_mask: 0,
match: [] match: Openflow.Match.new()
) )
alias __MODULE__ alias __MODULE__
@type t :: %Request{
version: 4,
datapath_id: String.t(),
aux_id: 0..0xFF | nil,
xid: 0..0xFFFFFFFF,
table_id: 0..0xFF | :all | :max,
out_port: Openflow.Port.no(),
out_group: Openflow.GroupMod.id(),
cookie: 0..0xFFFFFFFFFFFFFFFF,
cookie_mask: 0..0xFFFFFFFFFFFFFFFF,
match: %Openflow.Match{fields: [map()], type: :oxm}
}
@spec ofp_type() :: 18
def ofp_type, do: 18 def ofp_type, do: 18
def new(options) do @spec new(
xid = Keyword.get(options, :xid, 0) version: 4,
table_id = Keyword.get(options, :table_id, :all) datapath_id: String.t(),
out_port = Keyword.get(options, :out_port, :any) aux_id: 0..0xFF | nil,
out_group = Keyword.get(options, :out_group, :any) xid: 0..0xFFFFFFFF,
cookie = Keyword.get(options, :cookie, 0) table_id: 0..0xFF | :all | :max,
cookie_mask = Keyword.get(options, :cookie, 0) out_port: Openflow.Port.no(),
match = Keyword.get(options, :match, []) out_group: Openflow.GroupMod.id(),
cookie: 0..0xFFFFFFFFFFFFFFFF,
cookie_mask: 0..0xFFFFFFFFFFFFFFFF,
match: %Openflow.Match{fields: [map()], type: :oxm}
) :: t()
def new(options \\ []) do
%Request{
xid: options[:xid] || 0,
table_id: options[:table_id] || :all,
out_port: options[:out_port] || :any,
out_group: options[:out_group] || :any,
cookie: options[:cookie] || 0,
cookie_mask: options[:cookie_mask] || 0,
match: options[:match] || Openflow.Match.new()
}
end
@spec read(<<_::256, _::_*8>>) :: t()
def read(<<
table_id_int::8,
_::size(3)-unit(8),
out_port_int::32,
out_group_int::32,
_::size(4)-unit(8),
cookie::64,
cookie_mask::64,
match_bin::bytes
>>) do
match =
match_bin
|> Openflow.Match.read()
|> Kernel.elem(0)
%Request{ %Request{
xid: xid, table_id: Openflow.Utils.get_enum(table_id_int, :table_id),
table_id: table_id, out_port: Openflow.Utils.get_enum(out_port_int, :openflow13_port_no),
out_port: out_port, out_group: Openflow.Utils.get_enum(out_group_int, :group_id),
out_group: out_group,
cookie: cookie,
cookie_mask: cookie_mask,
match: match
}
end
def read(
<<table_id_int::8, _::size(3)-unit(8), out_port_int::32, out_group_int::32,
_::size(4)-unit(8), cookie::64, cookie_mask::64, match_bin::bytes>>
) do
table_id = Openflow.Utils.get_enum(table_id_int, :table_id)
out_port = Openflow.Utils.get_enum(out_port_int, :openflow13_port_no)
out_group = Openflow.Utils.get_enum(out_group_int, :group_id)
{match, _rest} = Openflow.Match.read(match_bin)
%Request{
table_id: table_id,
out_port: out_port,
out_group: out_group,
cookie: cookie, cookie: cookie,
cookie_mask: cookie_mask, cookie_mask: cookie_mask,
match: match match: match
} }
end end
@spec to_binary(t()) :: <<_::256, _::_*8>>
def to_binary( def to_binary(
%Request{ %Request{
table_id: table_id, table_id: table_id,
@ -66,16 +93,16 @@ defmodule Openflow.Multipart.Aggregate.Request do
match: match match: match
} = msg } = msg
) do ) do
table_id_int = Openflow.Utils.get_enum(table_id, :table_id) <<
out_port_int = Openflow.Utils.get_enum(out_port, :openflow13_port_no) Openflow.Multipart.Request.header(msg)::bytes,
out_group_int = Openflow.Utils.get_enum(out_group, :group_id) Openflow.Utils.get_enum(table_id, :table_id)::8,
match_bin = Openflow.Match.to_binary(match) 0::size(3)-unit(8),
Openflow.Utils.get_enum(out_port, :openflow13_port_no)::32,
body_bin = Openflow.Utils.get_enum(out_group, :group_id)::32,
<<table_id_int::8, 0::size(3)-unit(8), out_port_int::32, out_group_int::32, 0::size(4)-unit(8),
0::size(4)-unit(8), cookie::64, cookie_mask::64, match_bin::bytes>> cookie::64,
cookie_mask::64,
header_bin = Openflow.Multipart.Request.header(msg) Openflow.Match.to_binary(match)::bytes
<<header_bin::bytes, body_bin::bytes>> >>
end end
end end