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 | """ |
| 5 | |
| 6 | class NetworkElement: |
| 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 | |
| 21 | def setPendingDown( self ): |
| 22 | self.status = 'pending_down' |
| 23 | |
| 24 | def setRemoved( self ): |
| 25 | self.status = 'removed' |
| 26 | |
| 27 | def bringDown( self ): |
| 28 | self.status = 'down' |
| 29 | |
| 30 | def bringUp( self ): |
| 31 | self.status = 'up' |
| 32 | |
| 33 | class Device( NetworkElement ): |
| 34 | def __init__( self, index, name, dpid ): |
| 35 | NetworkElement.__init__( self, index ) |
| 36 | self.name = name |
| 37 | self.dpid = dpid |
| 38 | self.hosts = [] |
| 39 | # For each bidirectional link, we only store one direction here |
| 40 | self.outgoingLinks = [] |
| 41 | |
| 42 | def __str__( self ): |
| 43 | return "name: " + self.name + ", dpid: " + self.dpid |
| 44 | |
| 45 | class Host( NetworkElement ): |
| 46 | def __init__( self, index, name, id, mac, device, devicePort, vlan, ipAddresses ): |
| 47 | NetworkElement.__init__( self, index ) |
| 48 | self.name = name |
| 49 | self.id = id |
| 50 | self.mac = mac |
| 51 | self.device = device |
| 52 | self.devicePort = devicePort |
| 53 | self.vlan = vlan |
| 54 | self.ipAddresses = ipAddresses |
| 55 | self.correspondents = [] |
| 56 | self.handle = None |
| 57 | |
| 58 | def __str__( self ): |
| 59 | return "name: " + self.name + ", mac: " + self.mac + ", device: " + self.device.dpid + ", ipAddresses: " + str( self.ipAddresses ) |
| 60 | |
| 61 | def setHandle( self, handle ): |
| 62 | self.handle = handle |
| 63 | |
| 64 | class Link( NetworkElement ): |
| 65 | """ |
| 66 | Unidirectional link |
| 67 | """ |
| 68 | def __init__( self, index, deviceA, portA, deviceB, portB ): |
| 69 | NetworkElement.__init__( self, index ) |
| 70 | self.backwardLink = None |
| 71 | self.deviceA = deviceA |
| 72 | self.portA = portA |
| 73 | self.deviceB = deviceB |
| 74 | self.portB = portB |
| 75 | |
| 76 | def __str__( self ): |
| 77 | return self.deviceA.dpid + "/" + self.portA + " - " + self.deviceB.dpid + "/" + self.portB |
| 78 | |
| 79 | def setBackwardLink( self, link ): |
| 80 | self.backwardLink = link |