blob: 31a408469b16556bd431b8535662a97cd211f540 [file] [log] [blame]
You Wangdb927a52016-02-26 11:03:28 -08001"""
2This file contains device, host and link class for CHOTestMonkey
3Author: you@onlab.us
4"""
5
6class 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
You Wangdb927a52016-02-26 11:03:28 -080021 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
30class Device( NetworkElement ):
31 def __init__( self, index, name, dpid ):
32 NetworkElement.__init__( self, index )
33 self.name = name
34 self.dpid = dpid
35 self.hosts = []
36 # For each bidirectional link, we only store one direction here
37 self.outgoingLinks = []
38
39 def __str__( self ):
You Wang7a27f3a2016-07-05 10:12:27 -070040 return "name: " + self.name + ", dpid: " + self.dpid + ", status: " + self.status
You Wangdb927a52016-02-26 11:03:28 -080041
42class Host( NetworkElement ):
43 def __init__( self, index, name, id, mac, device, devicePort, vlan, ipAddresses ):
44 NetworkElement.__init__( self, index )
45 self.name = name
46 self.id = id
47 self.mac = mac
48 self.device = device
49 self.devicePort = devicePort
50 self.vlan = vlan
51 self.ipAddresses = ipAddresses
52 self.correspondents = []
53 self.handle = None
54
55 def __str__( self ):
You Wang7a27f3a2016-07-05 10:12:27 -070056 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 -080057
58 def setHandle( self, handle ):
59 self.handle = handle
60
61class Link( NetworkElement ):
62 """
63 Unidirectional link
64 """
65 def __init__( self, index, deviceA, portA, deviceB, portB ):
66 NetworkElement.__init__( self, index )
67 self.backwardLink = None
68 self.deviceA = deviceA
69 self.portA = portA
70 self.deviceB = deviceB
71 self.portB = portB
72
73 def __str__( self ):
You Wang7a27f3a2016-07-05 10:12:27 -070074 return self.deviceA.dpid + "/" + self.portA + " - " + self.deviceB.dpid + "/" + self.portB + ", status: " + self.status
You Wangdb927a52016-02-26 11:03:28 -080075
76 def setBackwardLink( self, link ):
77 self.backwardLink = link