blob: 4c60f4a05d770e9cf7c786d7c94fbad4e6a7761c [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"""
You Wangdb927a52016-02-26 11:03:28 -08005class NetworkElement:
Jon Hall2bb3e212017-05-24 17:07:25 -07006
You Wangdb927a52016-02-26 11:03:28 -08007 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
Jon Hall2bb3e212017-05-24 17:07:25 -070030
You Wangdb927a52016-02-26 11:03:28 -080031class Device( NetworkElement ):
Jon Hall2bb3e212017-05-24 17:07:25 -070032
You Wangdb927a52016-02-26 11:03:28 -080033 def __init__( self, index, name, dpid ):
34 NetworkElement.__init__( self, index )
35 self.name = name
36 self.dpid = dpid
37 self.hosts = []
38 # For each bidirectional link, we only store one direction here
39 self.outgoingLinks = []
40
41 def __str__( self ):
You Wang7a27f3a2016-07-05 10:12:27 -070042 return "name: " + self.name + ", dpid: " + self.dpid + ", status: " + self.status
You Wangdb927a52016-02-26 11:03:28 -080043
Jon Hall2bb3e212017-05-24 17:07:25 -070044
You Wangdb927a52016-02-26 11:03:28 -080045class Host( NetworkElement ):
Jon Hall2bb3e212017-05-24 17:07:25 -070046
You Wangdb927a52016-02-26 11:03:28 -080047 def __init__( self, index, name, id, mac, device, devicePort, vlan, ipAddresses ):
48 NetworkElement.__init__( self, index )
49 self.name = name
50 self.id = id
51 self.mac = mac
52 self.device = device
53 self.devicePort = devicePort
54 self.vlan = vlan
55 self.ipAddresses = ipAddresses
56 self.correspondents = []
57 self.handle = None
58
59 def __str__( self ):
You Wang7a27f3a2016-07-05 10:12:27 -070060 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 -080061
62 def setHandle( self, handle ):
63 self.handle = handle
64
Jon Hall2bb3e212017-05-24 17:07:25 -070065
You Wangdb927a52016-02-26 11:03:28 -080066class Link( NetworkElement ):
Jon Hall2bb3e212017-05-24 17:07:25 -070067
You Wangdb927a52016-02-26 11:03:28 -080068 """
69 Unidirectional link
70 """
71 def __init__( self, index, deviceA, portA, deviceB, portB ):
72 NetworkElement.__init__( self, index )
73 self.backwardLink = None
74 self.deviceA = deviceA
75 self.portA = portA
76 self.deviceB = deviceB
77 self.portB = portB
78
79 def __str__( self ):
You Wang7a27f3a2016-07-05 10:12:27 -070080 return self.deviceA.dpid + "/" + self.portA + " - " + self.deviceB.dpid + "/" + self.portB + ", status: " + self.status
You Wangdb927a52016-02-26 11:03:28 -080081
82 def setBackwardLink( self, link ):
83 self.backwardLink = link