From 4803c61061e844b86987b6fbf2e9996747b1ac07 Mon Sep 17 00:00:00 2001 From: Eishun Kondoh Date: Thu, 22 Mar 2018 23:49:03 +0900 Subject: [PATCH] Fix to accept transaction_id to all message structs --- lib/openflow/barrier/request.ex | 4 ++-- lib/openflow/echo/reply.ex | 8 +++++++- lib/openflow/echo/request.ex | 8 +++++++- lib/openflow/experimenter.ex | 1 + lib/openflow/features/request.ex | 4 ++-- lib/openflow/flow_mod.ex | 2 ++ lib/openflow/get_async/request.ex | 4 ++++ lib/openflow/get_config/request.ex | 4 ++-- lib/openflow/group_mod.ex | 3 ++- lib/openflow/multipart/aggregate/request.ex | 2 ++ lib/openflow/multipart/desc/request.ex | 4 ++-- lib/openflow/multipart/flow/request.ex | 2 ++ lib/openflow/multipart/group/ *Minibuf-1* | 1 - lib/openflow/multipart/group/.# *Minibuf-1* | 1 - lib/openflow/multipart/group/request.ex | 9 ++++++++- lib/openflow/multipart/group_desc/request.ex | 4 ++-- lib/openflow/multipart/group_features/request.ex | 4 ++-- lib/openflow/multipart/meter/request.ex | 9 ++++++++- lib/openflow/multipart/meter_config/request.ex | 9 ++++++++- lib/openflow/multipart/port_desc/request.ex | 4 ++-- lib/openflow/multipart/port_stats/request.ex | 9 ++++++++- lib/openflow/multipart/queue/request.ex | 3 ++- lib/openflow/multipart/table/request.ex | 4 ++-- lib/openflow/multipart/table_features/request.ex | 7 +++++-- lib/openflow/role/request.ex | 3 ++- lib/openflow/set_async.ex | 12 ++++++++++++ lib/openflow/set_config.ex | 3 ++- lib/openflow/table_mod.ex | 8 +++++++- lib/tres/message_helper.ex | 16 +++++++++++++--- 29 files changed, 118 insertions(+), 34 deletions(-) delete mode 100644 lib/openflow/multipart/group/ *Minibuf-1* delete mode 120000 lib/openflow/multipart/group/.# *Minibuf-1* diff --git a/lib/openflow/barrier/request.ex b/lib/openflow/barrier/request.ex index 399e533..346270c 100644 --- a/lib/openflow/barrier/request.ex +++ b/lib/openflow/barrier/request.ex @@ -12,8 +12,8 @@ defmodule Openflow.Barrier.Request do def ofp_type, do: 20 - def new do - %Request{} + def new(xid \\ 0) do + %Request{xid: xid} end def read(_) do diff --git a/lib/openflow/echo/reply.ex b/lib/openflow/echo/reply.ex index 455ef64..dbc7029 100644 --- a/lib/openflow/echo/reply.ex +++ b/lib/openflow/echo/reply.ex @@ -13,7 +13,13 @@ defmodule Openflow.Echo.Reply do def ofp_type, do: 3 - def new(data \\ "") do + def new(options) when is_list(options) do + %Reply{ + xid: options[:xid] || 0, + data: options[:data] || "" + } + end + def new(data) when is_binary(data) do %Reply{data: data} end diff --git a/lib/openflow/echo/request.ex b/lib/openflow/echo/request.ex index f3a6af3..36dbc0d 100644 --- a/lib/openflow/echo/request.ex +++ b/lib/openflow/echo/request.ex @@ -13,7 +13,13 @@ defmodule Openflow.Echo.Request do def ofp_type, do: 2 - def new(data \\ "") do + def new(options) when is_list(options) do + %Request{ + xid: options[:xid] || 0, + data: options[:data] || "" + } + end + def new(data) when is_binary(data) do %Request{data: data} end diff --git a/lib/openflow/experimenter.ex b/lib/openflow/experimenter.ex index 1d540f0..52f1505 100644 --- a/lib/openflow/experimenter.ex +++ b/lib/openflow/experimenter.ex @@ -15,6 +15,7 @@ defmodule Openflow.Experimenter do def new(options) do %Experimenter{ + xid: options[:xid] || 0, exp_id: Keyword.get(options, :exp_id, 0), exp_type: Keyword.get(options, :exp_type, 0), data: Keyword.get(options, :data, "") diff --git a/lib/openflow/features/request.ex b/lib/openflow/features/request.ex index 83aadbb..8fb5f4e 100644 --- a/lib/openflow/features/request.ex +++ b/lib/openflow/features/request.ex @@ -12,8 +12,8 @@ defmodule Openflow.Features.Request do def ofp_type, do: 5 - def new do - %Request{} + def new(xid \\ 0) do + %Request{xid: xid} end def read(_) do diff --git a/lib/openflow/flow_mod.ex b/lib/openflow/flow_mod.ex index 1c1d972..4b3b541 100644 --- a/lib/openflow/flow_mod.ex +++ b/lib/openflow/flow_mod.ex @@ -24,6 +24,7 @@ defmodule Openflow.FlowMod do def ofp_type, do: 14 def new(options \\ []) do + xid = Keyword.get(options, :xid, 0) cookie = Keyword.get(options, :cookie, 0) cookie_mask = Keyword.get(options, :cookie_mask, 0) table_id = Keyword.get(options, :table_id, 0) @@ -39,6 +40,7 @@ defmodule Openflow.FlowMod do instructions = Keyword.get(options, :instructions, []) %FlowMod{ + xid: xid, cookie: cookie, cookie_mask: cookie_mask, priority: priority, diff --git a/lib/openflow/get_async/request.ex b/lib/openflow/get_async/request.ex index 3be0048..0306095 100644 --- a/lib/openflow/get_async/request.ex +++ b/lib/openflow/get_async/request.ex @@ -12,6 +12,10 @@ defmodule Openflow.GetAsync.Request do def ofp_type, do: 26 + def new(xid \\ 0) do + %Request{xid: xid} + end + def read(_) do %Request{} end diff --git a/lib/openflow/get_config/request.ex b/lib/openflow/get_config/request.ex index e9e0af4..f5ec984 100644 --- a/lib/openflow/get_config/request.ex +++ b/lib/openflow/get_config/request.ex @@ -12,8 +12,8 @@ defmodule Openflow.GetConfig.Request do def ofp_type, do: 7 - def new do - %Request{} + def new(xid \\ 0) do + %Request{xid: xid} end def read(_) do diff --git a/lib/openflow/group_mod.ex b/lib/openflow/group_mod.ex index f8f2a54..6f76684 100644 --- a/lib/openflow/group_mod.ex +++ b/lib/openflow/group_mod.ex @@ -15,11 +15,12 @@ defmodule Openflow.GroupMod do def ofp_type, do: 15 def new(options \\ []) do + xid = Keyword.get(options, :xid, 0) command = Keyword.get(options, :command, :add) type = Keyword.get(options, :type, :all) group_id = Keyword.get(options, :group_id, 0) buckets = Keyword.get(options, :buckets, []) - %GroupMod{command: command, type: type, group_id: group_id, buckets: buckets} + %GroupMod{xid: xid, command: command, type: type, group_id: group_id, buckets: buckets} end def read(<>) do diff --git a/lib/openflow/multipart/aggregate/request.ex b/lib/openflow/multipart/aggregate/request.ex index 89f55e3..0335cb9 100644 --- a/lib/openflow/multipart/aggregate/request.ex +++ b/lib/openflow/multipart/aggregate/request.ex @@ -18,6 +18,7 @@ defmodule Openflow.Multipart.Aggregate.Request do def ofp_type, do: 18 def new(options) do + xid = Keyword.get(options, :xid, 0) table_id = Keyword.get(options, :table_id, :all) out_port = Keyword.get(options, :out_port, :any) out_group = Keyword.get(options, :out_group, :any) @@ -26,6 +27,7 @@ defmodule Openflow.Multipart.Aggregate.Request do match = Keyword.get(options, :match, []) %Request{ + xid: xid, table_id: table_id, out_port: out_port, out_group: out_group, diff --git a/lib/openflow/multipart/desc/request.ex b/lib/openflow/multipart/desc/request.ex index 4d9bef7..f0b17c5 100644 --- a/lib/openflow/multipart/desc/request.ex +++ b/lib/openflow/multipart/desc/request.ex @@ -11,8 +11,8 @@ defmodule Openflow.Multipart.Desc.Request do def ofp_type, do: 18 - def new do - %Request{} + def new(xid \\ 0) do + %Request{xid: xid} end def read("") do diff --git a/lib/openflow/multipart/flow/request.ex b/lib/openflow/multipart/flow/request.ex index dc14e43..c3b37b6 100644 --- a/lib/openflow/multipart/flow/request.ex +++ b/lib/openflow/multipart/flow/request.ex @@ -18,6 +18,7 @@ defmodule Openflow.Multipart.Flow.Request do def ofp_type, do: 18 def new(options \\ []) do + xid = Keyword.get(options, :xid, 0) table_id = Keyword.get(options, :table_id, :all) out_port = Keyword.get(options, :out_port, :any) out_group = Keyword.get(options, :out_group, :any) @@ -26,6 +27,7 @@ defmodule Openflow.Multipart.Flow.Request do match = Keyword.get(options, :match, Openflow.Match.new()) %Request{ + xid: xid, table_id: table_id, out_port: out_port, out_group: out_group, diff --git a/lib/openflow/multipart/group/ *Minibuf-1* b/lib/openflow/multipart/group/ *Minibuf-1* deleted file mode 100644 index 04e6d8d..0000000 --- a/lib/openflow/multipart/group/ *Minibuf-1* +++ /dev/null @@ -1 +0,0 @@ -Replace regexp Queue with: Group \ No newline at end of file diff --git a/lib/openflow/multipart/group/.# *Minibuf-1* b/lib/openflow/multipart/group/.# *Minibuf-1* deleted file mode 120000 index 7cdb737..0000000 --- a/lib/openflow/multipart/group/.# *Minibuf-1* +++ /dev/null @@ -1 +0,0 @@ -shun159@shun159.8967:1509553730 \ No newline at end of file diff --git a/lib/openflow/multipart/group/request.ex b/lib/openflow/multipart/group/request.ex index bc7130c..30103d8 100644 --- a/lib/openflow/multipart/group/request.ex +++ b/lib/openflow/multipart/group/request.ex @@ -12,7 +12,14 @@ defmodule Openflow.Multipart.Group.Request do def ofp_type, do: 18 - def new(group_id \\ :all) do + def new(options) when is_list(options) do + %Request{ + xid: options[:xid] || 0, + group_id: options[:group_id] || :all + } + end + + def new(group_id) when is_integer(group_id) or is_atom(group_id) do %Request{group_id: group_id} end diff --git a/lib/openflow/multipart/group_desc/request.ex b/lib/openflow/multipart/group_desc/request.ex index 7fda473..c8c3dae 100644 --- a/lib/openflow/multipart/group_desc/request.ex +++ b/lib/openflow/multipart/group_desc/request.ex @@ -11,8 +11,8 @@ defmodule Openflow.Multipart.GroupDesc.Request do def ofp_type, do: 18 - def new do - %Request{} + def new(xid \\ 0) do + %Request{xid: xid} end def read("") do diff --git a/lib/openflow/multipart/group_features/request.ex b/lib/openflow/multipart/group_features/request.ex index b44c0dd..e473878 100644 --- a/lib/openflow/multipart/group_features/request.ex +++ b/lib/openflow/multipart/group_features/request.ex @@ -11,8 +11,8 @@ defmodule Openflow.Multipart.GroupFeatures.Request do def ofp_type, do: 18 - def new do - %Request{} + def new(xid \\ 0) do + %Request{xid: xid} end def read("") do diff --git a/lib/openflow/multipart/meter/request.ex b/lib/openflow/multipart/meter/request.ex index 084b2fb..ea7bbdf 100644 --- a/lib/openflow/multipart/meter/request.ex +++ b/lib/openflow/multipart/meter/request.ex @@ -12,10 +12,17 @@ defmodule Openflow.Multipart.Meter.Request do def ofp_type, do: 18 - def new(meter_id \\ :all) do + def new(meter_id) when is_integer(meter_id) or is_atom(meter_id) do %Request{meter_id: meter_id} end + def new(options) when is_list(options) do + %Request{ + xid: options[:xid] || 0, + meter_id: options[:meter_id] || :all + } + end + def read(<>) do meter_id = Openflow.Utils.get_enum(meter_id_int, :meter_id) %Request{meter_id: meter_id} diff --git a/lib/openflow/multipart/meter_config/request.ex b/lib/openflow/multipart/meter_config/request.ex index afd7dd1..bd4c7a2 100644 --- a/lib/openflow/multipart/meter_config/request.ex +++ b/lib/openflow/multipart/meter_config/request.ex @@ -12,10 +12,17 @@ defmodule Openflow.Multipart.MeterConfig.Request do def ofp_type, do: 18 - def new(meter_id \\ :all) do + def new(meter_id) when is_integer(meter_id) or is_atom(meter_id) do %Request{meter_id: meter_id} end + def new(options) when is_list(options) do + %Request{ + xid: options[:xid] || 0, + meter_id: options[:meter_id] || :all + } + end + def read(<>) do meter_id = Openflow.Utils.get_enum(meter_id_int, :meter_id) %Request{meter_id: meter_id} diff --git a/lib/openflow/multipart/port_desc/request.ex b/lib/openflow/multipart/port_desc/request.ex index e6bfe44..2a029f3 100644 --- a/lib/openflow/multipart/port_desc/request.ex +++ b/lib/openflow/multipart/port_desc/request.ex @@ -11,8 +11,8 @@ defmodule Openflow.Multipart.PortDesc.Request do def ofp_type, do: 18 - def new do - %Request{} + def new(xid \\ 0) do + %Request{xid: xid} end def read("") do diff --git a/lib/openflow/multipart/port_stats/request.ex b/lib/openflow/multipart/port_stats/request.ex index 6b91648..ba85c04 100644 --- a/lib/openflow/multipart/port_stats/request.ex +++ b/lib/openflow/multipart/port_stats/request.ex @@ -12,10 +12,17 @@ defmodule Openflow.Multipart.PortStats.Request do def ofp_type, do: 18 - def new(port_no \\ :any) do + def new(port_no) when is_integer(port_no) or is_atom(port_no) do %Request{port_number: port_no} end + def new(options) when is_list(options) do + %Request{ + xid: options[:xid] || 0, + port_number: options[:port_no] || :any + } + end + def read(<>) do port_no = Openflow.Utils.get_enum(port_no_int, :openflow13_port_no) %Request{port_number: port_no} diff --git a/lib/openflow/multipart/queue/request.ex b/lib/openflow/multipart/queue/request.ex index 7cab958..4240ede 100644 --- a/lib/openflow/multipart/queue/request.ex +++ b/lib/openflow/multipart/queue/request.ex @@ -14,9 +14,10 @@ defmodule Openflow.Multipart.Queue.Request do def ofp_type, do: 18 def new(options) do + xid = Keyword.get(options, :xid, 0) 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} + %Request{xid: xid, port_number: port_no, queue_id: queue_id} end def read(<>) do diff --git a/lib/openflow/multipart/table/request.ex b/lib/openflow/multipart/table/request.ex index 39938c2..1e0390d 100644 --- a/lib/openflow/multipart/table/request.ex +++ b/lib/openflow/multipart/table/request.ex @@ -11,8 +11,8 @@ defmodule Openflow.Multipart.Table.Request do def ofp_type, do: 18 - def new do - %Request{} + def new(xid \\ 0) do + %Request{xid: xid} end def read("") do diff --git a/lib/openflow/multipart/table_features/request.ex b/lib/openflow/multipart/table_features/request.ex index b4b9fad..451977d 100644 --- a/lib/openflow/multipart/table_features/request.ex +++ b/lib/openflow/multipart/table_features/request.ex @@ -14,8 +14,11 @@ defmodule Openflow.Multipart.TableFeatures.Request do def ofp_type, do: 18 - def new(tables \\ []) do - %Request{tables: tables} + def new(options \\ []) do + %Request{ + xid: options[:xid] || 0, + tables: options[:tables] || [] + } end def read(<>) do diff --git a/lib/openflow/role/request.ex b/lib/openflow/role/request.ex index fcb66f1..3bacde8 100644 --- a/lib/openflow/role/request.ex +++ b/lib/openflow/role/request.ex @@ -15,9 +15,10 @@ defmodule Openflow.Role.Request do def ofp_type, do: 24 def new(options \\ []) do + xid = Keyword.get(options, :xid, 0) role = Keyword.get(options, :role, :nochange) generation_id = Keyword.get(options, :generation_id, 0) - %Request{role: role, generation_id: generation_id} + %Request{xid: xid, role: role, generation_id: generation_id} end def read(<>) do diff --git a/lib/openflow/set_async.ex b/lib/openflow/set_async.ex index 717d644..f42095b 100644 --- a/lib/openflow/set_async.ex +++ b/lib/openflow/set_async.ex @@ -18,6 +18,18 @@ defmodule Openflow.SetAsync do def ofp_type, do: 28 + def new(options \\ []) do + %SetAsync{ + xid: options[:xid] || 0, + packet_in_mask_master: options[:packet_in_mask_master], + packet_in_mask_slave: options[:packet_in_mask_slave], + port_status_mask_master: options[:port_status_mask_master], + port_status_mask_slave: options[:port_status_mask_slave], + flow_removed_mask_master: options[:flow_removed_mask_master], + flow_removed_mask_slave: options[:flow_removed_mask_slave] + } + end + def read( <> diff --git a/lib/openflow/set_config.ex b/lib/openflow/set_config.ex index 18f3a8c..95929a8 100644 --- a/lib/openflow/set_config.ex +++ b/lib/openflow/set_config.ex @@ -14,9 +14,10 @@ defmodule Openflow.SetConfig do def ofp_type, do: 9 def new(options \\ []) do + xid = Keyword.get(options, :xid, 0) flags = Keyword.get(options, :flags, []) miss_send_len = Keyword.get(options, :miss_send_len, :no_buffer) - %SetConfig{flags: flags, miss_send_len: miss_send_len} + %SetConfig{xid: xid, flags: flags, miss_send_len: miss_send_len} end def read(<>) do diff --git a/lib/openflow/table_mod.ex b/lib/openflow/table_mod.ex index 2ea364a..1f6adb4 100644 --- a/lib/openflow/table_mod.ex +++ b/lib/openflow/table_mod.ex @@ -12,7 +12,13 @@ defmodule Openflow.TableMod do def ofp_type, do: 17 - def new(table_id) do + def new(options) when is_list(options) do + %TableMod{ + xid: options[:xid] || 0, + table_id: options[:table_id] || 0 + } + end + def new(table_id) when is_integer(table_id) or is_atom(table_id) do %TableMod{table_id: table_id} end diff --git a/lib/tres/message_helper.ex b/lib/tres/message_helper.ex index 0c7946e..8a6dc4a 100644 --- a/lib/tres/message_helper.ex +++ b/lib/tres/message_helper.ex @@ -24,6 +24,7 @@ defmodule Tres.MessageHelper do command = Tres.Utils.flow_command(:modify, options) flow_mod = %Openflow.FlowMod{ + xid: options[:xid] || 0, cookie: options[:cookie] || 0, table_id: options[:table_id] || 0, command: command, @@ -42,6 +43,7 @@ defmodule Tres.MessageHelper do command = Tres.Utils.flow_command(:delete, options) flow_mod = %Openflow.FlowMod{ + xid: options[:xid] || 0, cookie: options[:cookie] || 0, cookie_mask: options[:cookie_mask] || 0, table_id: options[:table_id] || :all, @@ -56,6 +58,7 @@ defmodule Tres.MessageHelper do defp send_packet_out(datapath_id, options \\ []) do packet_out = %Openflow.PacketOut{ + xid: options[:xid] || 0, buffer_id: options[:buffer_id] || :no_buffer, in_port: options[:in_port] || :controller, actions: options[:actions] || [], @@ -68,6 +71,7 @@ defmodule Tres.MessageHelper do defp send_group_mod_add(datapath_id, options \\ []) do group_mod = Openflow.GroupMod.new( + xid: options[:xid] || 0, command: :add, type: options[:type] || :all, group_id: options[:group_id] || 0, @@ -77,14 +81,19 @@ defmodule Tres.MessageHelper do send_message(group_mod, datapath_id) end - defp send_group_mod_delete(datapath_id, group_id) do - group_mod = Openflow.GroupMod.new(command: :delete, group_id: group_id) + defp send_group_mod_delete(datapath_id, options \\ []) do + group_mod = Openflow.GroupMod.new( + xid: options[:xid] || 0, + command: :delete, + group_id: options[:group_id] || :all + ) send_message(group_mod, datapath_id) end - defp send_group_mod_modify(datapath_id, options) do + defp send_group_mod_modify(datapath_id, options \\ []) do group_mod = Openflow.GroupMod.new( + xid: options[:xid] || 0, command: :modify, type: options[:type] || :all, group_id: options[:group_id] || 0, @@ -97,6 +106,7 @@ defmodule Tres.MessageHelper do defp send_role_request(datapath_id, options) do role_request = Openflow.Role.Request.new( + xid: options[:xid] || 0, role: options[:role] || :nochange, generation_id: options[:generation_id] || 0 )