Skip to content

Commit

Permalink
small bug fixes in tofino backend and dependency installer
Browse files Browse the repository at this point in the history
  • Loading branch information
jsonch committed May 23, 2024
1 parent b46a1be commit 73e04b2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
22 changes: 12 additions & 10 deletions install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ then
exit 1
fi
sudo apt-get install opam -y
# Initialize opam, if not already initialized
if ! opam var root &> /dev/null
then
opam init -y --auto-setup
fi
fi

if ! command -v opam &> /dev/null
then
echo "Failed to install opam. Exiting."
exit 1
fi
# Initialize opam, if not already initialized
if ! opam var root &> /dev/null
then
opam init -y --auto-setup
fi

if ! command -v opam &> /dev/null
then
echo "Opam not working, even after install and init attempts. Exiting."
exit 1
fi


# check for opam depext and install if not found
if ! opam list --installed depext &> /dev/null
then
Expand Down
2 changes: 1 addition & 1 deletion scripts/tofino/p4tapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ function start_asic_sim() {

# start the bf_switchd included with sde
function start_switchd() {
local CMD="sudo env SDE=$SDE SDE_INSTALL=$SDE_INSTALL PATH=$SDE_INSTALL/bin:$PATH LD_LIBRARY_PATH=/usr/local/lib:$SDE_INSTALL/lib:$LD_LIBRARY_PATH $SDE_INSTALL/bin/bf_switchd --background --status-port 7777 --install-dir $SDE_INSTALL --conf-file $1"
local CMD="sudo env SDE=$SDE SDE_INSTALL=$SDE_INSTALL PATH=$SDE_INSTALL/bin:$PATH LD_LIBRARY_PATH=/usr/local/lib:$SDE_INSTALL/lib:$LD_LIBRARY_PATH $SDE_INSTALL/bin/bf_switchd --background --status-port 7777 --install-dir $SDE_INSTALL --conf-file $1 --kernel-pkt"
# local CMD="sudo $SDE_INSTALL/bin/bf_switchd --install-dir $SDE_INSTALL --conf-file $1"
local SIG="bf_switchd: server started - listening on port 9999"
echo "SWITCHD COMMAND: $CMD"
Expand Down
19 changes: 18 additions & 1 deletion src/lib/backend/tofino/p4/TofinoCoreToP4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1870,13 +1870,30 @@ let prog_to_p4_prog (prog : prog) : p4_prog =
{globals; ingress=ingress_pipe; control_config; egress=egress_pipe;}
;;

let translate_prog prog =
(* derive the port declarations from the spec *)
let port_decls portspec =
let open ParsePortSpec in
let all_ports = portspec.external_ports@portspec.internal_ports in
let decls = List.map
(fun port_config ->
let dpid = port_config.dpid in
let speed = port_config.speed in
decl@@DPort{dpid; speed})
all_ports
in
decls
;;

let translate_prog prog portspec =
(* print_endline ("translating prog: " ^ (TofinoCorePrinting.prog_to_string prog)); *)
let p4_prog = prog_to_p4_prog prog in
(* print_endline "----- p4_prog -----";
print_endline (p4_prog_to_string p4_prog);
print_endline "-------------------"; *)
let tofino_prog = p4_prog_to_tofino_prog p4_prog in
let tofino_port_decls = port_decls portspec in
let control_config = tofino_port_decls@tofino_prog.control_config in
let tofino_prog = {tofino_prog with control_config} in
tofino_prog
;;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/backend/tofino/tofinoPipeline.ml
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ let compile ds portspec =

(* translate into final P4-tofino-lite IR *)
report_if_verbose "-------Translating to final P4-tofino-lite IR-------";
let tofino_prog = TofinoCoreToP4.translate_prog core_prog in
let tofino_prog = TofinoCoreToP4.translate_prog core_prog portspec in
(* generate the python event library *)
let py_eventlib =
if
Expand Down

0 comments on commit 73e04b2

Please sign in to comment.