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' |
| 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 Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 81 | def __str__( self ): |
| 82 | return "ID: " + self.id |
| 83 | |
| 84 | class 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 Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame^] | 91 | 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 Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 111 | def __str__( self ): |
| 112 | return "ID: " + self.id |