PageRenderTime 20610ms CodeModel.GetById 59ms RepoModel.GetById 6ms app.codeStats 0ms

/protocols/ss7/m3ua/impl/src/main/java/org/mobicents/protocols/ss7/m3ua/impl/router/ServerM3UARouter.java

http://mobicents.googlecode.com/
Java | 140 lines | 54 code | 14 blank | 72 comment | 16 complexity | 7b190e06b46487280e6de994a7f2462e 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.router;
  23. import javolution.util.FastList;
  24. import org.mobicents.protocols.ss7.m3ua.impl.As;
  25. import org.mobicents.protocols.ss7.m3ua.parameter.OPCList;
  26. import org.mobicents.protocols.ss7.m3ua.parameter.RoutingKey;
  27. import org.mobicents.protocols.ss7.m3ua.parameter.ServiceIndicators;
  28. /**
  29. * <p>
  30. * All the incoming MTP3 traffic is routed as per the rules defined in
  31. * M3UARouter. The routing decision is based on passed dpc, opc and si from the
  32. * MTP3 Signaling Information field (SIF) and Service Information Octet (SIO)
  33. * </p>
  34. * <p>
  35. * The {@link ServerM3UARouter} act as tree where each {@link DPCNode} act as parent
  36. * node containing {@link OPCNode} as leafs. Each {@link OPCNode} further
  37. * contains {@link SINode} as leafs. The {@link SINode} contains the reference
  38. * to corresponding {@link As}.
  39. * </p>
  40. *
  41. * @author amit bhayani
  42. *
  43. */
  44. public class ServerM3UARouter {
  45. private FastList<DPCNode> dpcList = new FastList<DPCNode>();
  46. public ServerM3UARouter() {
  47. }
  48. /**
  49. * <p>
  50. * Create a Tree structure adding the reference to passed As. The Tree is
  51. * created starting from {@link DPCNode} as parent node containing 'n'
  52. * {@link OPCNode} leafs where 'n' is list of OPC passed. For each
  53. * {@link OPCNode} there will be 'm' {@link SINode} leafs where 'm' is
  54. * number of Service Indicator passed.
  55. * </p>
  56. *
  57. * <p>
  58. * DPC is mandatory while OPC and SI list are optional. If OPC or SI is not
  59. * passed the wild card '-1' leaf will be added to parent node
  60. * </p>
  61. *
  62. * @param rk
  63. * @param as
  64. * @throws Exception
  65. */
  66. public void addRk(RoutingKey rk, As as) throws Exception {
  67. int dpc = rk.getDestinationPointCodes()[0].getPointCode();
  68. OPCList[] opcArray = rk.getOPCLists();
  69. int opcIntArr[] = null;
  70. if (opcArray == null) {
  71. opcIntArr = new int[] { -1 };
  72. } else {
  73. opcIntArr = opcArray[0].getPointCodes();
  74. }
  75. ServiceIndicators[] siArray = rk.getServiceIndicators();
  76. short[] siShortArr = null;
  77. if (siArray == null) {
  78. siShortArr = new short[] { -1 };
  79. } else {
  80. siShortArr = siArray[0].getIndicators();
  81. }
  82. for (FastList.Node<DPCNode> n = dpcList.head(), end = dpcList.tail(); (n = n.getNext()) != end;) {
  83. DPCNode dpcNode = n.getValue();
  84. if (dpcNode.dpc == dpc) {
  85. this.addSi(dpcNode, opcIntArr, siShortArr, as);
  86. return;
  87. }
  88. }
  89. DPCNode dpcNode = new DPCNode(dpc);
  90. this.addSi(dpcNode, opcIntArr, siShortArr, as);
  91. this.dpcList.add(dpcNode);
  92. }
  93. /**
  94. * <p>
  95. * Match the passed dpc, opc and si with Tree structure and return the As
  96. * from corresponding matched {@link SINode}.
  97. * </p>
  98. *
  99. * <p>
  100. * For example if AS1 is added for Routing Key with DPC=123 only. The tree
  101. * will be formed with 123 as {@link DPCNode} parent node and -1 as
  102. * {@link OPCNode} leaf and within {@link OPCNode} -1 as {@link SINode}
  103. * </p>
  104. *
  105. * @param dpc
  106. * @param opc
  107. * @param si
  108. * @return
  109. */
  110. public As getAs(int dpc, int opc, short si) {
  111. for (FastList.Node<DPCNode> n = dpcList.head(), end = dpcList.tail(); (n = n.getNext()) != end;) {
  112. DPCNode dpcNode = n.getValue();
  113. if (dpcNode.dpc == dpc) {
  114. return dpcNode.getAs(opc, si);
  115. }
  116. }
  117. return null;
  118. }
  119. private void addSi(DPCNode dpcNode, int[] opcIntArr, short[] siShortArr, As as) throws Exception {
  120. for (int i = 0; i < opcIntArr.length; i++) {
  121. for (int j = 0; j < siShortArr.length; j++) {
  122. dpcNode.addSi(opcIntArr[i], siShortArr[j], as);
  123. }
  124. }
  125. }
  126. }