Hey sorry if my explanation feels vague, for now I just want to make a simple switch which should do basic forwading
So, I did run the command
sudo simple_switch_grpc -i 1@wlx0c0e761be19c -i 2@enp2s0 --device-id 0 --no-p4 --log-console --thrift-port 9090 – --grpc-server-addr 0.0.0.0:50051
and then in another terminal I created a controller which just connects to the switch
controller.py
import argparse
import grpc
import os
import sys
from time import sleep
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "utils/"))
import bmv2
from switch import ShutdownAllSwitchConnections
from utils.convert import encodeNum
import helper
def printGrpcError(e):
print("gRPC Error:", e.details(), end="")
status_code = e.code()
print("(%s)" % status_code.name, end="")
traceback = sys.exc_info()[2]
print("[%s:%d]" % (traceback.tb_frame.f_code.co_filename, traceback.tb_lineno))
def main(p4info_file_path, bmv2_file_path):
# Instantiate a P4Runtime helper from the p4info file
p4info_helper = helper.P4InfoHelper(p4info_file_path)
try:
# Create a switch connection object for s1 and s2;
# this is backed by a P4Runtime gRPC connection.
# Also, dump all P4Runtime messages sent to switch to given txt files.
s1 = bmv2.Bmv2SwitchConnection(
name="s0",
address="0.0.0.0:50051",
device_id=0,
proto_dump_file="p4runtime.log",
)
# Send master arbitration update message to establish this controller as
# master (required by P4Runtime before performing any other write operation)
if s1.MasterArbitrationUpdate() == None:
print("Failed to establish the connection")
# Install the P4 program on the switches
s1.SetForwardingPipelineConfig(
p4info=p4info_helper.p4info, bmv2_json_file_path=bmv2_file_path
)
print("Installed P4 Program using SetForwardingPipelineConfig on s1")
except KeyboardInterrupt:
print(" Shutting down.")
except grpc.RpcError as e:
printGrpcError(e)
ShutdownAllSwitchConnections()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="P4Runtime Controller")
parser.add_argument(
"--p4info",
help="p4info proto in text format from p4c",
type=str,
action="store",
required=False,
default="./firmeware.p4info.txt",
)
parser.add_argument(
"--bmv2-json",
help="BMv2 JSON file from p4c",
type=str,
action="store",
required=False,
default="./simple.json",
)
args = parser.parse_args()
if not os.path.exists(args.p4info):
parser.print_help()
print("\np4info file %s not found!" % args.p4info)
parser.exit(1)
if not os.path.exists(args.bmv2_json):
parser.print_help()
print("\nBMv2 JSON file %s not found!" % args.bmv2_json)
parser.exit(2)
main(args.p4info, args.bmv2_json)
With command
python3 s_controller.py --p4info basic.p4.p4info.txt --bmv2-json basic.json
and it gives the output
Installed P4 Program using SetForwardingPipelineConfig on s1
So I am assuming the p4 program is installed correctly on switch and now I can write further rules right?