/protocols/ss7/m3ua/impl/src/test/java/org/mobicents/protocols/ss7/m3ua/impl/as/RemSgFSMTest.java

http://mobicents.googlecode.com/ · Java · 551 lines · 331 code · 104 blank · 116 comment · 16 complexity · ca83baf897aa35a6e0c1f432eb767078 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. package org.mobicents.protocols.ss7.m3ua.impl.as;
  23. import static org.junit.Assert.assertEquals;
  24. import static org.junit.Assert.assertNotNull;
  25. import static org.junit.Assert.assertNull;
  26. import static org.junit.Assert.assertTrue;
  27. import java.io.IOException;
  28. import org.junit.After;
  29. import org.junit.AfterClass;
  30. import org.junit.Before;
  31. import org.junit.BeforeClass;
  32. import org.junit.Test;
  33. import org.mobicents.protocols.ss7.m3ua.impl.As;
  34. import org.mobicents.protocols.ss7.m3ua.impl.AsState;
  35. import org.mobicents.protocols.ss7.m3ua.impl.Asp;
  36. import org.mobicents.protocols.ss7.m3ua.impl.AspFactory;
  37. import org.mobicents.protocols.ss7.m3ua.impl.AspState;
  38. import org.mobicents.protocols.ss7.m3ua.impl.CommunicationListener.CommunicationState;
  39. import org.mobicents.protocols.ss7.m3ua.impl.message.M3UAMessageImpl;
  40. import org.mobicents.protocols.ss7.m3ua.impl.message.MessageFactoryImpl;
  41. import org.mobicents.protocols.ss7.m3ua.impl.message.transfer.PayloadDataImpl;
  42. import org.mobicents.protocols.ss7.m3ua.impl.parameter.ParameterFactoryImpl;
  43. import org.mobicents.protocols.ss7.m3ua.impl.parameter.ProtocolDataImpl;
  44. import org.mobicents.protocols.ss7.m3ua.message.M3UAMessage;
  45. import org.mobicents.protocols.ss7.m3ua.message.MessageClass;
  46. import org.mobicents.protocols.ss7.m3ua.message.MessageType;
  47. import org.mobicents.protocols.ss7.m3ua.message.asptm.ASPActiveAck;
  48. import org.mobicents.protocols.ss7.m3ua.message.mgmt.Notify;
  49. import org.mobicents.protocols.ss7.m3ua.parameter.RoutingContext;
  50. import org.mobicents.protocols.ss7.m3ua.parameter.Status;
  51. import org.mobicents.protocols.ss7.m3ua.parameter.TrafficModeType;
  52. /**
  53. * Tests the FSM of client side AS and ASP's
  54. *
  55. * @author amit bhayani
  56. *
  57. */
  58. public class RemSgFSMTest {
  59. private ParameterFactoryImpl parmFactory = new ParameterFactoryImpl();
  60. private MessageFactoryImpl messageFactory = new MessageFactoryImpl();
  61. private ClientM3UAManagement clientM3UAMgmt = new ClientM3UAManagement();
  62. public RemSgFSMTest() {
  63. }
  64. @BeforeClass
  65. public static void setUpClass() throws Exception {
  66. }
  67. @AfterClass
  68. public static void tearDownClass() throws Exception {
  69. }
  70. @Before
  71. public void setUp() throws IOException {
  72. clientM3UAMgmt.start();
  73. }
  74. @After
  75. public void tearDown() throws IOException {
  76. clientM3UAMgmt.getAppServers().clear();
  77. clientM3UAMgmt.getAspfactories().clear();
  78. clientM3UAMgmt.getDpcVsAsName().clear();
  79. clientM3UAMgmt.stop();
  80. }
  81. @Test
  82. public void testSingleAspInAs() throws Exception {
  83. // 5.1.1. Single ASP in an Application Server ("1+0" sparing),
  84. RoutingContext rc = parmFactory.createRoutingContext(new long[] { 100 });
  85. // As as = rsgw.createAppServer("testas", rc, rKey, trModType);
  86. As as = clientM3UAMgmt.createAppServer("m3ua as create rc 100 testas".split(" "));
  87. // AspFactory localAspFactory = rsgw.createAspFactory("testasp",
  88. // "127.0.0.1", 2777, "127.0.0.1", 2778);
  89. AspFactory localAspFactory = clientM3UAMgmt
  90. .createAspFactory("m3ua asp create ip 127.0.0.1 port 2777 remip 127.0.0.1 remport 2778 testasp"
  91. .split(" "));
  92. localAspFactory.start();
  93. Asp asp = clientM3UAMgmt.assignAspToAs("testas", "testasp");
  94. // Check for Communication UP
  95. localAspFactory.onCommStateChange(CommunicationState.UP);
  96. // Once comunication is UP, ASP_UP should have been sent.
  97. assertEquals(AspState.UP_SENT, asp.getState());
  98. assertTrue(validateMessage(localAspFactory, MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_UP, -1, -1));
  99. // The other side will send ASP_UP_ACK and after that NTFY(AS-INACTIVE)
  100. M3UAMessageImpl message = messageFactory.createMessage(MessageClass.ASP_STATE_MAINTENANCE,
  101. MessageType.ASP_UP_ACK);
  102. localAspFactory.read(message);
  103. Notify notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
  104. notify.setRoutingContext(rc);
  105. Status status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_INACTIVE);
  106. notify.setStatus(status);
  107. localAspFactory.read(notify);
  108. assertEquals(AspState.ACTIVE_SENT, asp.getState());
  109. assertTrue(validateMessage(localAspFactory, MessageClass.ASP_TRAFFIC_MAINTENANCE, MessageType.ASP_ACTIVE, -1,
  110. -1));
  111. // also the AS should be INACTIVE now
  112. assertEquals(AsState.INACTIVE, as.getState());
  113. // The other side will send ASP_ACTIVE_ACK and after that
  114. // NTFY(AS-ACTIVE)
  115. ASPActiveAck aspActiveAck = (ASPActiveAck) messageFactory.createMessage(MessageClass.ASP_TRAFFIC_MAINTENANCE,
  116. MessageType.ASP_ACTIVE_ACK);
  117. aspActiveAck.setRoutingContext(rc);
  118. localAspFactory.read(aspActiveAck);
  119. notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
  120. notify.setRoutingContext(rc);
  121. status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_ACTIVE);
  122. notify.setStatus(status);
  123. localAspFactory.read(notify);
  124. assertEquals(AspState.ACTIVE, asp.getState());
  125. // also the AS should be ACTIVE now
  126. assertEquals(AsState.ACTIVE, as.getState());
  127. // Lets stop ASP Factory
  128. localAspFactory.stop();
  129. assertEquals(AspState.DOWN_SENT, asp.getState());
  130. assertTrue(validateMessage(localAspFactory, MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_DOWN, -1, -1));
  131. // also the AS is PENDING
  132. assertEquals(AsState.PENDING, as.getState());
  133. // Make sure we don't have any more
  134. assertNull(localAspFactory.txPoll());
  135. }
  136. @Test
  137. public void testSingleAspInMultipleAs() throws Exception {
  138. // 5.1.1.3. Single ASP in Multiple Application Servers (Each with "1+0"
  139. // Sparing)
  140. // Define 1st AS
  141. RoutingContext rc1 = parmFactory.createRoutingContext(new long[] { 100 });
  142. // As remAs1 = rsgw.createAppServer("testas1", rc1, rKey1, trModType1);
  143. As remAs1 = clientM3UAMgmt.createAppServer("m3ua as create rc 100 testas1".split(" "));
  144. // Define 2nd AS
  145. RoutingContext rc2 = parmFactory.createRoutingContext(new long[] { 200 });
  146. // As remAs2 = rsgw.createAppServer("testas2", rc2, rKey2, trModType2);
  147. As remAs2 = clientM3UAMgmt.createAppServer("m3ua as create rc 200 testas2".split(" "));
  148. // AspFactory aspFactory = rsgw.createAspFactory("testasp", "127.0.0.1",
  149. // 2777, "127.0.0.1", 2778);
  150. AspFactory aspFactory = clientM3UAMgmt
  151. .createAspFactory("m3ua asp create ip 127.0.0.1 port 3777 remip 127.0.0.1 remport 3112 testasp"
  152. .split(" "));
  153. aspFactory.start();
  154. // Both ASP uses same underlying M3UAChannel
  155. Asp remAsp1 = clientM3UAMgmt.assignAspToAs("testas1", "testasp");
  156. Asp remAsp2 = clientM3UAMgmt.assignAspToAs("testas2", "testasp");
  157. // Check for Communication UP
  158. aspFactory.onCommStateChange(CommunicationState.UP);
  159. assertEquals(AspState.UP_SENT, remAsp1.getState());
  160. assertEquals(AspState.UP_SENT, remAsp2.getState());
  161. // Once communication is UP, ASP_UP should have been sent.
  162. assertTrue(validateMessage(aspFactory, MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_UP, -1, -1));
  163. // Both the AS is still DOWN
  164. assertEquals(AsState.DOWN, remAs1.getState());
  165. assertEquals(AsState.DOWN, remAs2.getState());
  166. // The other side will send ASP_UP_ACK and after that NTFY(AS-INACTIVE)
  167. // for both the AS
  168. M3UAMessageImpl message = messageFactory.createMessage(MessageClass.ASP_STATE_MAINTENANCE,
  169. MessageType.ASP_UP_ACK);
  170. aspFactory.read(message);
  171. assertEquals(AspState.ACTIVE_SENT, remAsp1.getState());
  172. assertEquals(AspState.ACTIVE_SENT, remAsp2.getState());
  173. // ASP_ACTIVE for both ASP in txQueue
  174. assertTrue(validateMessage(aspFactory, MessageClass.ASP_TRAFFIC_MAINTENANCE, MessageType.ASP_ACTIVE, -1, -1));
  175. assertTrue(validateMessage(aspFactory, MessageClass.ASP_TRAFFIC_MAINTENANCE, MessageType.ASP_ACTIVE, -1, -1));
  176. Notify notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
  177. notify.setRoutingContext(rc1);
  178. Status status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_INACTIVE);
  179. notify.setStatus(status);
  180. aspFactory.read(notify);
  181. // the AS1 should be INACTIVE now but AS2 still DOWN
  182. assertEquals(AsState.INACTIVE, remAs1.getState());
  183. assertEquals(AsState.DOWN, remAs2.getState());
  184. notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
  185. notify.setRoutingContext(rc2);// RC 200
  186. status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_INACTIVE);
  187. notify.setStatus(status);
  188. aspFactory.read(notify);
  189. // AS2 should be INACTIVE now
  190. assertEquals(AsState.INACTIVE, remAs2.getState());
  191. // The other side will send ASP_ACTIVE_ACK and after that
  192. // NTFY(AS-ACTIVE)
  193. ASPActiveAck aspActiveAck = (ASPActiveAck) messageFactory.createMessage(MessageClass.ASP_TRAFFIC_MAINTENANCE,
  194. MessageType.ASP_ACTIVE_ACK);
  195. aspActiveAck.setRoutingContext(this.parmFactory.createRoutingContext(new long[] { 100, 200 }));
  196. aspFactory.read(aspActiveAck);
  197. // Both ASP are ACTIVE now
  198. assertEquals(AspState.ACTIVE, remAsp1.getState());
  199. assertEquals(AspState.ACTIVE, remAsp2.getState());
  200. notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
  201. notify.setRoutingContext(rc1);
  202. status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_ACTIVE);
  203. notify.setStatus(status);
  204. aspFactory.read(notify);
  205. // the AS1 should be ACTIVE now but AS2 still INACTIVE
  206. assertEquals(AsState.ACTIVE, remAs1.getState());
  207. assertEquals(AsState.INACTIVE, remAs2.getState());
  208. notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
  209. notify.setRoutingContext(rc2);
  210. status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_ACTIVE);
  211. notify.setStatus(status);
  212. aspFactory.read(notify);
  213. // the AS2 is also ACTIVE now
  214. assertEquals(AsState.ACTIVE, remAs1.getState());
  215. assertEquals(AsState.ACTIVE, remAs2.getState());
  216. // Lets stop ASP Factory
  217. aspFactory.stop();
  218. assertEquals(AspState.DOWN_SENT, remAsp1.getState());
  219. assertEquals(AspState.DOWN_SENT, remAsp2.getState());
  220. assertTrue(validateMessage(aspFactory, MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_DOWN, -1, -1));
  221. // also the both AS is PENDING
  222. assertEquals(AsState.PENDING, remAs1.getState());
  223. assertEquals(AsState.PENDING, remAs2.getState());
  224. // Make sure we don't have any more
  225. assertNull(aspFactory.txPoll());
  226. }
  227. @Test
  228. public void testTwoAspInAsOverride() throws Exception {
  229. // 5.1.2. Two ASPs in Application Server ("1+1" Sparing)
  230. RoutingContext rc = parmFactory.createRoutingContext(new long[] { 100 });
  231. TrafficModeType trModType = parmFactory.createTrafficModeType(TrafficModeType.Override);
  232. // As remAs = rsgw.createAppServer("testas", rc, rKey, trModType);
  233. As remAs = clientM3UAMgmt.createAppServer("m3ua as create rc 100 testas".split(" "));
  234. // AspFactory aspFactory1 = rsgw.createAspFactory("testasp1",
  235. // "127.0.0.1", 2777, "127.0.0.1", 2777);
  236. AspFactory aspFactory1 = clientM3UAMgmt
  237. .createAspFactory("m3ua asp create ip 127.0.0.1 port 3777 remip 127.0.0.1 remport 3112 testasp1"
  238. .split(" "));
  239. aspFactory1.start();
  240. // AspFactory aspFactory2 = rsgw.createAspFactory("testasp2",
  241. // "127.0.0.1", 2777, "127.0.0.1", 2778);
  242. AspFactory aspFactory2 = clientM3UAMgmt
  243. .createAspFactory("m3ua asp create ip 127.0.0.1 port 3778 remip 127.0.0.1 remport 3112 testasp2"
  244. .split(" "));
  245. aspFactory2.start();
  246. Asp remAsp1 = clientM3UAMgmt.assignAspToAs("testas", "testasp1");
  247. Asp remAsp2 = clientM3UAMgmt.assignAspToAs("testas", "testasp2");
  248. // Check for Communication UP for ASP1
  249. aspFactory1.onCommStateChange(CommunicationState.UP);
  250. assertEquals(AspState.UP_SENT, remAsp1.getState());
  251. // ASP_UP should have been sent.
  252. assertTrue(validateMessage(aspFactory1, MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_UP, -1, -1));
  253. // But AS is still Down
  254. assertEquals(AsState.DOWN, remAs.getState());
  255. // Far end send ASP_UP_ACK and NTFY
  256. M3UAMessageImpl message = messageFactory.createMessage(MessageClass.ASP_STATE_MAINTENANCE,
  257. MessageType.ASP_UP_ACK);
  258. aspFactory1.read(message);
  259. assertEquals(AspState.ACTIVE_SENT, remAsp1.getState());
  260. assertTrue(validateMessage(aspFactory1, MessageClass.ASP_TRAFFIC_MAINTENANCE, MessageType.ASP_ACTIVE, -1, -1));
  261. Notify notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
  262. notify.setRoutingContext(rc);
  263. Status status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_INACTIVE);
  264. notify.setStatus(status);
  265. aspFactory1.read(notify);
  266. // the AS1 should be INACTIVE
  267. assertEquals(AsState.INACTIVE, remAs.getState());
  268. // The other side will send ASP_ACTIVE_ACK and after that
  269. // NTFY(AS-ACTIVE)
  270. ASPActiveAck aspActiveAck = (ASPActiveAck) messageFactory.createMessage(MessageClass.ASP_TRAFFIC_MAINTENANCE,
  271. MessageType.ASP_ACTIVE_ACK);
  272. aspActiveAck.setRoutingContext(rc);
  273. aspActiveAck.setTrafficModeType(trModType);
  274. aspFactory1.read(aspActiveAck);
  275. assertEquals(AspState.ACTIVE, remAsp1.getState());
  276. notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
  277. notify.setRoutingContext(rc);
  278. status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_ACTIVE);
  279. notify.setStatus(status);
  280. aspFactory1.read(notify);
  281. aspFactory2.read(notify);
  282. assertEquals(AsState.ACTIVE, remAs.getState());
  283. // Communication UP for ASP2
  284. aspFactory2.onCommStateChange(CommunicationState.UP);
  285. assertEquals(AspState.UP_SENT, remAsp2.getState());
  286. // ASP_UP should have been sent.
  287. assertTrue(validateMessage(aspFactory2, MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_UP, -1, -1));
  288. // Far end send ASP_UP_ACK
  289. message = messageFactory.createMessage(MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_UP_ACK);
  290. aspFactory2.read(message);
  291. // ASP2 now is INACTIVE as ASP1 is still ACTIVATING
  292. assertEquals(AspState.INACTIVE, remAsp2.getState());
  293. // Bring down ASP1
  294. // 5.2.1. 1+1 Sparing, Withdrawal of ASP, Backup Override
  295. aspFactory1.onCommStateChange(CommunicationState.LOST);
  296. // the ASP is DOWN and AS goes in PENDING STATE
  297. assertEquals(AspState.DOWN, remAsp1.getState());
  298. assertEquals(AsState.PENDING, remAs.getState());
  299. // Aslo the ASP_ACTIVE for ASP2 should have been sent
  300. assertEquals(AspState.ACTIVE_SENT, remAsp2.getState());
  301. assertTrue(validateMessage(aspFactory2, MessageClass.ASP_TRAFFIC_MAINTENANCE, MessageType.ASP_ACTIVE, -1, -1));
  302. // We will not get Alternate ASP Active as this ASP's channel is dead
  303. // The other side will send ASP_ACTIVE_ACK and after that
  304. // NTFY(AS-ACTIVE)
  305. aspActiveAck = (ASPActiveAck) messageFactory.createMessage(MessageClass.ASP_TRAFFIC_MAINTENANCE,
  306. MessageType.ASP_ACTIVE_ACK);
  307. aspActiveAck.setRoutingContext(rc);
  308. aspFactory2.read(aspActiveAck);
  309. assertEquals(AspState.ACTIVE, remAsp2.getState());
  310. // We should get Notify that AS is ACTIVE
  311. notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
  312. notify.setRoutingContext(rc);
  313. status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_ACTIVE);
  314. notify.setStatus(status);
  315. aspFactory2.read(notify);
  316. assertEquals(AsState.ACTIVE, remAs.getState());
  317. assertNull(aspFactory1.txPoll());
  318. assertNull(aspFactory2.txPoll());
  319. }
  320. @Test
  321. public void testPendingQueue() throws Exception {
  322. RoutingContext rc = parmFactory.createRoutingContext(new long[] { 100 });
  323. // As as = rsgw.createAppServer("testas", rc, rKey, trModType);
  324. As as = clientM3UAMgmt.createAppServer("m3ua as create rc 100 testas".split(" "));
  325. // AspFactory localAspFactory = rsgw.createAspFactory("testasp",
  326. // "127.0.0.1", 2777, "127.0.0.1", 2778);
  327. AspFactory localAspFactory = clientM3UAMgmt
  328. .createAspFactory("m3ua asp create ip 127.0.0.1 port 2777 remip 127.0.0.1 remport 2778 testasp"
  329. .split(" "));
  330. localAspFactory.start();
  331. Asp asp = clientM3UAMgmt.assignAspToAs("testas", "testasp");
  332. // Check for Communication UP
  333. localAspFactory.onCommStateChange(CommunicationState.UP);
  334. // Once comunication is UP, ASP_UP should have been sent.
  335. assertEquals(AspState.UP_SENT, asp.getState());
  336. assertTrue(validateMessage(localAspFactory, MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_UP, -1, -1));
  337. // The other side will send ASP_UP_ACK and after that NTFY(AS-INACTIVE)
  338. M3UAMessageImpl message = messageFactory.createMessage(MessageClass.ASP_STATE_MAINTENANCE,
  339. MessageType.ASP_UP_ACK);
  340. localAspFactory.read(message);
  341. Notify notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
  342. notify.setRoutingContext(rc);
  343. Status status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_INACTIVE);
  344. notify.setStatus(status);
  345. localAspFactory.read(notify);
  346. assertEquals(AspState.ACTIVE_SENT, asp.getState());
  347. assertTrue(validateMessage(localAspFactory, MessageClass.ASP_TRAFFIC_MAINTENANCE, MessageType.ASP_ACTIVE, -1,
  348. -1));
  349. // also the AS should be INACTIVE now
  350. assertEquals(AsState.INACTIVE, as.getState());
  351. // The other side will send ASP_ACTIVE_ACK and after that
  352. // NTFY(AS-ACTIVE)
  353. ASPActiveAck aspActiveAck = (ASPActiveAck) messageFactory.createMessage(MessageClass.ASP_TRAFFIC_MAINTENANCE,
  354. MessageType.ASP_ACTIVE_ACK);
  355. aspActiveAck.setRoutingContext(rc);
  356. localAspFactory.read(aspActiveAck);
  357. notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
  358. notify.setRoutingContext(rc);
  359. status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_ACTIVE);
  360. notify.setStatus(status);
  361. localAspFactory.read(notify);
  362. assertEquals(AspState.ACTIVE, asp.getState());
  363. // also the AS should be ACTIVE now
  364. assertEquals(AsState.ACTIVE, as.getState());
  365. // Lets stop ASP Factory
  366. localAspFactory.stop();
  367. assertEquals(AspState.DOWN_SENT, asp.getState());
  368. assertTrue(validateMessage(localAspFactory, MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_DOWN, -1, -1));
  369. // also the AS is PENDING
  370. assertEquals(AsState.PENDING, as.getState());
  371. // The far end sends DOWN_ACK
  372. message = messageFactory.createMessage(MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_DOWN_ACK);
  373. localAspFactory.read(message);
  374. // start the ASP Factory again
  375. localAspFactory.start();
  376. // Now lets add some PayloadData
  377. PayloadDataImpl payload = (PayloadDataImpl) messageFactory.createMessage(MessageClass.TRANSFER_MESSAGES,
  378. MessageType.PAYLOAD);
  379. ProtocolDataImpl p1 = (ProtocolDataImpl) parmFactory.createProtocolData(1408, 123, 3, 1, 0, 1, new byte[] { 1,
  380. 2, 3, 4 });
  381. payload.setRoutingContext(rc);
  382. payload.setData(p1);
  383. as.write(payload);
  384. // Now again the ASP is brought up
  385. localAspFactory.onCommStateChange(CommunicationState.UP);
  386. // Once communication is UP, ASP_UP should have been sent.
  387. assertEquals(AspState.UP_SENT, asp.getState());
  388. assertTrue(validateMessage(localAspFactory, MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_UP, -1, -1));
  389. // The other side will send ASP_UP_ACK and after that NTFY(AS-INACTIVE)
  390. message = messageFactory.createMessage(MessageClass.ASP_STATE_MAINTENANCE, MessageType.ASP_UP_ACK);
  391. localAspFactory.read(message);
  392. notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
  393. notify.setRoutingContext(rc);
  394. status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_INACTIVE);
  395. notify.setStatus(status);
  396. localAspFactory.read(notify);
  397. assertEquals(AspState.ACTIVE_SENT, asp.getState());
  398. assertTrue(validateMessage(localAspFactory, MessageClass.ASP_TRAFFIC_MAINTENANCE, MessageType.ASP_ACTIVE, -1,
  399. -1));
  400. // AS should still be PENDING
  401. assertEquals(AsState.PENDING, as.getState());
  402. // The other side will send ASP_ACTIVE_ACK and after that
  403. // NTFY(AS-ACTIVE)
  404. aspActiveAck = (ASPActiveAck) messageFactory.createMessage(MessageClass.ASP_TRAFFIC_MAINTENANCE,
  405. MessageType.ASP_ACTIVE_ACK);
  406. aspActiveAck.setRoutingContext(rc);
  407. localAspFactory.read(aspActiveAck);
  408. notify = (Notify) messageFactory.createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
  409. notify.setRoutingContext(rc);
  410. status = parmFactory.createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_ACTIVE);
  411. notify.setStatus(status);
  412. localAspFactory.read(notify);
  413. assertEquals(AspState.ACTIVE, asp.getState());
  414. // also the AS should be ACTIVE now
  415. assertEquals(AsState.ACTIVE, as.getState());
  416. // Also we should have PayloadData
  417. M3UAMessage payLoadTemp = localAspFactory.txPoll();
  418. assertNotNull(payLoadTemp);
  419. assertEquals(MessageClass.TRANSFER_MESSAGES, payLoadTemp.getMessageClass());
  420. assertEquals(MessageType.PAYLOAD, payLoadTemp.getMessageType());
  421. // Make sure we don't have any more
  422. assertNull(localAspFactory.txPoll());
  423. }
  424. private boolean validateMessage(AspFactory factory, int msgClass, int msgType, int type, int info) {
  425. M3UAMessage message = factory.txPoll();
  426. if (message == null) {
  427. return false;
  428. }
  429. if (message.getMessageClass() != msgClass || message.getMessageType() != msgType) {
  430. return false;
  431. }
  432. if (message.getMessageClass() == MessageClass.MANAGEMENT) {
  433. if (message.getMessageType() == MessageType.NOTIFY) {
  434. Status s = ((Notify) message).getStatus();
  435. if (s.getType() != type || s.getInfo() != info) {
  436. return false;
  437. } else {
  438. return true;
  439. }
  440. }
  441. // TODO take care of Error?
  442. return true;
  443. } else {
  444. return true;
  445. }
  446. }
  447. }