Openflow parser
This commit is contained in:
parent
70b0d8919e
commit
fc02a678de
338 changed files with 9081 additions and 0 deletions
78
lib/openflow/multipart/port_stats/reply.ex
Normal file
78
lib/openflow/multipart/port_stats/reply.ex
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
defmodule Openflow.Multipart.PortStats.Reply do
|
||||
defstruct(
|
||||
version: 4,
|
||||
xid: 0,
|
||||
datapath_id: nil, # virtual field
|
||||
flags: [],
|
||||
ports: []
|
||||
)
|
||||
|
||||
alias __MODULE__
|
||||
|
||||
def ofp_type, do: 18
|
||||
|
||||
def new(ports \\ []) do
|
||||
%Reply{ports: ports}
|
||||
end
|
||||
|
||||
def read(<<ports_bin::bytes>>) do
|
||||
ports = Openflow.Multipart.PortStats.read(ports_bin)
|
||||
%Reply{ports: ports}
|
||||
end
|
||||
end
|
||||
|
||||
defmodule Openflow.Multipart.PortStats do
|
||||
defstruct(
|
||||
port_number: 0,
|
||||
rx_packets: 0,
|
||||
tx_packets: 0,
|
||||
rx_bytes: 0,
|
||||
tx_bytes: 0,
|
||||
rx_dropped: 0,
|
||||
tx_dropped: 0,
|
||||
rx_errors: 0,
|
||||
tx_errors: 0,
|
||||
rx_frame_err: 0,
|
||||
rx_over_err: 0,
|
||||
rx_crc_err: 0,
|
||||
collisions: 0,
|
||||
duration_sec: 0,
|
||||
duration_nsec: 0
|
||||
)
|
||||
|
||||
alias __MODULE__
|
||||
|
||||
def read(binary) do
|
||||
do_read([], binary)
|
||||
end
|
||||
|
||||
# private functions
|
||||
|
||||
defp do_read(acc, ""), do: Enum.reverse(acc)
|
||||
defp do_read(acc, <<port_stats_bin::112-bytes, rest::bytes>>) do
|
||||
do_read([codec(port_stats_bin)|acc], rest)
|
||||
end
|
||||
|
||||
defp codec(<<port_no::32, _::size(4)-unit(8), rx_packets::64,
|
||||
tx_packets::64, rx_bytes::64, tx_bytes::64,
|
||||
rx_dropped::64, tx_dropped::64, rx_errors::64,
|
||||
tx_errors::64, rx_frame_err::64, rx_over_err::64,
|
||||
rx_crc_err::64, collisions::64,
|
||||
duration_sec::32, duration_nsec::32>>) do
|
||||
%PortStats{port_number: port_no,
|
||||
rx_packets: rx_packets,
|
||||
tx_packets: tx_packets,
|
||||
rx_bytes: rx_bytes,
|
||||
tx_bytes: tx_bytes,
|
||||
rx_dropped: rx_dropped,
|
||||
tx_dropped: tx_dropped,
|
||||
rx_errors: rx_errors,
|
||||
tx_errors: tx_errors,
|
||||
rx_frame_err: rx_frame_err,
|
||||
rx_over_err: rx_over_err,
|
||||
rx_crc_err: rx_crc_err,
|
||||
collisions: collisions,
|
||||
duration_sec: duration_sec,
|
||||
duration_nsec: duration_nsec}
|
||||
end
|
||||
end
|
||||
29
lib/openflow/multipart/port_stats/request.ex
Normal file
29
lib/openflow/multipart/port_stats/request.ex
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
defmodule Openflow.Multipart.PortStats.Request do
|
||||
defstruct(
|
||||
version: 4,
|
||||
xid: 0,
|
||||
datapath_id: nil, # virtual field
|
||||
flags: [],
|
||||
port_number: :any
|
||||
)
|
||||
|
||||
alias __MODULE__
|
||||
|
||||
def ofp_type, do: 18
|
||||
|
||||
def new(port_no \\ :any) do
|
||||
%Request{port_number: port_no}
|
||||
end
|
||||
|
||||
def read(<<port_no_int::32, _::size(4)-unit(8)>>) do
|
||||
port_no = Openflow.Utils.get_enum(port_no_int, :openflow13_port_no)
|
||||
%Request{port_number: port_no}
|
||||
end
|
||||
|
||||
def to_binary(%Request{port_number: port_no} = msg) do
|
||||
port_no_int = Openflow.Utils.get_enum(port_no, :openflow13_port_no)
|
||||
body_bin = <<port_no_int::32, 0::size(4)-unit(8)>>
|
||||
header_bin = Openflow.Multipart.Request.header(msg)
|
||||
<<header_bin::bytes, body_bin::bytes>>
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue