-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpad.py
More file actions
129 lines (92 loc) · 2.87 KB
/
pad.py
File metadata and controls
129 lines (92 loc) · 2.87 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from xdpd_gnu_linux_v03_gen.generate_rofl_xdpd import translate_p4_to_xdpd, generate_xdpd_rofl
from p4_interpreter import parse_p4
__protocols = {}
__functions = {}
# ---------------- PAD API functions ---------------------------------------------------
# --- CAPABILITIES ---
def get_all_capabilities():
raise Exception("Not implemented")
def get_capability(name):
raise Exception("Not implemented")
# --- PROTOCOLS ---
def add_protocol(name, spec):
__protocols[name] = spec
def remove_protocol(name):
if name in __protocols:
del __protocols[name]
def remove_all_protocols():
global __protocols
__protocols = {}
# --- FUNCTIONS ---
def add_function(name, spec):
__functions[name] = spec
def remove_function(name):
if name in __functions:
del __functions[name]
def remove_all_functions():
global __functions
__functions = {}
# --- COMMIT ---
def commit_configuration():
def join_specs(spec_dict_container):
"returns all specs in a single string"
joined_specs = ""
for spec in spec_dict_container.values():
joined_specs += spec
return joined_specs
fields = translate_p4_to_xdpd(parse_p4(join_specs(__protocols)),
parse_p4(join_specs(__functions)))
result = generate_xdpd_rofl(fields)
# TODO automatic ROFL and XDPD recompilation
return result
# --- ENTRIES ---
def add_entry(structure_id, key, mask, result):
raise NotImplementedError()
def remove_entry(structure_id, key, mask):
raise NotImplementedError()
def remove_all_entries(structure_id):
raise NotImplementedError()
if __name__ == "__main__":
import pprint
# Example of usage:
ethernet_hrd = """
header ethernet {
fields {
dst_addr : 48;
src_addr : 48;
ethertype : 16;
}
}
parser start {
ethernet;
}
parser ethernet {
switch(ethertype) {
case 0x9100: ictp;
}
}
"""
ictp_hdr = """
header ictp {
fields {
nid : 32;
csn : 32;
}
}
"""
push_ictp = """
action push_ictp {
add_header(ictp, sizeof(ethernet));
}
"""
pop_ictp = """
action pop_ictp {
remove_header(ictp, sizeof(ethernet));
}
"""
add_protocol("Ethernet", ethernet_hrd)
add_protocol("ICTP", ictp_hdr)
add_function("push_ictp", push_ictp)
add_function("pop_ictp", pop_ictp)
of_extensions_ids = commit_configuration()
pprint.pprint(of_extensions_ids)