Skip to content

Commit

Permalink
web: add packets for each example
Browse files Browse the repository at this point in the history
  • Loading branch information
hackedy committed Nov 30, 2021
1 parent ac374f7 commit 17597d3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 31 deletions.
19 changes: 13 additions & 6 deletions html_build/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ <h3>P4 Program</h3>
<div class="row">
<div class="col-lg-3">
<h3>Input Packet</h3>
<textarea rows="4" cols="100" id="packet-in" style="font-family: 'Consolas'; font-size:10pt;" spellcheck="false">01
0F 01
AA BB
50 65 74 72 34 20 69 73 20 61 77 65 73 6f 6d 65 21</textarea>
<textarea rows="4" cols="100" id="packet-in" style="font-family: 'Consolas'; font-size:10pt;" spellcheck="false"></textarea>
</div>
</div>
<div class="row">
Expand Down Expand Up @@ -133,13 +130,23 @@ <h3>Output</h3>
var in_area = document.getElementById("packet-in")
var out_area = document.getElementById("packet-out")
button.onclick = function () {
const button = document.getElementById("evaluate")
var in_area = document.getElementById("packet-in")
var out_area = document.getElementById("packet-out")
out_area.value = Petr4.eval(in_area.value, control_editor.getValue(), p4_editor.getValue());
}

function select_demo(){
var path = "/" + document.getElementById("demo_options").value;
var code = Petr4.read(path);
var in_area = document.getElementById("packet-in")
var code_path = "/" + document.getElementById("demo_options").value;
var pkt_path = code_path + ".pkt";
var desc_path = code_path + ".txt";
var code = Petr4.read(code_path);
var pkt = Petr4.read(pkt_path);
var desc = Petr4.read(desc_path);
in_area.value = pkt;
p4_editor.setValue(code, -1);
// TODO update description <div> innerHTML here
}
select_demo();
</script>
Expand Down
19 changes: 19 additions & 0 deletions web/bake.ml
Original file line number Diff line number Diff line change
Expand Up @@ -759,3 +759,22 @@ control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {

V1Switch(p(), vrfy(), ingress(), egress(), update(), deparser()) main;
|}

let sr_acl_p4_pkt =
"01 0F 01 AA BB 50 65 74 72 34 20 69 73 20 61 77 65 73 6F 6D 65 21"

let null_pkt = "00 00 00 00 00 00 00 00"

let fs =
[("/core.p4", core_p4_str);
("/v1model.p4", v1model_p4_str);
("/sr_acl.p4", sr_acl_p4_str);
("/sr_acl.p4.pkt", sr_acl_p4_pkt);
("/register.p4", register_p4_str);
("/register.p4.pkt", null_pkt);
("/switch_ebpf.p4", switch_ebpf_p4_str);
("/switch_ebpf.p4.pkt", null_pkt);
("/table-entries-lpm-bmv2.p4", table_entries_lpm_bmv2_p4_str);
("/table-entries-lpm-bmv2.p4.pkt", null_pkt);
("/union-valid-bmv2.p4", union_valid_bmv2_p4_str);
("/union-valid-bmv2.p4.pkt", null_pkt)]
35 changes: 10 additions & 25 deletions web/web.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,28 @@

open Petr4.Common
open Js_of_ocaml
open Core_kernel

exception ParsingError of string

module Webpp = P4pp.Eval.Make(struct
let exists = function
| "/core.p4"
| "/sr_acl.p4"
| "/register.p4"
| "/switch_ebpf.p4"
| "/table-entries-lpm-bmv2.p4"
| "/union-valid-bmv2.p4"
| "/v1model.p4" ->
true
| str ->
false
let exists =
List.Assoc.mem ~equal:String.equal Bake.fs

let load = function
| "/core.p4" -> Bake.core_p4_str
| "/sr_acl.p4" -> Bake.sr_acl_p4_str
| "/v1model.p4" -> Bake.v1model_p4_str
| "/register.p4" -> Bake.register_p4_str
| "/switch_ebpf.p4" -> Bake.switch_ebpf_p4_str
| "/table-entries-lpm-bmv2.p4" ->
Bake.table_entries_lpm_bmv2_p4_str
| "/union-valid-bmv2.p4" ->
Bake.union_valid_bmv2_p4_str
| fn -> failwith (fn ^ ": not found")
let load path =
match List.Assoc.find ~equal:String.equal Bake.fs path with
| Some contents -> contents
| None -> failwith (path ^ ": not found")
end)

module Conf: Parse_config = struct
let red s = s
let green s = s

let preprocess _ p4_file_contents =
let file ="input.p4" in
let file = "input.p4" in
let env = P4pp.Eval.empty file ["/"] [] in
let str,_ = Webpp.preprocess env file p4_file_contents in
let str, _ = Webpp.preprocess env file p4_file_contents in
str
end

Expand All @@ -76,5 +61,5 @@ let _ =
try
eval false (Js.to_string packet) [] (Js.to_string control_string) (Js.to_string p4_content) |> Js.string
with e ->
Printf.sprintf "Exception: %s" (Printexc.to_string e) |> Js.string
Printf.sprintf "Exception: %s" (Exn.to_string e) |> Js.string
end)

0 comments on commit 17597d3

Please sign in to comment.