Skip to content

Commit 1487294

Browse files
author
David Gengenbach
committed
Add support to manage multiple switches
1 parent 07ef764 commit 1487294

File tree

6 files changed

+196
-138
lines changed

6 files changed

+196
-138
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
Dockerfile
2+
venv/

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*~
22
*.pyc
33
.coverage
4+
venv/

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,22 +272,24 @@ import p4runtime_sh.shell as sh
272272

273273
# you can omit the config argument if the switch is already configured with the
274274
# correct P4 dataplane.
275-
sh.setup(
275+
client = sh.setup(
276276
device_id=1,
277277
grpc_addr='localhost:50051',
278278
election_id=(0, 1), # (high, low)
279-
config=sh.FwdPipeConfig('config/p4info.pb.txt', 'config/device_config.bin')
279+
config=sh.FwdPipeConfig('config/p4info.pb.txt', 'config/device_config.bin'),
280+
# This enables controlling multiple switches
281+
set_global_client=False
280282
)
281283

282284
# see p4runtime_sh/test.py for more examples
283-
te = sh.TableEntry('<table_name>')(action='<action_name>')
285+
te = sh.TableEntry('<table_name>', client=client)(action='<action_name>')
284286
te.match['<name>'] = '<value>'
285287
te.action['<name>'] = '<value>'
286288
te.insert()
287289

288290
# ...
289291

290-
sh.teardown()
292+
sh.teardown(client)
291293
```
292294

293295
Note that at the moment the P4Runtime client object is a global variable, which

p4runtime_sh/p4runtime.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from p4.v1 import p4runtime_pb2
2727
from p4.v1 import p4runtime_pb2_grpc
2828

29+
from p4runtime_sh.context import Context
30+
2931

3032
class P4RuntimeErrorFormatException(Exception):
3133
def __init__(self, message):
@@ -137,6 +139,7 @@ def handle(*args, **kwargs):
137139

138140
class P4RuntimeClient:
139141
def __init__(self, device_id, grpc_addr, election_id):
142+
self.context = Context()
140143
self.device_id = device_id
141144
self.election_id = election_id
142145
logging.debug("Connecting to device {} at {}".format(device_id, grpc_addr))

0 commit comments

Comments
 (0)