diff --git a/examples/utils/generator/makefile b/examples/utils/generator/makefile index ed3da088..c5937c78 100644 --- a/examples/utils/generator/makefile +++ b/examples/utils/generator/makefile @@ -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: diff --git a/src/bin/Compiler.ml b/src/bin/Compiler.ml index 75154878..98355a29 100644 --- a/src/bin/Compiler.ml +++ b/src/bin/Compiler.ml @@ -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); diff --git a/src/lib/backend/tofino/p4/TofinoCoreToP4.ml b/src/lib/backend/tofino/p4/TofinoCoreToP4.ml index f88f7e17..0bcc60a1 100644 --- a/src/lib/backend/tofino/p4/TofinoCoreToP4.ml +++ b/src/lib/backend/tofino/p4/TofinoCoreToP4.ml @@ -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 diff --git a/src/lib/backend/tofino/util/ParsePortSpec.ml b/src/lib/backend/tofino/util/ParsePortSpec.ml index 662d646e..072f8c4a 100644 --- a/src/lib/backend/tofino/util/ParsePortSpec.ml +++ b/src/lib/backend/tofino/util/ParsePortSpec.ml @@ -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; } @@ -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 diff --git a/src/lib/frontend/Cmdline.ml b/src/lib/frontend/Cmdline.ml index 9aeb806e..d84d9ffd 100644 --- a/src/lib/frontend/Cmdline.ml +++ b/src/lib/frontend/Cmdline.ml @@ -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 *) @@ -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 @@ -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 @ 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." )