You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 1 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 2 | Copyright 2016 Open Networking Foundation ( ONF ) |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 7 | |
| 8 | TestON is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 2 of the License, or |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 11 | ( at your option ) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 12 | |
| 13 | TestON is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | """ |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 21 | """ |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 22 | This file contains device, host and link class for CHOTestMonkey |
| 23 | Author: you@onlab.us |
| 24 | """ |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 25 | class NetworkElement: |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 26 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 27 | def __init__( self, index ): |
| 28 | self.default = '' |
| 29 | self.index = index |
| 30 | self.status = 'up' |
| 31 | |
| 32 | def isUp( self ): |
| 33 | return self.status == 'up' |
| 34 | |
| 35 | def isDown( self ): |
| 36 | return self.status == 'down' |
| 37 | |
| 38 | def isRemoved( self ): |
| 39 | return self.status == 'removed' |
| 40 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 41 | def setRemoved( self ): |
| 42 | self.status = 'removed' |
| 43 | |
| 44 | def bringDown( self ): |
| 45 | self.status = 'down' |
| 46 | |
| 47 | def bringUp( self ): |
| 48 | self.status = 'up' |
| 49 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 50 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 51 | class Device( NetworkElement ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 52 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 53 | def __init__( self, index, name, dpid ): |
| 54 | NetworkElement.__init__( self, index ) |
| 55 | self.name = name |
| 56 | self.dpid = dpid |
| 57 | self.hosts = [] |
| 58 | # For each bidirectional link, we only store one direction here |
| 59 | self.outgoingLinks = [] |
| 60 | |
| 61 | def __str__( self ): |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 62 | return "name: " + self.name + ", dpid: " + self.dpid + ", status: " + self.status |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 63 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 64 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 65 | class Host( NetworkElement ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 66 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 67 | def __init__( self, index, name, id, mac, device, devicePort, vlan, ipAddresses ): |
| 68 | NetworkElement.__init__( self, index ) |
| 69 | self.name = name |
| 70 | self.id = id |
| 71 | self.mac = mac |
| 72 | self.device = device |
| 73 | self.devicePort = devicePort |
| 74 | self.vlan = vlan |
| 75 | self.ipAddresses = ipAddresses |
| 76 | self.correspondents = [] |
| 77 | self.handle = None |
| 78 | |
| 79 | def __str__( self ): |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 80 | return "name: " + self.name + ", mac: " + self.mac + ", device: " + self.device.dpid + ", ipAddresses: " + str( self.ipAddresses ) + ", status: " + self.status |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 81 | |
| 82 | def setHandle( self, handle ): |
| 83 | self.handle = handle |
| 84 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 85 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 86 | class Link( NetworkElement ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 87 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 88 | """ |
| 89 | Unidirectional link |
| 90 | """ |
| 91 | def __init__( self, index, deviceA, portA, deviceB, portB ): |
| 92 | NetworkElement.__init__( self, index ) |
| 93 | self.backwardLink = None |
| 94 | self.deviceA = deviceA |
| 95 | self.portA = portA |
| 96 | self.deviceB = deviceB |
| 97 | self.portB = portB |
| 98 | |
| 99 | def __str__( self ): |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 100 | return self.deviceA.dpid + "/" + self.portA + " - " + self.deviceB.dpid + "/" + self.portB + ", status: " + self.status |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 101 | |
| 102 | def setBackwardLink( self, link ): |
| 103 | self.backwardLink = link |