/protocols/jain-mgcp/stack/src/test/java/org/mobicents/protocols/mgcp/stack/test/createconnection/CA.java
Java | 128 lines | 76 code | 30 blank | 22 comment | 5 complexity | 5aa24754ee62c2367fdec1b1575d5bca MD5 | raw file
1/* 2 * JBoss, Home of Professional Open Source 3 * Copyright 2011, Red Hat, Inc. and individual contributors 4 * by the @authors tag. See the copyright.txt in the distribution for a 5 * full listing of individual contributors. 6 * 7 * This is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU Lesser General Public License as 9 * published by the Free Software Foundation; either version 2.1 of 10 * the License, or (at your option) any later version. 11 * 12 * This software is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this software; if not, write to the Free 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 21 */ 22 23package org.mobicents.protocols.mgcp.stack.test.createconnection; 24 25import jain.protocol.ip.mgcp.JainMgcpCommandEvent; 26import jain.protocol.ip.mgcp.JainMgcpEvent; 27import jain.protocol.ip.mgcp.JainMgcpResponseEvent; 28import jain.protocol.ip.mgcp.message.Constants; 29import jain.protocol.ip.mgcp.message.CreateConnection; 30import jain.protocol.ip.mgcp.message.CreateConnectionResponse; 31import jain.protocol.ip.mgcp.message.parms.CallIdentifier; 32import jain.protocol.ip.mgcp.message.parms.ConnectionDescriptor; 33import jain.protocol.ip.mgcp.message.parms.ConnectionMode; 34import jain.protocol.ip.mgcp.message.parms.EndpointIdentifier; 35import jain.protocol.ip.mgcp.message.parms.ReturnCode; 36 37import org.apache.log4j.Logger; 38import org.mobicents.protocols.mgcp.stack.JainMgcpExtendedListener; 39import org.mobicents.protocols.mgcp.stack.JainMgcpStackProviderImpl; 40 41public class CA implements JainMgcpExtendedListener { 42 43 private static Logger logger = Logger.getLogger(CA.class); 44 45 private JainMgcpStackProviderImpl caProvider; 46 private int mgStack = 0; 47 private boolean responseReceived = false; 48 49 public CA(JainMgcpStackProviderImpl caProvider, JainMgcpStackProviderImpl mgwProvider) { 50 this.caProvider = caProvider; 51 mgStack = mgwProvider.getJainMgcpStack().getPort(); 52 } 53 54 public void sendCreateConnection() { 55 56 try { 57 caProvider.addJainMgcpListener(this); 58 59 CallIdentifier callID = caProvider.getUniqueCallIdentifier(); 60 61 EndpointIdentifier endpointID = new EndpointIdentifier("media/trunk/Announcement/$", "127.0.0.1:" + mgStack); 62 63 CreateConnection createConnection = new CreateConnection(this, callID, endpointID, ConnectionMode.SendRecv); 64 65 String sdpData = "v=0\r\n" + "o=4855 13760799956958020 13760799956958020" + " IN IP4 127.0.0.1\r\n" 66 + "s=mysession session\r\n" + "p=+46 8 52018010\r\n" + "c=IN IP4 127.0.0.1\r\n" + "t=0 0\r\n" 67 + "m=audio 6022 RTP/AVP 0 4 18\r\n" + "a=rtpmap:0 PCMU/8000\r\n" + "a=rtpmap:4 G723/8000\r\n" 68 + "a=rtpmap:18 G729A/8000\r\n" + "a=ptime:20\r\n"; 69 70 createConnection.setRemoteConnectionDescriptor(new ConnectionDescriptor(sdpData)); 71 72 createConnection.setTransactionHandle(caProvider.getUniqueTransactionHandler()); 73 74 caProvider.sendMgcpEvents(new JainMgcpEvent[] { createConnection }); 75 76 logger.debug(" CreateConnection command sent for TxId " + createConnection.getTransactionHandle() 77 + " and CallId " + callID); 78 } catch (Exception e) { 79 // TODO Auto-generated catch block 80 e.printStackTrace(); 81 CreateConnectionTest.fail("Unexpected Exception"); 82 } 83 } 84 85 public void checkState() { 86 CreateConnectionTest.assertTrue("Expect to receive CRCX Response", responseReceived); 87 88 } 89 90 public void transactionEnded(int handle) { 91 logger.info("transactionEnded " + handle); 92 93 } 94 95 public void transactionRxTimedOut(JainMgcpCommandEvent command) { 96 logger.info("transactionRxTimedOut " + command); 97 98 } 99 100 public void transactionTxTimedOut(JainMgcpCommandEvent command) { 101 logger.info("transactionTxTimedOut " + command); 102 103 } 104 105 public void processMgcpCommandEvent(JainMgcpCommandEvent jainmgcpcommandevent) { 106 logger.info("processMgcpCommandEvent " + jainmgcpcommandevent); 107 } 108 109 public void processMgcpResponseEvent(JainMgcpResponseEvent jainmgcpresponseevent) { 110 logger.debug("processMgcpResponseEvent = " + jainmgcpresponseevent); 111 switch (jainmgcpresponseevent.getObjectIdentifier()) { 112 case Constants.RESP_CREATE_CONNECTION: 113 CreateConnectionResponse response = (CreateConnectionResponse) jainmgcpresponseevent; 114 if (response.getReturnCode().getValue() == ReturnCode.ENDPOINT_UNKNOWN 115 || response.getReturnCode().getValue() == ReturnCode.TRANSACTION_EXECUTED_NORMALLY) { 116 responseReceived = true; 117 } 118 break; 119 default: 120 logger.warn("This RESPONSE is unexpected " + jainmgcpresponseevent); 121 CreateConnectionTest.fail("Incorrect response for CRCX command "); 122 break; 123 124 } 125 126 } 127 128}