Network.hh revision 9859:1bd310386038
16657Snate@binkert.org/*
26657Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
36657Snate@binkert.org * All rights reserved.
46657Snate@binkert.org *
56657Snate@binkert.org * Redistribution and use in source and binary forms, with or without
66657Snate@binkert.org * modification, are permitted provided that the following conditions are
76657Snate@binkert.org * met: redistributions of source code must retain the above copyright
86657Snate@binkert.org * notice, this list of conditions and the following disclaimer;
96657Snate@binkert.org * redistributions in binary form must reproduce the above copyright
106657Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
116657Snate@binkert.org * documentation and/or other materials provided with the distribution;
126657Snate@binkert.org * neither the name of the copyright holders nor the names of its
136657Snate@binkert.org * contributors may be used to endorse or promote products derived from
146657Snate@binkert.org * this software without specific prior written permission.
156657Snate@binkert.org *
166657Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176657Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186657Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196657Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206657Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216657Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226657Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236657Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246657Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256657Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266657Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276657Snate@binkert.org */
286657Snate@binkert.org
296657Snate@binkert.org/*
306657Snate@binkert.org * The Network class is the base class for classes that implement the
316657Snate@binkert.org * interconnection network between components (processor/cache
326657Snate@binkert.org * components and memory/directory components).  The interconnection
336657Snate@binkert.org * network as described here is not a physical network, but a
346657Snate@binkert.org * programming concept used to implement all communication between
356657Snate@binkert.org * components.  Thus parts of this 'network' will model the on-chip
366657Snate@binkert.org * connections between cache controllers and directory controllers as
376657Snate@binkert.org * well as the links between chip and network switches.
386657Snate@binkert.org */
396657Snate@binkert.org
406657Snate@binkert.org#ifndef __MEM_RUBY_NETWORK_NETWORK_HH__
416657Snate@binkert.org#define __MEM_RUBY_NETWORK_NETWORK_HH__
426657Snate@binkert.org
436657Snate@binkert.org#include <iostream>
446657Snate@binkert.org#include <string>
456657Snate@binkert.org#include <vector>
466657Snate@binkert.org
476657Snate@binkert.org#include "mem/protocol/LinkDirection.hh"
486657Snate@binkert.org#include "mem/protocol/MessageSizeType.hh"
496657Snate@binkert.org#include "mem/ruby/common/TypeDefines.hh"
506657Snate@binkert.org#include "mem/ruby/network/Topology.hh"
516657Snate@binkert.org#include "mem/packet.hh"
526657Snate@binkert.org#include "params/RubyNetwork.hh"
536657Snate@binkert.org#include "sim/clocked_object.hh"
546657Snate@binkert.org
556657Snate@binkert.orgclass NetDest;
566657Snate@binkert.orgclass MessageBuffer;
576657Snate@binkert.orgclass Throttle;
586657Snate@binkert.org
596657Snate@binkert.orgclass Network : public ClockedObject
606657Snate@binkert.org{
616657Snate@binkert.org  public:
626657Snate@binkert.org    typedef RubyNetworkParams Params;
636657Snate@binkert.org    Network(const Params *p);
646657Snate@binkert.org    virtual ~Network() {}
656657Snate@binkert.org    const Params * params() const
666657Snate@binkert.org    { return dynamic_cast<const Params *>(_params);}
676657Snate@binkert.org
686657Snate@binkert.org    virtual void init();
696657Snate@binkert.org
706657Snate@binkert.org    static uint32_t getNumberOfVirtualNetworks() { return m_virtual_networks; }
716657Snate@binkert.org    static uint32_t MessageSizeType_to_int(MessageSizeType size_type);
726657Snate@binkert.org
736657Snate@binkert.org    // returns the queue requested for the given component
74    virtual MessageBuffer* getToNetQueue(NodeID id, bool ordered,
75        int netNumber, std::string vnet_type) = 0;
76    virtual MessageBuffer* getFromNetQueue(NodeID id, bool ordered,
77        int netNumber, std::string vnet_type) = 0;
78    virtual const std::vector<Throttle*>* getThrottles(NodeID id) const;
79    virtual int getNumNodes() {return 1;}
80
81    virtual void makeOutLink(SwitchID src, NodeID dest, BasicLink* link,
82                             LinkDirection direction,
83                             const NetDest& routing_table_entry) = 0;
84    virtual void makeInLink(NodeID src, SwitchID dest, BasicLink* link,
85                            LinkDirection direction,
86                            const NetDest& routing_table_entry) = 0;
87    virtual void makeInternalLink(SwitchID src, SwitchID dest, BasicLink* link,
88                                  LinkDirection direction,
89                                  const NetDest& routing_table_entry) = 0;
90
91    virtual void printStats(std::ostream& out) const = 0;
92    virtual void clearStats() = 0;
93    virtual void print(std::ostream& out) const = 0;
94
95    /*
96     * Virtual functions for functionally reading and writing packets in
97     * the network. Each network needs to implement these for functional
98     * accesses to work correctly.
99     */
100    virtual bool functionalRead(Packet *pkt)
101    { fatal("Functional read not implemented.\n"); }
102    virtual uint32_t functionalWrite(Packet *pkt)
103    { fatal("Functional write not implemented.\n"); }
104
105  protected:
106    // Private copy constructor and assignment operator
107    Network(const Network& obj);
108    Network& operator=(const Network& obj);
109
110  protected:
111    const std::string m_name;
112    int m_nodes;
113    static uint32_t m_virtual_networks;
114    Topology* m_topology_ptr;
115    static uint32_t m_control_msg_size;
116    static uint32_t m_data_msg_size;
117};
118
119inline std::ostream&
120operator<<(std::ostream& out, const Network& obj)
121{
122    obj.print(out);
123    out << std::flush;
124    return out;
125}
126
127#endif // __MEM_RUBY_NETWORK_NETWORK_HH__
128