Skip to content

Commit b3b2c59

Browse files
committed
Merge branch 'master' into LearningSwitch0x04
solve the conflict of setup.ml
2 parents e7c82f8 + 80de655 commit b3b2c59

13 files changed

+629
-410
lines changed

_oasis

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
OASISFormat: 0.3
22
OCamlVersion: >= 4.01.0
33
Name: openflow
4-
Version: 0.4.0
4+
Version: 0.5.0
55
Synopsis: Serialization library for OpenFlow
66
Authors: https://github.com/frenetic-lang/ocaml-openflow/contributors
77
License: LGPL

async/Async_OpenFlow.mli

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ module Platform : sig
4949
-> ?verbose:bool
5050
-> ?log_disconnects:bool
5151
-> ?buffer_age_limit:[ `At_most of Time.Span.t | `Unlimited ]
52+
-> ?monitor_connections:bool
5253
-> port:int
5354
-> unit
5455
-> t Deferred.t
@@ -65,6 +66,8 @@ module Platform : sig
6566
-> m
6667
-> [ `Drop of exn | `Sent of Time.t ] Deferred.t
6768

69+
val send_ignore_errors : t -> Client_id.t -> m -> unit
70+
6871
val send_to_all : t -> m -> unit
6972

7073
val client_addr_port
@@ -144,7 +147,11 @@ module Chunk : sig
144147
| `Message of Client_id.t * m
145148
]
146149

147-
val echo : (t, e, e) Stage.t
150+
val set_monitor_interval : t -> Time.Span.t -> unit
151+
val set_idle_wait : t -> Time.Span.t -> unit
152+
val set_kill_wait : t -> Time.Span.t -> unit
153+
154+
val echo : (t, h, h) Stage.t
148155
val handshake : int -> (t, e, h) Stage.t
149156
end
150157

@@ -165,8 +172,15 @@ module OpenFlow0x01 : sig
165172
| `Message of Client_id.t * m
166173
]
167174

168-
val switch_id_of_client : t -> Client_id.t -> SDN_Types.switchId
169-
val client_id_of_switch : t -> SDN_Types.switchId -> Client_id.t
175+
val switch_id_of_client_exn : t -> Client_id.t -> SDN_Types.switchId
176+
val client_id_of_switch_exn : t -> SDN_Types.switchId -> Client_id.t
177+
178+
val switch_id_of_client : t -> Client_id.t -> SDN_Types.switchId option
179+
val client_id_of_switch : t -> SDN_Types.switchId -> Client_id.t option
180+
181+
val set_monitor_interval : t -> Time.Span.t -> unit
182+
val set_idle_wait : t -> Time.Span.t -> unit
183+
val set_kill_wait : t -> Time.Span.t -> unit
170184

171185
val features : (t, e, f) Stage.t
172186
end

async/Async_OpenFlow0x01.ml

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,32 +60,41 @@ module Controller = struct
6060
let close t = ChunkController.close t.sub
6161
let has_client_id t = ChunkController.has_client_id t.sub
6262
let send t s_id msg = ChunkController.send t.sub s_id (Message.marshal' msg)
63+
let send_ignore_errors t s_id msg = ChunkController.send_ignore_errors t.sub s_id (Message.marshal' msg)
6364
let send_to_all t msg = ChunkController.send_to_all t.sub (Message.marshal' msg)
6465
let client_addr_port t = ChunkController.client_addr_port t.sub
6566
let listening_port t = ChunkController.listening_port t.sub
6667

6768
(* XXX(seliopou): Raises `Not_found` if the client is no longer connected. *)
68-
let switch_id_of_client t c_id = ClientMap.find_exn t.switches c_id
69-
let client_id_of_switch t sw_id = SwitchMap.find_exn t.clients sw_id
69+
let switch_id_of_client_exn t c_id = ClientMap.find_exn t.switches c_id
70+
let client_id_of_switch_exn t sw_id = SwitchMap.find_exn t.clients sw_id
71+
72+
let switch_id_of_client t c_id = ClientMap.find t.switches c_id
73+
let client_id_of_switch t sw_id = SwitchMap.find t.clients sw_id
74+
75+
let set_monitor_interval (t:t) (s:Time.Span.t) : unit =
76+
ChunkController.set_monitor_interval t.sub s
77+
78+
let set_idle_wait (t:t) (s:Time.Span.t) : unit =
79+
ChunkController.set_idle_wait t.sub s
80+
81+
let set_kill_wait (t:t) (s:Time.Span.t) : unit =
82+
ChunkController.set_kill_wait t.sub s
7083

7184
let create ?max_pending_connections
7285
?verbose
7386
?log_disconnects
74-
?buffer_age_limit ~port () =
87+
?buffer_age_limit
88+
?monitor_connections ~port () =
7589
ChunkController.create ?max_pending_connections ?verbose ?log_disconnects
76-
?buffer_age_limit ~port ()
90+
?buffer_age_limit ?monitor_connections ~port ()
7791
>>| function t ->
7892
{ sub = t
7993
; shakes = ClientSet.empty
8094
; switches = ClientMap.empty
8195
; clients = SwitchMap.empty
8296
}
8397

84-
let _send t c_id m =
85-
send t c_id (0l, m) >>| function
86-
| `Drop exn -> raise exn
87-
| `Sent _ -> ()
88-
8998
let openflow0x01 t evt =
9099
match evt with
91100
| `Connect (c_id, version) ->
@@ -104,15 +113,24 @@ module Controller = struct
104113
let features t evt =
105114
match evt with
106115
| `Connect (c_id) ->
116+
assert (not (ClientSet.mem t.shakes c_id));
107117
t.shakes <- ClientSet.add t.shakes c_id;
108-
send t c_id (0l, M.SwitchFeaturesRequest) >>| ChunkController.ensure
118+
send t c_id (0l, M.SwitchFeaturesRequest)
119+
(* XXX(seliopou): This swallows any errors that might have occurred
120+
* while attemping the handshake. Any such error should not be raised,
121+
* since as far as the user is concerned the connection never existed.
122+
* At the very least, the exception should be logged, which it will be
123+
* as long as the log_disconnects option is not disabled when creating
124+
* the controller.
125+
* *)
126+
>>| (function _ -> [])
109127
| `Message (c_id, (xid, msg)) when ClientSet.mem t.shakes c_id ->
110128
begin match msg with
111129
| M.SwitchFeaturesReply fs ->
112130
let switch_id = fs.OpenFlow0x01.SwitchFeatures.switch_id in
113131
t.switches <- ClientMap.add t.switches c_id switch_id;
114-
t.clients <- SwitchMap.add t.clients switch_id c_id;
115-
t.shakes <- ClientSet.remove t.shakes c_id;
132+
t.clients <- SwitchMap.add t.clients switch_id c_id;
133+
t.shakes <- ClientSet.remove t.shakes c_id;
116134
return [`Connect(c_id, fs)]
117135
| _ ->
118136
Log.of_lazy ~tags ~level:`Debug (lazy
@@ -126,11 +144,12 @@ module Controller = struct
126144
let m_sw_id = ClientMap.find t.switches c_id in
127145
match m_sw_id with
128146
| None -> (* features request did not complete *)
147+
assert (ClientSet.mem t.shakes c_id);
129148
t.shakes <- ClientSet.remove t.shakes c_id;
130149
return []
131150
| Some(sw_id) -> (* features request did complete *)
132-
t.clients <- SwitchMap.remove t.clients sw_id;
133151
t.switches <- ClientMap.remove t.switches c_id;
152+
t.clients <- SwitchMap.remove t.clients sw_id;
134153
return [`Disconnect(c_id, sw_id, exn)]
135154

136155
let listen t =

async/Async_OpenFlow0x04.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ module Controller = struct
6060
let create ?max_pending_connections
6161
?verbose
6262
?log_disconnects
63-
?buffer_age_limit ~port () =
63+
?buffer_age_limit
64+
?monitor_connections ~port () =
6465
ChunkController.create ?max_pending_connections ?verbose ?log_disconnects
65-
?buffer_age_limit ~port ()
66+
?buffer_age_limit ?monitor_connections ~port ()
6667
>>| function t -> { sub = t }
6768

6869
let listen t =
@@ -77,6 +78,7 @@ module Controller = struct
7778
let close t = ChunkController.close t.sub
7879
let has_client_id t = ChunkController.has_client_id t.sub
7980
let send t s_id msg = ChunkController.send t.sub s_id (Message.marshal' msg)
81+
let send_ignore_errors t s_id msg = ChunkController.send_ignore_errors t.sub s_id (Message.marshal' msg)
8082
let send_to_all t msg = ChunkController.send_to_all t.sub (Message.marshal' msg)
8183
let client_addr_port t = ChunkController.client_addr_port t.sub
8284
let listening_port t = ChunkController.listening_port t.sub

0 commit comments

Comments
 (0)