PageRenderTime 26ms CodeModel.GetById 2ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 1ms

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