Skip to content

Commit

Permalink
Merge pull request #155 from frenetic-lang/activity
Browse files Browse the repository at this point in the history
connection activity fixes
  • Loading branch information
seliopou committed Aug 14, 2014
2 parents 62dc4fe + cc96a0c commit 1c73bb8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion async/Async_OpenFlow.mli
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ module Chunk : sig
val set_idle_wait : t -> Time.Span.t -> unit
val set_kill_wait : t -> Time.Span.t -> unit

val echo : (t, h, h) Stage.t
val echo : (t, e, e) Stage.t
val handshake : int -> (t, e, h) Stage.t
end

Expand Down
2 changes: 1 addition & 1 deletion async/Async_OpenFlow0x01.ml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ module Controller = struct
let open ChunkController in
let stages =
(local (fun t -> t.sub)
(handshake 0x01 >=> echo))
(echo >=> handshake 0x01))
>=> openflow0x01 in
run stages t (listen t.sub)
end
2 changes: 1 addition & 1 deletion async/Async_OpenFlow0x04.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module Controller = struct
let open ChunkController in
let stages =
(local (fun t -> t.sub)
(handshake 0x04 >=> echo))
(echo >=> handshake 0x04))
>=> openflow0x04 in
run stages t (listen t.sub)

Expand Down
23 changes: 12 additions & 11 deletions async/Async_OpenFlowChunk.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@ module Controller = struct

module Conn = struct
type t = {
state : [ `Handshake | `Active | `Idle | `Kill ];
state : [ `Active | `Idle | `Kill ];
version : int option;
state_entered : Time.t;
last_activity : Time.t
}

let create () : t =
let now = Time.now () in
{ state = `Handshake
{ state = `Active
; version = None
; state_entered = now
; last_activity = now
}

let activity (t:t) : t =
let t = { t with last_activity = Time.now () } in
if t.state = `Active then
t
else
if t.state = `Idle then
{ t with state = `Active; state_entered = t.last_activity }
else
t

let complete_handshake (t:t) (version:int) : t =
activity { t with version = Some(version) }
Expand Down Expand Up @@ -107,7 +107,7 @@ module Controller = struct
| None -> assert false
| Some(conn) -> Some(Conn.complete_handshake conn version))

let activity (t:t) ?ver (c_id:Client_id.t) =
let activity (t:t) (c_id:Client_id.t) =
ClientTbl.change t.clients c_id (function
| None -> assert false
| Some(conn) -> Some(Conn.activity conn))
Expand Down Expand Up @@ -194,8 +194,8 @@ module Controller = struct
let has_client_id t c_id =
Platform.has_client_id t.platform c_id &&
match ClientTbl.find t.clients c_id with
| Some(conn) -> not (conn.Conn.state = `Handshake)
| _ -> false
| Some({ Conn.version = Some(_) }) -> true
| _ -> false

let send t c_id m =
Platform.send t.platform c_id m
Expand Down Expand Up @@ -228,7 +228,7 @@ module Controller = struct
| `Message (c_id, msg) ->
begin match ClientTbl.find t.clients c_id with
| None -> assert false
| Some({ Conn.state = `Handshake }) ->
| Some({ Conn.version = None }) ->
let hdr, bits = msg in
begin
if not (hdr.type_code = type_code_hello) then begin
Expand All @@ -247,7 +247,7 @@ module Controller = struct
| `Disconnect (c_id, exn) ->
begin match ClientTbl.find t.clients c_id with
| None -> assert false
| Some({ Conn.state = `Handshake }) ->
| Some({ Conn.version = None }) ->
ClientTbl.remove t.clients c_id;
return []
| Some(_) ->
Expand All @@ -259,6 +259,7 @@ module Controller = struct
let open Header in
match evt with
| `Message (c_id, (hdr, bytes)) ->
Handler.activity t c_id;
begin if hdr.Header.type_code = type_code_echo_request then
(* Echo requests get a reply *)
let hdr = { hdr with type_code = type_code_echo_reply } in
Expand All @@ -272,7 +273,7 @@ module Controller = struct
* *)
>>| (function _ -> [])
else if hdr.Header.type_code = type_code_echo_reply then
(* Echo replies get eaten *)
(* Echo replies get eaten. The activity has been recorded above. *)
return []
else
(* All other messages get forwarded *)
Expand Down

0 comments on commit 1c73bb8

Please sign in to comment.