quality: Add test cases for port_desc and port_stats messages
This commit is contained in:
parent
2e3f772b1f
commit
599f1947db
8 changed files with 153 additions and 31 deletions
|
|
@ -32,12 +32,12 @@ defmodule OfpMeterStatsTest do
|
|||
%Openflow.Multipart.Meter{
|
||||
band_stats: [%{byte_band_count: 0, packet_band_count: 0}],
|
||||
byte_in_count: 0,
|
||||
duration_nsec: 480000,
|
||||
duration_nsec: 480_000,
|
||||
duration_sec: 0,
|
||||
flow_count: 0,
|
||||
meter_id: 100,
|
||||
packet_in_count: 0
|
||||
}
|
||||
}
|
||||
],
|
||||
version: 4,
|
||||
xid: 0
|
||||
|
|
|
|||
62
test/lib/openflow/ofp_port_desc_stats_test.exs
Normal file
62
test/lib/openflow/ofp_port_desc_stats_test.exs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
defmodule OfpPortDescTest do
|
||||
use ExUnit.Case
|
||||
|
||||
describe "Openflow.Multipart.PortDesc.Request" do
|
||||
test "with default values" do
|
||||
desc = Openflow.Multipart.PortDesc.Request.new(0)
|
||||
|
||||
desc
|
||||
|> Openflow.to_binary()
|
||||
|> Openflow.read()
|
||||
|> Kernel.elem(1)
|
||||
|> Kernel.==(desc)
|
||||
|> assert()
|
||||
end
|
||||
end
|
||||
|
||||
describe "Openflow.Multipart.PortDesc.Reply" do
|
||||
test "with test packet_data" do
|
||||
port_desc_stats =
|
||||
"test/packet_data/4-54-ofp_port_desc_reply.packet"
|
||||
|> File.read!()
|
||||
|> Openflow.read()
|
||||
|> Kernel.elem(1)
|
||||
|
||||
%Openflow.Multipart.PortDesc.Reply{
|
||||
aux_id: nil,
|
||||
datapath_id: nil,
|
||||
flags: [],
|
||||
ports: [
|
||||
%Openflow.Port{
|
||||
advertised_features: [:copper, :autoneg],
|
||||
config: [],
|
||||
current_features: [:"100mb_fd", :copper, :autoneg],
|
||||
current_speed: 5000,
|
||||
hw_addr: "f20ba47df8ea",
|
||||
max_speed: 5000,
|
||||
name: "Port6",
|
||||
number: 6,
|
||||
peer_features: [:"100mb_fd", :copper, :autoneg],
|
||||
state: [:live],
|
||||
supported_features: [:"100mb_fd", :copper, :autoneg]
|
||||
},
|
||||
%Openflow.Port{
|
||||
advertised_features: [:copper, :autoneg],
|
||||
config: [],
|
||||
current_features: [:"100mb_fd", :copper, :autoneg],
|
||||
current_speed: 5000,
|
||||
hw_addr: "f20ba4d03f70",
|
||||
max_speed: 5000,
|
||||
name: "Port7",
|
||||
number: 7,
|
||||
peer_features: [:"100mb_fd", :copper, :autoneg],
|
||||
state: [:live],
|
||||
supported_features: [:"100mb_fd", :copper, :autoneg]
|
||||
}
|
||||
],
|
||||
version: 4,
|
||||
xid: 0
|
||||
} = port_desc_stats
|
||||
end
|
||||
end
|
||||
end
|
||||
72
test/lib/openflow/ofp_port_stats_test.exs
Normal file
72
test/lib/openflow/ofp_port_stats_test.exs
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
defmodule OfpPortStatsTest do
|
||||
use ExUnit.Case
|
||||
|
||||
describe "Openflow.Multipart.Port.Request" do
|
||||
test "with default values" do
|
||||
port_stats =
|
||||
%Openflow.Multipart.Port.Request{}
|
||||
|> Map.to_list()
|
||||
|> Openflow.Multipart.Port.Request.new()
|
||||
|> Openflow.to_binary()
|
||||
|> Openflow.read()
|
||||
|> Kernel.elem(1)
|
||||
|
||||
assert port_stats.xid == 0
|
||||
assert port_stats.port_number == :any
|
||||
end
|
||||
end
|
||||
|
||||
describe "Openflow.Multipart.Port.Reply" do
|
||||
test "with test packet_data" do
|
||||
port_stats =
|
||||
"test/packet_data/4-30-ofp_port_stats_reply.packet"
|
||||
|> File.read!()
|
||||
|> Openflow.read()
|
||||
|> Kernel.elem(1)
|
||||
|
||||
%Openflow.Multipart.Port.Reply{
|
||||
aux_id: nil,
|
||||
datapath_id: nil,
|
||||
flags: [],
|
||||
ports: [
|
||||
%Openflow.Multipart.PortStats{
|
||||
collisions: 0,
|
||||
duration_nsec: 0,
|
||||
duration_sec: 0,
|
||||
port_number: 7,
|
||||
rx_bytes: 0,
|
||||
rx_crc_err: 0,
|
||||
rx_dropped: 0,
|
||||
rx_errors: 0,
|
||||
rx_frame_err: 0,
|
||||
rx_over_err: 0,
|
||||
rx_packets: 0,
|
||||
tx_bytes: 336,
|
||||
tx_dropped: 0,
|
||||
tx_errors: 0,
|
||||
tx_packets: 4
|
||||
},
|
||||
%Openflow.Multipart.PortStats{
|
||||
collisions: 0,
|
||||
duration_nsec: 0,
|
||||
duration_sec: 0,
|
||||
port_number: 6,
|
||||
rx_bytes: 336,
|
||||
rx_crc_err: 0,
|
||||
rx_dropped: 0,
|
||||
rx_errors: 0,
|
||||
rx_frame_err: 0,
|
||||
rx_over_err: 0,
|
||||
rx_packets: 4,
|
||||
tx_bytes: 336,
|
||||
tx_dropped: 0,
|
||||
tx_errors: 0,
|
||||
tx_packets: 4
|
||||
}
|
||||
],
|
||||
version: 4,
|
||||
xid: 0
|
||||
} = port_stats
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue