Skip to content

Commit

Permalink
Add support to manage multiple switches
Browse files Browse the repository at this point in the history
  • Loading branch information
David Gengenbach committed Nov 10, 2020
1 parent 07ef764 commit ced0253
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 137 deletions.
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

0 comments on commit ced0253

Please sign in to comment.