Skip to content

Commit 5b38fcc

Browse files
committed
multi: keep track of xids in ChunkController
The ChunkController keeps track of a per-connection xid that users can use to generate new xids.
1 parent 06d6700 commit 5b38fcc

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

async/Async_OpenFlow.mli

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ module Chunk : sig
162162
]
163163

164164
val client_version : t -> Client_id.t -> int
165+
val client_next_xid : t -> Client_id.t -> int32
165166

166167
val send_txn
167168
: t
@@ -191,7 +192,7 @@ module OpenFlow0x01 : sig
191192
val send_txn
192193
: t
193194
-> Client_id.t
194-
-> m
195+
-> OpenFlow0x01.Message.t
195196
-> [ `Sent of Message.t Ivar.t | `Drop of exn ] Deferred.t
196197
end
197198

@@ -214,7 +215,7 @@ module OpenFlow0x04 : sig
214215
val send_txn
215216
: t
216217
-> Client_id.t
217-
-> m
218+
-> OpenFlow0x04.Message.t
218219
-> [ `Sent of Message.t Ivar.t | `Drop of exn ] Deferred.t
219220
end
220221

async/Async_OpenFlow0x01.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ module Controller = struct
9696

9797
let send_txn t sw_id msg =
9898
let c_id = client_id_of_switch_exn t sw_id in
99-
ChunkController.send_txn t.sub c_id (Message.marshal' msg)
99+
let xid = ChunkController.client_next_xid t.sub c_id in
100+
ChunkController.send_txn t.sub c_id (Message.marshal' (xid, msg))
100101

101102
let send_ignore_errors t sw_id msg =
102103
let c_id = client_id_of_switch_exn t sw_id in

async/Async_OpenFlow0x04.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ module Controller = struct
131131

132132
let send_txn t sw_id msg =
133133
let c_id = client_id_of_switch_exn t sw_id in
134-
ChunkController.send_txn t.sub c_id (Message.marshal' msg)
134+
let xid = ChunkController.client_next_xid t.sub c_id in
135+
ChunkController.send_txn t.sub c_id (Message.marshal' (xid, msg))
135136

136137
let send_ignore_errors t sw_id msg =
137138
let c_id = client_id_of_switch_exn t sw_id in

async/Async_OpenFlowChunk.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ module Controller = struct
4747
type t = {
4848
state : [ `Active | `Idle | `Kill ];
4949
version : int option;
50+
mutable xid : int32;
5051
txns : r Ivar.t XidTbl.t;
5152
state_entered : Time.t;
5253
last_activity : Time.t
@@ -56,11 +57,17 @@ module Controller = struct
5657
let now = Time.now () in
5758
{ state = `Active
5859
; version = None
60+
; xid = 1l
5961
; txns = XidTbl.create ()
6062
; state_entered = now
6163
; last_activity = now
6264
}
6365

66+
let next_xid (t:t) =
67+
let xid = t.xid in
68+
t.xid <- Int32.(xid + 1l);
69+
xid
70+
6471
let add_txn (t:t) m =
6572
let xid = (Message.header_of m).OpenFlow_Header.xid in
6673
let ivar = ref None in
@@ -266,6 +273,9 @@ module Controller = struct
266273
| None -> raise Not_found
267274
| Some(ver) -> ver
268275

276+
let client_next_xid t c_id =
277+
Conn.next_xid (Client_id.Table.find_exn t.clients c_id)
278+
269279
let handshake v t evt =
270280
let open Header in
271281
match evt with

0 commit comments

Comments
 (0)