PerfectSwitch.hh revision 6145
112837Sgabeblack@google.com 212837Sgabeblack@google.com/* 312837Sgabeblack@google.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 412837Sgabeblack@google.com * All rights reserved. 512837Sgabeblack@google.com * 612837Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 712837Sgabeblack@google.com * modification, are permitted provided that the following conditions are 812837Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 912837Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 1012837Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1112837Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1212837Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1312837Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1412837Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1512837Sgabeblack@google.com * this software without specific prior written permission. 1612837Sgabeblack@google.com * 1712837Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1812837Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1912837Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2012837Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2112837Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2212837Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2312837Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2412837Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2512837Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2612837Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2712837Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2812837Sgabeblack@google.com */ 2912837Sgabeblack@google.com 3012901Sgabeblack@google.com/* 3113135Sgabeblack@google.com * $Id$ 3212901Sgabeblack@google.com * 3312901Sgabeblack@google.com * Description: Perfect switch, of course it is perfect and no latency or what 3412837Sgabeblack@google.com * so ever. Every cycle it is woke up and perform all the 3512982Sgabeblack@google.com * necessary routings that must be done. Note, this switch also 3612951Sgabeblack@google.com * has number of input ports/output ports and has a routing table 3712953Sgabeblack@google.com * as well. 3813155Sgabeblack@google.com * 3912837Sgabeblack@google.com */ 4012951Sgabeblack@google.com 4113155Sgabeblack@google.com#ifndef PerfectSwitch_H 4213135Sgabeblack@google.com#define PerfectSwitch_H 4312837Sgabeblack@google.com 4412952Sgabeblack@google.com#include "Global.hh" 4512952Sgabeblack@google.com#include "Vector.hh" 4612952Sgabeblack@google.com#include "Consumer.hh" 4712952Sgabeblack@google.com#include "NodeID.hh" 4812952Sgabeblack@google.com 4912952Sgabeblack@google.comclass MessageBuffer; 5013135Sgabeblack@google.comclass NetDest; 5113135Sgabeblack@google.comclass SimpleNetwork; 5213135Sgabeblack@google.com 5313135Sgabeblack@google.comclass LinkOrder { 5413135Sgabeblack@google.compublic: 5513135Sgabeblack@google.com int m_link; 5613135Sgabeblack@google.com int m_value; 5713135Sgabeblack@google.com}; 5812993Sgabeblack@google.com 5912993Sgabeblack@google.comclass PerfectSwitch : public Consumer { 6012952Sgabeblack@google.compublic: 6112952Sgabeblack@google.com // Constructors 6212952Sgabeblack@google.com 6312952Sgabeblack@google.com // constructor specifying the number of ports 6412952Sgabeblack@google.com PerfectSwitch(SwitchID sid, SimpleNetwork* network_ptr); 6513135Sgabeblack@google.com void addInPort(const Vector<MessageBuffer*>& in); 6613135Sgabeblack@google.com void addOutPort(const Vector<MessageBuffer*>& out, const NetDest& routing_table_entry); 6713135Sgabeblack@google.com void clearRoutingTables(); 6813135Sgabeblack@google.com void clearBuffers(); 6913135Sgabeblack@google.com void reconfigureOutPort(const NetDest& routing_table_entry); 7013135Sgabeblack@google.com int getInLinks() const { return m_in.size(); } 7113135Sgabeblack@google.com int getOutLinks() const { return m_out.size(); } 7213135Sgabeblack@google.com 7312993Sgabeblack@google.com // Destructor 7412993Sgabeblack@google.com ~PerfectSwitch(); 7512952Sgabeblack@google.com 7612952Sgabeblack@google.com // Public Methods 7712952Sgabeblack@google.com void wakeup(); 7812952Sgabeblack@google.com 7912952Sgabeblack@google.com void printStats(ostream& out) const; 8013135Sgabeblack@google.com void clearStats(); 8113135Sgabeblack@google.com void printConfig(ostream& out) const; 8213135Sgabeblack@google.com 8313135Sgabeblack@google.com void print(ostream& out) const; 8413135Sgabeblack@google.comprivate: 8513135Sgabeblack@google.com 8613135Sgabeblack@google.com // Private copy constructor and assignment operator 8713135Sgabeblack@google.com PerfectSwitch(const PerfectSwitch& obj); 8812993Sgabeblack@google.com PerfectSwitch& operator=(const PerfectSwitch& obj); 8913060Sgabeblack@google.com 9012993Sgabeblack@google.com // Data Members (m_ prefix) 9112952Sgabeblack@google.com SwitchID m_switch_id; 9212952Sgabeblack@google.com 9313035Sgabeblack@google.com // vector of queues from the components 9413035Sgabeblack@google.com Vector<Vector<MessageBuffer*> > m_in; 9512952Sgabeblack@google.com Vector<Vector<MessageBuffer*> > m_out; 9612952Sgabeblack@google.com Vector<NetDest> m_routing_table; 9712837Sgabeblack@google.com Vector<LinkOrder> m_link_order; 9812837Sgabeblack@google.com int m_virtual_networks; 9912837Sgabeblack@google.com int m_round_robin_start; 10013091Sgabeblack@google.com int m_wakeups_wo_switch; 10112951Sgabeblack@google.com SimpleNetwork* m_network_ptr; 10212951Sgabeblack@google.com}; 10312837Sgabeblack@google.com 10413091Sgabeblack@google.com// Output operator declaration 10512951Sgabeblack@google.comostream& operator<<(ostream& out, const PerfectSwitch& obj); 10612951Sgabeblack@google.com 10712837Sgabeblack@google.com// ******************* Definitions ******************* 10813091Sgabeblack@google.com 10912837Sgabeblack@google.com// Output operator definition 11012982Sgabeblack@google.comextern inline 11112837Sgabeblack@google.comostream& operator<<(ostream& out, const PerfectSwitch& obj) 11213091Sgabeblack@google.com{ 11312837Sgabeblack@google.com obj.print(out); 11412837Sgabeblack@google.com out << flush; 11512837Sgabeblack@google.com return out; 11612837Sgabeblack@google.com} 11712837Sgabeblack@google.com 11812837Sgabeblack@google.com#endif //PerfectSwitch_H 11912837Sgabeblack@google.com