Formatted

This commit is contained in:
Eishun Kondoh 2018-01-30 22:47:31 +09:00
parent 5fc01a9bec
commit 7635272fbd
150 changed files with 5055 additions and 4032 deletions

View file

@ -1,11 +1,12 @@
defmodule Openflow.Multipart.Flow.Reply do
defstruct(
version: 4,
xid: 0,
datapath_id: nil, # virtual field
aux_id: nil,
flags: [],
flows: []
version: 4,
xid: 0,
# virtual field
datapath_id: nil,
aux_id: nil,
flags: [],
flows: []
)
alias __MODULE__
@ -22,29 +23,32 @@ defmodule Openflow.Multipart.Flow.Reply do
end
def append_body(%Reply{flows: flows} = message, %Reply{flags: [:more], flows: continue}) do
%{message|flows: [continue|flows]}
%{message | flows: [continue | flows]}
end
def append_body(%Reply{flows: flows} = message, %Reply{flags: [], flows: continue}) do
new_flows = [continue|flows]
|> Enum.reverse
|> List.flatten
%{message|flows: new_flows}
new_flows =
[continue | flows]
|> Enum.reverse()
|> List.flatten()
%{message | flows: new_flows}
end
end
defmodule Openflow.Multipart.FlowStats do
defstruct(
table_id: 0,
duration_sec: 0,
table_id: 0,
duration_sec: 0,
duration_nsec: 0,
priority: 0,
idle_timeout: 0,
hard_timeout: 0,
flags: 0,
cookie: 0,
packet_count: 0,
byte_count: 0,
match: [],
priority: 0,
idle_timeout: 0,
hard_timeout: 0,
flags: 0,
cookie: 0,
packet_count: 0,
byte_count: 0,
match: [],
instructions: []
)
@ -57,30 +61,35 @@ defmodule Openflow.Multipart.FlowStats do
# private functions
defp do_read(acc, ""), do: Enum.reverse(acc)
defp do_read(acc, <<length::16, _tail::bytes>> = binary) do
<<flow_stats_bin::size(length)-bytes, rest::bytes>> = binary
do_read([codec(flow_stats_bin)|acc], rest)
do_read([codec(flow_stats_bin) | acc], rest)
end
defp codec(<<_length::16, table_id_int::8, 0::8, duration_sec::32,
duration_nsec::32, priority::16, idle::16, hard::16,
flags_int::16, _::size(4)-unit(8), cookie::64,
packet_count::64, byte_count::64, tail::bytes>>) do
defp codec(
<<_length::16, table_id_int::8, 0::8, duration_sec::32, duration_nsec::32, priority::16,
idle::16, hard::16, flags_int::16, _::size(4)-unit(8), cookie::64, packet_count::64,
byte_count::64, tail::bytes>>
) do
{match, instructions_bin} = Openflow.Match.read(tail)
table_id = Openflow.Utils.get_enum(table_id_int, :table_id)
flags = Openflow.Enums.int_to_flags(flags_int, :flow_mod_flags)
instructions = Openflow.Instruction.read(instructions_bin)
%FlowStats{table_id: table_id,
duration_sec: duration_sec,
duration_nsec: duration_nsec,
priority: priority,
idle_timeout: idle,
hard_timeout: hard,
flags: flags,
cookie: cookie,
packet_count: packet_count,
byte_count: byte_count,
match: match,
instructions: instructions}
%FlowStats{
table_id: table_id,
duration_sec: duration_sec,
duration_nsec: duration_nsec,
priority: priority,
idle_timeout: idle,
hard_timeout: hard,
flags: flags,
cookie: cookie,
packet_count: packet_count,
byte_count: byte_count,
match: match,
instructions: instructions
}
end
end

View file

@ -1,15 +1,16 @@
defmodule Openflow.Multipart.Flow.Request do
defstruct(
version: 4,
xid: 0,
datapath_id: nil, # virtual field
flags: [],
table_id: :all,
out_port: :any,
out_group: :any,
cookie: 0,
cookie_mask: 0,
match: []
version: 4,
xid: 0,
# virtual field
datapath_id: nil,
flags: [],
table_id: :all,
out_port: :any,
out_group: :any,
cookie: 0,
cookie_mask: 0,
match: []
)
alias __MODULE__
@ -22,45 +23,56 @@ defmodule Openflow.Multipart.Flow.Request do
out_group = Keyword.get(options, :out_group, :any)
cookie = Keyword.get(options, :cookie, 0)
cookie_mask = Keyword.get(options, :cookie, 0)
match = Keyword.get(options, :match, Openflow.Match.new)
%Request{table_id: table_id,
out_port: out_port,
out_group: out_group,
cookie: cookie,
cookie_mask: cookie_mask,
match: match}
match = Keyword.get(options, :match, Openflow.Match.new())
%Request{
table_id: table_id,
out_port: out_port,
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
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_mask: cookie_mask,
match: match}
%Request{
table_id: table_id,
out_port: out_port,
out_group: out_group,
cookie: cookie,
cookie_mask: cookie_mask,
match: match
}
end
def to_binary(%Request{table_id: table_id,
out_port: out_port,
out_group: out_group,
cookie: cookie,
cookie_mask: cookie_mask,
match: match} = msg) do
def to_binary(
%Request{
table_id: table_id,
out_port: out_port,
out_group: out_group,
cookie: cookie,
cookie_mask: cookie_mask,
match: match
} = msg
) do
table_id_int = Openflow.Utils.get_enum(table_id, :table_id)
out_port_int = Openflow.Utils.get_enum(out_port, :openflow13_port_no)
out_group_int = Openflow.Utils.get_enum(out_group, :group_id)
match_bin = Openflow.Match.to_binary(match)
body_bin = <<table_id_int::8, 0::size(3)-unit(8),
out_port_int::32, out_group_int::32,
0::size(4)-unit(8), cookie::64,
cookie_mask::64, match_bin::bytes>>
body_bin =
<<table_id_int::8, 0::size(3)-unit(8), out_port_int::32, out_group_int::32,
0::size(4)-unit(8), cookie::64, cookie_mask::64, match_bin::bytes>>
header_bin = Openflow.Multipart.Request.header(msg)
<<header_bin::bytes, body_bin::bytes>>
end