Topology.hh revision 9560:322472967603
172SN/A/*
21762SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
372SN/A * All rights reserved.
472SN/A *
572SN/A * Redistribution and use in source and binary forms, with or without
672SN/A * modification, are permitted provided that the following conditions are
772SN/A * met: redistributions of source code must retain the above copyright
872SN/A * notice, this list of conditions and the following disclaimer;
972SN/A * redistributions in binary form must reproduce the above copyright
1072SN/A * notice, this list of conditions and the following disclaimer in the
1172SN/A * documentation and/or other materials provided with the distribution;
1272SN/A * neither the name of the copyright holders nor the names of its
1372SN/A * contributors may be used to endorse or promote products derived from
1472SN/A * this software without specific prior written permission.
1572SN/A *
1672SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1772SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1872SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1972SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2072SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2172SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2272SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2372SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2472SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2572SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2672SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu */
282665Ssaidi@eecs.umich.edu
292665Ssaidi@eecs.umich.edu/*
3072SN/A * The topology here is configurable; it can be a hierachical (default
3112SN/A * one) or a 2D torus or a 2D torus with half switches killed. I think
3212SN/A * all input port has a one-input-one-output switch connected just to
3312SN/A * control and bandwidth, since we don't control bandwidth on input
3412SN/A * ports.  Basically, the class has a vector of nodes and edges. First
3512SN/A * 2*m_nodes elements in the node vector are input and output
3612SN/A * ports. Edges are represented in two vectors of src and dest
3712SN/A * nodes. All edges have latency.
3812SN/A */
39125SN/A
40125SN/A#ifndef __MEM_RUBY_NETWORK_SIMPLE_TOPOLOGY_HH__
41125SN/A#define __MEM_RUBY_NETWORK_SIMPLE_TOPOLOGY_HH__
42125SN/A
43125SN/A#include <iostream>
44125SN/A#include <string>
45125SN/A#include <vector>
46125SN/A
47125SN/A#include "mem/protocol/LinkDirection.hh"
48125SN/A#include "mem/ruby/common/TypeDefines.hh"
49125SN/A#include "mem/ruby/network/BasicRouter.hh"
50125SN/A#include "params/Topology.hh"
51125SN/A#include "sim/sim_object.hh"
52125SN/A
5312SN/Aclass NetDest;
5412SN/Aclass Network;
5512SN/A
5612SN/Atypedef std::vector<std::vector<int> > Matrix;
5712SN/A
5812SN/Astruct LinkEntry
5912SN/A{
6012SN/A    BasicLink *link;
6112SN/A    LinkDirection direction;
6212SN/A};
6312SN/A
6412SN/Atypedef std::map<std::pair<int, int>, LinkEntry> LinkMap;
6512SN/A
6612SN/Aclass Topology : public SimObject
6712SN/A{
6812SN/A  public:
6912SN/A    typedef TopologyParams Params;
7012SN/A    Topology(const Params *p);
71    virtual ~Topology() {}
72    const Params *params() const { return (const Params *)_params; }
73
74    void init();
75    int numSwitches() const { return m_number_of_switches; }
76    void createLinks(Network *net, bool isReconfiguration);
77
78    void initNetworkPtr(Network* net_ptr);
79
80    const std::string getName() { return m_name; }
81    void print(std::ostream& out) const { out << "[Topology]"; }
82
83  protected:
84    void addLink(SwitchID src, SwitchID dest, BasicLink* link,
85                 LinkDirection dir);
86    void makeLink(Network *net, SwitchID src, SwitchID dest,
87                  const NetDest& routing_table_entry,
88                  bool isReconfiguration);
89
90    std::string getDesignStr();
91    // Private copy constructor and assignment operator
92    Topology(const Topology& obj);
93    Topology& operator=(const Topology& obj);
94
95    std::string m_name;
96    NodeID m_nodes;
97    int m_number_of_switches;
98
99    std::vector<BasicExtLink*> m_ext_link_vector;
100    std::vector<BasicIntLink*> m_int_link_vector;
101
102    Matrix m_component_latencies;
103    Matrix m_component_inter_switches;
104
105    LinkMap m_link_map;
106    std::vector<BasicRouter*> m_router_vector;
107};
108
109inline std::ostream&
110operator<<(std::ostream& out, const Topology& obj)
111{
112    obj.print(out);
113    out << std::flush;
114    return out;
115}
116
117#endif // __MEM_RUBY_NETWORK_SIMPLE_TOPOLOGY_HH__
118