Skip to content

Commit

Permalink
Merge pull request #62 from adferguson/of10_flow_rem_qc
Browse files Browse the repository at this point in the history
quickcheck and additional bugfix for FlowRemoved
  • Loading branch information
reitblatt committed Jan 5, 2014
2 parents 9aa1527 + d39cedc commit e0cbd2a
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 26 deletions.
5 changes: 3 additions & 2 deletions lib/OpenFlow0x01.ml
Original file line number Diff line number Diff line change
Expand Up @@ -949,8 +949,9 @@ module FlowRemoved = struct
msg.packet_count
msg.byte_count

let size_of _ =
sizeof_ofp_flow_removed
let size_of msg =
(Match.size_of msg.pattern)
+ sizeof_ofp_flow_removed

let marshal (msg:t) (bits:Cstruct.t) : int =
let bits = Cstruct.shift bits (Match.marshal msg.pattern bits) in
Expand Down
8 changes: 8 additions & 0 deletions lib/OpenFlow0x01.mli
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,20 @@ module FlowRemoved : sig

val to_string : t -> string

val to_int : t -> int16
val of_int : int16 -> t

end

type t = flowRemoved

val to_string : t -> string

val marshal : t -> Cstruct.t -> int
val parse : Cstruct.t -> t

val size_of : t -> int

end

module PacketOut : sig
Expand Down
93 changes: 75 additions & 18 deletions quickcheck/OpenFlow0x01_Arbitrary.ml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,24 @@ module Action = struct

end

module Timeout = struct
type t = OpenFlow0x01.Timeout.t
type s = Packet.int16

let arbitrary =
let open Gen in
let open OpenFlow0x01_Core in
oneof [
ret_gen Permanent;
arbitrary_uint16 >>= (fun n -> ret_gen (ExpiresAfter n))
]

let to_string = OpenFlow0x01.Timeout.to_string

let marshal = OpenFlow0x01.Timeout.to_int
let parse = OpenFlow0x01.Timeout.of_int
end

module FlowMod = struct

module Command = struct
Expand All @@ -285,24 +303,6 @@ module FlowMod = struct
let parse = FlowMod.Command.of_int
end

module Timeout = struct
type t = OpenFlow0x01.Timeout.t
type s = Packet.int16

let arbitrary =
let open Gen in
let open OpenFlow0x01_Core in
oneof [
ret_gen Permanent;
arbitrary_uint16 >>= (fun n -> ret_gen (ExpiresAfter n))
]

let to_string = OpenFlow0x01.Timeout.to_string

let marshal = OpenFlow0x01.Timeout.to_int
let parse = OpenFlow0x01.Timeout.of_int
end

type t = FlowMod.t
type s = Cstruct.t

Expand Down Expand Up @@ -342,3 +342,60 @@ module FlowMod = struct
let size_of = FlowMod.size_of

end

module FlowRemoved = struct

module Reason = struct
type t = FlowRemoved.Reason.t
type s = Packet.int8

let arbitrary =
let open Gen in
let open OpenFlow0x01_Core in
oneof [
ret_gen IdleTimeout;
ret_gen HardTimeout;
ret_gen Delete;
]

let to_string = FlowRemoved.Reason.to_string

let marshal = FlowRemoved.Reason.to_int
let parse = FlowRemoved.Reason.of_int
end

type t = FlowRemoved.t
type s = Cstruct.t

let arbitrary =
let open Gen in
let open OpenFlow0x01_Core in
Match.arbitrary >>= fun pattern ->
arbitrary_uint48 >>= fun cookie ->
arbitrary_uint16 >>= fun priority ->
Reason.arbitrary >>= fun reason ->
arbitrary_uint32 >>= fun duration_sec ->
arbitrary_uint32 >>= fun duration_nsec ->
Timeout.arbitrary >>= fun idle_timeout ->
arbitrary_uint48 >>= fun packet_count ->
arbitrary_uint48 >>= fun byte_count ->
ret_gen {
pattern = pattern;
cookie = cookie;
priority = priority;
reason = reason;
duration_sec = duration_sec;
duration_nsec = duration_nsec;
idle_timeout = idle_timeout;
packet_count = packet_count;
byte_count = byte_count
}

let to_string = FlowRemoved.to_string

let marshal = FlowRemoved.marshal
let parse = FlowRemoved.parse

let size_of = FlowRemoved.size_of

end
9 changes: 8 additions & 1 deletion quickcheck/OpenFlow0x01_Arbitrary.mli
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,16 @@ module Wildcards : OpenFlow0x01_Arbitrary
module Match : OpenFlow0x01_ArbitraryCstruct
module PseudoPort : OpenFlow0x01_Arbitrary
module Action : OpenFlow0x01_ArbitraryCstruct
module Timeout : OpenFlow0x01_Arbitrary

module FlowMod : sig
include OpenFlow0x01_ArbitraryCstruct

module Command : OpenFlow0x01_Arbitrary
module Timeout : OpenFlow0x01_Arbitrary
end

module FlowRemoved : sig
include OpenFlow0x01_ArbitraryCstruct

module Reason : OpenFlow0x01_Arbitrary
end
20 changes: 15 additions & 5 deletions test/Test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,31 @@ module RoundTripping = struct
(openflow_quickCheck GenAction.arbitrary
GenAction.to_string GenAction.parse GenAction.marshal)

TEST "OpenFlow0x01 Timeout RoundTrip" =
let module GenTimeout = Gen.Timeout in
(openflow_quickCheck GenTimeout.arbitrary
GenTimeout.to_string GenTimeout.parse GenTimeout.marshal)

TEST "OpenFlow0x01 FlowMod.Command RoundTrip" =
let module GenCommand = Gen.FlowMod.Command in
(openflow_quickCheck GenCommand.arbitrary
GenCommand.to_string GenCommand.parse GenCommand.marshal)

TEST "OpenFlow0x01 FlowMod.Timeout RoundTrip" =
let module GenTimeout = Gen.FlowMod.Timeout in
(openflow_quickCheck GenTimeout.arbitrary
GenTimeout.to_string GenTimeout.parse GenTimeout.marshal)

TEST "OpenFlow0x01 FlowMod RoundTrip" =
let module GenFlowMod = Gen.OpenFlow0x01_Unsize(Gen.FlowMod) in
(openflow_quickCheck GenFlowMod.arbitrary
GenFlowMod.to_string GenFlowMod.parse GenFlowMod.marshal)

TEST "OpenFlow0x01 FlowRemoved.Reason RoundTrip" =
let module GenReason = Gen.FlowRemoved.Reason in
(openflow_quickCheck GenReason.arbitrary
GenReason.to_string GenReason.parse GenReason.marshal)

TEST "OpenFlow0x01 FlowRemoved RoundTrip" =
let module GenFlowRemoved = Gen.OpenFlow0x01_Unsize(Gen.FlowRemoved) in
(openflow_quickCheck GenFlowRemoved.arbitrary
GenFlowRemoved.to_string GenFlowRemoved.parse GenFlowRemoved.marshal)

TEST "OpenFlow Hello Test 1" =
let open Message in
let bs = Cstruct.create 101 in
Expand Down

0 comments on commit e0cbd2a

Please sign in to comment.