Skip to content

Creating Apps With OCaml and Ox

Craig Riecke edited this page Jun 21, 2016 · 2 revisions

Ox is a framework for straight OpenFlow programming in OCaml, in other words there is no NetKAT involved in Ox. It is similar to Python-based frameworks RYU and Pox in this respect. Since Frenetic already has an OpenFlow library baked in (and it's the only OCaml-based OpenFlow implementation out there), you can think of Ox as a thin OCaml veneer over the top of it.

The Frenetic Tutorial covers Ox, mostly as a contrasting technology to NetKAT.

Here's a template for an Ox program:

open Frenetic_Ox
open Frenetic_OpenFlow0x01
open Core.Std
open Async.Std

module MyApplication = struct
  include DefaultHandlers
  open Platform

  let packet_in (sw : switchId) (xid : xid) (pk : packetIn) : unit =
     ()

  let switch_disconnected (sw : switchId) : unit = ()

  let switch_connected (sw : switchId) (feats : SwitchFeatures.t) : unit = ()

  let barrier_reply _ _ = ()

  let stats_reply _ _ _ = ()

  let cleanup _ = ()

end

let _ =
  let module C = Make (MyApplication) in
  C.start ();

The handlers listed above mirror OpenFlow 1.0's switch-to-controller messages (and are also in Frenetic_Ox.Default_Handlers, so you don't need to provide all of them). Most of the data types you use in Ox, like SwitchFeatures.t are from the Frenetic_OpenFlow0x01 module.

The commands for Ox mirror OpenFlow 1.0's controller-to-switch messages, and are also listed in Frenetic_OpenFlow0x01. For example, a Packet Out command looks like this:

  send_packet_out sw 0l {
    output_payload = pk.input_payload;
    port_id = None;
    apply_actions = [Output AllPorts] 
  }

Then compile the code:

frenetic@ubuntu-14.04:~/src/frenetic/examples$ ox-build template_ox.d.byte

The ox-build is a bundled crutch build script, similar to Jane Street's core-build. See the Build Section for more sophisticated Build script tips.

See the API Documentation for Frenetic_OpenFlow0x01 or in the source code on Github.