@@ -21,9 +21,9 @@ type t =
21
21
}
22
22
23
23
type e = [
24
- | `Connect of SDN .switchId * SDN .switchFeatures
24
+ | `Connect of SDN .switchId * SDN .switchFeatures
25
25
| `Disconnect of SDN .switchId * Sexp .t
26
- | `PacketIn of SDN .switchId * SDN .pktIn
26
+ | `PacketIn of SDN .switchId * SDN .pktIn
27
27
| `PortUp of SDN .switchId * SDN .portId
28
28
| `PortDown of SDN .switchId * SDN .portId ]
29
29
@@ -71,7 +71,9 @@ let listen_of0x01 (t : t) : Chunk_Controller.h Pipe.Writer.t * e Pipe.Reader.t =
71
71
| `Connect (sw_id , fs ) ->
72
72
let sdn_fs =
73
73
{ SDN. switch_id = sw_id
74
- ; SDN. switch_ports = List. filter_map fs.OF.SwitchFeatures. ports ~f: get_port }
74
+ ; SDN. switch_ports = List. filter_map fs.OF.SwitchFeatures. ports
75
+ ~f: get_port
76
+ }
75
77
in
76
78
Some (`Connect (sw_id, sdn_fs))
77
79
| `Disconnect (sw_id , exn ) ->
@@ -165,7 +167,7 @@ let listen (t : t) : e Pipe.Reader.t =
165
167
match version with
166
168
| 0x01 -> Pipe. write of0x01_w e
167
169
| 0x04 -> Pipe. write of0x04_w e
168
- | _ -> failwith " Unsupported version" ));
170
+ | v -> failwith Printf. (sprintf " SDN.listen: unsupported version: %d " v) ));
169
171
Pipe. interleave [of0x01_r; of0x04_r]
170
172
171
173
let switch_version (t : t ) (sw_id : SDN.switchId ) =
@@ -182,14 +184,13 @@ let clear_flows ?(pattern:SDN.Pattern.t option) (t:t) (sw_id:SDN.switchId) =
182
184
| 0x01 ->
183
185
let pattern = Option. map pattern ~f: SDN_OpenFlow0x01. from_pattern in
184
186
OF0x01_Controller. clear_flows ?pattern t.sub_0x01 sw_id
185
- | 0x04
186
- | _ -> failwith " Unsupported version"
187
-
188
- let clear_table (t : t ) (sw_id : SDN.switchId ) =
189
- match switch_version t sw_id with
190
- | 0x01 -> OF0x01_Controller. clear_flows t.sub_0x01 sw_id
191
- | 0x04 -> OF0x04_Controller. clear_table t.sub_0x04 sw_id
192
- | _ -> failwith " Unsupported version"
187
+ | 0x04 ->
188
+ let pattern = match Option. map pattern ~f: SDN_OpenFlow0x04. from_pattern with
189
+ | Some (pattern , _ ) -> Some (pattern)
190
+ | None -> None
191
+ in
192
+ OF0x04_Controller. clear_flows ?pattern t.sub_0x04 sw_id
193
+ | v -> failwith Printf. (sprintf " SDN.clear_flows: unsupported version: %d" v)
193
194
194
195
let install_flows ?(clear =true ) (t : t ) (sw_id : SDN.switchId ) flows =
195
196
let priority = ref 65536 in
@@ -203,21 +204,22 @@ let install_flows ?(clear=true) (t : t) (sw_id : SDN.switchId) flows =
203
204
let f flow = decr priority; SDN_OpenFlow0x04. from_flow groups ! priority flow in
204
205
let flow_mods = List. map flows ~f in
205
206
let open Deferred.Result in
207
+ OF0x04_Controller. clear_groups t.sub_0x04 sw_id >> = fun () ->
206
208
OF0x04_Controller. send_flow_mods ~clear t.sub_0x04 sw_id flow_mods >> = fun () ->
207
209
let f group = OF0x04_Controller. send_result t.sub_0x04 sw_id (0l , group) in
208
210
Deferred.Result. all_ignore (List. map (GroupTable0x04. commit groups) ~f )
209
- | _ -> failwith " Unsupported version"
211
+ | v -> failwith Printf. (sprintf " SDN.install_flows: unsupported version: %d " v)
210
212
211
213
let send_pkt_out (t : t ) (sw_id : SDN.switchId ) (pkt_out : SDN.pktOut ) =
212
214
match switch_version t sw_id with
213
215
| 0x01 -> OF0x01_Controller. send_pkt_out t.sub_0x01 sw_id
214
216
(SDN_OpenFlow0x01. from_packetOut pkt_out)
215
217
| 0x04 -> OF0x04_Controller. send_pkt_out t.sub_0x04 sw_id
216
218
(SDN_OpenFlow0x04. from_packetOut pkt_out)
217
- | _ -> failwith " Unsupported version"
219
+ | v -> failwith Printf. (sprintf " SDN.send_pkt_out: unsupported version: %d " v)
218
220
219
221
let barrier (t : t ) (sw_id : SDN.switchId ) =
220
222
match switch_version t sw_id with
221
223
| 0x01 -> OF0x01_Controller. barrier t.sub_0x01 sw_id
222
224
| 0x04 -> OF0x04_Controller. barrier t.sub_0x04 sw_id
223
- | _ -> failwith " Unsupported version"
225
+ | v -> failwith Printf. (sprintf " SDN.barrier: unsupported version: %d " v)
0 commit comments