You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 1 | """ |
| 2 | This file contains intent class for CHOTestMonkey |
| 3 | Author: you@onlab.us |
| 4 | """ |
| 5 | from threading import Lock |
| 6 | |
| 7 | class 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 | |
| 31 | class Intent: |
| 32 | def __init__( self, id ): |
| 33 | self.default = '' |
| 34 | self.type = 'INTENT' |
| 35 | self.id = id |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 36 | self.expectedState = 'UNKNOWN' |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 37 | |
| 38 | def isHostIntent( self ): |
| 39 | return self.type == 'INTENT_HOST' |
| 40 | |
| 41 | def isPointIntent( self ): |
| 42 | return self.type == 'INTENT_POINT' |
| 43 | |
You Wang | 2b687c0 | 2016-05-13 17:01:31 -0700 | [diff] [blame] | 44 | def isFailed( self ): |
| 45 | return self.expectedState == 'FAILED' |
| 46 | |
| 47 | def isInstalled( self ): |
| 48 | return self.expectedState == 'INSTALLED' |
| 49 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 50 | class 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 Wang | 2b687c0 | 2016-05-13 17:01:31 -0700 | [diff] [blame] | 56 | self.deviceA = hostA.device |
| 57 | self.deviceB = hostB.device |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 58 | |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 59 | def setWithdrawn( self ): |
| 60 | self.expectedState = 'WITHDRAWN' |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 61 | if self.hostB in self.hostA.correspondents: |
| 62 | self.hostA.correspondents.remove( self.hostB ) |
| 63 | if self.hostA in self.hostB.correspondents: |
| 64 | self.hostB.correspondents.remove( self.hostA ) |
| 65 | |
| 66 | def setFailed( self ): |
| 67 | self.expectedState = 'FAILED' |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 68 | |
| 69 | def setInstalled( self ): |
You Wang | c848af1 | 2016-07-14 09:53:58 -0700 | [diff] [blame] | 70 | if self.expectedState == 'UNKNOWN': |
| 71 | self.hostA.correspondents.append( self.hostB ) |
| 72 | self.hostB.correspondents.append( self.hostA ) |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 73 | self.expectedState = 'INSTALLED' |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 74 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 75 | def __str__( self ): |
| 76 | return "ID: " + self.id |
| 77 | |
| 78 | class PointIntent( Intent ): |
| 79 | def __init__( self, id, deviceA, deviceB ): |
| 80 | Intent.__init__( self, id ) |
| 81 | self.type = 'INTENT_POINT' |
| 82 | self.deviceA = deviceA |
| 83 | self.deviceB = deviceB |
| 84 | |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 85 | def setWithdrawn( self ): |
| 86 | self.expectedState = 'WITHDRAWN' |
| 87 | for hostA in self.deviceA.hosts: |
| 88 | for hostB in self.deviceB.hosts: |
| 89 | if hostB in hostA.correspondents: |
| 90 | hostA.correspondents.remove( hostB ) |
| 91 | |
| 92 | def setFailed( self ): |
| 93 | self.expectedState = 'FAILED' |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 94 | |
| 95 | def setInstalled( self ): |
You Wang | c848af1 | 2016-07-14 09:53:58 -0700 | [diff] [blame] | 96 | if self.expectedState == 'UNKNOWN': |
| 97 | for hostA in self.deviceA.hosts: |
| 98 | for hostB in self.deviceB.hosts: |
| 99 | hostA.correspondents.append( hostB ) |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 100 | self.expectedState = 'INSTALLED' |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 101 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 102 | def __str__( self ): |
| 103 | return "ID: " + self.id |