Openflow parser
This commit is contained in:
parent
70b0d8919e
commit
fc02a678de
338 changed files with 9081 additions and 0 deletions
59
lib/openflow/multipart/queue/reply.ex
Normal file
59
lib/openflow/multipart/queue/reply.ex
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
defmodule Openflow.Multipart.Queue.Reply do
|
||||
defstruct(
|
||||
version: 4,
|
||||
xid: 0,
|
||||
datapath_id: nil, # virtual field
|
||||
flags: [],
|
||||
queues: []
|
||||
)
|
||||
|
||||
alias __MODULE__
|
||||
|
||||
def ofp_type, do: 18
|
||||
|
||||
def new(queues \\ []) do
|
||||
%Reply{queues: queues}
|
||||
end
|
||||
|
||||
def read(<<queues_bin::bytes>>) do
|
||||
queues = Openflow.Multipart.Queue.read(queues_bin)
|
||||
%Reply{queues: queues}
|
||||
end
|
||||
end
|
||||
|
||||
defmodule Openflow.Multipart.Queue do
|
||||
defstruct(
|
||||
port_number: 0,
|
||||
queue_id: 0,
|
||||
tx_bytes: 0,
|
||||
tx_packets: 0,
|
||||
tx_errors: 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, <<queue_bin::40-bytes, rest::bytes>>) do
|
||||
do_read([codec(queue_bin)|acc], rest)
|
||||
end
|
||||
|
||||
defp codec(<<port_no::32, queue_id::32, tx_bytes::64,
|
||||
tx_packets::64, tx_errors::64,
|
||||
duration_sec::32, duration_nsec::32>>) do
|
||||
%Queue{port_number: port_no,
|
||||
queue_id: queue_id,
|
||||
tx_bytes: tx_bytes,
|
||||
tx_packets: tx_packets,
|
||||
tx_errors: tx_errors,
|
||||
duration_sec: duration_sec,
|
||||
duration_nsec: duration_nsec}
|
||||
end
|
||||
end
|
||||
34
lib/openflow/multipart/queue/request.ex
Normal file
34
lib/openflow/multipart/queue/request.ex
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
defmodule Openflow.Multipart.Queue.Request do
|
||||
defstruct(
|
||||
version: 4,
|
||||
xid: 0,
|
||||
datapath_id: nil, # virtual field
|
||||
flags: [],
|
||||
port_number: :any,
|
||||
queue_id: :all
|
||||
)
|
||||
|
||||
alias __MODULE__
|
||||
|
||||
def ofp_type, do: 18
|
||||
|
||||
def new(options) do
|
||||
port_no = Keyword.get(options, :port_number, :any)
|
||||
queue_id = Keyword.get(options, :queue_id, :all)
|
||||
%Request{port_number: port_no, queue_id: queue_id}
|
||||
end
|
||||
|
||||
def read(<<port_no_int::32, queue_id_int::32>>) do
|
||||
port_no = Openflow.Utils.get_enum(port_no_int, :openflow13_port_no)
|
||||
queue_id = Openflow.Utils.get_enum(queue_id_int, :queue_id)
|
||||
%Request{port_number: port_no, queue_id: queue_id}
|
||||
end
|
||||
|
||||
def to_binary(%Request{port_number: port_no, queue_id: queue_id} = msg) do
|
||||
port_no_int = Openflow.Utils.get_enum(port_no, :openflow13_port_no)
|
||||
queue_id_int = Openflow.Utils.get_enum(queue_id, :queue_id)
|
||||
body_bin = <<port_no_int::32, queue_id_int::32>>
|
||||
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