diff --git a/lib/OpenFlow0x01.ml b/lib/OpenFlow0x01.ml index d7d98f7..e31e6a3 100644 --- a/lib/OpenFlow0x01.ml +++ b/lib/OpenFlow0x01.ml @@ -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 diff --git a/lib/OpenFlow0x01.mli b/lib/OpenFlow0x01.mli index 0d08080..5b691e0 100644 --- a/lib/OpenFlow0x01.mli +++ b/lib/OpenFlow0x01.mli @@ -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 diff --git a/quickcheck/OpenFlow0x01_Arbitrary.ml b/quickcheck/OpenFlow0x01_Arbitrary.ml index 8cffcae..11550d3 100644 --- a/quickcheck/OpenFlow0x01_Arbitrary.ml +++ b/quickcheck/OpenFlow0x01_Arbitrary.ml @@ -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 @@ -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 @@ -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 diff --git a/quickcheck/OpenFlow0x01_Arbitrary.mli b/quickcheck/OpenFlow0x01_Arbitrary.mli index 5b22da6..ba36878 100644 --- a/quickcheck/OpenFlow0x01_Arbitrary.mli +++ b/quickcheck/OpenFlow0x01_Arbitrary.mli @@ -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 diff --git a/test/Test.ml b/test/Test.ml index 6d993b7..5dd8cd6 100644 --- a/test/Test.ml +++ b/test/Test.ml @@ -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