Formatted
This commit is contained in:
parent
5fc01a9bec
commit
7635272fbd
150 changed files with 5055 additions and 4032 deletions
81
test/flay.ex
81
test/flay.ex
|
|
@ -5,13 +5,11 @@ defmodule Flay do
|
|||
import Logger
|
||||
|
||||
defmodule State do
|
||||
defstruct [
|
||||
datapath_id: nil,
|
||||
tester_pid: nil,
|
||||
conn_ref: nil,
|
||||
reply_to: nil,
|
||||
default_profile: nil,
|
||||
]
|
||||
defstruct datapath_id: nil,
|
||||
tester_pid: nil,
|
||||
conn_ref: nil,
|
||||
reply_to: nil,
|
||||
default_profile: nil
|
||||
end
|
||||
|
||||
def start_link(datapath, args) do
|
||||
|
|
@ -26,32 +24,37 @@ defmodule Flay do
|
|||
end
|
||||
|
||||
def handle_call(:port_desc_stats, from, state) do
|
||||
send_message(PortDesc.Request.new, state.datapath_id)
|
||||
{:noreply, %{state|reply_to: from}}
|
||||
send_message(PortDesc.Request.new(), state.datapath_id)
|
||||
{:noreply, %{state | reply_to: from}}
|
||||
end
|
||||
|
||||
def handle_call(:flow_stats, from, state) do
|
||||
send_message(Flow.Request.new, state.datapath_id)
|
||||
{:noreply, %{state|reply_to: from}}
|
||||
send_message(Flow.Request.new(), state.datapath_id)
|
||||
{:noreply, %{state | reply_to: from}}
|
||||
end
|
||||
|
||||
def handle_cast(:desc_stats, state) do
|
||||
send_message(Desc.Request.new, state.datapath_id)
|
||||
send_message(Desc.Request.new(), state.datapath_id)
|
||||
{:noreply, state}
|
||||
end
|
||||
|
||||
def handle_cast({:register_pid, tester_pid}, state) do
|
||||
{:noreply, %{state|tester_pid: tester_pid}}
|
||||
{:noreply, %{state | tester_pid: tester_pid}}
|
||||
end
|
||||
|
||||
def handle_cast({:flow_install, flow_opts, tester_pid}, state) do
|
||||
send_flow_mod_add(state.datapath_id, flow_opts)
|
||||
flow_opts_to_ofp_print(flow_opts)
|
||||
{:noreply, %{state|tester_pid: tester_pid}}
|
||||
{:noreply, %{state | tester_pid: tester_pid}}
|
||||
end
|
||||
|
||||
def handle_cast(:flow_del, state) do
|
||||
send_flow_mod_delete(state.datapath_id)
|
||||
{:noreply, state}
|
||||
end
|
||||
|
||||
def handle_cast({:flow_del, cookie}, state) do
|
||||
send_flow_mod_delete(state.datapath_id, cookie: cookie, cookie_mask: 0xffffffffffffffff)
|
||||
send_flow_mod_delete(state.datapath_id, cookie: cookie, cookie_mask: 0xFFFFFFFFFFFFFFFF)
|
||||
{:noreply, state}
|
||||
end
|
||||
|
||||
|
|
@ -59,31 +62,36 @@ defmodule Flay do
|
|||
send(state.tester_pid, error)
|
||||
{:noreply, state}
|
||||
end
|
||||
|
||||
def handle_info(%PacketIn{} = pktin, state) do
|
||||
send(state.tester_pid, pktin)
|
||||
{:noreply, state}
|
||||
end
|
||||
|
||||
def handle_info(%TableFeatures.Reply{} = table, state) do
|
||||
{:noreply, %{state|default_profile: table}}
|
||||
{:noreply, %{state | default_profile: table}}
|
||||
end
|
||||
|
||||
def handle_info(%PortDesc.Reply{} = desc, state) do
|
||||
GenServer.reply(state.reply_to, desc)
|
||||
{:noreply, state}
|
||||
end
|
||||
|
||||
def handle_info(%Desc.Reply{} = desc, state) do
|
||||
info(
|
||||
"[#{__MODULE__}] Switch Desc: "
|
||||
<> "mfr = #{desc.mfr_desc} "
|
||||
<> "hw = #{desc.hw_desc} "
|
||||
<> "sw = #{desc.sw_desc} "
|
||||
"[#{__MODULE__}] Switch Desc: " <>
|
||||
"mfr = #{desc.mfr_desc} " <> "hw = #{desc.hw_desc} " <> "sw = #{desc.sw_desc} "
|
||||
)
|
||||
|
||||
init_bridge(state.datapath_id, desc)
|
||||
{:noreply, state}
|
||||
end
|
||||
|
||||
def handle_info(%Flow.Reply{} = desc, state) do
|
||||
GenServer.reply(state.reply_to, desc)
|
||||
{:noreply, %{state|reply_to: nil}}
|
||||
{:noreply, %{state | reply_to: nil}}
|
||||
end
|
||||
|
||||
# `Catch all` function is required.
|
||||
def handle_info(info, state) do
|
||||
:ok = warn("[#{__MODULE__}] unhandled message #{inspect(info)}")
|
||||
|
|
@ -94,11 +102,11 @@ defmodule Flay do
|
|||
|
||||
defp flow_opts_to_ofp_print(flow_opts) do
|
||||
flow_opts
|
||||
|> FlowMod.new
|
||||
|> Openflow.to_binary
|
||||
|> FlowMod.new()
|
||||
|> Openflow.to_binary()
|
||||
|> binary_to_space_delimited_hex
|
||||
|> ofp_print_cmd
|
||||
|> Logger.info
|
||||
|> Logger.info()
|
||||
end
|
||||
|
||||
defp ofp_print_cmd(print_args) do
|
||||
|
|
@ -110,7 +118,7 @@ defmodule Flay do
|
|||
binary
|
||||
|> split_to_hex_string
|
||||
|> Enum.join(" ")
|
||||
|> String.downcase
|
||||
|> String.downcase()
|
||||
end
|
||||
|
||||
defp split_to_hex_string(binary) do
|
||||
|
|
@ -120,24 +128,26 @@ defmodule Flay do
|
|||
defp integer_to_hex(int) do
|
||||
case Integer.to_string(int, 16) do
|
||||
<<d>> -> <<48, d>>
|
||||
dd -> dd
|
||||
dd -> dd
|
||||
end
|
||||
end
|
||||
|
||||
defp init_controller([datapath_id, tester_pid]) do
|
||||
conn_ref = SwitchRegistry.monitor(datapath_id)
|
||||
|
||||
%State{
|
||||
datapath_id: datapath_id,
|
||||
tester_pid: tester_pid,
|
||||
conn_ref: conn_ref
|
||||
tester_pid: tester_pid,
|
||||
conn_ref: conn_ref
|
||||
}
|
||||
end
|
||||
|
||||
defp init_bridge(datapath_id, %Desc.Reply{mfr_desc: "Aruba"}) do
|
||||
:ok = info("Transform flow table pipeline")
|
||||
|
||||
tables = [
|
||||
TableFeatures.Body.new(
|
||||
table_id: 0,
|
||||
table_id: 0,
|
||||
name: "classifier",
|
||||
max_entries: 50,
|
||||
config: [:table_miss_mask],
|
||||
|
|
@ -161,7 +171,7 @@ defmodule Flay do
|
|||
:ip_proto,
|
||||
:ipv4_src,
|
||||
:udp_dst,
|
||||
:tcp_dst,
|
||||
:tcp_dst
|
||||
],
|
||||
instructions: [
|
||||
Openflow.Instruction.GotoTable,
|
||||
|
|
@ -178,11 +188,11 @@ defmodule Flay do
|
|||
:vlan_vid
|
||||
],
|
||||
next_tables: [
|
||||
1,
|
||||
],
|
||||
1
|
||||
]
|
||||
),
|
||||
TableFeatures.Body.new(
|
||||
table_id: 1,
|
||||
table_id: 1,
|
||||
name: "admission_control",
|
||||
max_entries: 50,
|
||||
config: [:table_miss_mask],
|
||||
|
|
@ -223,13 +233,16 @@ defmodule Flay do
|
|||
:vlan_vid,
|
||||
:ipv4_src,
|
||||
:ipv4_dst
|
||||
],
|
||||
]
|
||||
)
|
||||
]
|
||||
|
||||
TableFeatures.Request.new(tables)
|
||||
|> send_message(datapath_id)
|
||||
|
||||
send_flow_mod_delete(datapath_id, table_id: :all)
|
||||
end
|
||||
|
||||
defp init_bridge(_datapath_id, _mfr) do
|
||||
:ok = info("Flow pipeline profile is not defined")
|
||||
:ok
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -6,11 +6,13 @@ defmodule OfpActionTest do
|
|||
test_file = "test/packet_data/nx_bundle.raw"
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
|
||||
bundle =
|
||||
Openflow.Action.NxBundle.new(
|
||||
algorithm: :highest_random_weight,
|
||||
slaves: [4, 8]
|
||||
slaves: [4, 8]
|
||||
)
|
||||
|
||||
actions_bin = Openflow.Action.to_binary(bundle)
|
||||
assert actions_bin == packet
|
||||
assert actions == [bundle]
|
||||
|
|
@ -20,12 +22,14 @@ defmodule OfpActionTest do
|
|||
test_file = "test/packet_data/nx_bundle_load.raw"
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
|
||||
bundle_load =
|
||||
Openflow.Action.NxBundleLoad.new(
|
||||
algorithm: :highest_random_weight,
|
||||
slaves: [4, 8],
|
||||
dst_field: :reg0
|
||||
)
|
||||
|
||||
actions_bin = Openflow.Action.to_binary(bundle_load)
|
||||
assert actions_bin == packet
|
||||
assert actions == [bundle_load]
|
||||
|
|
@ -35,11 +39,14 @@ defmodule OfpActionTest do
|
|||
test_file = "test/packet_data/nx_controller.raw"
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
controller = Openflow.Action.NxController.new(
|
||||
max_len: 1234,
|
||||
reason: :invalid_ttl,
|
||||
id: 5678
|
||||
)
|
||||
|
||||
controller =
|
||||
Openflow.Action.NxController.new(
|
||||
max_len: 1234,
|
||||
reason: :invalid_ttl,
|
||||
id: 5678
|
||||
)
|
||||
|
||||
actions_bin = Openflow.Action.to_binary(controller)
|
||||
assert actions_bin == packet
|
||||
assert actions == [controller]
|
||||
|
|
@ -49,12 +56,15 @@ defmodule OfpActionTest do
|
|||
test_file = "test/packet_data/nx_controller2.raw"
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
controller2 = Openflow.Action.NxController2.new(
|
||||
max_len: 1234,
|
||||
reason: :invalid_ttl,
|
||||
userdata: <<1,2,3,4,5>>,
|
||||
pause: true
|
||||
)
|
||||
|
||||
controller2 =
|
||||
Openflow.Action.NxController2.new(
|
||||
max_len: 1234,
|
||||
reason: :invalid_ttl,
|
||||
userdata: <<1, 2, 3, 4, 5>>,
|
||||
pause: true
|
||||
)
|
||||
|
||||
assert actions == [controller2]
|
||||
end
|
||||
|
||||
|
|
@ -102,13 +112,19 @@ defmodule OfpActionTest do
|
|||
test "with ct(commit,exec(load:0->NXM_NX_CT_LABEL[64..127],load:0x1d->NXM_NX_CT_LABEL[0..63]))" do
|
||||
test_file =
|
||||
"test/packet_data/nx_ct(commit,exec(load:0->NXM_NX_CT_LABEL[64..127],load:0x1d->NXM_NX_CT_LABEL[0..63])).raw"
|
||||
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
ct = Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit],
|
||||
exec: [Openflow.Action.NxRegLoad.new(dst_field: :ct_label, value: 0, offset: 64, n_bits: 64),
|
||||
Openflow.Action.NxRegLoad.new(dst_field: :ct_label, value: 0x1d, n_bits: 64)]
|
||||
)
|
||||
|
||||
ct =
|
||||
Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit],
|
||||
exec: [
|
||||
Openflow.Action.NxRegLoad.new(dst_field: :ct_label, value: 0, offset: 64, n_bits: 64),
|
||||
Openflow.Action.NxRegLoad.new(dst_field: :ct_label, value: 0x1D, n_bits: 64)
|
||||
]
|
||||
)
|
||||
|
||||
actions_bin = Openflow.Action.to_binary(ct)
|
||||
assert actions_bin == packet
|
||||
assert actions == [ct]
|
||||
|
|
@ -118,10 +134,13 @@ defmodule OfpActionTest do
|
|||
test_file = "test/packet_data/nx_ct(commit,exec(load:0xf009->NXM_NX_CT_MARK[])).raw"
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
ct = Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit],
|
||||
exec: [Openflow.Action.NxRegLoad.new(dst_field: :ct_mark, value: 0xf009)]
|
||||
)
|
||||
|
||||
ct =
|
||||
Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit],
|
||||
exec: [Openflow.Action.NxRegLoad.new(dst_field: :ct_mark, value: 0xF009)]
|
||||
)
|
||||
|
||||
actions_bin = Openflow.Action.to_binary(ct)
|
||||
assert actions_bin == packet
|
||||
assert actions == [ct]
|
||||
|
|
@ -131,10 +150,13 @@ defmodule OfpActionTest do
|
|||
test_file = "test/packet_data/nx_ct(commit,force,exec(load:0xf009->NXM_NX_CT_MARK[])).raw"
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
ct = Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit, :force],
|
||||
exec: [Openflow.Action.NxRegLoad.new(dst_field: :ct_mark, value: 0xf009)]
|
||||
)
|
||||
|
||||
ct =
|
||||
Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit, :force],
|
||||
exec: [Openflow.Action.NxRegLoad.new(dst_field: :ct_mark, value: 0xF009)]
|
||||
)
|
||||
|
||||
actions_bin = Openflow.Action.to_binary(ct)
|
||||
assert actions_bin == packet
|
||||
assert actions == [ct]
|
||||
|
|
@ -144,10 +166,13 @@ defmodule OfpActionTest do
|
|||
test_file = "test/packet_data/nx_ct(commit,nat(dst)).raw"
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
ct = Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit],
|
||||
exec: [Openflow.Action.NxNat.new(flags: [:dst])]
|
||||
)
|
||||
|
||||
ct =
|
||||
Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit],
|
||||
exec: [Openflow.Action.NxNat.new(flags: [:dst])]
|
||||
)
|
||||
|
||||
actions_bin = Openflow.Action.to_binary(ct)
|
||||
assert actions_bin == packet
|
||||
assert actions == [ct]
|
||||
|
|
@ -159,16 +184,19 @@ defmodule OfpActionTest do
|
|||
actions = Openflow.Action.read(packet)
|
||||
{:ok, ipv4_min} = :inet.parse_ipv4_address('10.0.0.128')
|
||||
{:ok, ipv4_max} = :inet.parse_ipv4_address('10.0.0.254')
|
||||
ct = Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit],
|
||||
exec: [
|
||||
Openflow.Action.NxNat.new(
|
||||
flags: [:dst, :protocol_hash],
|
||||
ipv4_min: ipv4_min,
|
||||
ipv4_max: ipv4_max
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
ct =
|
||||
Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit],
|
||||
exec: [
|
||||
Openflow.Action.NxNat.new(
|
||||
flags: [:dst, :protocol_hash],
|
||||
ipv4_min: ipv4_min,
|
||||
ipv4_max: ipv4_max
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
actions_bin = Openflow.Action.to_binary(ct)
|
||||
assert actions_bin == packet
|
||||
assert actions == [ct]
|
||||
|
|
@ -178,10 +206,13 @@ defmodule OfpActionTest do
|
|||
test_file = "test/packet_data/nx_ct(commit,nat(src)).raw"
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
ct = Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit],
|
||||
exec: [Openflow.Action.NxNat.new(flags: [:src])]
|
||||
)
|
||||
|
||||
ct =
|
||||
Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit],
|
||||
exec: [Openflow.Action.NxNat.new(flags: [:src])]
|
||||
)
|
||||
|
||||
actions_bin = Openflow.Action.to_binary(ct)
|
||||
assert actions_bin == packet
|
||||
assert actions == [ct]
|
||||
|
|
@ -192,38 +223,46 @@ defmodule OfpActionTest do
|
|||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
{:ok, ipv4_min} = :inet.parse_ipv4_address('10.0.0.240')
|
||||
ct = Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit],
|
||||
exec: [
|
||||
Openflow.Action.NxNat.new(
|
||||
flags: [:src, :protocol_random],
|
||||
ipv4_min: ipv4_min
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
ct =
|
||||
Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit],
|
||||
exec: [
|
||||
Openflow.Action.NxNat.new(
|
||||
flags: [:src, :protocol_random],
|
||||
ipv4_min: ipv4_min
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
actions_bin = Openflow.Action.to_binary(ct)
|
||||
assert actions_bin == packet
|
||||
assert actions == [ct]
|
||||
end
|
||||
|
||||
test "with ct(commit,nat(src=10.0.0.240-10.0.0.254:32768-65535,persistent))" do
|
||||
test_file = "test/packet_data/nx_ct(commit,nat(src=10.0.0.240-10.0.0.254:32768-65535,persistent)).raw"
|
||||
test_file =
|
||||
"test/packet_data/nx_ct(commit,nat(src=10.0.0.240-10.0.0.254:32768-65535,persistent)).raw"
|
||||
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
{:ok, ipv4_min} = :inet.parse_ipv4_address('10.0.0.240')
|
||||
{:ok, ipv4_max} = :inet.parse_ipv4_address('10.0.0.254')
|
||||
ct = Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit],
|
||||
exec: [
|
||||
Openflow.Action.NxNat.new(
|
||||
flags: [:src, :persistent],
|
||||
ipv4_min: ipv4_min,
|
||||
ipv4_max: ipv4_max,
|
||||
proto_min: 32_768,
|
||||
proto_max: 65_535
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
ct =
|
||||
Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit],
|
||||
exec: [
|
||||
Openflow.Action.NxNat.new(
|
||||
flags: [:src, :persistent],
|
||||
ipv4_min: ipv4_min,
|
||||
ipv4_max: ipv4_max,
|
||||
proto_min: 32_768,
|
||||
proto_max: 65_535
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
actions_bin = Openflow.Action.to_binary(ct)
|
||||
assert actions_bin == packet
|
||||
assert actions == [ct]
|
||||
|
|
@ -234,61 +273,74 @@ defmodule OfpActionTest do
|
|||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
{:ok, ipv4_min} = :inet.parse_ipv4_address('10.0.0.240')
|
||||
ct = Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit],
|
||||
exec: [
|
||||
Openflow.Action.NxNat.new(
|
||||
flags: [:src, :protocol_random],
|
||||
ipv4_min: ipv4_min,
|
||||
proto_min: 32_768,
|
||||
proto_max: 65_535
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
ct =
|
||||
Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit],
|
||||
exec: [
|
||||
Openflow.Action.NxNat.new(
|
||||
flags: [:src, :protocol_random],
|
||||
ipv4_min: ipv4_min,
|
||||
proto_min: 32_768,
|
||||
proto_max: 65_535
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
actions_bin = Openflow.Action.to_binary(ct)
|
||||
assert actions_bin == packet
|
||||
assert actions == [ct]
|
||||
end
|
||||
|
||||
test "with ct(commit,nat(src=[fe80::20c:29ff:fe88:1]-[fe80::20c:29ff:fe88:a18b]:255-4096,random))" do
|
||||
test_file = "test/packet_data/nx_ct(commit,nat(src=[fe80::20c:29ff:fe88:1]-[fe80::20c:29ff:fe88:a18b]:255-4096,random)).raw"
|
||||
test_file =
|
||||
"test/packet_data/nx_ct(commit,nat(src=[fe80::20c:29ff:fe88:1]-[fe80::20c:29ff:fe88:a18b]:255-4096,random)).raw"
|
||||
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
{:ok, ipv6_min} = :inet.parse_ipv6_address('fe80::20c:29ff:fe88:1')
|
||||
{:ok, ipv6_max} = :inet.parse_ipv6_address('fe80::20c:29ff:fe88:a18b')
|
||||
ct = Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit],
|
||||
exec: [
|
||||
Openflow.Action.NxNat.new(
|
||||
flags: [:src, :protocol_random],
|
||||
ipv6_min: ipv6_min,
|
||||
ipv6_max: ipv6_max,
|
||||
proto_min: 255,
|
||||
proto_max: 4096
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
ct =
|
||||
Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit],
|
||||
exec: [
|
||||
Openflow.Action.NxNat.new(
|
||||
flags: [:src, :protocol_random],
|
||||
ipv6_min: ipv6_min,
|
||||
ipv6_max: ipv6_max,
|
||||
proto_min: 255,
|
||||
proto_max: 4096
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
actions_bin = Openflow.Action.to_binary(ct)
|
||||
assert actions_bin == packet
|
||||
assert actions == [ct]
|
||||
end
|
||||
|
||||
test "with ct(commit,nat(src=fe80::20c:29ff:fe88:1-fe80::20c:29ff:fe88:a18b,random))" do
|
||||
test_file = "test/packet_data/nx_ct(commit,nat(src=fe80::20c:29ff:fe88:1-fe80::20c:29ff:fe88:a18b,random)).raw"
|
||||
test_file =
|
||||
"test/packet_data/nx_ct(commit,nat(src=fe80::20c:29ff:fe88:1-fe80::20c:29ff:fe88:a18b,random)).raw"
|
||||
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
{:ok, ipv6_min} = :inet.parse_ipv6_address('fe80::20c:29ff:fe88:1')
|
||||
{:ok, ipv6_max} = :inet.parse_ipv6_address('fe80::20c:29ff:fe88:a18b')
|
||||
ct = Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit],
|
||||
exec: [
|
||||
Openflow.Action.NxNat.new(
|
||||
flags: [:src, :protocol_random],
|
||||
ipv6_min: ipv6_min,
|
||||
ipv6_max: ipv6_max
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
ct =
|
||||
Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit],
|
||||
exec: [
|
||||
Openflow.Action.NxNat.new(
|
||||
flags: [:src, :protocol_random],
|
||||
ipv6_min: ipv6_min,
|
||||
ipv6_max: ipv6_max
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
actions_bin = Openflow.Action.to_binary(ct)
|
||||
assert actions_bin == packet
|
||||
assert actions == [ct]
|
||||
|
|
@ -299,10 +351,13 @@ defmodule OfpActionTest do
|
|||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
{:ok, ipv6_min} = :inet.parse_ipv6_address('fe80::20c:29ff:fe88:a18b')
|
||||
ct = Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit],
|
||||
exec: [Openflow.Action.NxNat.new(flags: [:src, :protocol_random], ipv6_min: ipv6_min)]
|
||||
)
|
||||
|
||||
ct =
|
||||
Openflow.Action.NxConntrack.new(
|
||||
flags: [:commit],
|
||||
exec: [Openflow.Action.NxNat.new(flags: [:src, :protocol_random], ipv6_min: ipv6_min)]
|
||||
)
|
||||
|
||||
actions_bin = Openflow.Action.to_binary(ct)
|
||||
assert actions_bin == packet
|
||||
assert actions == [ct]
|
||||
|
|
@ -312,7 +367,7 @@ defmodule OfpActionTest do
|
|||
test_file = "test/packet_data/nx_ct(nat).raw"
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
ct = Openflow.Action.NxConntrack.new(exec: [Openflow.Action.NxNat.new])
|
||||
ct = Openflow.Action.NxConntrack.new(exec: [Openflow.Action.NxNat.new()])
|
||||
actions_bin = Openflow.Action.to_binary(ct)
|
||||
assert actions_bin == packet
|
||||
assert actions == [ct]
|
||||
|
|
@ -352,7 +407,7 @@ defmodule OfpActionTest do
|
|||
test_file = "test/packet_data/nx_ct.raw"
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
ct = Openflow.Action.NxConntrack.new
|
||||
ct = Openflow.Action.NxConntrack.new()
|
||||
actions_bin = Openflow.Action.to_binary(ct)
|
||||
assert actions_bin == packet
|
||||
assert actions == [ct]
|
||||
|
|
@ -362,7 +417,7 @@ defmodule OfpActionTest do
|
|||
test_file = "test/packet_data/nx_ct_clear.raw"
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
ct = Openflow.Action.NxCtClear.new
|
||||
ct = Openflow.Action.NxCtClear.new()
|
||||
actions_bin = Openflow.Action.to_binary(ct)
|
||||
assert actions_bin == packet
|
||||
assert actions == [ct]
|
||||
|
|
@ -372,7 +427,7 @@ defmodule OfpActionTest do
|
|||
test_file = "test/packet_data/nx_dec_ttl.raw"
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
dec_ttl = Openflow.Action.NxDecTtl.new
|
||||
dec_ttl = Openflow.Action.NxDecTtl.new()
|
||||
actions_bin = Openflow.Action.to_binary(dec_ttl)
|
||||
assert actions_bin == packet
|
||||
assert actions == [dec_ttl]
|
||||
|
|
@ -392,7 +447,7 @@ defmodule OfpActionTest do
|
|||
test_file = "test/packet_data/nx_exit.raw"
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
exit = Openflow.Action.NxExit.new
|
||||
exit = Openflow.Action.NxExit.new()
|
||||
actions_bin = Openflow.Action.to_binary(exit)
|
||||
assert actions_bin == packet
|
||||
assert actions == [exit]
|
||||
|
|
@ -412,21 +467,24 @@ defmodule OfpActionTest do
|
|||
test_file = "test/packet_data/nx_learn.raw"
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
learn = Openflow.Action.NxLearn.new(
|
||||
idle_timeout: 10,
|
||||
hard_timeout: 20,
|
||||
priority: 80,
|
||||
cookie: 0x123456789abcdef0,
|
||||
flags: [],
|
||||
table_id: 2,
|
||||
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_eth_src, dst: :nx_eth_dst),
|
||||
Openflow.Action.NxFlowSpecOutput.new(src: :nx_in_port)
|
||||
]
|
||||
)
|
||||
|
||||
learn =
|
||||
Openflow.Action.NxLearn.new(
|
||||
idle_timeout: 10,
|
||||
hard_timeout: 20,
|
||||
priority: 80,
|
||||
cookie: 0x123456789ABCDEF0,
|
||||
flags: [],
|
||||
table_id: 2,
|
||||
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_eth_src, dst: :nx_eth_dst),
|
||||
Openflow.Action.NxFlowSpecOutput.new(src: :nx_in_port)
|
||||
]
|
||||
)
|
||||
|
||||
actions_bin = Openflow.Action.to_binary(learn)
|
||||
assert actions_bin == packet
|
||||
assert actions == [learn]
|
||||
|
|
@ -436,24 +494,27 @@ defmodule OfpActionTest do
|
|||
test_file = "test/packet_data/nx_learn2.raw"
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
learn2 = Openflow.Action.NxLearn2.new(
|
||||
idle_timeout: 10,
|
||||
hard_timeout: 20,
|
||||
priority: 80,
|
||||
cookie: 0x123456789abcdef0,
|
||||
flags: [:write_result],
|
||||
table_id: 2,
|
||||
fin_idle_timeout: 2,
|
||||
fin_hard_timeout: 4,
|
||||
limit: 1,
|
||||
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_eth_src, dst: :nx_eth_dst),
|
||||
Openflow.Action.NxFlowSpecOutput.new(src: :nx_in_port)
|
||||
]
|
||||
)
|
||||
|
||||
learn2 =
|
||||
Openflow.Action.NxLearn2.new(
|
||||
idle_timeout: 10,
|
||||
hard_timeout: 20,
|
||||
priority: 80,
|
||||
cookie: 0x123456789ABCDEF0,
|
||||
flags: [:write_result],
|
||||
table_id: 2,
|
||||
fin_idle_timeout: 2,
|
||||
fin_hard_timeout: 4,
|
||||
limit: 1,
|
||||
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_eth_src, dst: :nx_eth_dst),
|
||||
Openflow.Action.NxFlowSpecOutput.new(src: :nx_in_port)
|
||||
]
|
||||
)
|
||||
|
||||
actions_bin = Openflow.Action.to_binary(learn2)
|
||||
assert actions_bin == packet
|
||||
assert actions == [learn2]
|
||||
|
|
@ -463,11 +524,14 @@ defmodule OfpActionTest do
|
|||
test_file = "test/packet_data/nx_multipath.raw"
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
multipath = Openflow.Action.NxMultipath.new(
|
||||
algorithm: :modulo_n,
|
||||
basis: 50,
|
||||
dst_field: :reg0
|
||||
)
|
||||
|
||||
multipath =
|
||||
Openflow.Action.NxMultipath.new(
|
||||
algorithm: :modulo_n,
|
||||
basis: 50,
|
||||
dst_field: :reg0
|
||||
)
|
||||
|
||||
actions_bin = Openflow.Action.to_binary(multipath)
|
||||
assert actions_bin == packet
|
||||
assert actions == [multipath]
|
||||
|
|
@ -477,7 +541,7 @@ defmodule OfpActionTest do
|
|||
test_file = "test/packet_data/nx_note.raw"
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
note = Openflow.Action.NxNote.new(<<0x11, 0xe9, 0x9a, 0xad, 0x67, 0xf3>>)
|
||||
note = Openflow.Action.NxNote.new(<<0x11, 0xE9, 0x9A, 0xAD, 0x67, 0xF3>>)
|
||||
actions_bin = Openflow.Action.to_binary(note)
|
||||
assert actions_bin == packet
|
||||
assert actions == [note]
|
||||
|
|
@ -507,7 +571,7 @@ defmodule OfpActionTest do
|
|||
test_file = "test/packet_data/nx_pop_queue.raw"
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
pop_queue = Openflow.Action.NxPopQueue.new
|
||||
pop_queue = Openflow.Action.NxPopQueue.new()
|
||||
actions_bin = Openflow.Action.to_binary(pop_queue)
|
||||
assert actions_bin == packet
|
||||
assert actions == [pop_queue]
|
||||
|
|
@ -517,7 +581,7 @@ defmodule OfpActionTest do
|
|||
test_file = "test/packet_data/nx_reg_load.raw"
|
||||
packet = File.read!(test_file)
|
||||
actions = Openflow.Action.read(packet)
|
||||
reg_load = Openflow.Action.NxRegLoad.new(dst_field: :nx_vlan_tci, value: 0xf009)
|
||||
reg_load = Openflow.Action.NxRegLoad.new(dst_field: :nx_vlan_tci, value: 0xF009)
|
||||
actions_bin = Openflow.Action.to_binary(reg_load)
|
||||
assert actions_bin == packet
|
||||
assert actions == [reg_load]
|
||||
|
|
|
|||
|
|
@ -6,8 +6,9 @@ defmodule OfpEchoTest do
|
|||
test "with OFP_ECHO_REQUEST packet" do
|
||||
{:ok, %Openflow.Echo.Request{} = echo, ""} =
|
||||
"test/packet_data/ofp_echo_request.raw"
|
||||
|> File.read!
|
||||
|> Openflow.read
|
||||
|> File.read!()
|
||||
|> Openflow.read()
|
||||
|
||||
assert echo.version == 4
|
||||
assert echo.xid == 0
|
||||
assert echo.data == ""
|
||||
|
|
@ -16,8 +17,9 @@ defmodule OfpEchoTest do
|
|||
test "with OFP_ECHO_REPLY packet" do
|
||||
{:ok, %Openflow.Echo.Reply{} = echo, ""} =
|
||||
"test/packet_data/ofp_echo_reply.raw"
|
||||
|> File.read!
|
||||
|> Openflow.read
|
||||
|> File.read!()
|
||||
|> Openflow.read()
|
||||
|
||||
assert echo.version == 4
|
||||
assert echo.xid == 0
|
||||
assert echo.data == ""
|
||||
|
|
@ -31,9 +33,11 @@ defmodule OfpEchoTest do
|
|||
xid: 0,
|
||||
data: ""
|
||||
}
|
||||
|
||||
expect =
|
||||
"test/packet_data/ofp_echo_request.raw"
|
||||
|> File.read!
|
||||
|> File.read!()
|
||||
|
||||
assert Openflow.to_binary(echo) == expect
|
||||
end
|
||||
|
||||
|
|
@ -43,9 +47,11 @@ defmodule OfpEchoTest do
|
|||
xid: 0,
|
||||
data: ""
|
||||
}
|
||||
|
||||
expect =
|
||||
"test/packet_data/ofp_echo_reply.raw"
|
||||
|> File.read!
|
||||
|> File.read!()
|
||||
|
||||
assert Openflow.to_binary(echo) == expect
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,8 +6,9 @@ defmodule OfpErrorTest do
|
|||
test "with OFP_ERROR packet" do
|
||||
{:ok, error, ""} =
|
||||
"test/packet_data/ofp_error.raw"
|
||||
|> File.read!
|
||||
|> Openflow.read
|
||||
|> File.read!()
|
||||
|> Openflow.read()
|
||||
|
||||
assert error.version == 4
|
||||
assert error.xid == 0
|
||||
assert error.type == :bad_action
|
||||
|
|
@ -19,35 +20,55 @@ defmodule OfpErrorTest do
|
|||
describe "Openflow.to_binary/1" do
|
||||
test "with %Openflow.Error{}" do
|
||||
error = %Openflow.ErrorMsg{
|
||||
version: 4,
|
||||
version: 4,
|
||||
xid: 0,
|
||||
type: :bad_action,
|
||||
code: :unsupported_order,
|
||||
data: "fugafuga",
|
||||
data: "fugafuga"
|
||||
}
|
||||
|
||||
expect =
|
||||
"test/packet_data/ofp_error.raw"
|
||||
|> File.read!
|
||||
|> File.read!()
|
||||
|
||||
assert Openflow.to_binary(error) == expect
|
||||
end
|
||||
|
||||
test "with experimenter %Openflow.Error{}" do
|
||||
error = %Openflow.ErrorMsg{
|
||||
version: 4,
|
||||
version: 4,
|
||||
xid: 0,
|
||||
type: :experimenter,
|
||||
exp_type: 1,
|
||||
experimenter: 0xdeadbeef,
|
||||
data: "hogehoge",
|
||||
experimenter: 0xDEADBEEF,
|
||||
data: "hogehoge"
|
||||
}
|
||||
|
||||
expect = <<
|
||||
4, 1, 0, 24, 0, 0, 0,
|
||||
0, 255, 255, 0, 1, 222,
|
||||
173, 190, 239, 104, 111, 103,
|
||||
101, 104, 111, 103, 101
|
||||
4,
|
||||
1,
|
||||
0,
|
||||
24,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
255,
|
||||
255,
|
||||
0,
|
||||
1,
|
||||
222,
|
||||
173,
|
||||
190,
|
||||
239,
|
||||
104,
|
||||
111,
|
||||
103,
|
||||
101,
|
||||
104,
|
||||
111,
|
||||
103,
|
||||
101
|
||||
>>
|
||||
|
||||
assert Openflow.to_binary(error) == expect
|
||||
|
|
|
|||
|
|
@ -6,8 +6,9 @@ defmodule OfpFeaturesTest do
|
|||
test "with OFP_FEATURES_REQUEST packet" do
|
||||
{:ok, %Openflow.Features.Request{} = features, ""} =
|
||||
"test/packet_data/ofp_features_request.raw"
|
||||
|> File.read!
|
||||
|> Openflow.read
|
||||
|> File.read!()
|
||||
|> Openflow.read()
|
||||
|
||||
assert features.version == 4
|
||||
assert features.xid == 0
|
||||
end
|
||||
|
|
@ -15,15 +16,23 @@ defmodule OfpFeaturesTest do
|
|||
test "with OFP_FEATURES_REPLY packet" do
|
||||
{:ok, %Openflow.Features.Reply{} = features, ""} =
|
||||
"test/packet_data/ofp_features_reply.raw"
|
||||
|> File.read!
|
||||
|> Openflow.read
|
||||
|> File.read!()
|
||||
|> Openflow.read()
|
||||
|
||||
assert features.version == 4
|
||||
assert features.xid == 0
|
||||
assert features.datapath_id == "0000000000000001"
|
||||
assert features.n_buffers == 255
|
||||
assert features.n_tables == 255
|
||||
assert features.aux_id == 0
|
||||
assert features.capabilities == [:flow_stats, :table_stats, :port_stats, :group_stats, :queue_stats]
|
||||
|
||||
assert features.capabilities == [
|
||||
:flow_stats,
|
||||
:table_stats,
|
||||
:port_stats,
|
||||
:group_stats,
|
||||
:queue_stats
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -33,9 +42,11 @@ defmodule OfpFeaturesTest do
|
|||
version: 4,
|
||||
xid: 0
|
||||
}
|
||||
|
||||
expect =
|
||||
"test/packet_data/ofp_features_request.raw"
|
||||
|> File.read!
|
||||
|> File.read!()
|
||||
|
||||
assert Openflow.to_binary(features) == expect
|
||||
end
|
||||
end
|
||||
|
|
@ -48,11 +59,13 @@ defmodule OfpFeaturesTest do
|
|||
n_buffers: 255,
|
||||
n_tables: 255,
|
||||
aux_id: 0,
|
||||
capabilities: [:flow_stats, :table_stats, :port_stats, :group_stats, :queue_stats],
|
||||
capabilities: [:flow_stats, :table_stats, :port_stats, :group_stats, :queue_stats]
|
||||
}
|
||||
|
||||
expect =
|
||||
"test/packet_data/ofp_features_reply.raw"
|
||||
|> File.read!
|
||||
|> File.read!()
|
||||
|
||||
assert Openflow.to_binary(features) == expect
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -23,37 +23,39 @@ defmodule OfpFlowModTest do
|
|||
assert fm.idle_timeout == 0
|
||||
assert fm.hard_timeout == 0
|
||||
assert fm.priority == 123
|
||||
assert fm.buffer_id == 0xffff
|
||||
assert fm.buffer_id == 0xFFFF
|
||||
assert fm.out_port == :any
|
||||
assert fm.out_group == :any
|
||||
assert fm.flags == []
|
||||
assert fm.match == Openflow.Match.new(eth_dst: "f20ba47df8ea")
|
||||
|
||||
assert fm.instructions == [
|
||||
Openflow.Instruction.WriteActions.new([
|
||||
Openflow.Action.SetField.new({:vlan_vid, 258}),
|
||||
Openflow.Action.CopyTtlOut.new,
|
||||
Openflow.Action.CopyTtlIn.new,
|
||||
Openflow.Action.CopyTtlIn.new,
|
||||
Openflow.Action.PopPbb.new,
|
||||
Openflow.Action.PushPbb.new(4660),
|
||||
Openflow.Action.PopMpls.new(39030),
|
||||
Openflow.Action.PushMpls.new(34887),
|
||||
Openflow.Action.PopVlan.new,
|
||||
Openflow.Action.PushVlan.new(33024),
|
||||
Openflow.Action.DecMplsTtl.new,
|
||||
Openflow.Action.SetMplsTtl.new(10),
|
||||
Openflow.Action.DecNwTtl.new,
|
||||
Openflow.Action.SetNwTtl.new(10),
|
||||
Openflow.Action.Experimenter.new(101, <<0, 1, 2, 3, 4, 5, 6, 7>>),
|
||||
Openflow.Action.SetQueue.new(3),
|
||||
Openflow.Action.Group.new(99),
|
||||
Openflow.Action.Output.new(6)
|
||||
]),
|
||||
Openflow.Instruction.ApplyActions.new([
|
||||
Openflow.Action.SetField.new({:eth_src, "010203040506"}),
|
||||
Openflow.Action.SetField.new({:onf_pbb_uca, 1})
|
||||
])
|
||||
]
|
||||
Openflow.Instruction.WriteActions.new([
|
||||
Openflow.Action.SetField.new({:vlan_vid, 258}),
|
||||
Openflow.Action.CopyTtlOut.new(),
|
||||
Openflow.Action.CopyTtlIn.new(),
|
||||
Openflow.Action.CopyTtlIn.new(),
|
||||
Openflow.Action.PopPbb.new(),
|
||||
Openflow.Action.PushPbb.new(4660),
|
||||
Openflow.Action.PopMpls.new(39030),
|
||||
Openflow.Action.PushMpls.new(34887),
|
||||
Openflow.Action.PopVlan.new(),
|
||||
Openflow.Action.PushVlan.new(33024),
|
||||
Openflow.Action.DecMplsTtl.new(),
|
||||
Openflow.Action.SetMplsTtl.new(10),
|
||||
Openflow.Action.DecNwTtl.new(),
|
||||
Openflow.Action.SetNwTtl.new(10),
|
||||
Openflow.Action.Experimenter.new(101, <<0, 1, 2, 3, 4, 5, 6, 7>>),
|
||||
Openflow.Action.SetQueue.new(3),
|
||||
Openflow.Action.Group.new(99),
|
||||
Openflow.Action.Output.new(6)
|
||||
]),
|
||||
Openflow.Instruction.ApplyActions.new([
|
||||
Openflow.Action.SetField.new({:eth_src, "010203040506"}),
|
||||
Openflow.Action.SetField.new({:onf_pbb_uca, 1})
|
||||
])
|
||||
]
|
||||
|
||||
assert Openflow.to_binary(fm) == binary
|
||||
end
|
||||
|
||||
|
|
@ -69,7 +71,7 @@ defmodule OfpFlowModTest do
|
|||
assert fm.idle_timeout == 0
|
||||
assert fm.hard_timeout == 0
|
||||
assert fm.priority == 123
|
||||
assert fm.buffer_id == 0xffff
|
||||
assert fm.buffer_id == 0xFFFF
|
||||
assert fm.out_port == :any
|
||||
assert fm.out_group == :any
|
||||
assert fm.flags == []
|
||||
|
|
@ -89,15 +91,17 @@ defmodule OfpFlowModTest do
|
|||
assert fm.idle_timeout == 0
|
||||
assert fm.hard_timeout == 0
|
||||
assert fm.priority == 123
|
||||
assert fm.buffer_id == 0xffff
|
||||
assert fm.buffer_id == 0xFFFF
|
||||
assert fm.out_port == :any
|
||||
assert fm.out_group == :any
|
||||
assert fm.flags == []
|
||||
assert fm.match == Openflow.Match.new(eth_dst: "f20ba47df8ea")
|
||||
|
||||
assert fm.instructions == [
|
||||
Openflow.Instruction.Meter.new(1),
|
||||
Openflow.Instruction.WriteActions.new([Openflow.Action.Output.new(6)])
|
||||
]
|
||||
Openflow.Instruction.Meter.new(1),
|
||||
Openflow.Instruction.WriteActions.new([Openflow.Action.Output.new(6)])
|
||||
]
|
||||
|
||||
assert Openflow.to_binary(fm) == binary
|
||||
end
|
||||
|
||||
|
|
@ -112,54 +116,57 @@ defmodule OfpFlowModTest do
|
|||
assert fm.idle_timeout == 0
|
||||
assert fm.hard_timeout == 0
|
||||
assert fm.priority == 123
|
||||
assert fm.buffer_id == 0xffff
|
||||
assert fm.buffer_id == 0xFFFF
|
||||
assert fm.out_port == :any
|
||||
assert fm.out_group == :any
|
||||
assert fm.flags == []
|
||||
assert fm.match == Openflow.Match.new(
|
||||
in_port: 84_281_096,
|
||||
in_phy_port: 16_909_060,
|
||||
metadata: 283_686_952_306_183,
|
||||
eth_type: 2054,
|
||||
eth_dst: "ffffffffffff",
|
||||
eth_src: "f20ba47df8ea",
|
||||
vlan_vid: 999,
|
||||
ip_dscp: 9,
|
||||
ip_ecn: 3,
|
||||
ip_proto: 99,
|
||||
ipv4_src: {1, 2, 3, 4},
|
||||
ipv4_dst: {1, 2, 3, 4},
|
||||
tcp_src: 8080,
|
||||
tcp_dst: 18_080,
|
||||
udp_src: 28_080,
|
||||
udp_dst: 55_936,
|
||||
sctp_src: 48_080,
|
||||
sctp_dst: 59_328,
|
||||
icmpv4_type: 100,
|
||||
icmpv4_code: 101,
|
||||
arp_op: 1,
|
||||
arp_spa: {10, 0, 0, 1},
|
||||
arp_tpa: {10, 0, 0, 3},
|
||||
arp_sha: "f20ba47df8ea",
|
||||
arp_tha: "000000000000",
|
||||
ipv6_src: {65152, 0, 0, 0, 61451, 42239, 65096, 10405},
|
||||
ipv6_dst: {65152, 0, 0, 0, 61451, 42239, 65029, 47068},
|
||||
ipv6_flabel: 541_473,
|
||||
icmpv6_type: 200,
|
||||
icmpv6_code: 201,
|
||||
ipv6_nd_target: {65152, 0, 0, 0, 2656, 28415, 65151, 29927},
|
||||
ipv6_nd_sll: "00000000029a",
|
||||
ipv6_nd_tll: "00000000022b",
|
||||
mpls_label: 624_485,
|
||||
mpls_tc: 5,
|
||||
mpls_bos: 1,
|
||||
pbb_isid: 11_259_375,
|
||||
tunnel_id: 651061555542690057,
|
||||
ipv6_exthdr: [:auth, :frag, :router, :hop, :unrep, :unseq],
|
||||
onf_pbb_uca: 1,
|
||||
tun_src: {1, 2, 3, 4},
|
||||
tun_dst: {1, 2, 3, 4}
|
||||
)
|
||||
|
||||
assert fm.match ==
|
||||
Openflow.Match.new(
|
||||
in_port: 84_281_096,
|
||||
in_phy_port: 16_909_060,
|
||||
metadata: 283_686_952_306_183,
|
||||
eth_type: 2054,
|
||||
eth_dst: "ffffffffffff",
|
||||
eth_src: "f20ba47df8ea",
|
||||
vlan_vid: 999,
|
||||
ip_dscp: 9,
|
||||
ip_ecn: 3,
|
||||
ip_proto: 99,
|
||||
ipv4_src: {1, 2, 3, 4},
|
||||
ipv4_dst: {1, 2, 3, 4},
|
||||
tcp_src: 8080,
|
||||
tcp_dst: 18_080,
|
||||
udp_src: 28_080,
|
||||
udp_dst: 55_936,
|
||||
sctp_src: 48_080,
|
||||
sctp_dst: 59_328,
|
||||
icmpv4_type: 100,
|
||||
icmpv4_code: 101,
|
||||
arp_op: 1,
|
||||
arp_spa: {10, 0, 0, 1},
|
||||
arp_tpa: {10, 0, 0, 3},
|
||||
arp_sha: "f20ba47df8ea",
|
||||
arp_tha: "000000000000",
|
||||
ipv6_src: {65152, 0, 0, 0, 61451, 42239, 65096, 10405},
|
||||
ipv6_dst: {65152, 0, 0, 0, 61451, 42239, 65029, 47068},
|
||||
ipv6_flabel: 541_473,
|
||||
icmpv6_type: 200,
|
||||
icmpv6_code: 201,
|
||||
ipv6_nd_target: {65152, 0, 0, 0, 2656, 28415, 65151, 29927},
|
||||
ipv6_nd_sll: "00000000029a",
|
||||
ipv6_nd_tll: "00000000022b",
|
||||
mpls_label: 624_485,
|
||||
mpls_tc: 5,
|
||||
mpls_bos: 1,
|
||||
pbb_isid: 11_259_375,
|
||||
tunnel_id: 651_061_555_542_690_057,
|
||||
ipv6_exthdr: [:auth, :frag, :router, :hop, :unrep, :unseq],
|
||||
onf_pbb_uca: 1,
|
||||
tun_src: {1, 2, 3, 4},
|
||||
tun_dst: {1, 2, 3, 4}
|
||||
)
|
||||
|
||||
assert fm.instructions == []
|
||||
assert Openflow.to_binary(fm) == binary
|
||||
end
|
||||
|
|
@ -168,8 +175,8 @@ defmodule OfpFlowModTest do
|
|||
binary = File.read!(@flow_mod5)
|
||||
{:ok, fm, ""} = Openflow.read(binary)
|
||||
|
||||
assert fm.cookie == 0x123456789abcdef0
|
||||
assert fm.cookie_mask == 0xffffffffffffffff
|
||||
assert fm.cookie == 0x123456789ABCDEF0
|
||||
assert fm.cookie_mask == 0xFFFFFFFFFFFFFFFF
|
||||
assert fm.table_id == 2
|
||||
assert fm.command == :add
|
||||
assert fm.idle_timeout == 0
|
||||
|
|
@ -179,51 +186,59 @@ defmodule OfpFlowModTest do
|
|||
assert fm.out_port == 0
|
||||
assert fm.out_group == 0
|
||||
assert fm.flags == []
|
||||
assert fm.match == Openflow.Match.new(
|
||||
in_port: 43981,
|
||||
eth_dst: "aabbcc998877",
|
||||
eth_type: 2048,
|
||||
vlan_vid: 5095,
|
||||
ipv4_dst: {192, 168, 2, 1},
|
||||
tunnel_id: 50_000,
|
||||
tun_src: {192, 168, 2, 3},
|
||||
tun_dst: {192, 168, 2, 4}
|
||||
)
|
||||
|
||||
assert fm.match ==
|
||||
Openflow.Match.new(
|
||||
in_port: 43981,
|
||||
eth_dst: "aabbcc998877",
|
||||
eth_type: 2048,
|
||||
vlan_vid: 5095,
|
||||
ipv4_dst: {192, 168, 2, 1},
|
||||
tunnel_id: 50_000,
|
||||
tun_src: {192, 168, 2, 3},
|
||||
tun_dst: {192, 168, 2, 4}
|
||||
)
|
||||
|
||||
assert fm.instructions == [
|
||||
Openflow.Instruction.ApplyActions.new([
|
||||
Openflow.Action.PopVlan.new,
|
||||
Openflow.Action.SetField.new({:ipv4_dst, {192, 168, 2, 9}}),
|
||||
Openflow.Action.NxLearn.new(
|
||||
hard_timeout: 300,
|
||||
priority: 1,
|
||||
table_id: 99,
|
||||
flow_specs: [
|
||||
Openflow.Action.NxFlowSpecMatch.new(src: :vlan_vid, dst: :vlan_vid, n_bits: 12),
|
||||
Openflow.Action.NxFlowSpecMatch.new(src: :nx_eth_src, dst: :nx_eth_dst),
|
||||
Openflow.Action.NxFlowSpecLoad.new(src: 0, dst: :vlan_vid, n_bits: 12),
|
||||
Openflow.Action.NxFlowSpecLoad.new(src: :tun_id, dst: :tun_id),
|
||||
Openflow.Action.NxFlowSpecOutput.new(src: :in_port)
|
||||
]
|
||||
)
|
||||
]),
|
||||
Openflow.Instruction.GotoTable.new(100)
|
||||
]
|
||||
Openflow.Instruction.ApplyActions.new([
|
||||
Openflow.Action.PopVlan.new(),
|
||||
Openflow.Action.SetField.new({:ipv4_dst, {192, 168, 2, 9}}),
|
||||
Openflow.Action.NxLearn.new(
|
||||
hard_timeout: 300,
|
||||
priority: 1,
|
||||
table_id: 99,
|
||||
flow_specs: [
|
||||
Openflow.Action.NxFlowSpecMatch.new(
|
||||
src: :vlan_vid,
|
||||
dst: :vlan_vid,
|
||||
n_bits: 12
|
||||
),
|
||||
Openflow.Action.NxFlowSpecMatch.new(src: :nx_eth_src, dst: :nx_eth_dst),
|
||||
Openflow.Action.NxFlowSpecLoad.new(src: 0, dst: :vlan_vid, n_bits: 12),
|
||||
Openflow.Action.NxFlowSpecLoad.new(src: :tun_id, dst: :tun_id),
|
||||
Openflow.Action.NxFlowSpecOutput.new(src: :in_port)
|
||||
]
|
||||
)
|
||||
]),
|
||||
Openflow.Instruction.GotoTable.new(100)
|
||||
]
|
||||
|
||||
assert Openflow.to_binary(fm) == binary
|
||||
end
|
||||
|
||||
test "with OFP_FLOW_MOD packet(6)" do\
|
||||
test "with OFP_FLOW_MOD packet(6)" do
|
||||
{:error, :binary_too_small} =
|
||||
@flow_mod6
|
||||
|> File.read!
|
||||
|> Openflow.read
|
||||
|> File.read!()
|
||||
|> Openflow.read()
|
||||
end
|
||||
|
||||
test "with OFP_FLOW_MOD packet(7)" do
|
||||
binary = File.read!(@flow_mod7)
|
||||
{:ok, fm, ""} = Openflow.read(binary)
|
||||
|
||||
assert fm.cookie == 0x123456789abcdef0
|
||||
assert fm.cookie_mask == 0xffffffffffffffff
|
||||
assert fm.cookie == 0x123456789ABCDEF0
|
||||
assert fm.cookie_mask == 0xFFFFFFFFFFFFFFFF
|
||||
assert fm.table_id == 4
|
||||
assert fm.command == :add
|
||||
assert fm.idle_timeout == 0
|
||||
|
|
@ -233,21 +248,25 @@ defmodule OfpFlowModTest do
|
|||
assert fm.out_port == 0
|
||||
assert fm.out_group == 0
|
||||
assert fm.flags == []
|
||||
assert fm.match == Openflow.Match.new(
|
||||
in_port: 43981,
|
||||
eth_dst: "aabbcc998877",
|
||||
eth_type: 2048,
|
||||
vlan_vid: 5095,
|
||||
ipv4_dst: {192, 168, 2, 1},
|
||||
tunnel_id: 50_000,
|
||||
tun_src: {192, 168, 2, 3},
|
||||
tun_dst: {192, 168, 2, 4}
|
||||
)
|
||||
|
||||
assert fm.match ==
|
||||
Openflow.Match.new(
|
||||
in_port: 43981,
|
||||
eth_dst: "aabbcc998877",
|
||||
eth_type: 2048,
|
||||
vlan_vid: 5095,
|
||||
ipv4_dst: {192, 168, 2, 1},
|
||||
tunnel_id: 50_000,
|
||||
tun_src: {192, 168, 2, 3},
|
||||
tun_dst: {192, 168, 2, 4}
|
||||
)
|
||||
|
||||
assert fm.instructions == [
|
||||
Openflow.Instruction.ApplyActions.new([
|
||||
Openflow.Action.NxConjunction.new(clause: 1, id: 0xabcdef, n_clauses: 2)
|
||||
])
|
||||
]
|
||||
Openflow.Instruction.ApplyActions.new([
|
||||
Openflow.Action.NxConjunction.new(clause: 1, id: 0xABCDEF, n_clauses: 2)
|
||||
])
|
||||
]
|
||||
|
||||
assert Openflow.to_binary(fm) == binary
|
||||
end
|
||||
|
||||
|
|
@ -255,8 +274,8 @@ defmodule OfpFlowModTest do
|
|||
binary = File.read!(@flow_mod8)
|
||||
{:ok, fm, ""} = Openflow.read(binary)
|
||||
|
||||
assert fm.cookie == 0x123456789abcdef0
|
||||
assert fm.cookie_mask == 0xffffffffffffffff
|
||||
assert fm.cookie == 0x123456789ABCDEF0
|
||||
assert fm.cookie_mask == 0xFFFFFFFFFFFFFFFF
|
||||
assert fm.table_id == 3
|
||||
assert fm.command == :add
|
||||
assert fm.idle_timeout == 0
|
||||
|
|
@ -266,14 +285,16 @@ defmodule OfpFlowModTest do
|
|||
assert fm.out_port == 0
|
||||
assert fm.out_group == 0
|
||||
assert fm.flags == []
|
||||
assert fm.match == Openflow.Match.new(conj_id: 0xabcdef)
|
||||
assert fm.match == Openflow.Match.new(conj_id: 0xABCDEF)
|
||||
|
||||
assert fm.instructions == [
|
||||
Openflow.Instruction.ApplyActions.new([
|
||||
Openflow.Action.PopVlan.new,
|
||||
Openflow.Action.SetField.new({:ipv4_dst, {192, 168, 2, 9}})
|
||||
]),
|
||||
Openflow.Instruction.GotoTable.new(100)
|
||||
]
|
||||
Openflow.Instruction.ApplyActions.new([
|
||||
Openflow.Action.PopVlan.new(),
|
||||
Openflow.Action.SetField.new({:ipv4_dst, {192, 168, 2, 9}})
|
||||
]),
|
||||
Openflow.Instruction.GotoTable.new(100)
|
||||
]
|
||||
|
||||
assert Openflow.to_binary(fm) == binary
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ defmodule OfpFlowRemovedTest do
|
|||
test "with OFP_FLOW_REMOVED packet(with a match field)" do
|
||||
{:ok, flow_removed, ""} =
|
||||
"test/packet_data/4-40-ofp_flow_removed.packet"
|
||||
|> File.read!
|
||||
|> Openflow.read
|
||||
|> File.read!()
|
||||
|> Openflow.read()
|
||||
|
||||
assert flow_removed.version == 4
|
||||
assert flow_removed.xid == 0
|
||||
assert flow_removed.cookie == 0
|
||||
assert flow_removed.priority == 0xffff
|
||||
assert flow_removed.priority == 0xFFFF
|
||||
assert flow_removed.reason == :idle_timeout
|
||||
assert flow_removed.table_id == 0
|
||||
assert flow_removed.duration_sec == 3
|
||||
|
|
@ -27,12 +27,12 @@ defmodule OfpFlowRemovedTest do
|
|||
test "with OFP_FLOW_REMOVED packet(with match fields)" do
|
||||
{:ok, flow_removed, ""} =
|
||||
"test/packet_data/libofproto-OFP13-flow_removed.packet"
|
||||
|> File.read!
|
||||
|> Openflow.read
|
||||
|> File.read!()
|
||||
|> Openflow.read()
|
||||
|
||||
assert flow_removed.version == 4
|
||||
assert flow_removed.xid == 0
|
||||
assert flow_removed.cookie == 0x123456789abcdef0
|
||||
assert flow_removed.cookie == 0x123456789ABCDEF0
|
||||
assert flow_removed.priority == 100
|
||||
assert flow_removed.reason == :idle_timeout
|
||||
assert flow_removed.table_id == 1
|
||||
|
|
@ -42,16 +42,17 @@ defmodule OfpFlowRemovedTest do
|
|||
assert flow_removed.hard_timeout == 300
|
||||
assert flow_removed.packet_count == 200
|
||||
assert flow_removed.byte_count == 100
|
||||
|
||||
assert flow_removed.match == [
|
||||
in_port: 43_981,
|
||||
eth_dst: "aabbcc998877",
|
||||
eth_type: 2048,
|
||||
vlan_vid: 5095,
|
||||
ipv4_dst: {192, 168, 2, 1},
|
||||
tunnel_id: 50_000,
|
||||
tun_src: {192, 168, 2, 3},
|
||||
tun_dst: {192, 168, 2, 4}
|
||||
]
|
||||
in_port: 43_981,
|
||||
eth_dst: "aabbcc998877",
|
||||
eth_type: 2048,
|
||||
vlan_vid: 5095,
|
||||
ipv4_dst: {192, 168, 2, 1},
|
||||
tunnel_id: 50_000,
|
||||
tun_src: {192, 168, 2, 3},
|
||||
tun_dst: {192, 168, 2, 4}
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,8 +6,9 @@ defmodule OfpGetConfigTest do
|
|||
test "with OFP_GET_CONFIG_REQUEST packet" do
|
||||
{:ok, %Openflow.GetConfig.Request{} = config, ""} =
|
||||
"test/packet_data/ofp_get_config_request.raw"
|
||||
|> File.read!
|
||||
|> Openflow.read
|
||||
|> File.read!()
|
||||
|> Openflow.read()
|
||||
|
||||
assert config.version == 4
|
||||
assert config.xid == 0
|
||||
end
|
||||
|
|
@ -15,8 +16,9 @@ defmodule OfpGetConfigTest do
|
|||
test "with OFP_GET_CONFIG_REPLY packet" do
|
||||
{:ok, %Openflow.GetConfig.Reply{} = config, ""} =
|
||||
"test/packet_data/ofp_get_config_reply.raw"
|
||||
|> File.read!
|
||||
|> Openflow.read
|
||||
|> File.read!()
|
||||
|> Openflow.read()
|
||||
|
||||
assert config.version == 4
|
||||
assert config.xid == 0
|
||||
assert config.flags == []
|
||||
|
|
@ -30,9 +32,11 @@ defmodule OfpGetConfigTest do
|
|||
version: 4,
|
||||
xid: 0
|
||||
}
|
||||
|
||||
expect =
|
||||
"test/packet_data/ofp_get_config_request.raw"
|
||||
|> File.read!
|
||||
|> File.read!()
|
||||
|
||||
assert Openflow.to_binary(config) == expect
|
||||
end
|
||||
|
||||
|
|
@ -43,9 +47,11 @@ defmodule OfpGetConfigTest do
|
|||
flags: [],
|
||||
miss_send_len: 128
|
||||
}
|
||||
|
||||
expect =
|
||||
"test/packet_data/ofp_get_config_reply.raw"
|
||||
|> File.read!
|
||||
|> File.read!()
|
||||
|
||||
assert Openflow.to_binary(config) == expect
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,14 +12,16 @@ defmodule OfpGroupModTest do
|
|||
assert group_mod.command == :add
|
||||
assert group_mod.type == :all
|
||||
assert group_mod.group_id == 1
|
||||
|
||||
assert group_mod.buckets == [
|
||||
Openflow.Bucket.new(
|
||||
weight: 1,
|
||||
watch_port: 1,
|
||||
watch_group: 1,
|
||||
actions: [Openflow.Action.Output.new(2)]
|
||||
)
|
||||
]
|
||||
Openflow.Bucket.new(
|
||||
weight: 1,
|
||||
watch_port: 1,
|
||||
watch_group: 1,
|
||||
actions: [Openflow.Action.Output.new(2)]
|
||||
)
|
||||
]
|
||||
|
||||
assert Openflow.to_binary(group_mod) == binary
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,8 +6,9 @@ defmodule OfpHelloTest do
|
|||
test "with OFP_HELLO packet" do
|
||||
{:ok, hello, ""} =
|
||||
"test/packet_data/ofp_hello.raw"
|
||||
|> File.read!
|
||||
|> Openflow.read
|
||||
|> File.read!()
|
||||
|> Openflow.read()
|
||||
|
||||
assert hello.version == 4
|
||||
assert hello.xid == 0
|
||||
assert hello.elements == [versionbitmap: [30, 10, 9, 3, 2, 1]]
|
||||
|
|
@ -17,9 +18,11 @@ defmodule OfpHelloTest do
|
|||
describe "Openflow.to_binary/1" do
|
||||
test "with %Openflow.Hello{}" do
|
||||
hello = Openflow.Hello.new([30, 10, 9, 3, 2, 1])
|
||||
|
||||
expect =
|
||||
"test/packet_data/ofp_hello.raw"
|
||||
|> File.read!
|
||||
|> File.read!()
|
||||
|
||||
assert Openflow.to_binary(hello) == expect
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ defmodule OfpPacketInTest do
|
|||
test "with OFP_PACKET_IN packet(with simple matches)" do
|
||||
{:ok, pktin, ""} =
|
||||
"test/packet_data/4-4-ofp_packet_in.packet"
|
||||
|> File.read!
|
||||
|> Openflow.read
|
||||
|> File.read!()
|
||||
|> Openflow.read()
|
||||
|
||||
assert pktin.version == 4
|
||||
assert pktin.xid == 0
|
||||
|
|
@ -15,73 +15,75 @@ defmodule OfpPacketInTest do
|
|||
assert pktin.table_id == 1
|
||||
assert pktin.reason == :action
|
||||
assert pktin.in_port == 6
|
||||
|
||||
assert pktin.match == [
|
||||
eth_type: 2054,
|
||||
eth_dst: "ffffffffffff",
|
||||
eth_src: "f20ba47df8ea",
|
||||
arp_op: 1,
|
||||
arp_spa: {10, 0, 0, 1},
|
||||
arp_tpa: {10, 0, 0, 3},
|
||||
arp_sha: "f20ba47df8ea",
|
||||
arp_tha: "000000000000"
|
||||
]
|
||||
eth_type: 2054,
|
||||
eth_dst: "ffffffffffff",
|
||||
eth_src: "f20ba47df8ea",
|
||||
arp_op: 1,
|
||||
arp_spa: {10, 0, 0, 1},
|
||||
arp_tpa: {10, 0, 0, 3},
|
||||
arp_sha: "f20ba47df8ea",
|
||||
arp_tha: "000000000000"
|
||||
]
|
||||
end
|
||||
|
||||
test "with OFP_PACKET_IN packet(with complex matches)" do
|
||||
{:ok, pktin, ""} =
|
||||
"test/packet_data/4-59-ofp_packet_in.packet"
|
||||
|> File.read!
|
||||
|> Openflow.read
|
||||
|> File.read!()
|
||||
|> Openflow.read()
|
||||
|
||||
assert pktin.version == 4
|
||||
assert pktin.xid == 0
|
||||
assert pktin.total_len == 0
|
||||
assert pktin.table_id == 200
|
||||
assert pktin.reason == :no_match
|
||||
assert pktin.in_port == 84281096
|
||||
assert pktin.in_port == 84_281_096
|
||||
|
||||
assert pktin.match == [
|
||||
in_phy_port: 16909060,
|
||||
metadata: 283686952306183,
|
||||
eth_type: 2054,
|
||||
eth_dst: "ffffffffffff",
|
||||
eth_src: "f20ba47df8ea",
|
||||
vlan_vid: 999,
|
||||
ip_dscp: 9,
|
||||
ip_ecn: 3,
|
||||
ip_proto: 99,
|
||||
ipv4_src: {1, 2, 3, 4},
|
||||
ipv4_dst: {1, 2, 3, 4},
|
||||
tcp_src: 8080,
|
||||
tcp_dst: 18080,
|
||||
udp_src: 28080,
|
||||
udp_dst: 55936,
|
||||
sctp_src: 48080,
|
||||
sctp_dst: 59328,
|
||||
icmpv4_type: 100,
|
||||
icmpv4_code: 101,
|
||||
arp_op: 1,
|
||||
arp_spa: {10, 0, 0, 1},
|
||||
arp_tpa: {10, 0, 0, 3},
|
||||
arp_sha: "f20ba47df8ea",
|
||||
arp_tha: "000000000000",
|
||||
ipv6_src: {65152, 0, 0, 0, 61451, 42239, 65096, 10405},
|
||||
ipv6_dst: {65152, 0, 0, 0, 61451, 42239, 65029, 47068},
|
||||
ipv6_flabel: 541473,
|
||||
icmpv6_type: 200,
|
||||
icmpv6_code: 201,
|
||||
ipv6_nd_target: {65152, 0, 0, 0, 2656, 28415, 65151, 29927},
|
||||
ipv6_nd_sll: "00000000029a",
|
||||
ipv6_nd_tll: "00000000022b",
|
||||
mpls_label: 624485,
|
||||
mpls_tc: 5,
|
||||
mpls_bos: 1,
|
||||
pbb_isid: 11259375,
|
||||
tunnel_id: 651061555542690057,
|
||||
ipv6_exthdr: [:auth, :frag, :router, :hop, :unrep, :unseq],
|
||||
onf_pbb_uca: 1,
|
||||
tun_src: {1, 2, 3, 4},
|
||||
tun_dst: {1, 2, 3, 4}
|
||||
]
|
||||
in_phy_port: 16_909_060,
|
||||
metadata: 283_686_952_306_183,
|
||||
eth_type: 2054,
|
||||
eth_dst: "ffffffffffff",
|
||||
eth_src: "f20ba47df8ea",
|
||||
vlan_vid: 999,
|
||||
ip_dscp: 9,
|
||||
ip_ecn: 3,
|
||||
ip_proto: 99,
|
||||
ipv4_src: {1, 2, 3, 4},
|
||||
ipv4_dst: {1, 2, 3, 4},
|
||||
tcp_src: 8080,
|
||||
tcp_dst: 18080,
|
||||
udp_src: 28080,
|
||||
udp_dst: 55936,
|
||||
sctp_src: 48080,
|
||||
sctp_dst: 59328,
|
||||
icmpv4_type: 100,
|
||||
icmpv4_code: 101,
|
||||
arp_op: 1,
|
||||
arp_spa: {10, 0, 0, 1},
|
||||
arp_tpa: {10, 0, 0, 3},
|
||||
arp_sha: "f20ba47df8ea",
|
||||
arp_tha: "000000000000",
|
||||
ipv6_src: {65152, 0, 0, 0, 61451, 42239, 65096, 10405},
|
||||
ipv6_dst: {65152, 0, 0, 0, 61451, 42239, 65029, 47068},
|
||||
ipv6_flabel: 541_473,
|
||||
icmpv6_type: 200,
|
||||
icmpv6_code: 201,
|
||||
ipv6_nd_target: {65152, 0, 0, 0, 2656, 28415, 65151, 29927},
|
||||
ipv6_nd_sll: "00000000029a",
|
||||
ipv6_nd_tll: "00000000022b",
|
||||
mpls_label: 624_485,
|
||||
mpls_tc: 5,
|
||||
mpls_bos: 1,
|
||||
pbb_isid: 11_259_375,
|
||||
tunnel_id: 651_061_555_542_690_057,
|
||||
ipv6_exthdr: [:auth, :frag, :router, :hop, :unrep, :unseq],
|
||||
onf_pbb_uca: 1,
|
||||
tun_src: {1, 2, 3, 4},
|
||||
tun_dst: {1, 2, 3, 4}
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,27 +3,112 @@ defmodule OfpPacketOutTest do
|
|||
doctest Openflow
|
||||
|
||||
@packet <<
|
||||
0xf2, 0x0b, 0xa4, 0xd0, 0x3f, 0x70, 0xf2, 0x0b,
|
||||
0xa4, 0x7d, 0xf8, 0xea, 0x08, 0x00, 0x45, 0x00,
|
||||
0x00, 0x54, 0xf8, 0x1a, 0x00, 0x00, 0xff, 0x01,
|
||||
0xaf, 0x8b, 0x0a, 0x00, 0x00, 0x01, 0x0a, 0x00,
|
||||
0x00, 0x02, 0x08, 0x00, 0x02, 0x08, 0xf7, 0x60,
|
||||
0x00, 0x00, 0x31, 0xd6, 0x02, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0xab, 0x8d, 0x2d, 0x31, 0x00, 0x00,
|
||||
0x00, 0x00, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
|
||||
0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
|
||||
0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25,
|
||||
0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
|
||||
0x2e, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00
|
||||
0xF2,
|
||||
0x0B,
|
||||
0xA4,
|
||||
0xD0,
|
||||
0x3F,
|
||||
0x70,
|
||||
0xF2,
|
||||
0x0B,
|
||||
0xA4,
|
||||
0x7D,
|
||||
0xF8,
|
||||
0xEA,
|
||||
0x08,
|
||||
0x00,
|
||||
0x45,
|
||||
0x00,
|
||||
0x00,
|
||||
0x54,
|
||||
0xF8,
|
||||
0x1A,
|
||||
0x00,
|
||||
0x00,
|
||||
0xFF,
|
||||
0x01,
|
||||
0xAF,
|
||||
0x8B,
|
||||
0x0A,
|
||||
0x00,
|
||||
0x00,
|
||||
0x01,
|
||||
0x0A,
|
||||
0x00,
|
||||
0x00,
|
||||
0x02,
|
||||
0x08,
|
||||
0x00,
|
||||
0x02,
|
||||
0x08,
|
||||
0xF7,
|
||||
0x60,
|
||||
0x00,
|
||||
0x00,
|
||||
0x31,
|
||||
0xD6,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0xAB,
|
||||
0x8D,
|
||||
0x2D,
|
||||
0x31,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x10,
|
||||
0x11,
|
||||
0x12,
|
||||
0x13,
|
||||
0x14,
|
||||
0x15,
|
||||
0x16,
|
||||
0x17,
|
||||
0x18,
|
||||
0x19,
|
||||
0x1A,
|
||||
0x1B,
|
||||
0x1C,
|
||||
0x1D,
|
||||
0x1E,
|
||||
0x1F,
|
||||
0x20,
|
||||
0x21,
|
||||
0x22,
|
||||
0x23,
|
||||
0x24,
|
||||
0x25,
|
||||
0x26,
|
||||
0x27,
|
||||
0x28,
|
||||
0x29,
|
||||
0x2A,
|
||||
0x2B,
|
||||
0x2C,
|
||||
0x2D,
|
||||
0x2E,
|
||||
0x2F,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00
|
||||
>>
|
||||
|
||||
describe "Openflow.read/1" do
|
||||
test "with OFP_PACKET_OUT packet" do
|
||||
{:ok, pktout, ""} =
|
||||
"test/packet_data/libofproto-OFP13-ofp_packet_out_packet_library.packet"
|
||||
|> File.read!
|
||||
|> Openflow.read
|
||||
|> File.read!()
|
||||
|> Openflow.read()
|
||||
|
||||
assert pktout.version == 4
|
||||
assert pktout.xid == 0
|
||||
|
|
@ -37,12 +122,12 @@ defmodule OfpPacketOutTest do
|
|||
describe "Openflow.to_binary/1" do
|
||||
pktout = %Openflow.PacketOut{
|
||||
actions: [Openflow.Action.Output.new(port_number: :all)],
|
||||
data: @packet
|
||||
data: @packet
|
||||
}
|
||||
|
||||
expect =
|
||||
"test/packet_data/libofproto-OFP13-ofp_packet_out_packet_library.packet"
|
||||
|> File.read!
|
||||
|> File.read!()
|
||||
|
||||
assert Openflow.to_binary(pktout) == expect
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ defmodule OfpPortStatusTest do
|
|||
test "with OFP_PORT_STATUS packet" do
|
||||
{:ok, port_status, ""} =
|
||||
"test/packet_data/libofproto-OFP13-port_status.packet"
|
||||
|> File.read!
|
||||
|> Openflow.read
|
||||
|> File.read!()
|
||||
|> Openflow.read()
|
||||
|
||||
assert port_status.version == 4
|
||||
assert port_status.xid == 0
|
||||
|
|
@ -27,8 +27,8 @@ defmodule OfpPortStatusTest do
|
|||
test "with OFP_PORT_STATUS packet(with kanji port name)" do
|
||||
{:ok, port_status, ""} =
|
||||
"test/packet_data/4-39-ofp_port_status.packet"
|
||||
|> File.read!
|
||||
|> Openflow.read
|
||||
|> File.read!()
|
||||
|> Openflow.read()
|
||||
|
||||
assert port_status.version == 4
|
||||
assert port_status.xid == 0
|
||||
|
|
|
|||
|
|
@ -6,8 +6,9 @@ defmodule OfpSetConfigTest do
|
|||
test "with OFP_SET_CONFIG packet" do
|
||||
{:ok, %Openflow.SetConfig{} = config, ""} =
|
||||
"test/packet_data/ofp_set_config.raw"
|
||||
|> File.read!
|
||||
|> Openflow.read
|
||||
|> File.read!()
|
||||
|> Openflow.read()
|
||||
|
||||
assert config.version == 4
|
||||
assert config.xid == 0
|
||||
assert config.flags == []
|
||||
|
|
@ -23,9 +24,11 @@ defmodule OfpSetConfigTest do
|
|||
flags: [],
|
||||
miss_send_len: 128
|
||||
}
|
||||
|
||||
expect =
|
||||
"test/packet_data/ofp_set_config.raw"
|
||||
|> File.read!
|
||||
|> File.read!()
|
||||
|
||||
assert Openflow.to_binary(config) == expect
|
||||
end
|
||||
end
|
||||
|
|
|
|||
33
test/pf.ex
33
test/pf.ex
|
|
@ -8,11 +8,9 @@ defmodule Pf do
|
|||
end
|
||||
|
||||
defmodule State do
|
||||
defstruct [
|
||||
ifname: nil,
|
||||
pcap_ref: nil,
|
||||
tester_pid: nil
|
||||
]
|
||||
defstruct ifname: nil,
|
||||
pcap_ref: nil,
|
||||
tester_pid: nil
|
||||
end
|
||||
|
||||
def inject!(pid, packet, payload \\ "") do
|
||||
|
|
@ -33,24 +31,28 @@ defmodule Pf do
|
|||
end
|
||||
|
||||
def handle_cast({:inject, {headers, payload}}, state) do
|
||||
headers_bin = for header <- headers do
|
||||
case header do
|
||||
ether() -> :pkt.ether(header)
|
||||
{:"802.1q", _, _, _, _} = vlan -> :pkt_802_1q.codec(vlan)
|
||||
arp() -> :pkt.arp(header)
|
||||
ipv4() -> :pkt.ipv4(header)
|
||||
lldp() -> :pkt.lldp(header)
|
||||
udp() -> :pkt.udp(header)
|
||||
tcp() -> :pkt.tcp(header)
|
||||
headers_bin =
|
||||
for header <- headers do
|
||||
case header do
|
||||
ether() -> :pkt.ether(header)
|
||||
{:"802.1q", _, _, _, _} = vlan -> :pkt_802_1q.codec(vlan)
|
||||
arp() -> :pkt.arp(header)
|
||||
ipv4() -> :pkt.ipv4(header)
|
||||
lldp() -> :pkt.lldp(header)
|
||||
udp() -> :pkt.udp(header)
|
||||
tcp() -> :pkt.tcp(header)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
binary = Enum.join(headers_bin, "")
|
||||
:epcap.send(state.pcap_ref, <<binary::bytes, payload::bytes>>)
|
||||
{:noreply, state}
|
||||
end
|
||||
|
||||
def handle_cast(:stop, state) do
|
||||
{:stop, :normal, state}
|
||||
end
|
||||
|
||||
def handle_cast(_req, state) do
|
||||
{:noreply, state}
|
||||
end
|
||||
|
|
@ -61,6 +63,7 @@ defmodule Pf do
|
|||
send(state.tester_pid, {to_string(state.ifname), Enum.take(packet, packet_len - 1)})
|
||||
{:noreply, state}
|
||||
end
|
||||
|
||||
def handle_info(_info, state) do
|
||||
{:noreply, state}
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue