Skip to content

Commit 8121a28

Browse files
committed
multi: add send_txn_with, use in barrier
Transaction-based messages always require the same error handling, with the matching and transformation of the response being the only thing specific to the original request. send_txn_with encapsulates the error handling, and takes the message-specific response handling as a function.
1 parent 5b37186 commit 8121a28

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

async/Async_OpenFlow0x01.ml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ module Controller = struct
9999
let xid = ChunkController.client_next_xid t.sub c_id in
100100
ChunkController.send_txn t.sub c_id (Message.marshal' (xid, msg))
101101

102+
let send_txn_with t sw_id msg f =
103+
try begin
104+
send_txn t sw_id msg
105+
>>= function
106+
| `Sent ivar -> Ivar.read ivar >>| f
107+
| `Drop exn -> return (Result.Error exn)
108+
end with Not_found -> return (Result.Error Not_found)
109+
102110
let send_ignore_errors t sw_id msg =
103111
let c_id = client_id_of_switch_exn t sw_id in
104112
ChunkController.send_ignore_errors t.sub c_id (Message.marshal' msg)
@@ -213,15 +221,7 @@ module Controller = struct
213221
send_result t sw_id (0l, M.PacketOutMsg pkt_out)
214222

215223
let barrier t sw_id =
216-
try begin
217-
send_txn t sw_id M.BarrierRequest
218-
>>= function
219-
| `Sent ivar -> begin Ivar.read ivar
220-
>>| function
221-
| M.BarrierReply -> Result.Ok ()
222-
| _ -> assert false
223-
end
224-
| `Drop exn -> return (Result.Error exn)
225-
end with Not_found -> return (Result.Error Not_found)
226-
224+
send_txn_with t sw_id M.BarrierRequest (function
225+
| M.BarrierReply -> Result.Ok ()
226+
| _ -> assert false)
227227
end

async/Async_OpenFlow0x04.ml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ module Controller = struct
134134
let xid = ChunkController.client_next_xid t.sub c_id in
135135
ChunkController.send_txn t.sub c_id (Message.marshal' (xid, msg))
136136

137+
let send_txn_with t sw_id msg f =
138+
try begin
139+
send_txn t sw_id msg
140+
>>= function
141+
| `Sent ivar -> Ivar.read ivar >>| f
142+
| `Drop exn -> return (Result.Error exn)
143+
end with Not_found -> return (Result.Error Not_found)
144+
137145
let send_ignore_errors t sw_id msg =
138146
let c_id = client_id_of_switch_exn t sw_id in
139147
ChunkController.send_ignore_errors t.sub c_id (Message.marshal' msg)
@@ -247,15 +255,8 @@ module Controller = struct
247255
send_result t sw_id (0l, M.PacketOutMsg pkt_out)
248256

249257
let barrier t sw_id =
250-
try begin
251-
send_txn t sw_id M.BarrierRequest
252-
>>= function
253-
| `Sent ivar -> begin Ivar.read ivar
254-
>>| function
255-
| M.BarrierReply -> Result.Ok ()
256-
| _ -> assert false
257-
end
258-
| `Drop exn -> return (Result.Error exn)
259-
end with Not_found -> return (Result.Error Not_found)
258+
send_txn_with t sw_id M.BarrierRequest (function
259+
| M.BarrierReply -> Result.Ok ()
260+
| _ -> assert false)
260261

261262
end

0 commit comments

Comments
 (0)