Created
December 12, 2013 05:05
-
-
Save arjunguha/7923434 to your computer and use it in GitHub Desktop.
Typed_tcp for OpenFlow 1.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Core.Std | |
open Async.Std | |
open OpenFlow0x01 | |
module OFMessage = struct | |
type t = (xid * Message.t) sexp_opaque with sexp | |
end | |
module OpenFlowArg = struct | |
module Client_message = OFMessage | |
module Server_message = OFMessage | |
module Transport = struct | |
type t = Reader.t * Writer.t | |
let create (r : Reader.t) (w : Writer.t) = return (r, w) | |
let close ((_, w) : t) = Writer.close w | |
let flushed_time ((_, w) : t) = Writer.flushed_time w | |
let read ((r, _) : t) = | |
let ofhdr_str = String.create Message.Header.size in | |
Reader.really_read r ofhdr_str >>= function | |
| `Eof _ -> return `Eof | |
| `Ok -> | |
let hdr = Message.Header.parse ofhdr_str in | |
let body_len = Message.Header.len hdr - Message.Header.size in | |
let body_buf = String.create body_len in | |
Reader.really_read r body_buf >>= function | |
| `Eof _ -> return `Eof | |
| `Ok -> return (`Ok (Message.parse hdr body_buf)) | |
let write ((_, w) : t) (xid, msg) = | |
Writer.write w (Message.marshal xid msg) | |
end | |
end | |
module Tcp = Typed_tcp.Make (OpenFlowArg) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Core.Std | |
open Async.Std | |
open OpenFlow0x01 | |
module OFMessage : sig | |
type t = (xid * Message.t) | |
end | |
module Tcp : Typed_tcp.S with | |
module Client_message = OFMessage | |
and module Server_message = OFMessage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment