Skip to content

Commit

Permalink
tofino backend: bring up ports from the command line
Browse files Browse the repository at this point in the history
  • Loading branch information
jsonch committed Jun 17, 2024
1 parent 9fc2d34 commit e2d6c64
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/utils/generator/makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DPTC="../../../dptc"

build:
$(DPTC) generator.dpt -o build
$(DPTC) --port 130@40 --recirc_port 196 generator.dpt -o build
assemble:
cd build && make
sim:
Expand Down
6 changes: 5 additions & 1 deletion src/bin/Compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ let profile_for_tofino target_filename portspec build_dir profile_cmd =
;;

let compile_to_tofino dptfn =
let portspec = ParsePortSpec.parse Cmdline.cfg.portspec in
(* use the command line port arguments if there is no spec file *)
let portspec = if (Cmdline.cfg.portspec = None)
then ParsePortSpec.create (Cmdline.cfg.ports) (Cmdline.cfg.recirc_port)
else ParsePortSpec.parse Cmdline.cfg.portspec
in
report
@@ "Starting P4-Tofino compilation. Using switch port configuration: ";
print_endline (ParsePortSpec.string_of_portconfig portspec);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/backend/tofino/p4/TofinoCoreToP4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,7 @@ let prog_to_p4_prog (prog : prog) : p4_prog =
{globals; ingress=ingress_pipe; control_config; egress=egress_pipe;}
;;

(* derive the port declarations from the spec *)
(* read port initialization declarations from config *)
let port_decls portspec =
let open ParsePortSpec in
let all_ports = portspec.external_ports@portspec.internal_ports in
Expand Down
11 changes: 10 additions & 1 deletion src/lib/backend/tofino/util/ParsePortSpec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ let p dpid speed = {dpid; speed}

type port_config = {
recirc_dpid : int;
internal_ports : port list;
(* All of the config below is depreciated.
They are only used by a complicated (and unnecessary)
tofino-specific pass that generates a parser based on a port spec.*)
internal_ports : port list;
external_ports : port list;
port_events : (int * string) list;
}
Expand Down Expand Up @@ -52,6 +55,12 @@ let check recirc_dpid internal_dpids external_dpids (bound_dpids : int list) =
not (Caml.List.exists (fun dpid -> Caml.List.mem dpid all_dpids) bound_dpids)
;;

(* new simpler method. Should be called on vals from command line --port and --recirc_port *)
let create front_panel_ports recirc_dpid =
let external_ports = Caml.List.map (fun (dpid, speed) -> p dpid speed) front_panel_ports in
{recirc_dpid; internal_ports = []; external_ports; port_events = []}
;;

let parse fn_opt =
match fn_opt with
| None -> default_port_config
Expand Down
21 changes: 20 additions & 1 deletion src/lib/frontend/Cmdline.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ type config =
; mutable interactive : bool
(** Run interpreter interactively (stdin / stdout) **)
; mutable output : string
; mutable json : bool (* tofino backend *) (** Print json outputs **)
; mutable json : bool (** Print json outputs **)
(* tofino backend config *)
; mutable builddir : string (* build directory where p4 + other code goes *)
; mutable portspec : string option (* path to port specification json *)
(* portspec is depreciated and not necessary. Just use ports and recirc_ports flags *)
; mutable ports : (int * int) list (* list of port ids and speeds *)
; mutable recirc_port : int (* port id for recirculation *)
; mutable profile_cmd :
string option (* something with profiling -- probably depreciated *)
; mutable ctl_fn : string option (* path to optional python control program *)
Expand Down Expand Up @@ -65,6 +69,8 @@ let default () =
; json = false
; builddir = "lucid_tofino_build"
; portspec = None
; ports = [(128, 10); (129, 10); (130, 10); (131, 10)]
; recirc_port = 196 (* default for tofino1 *)
; profile_cmd = None
; ctl_fn = None
; serverlib = false
Expand Down Expand Up @@ -217,6 +223,19 @@ let parse_tofino () =
; ( "--ports"
, Arg.String set_portspec
, "Path to the ports specification file" )
; ( "--port"
, Arg.String
(fun s ->
let (id, speed) =
match String.split_on_char '@' s with
| [id; speed] -> (int_of_string id, int_of_string speed)
| _ -> failwith "Invalid port specification"
in
cfg.ports <- (id, speed) :: cfg.ports)
, "--port <dpid>@<speed> Specify a port to be brought up automatically in the generated control plane. Can be used multiple times." )
; ( "--recirc_port"
, Arg.Int (fun i -> cfg.recirc_port <- i)
, "Port id for recirculation" )
; ( "-p"
, Arg.String set_profile_cmd
, "Profile program instead of compiling." )
Expand Down

0 comments on commit e2d6c64

Please sign in to comment.