Topology.cc (11320:42ecb523c64a) Topology.cc (11663:cf870cd20cfc)
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 41 unchanged lines hidden (view full) ---

50 const vector<BasicExtLink *> &ext_links,
51 const vector<BasicIntLink *> &int_links)
52 : m_nodes(ext_links.size()), m_number_of_switches(num_routers),
53 m_ext_link_vector(ext_links), m_int_link_vector(int_links)
54{
55 // Total nodes/controllers in network
56 assert(m_nodes > 1);
57
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 41 unchanged lines hidden (view full) ---

50 const vector<BasicExtLink *> &ext_links,
51 const vector<BasicIntLink *> &int_links)
52 : m_nodes(ext_links.size()), m_number_of_switches(num_routers),
53 m_ext_link_vector(ext_links), m_int_link_vector(int_links)
54{
55 // Total nodes/controllers in network
56 assert(m_nodes > 1);
57
58 // analyze both the internal and external links, create data structures
59 // Note that the python created links are bi-directional, but that the
60 // topology and networks utilize uni-directional links. Thus each
61 // BasicLink is converted to two calls to add link, on for each direction
58 // analyze both the internal and external links, create data structures.
59 // The python created external links are bi-directional,
60 // and the python created internal links are uni-directional.
61 // The networks and topology utilize uni-directional links.
62 // Thus each external link is converted to two calls to addLink,
63 // one for each direction.
64 //
65 // External Links
62 for (vector<BasicExtLink*>::const_iterator i = ext_links.begin();
63 i != ext_links.end(); ++i) {
64 BasicExtLink *ext_link = (*i);
65 AbstractController *abs_cntrl = ext_link->params()->ext_node;
66 BasicRouter *router = ext_link->params()->int_node;
67
68 int machine_base_idx = MachineType_base_number(abs_cntrl->getType());
69 int ext_idx1 = machine_base_idx + abs_cntrl->getVersion();
70 int ext_idx2 = ext_idx1 + m_nodes;
71 int int_idx = router->params()->router_id + 2*m_nodes;
72
73 // create the internal uni-directional links in both directions
66 for (vector<BasicExtLink*>::const_iterator i = ext_links.begin();
67 i != ext_links.end(); ++i) {
68 BasicExtLink *ext_link = (*i);
69 AbstractController *abs_cntrl = ext_link->params()->ext_node;
70 BasicRouter *router = ext_link->params()->int_node;
71
72 int machine_base_idx = MachineType_base_number(abs_cntrl->getType());
73 int ext_idx1 = machine_base_idx + abs_cntrl->getVersion();
74 int ext_idx2 = ext_idx1 + m_nodes;
75 int int_idx = router->params()->router_id + 2*m_nodes;
76
77 // create the internal uni-directional links in both directions
74 // the first direction is marked: In
75 addLink(ext_idx1, int_idx, ext_link, LinkDirection_In);
76 // the first direction is marked: Out
77 addLink(int_idx, ext_idx2, ext_link, LinkDirection_Out);
78 // ext to int
79 addLink(ext_idx1, int_idx, ext_link);
80 // int to ext
81 addLink(int_idx, ext_idx2, ext_link);
78 }
79
82 }
83
84 // Internal Links
80 for (vector<BasicIntLink*>::const_iterator i = int_links.begin();
81 i != int_links.end(); ++i) {
82 BasicIntLink *int_link = (*i);
85 for (vector<BasicIntLink*>::const_iterator i = int_links.begin();
86 i != int_links.end(); ++i) {
87 BasicIntLink *int_link = (*i);
83 BasicRouter *router_a = int_link->params()->node_a;
84 BasicRouter *router_b = int_link->params()->node_b;
88 BasicRouter *router_src = int_link->params()->src_node;
89 BasicRouter *router_dst = int_link->params()->dst_node;
85
86 // Store the IntLink pointers for later
87 m_int_link_vector.push_back(int_link);
88
90
91 // Store the IntLink pointers for later
92 m_int_link_vector.push_back(int_link);
93
89 int a = router_a->params()->router_id + 2*m_nodes;
90 int b = router_b->params()->router_id + 2*m_nodes;
94 int src = router_src->params()->router_id + 2*m_nodes;
95 int dst = router_dst->params()->router_id + 2*m_nodes;
91
96
92 // create the internal uni-directional links in both directions
93 // the first direction is marked: In
94 addLink(a, b, int_link, LinkDirection_In);
95 // the second direction is marked: Out
96 addLink(b, a, int_link, LinkDirection_Out);
97 // create the internal uni-directional link from src to dst
98 addLink(src, dst, int_link);
97 }
98}
99
100void
101Topology::createLinks(Network *net)
102{
103 // Find maximum switchID
104 SwitchID max_switch_id = 0;

--- 41 unchanged lines hidden (view full) ---

146 shortest_path_to_node(i, j, topology_weights, dist);
147 makeLink(net, i, j, destination_set);
148 }
149 }
150 }
151}
152
153void
99 }
100}
101
102void
103Topology::createLinks(Network *net)
104{
105 // Find maximum switchID
106 SwitchID max_switch_id = 0;

--- 41 unchanged lines hidden (view full) ---

148 shortest_path_to_node(i, j, topology_weights, dist);
149 makeLink(net, i, j, destination_set);
150 }
151 }
152 }
153}
154
155void
154Topology::addLink(SwitchID src, SwitchID dest, BasicLink* link,
155 LinkDirection dir)
156Topology::addLink(SwitchID src, SwitchID dest, BasicLink* link)
156{
157 assert(src <= m_number_of_switches+m_nodes+m_nodes);
158 assert(dest <= m_number_of_switches+m_nodes+m_nodes);
159
160 std::pair<int, int> src_dest_pair;
161 LinkEntry link_entry;
162
163 src_dest_pair.first = src;
164 src_dest_pair.second = dest;
157{
158 assert(src <= m_number_of_switches+m_nodes+m_nodes);
159 assert(dest <= m_number_of_switches+m_nodes+m_nodes);
160
161 std::pair<int, int> src_dest_pair;
162 LinkEntry link_entry;
163
164 src_dest_pair.first = src;
165 src_dest_pair.second = dest;
165 link_entry.direction = dir;
166 link_entry.link = link;
167 m_link_map[src_dest_pair] = link_entry;
168}
169
170void
171Topology::makeLink(Network *net, SwitchID src, SwitchID dest,
172 const NetDest& routing_table_entry)
173{
174 // Make sure we're not trying to connect two end-point nodes
175 // directly together
176 assert(src >= 2 * m_nodes || dest >= 2 * m_nodes);
177
178 std::pair<int, int> src_dest;
179 LinkEntry link_entry;
180
181 if (src < m_nodes) {
182 src_dest.first = src;
183 src_dest.second = dest;
184 link_entry = m_link_map[src_dest];
166 link_entry.link = link;
167 m_link_map[src_dest_pair] = link_entry;
168}
169
170void
171Topology::makeLink(Network *net, SwitchID src, SwitchID dest,
172 const NetDest& routing_table_entry)
173{
174 // Make sure we're not trying to connect two end-point nodes
175 // directly together
176 assert(src >= 2 * m_nodes || dest >= 2 * m_nodes);
177
178 std::pair<int, int> src_dest;
179 LinkEntry link_entry;
180
181 if (src < m_nodes) {
182 src_dest.first = src;
183 src_dest.second = dest;
184 link_entry = m_link_map[src_dest];
185 net->makeInLink(src, dest - (2 * m_nodes), link_entry.link,
186 link_entry.direction, routing_table_entry);
185 net->makeExtInLink(src, dest - (2 * m_nodes), link_entry.link,
186 routing_table_entry);
187 } else if (dest < 2*m_nodes) {
188 assert(dest >= m_nodes);
189 NodeID node = dest - m_nodes;
190 src_dest.first = src;
191 src_dest.second = dest;
192 link_entry = m_link_map[src_dest];
187 } else if (dest < 2*m_nodes) {
188 assert(dest >= m_nodes);
189 NodeID node = dest - m_nodes;
190 src_dest.first = src;
191 src_dest.second = dest;
192 link_entry = m_link_map[src_dest];
193 net->makeOutLink(src - (2 * m_nodes), node, link_entry.link,
194 link_entry.direction, routing_table_entry);
193 net->makeExtOutLink(src - (2 * m_nodes), node, link_entry.link,
194 routing_table_entry);
195 } else {
196 assert((src >= 2 * m_nodes) && (dest >= 2 * m_nodes));
197 src_dest.first = src;
198 src_dest.second = dest;
199 link_entry = m_link_map[src_dest];
200 net->makeInternalLink(src - (2 * m_nodes), dest - (2 * m_nodes),
195 } else {
196 assert((src >= 2 * m_nodes) && (dest >= 2 * m_nodes));
197 src_dest.first = src;
198 src_dest.second = dest;
199 link_entry = m_link_map[src_dest];
200 net->makeInternalLink(src - (2 * m_nodes), dest - (2 * m_nodes),
201 link_entry.link, link_entry.direction,
201 link_entry.link,
202 routing_table_entry);
203 }
204}
205
206// The following all-pairs shortest path algorithm is based on the
207// discussion from Cormen et al., Chapter 26.1.
208void
209Topology::extend_shortest_path(Matrix &current_dist, Matrix &latencies,

--- 89 unchanged lines hidden ---
202 routing_table_entry);
203 }
204}
205
206// The following all-pairs shortest path algorithm is based on the
207// discussion from Cormen et al., Chapter 26.1.
208void
209Topology::extend_shortest_path(Matrix &current_dist, Matrix &latencies,

--- 89 unchanged lines hidden ---