#! /bin/bash -ex

compile_flag=0
offload_flag=0
assign_ip_flag=0
location=$(pwd)
while getopts 'coi' flag; do
  case "${flag}" in
    c) compile_flag=1 ;;
    o) offload_flag=1 ;;
    i) assign_ip_flag=1 ;;
  esac
done

if [[ $compile_flag -eq 1 ]]
then
    # compile the nfp code
    sudo /opt/netronome/p4/bin/nfp4build -o ./p4src/test.nffw -p ./p4src/out -4 ./p4src/test.p4 -l lithium --nfp4c_p4_version 16 --nfirc_mac_ingress_timestamp --nfp4c_p4_compiler p4c-nfp -e
fi

if [[ $offload_flag -eq 1 ]]
then
  # move to p4 bin
  cd /opt/netronome/p4/bin/

  # offload
  sudo ./rtecli design-load -f $location/p4src/test.nffw -c $location/p4src/test.p4cfg -p $location/p4src/out/pif_design.json

  # returning back to base
  cd $location
fi

if [[ $assign_ip_flag -eq 1 ]]
then
    #assigning IPs to network interfaces
    sudo ./assign_ip_test.sh
fi

