Skip to content

Commit

Permalink
Refactor Into Plugin Architecture (#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
craig-riecke authored Jul 22, 2016
1 parent a1e70c9 commit 5e1fe76
Show file tree
Hide file tree
Showing 44 changed files with 1,558 additions and 1,280 deletions.
6 changes: 2 additions & 4 deletions _oasis
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Library frenetic
Frenetic_NetKAT_Net,
Frenetic_NetKAT_Parser,
Frenetic_NetKAT_Pretty,
Frenetic_NetKAT_SDN_Json,
Frenetic_NetKAT_Semantics,
Frenetic_Network,
Frenetic_OpenFlow,
Expand Down Expand Up @@ -90,9 +89,8 @@ Library async
Frenetic_Compile_Server,
Frenetic_Log,
Frenetic_Http_Controller,
Frenetic_OpenFlow0x01_Controller,
Frenetic_OpenFlow0x01_Plugin,
Frenetic_NetKAT_Controller,
Frenetic_NetKAT_Updates,
Frenetic_Ox

Executable frenetic
Expand Down Expand Up @@ -181,7 +179,7 @@ Executable benchmark
Test all_tests
Run$: flag(tests)
# -only-test Test_Frenetic_GroupTable0x04.ml
Command: $testtool inline-test-runner frenetic
Command: $testtool inline-test-runner frenetic
TestTools: testtool

Document frenetic
Expand Down
4 changes: 2 additions & 2 deletions async/Frenetic_Compile_Server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let compile_respond pol =
(* JSON conversion is not timed. *)
let json_tbls = List.map tbls ~f:(fun (sw, tbl) ->
`Assoc [("switch_id", `Int (Int64.to_int_exn sw));
("tbl", Frenetic_NetKAT_SDN_Json.flowTable_to_json tbl)]) in
("tbl", Frenetic_NetKAT_Json.flowTable_to_json tbl)]) in
let resp = Yojson.Basic.to_string ~std:true (`List json_tbls) in
let headers = Cohttp.Header.init_with
"X-Compile-Time" (Float.to_string time) in
Expand Down Expand Up @@ -53,7 +53,7 @@ let handle_request
let sw = Int64.of_string switchId in
Comp.compile_local ~options:!current_compiler_options !policy |>
Comp.to_table ~options:!current_compiler_options sw |>
Frenetic_NetKAT_SDN_Json.flowTable_to_json |>
Frenetic_NetKAT_Json.flowTable_to_json |>
Yojson.Basic.to_string ~std:true |>
Cohttp_async.Server.respond_with_string
| `POST, ["config"] ->
Expand Down
45 changes: 19 additions & 26 deletions async/Frenetic_Http_Controller.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ type client = {

let current_compiler_options = ref Comp.default_compiler_options

(* TODO(arjun):
<facepalm>
These are OpenFlow 1.0 types. Everywhere else, we are using SDN_Types. *)
let port_to_json port = `Int (Int32.to_int_exn port)

let switch_and_ports_to_json (sw, ports) =
Expand All @@ -34,7 +29,6 @@ let current_switches_to_json lst =

let current_switches_to_json_string lst =
Yojson.Basic.to_string ~std:true (current_switches_to_json lst)
(* </facepalm> *)

let unions (pols : policy list) : policy =
List.fold_left pols ~init:drop ~f:(fun p q -> Union (p, q))
Expand Down Expand Up @@ -66,8 +60,9 @@ let get_client (clientId: string): client =
{ policy_node = node; event_reader = r; event_writer = w }
)

(* The Controller module is a parameter because port_stats and packet_out are called directly. *)
let handle_request
(module Controller : Frenetic_NetKAT_Controller.CONTROLLER)
(module Controller : Frenetic_NetKAT_Controller.CONTROLLER)
~(body : Cohttp_async.Body.t)
(client_addr : Socket.Address.Inet.t)
(request : Request.t) : Server.response Deferred.t =
Expand All @@ -79,22 +74,21 @@ let handle_request
| `GET, ["port_stats"; switch_id; port_id] ->
port_stats (Int64.of_string switch_id) (Int32.of_string port_id)
>>= fun portStats ->
Server.respond_with_string (Frenetic_NetKAT_Json.port_stats_to_json_string portStats)
Server.respond_with_string (Frenetic_NetKAT_Json.port_stat_to_json_string portStats)
| `GET, ["current_switches"] ->
current_switches () >>= fun switches ->
switches () >>= fun switches ->
Server.respond_with_string (current_switches_to_json_string switches)
| `GET, ["query"; name] ->
if (is_query name) then
query name
>>= fun stats ->
Server.respond_with_string (Frenetic_NetKAT_Json.stats_to_json_string stats)
else
begin
Log.info "query %s is not defined in the current policy" name;
let headers = Cohttp.Header.init_with "X-Query-Not-Defined" "true" in
Server.respond_with_string ~headers
(Frenetic_NetKAT_Json.stats_to_json_string (0L, 0L))
end
(* TODO: check if query exists *)
query name
>>= fun stats ->
Server.respond_with_string (Frenetic_NetKAT_Json.stats_to_json_string stats)
(* begin *)
(* Log.info "query %s is not defined in the current policy" name; *)
(* let headers = Cohttp.Header.init_with "X-Query-Not-Defined" "true" in *)
(* Server.respond_with_string ~headers *)
(* (Frenetic_NetKAT_Json.stats_to_json_string (0L, 0L)) *)
(* end *)
| `GET, [clientId; "event"] ->
let curr_client = get_client clientId in
(* Check if there are events that this client has not seen yet *)
Expand All @@ -106,10 +100,9 @@ let handle_request
handle_parse_errors' body
(fun str ->
let json = Yojson.Basic.from_string str in
Frenetic_NetKAT_SDN_Json.pkt_out_from_json json)
(fun (sw_id, pkt_out) ->
send_packet_out sw_id pkt_out
>>= fun () ->
Frenetic_NetKAT_Json.pkt_out_from_json json)
(fun (sw_id, port_id, payload, policies) ->
packet_out sw_id port_id payload policies >>= fun () ->
Cohttp_async.Server.respond `OK)
| `POST, [clientId; "update_json"] ->
handle_parse_errors body parse_update_json
Expand Down Expand Up @@ -144,14 +137,14 @@ let print_error addr exn =
| None -> Log.error "%s" monitor_exn

let listen ~http_port ~openflow_port =
let module Controller = Frenetic_NetKAT_Controller.Make in
let module Controller = Frenetic_NetKAT_Controller.Make(Frenetic_OpenFlow0x01_Plugin) in
let on_handler_error = `Call print_error in
let _ = Cohttp_async.Server.create
~on_handler_error
(Tcp.on_port http_port)
(handle_request (module Controller)) in
let (_, pol_reader) = Frenetic_DynGraph.to_pipe pol in
let _ = Pipe.iter pol_reader ~f:(fun pol -> Controller.update_policy pol) in
let _ = Pipe.iter pol_reader ~f:(fun pol -> Controller.update pol) in
Controller.start openflow_port;
don't_wait_for(propogate_events Controller.event);
Deferred.return ()
Expand Down
Loading

0 comments on commit 5e1fe76

Please sign in to comment.