Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WORK IN PROGRESS] Add support to manage multiple switches #50

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Dockerfile
venv/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*~
*.pyc
.coverage
venv/
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,22 +272,24 @@ import p4runtime_sh.shell as sh

# you can omit the config argument if the switch is already configured with the
# correct P4 dataplane.
sh.setup(
client = sh.setup(
device_id=1,
grpc_addr='localhost:50051',
election_id=(0, 1), # (high, low)
config=sh.FwdPipeConfig('config/p4info.pb.txt', 'config/device_config.bin')
config=sh.FwdPipeConfig('config/p4info.pb.txt', 'config/device_config.bin'),
# This enables controlling multiple switches
set_global_client=False
)

# see p4runtime_sh/test.py for more examples
te = sh.TableEntry('<table_name>')(action='<action_name>')
te = sh.TableEntry('<table_name>', client=client)(action='<action_name>')
te.match['<name>'] = '<value>'
te.action['<name>'] = '<value>'
te.insert()

# ...

sh.teardown()
sh.teardown(client)
```

Note that at the moment the P4Runtime client object is a global variable, which
Expand Down
3 changes: 3 additions & 0 deletions p4runtime_sh/p4runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from p4.v1 import p4runtime_pb2
from p4.v1 import p4runtime_pb2_grpc

from p4runtime_sh.context import Context


class P4RuntimeErrorFormatException(Exception):
def __init__(self, message):
Expand Down Expand Up @@ -137,6 +139,7 @@ def handle(*args, **kwargs):

class P4RuntimeClient:
def __init__(self, device_id, grpc_addr, election_id):
self.context = Context()
self.device_id = device_id
self.election_id = election_id
logging.debug("Connecting to device {} at {}".format(device_id, grpc_addr))
Expand Down
Loading