blob: 97cc92cb3531bd0e633ec5f275ec992167d77975 [file] [log] [blame]
You Wangdb927a52016-02-26 11:03:28 -08001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2016 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or 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 Ronquillo23fb2162017-09-15 14:59:57 -070011 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070012
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 Ronquillob27ce4c2017-07-17 12:41:28 -070021"""
You Wangdb927a52016-02-26 11:03:28 -080022This file contains device, host and link class for CHOTestMonkey
23Author: you@onlab.us
24"""
You Wangdb927a52016-02-26 11:03:28 -080025class NetworkElement:
Jon Hall2bb3e212017-05-24 17:07:25 -070026
You Wangdb927a52016-02-26 11:03:28 -080027 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 Wangdb927a52016-02-26 11:03:28 -080041 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 Hall2bb3e212017-05-24 17:07:25 -070050
You Wangdb927a52016-02-26 11:03:28 -080051class Device( NetworkElement ):
Jon Hall2bb3e212017-05-24 17:07:25 -070052
You Wangdb927a52016-02-26 11:03:28 -080053 def __init__( self, index, name, dpid ):
54 NetworkElement.__init__( self, index )
55 self.name = name
56 self.dpid = dpid
You Wang7d14d642019-01-23 15:10:08 -080057 self.hosts = {}
58 self.downPorts = []
You Wangdb927a52016-02-26 11:03:28 -080059 # For each bidirectional link, we only store one direction here
60 self.outgoingLinks = []
61
62 def __str__( self ):
You Wang7a27f3a2016-07-05 10:12:27 -070063 return "name: " + self.name + ", dpid: " + self.dpid + ", status: " + self.status
You Wangdb927a52016-02-26 11:03:28 -080064
Jon Hall2bb3e212017-05-24 17:07:25 -070065
You Wangdb927a52016-02-26 11:03:28 -080066class Host( NetworkElement ):
Jon Hall2bb3e212017-05-24 17:07:25 -070067
You Wang7d14d642019-01-23 15:10:08 -080068 def __init__( self, index, name, id, mac, devices, vlan, ipAddresses ):
You Wangdb927a52016-02-26 11:03:28 -080069 NetworkElement.__init__( self, index )
70 self.name = name
71 self.id = id
72 self.mac = mac
You Wang7d14d642019-01-23 15:10:08 -080073 self.devices = devices
You Wangdb927a52016-02-26 11:03:28 -080074 self.vlan = vlan
75 self.ipAddresses = ipAddresses
76 self.correspondents = []
77 self.handle = None
You Wang7d14d642019-01-23 15:10:08 -080078 self.isDualHomed = True if len( self.devices ) == 2 else False
You Wangdb927a52016-02-26 11:03:28 -080079
80 def __str__( self ):
You Wang7d14d642019-01-23 15:10:08 -080081 return "name: " + self.name + ", mac: " + self.mac + ", devices: " + str( [ device.dpid for device in self.devices ] ) + ", ipAddresses: " + str( self.ipAddresses ) + ", status: " + self.status
You Wangdb927a52016-02-26 11:03:28 -080082
83 def setHandle( self, handle ):
84 self.handle = handle
85
You Wang7d14d642019-01-23 15:10:08 -080086 def setRemoved( self ):
87 if all( device.isRemoved() for device in self.devices ):
88 self.status = 'removed'
Jon Hall2bb3e212017-05-24 17:07:25 -070089
You Wangdb927a52016-02-26 11:03:28 -080090class Link( NetworkElement ):
Jon Hall2bb3e212017-05-24 17:07:25 -070091
You Wangdb927a52016-02-26 11:03:28 -080092 """
93 Unidirectional link
94 """
95 def __init__( self, index, deviceA, portA, deviceB, portB ):
96 NetworkElement.__init__( self, index )
97 self.backwardLink = None
98 self.deviceA = deviceA
99 self.portA = portA
100 self.deviceB = deviceB
101 self.portB = portB
102
103 def __str__( self ):
You Wang7a27f3a2016-07-05 10:12:27 -0700104 return self.deviceA.dpid + "/" + self.portA + " - " + self.deviceB.dpid + "/" + self.portB + ", status: " + self.status
You Wangdb927a52016-02-26 11:03:28 -0800105
106 def setBackwardLink( self, link ):
107 self.backwardLink = link