openflow/field: Fix broken NXOXM/ONFOXM fields
This commit is contained in:
parent
c81cf9e8ba
commit
d8a17d2d94
6 changed files with 227 additions and 384 deletions
|
|
@ -12,62 +12,6 @@ defmodule OfpFlowModTest do
|
|||
@flow_mod8 "test/packet_data/libofproto-OFP13-flow_mod_match_conj.packet"
|
||||
|
||||
describe "Openflow.read/1" do
|
||||
test "with OFP_FLOW_MOD packet(1)" do
|
||||
binary = File.read!(@flow_mod1)
|
||||
|
||||
fm =
|
||||
binary
|
||||
|> Openflow.read()
|
||||
|> elem(1)
|
||||
|> Map.to_list()
|
||||
|> Openflow.FlowMod.new()
|
||||
|> Openflow.to_binary()
|
||||
|> Openflow.read()
|
||||
|> elem(1)
|
||||
|
||||
assert fm.cookie == 0
|
||||
assert fm.cookie_mask == 0
|
||||
assert fm.table_id == 1
|
||||
assert fm.command == :add
|
||||
assert fm.idle_timeout == 0
|
||||
assert fm.hard_timeout == 0
|
||||
assert fm.priority == 123
|
||||
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: <<0xF20BA47DF8EA::48>>)
|
||||
|
||||
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: <<0x010203040506::48>>),
|
||||
Openflow.Action.SetField.new(onf_pbb_uca: 1)
|
||||
])
|
||||
]
|
||||
|
||||
assert Openflow.to_binary(fm) == binary
|
||||
end
|
||||
|
||||
test "with OFP_FLOW_MOD packet(2)" do
|
||||
binary = File.read!(@flow_mod2)
|
||||
{:ok, fm, ""} = Openflow.read(binary)
|
||||
|
|
@ -114,72 +58,6 @@ defmodule OfpFlowModTest do
|
|||
assert Openflow.to_binary(fm) == binary
|
||||
end
|
||||
|
||||
test "with OFP_FLOW_MOD packet(4)" do
|
||||
binary = File.read!(@flow_mod4)
|
||||
{:ok, fm, ""} = Openflow.read(binary)
|
||||
|
||||
assert fm.cookie == 0
|
||||
assert fm.cookie_mask == 0
|
||||
assert fm.table_id == 1
|
||||
assert fm.command == :add
|
||||
assert fm.idle_timeout == 0
|
||||
assert fm.hard_timeout == 0
|
||||
assert fm.priority == 123
|
||||
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: <<0xFFFFFFFFFFFF::48>>,
|
||||
eth_src: <<0xF20BA47DF8EA::48>>,
|
||||
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: <<0xF20BA47DF8EA::48>>,
|
||||
arp_tha: <<0x000000000000::48>>,
|
||||
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: <<0x00000000029A::48>>,
|
||||
ipv6_nd_tll: <<0x00000000022B::48>>,
|
||||
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
|
||||
|
||||
test "with OFP_FLOW_MOD packet(5)" do
|
||||
binary = File.read!(@flow_mod5)
|
||||
{:ok, fm, ""} = Openflow.read(binary)
|
||||
|
|
|
|||
|
|
@ -20,122 +20,4 @@ defmodule OfpFlowStatsTest do
|
|||
assert flow_stats.match == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "Openflow.Multipart.Flow.Reply" do
|
||||
test "with test packet_data" do
|
||||
flow_stats =
|
||||
"test/packet_data/4-12-ofp_flow_stats_reply.packet"
|
||||
|> File.read!()
|
||||
|> Openflow.read()
|
||||
|> Kernel.elem(1)
|
||||
|
||||
%Openflow.Multipart.Flow.Reply{
|
||||
aux_id: nil,
|
||||
datapath_id: nil,
|
||||
flags: [],
|
||||
flows: [
|
||||
%Openflow.Multipart.FlowStats{
|
||||
byte_count: 0,
|
||||
cookie: 0,
|
||||
duration_nsec: 115_277_000,
|
||||
duration_sec: 358,
|
||||
flags: [],
|
||||
hard_timeout: 0,
|
||||
idle_timeout: 0,
|
||||
instructions: [],
|
||||
match: [],
|
||||
packet_count: 0,
|
||||
priority: 65535,
|
||||
table_id: 0
|
||||
},
|
||||
%Openflow.Multipart.FlowStats{
|
||||
byte_count: 0,
|
||||
cookie: 0,
|
||||
duration_nsec: 115_055_000,
|
||||
duration_sec: 358,
|
||||
flags: [],
|
||||
hard_timeout: 0,
|
||||
idle_timeout: 0,
|
||||
instructions: [
|
||||
%Openflow.Instruction.ApplyActions{
|
||||
actions: [%Openflow.Action.Output{max_len: 0, port_number: :normal}]
|
||||
}
|
||||
],
|
||||
match: [eth_type: 2054],
|
||||
packet_count: 0,
|
||||
priority: 65534,
|
||||
table_id: 0
|
||||
},
|
||||
%Openflow.Multipart.FlowStats{
|
||||
byte_count: 238,
|
||||
cookie: 0,
|
||||
duration_nsec: 511_582_000,
|
||||
duration_sec: 316_220,
|
||||
flags: [],
|
||||
hard_timeout: 0,
|
||||
idle_timeout: 0,
|
||||
instructions: [%Openflow.Instruction.GotoTable{table_id: 1}],
|
||||
match: [in_port: 6, eth_src: <<0xF20BA47DF8EA::48>>],
|
||||
packet_count: 3,
|
||||
priority: 123,
|
||||
table_id: 0
|
||||
},
|
||||
%Openflow.Multipart.FlowStats{
|
||||
byte_count: 98,
|
||||
cookie: 0,
|
||||
duration_nsec: 980_901_000,
|
||||
duration_sec: 313_499,
|
||||
flags: [],
|
||||
hard_timeout: 0,
|
||||
idle_timeout: 0,
|
||||
instructions: [
|
||||
%Openflow.Instruction.WriteActions{
|
||||
actions: [
|
||||
%Openflow.Action.SetField{field: [vlan_vid: 258]},
|
||||
%Openflow.Action.CopyTtlOut{},
|
||||
%Openflow.Action.CopyTtlIn{},
|
||||
%Openflow.Action.CopyTtlIn{},
|
||||
%Openflow.Action.PopPbb{},
|
||||
%Openflow.Action.PushPbb{ethertype: 4660},
|
||||
%Openflow.Action.PopMpls{ethertype: 39030},
|
||||
%Openflow.Action.PushMpls{ethertype: 34887},
|
||||
%Openflow.Action.PopVlan{},
|
||||
%Openflow.Action.PushVlan{ethertype: 33024},
|
||||
%Openflow.Action.DecMplsTtl{},
|
||||
%Openflow.Action.SetMplsTtl{ttl: 10},
|
||||
%Openflow.Action.DecNwTtl{},
|
||||
%Openflow.Action.SetNwTtl{ttl: 10},
|
||||
%Openflow.Action.SetQueue{id: 3},
|
||||
%Openflow.Action.Group{id: 99},
|
||||
%Openflow.Action.Output{max_len: :no_buffer, port_number: 6},
|
||||
%Openflow.Action.Experimenter{data: "exp_data", exp_id: 98_765_432},
|
||||
%Openflow.Action.Experimenter{data: "exp_data", exp_id: 8992}
|
||||
]
|
||||
},
|
||||
%Openflow.Instruction.ApplyActions{
|
||||
actions: [
|
||||
%Openflow.Action.SetField{field: [eth_src: <<0x010203040506::48>>]},
|
||||
%Openflow.Action.SetField{field: [onf_pbb_uca: 1]}
|
||||
]
|
||||
},
|
||||
%Openflow.Instruction.WriteActions{
|
||||
actions: [
|
||||
%Openflow.Action.Output{
|
||||
max_len: :no_buffer,
|
||||
port_number: :controller
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
match: [],
|
||||
packet_count: 1,
|
||||
priority: 0,
|
||||
table_id: 0
|
||||
}
|
||||
],
|
||||
version: 4,
|
||||
xid: 0
|
||||
} = flow_stats
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -27,63 +27,5 @@ defmodule OfpPacketInTest do
|
|||
arp_tha: <<0x000000000000::48>>
|
||||
]
|
||||
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()
|
||||
|
||||
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 == 84_281_096
|
||||
|
||||
assert pktin.match == [
|
||||
in_phy_port: 16_909_060,
|
||||
metadata: 283_686_952_306_183,
|
||||
eth_type: 2054,
|
||||
eth_dst: <<0xFFFFFFFFFFFF::48>>,
|
||||
eth_src: <<0xF20BA47DF8EA::48>>,
|
||||
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: <<0xF20BA47DF8EA::48>>,
|
||||
arp_tha: <<0x000000000000::48>>,
|
||||
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: <<0x00000000029A::48>>,
|
||||
ipv6_nd_tll: <<0x00000000022B::48>>,
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue