blob: 50d6159702bfbccae511601c2bf2df8c7cd59f65 [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
57 self.hosts = []
58 # For each bidirectional link, we only store one direction here
59 self.outgoingLinks = []
60
61 def __str__( self ):
You Wang7a27f3a2016-07-05 10:12:27 -070062 return "name: " + self.name + ", dpid: " + self.dpid + ", status: " + self.status
You Wangdb927a52016-02-26 11:03:28 -080063
Jon Hall2bb3e212017-05-24 17:07:25 -070064
You Wangdb927a52016-02-26 11:03:28 -080065class Host( NetworkElement ):
Jon Hall2bb3e212017-05-24 17:07:25 -070066
You Wangdb927a52016-02-26 11:03:28 -080067 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 Wang7a27f3a2016-07-05 10:12:27 -070080 return "name: " + self.name + ", mac: " + self.mac + ", device: " + self.device.dpid + ", ipAddresses: " + str( self.ipAddresses ) + ", status: " + self.status
You Wangdb927a52016-02-26 11:03:28 -080081
82 def setHandle( self, handle ):
83 self.handle = handle
84
Jon Hall2bb3e212017-05-24 17:07:25 -070085
You Wangdb927a52016-02-26 11:03:28 -080086class Link( NetworkElement ):
Jon Hall2bb3e212017-05-24 17:07:25 -070087
You Wangdb927a52016-02-26 11:03:28 -080088 """
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 Wang7a27f3a2016-07-05 10:12:27 -0700100 return self.deviceA.dpid + "/" + self.portA + " - " + self.deviceB.dpid + "/" + self.portB + ", status: " + self.status
You Wangdb927a52016-02-26 11:03:28 -0800101
102 def setBackwardLink( self, link ):
103 self.backwardLink = link