openflow/learn_flow_spec: Fix to use src field if dst field is omitted, as dst field.

This commit is contained in:
Eishun Kondoh 2019-07-24 02:05:39 +09:00
parent 6ce014ea91
commit 6dc3cfd500
3 changed files with 34 additions and 33 deletions

View file

@ -56,29 +56,7 @@ defmodule NxLearningSwitch do
send_flow_mod_add(
datapath_id,
table_id: 0,
instructions: ApplyActions.new([
NxLearn.new(
table_id: 1,
priority: 2,
hard_timeout: 10,
flow_specs: [
NxFlowSpecMatch.new(
src: :eth_src,
dst: :eth_dst
),
NxFlowSpecMatch.new(
src: :vlan_vid,
dst: :vlan_vid,
offset: 0,
n_bits: 12
),
NxFlowSpecOutput.new(
src: :nx_in_port
)
]
),
NxResubmitTable.new(1)
])
instructions: l2_learning_instr()
)
end
@ -90,4 +68,28 @@ defmodule NxLearningSwitch do
instructions: ApplyActions.new(Output.new(:flood))
)
end
defp l2_learning_instr do
ApplyActions.new([
l2_learning_action(),
NxResubmitTable.new(1)
])
end
defp l2_learning_action do
NxLearn.new(
table_id: 1,
priority: 2,
hard_timeout: 10,
flow_specs: l2_learning_flow_specs()
)
end
defp l2_learning_flow_specs do
[
NxFlowSpecMatch.new(src: :eth_src, dst: :eth_dst),
NxFlowSpecMatch.new(src: :vlan_vid, n_bits: 12),
NxFlowSpecOutput.new(src: :nx_in_port)
]
end
end

View file

@ -29,8 +29,8 @@ defmodule Openflow.Action.NxFlowSpecMatch do
dst_offset: non_neg_integer()
) :: t()
def new(options \\ []) do
dst = options[:dst] || raise ":dst must be specified"
src = options[:src] || raise ":src must be specified"
dst = options[:dst] || src
n_bits = options[:n_bits] || Openflow.Match.n_bits_of(dst)
%NxFlowSpecMatch{

View file

@ -741,7 +741,7 @@ defmodule OfpActionTest do
fin_idle_timeout: 2,
fin_hard_timeout: 4,
flow_specs: [
Openflow.Action.NxFlowSpecMatch.new(src: :nx_vlan_tci, dst: :nx_vlan_tci, n_bits: 12),
Openflow.Action.NxFlowSpecMatch.new(src: :nx_vlan_tci, n_bits: 12),
Openflow.Action.NxFlowSpecMatch.new(src: :nx_eth_src, dst: :nx_eth_dst),
Openflow.Action.NxFlowSpecOutput.new(src: :nx_in_port)
]
@ -773,7 +773,7 @@ defmodule OfpActionTest do
result_dst: :reg0,
result_dst_offset: 8,
flow_specs: [
Openflow.Action.NxFlowSpecMatch.new(src: :nx_vlan_tci, dst: :nx_vlan_tci, n_bits: 12),
Openflow.Action.NxFlowSpecMatch.new(src: :nx_vlan_tci, n_bits: 12),
Openflow.Action.NxFlowSpecMatch.new(src: :nx_eth_src, dst: :nx_eth_dst),
Openflow.Action.NxFlowSpecOutput.new(src: :nx_in_port)
]
@ -846,22 +846,21 @@ defmodule OfpActionTest do
end
test "with no option" do
assert_raise RuntimeError, ":dst must be specified", fn ->
assert_raise RuntimeError, ":src must be specified", fn ->
Openflow.Action.NxFlowSpecMatch.new()
end
end
test "with no dst option" do
assert_raise RuntimeError, ":dst must be specified", fn ->
Openflow.Action.NxFlowSpecMatch.new(src: :in_port)
end
end
test "with no src option" do
assert_raise RuntimeError, ":src must be specified", fn ->
Openflow.Action.NxFlowSpecMatch.new(dst: :reg0)
end
end
test "with no dst option" do
learn = Openflow.Action.NxFlowSpecMatch.new(src: :in_port)
assert learn.dst == :in_port
end
end
describe "Openflow.Action.NxFlowSpecLoad" do