Cluster.py (9148:a7a72f42919e) | Cluster.py (9862:54d6728d99cf) |
---|---|
1# Copyright (c) 2012 Advanced Micro Devices, Inc. 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright --- 59 unchanged lines hidden (view full) --- 68 self.intBW = intBW 69 self.extBW = extBW 70 self.intLatency = intLatency 71 self.extLatency = extLatency 72 73 def add(self, node): 74 self.nodes.append(node) 75 | 1# Copyright (c) 2012 Advanced Micro Devices, Inc. 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright --- 59 unchanged lines hidden (view full) --- 68 self.intBW = intBW 69 self.extBW = extBW 70 self.intLatency = intLatency 71 self.extLatency = extLatency 72 73 def add(self, node): 74 self.nodes.append(node) 75 |
76 def makeTopology(self, options, IntLink, ExtLink, Router): | 76 def makeTopology(self, options, network, IntLink, ExtLink, Router): |
77 """ Recursively make all of the links and routers 78 """ | 77 """ Recursively make all of the links and routers 78 """ |
79 routers = [] 80 int_links = [] 81 ext_links = [] | |
82 83 # make a router to connect all of the nodes 84 self.router = Router(router_id=self.num_routers()) | 79 80 # make a router to connect all of the nodes 81 self.router = Router(router_id=self.num_routers()) |
85 routers.append(self.router) | 82 network.routers.append(self.router) 83 |
86 for node in self.nodes: 87 if type(node) == Cluster: | 84 for node in self.nodes: 85 if type(node) == Cluster: |
88 subRouters, subIntLinks, subExtLinks = node.makeTopology(options, IntLink, ExtLink, Router) 89 routers += subRouters 90 int_links += subIntLinks 91 ext_links += subExtLinks | 86 node.makeTopology(options, network, IntLink, ExtLink, Router) |
92 93 # connect this cluster to the router 94 link = IntLink(link_id=self.num_int_links(), node_a=self.router, node_b=node.router) 95 if node.extBW: 96 link.bandwidth_factor = node.extBW 97 elif self.intBW: # if there is an interanl b/w for this node and no ext b/w to override 98 link.bandwidth_factor = self.intBW 99 100 if node.extLatency: 101 link.latency = node.extLatency 102 elif self.intLatency: 103 link.latency = self.intLatency 104 | 87 88 # connect this cluster to the router 89 link = IntLink(link_id=self.num_int_links(), node_a=self.router, node_b=node.router) 90 if node.extBW: 91 link.bandwidth_factor = node.extBW 92 elif self.intBW: # if there is an interanl b/w for this node and no ext b/w to override 93 link.bandwidth_factor = self.intBW 94 95 if node.extLatency: 96 link.latency = node.extLatency 97 elif self.intLatency: 98 link.latency = self.intLatency 99 |
105 int_links.append(link) | 100 network.int_links.append(link) |
106 else: 107 # node is just a controller connect it to the router via a ext_link 108 link = ExtLink(link_id=self.num_ext_links(), ext_node=node, int_node=self.router) 109 if self.intBW: 110 link.bandwidth_factor = self.intBW 111 if self.intLatency: 112 link.latency = self.intLatency 113 | 101 else: 102 # node is just a controller connect it to the router via a ext_link 103 link = ExtLink(link_id=self.num_ext_links(), ext_node=node, int_node=self.router) 104 if self.intBW: 105 link.bandwidth_factor = self.intBW 106 if self.intLatency: 107 link.latency = self.intLatency 108 |
114 ext_links.append(link) | 109 network.ext_links.append(link) |
115 | 110 |
116 return routers, int_links, ext_links 117 | |
118 def __len__(self): 119 return len([i for i in self.nodes if type(i) != Cluster]) + \ 120 sum([len(i) for i in self.nodes if type(i) == Cluster]) | 111 def __len__(self): 112 return len([i for i in self.nodes if type(i) != Cluster]) + \ 113 sum([len(i) for i in self.nodes if type(i) == Cluster]) |