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