Skip to content

Commit 6532bb1

Browse files
committed
multi/0x01: add clear_flows API, make pattern args optional
1 parent 1da0db2 commit 6532bb1

File tree

3 files changed

+46
-25
lines changed

3 files changed

+46
-25
lines changed

async/Async_OpenFlow.mli

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,29 @@ module OpenFlow0x01 : sig
199199
open OpenFlow0x01_Core
200200
open OpenFlow0x01_Stats
201201

202-
val clear_table : t -> Client_id.t -> (unit, exn) Deferred.Result.t
203-
val send_flow_mods : ?clear:bool -> t -> Client_id.t -> flowMod list -> (unit, exn) Deferred.Result.t
202+
val clear_flows
203+
: ?pattern:pattern -> t -> Client_id.t
204+
-> (unit, exn) Deferred.Result.t
204205

205-
val send_pkt_out : t -> Client_id.t -> packetOut -> (unit, exn) Deferred.Result.t
206-
val barrier : t -> Client_id.t -> (unit, exn) Result.t Deferred.t
207-
val aggregate_stats : t -> Client_id.t -> pattern -> (aggregateStats, exn) Deferred.Result.t
208-
val individual_stats : t -> Client_id.t -> pattern -> (individualStats list, exn) Deferred.Result.t
206+
val send_flow_mods
207+
: ?clear:bool -> t -> Client_id.t -> flowMod list
208+
-> (unit, exn) Deferred.Result.t
209+
210+
val send_pkt_out
211+
: t -> Client_id.t -> packetOut
212+
-> (unit, exn) Deferred.Result.t
213+
214+
val barrier
215+
: t -> Client_id.t
216+
-> (unit, exn) Result.t Deferred.t
217+
218+
val aggregate_stats
219+
: ?pattern:pattern -> t -> Client_id.t
220+
-> (aggregateStats, exn) Deferred.Result.t
221+
222+
val individual_stats
223+
: ?pattern:pattern -> t -> Client_id.t
224+
-> (individualStats list, exn) Deferred.Result.t
209225
end
210226

211227
end

async/Async_OpenFlow0x01.ml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -202,28 +202,28 @@ module Controller = struct
202202
let open ChunkController in
203203
listen_pipe t (run (handshake 0x01) t.sub (listen t.sub))
204204

205-
let clear_table (t : t) (sw_id : Client_id.t) =
206-
send_result t sw_id (0l, M.FlowModMsg (C.delete_all_flows))
207-
208-
let send_flow_mods ?(clear=true) (t : t) (sw_id : Client_id.t) flow_mods =
209-
begin if clear then clear_table t sw_id else return (Result.Ok ()) end
210-
>>= function
211-
| Result.Error exn -> return (Result.Error exn)
212-
| Result.Ok () ->
213-
let sends = List.map flow_mods
214-
~f:(fun f -> send_result t sw_id (0l, M.FlowModMsg f))
215-
in
216-
Deferred.Result.all_ignore sends
217-
218-
let send_pkt_out (t : t) (sw_id : Client_id.t) pkt_out =
205+
let clear_flows ?(pattern=C.match_all) (t:t) (sw_id:Client_id.t) =
206+
send_result t sw_id (0l, M.FlowModMsg
207+
{ C.delete_all_flows with C.pattern = pattern })
208+
209+
let send_flow_mods ?(clear=true) (t:t) (sw_id:Client_id.t) flow_mods =
210+
let open Deferred.Result in
211+
begin if clear then clear_flows t sw_id else return () end
212+
>>= fun () ->
213+
let sends = List.map flow_mods
214+
~f:(fun f -> send_result t sw_id (0l, M.FlowModMsg f))
215+
in
216+
all_ignore sends
217+
218+
let send_pkt_out (t:t) (sw_id:Client_id.t) pkt_out =
219219
send_result t sw_id (0l, M.PacketOutMsg pkt_out)
220220

221221
let barrier t sw_id =
222222
send_txn_with t sw_id M.BarrierRequest (function
223223
| M.BarrierReply -> Result.Ok ()
224224
| _ -> assert false)
225225

226-
let aggregate_stats t sw_id pattern =
226+
let aggregate_stats ?(pattern=C.match_all) (t:t) sw_id =
227227
let open OpenFlow0x01_Stats in
228228
let msg = AggregateRequest
229229
{ as_of_match = pattern
@@ -234,7 +234,7 @@ module Controller = struct
234234
| M.StatsReplyMsg (AggregateFlowRep r) -> Result.Ok r
235235
| _ -> assert false)
236236

237-
let individual_stats t sw_id pattern =
237+
let individual_stats ?(pattern=C.match_all) (t:t) sw_id =
238238
let open OpenFlow0x01_Stats in
239239
let msg = IndividualRequest
240240
{ is_of_match = pattern

async/Async_SDN.ml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,17 @@ let switch_version (t : t) (sw_id : SDN.switchId) =
177177
end
178178
| Some _ -> 0x01
179179

180-
let clear_flows (t : t) (pattern : SDN.Pattern.t) (sw_id : SDN.switchId) =
181-
failwith "NYI: SDN.clear_flows"
180+
let clear_flows ?(pattern:SDN.Pattern.t option) (t:t) (sw_id:SDN.switchId) =
181+
match switch_version t sw_id with
182+
| 0x01 ->
183+
let pattern = Option.map pattern ~f:SDN_OpenFlow0x01.from_pattern in
184+
OF0x01_Controller.clear_flows ?pattern t.sub_0x01 sw_id
185+
| 0x04
186+
| _ -> failwith "Unsupported version"
182187

183188
let clear_table (t : t) (sw_id : SDN.switchId) =
184189
match switch_version t sw_id with
185-
| 0x01 -> OF0x01_Controller.clear_table t.sub_0x01 sw_id
190+
| 0x01 -> OF0x01_Controller.clear_flows t.sub_0x01 sw_id
186191
| 0x04 -> OF0x04_Controller.clear_table t.sub_0x04 sw_id
187192
| _ -> failwith "Unsupported version"
188193

0 commit comments

Comments
 (0)