Fix
This commit is contained in:
parent
5879c9cf37
commit
36035389e9
1 changed files with 27 additions and 9 deletions
|
|
@ -76,8 +76,17 @@ defmodule Openflow.NxResume do
|
||||||
|
|
||||||
def new(options \\ []) do
|
def new(options \\ []) do
|
||||||
packet_in = options[:packet_in]
|
packet_in = options[:packet_in]
|
||||||
|
packet = options[:packet] || packet_in.packet
|
||||||
|
|
||||||
%NxResume{
|
%NxResume{
|
||||||
packet: options[:packet] || packet_in.packet,
|
packet: options[:packet] || packet_in.packet,
|
||||||
|
full_len: byte_size(packet),
|
||||||
|
buffer_id: packet_in.buffer_id || :no_buffer,
|
||||||
|
table_id: packet_in.table_id,
|
||||||
|
cookie: packet_in.cookie,
|
||||||
|
reason: packet_in.reason,
|
||||||
|
metadata: packet_in.metadata,
|
||||||
|
userdata: packet_in.userdata,
|
||||||
continuation_bridge: packet_in.continuation_bridge,
|
continuation_bridge: packet_in.continuation_bridge,
|
||||||
continuation_stack: packet_in.continuation_stack,
|
continuation_stack: packet_in.continuation_stack,
|
||||||
continuation_conntracked: packet_in.continuation_conntracked,
|
continuation_conntracked: packet_in.continuation_conntracked,
|
||||||
|
|
@ -92,7 +101,9 @@ defmodule Openflow.NxResume do
|
||||||
def to_binary(%NxResume{} = pin) do
|
def to_binary(%NxResume{} = pin) do
|
||||||
props_bin = encode_props("", pin, @encode_keys)
|
props_bin = encode_props("", pin, @encode_keys)
|
||||||
continuations_bin = encode_continuations("", pin, @continuation_keys)
|
continuations_bin = encode_continuations("", pin, @continuation_keys)
|
||||||
<<@experimenter::32, @nx_type::32, props_bin::bytes, continuations_bin::bytes>>
|
bin0 = <<@experimenter::32, @nx_type::32, props_bin::bytes, continuations_bin::bytes>>
|
||||||
|
pad_length = Openflow.Utils.pad_length(byte_size(bin0) + 8, 8)
|
||||||
|
<<bin0::bytes, 0::size(pad_length)-unit(8)>>
|
||||||
end
|
end
|
||||||
|
|
||||||
def read(<<@experimenter::32, @nx_type::32, props_bin::bytes>>) do
|
def read(<<@experimenter::32, @nx_type::32, props_bin::bytes>>) do
|
||||||
|
|
@ -120,9 +131,10 @@ defmodule Openflow.NxResume do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp encode_props(acc, %NxResume{buffer_id: buffer_id} = pin, [:buffer_id | rest])
|
defp encode_props(acc, %NxResume{buffer_id: buffer_id} = pin, [:buffer_id | rest])
|
||||||
when not is_nil(buffer_id) and is_integer(buffer_id) do
|
when not is_nil(buffer_id) do
|
||||||
length = @prop_header_length + 4
|
length = @prop_header_length + 4
|
||||||
binary = <<@buffer_id::16, length::16, buffer_id::32>>
|
buffer_id_int = Openflow.Utils.get_enum(buffer_id, :buffer_id)
|
||||||
|
binary = <<@buffer_id::16, length::16, buffer_id_int::32>>
|
||||||
encode_props(<<acc::bytes, binary::bytes>>, pin, rest)
|
encode_props(<<acc::bytes, binary::bytes>>, pin, rest)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -172,7 +184,8 @@ defmodule Openflow.NxResume do
|
||||||
if byte_size(acc) > 0 do
|
if byte_size(acc) > 0 do
|
||||||
length = @prop_header_length + byte_size(acc)
|
length = @prop_header_length + byte_size(acc)
|
||||||
pad_length = Openflow.Utils.pad_length(length, 8)
|
pad_length = Openflow.Utils.pad_length(length, 8)
|
||||||
<<@continuation::16, acc::bytes, 0::size(pad_length)-unit(8)>>
|
binary = <<@continuation::16, length::16, acc::bytes, 0::size(pad_length)-unit(8)>>
|
||||||
|
binary
|
||||||
else
|
else
|
||||||
<<>>
|
<<>>
|
||||||
end
|
end
|
||||||
|
|
@ -185,9 +198,9 @@ defmodule Openflow.NxResume do
|
||||||
)
|
)
|
||||||
when not is_nil(br) do
|
when not is_nil(br) do
|
||||||
length = @prop_header_length + byte_size(br)
|
length = @prop_header_length + byte_size(br)
|
||||||
pad_length = Openflow.Utils.pad_length(length, 8)
|
bridge_bin = <<br::16-bytes, acc::bytes>>
|
||||||
bridge_bin = <<br::bytes, 0::size(pad_length)-unit(8), acc::bytes>>
|
binary = <<@nxcpt_bridge::16, length::16, bridge_bin::bytes, 0::size(4)-unit(8), acc::bytes>>
|
||||||
binary = <<@nxcpt_bridge::16, length::16, bridge_bin::bytes, acc::bytes>>
|
|
||||||
encode_continuations(binary, pin, rest)
|
encode_continuations(binary, pin, rest)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -214,6 +227,7 @@ defmodule Openflow.NxResume do
|
||||||
pad_length = Openflow.Utils.pad_length(length, 8)
|
pad_length = Openflow.Utils.pad_length(length, 8)
|
||||||
mirrors_bin = <<mirrors::bytes, 0::size(pad_length)-unit(8), acc::bytes>>
|
mirrors_bin = <<mirrors::bytes, 0::size(pad_length)-unit(8), acc::bytes>>
|
||||||
binary = <<@nxcpt_mirrors::16, length::16, mirrors_bin::bytes, acc::bytes>>
|
binary = <<@nxcpt_mirrors::16, length::16, mirrors_bin::bytes, acc::bytes>>
|
||||||
|
|
||||||
encode_continuations(binary, pin, rest)
|
encode_continuations(binary, pin, rest)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -226,6 +240,7 @@ defmodule Openflow.NxResume do
|
||||||
pad_length = Openflow.Utils.pad_length(length, 8)
|
pad_length = Openflow.Utils.pad_length(length, 8)
|
||||||
conntracked_bin = <<1::size(1)-unit(8), 0::size(pad_length)-unit(8), acc::bytes>>
|
conntracked_bin = <<1::size(1)-unit(8), 0::size(pad_length)-unit(8), acc::bytes>>
|
||||||
binary = <<@nxcpt_conntracked::16, length::16, conntracked_bin::bytes, acc::bytes>>
|
binary = <<@nxcpt_conntracked::16, length::16, conntracked_bin::bytes, acc::bytes>>
|
||||||
|
|
||||||
encode_continuations(binary, pin, rest)
|
encode_continuations(binary, pin, rest)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -239,6 +254,7 @@ defmodule Openflow.NxResume do
|
||||||
pad_length = Openflow.Utils.pad_length(length, 8)
|
pad_length = Openflow.Utils.pad_length(length, 8)
|
||||||
table_id_bin = <<table_id::8, 0::size(pad_length)-unit(8), acc::bytes>>
|
table_id_bin = <<table_id::8, 0::size(pad_length)-unit(8), acc::bytes>>
|
||||||
binary = <<@nxcpt_table_id::16, length::16, table_id_bin::bytes, acc::bytes>>
|
binary = <<@nxcpt_table_id::16, length::16, table_id_bin::bytes, acc::bytes>>
|
||||||
|
|
||||||
encode_continuations(binary, pin, rest)
|
encode_continuations(binary, pin, rest)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -252,6 +268,7 @@ defmodule Openflow.NxResume do
|
||||||
pad_length = Openflow.Utils.pad_length(length, 8)
|
pad_length = Openflow.Utils.pad_length(length, 8)
|
||||||
cookie_bin = <<cookie::64, 0::size(pad_length)-unit(8), acc::bytes>>
|
cookie_bin = <<cookie::64, 0::size(pad_length)-unit(8), acc::bytes>>
|
||||||
binary = <<@nxcpt_cookie::16, length::16, cookie_bin::bytes, acc::bytes>>
|
binary = <<@nxcpt_cookie::16, length::16, cookie_bin::bytes, acc::bytes>>
|
||||||
|
|
||||||
encode_continuations(binary, pin, rest)
|
encode_continuations(binary, pin, rest)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -259,7 +276,8 @@ defmodule Openflow.NxResume do
|
||||||
acc,
|
acc,
|
||||||
%NxResume{continuation_actions: actions} = pin,
|
%NxResume{continuation_actions: actions} = pin,
|
||||||
[:continuation_actions | rest]
|
[:continuation_actions | rest]
|
||||||
) when is_nil(actions) do
|
)
|
||||||
|
when not is_nil(actions) do
|
||||||
actions_bin = Openflow.Action.to_binary(actions)
|
actions_bin = Openflow.Action.to_binary(actions)
|
||||||
length = @prop_header_length + byte_size(actions_bin)
|
length = @prop_header_length + byte_size(actions_bin)
|
||||||
pad_length = Openflow.Utils.pad_length(length, 8)
|
pad_length = Openflow.Utils.pad_length(length, 8)
|
||||||
|
|
@ -281,7 +299,7 @@ defmodule Openflow.NxResume do
|
||||||
encode_continuations(binary, pin, rest)
|
encode_continuations(binary, pin, rest)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp encode_continuations(acc, pin, [_ | rest]) do
|
defp encode_continuations(acc, pin, [other | rest]) do
|
||||||
encode_continuations(acc, pin, rest)
|
encode_continuations(acc, pin, rest)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue