-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenesisAst.py
87 lines (67 loc) · 1.58 KB
/
GenesisAst.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
from enum import Enum
class Type(Enum):
VAR = 0
IP = 1
SW = 2
ENDPT = 3
REACH = 4
CSRT = 5
class GPLAst(object):
def __init__(self, type) :
self.type = type
self.context = dict()
def getType(self) :
return self.type
def setType(self, type) :
self.type = type
class IpAst(GPLAst) :
def __init__(self, prefix, plen=32) :
GPLAst.__init__(self, type=Type.IP)
self.prefix = prefix
self.plen = plen
def printAst(self) :
print self.prefix + "/" + str(self.plen)
def getIp(self) :
return self.prefix + "/" + str(self.plen)
class SwAst(GPLAst) :
def __init__(self, name) :
GPLAst.__init__(self, type=Type.SW)
self.sw = name
def getSw(self) :
return self.sw
class EndpointAst(GPLAst):
def __init__(self, ip, sw):
GPLAst.__init__(self, type=Type.ENDPT)
self.ip = ip
self.sw = sw
def getIp(self) :
return self.ip.getIp()
def getSw(self) :
return self.sw.getSw()
class VariableAst(GPLAst) :
def __init__(self, name):
GPLAst.__init__(self, type=Type.VAR)
self.name = name
def getName(self) :
return self.name
class ReachAst(GPLAst):
def __init__(self, predicate, src, dst, waypoints=None) :
GPLAst.__init__(self, type=Type.REACH)
self.src = src
self.dst = dst
self.match = predicate
self.waypoints = waypoints
self.pc = -1
def setPacketClass(self, pc):
self.pc = pc
def getPacketClass(self):
return self.pc
class ConstraintAst(GPLAst):
def __init__(self, sw1, size):
GPLAst.__init__(self, type=Type.CSRT)
self.sw = name
self.maxSize = size
def getSw(self) :
return self.sw
def getMaxSize(self):
return self.maxSize