Formatted
This commit is contained in:
parent
5fc01a9bec
commit
7635272fbd
150 changed files with 5055 additions and 4032 deletions
|
|
@ -1,11 +1,12 @@
|
|||
defmodule Openflow.Multipart.Group.Reply do
|
||||
defstruct(
|
||||
version: 4,
|
||||
xid: 0,
|
||||
datapath_id: nil, # virtual field
|
||||
aux_id: nil,
|
||||
flags: [],
|
||||
groups: []
|
||||
version: 4,
|
||||
xid: 0,
|
||||
# virtual field
|
||||
datapath_id: nil,
|
||||
aux_id: nil,
|
||||
flags: [],
|
||||
groups: []
|
||||
)
|
||||
|
||||
alias __MODULE__
|
||||
|
|
@ -22,25 +23,28 @@ defmodule Openflow.Multipart.Group.Reply do
|
|||
end
|
||||
|
||||
def append_body(%Reply{groups: groups} = message, %Reply{flags: [:more], groups: continue}) do
|
||||
%{message|groups: [continue|groups]}
|
||||
%{message | groups: [continue | groups]}
|
||||
end
|
||||
|
||||
def append_body(%Reply{groups: groups} = message, %Reply{flags: [], groups: continue}) do
|
||||
new_groups = [continue|groups]
|
||||
|> Enum.reverse
|
||||
|> List.flatten
|
||||
%{message|groups: new_groups}
|
||||
new_groups =
|
||||
[continue | groups]
|
||||
|> Enum.reverse()
|
||||
|> List.flatten()
|
||||
|
||||
%{message | groups: new_groups}
|
||||
end
|
||||
end
|
||||
|
||||
defmodule Openflow.Multipart.Group do
|
||||
defstruct(
|
||||
group_id: 0,
|
||||
ref_count: 0,
|
||||
packet_count: 0,
|
||||
byte_count: 0,
|
||||
duration_sec: 0,
|
||||
group_id: 0,
|
||||
ref_count: 0,
|
||||
packet_count: 0,
|
||||
byte_count: 0,
|
||||
duration_sec: 0,
|
||||
duration_nsec: 0,
|
||||
bucket_stats: []
|
||||
bucket_stats: []
|
||||
)
|
||||
|
||||
@ofp_group_stats_size 40
|
||||
|
|
@ -54,27 +58,32 @@ defmodule Openflow.Multipart.Group do
|
|||
# private functions
|
||||
|
||||
defp do_read(acc, ""), do: Enum.reverse(acc)
|
||||
|
||||
defp do_read(acc, <<length::16, _binary::bytes>> = binary) do
|
||||
<<group_bin::size(length)-bytes, rest::bytes>> = binary
|
||||
do_read([codec(group_bin)|acc], rest)
|
||||
do_read([codec(group_bin) | acc], rest)
|
||||
end
|
||||
|
||||
defp codec(<<length::16, _::size(2)-unit(8),
|
||||
group_id::32, ref_count::32,
|
||||
_::size(4)-unit(8), packet_count::64,
|
||||
byte_count::64, duration_sec::32,
|
||||
duration_nsec::32, tail::bytes>>) do
|
||||
defp codec(
|
||||
<<length::16, _::size(2)-unit(8), group_id::32, ref_count::32, _::size(4)-unit(8),
|
||||
packet_count::64, byte_count::64, duration_sec::32, duration_nsec::32, tail::bytes>>
|
||||
) do
|
||||
bucket_stats_size = length - @ofp_group_stats_size
|
||||
<<bucket_stats_bin::size(bucket_stats_size)-bytes, _rest::bytes>> = tail
|
||||
bucket_stats = for <<packet_count::64, byte_count::64 <- bucket_stats_bin>> do
|
||||
%{packet_count: packet_count, byte_count: byte_count}
|
||||
end
|
||||
%Group{group_id: group_id,
|
||||
ref_count: ref_count,
|
||||
packet_count: packet_count,
|
||||
byte_count: byte_count,
|
||||
duration_sec: duration_sec,
|
||||
duration_nsec: duration_nsec,
|
||||
bucket_stats: bucket_stats}
|
||||
|
||||
bucket_stats =
|
||||
for <<packet_count::64, byte_count::64 <- bucket_stats_bin>> do
|
||||
%{packet_count: packet_count, byte_count: byte_count}
|
||||
end
|
||||
|
||||
%Group{
|
||||
group_id: group_id,
|
||||
ref_count: ref_count,
|
||||
packet_count: packet_count,
|
||||
byte_count: byte_count,
|
||||
duration_sec: duration_sec,
|
||||
duration_nsec: duration_nsec,
|
||||
bucket_stats: bucket_stats
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
defmodule Openflow.Multipart.Group.Request do
|
||||
defstruct(
|
||||
version: 4,
|
||||
xid: 0,
|
||||
datapath_id: nil, # virtual field
|
||||
version: 4,
|
||||
xid: 0,
|
||||
# virtual field
|
||||
datapath_id: nil,
|
||||
flags: [],
|
||||
group_id: :all
|
||||
group_id: :all
|
||||
)
|
||||
|
||||
alias __MODULE__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue