forked from ThomasGaTech/NetworksProject2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessage.py
More file actions
35 lines (29 loc) · 1.57 KB
/
Message.py
File metadata and controls
35 lines (29 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Project 2 for OMS6250
#
# This defines a Message sent from one node to another using Spanning Tree Protocol.
# Students should not modify this file.
#
# Copyright 2016 Michael Brown
# Based on prior work by Sean Donovan, 2015
class Message(object):
def __init__(self, claimedRoot, distanceToRoot, origenID, destinationID, pathThrough):
# root = id of the switch thought to be the root by the origen switch
# distance = the distance from the origen to the root node
# origen = the ID of the origen switch
# destination = the ID of the destination switch
# pathThrough = Boolean value indicating the path to the claimed root from the origen passes through the destination
self.root = claimedRoot
self.distance = distanceToRoot
self.origen = origenID
self.destination = destinationID
self.pathThrough = pathThrough
# Member function that returns True if the message is properly formed, and False otherwise
def verify_message(self):
valid = True
if self.pathThrough != True and self.pathThrough != False:
valid = False
if isinstance(self.root, int) == False or isinstance(self.distance, int) == False or isinstance(self.origen, int) == False or isinstance(self.destination, int) == False :
valid = False
return valid
def to_string(self):
return '{root: ' + str(self.root) + ', distance: ' + str(self.distance) + ', origen: ' + str(self.origen) + ', destination: ' + str(self.destination) + ', pathThrough: ' + str(self.pathThrough) + '}'