blob: 17e9e73271dbe44bf7541df827075ea4a0944913 [file] [log] [blame]
You Wangdb927a52016-02-26 11:03:28 -08001"""
2This file contains intent class for CHOTestMonkey
3Author: you@onlab.us
4"""
5from threading import Lock
6
7class Controller:
8 def __init__( self, index ):
9 self.default = ''
10 self.index = index
11 self.ip = main.onosIPs[ index - 1 ]
12 self.CLI = None
13 self.CLILock = Lock()
14 self.status = 'up'
15
16 def setCLI( self, CLI ):
17 self.CLI = CLI
18
19 def startCLI( self ):
20 return self.CLI.startOnosCli( self.ip )
21
22 def isUp( self ):
23 return self.status == 'up'
24
25 def bringDown( self ):
26 self.status = 'down'
27
28 def bringUp( self ):
29 self.status = 'up'
30
31class Intent:
32 def __init__( self, id ):
33 self.default = ''
34 self.type = 'INTENT'
35 self.id = id
You Wang56577c82016-07-12 10:49:23 -070036 self.expectedState = 'UNKNOWN'
You Wangdb927a52016-02-26 11:03:28 -080037
38 def isHostIntent( self ):
39 return self.type == 'INTENT_HOST'
40
41 def isPointIntent( self ):
42 return self.type == 'INTENT_POINT'
43
You Wang2b687c02016-05-13 17:01:31 -070044 def isFailed( self ):
45 return self.expectedState == 'FAILED'
46
47 def isInstalled( self ):
48 return self.expectedState == 'INSTALLED'
49
You Wangdb927a52016-02-26 11:03:28 -080050class HostIntent( Intent ):
51 def __init__( self, id, hostA, hostB ):
52 Intent.__init__( self, id )
53 self.type = 'INTENT_HOST'
54 self.hostA = hostA
55 self.hostB = hostB
You Wang2b687c02016-05-13 17:01:31 -070056 self.deviceA = hostA.device
57 self.deviceB = hostB.device
You Wangdb927a52016-02-26 11:03:28 -080058
You Wang56577c82016-07-12 10:49:23 -070059 def setWithdrawn( self ):
60 self.expectedState = 'WITHDRAWN'
61 # TODO: should we check whether hostA and hostB are made correspondents by other intents/flows?
62 if self.hostB in self.hostA.correspondents:
63 self.hostA.correspondents.remove( self.hostB )
64 if self.hostA in self.hostB.correspondents:
65 self.hostB.correspondents.remove( self.hostA )
66
67 def setFailed( self ):
68 self.expectedState = 'FAILED'
69 # TODO: should we check whether hostA and hostB are made correspondents by other intents/flows?
70 if self.hostB in self.hostA.correspondents:
71 self.hostA.correspondents.remove( self.hostB )
72 if self.hostA in self.hostB.correspondents:
73 self.hostB.correspondents.remove( self.hostA )
74
75 def setInstalled( self ):
76 self.expectedState = 'INSTALLED'
77 # TODO: should we check whether hostA and hostB are already correspondents?
78 self.hostA.correspondents.append( self.hostB )
79 self.hostB.correspondents.append( self.hostA )
80
You Wangdb927a52016-02-26 11:03:28 -080081 def __str__( self ):
82 return "ID: " + self.id
83
84class PointIntent( Intent ):
85 def __init__( self, id, deviceA, deviceB ):
86 Intent.__init__( self, id )
87 self.type = 'INTENT_POINT'
88 self.deviceA = deviceA
89 self.deviceB = deviceB
90
You Wang56577c82016-07-12 10:49:23 -070091 def setWithdrawn( self ):
92 self.expectedState = 'WITHDRAWN'
93 for hostA in self.deviceA.hosts:
94 for hostB in self.deviceB.hosts:
95 if hostB in hostA.correspondents:
96 hostA.correspondents.remove( hostB )
97
98 def setFailed( self ):
99 self.expectedState = 'FAILED'
100 for hostA in self.deviceA.hosts:
101 for hostB in self.deviceB.hosts:
102 if hostB in hostA.correspondents:
103 hostA.correspondents.remove( hostB )
104
105 def setInstalled( self ):
106 self.expectedState = 'INSTALLED'
107 for hostA in self.deviceA.hosts:
108 for hostB in self.deviceB.hosts:
109 hostA.correspondents.append( hostB )
110
You Wangdb927a52016-02-26 11:03:28 -0800111 def __str__( self ):
112 return "ID: " + self.id