private void routeInput(InputPort inputPort) {
		Flit flit = inputPort.peekNextFlit();
		if(flit != null) {
			int inputVC = flit.getVC();
			int outputPort = -1;
			int outputVC = -1;
			
			// Work out the output port and vc number
			if(flit instanceof HeaderFlit) {

				int flitSrc = ((HeaderFlit)flit).getSrc();
				int flitDest = ((HeaderFlit)flit).getDest();
				int procId = m_outputPorts[m_procOutputPort].getDownStreamNodeId();
				
				// Select an output port and output virtual channel
				if(flitDest == procId) {
					outputPort = m_procOutputPort;
					outputVC = m_outputPorts[outputPort].allocVC();
				} else {
					outputPort = flitDest == procId ? m_procOutputPort : 
						m_routingFunction.getOutputPort(m_nodeId, inputVC, flitSrc, flitDest);
					int routedVC = m_routingFunction.getOutputVC(m_nodeId, inputVC, flitSrc, flitDest);
					outputVC = routedVC == -1 ? m_outputPorts[outputPort].allocVC() : 
						m_outputPorts[outputPort].allocVC(routedVC);
				}
				
				// If could not allocate VC then replace flit and wait, otherwise open a connection
				if(outputVC == -1) {
					inputPort.setWaitingVC(inputVC);
					console("could not allocate a VC for I["+inputPort.getPortNum()+":"+inputVC+"] on O["+outputPort+":?]");
					return;
				} else {
					inputPort.setupConnection(inputVC, outputPort, outputVC);
					m_outputPorts[outputPort].setupConnection(outputVC, inputPort.getPortNum(), inputVC);
					console(flit+" opening connection I["+inputPort.getPortNum()+":"+inputVC+"] to O["+outputPort+":"+outputVC+"] on dsn VC "+outputVC);
				}
				
			} else if(flit instanceof BodyFlit || flit instanceof TailFlit) {
				outputPort = inputPort.getOutputPort(flit.getVC());
				outputVC = inputPort.getOutputVC(flit.getVC());
			}

			// Only poll the input flit if the output is empty
			//m_outputPorts[outputPort].setCurrVC(outputVC);
			if(m_outputPorts[outputPort].isEmpty(outputVC)) {
				m_outputPorts[outputPort].addFlit(outputVC, inputPort.takeNextFlit());
				//console("Routing link "+linkInput.getPortNum()+" flit "+flit.toShortStr()+" to OP["+outputPort+":"+flit.getVC()+"]");
			}
		}
	}