PageRenderTime 39ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/jain-mgcp/stack/src/test/java/org/mobicents/protocols/mgcp/stack/test/createconnection/CA.java

http://mobicents.googlecode.com/
Java | 128 lines | 76 code | 30 blank | 22 comment | 5 complexity | 5aa24754ee62c2367fdec1b1575d5bca MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  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. package org.mobicents.protocols.mgcp.stack.test.createconnection;
  23. import jain.protocol.ip.mgcp.JainMgcpCommandEvent;
  24. import jain.protocol.ip.mgcp.JainMgcpEvent;
  25. import jain.protocol.ip.mgcp.JainMgcpResponseEvent;
  26. import jain.protocol.ip.mgcp.message.Constants;
  27. import jain.protocol.ip.mgcp.message.CreateConnection;
  28. import jain.protocol.ip.mgcp.message.CreateConnectionResponse;
  29. import jain.protocol.ip.mgcp.message.parms.CallIdentifier;
  30. import jain.protocol.ip.mgcp.message.parms.ConnectionDescriptor;
  31. import jain.protocol.ip.mgcp.message.parms.ConnectionMode;
  32. import jain.protocol.ip.mgcp.message.parms.EndpointIdentifier;
  33. import jain.protocol.ip.mgcp.message.parms.ReturnCode;
  34. import org.apache.log4j.Logger;
  35. import org.mobicents.protocols.mgcp.stack.JainMgcpExtendedListener;
  36. import org.mobicents.protocols.mgcp.stack.JainMgcpStackProviderImpl;
  37. public class CA implements JainMgcpExtendedListener {
  38. private static Logger logger = Logger.getLogger(CA.class);
  39. private JainMgcpStackProviderImpl caProvider;
  40. private int mgStack = 0;
  41. private boolean responseReceived = false;
  42. public CA(JainMgcpStackProviderImpl caProvider, JainMgcpStackProviderImpl mgwProvider) {
  43. this.caProvider = caProvider;
  44. mgStack = mgwProvider.getJainMgcpStack().getPort();
  45. }
  46. public void sendCreateConnection() {
  47. try {
  48. caProvider.addJainMgcpListener(this);
  49. CallIdentifier callID = caProvider.getUniqueCallIdentifier();
  50. EndpointIdentifier endpointID = new EndpointIdentifier("media/trunk/Announcement/$", "127.0.0.1:" + mgStack);
  51. CreateConnection createConnection = new CreateConnection(this, callID, endpointID, ConnectionMode.SendRecv);
  52. String sdpData = "v=0\r\n" + "o=4855 13760799956958020 13760799956958020" + " IN IP4 127.0.0.1\r\n"
  53. + "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"
  54. + "m=audio 6022 RTP/AVP 0 4 18\r\n" + "a=rtpmap:0 PCMU/8000\r\n" + "a=rtpmap:4 G723/8000\r\n"
  55. + "a=rtpmap:18 G729A/8000\r\n" + "a=ptime:20\r\n";
  56. createConnection.setRemoteConnectionDescriptor(new ConnectionDescriptor(sdpData));
  57. createConnection.setTransactionHandle(caProvider.getUniqueTransactionHandler());
  58. caProvider.sendMgcpEvents(new JainMgcpEvent[] { createConnection });
  59. logger.debug(" CreateConnection command sent for TxId " + createConnection.getTransactionHandle()
  60. + " and CallId " + callID);
  61. } catch (Exception e) {
  62. // TODO Auto-generated catch block
  63. e.printStackTrace();
  64. CreateConnectionTest.fail("Unexpected Exception");
  65. }
  66. }
  67. public void checkState() {
  68. CreateConnectionTest.assertTrue("Expect to receive CRCX Response", responseReceived);
  69. }
  70. public void transactionEnded(int handle) {
  71. logger.info("transactionEnded " + handle);
  72. }
  73. public void transactionRxTimedOut(JainMgcpCommandEvent command) {
  74. logger.info("transactionRxTimedOut " + command);
  75. }
  76. public void transactionTxTimedOut(JainMgcpCommandEvent command) {
  77. logger.info("transactionTxTimedOut " + command);
  78. }
  79. public void processMgcpCommandEvent(JainMgcpCommandEvent jainmgcpcommandevent) {
  80. logger.info("processMgcpCommandEvent " + jainmgcpcommandevent);
  81. }
  82. public void processMgcpResponseEvent(JainMgcpResponseEvent jainmgcpresponseevent) {
  83. logger.debug("processMgcpResponseEvent = " + jainmgcpresponseevent);
  84. switch (jainmgcpresponseevent.getObjectIdentifier()) {
  85. case Constants.RESP_CREATE_CONNECTION:
  86. CreateConnectionResponse response = (CreateConnectionResponse) jainmgcpresponseevent;
  87. if (response.getReturnCode().getValue() == ReturnCode.ENDPOINT_UNKNOWN
  88. || response.getReturnCode().getValue() == ReturnCode.TRANSACTION_EXECUTED_NORMALLY) {
  89. responseReceived = true;
  90. }
  91. break;
  92. default:
  93. logger.warn("This RESPONSE is unexpected " + jainmgcpresponseevent);
  94. CreateConnectionTest.fail("Incorrect response for CRCX command ");
  95. break;
  96. }
  97. }
  98. }