blob: b6e15207bf8ab1f8cb3aa10550ec1f8a578e6942 [file] [log] [blame]
You Wangdb927a52016-02-26 11:03:28 -08001"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07002Copyright 2016 Open Networking Foundation (ONF)
3
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
11 (at your option) any later version.
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"""
21
22"""
You Wangdb927a52016-02-26 11:03:28 -080023This file contains device, host and link class for CHOTestMonkey
24Author: you@onlab.us
25"""
You Wangdb927a52016-02-26 11:03:28 -080026class NetworkElement:
Jon Hall2bb3e212017-05-24 17:07:25 -070027
You Wangdb927a52016-02-26 11:03:28 -080028 def __init__( self, index ):
29 self.default = ''
30 self.index = index
31 self.status = 'up'
32
33 def isUp( self ):
34 return self.status == 'up'
35
36 def isDown( self ):
37 return self.status == 'down'
38
39 def isRemoved( self ):
40 return self.status == 'removed'
41
You Wangdb927a52016-02-26 11:03:28 -080042 def setRemoved( self ):
43 self.status = 'removed'
44
45 def bringDown( self ):
46 self.status = 'down'
47
48 def bringUp( self ):
49 self.status = 'up'
50
Jon Hall2bb3e212017-05-24 17:07:25 -070051
You Wangdb927a52016-02-26 11:03:28 -080052class Device( NetworkElement ):
Jon Hall2bb3e212017-05-24 17:07:25 -070053
You Wangdb927a52016-02-26 11:03:28 -080054 def __init__( self, index, name, dpid ):
55 NetworkElement.__init__( self, index )
56 self.name = name
57 self.dpid = dpid
58 self.hosts = []
59 # 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 Wangdb927a52016-02-26 11:03:28 -080068 def __init__( self, index, name, id, mac, device, devicePort, vlan, ipAddresses ):
69 NetworkElement.__init__( self, index )
70 self.name = name
71 self.id = id
72 self.mac = mac
73 self.device = device
74 self.devicePort = devicePort
75 self.vlan = vlan
76 self.ipAddresses = ipAddresses
77 self.correspondents = []
78 self.handle = None
79
80 def __str__( self ):
You Wang7a27f3a2016-07-05 10:12:27 -070081 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 -080082
83 def setHandle( self, handle ):
84 self.handle = handle
85
Jon Hall2bb3e212017-05-24 17:07:25 -070086
You Wangdb927a52016-02-26 11:03:28 -080087class Link( NetworkElement ):
Jon Hall2bb3e212017-05-24 17:07:25 -070088
You Wangdb927a52016-02-26 11:03:28 -080089 """
90 Unidirectional link
91 """
92 def __init__( self, index, deviceA, portA, deviceB, portB ):
93 NetworkElement.__init__( self, index )
94 self.backwardLink = None
95 self.deviceA = deviceA
96 self.portA = portA
97 self.deviceB = deviceB
98 self.portB = portB
99
100 def __str__( self ):
You Wang7a27f3a2016-07-05 10:12:27 -0700101 return self.deviceA.dpid + "/" + self.portA + " - " + self.deviceB.dpid + "/" + self.portB + ", status: " + self.status
You Wangdb927a52016-02-26 11:03:28 -0800102
103 def setBackwardLink( self, link ):
104 self.backwardLink = link