-
Notifications
You must be signed in to change notification settings - Fork 0
/
P4Runtime_test.py
97 lines (81 loc) · 2.73 KB
/
P4Runtime_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# ALREADY DONE IN s1-runtime.json
# INTENDED AS AN EXAMPLE FOR FUTURE DEVELOPMENT
#!/usr/bin/env python2
import grpc
import os, sys
from time import sleep
# Import P4Runtime lib from parent utils dir
# Probably there's a better way of doing this.
sys.path.append(
os.path.join(os.path.dirname(os.path.abspath(__file__)),
'utils/p4runtime_lib'))
import bmv2
from error_utils import printGrpcError
from switch import ShutdownAllSwitchConnections
import helper
p4info_file_path = "build/Raft.p4.p4info.txt"
p4info_helper = helper.P4InfoHelper(p4info_file_path)
s1 = bmv2.Bmv2SwitchConnection(
name='s1',
address='127.0.0.1:50051',
device_id=0,
proto_dump_file='logs/s1-p4runtime-requests_my_py.txt')
s1.MasterArbitrationUpdate()
table_entry2 = p4info_helper.buildTableEntry(
table_name="MyIngress.follower",
match_fields={
"meta.raft_metadata.role": 0,
"hdr.raft.messageType": 10,
"hdr.ipv4.dstAddr": [0x0, 0xa, 1]
},
action_name="MyIngress.follower_timeout",
action_params={}
)
s1.WriteTableEntry(table_entry2)
print("Installed leader table entry rule on {}".format(s1.name))
def install_s1__entry_rule(): # DO NOT USE
# ALREADY DONE IN s1-runtime.json
# INTENDED AS AN EXAMPLE FOR FUTURE DEVELOPMENT
#!/usr/bin/env python2
import grpc
import os
from time import sleep
# Import P4Runtime lib from parent utils dir
# Probably there's a better way of doing this.
sys.path.append(
os.path.join(os.path.dirname(os.path.abspath(__file__)),
'utils/p4runtime_lib'))
import bmv2
from error_utils import printGrpcError
from switch import ShutdownAllSwitchConnections
import helper
p4info_file_path = "build/Raft.p4.p4info.txt"
p4info_helper = helper.P4InfoHelper(p4info_file_path)
s1 = bmv2.Bmv2SwitchConnection(
name='s1',
address='127.0.0.1:50051',
device_id=0,
proto_dump_file='logs/s1-p4runtime-requests_my_py.txt')
s1.MasterArbitrationUpdate()
table_entry = p4info_helper.buildTableEntry(
table_name="MyIngress.leader",
match_fields={
"meta.raft_metadata.role": 2,
"hdr.raft.messageType": 2
},
action_name="MyIngress.spread_new_request",
action_params={}
)
table_entry2 = p4info_helper.buildTableEntry(
table_name="MyIngress.follower",
match_fields={
"meta.raft_metadata.role": 0,
"hdr.raft.messageType": 10,
"hdr.ipv4.dstAddr": ["10.0.1.254", 32]
},
action_name="MyIngress.follower_timeout",
action_params={}
)
s1.WriteTableEntry(table_entry)
s1.WriteTableEntry(table_entry2)
print("Installed leader table entry rule on {}".format(s1.name))