Skip to content

Commit c2c5b74

Browse files
committed
multi: expose functions for message types
Rather than exposing low-level operations to send messages and deal with xids, provide an async-based fucntion interface for dealing with those methods. Currently suppor send_pkt_out and barrier.
1 parent 714ba82 commit c2c5b74

File tree

4 files changed

+73
-12
lines changed

4 files changed

+73
-12
lines changed

async/Async_OpenFlow.mli

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ module OpenFlow0x01 : sig
189189
include Platform.CTL
190190
with type t := t
191191

192-
val send_txn
193-
: t
194-
-> Client_id.t
195-
-> OpenFlow0x01.Message.t
196-
-> [ `Sent of Message.t Ivar.t | `Drop of exn ] Deferred.t
192+
(* val clear_flows : t -> SDN.Pattern.t -> Client_id.t -> (unit, exn) Deferred.Result.t *)
193+
val clear_table : t -> Client_id.t -> (unit, exn) Deferred.Result.t
194+
195+
val send_pkt_out : t -> Client_id.t -> OpenFlow0x01_Core.packetOut -> (unit, exn) Deferred.Result.t
196+
val barrier : t -> Client_id.t -> (unit, exn) Result.t Deferred.t
197197
end
198198

199199
end
@@ -212,11 +212,13 @@ module OpenFlow0x04 : sig
212212
include Platform.CTL
213213
with type t := t
214214

215-
val send_txn
216-
: t
217-
-> Client_id.t
218-
-> OpenFlow0x04.Message.t
219-
-> [ `Sent of Message.t Ivar.t | `Drop of exn ] Deferred.t
215+
216+
(* val clear_flows : t -> Pattern.t -> Client_id.t -> (unit, exn) Deferred.Result.t *)
217+
val clear_table : t -> Client_id.t -> (unit, exn) Deferred.Result.t
218+
219+
val send_pkt_out : t -> Client_id.t -> OpenFlow0x04_Core.packetOut -> (unit, exn) Deferred.Result.t
220+
val barrier : t -> Client_id.t -> (unit, exn) Result.t Deferred.t
221+
220222
end
221223

222224
end
@@ -245,13 +247,18 @@ module SDN : sig
245247

246248
val listen : t -> e Pipe.Reader.t
247249

248-
val clear_table : t -> switchId -> (unit, exn) Result.t Deferred.t
250+
(* val clear_flows : t -> Pattern.t -> switchId -> (unit, exn) Deferred.Result.t *)
251+
val clear_table : t -> switchId -> (unit, exn) Deferred.Result.t
249252

250253
val install_flows
251254
: ?clear:bool
252255
-> t
253256
-> switchId
254257
-> flow list
255-
-> (unit, exn) Result.t Deferred.t
258+
-> (unit, exn) Deferred.Result.t
259+
260+
val send_pkt_out : t -> switchId -> pktOut -> (unit, exn) Deferred.Result.t
261+
262+
val barrier : t -> switchId -> (unit, exn) Deferred.Result.t
256263

257264
end

async/Async_OpenFlow0x01.ml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ module Controller = struct
193193
let open ChunkController in
194194
listen_pipe t (run (handshake 0x01) t.sub (listen t.sub))
195195

196+
let clear_flows (t : t) (pattern : SDN_Types.Pattern.t) (sw_id : Client_id.t) =
197+
failwith "NYI: OF0x01.clear_flows"
198+
196199
let clear_table (t : t) (sw_id : Client_id.t) =
197200
send_result t sw_id (0l, M.FlowModMsg (C.delete_all_flows))
198201

@@ -205,4 +208,20 @@ module Controller = struct
205208
~f:(fun f -> send_result t sw_id (0l, M.FlowModMsg f))
206209
in
207210
Deferred.Result.all_ignore sends
211+
212+
let send_pkt_out (t : t) (sw_id : Client_id.t) pkt_out =
213+
send_result t sw_id (0l, M.PacketOutMsg pkt_out)
214+
215+
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+
208227
end

async/Async_OpenFlow0x04.ml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ module Controller = struct
225225
let open ChunkController in
226226
listen_pipe t (run (handshake 0x04) t.sub (listen t.sub))
227227

228+
let clear_flows (t : t) (pattern : SDN_Types.Pattern.t) (sw_id : Client_id.t) =
229+
failwith "NYI: OF0x04.clear_flows"
230+
228231
let clear_table (t : t) (sw_id : Client_id.t) =
229232
let flows = send_result t sw_id (0l, M.FlowModMsg C.delete_all_flows) in
230233
let groups = send_result t sw_id (0l, M.GroupModMsg C.delete_all_groups) in
@@ -240,4 +243,19 @@ module Controller = struct
240243
in
241244
Deferred.Result.all_ignore sends
242245

246+
let send_pkt_out (t : t) (sw_id : Client_id.t) pkt_out =
247+
send_result t sw_id (0l, M.PacketOutMsg pkt_out)
248+
249+
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)
260+
243261
end

async/Async_SDN.ml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ 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"
182+
180183
let clear_table (t : t) (sw_id : SDN.switchId) =
181184
match switch_version t sw_id with
182185
| 0x01 -> OF0x01_Controller.clear_table t.sub_0x01 sw_id
@@ -199,3 +202,17 @@ let install_flows ?(clear=true) (t : t) (sw_id : SDN.switchId) flows =
199202
let f group = OF0x04_Controller.send_result t.sub_0x04 sw_id (0l, group) in
200203
Deferred.Result.all_ignore (List.map (GroupTable0x04.commit groups) ~f)
201204
| _ -> failwith "Unsupported version"
205+
206+
let send_pkt_out (t : t) (sw_id : SDN.switchId) (pkt_out : SDN.pktOut) =
207+
match switch_version t sw_id with
208+
| 0x01 -> OF0x01_Controller.send_pkt_out t.sub_0x01 sw_id
209+
(SDN_OpenFlow0x01.from_packetOut pkt_out)
210+
| 0x04 -> OF0x04_Controller.send_pkt_out t.sub_0x04 sw_id
211+
(SDN_OpenFlow0x04.from_packetOut pkt_out)
212+
| _ -> failwith "Unsupported version"
213+
214+
let barrier (t : t) (sw_id : SDN.switchId) =
215+
match switch_version t sw_id with
216+
| 0x01 -> OF0x01_Controller.barrier t.sub_0x01 sw_id
217+
| 0x04 -> OF0x04_Controller.barrier t.sub_0x04 sw_id
218+
| _ -> failwith "Unsupported version"

0 commit comments

Comments
 (0)