PageRenderTime 37ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/protocols/ss7/m3ua/impl/src/test/java/org/mobicents/protocols/ss7/m3ua/impl/message/MessageFactoryTest.java

http://mobicents.googlecode.com/
Java | 279 lines | 191 code | 36 blank | 52 comment | 0 complexity | 94087a09e93588cec13445c41f1e5155 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.ss7.m3ua.impl.message;
  23. import static org.testng.Assert.assertEquals;
  24. import static org.testng.Assert.assertNotNull;
  25. import static org.testng.Assert.assertNull;
  26. import java.io.IOException;
  27. import org.mobicents.protocols.ss7.m3ua.message.MessageType;
  28. import org.mobicents.protocols.ss7.m3ua.message.transfer.PayloadData;
  29. import org.mobicents.protocols.ss7.m3ua.parameter.ProtocolData;
  30. import org.testng.annotations.AfterClass;
  31. import org.testng.annotations.AfterMethod;
  32. import org.testng.annotations.BeforeClass;
  33. import org.testng.annotations.BeforeMethod;
  34. import org.testng.annotations.Test;
  35. /**
  36. * @author amit bhayani
  37. *
  38. */
  39. public class MessageFactoryTest {
  40. private MessageFactoryImpl messageFactory = new MessageFactoryImpl();
  41. /**
  42. *
  43. */
  44. public MessageFactoryTest() {
  45. // TODO Auto-generated constructor stub
  46. }
  47. @BeforeClass
  48. public static void setUpClass() throws Exception {
  49. }
  50. @AfterClass
  51. public static void tearDownClass() throws Exception {
  52. }
  53. @BeforeMethod
  54. public void setUp() {
  55. }
  56. @AfterMethod
  57. public void tearDown() {
  58. }
  59. /**
  60. * This test is from Cisco ITP for SST with padding at last
  61. */
  62. @Test
  63. public void testSst() {
  64. byte[] data = new byte[] { 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x3c, 0x02, 0x00, 0x00, 0x08, 0x00, 0x00,
  65. 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x00, 0x00, 0x19, 0x02, 0x10, 0x00, 0x21, 0x00, 0x00, 0x17,
  66. (byte) 0x9d, 0x00, 0x00, 0x18, 0x1c, 0x03, 0x03, 0x00, 0x02, 0x09, 0x00, 0x03, 0x05, 0x07, 0x02, 0x42,
  67. 0x01, 0x02, 0x42, 0x01, 0x05, 0x03, (byte) 0xd5, 0x1c, 0x18, 0x00, 0x00, 0x00, 0x00 };
  68. // ByteBuffer byteBuffer = ByteBuffer.allocate(256);
  69. // byteBuffer.put(data);
  70. // byteBuffer.flip();
  71. // M3UAMessageImpl messageImpl = messageFactory.createMessage(byteBuffer);
  72. M3UAMessageImpl messageImpl = messageFactory.createSctpMessage(data);
  73. assertEquals(MessageType.PAYLOAD, messageImpl.getMessageType());
  74. PayloadData payloadData = (PayloadData) messageImpl;
  75. assertEquals(0l, payloadData.getNetworkAppearance().getNetApp());
  76. assertEquals(1, payloadData.getRoutingContext().getRoutingContexts().length);
  77. assertEquals(25l, payloadData.getRoutingContext().getRoutingContexts()[0]);
  78. ProtocolData protocolData = payloadData.getData();
  79. assertNotNull(protocolData);
  80. assertEquals(6045, protocolData.getOpc());
  81. assertEquals(6172, protocolData.getDpc());
  82. assertEquals(3, protocolData.getSI());
  83. assertEquals(2, protocolData.getSLS());
  84. assertEquals(3, protocolData.getNI());
  85. assertEquals(0, protocolData.getMP());
  86. // Test with sctp
  87. M3UAMessageImpl messageImpl1 = messageFactory.createSctpMessage(data);
  88. assertEquals(MessageType.PAYLOAD, messageImpl1.getMessageType());
  89. PayloadData payloadData1 = (PayloadData) messageImpl1;
  90. assertEquals(0l, payloadData1.getNetworkAppearance().getNetApp());
  91. assertEquals(1, payloadData1.getRoutingContext().getRoutingContexts().length);
  92. assertEquals(25l, payloadData1.getRoutingContext().getRoutingContexts()[0]);
  93. ProtocolData protocolData1 = payloadData1.getData();
  94. assertNotNull(protocolData1);
  95. assertEquals(6045, protocolData1.getOpc());
  96. assertEquals(6172, protocolData1.getDpc());
  97. assertEquals(3, protocolData1.getSI());
  98. assertEquals(2, protocolData1.getSLS());
  99. assertEquals(3, protocolData1.getNI());
  100. assertEquals(0, protocolData1.getMP());
  101. }
  102. @Test
  103. public void test2() {
  104. byte[] data = new byte[] { 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x00, 0x06, 0x00, 0x08, 0x00, 0x00,
  105. 0x00, 0x01, 0x02, 0x10, 0x00, (byte) 0xf8, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x03, 0x02,
  106. 0x00, 0x01, 0x09, 0x01, 0x03, 0x10, 0x1d, 0x0d, 0x53, 0x01, 0x00, (byte) 0x91, 0x00, 0x12, 0x04, 0x19,
  107. 0x09, 0x31, (byte) 0x91, 0x39, 0x08, 0x0d, 0x53, 0x02, 0x00, (byte) 0x92, 0x00, 0x12, 0x04, 0x19, 0x09,
  108. 0x31, (byte) 0x91, 0x39, 0x09, (byte) 0xc6, 0x62, (byte) 0x81, (byte) 0xc3, 0x48, 0x04, 0x00, 0x08,
  109. 0x00, 0x10, 0x6b, 0x1a, 0x28, 0x18, 0x06, 0x07, 0x00, 0x11, (byte) 0x86, 0x05, 0x01, 0x01, 0x01,
  110. (byte) 0xa0, 0x0d, 0x60, 0x0b, (byte) 0xa1, 0x09, 0x06, 0x07, 0x04, 0x00, 0x00, 0x01, 0x00, 0x32, 0x01,
  111. 0x6c, (byte) 0x81, (byte) 0x9e, (byte) 0xa1, (byte) 0x81, (byte) 0x9b, 0x02, 0x01, 0x01, 0x02, 0x01,
  112. 0x00, 0x30, (byte) 0x81, (byte) 0x92, (byte) 0x80, 0x01, 0x0c, (byte) 0x82, 0x09, 0x03, 0x10, 0x13,
  113. 0x60, (byte) 0x99, (byte) 0x86, 0x00, 0x00, 0x02, (byte) 0x83, 0x08, 0x04, 0x13, 0x19, (byte) 0x89,
  114. 0x17, (byte) 0x97, 0x31, 0x72, (byte) 0x85, 0x01, 0x0a, (byte) 0x88, 0x01, 0x01, (byte) 0x8a, 0x05,
  115. 0x04, 0x13, 0x19, (byte) 0x89, (byte) 0x86, (byte) 0xbb, 0x04, (byte) 0x80, 0x02, (byte) 0x80,
  116. (byte) 0x90, (byte) 0x9c, 0x01, 0x0c, (byte) 0x9f, 0x32, 0x08, 0x04, 0x64, 0x58, 0x05, (byte) 0x94,
  117. 0x74, 0x34, (byte) 0xf3, (byte) 0xbf, 0x33, 0x02, (byte) 0x80, 0x00, (byte) 0xbf, 0x34, 0x2b, 0x02,
  118. 0x01, 0x23, (byte) 0x80, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x81, 0x07,
  119. (byte) 0x91, 0x19, (byte) 0x89, (byte) 0x86, (byte) 0x91, 0x01, (byte) 0x82, (byte) 0x82, 0x08, 0x04,
  120. (byte) 0x97, 0x19, (byte) 0x89, (byte) 0x86, (byte) 0x91, 0x01, (byte) 0x82, (byte) 0xa3, 0x09,
  121. (byte) 0x80, 0x07, 0x04, (byte) 0xf4, (byte) 0x86, 0x00, 0x65, 0x18, (byte) 0xd1, (byte) 0xbf, 0x35,
  122. 0x03, (byte) 0x83, 0x01, 0x11, (byte) 0x9f, 0x36, 0x08, (byte) 0xd2, 0x25, 0x00, 0x00, 0x0d, 0x62,
  123. 0x0b, (byte) 0x88, (byte) 0x9f, 0x37, 0x07, (byte) 0x91, 0x19, (byte) 0x89, (byte) 0x86, (byte) 0x95,
  124. (byte) 0x99, (byte) 0x89, (byte) 0x9f, 0x39, 0x08, 0x02, 0x11, 0x20, 0x10, (byte) 0x91, 0x45, 0x51,
  125. 0x23 };
  126. //ByteBuffer byteBuffer = ByteBuffer.allocate(8192);
  127. //byteBuffer.put(data);
  128. //byteBuffer.flip();
  129. //M3UAMessageImpl messageImpl = messageFactory.createMessage(byteBuffer);
  130. M3UAMessageImpl messageImpl = messageFactory.createSctpMessage(data);
  131. assertEquals(MessageType.PAYLOAD, messageImpl.getMessageType());
  132. PayloadData payloadData = (PayloadData) messageImpl;
  133. assertNull(payloadData.getNetworkAppearance());
  134. assertEquals(1, payloadData.getRoutingContext().getRoutingContexts().length);
  135. assertEquals(1l, payloadData.getRoutingContext().getRoutingContexts()[0]);
  136. ProtocolData protocolData = payloadData.getData();
  137. assertNotNull(protocolData);
  138. assertEquals(2, protocolData.getOpc());
  139. assertEquals(1, protocolData.getDpc());
  140. assertEquals(3, protocolData.getSI());
  141. assertEquals(1, protocolData.getSLS());
  142. assertEquals(2, protocolData.getNI());
  143. assertEquals(0, protocolData.getMP());
  144. // Test with SCTP
  145. messageImpl = messageFactory.createSctpMessage(data);
  146. assertEquals(MessageType.PAYLOAD, messageImpl.getMessageType());
  147. payloadData = (PayloadData) messageImpl;
  148. assertNull(payloadData.getNetworkAppearance());
  149. assertEquals(1, payloadData.getRoutingContext().getRoutingContexts().length);
  150. assertEquals(1l, payloadData.getRoutingContext().getRoutingContexts()[0]);
  151. protocolData = payloadData.getData();
  152. assertNotNull(protocolData);
  153. assertEquals(2, protocolData.getOpc());
  154. assertEquals(1, protocolData.getDpc());
  155. assertEquals(3, protocolData.getSI());
  156. assertEquals(1, protocolData.getSLS());
  157. assertEquals(2, protocolData.getNI());
  158. assertEquals(0, protocolData.getMP());
  159. }
  160. @Test
  161. public void test3() {
  162. byte[] data = new byte[] { 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, (byte) 0xec, 0x00, 0x06, 0x00, 0x08, 0x00,
  163. 0x00, 0x00, 0x01, 0x02, 0x10, 0x00, (byte) 0xdc, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x03,
  164. 0x02, 0x00, 0x0f, 0x09, 0x01, 0x03, 0x10, 0x1d, 0x0d, 0x53, 0x01, 0x00, (byte) 0x91, 0x00, 0x12, 0x04,
  165. 0x19, 0x09, 0x31, (byte) 0x91, 0x39, 0x08, 0x0d, 0x53, 0x02, 0x00, (byte) 0x92, 0x00, 0x12, 0x04, 0x19,
  166. 0x09, 0x31, (byte) 0x91, 0x39, 0x09, (byte) 0xaa, 0x62, (byte) 0x81, (byte) 0xa7, 0x48, 0x04, 0x00,
  167. 0x07, (byte) 0xff, (byte) 0xf0, 0x6c, (byte) 0x81, (byte) 0x9e, (byte) 0xa1, (byte) 0x81, (byte) 0x9b,
  168. 0x02, 0x01, 0x01, 0x02, 0x01, 0x00, 0x30, (byte) 0x81, (byte) 0x92, (byte) 0x80, 0x01, 0x0c,
  169. (byte) 0x82, 0x09, 0x03, 0x10, 0x13, 0x60, (byte) 0x99, (byte) 0x86, 0x00, 0x00, 0x02, (byte) 0x83,
  170. 0x08, 0x04, 0x13, 0x19, (byte) 0x89, 0x17, (byte) 0x97, 0x31, 0x72, (byte) 0x85, 0x01, 0x0a,
  171. (byte) 0x88, 0x01, 0x01, (byte) 0x8a, 0x05, 0x04, 0x13, 0x19, (byte) 0x89, (byte) 0x86, (byte) 0xbb,
  172. 0x04, (byte) 0x80, 0x02, (byte) 0x80, (byte) 0x90, (byte) 0x9c, 0x01, 0x0c, (byte) 0x9f, 0x32, 0x08,
  173. 0x04, 0x64, 0x58, 0x05, (byte) 0x94, 0x74, 0x34, (byte) 0xf3, (byte) 0xbf, 0x33, 0x02, (byte) 0x80,
  174. 0x00, (byte) 0xbf, 0x34, 0x2b, 0x02, 0x01, 0x23, (byte) 0x80, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
  175. 0x00, 0x00, (byte) 0x81, 0x07, (byte) 0x91, 0x19, (byte) 0x89, (byte) 0x86, (byte) 0x91, 0x01,
  176. (byte) 0x82, (byte) 0x82, 0x08, 0x04, (byte) 0x97, 0x19, (byte) 0x89, (byte) 0x86, (byte) 0x91, 0x01,
  177. (byte) 0x82, (byte) 0xa3, 0x09, (byte) 0x80, 0x07, 0x04, (byte) 0xf4, (byte) 0x86, 0x00, 0x65, 0x18,
  178. (byte) 0xd1, (byte) 0xbf, 0x35, 0x03, (byte) 0x83, 0x01, 0x11, (byte) 0x9f, 0x36, 0x08, (byte) 0xd2,
  179. 0x25, 0x00, 0x00, 0x0d, 0x62, 0x0b, (byte) 0x88, (byte) 0x9f, 0x37, 0x07, (byte) 0x91, 0x19,
  180. (byte) 0x89, (byte) 0x86, (byte) 0x95, (byte) 0x99, (byte) 0x89, (byte) 0x9f, 0x39, 0x08, 0x02, 0x11,
  181. 0x20, 0x10, (byte) 0x91, 0x45, 0x51, 0x23 };
  182. // ByteBuffer byteBuffer = ByteBuffer.allocate(8192);
  183. // byteBuffer.put(data);
  184. // byteBuffer.flip();
  185. // M3UAMessageImpl messageImpl = messageFactory.createMessage(byteBuffer);
  186. M3UAMessageImpl messageImpl = messageFactory.createSctpMessage(data);
  187. assertEquals(MessageType.PAYLOAD, messageImpl.getMessageType());
  188. PayloadData payloadData = (PayloadData) messageImpl;
  189. assertNull(payloadData.getNetworkAppearance());
  190. assertEquals(1, payloadData.getRoutingContext().getRoutingContexts().length);
  191. assertEquals(1l, payloadData.getRoutingContext().getRoutingContexts()[0]);
  192. ProtocolData protocolData = payloadData.getData();
  193. assertNotNull(protocolData);
  194. assertEquals(2, protocolData.getOpc());
  195. assertEquals(1, protocolData.getDpc());
  196. assertEquals(3, protocolData.getSI());
  197. assertEquals(15, protocolData.getSLS());
  198. assertEquals(2, protocolData.getNI());
  199. assertEquals(0, protocolData.getMP());
  200. // Test with SCTP
  201. messageImpl = messageFactory.createSctpMessage(data);
  202. assertEquals(MessageType.PAYLOAD, messageImpl.getMessageType());
  203. payloadData = (PayloadData) messageImpl;
  204. assertNull(payloadData.getNetworkAppearance());
  205. assertEquals(1, payloadData.getRoutingContext().getRoutingContexts().length);
  206. assertEquals(1l, payloadData.getRoutingContext().getRoutingContexts()[0]);
  207. protocolData = payloadData.getData();
  208. assertNotNull(protocolData);
  209. assertEquals(2, protocolData.getOpc());
  210. assertEquals(1, protocolData.getDpc());
  211. assertEquals(3, protocolData.getSI());
  212. assertEquals(15, protocolData.getSLS());
  213. assertEquals(2, protocolData.getNI());
  214. assertEquals(0, protocolData.getMP());
  215. }
  216. // Test receiving for UnitDataService from live trace
  217. @Test
  218. public void testUnitDataService() throws IOException {
  219. byte[] data = new byte[] { 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, (byte) 0xB4, 0x02, 0x10, 0x00,
  220. (byte) 0xA9, 0x00, 0x00, 0x06, (byte) 0xBE, 0x00, 0x00, 0x06, (byte) 0xC5, 0x03, 0x02, 0x00, 0x02,
  221. 0x0A, 0x00, 0x03, 0x0D, 0x11, 0x0A, 0x52, (byte) 0x92, 0x00, 0x11, 0x04, (byte) 0x99, (byte) 0x99,
  222. (byte) 0x99, (byte) 0x99, 0x09, 0x04, 0x03, (byte) 0xBE, 0x06, (byte) 0x92, (byte) 0x83, 0x65,
  223. (byte) 0x81, (byte) 0x80, 0x48, 0x04, 0x00, 0x00, 0x00, 0x01, 0x49, 0x04, 0x00, 0x17, 0x3A, 0x26, 0x6B,
  224. 0x2A, 0x28, 0x28, 0x06, 0x07, 0x00, 0x11, (byte) 0x86, 0x05, 0x01, 0x01, 0x01, (byte) 0xA0, 0x1D, 0x61,
  225. 0x1B, (byte) 0x80, 0x02, 0x07, (byte) 0x80, (byte) 0xA1, 0x09, 0x06, 0x07, 0x04, 0x00, 0x00, 0x01,
  226. 0x00, 0x32, 0x01, (byte) 0xA2, 0x03, 0x02, 0x01, 0x00, (byte) 0xA3, 0x05, (byte) 0xA1, 0x03, 0x02,
  227. 0x01, 0x00, 0x6C, 0x46, (byte) 0xA1, 0x3C, 0x02, 0x01, 0x02, 0x02, 0x01, 0x17, 0x30, 0x34, (byte) 0xA0,
  228. 0x32, 0x30, 0x06, (byte) 0x80, 0x01, 0x0E, (byte) 0x81, 0x01, 0x01, 0x30, 0x06, (byte) 0x80, 0x01,
  229. 0x0D, (byte) 0x81, 0x01, 0x01, 0x30, 0x0B, (byte) 0x80, 0x01, 0x11, (byte) 0x81, 0x01, 0x01,
  230. (byte) 0xA2, 0x03, (byte) 0x80, 0x01, 0x01, 0x30, 0x0B, (byte) 0x80, 0x01, 0x11, (byte) 0x81, 0x01,
  231. 0x01, (byte) 0xA2, 0x03, (byte) 0x80, 0x01, 0x02, 0x30, 0x06, (byte) 0x80, 0x01, 0x12, (byte) 0x81,
  232. 0x01, 0x01, (byte) 0xA1, 0x06, 0x02, 0x01, 0x03, 0x02, 0x01, 0x1F, 0x00, 0x00, 0x00 };
  233. // ByteBuffer byteBuffer = ByteBuffer.allocate(8192);
  234. // byteBuffer.put(data);
  235. // byteBuffer.flip();
  236. // M3UAMessageImpl messageImpl = messageFactory.createMessage(byteBuffer);
  237. M3UAMessageImpl messageImpl = messageFactory.createSctpMessage(data);
  238. assertEquals(MessageType.PAYLOAD, messageImpl.getMessageType());
  239. PayloadData payloadData = (PayloadData) messageImpl;
  240. ProtocolData protocolData = payloadData.getData();
  241. assertNotNull(protocolData);
  242. }
  243. }