/** * This method sends an ATM cell containing 'setup' and an address to the router * * @param toAddress the address we want to connect to * @since 1.0 */ public void setupConnection(int toAddress) { // Create the ATM cell to send ATMCell conn = new ATMCell(0, "setup " + toAddress, this.getTraceID()); conn.setIsOAM(true); // Output to the console this.sentSetup(conn); // send the cell this.nic.sendCell(conn, this); }
/** * This method sends an ATM cell saying that we want to end the VC that we currently have open * Currently each computer can only have one VC, but the routers can have many VC open * * @since 1.0 */ public void endConnection() { if (this.vcNumber < 0) return; // Create the ATM cell to send ATMCell end = new ATMCell(this.vcNumber, "end " + this.vcNumber, this.getTraceID()); end.setIsOAM(true); // Output to the console this.sentEnd(end); this.vcNumber = -1; // Send the cell this.nic.sendCell(end, this); }
/** * Outputs to the console that a call proceeding message has been received * * @since 1.0 * @version 1.2 */ private void receivedCallProceeding(ATMCell cell) { System.out.println( "REC CALLPRO: Computer " + address + " received a call proceeding message " + cell.getTraceID()); }
/** * This method processes cells that are received from the nic * * @param cell the cell that was received * @param nic the nic the cell was received on * @since 1.0 */ public void receiveCell(ATMCell cell, ATMNIC nic) { if (cell.getIsOAM()) { String data = cell.getData(); if (data.startsWith("callpro")) { this.receivedCallProceeding(cell); } else if (data.startsWith("conn")) { this.receivedConnect(cell); int vcNum = this.getIntFromEndOfString(data); this.vcNumber = vcNum; System.out.println("The connection is setup on VC " + this.vcNumber); // send connect ack ATMCell callackCell = new ATMCell(0, "callack", this.getTraceID()); callackCell.setIsOAM(true); nic.sendCell(callackCell, this); this.sentConnectAck(callackCell); } else if (data.startsWith("endack")) { this.receivedEndAck(cell); } else if (data.startsWith("wait")) { this.receivedWait(cell); // send setup again int destAddr = this.getIntFromEndOfString(data); ATMCell setupCell = new ATMCell(0, "setup " + destAddr, this.getTraceID()); setupCell.setIsOAM(true); nic.sendCell(setupCell, this); this.sentSetup(setupCell); } } else { } }
/** * Outputs to the console that a connect ack message has been sent * * @since 1.2 */ private void sentConnectAck(ATMCell cell) { System.out.println( "SND CALLACK: Computer " + address + " sent a connect ack message " + cell.getTraceID()); }
/** * Outputs to the console that a wait message has been received * * @since 1.0 * @version 1.2 */ private void receivedWait(ATMCell cell) { System.out.println( "REC WAIT: Computer " + address + " received a wait message " + cell.getTraceID()); }
/** * Outputs to the console that an end message has been received * * @since 1.0 * @version 1.2 */ private void receivedEndAck(ATMCell cell) { System.out.println( "REC ENDACK: Computer " + address + " received an end ack message " + cell.getTraceID()); }
/** * Outputs to the console that an end message has been received * * @since 1.0 * @version 1.2 */ private void sentEnd(ATMCell cell) { System.out.println( "SND END: Computer " + address + " sent an end message " + cell.getTraceID()); }
/** * Outputs to the console that a connect message has been received * * @since 1.0 * @version 1.2 */ private void receivedConnect(ATMCell cell) { System.out.println( "REC CONN: Computer " + address + " received a connect message " + cell.getTraceID()); }
/** * Outputs to the console that a connect message has been sent * * @since 1.0 * @version 1.2 */ private void sentSetup(ATMCell cell) { System.out.println( "SND SETUP: Computer " + address + " sent a connect setup " + cell.getTraceID()); }