You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 1 | """ |
| 2 | This file contains device, host and link class for CHOTestMonkey |
| 3 | Author: you@onlab.us |
| 4 | """ |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 5 | class NetworkElement: |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 6 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 7 | def __init__( self, index ): |
| 8 | self.default = '' |
| 9 | self.index = index |
| 10 | self.status = 'up' |
| 11 | |
| 12 | def isUp( self ): |
| 13 | return self.status == 'up' |
| 14 | |
| 15 | def isDown( self ): |
| 16 | return self.status == 'down' |
| 17 | |
| 18 | def isRemoved( self ): |
| 19 | return self.status == 'removed' |
| 20 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 21 | def setRemoved( self ): |
| 22 | self.status = 'removed' |
| 23 | |
| 24 | def bringDown( self ): |
| 25 | self.status = 'down' |
| 26 | |
| 27 | def bringUp( self ): |
| 28 | self.status = 'up' |
| 29 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 30 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 31 | class Device( NetworkElement ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 32 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 33 | def __init__( self, index, name, dpid ): |
| 34 | NetworkElement.__init__( self, index ) |
| 35 | self.name = name |
| 36 | self.dpid = dpid |
| 37 | self.hosts = [] |
| 38 | # For each bidirectional link, we only store one direction here |
| 39 | self.outgoingLinks = [] |
| 40 | |
| 41 | def __str__( self ): |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 42 | return "name: " + self.name + ", dpid: " + self.dpid + ", status: " + self.status |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 43 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 44 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 45 | class Host( NetworkElement ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 46 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 47 | def __init__( self, index, name, id, mac, device, devicePort, vlan, ipAddresses ): |
| 48 | NetworkElement.__init__( self, index ) |
| 49 | self.name = name |
| 50 | self.id = id |
| 51 | self.mac = mac |
| 52 | self.device = device |
| 53 | self.devicePort = devicePort |
| 54 | self.vlan = vlan |
| 55 | self.ipAddresses = ipAddresses |
| 56 | self.correspondents = [] |
| 57 | self.handle = None |
| 58 | |
| 59 | def __str__( self ): |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 60 | 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] | 61 | |
| 62 | def setHandle( self, handle ): |
| 63 | self.handle = handle |
| 64 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 65 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 66 | class Link( NetworkElement ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame^] | 67 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 68 | """ |
| 69 | Unidirectional link |
| 70 | """ |
| 71 | def __init__( self, index, deviceA, portA, deviceB, portB ): |
| 72 | NetworkElement.__init__( self, index ) |
| 73 | self.backwardLink = None |
| 74 | self.deviceA = deviceA |
| 75 | self.portA = portA |
| 76 | self.deviceB = deviceB |
| 77 | self.portB = portB |
| 78 | |
| 79 | def __str__( self ): |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 80 | 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] | 81 | |
| 82 | def setBackwardLink( self, link ): |
| 83 | self.backwardLink = link |