Revision: 14893
Author: oleg.kulikoff
Date: Tue Oct 26 06:17:56 2010
Log: Issue 1912: SCCP routing rule interface
http://code.google.com/p/mobicents/source/detail?r=14893
Added:
/trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/router/AddressInformation.java
/trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/router/MTPInfo.java
/trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/router/Route.java
/trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/router/RouterImpl.java
/trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/router/Rule.java
/trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/router/Translation.java
=======================================
--- /dev/null
+++
/trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/router/AddressInformation.java
Tue Oct 26 06:17:56 2010
@@ -0,0 +1,182 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and individual contributors as
indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a full listing
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License, v. 2.0.
+ * This program is distributed in the hope that it will be useful, but
WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License,
+ * v. 2.0 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+package org.mobicents.protocols.ss7.sccp.impl.router;
+
+import org.mobicents.protocols.ss7.indicator.NatureOfAddress;
+import org.mobicents.protocols.ss7.indicator.NumberingPlan;
+
+/**
+ * Defines information required for compare and constrcut SCCP address.
+ *
+ * @author kulikov
+ */
+public class AddressInformation {
+ private final static String SEPARATOR = "#";
+ private final static String NULL = " ";
+
+ /** translation type */
+ private int tt;
+ /** numbering plan */
+ private NumberingPlan np;
+ /** nature of address */
+ private NatureOfAddress noa;
+ /** digits */
+ private String digits;
+ /** subsytem number */
+ private int ssn;
+
+ /**
+ * Creates new address information object.
+ *
+ * @param tt translation type
+ * @param np numbering plan
+ * @param noa nature of address
+ * @param digits global title mask
+ * @param ssn subsytem number.
+ */
+ public AddressInformation(int tt, NumberingPlan np, NatureOfAddress
noa, String digits, int ssn) {
+ this.tt = tt;
+ this.np = np;
+ this.noa = noa;
+ this.digits = digits;
+ this.ssn = ssn;
+ }
+
+ public static AddressInformation getInstance(String s) {
+ int l = 0;
+ int r = s.indexOf('#', l + 1);
+
+ String token = s.substring(l, r);
+
+ //parse params
+ int tt = token.equals(NULL) ? -1 : Integer.parseInt(token);
+
+ l = r + 1;
+ r = s.indexOf('#', l);
+
+ token = s.substring(l, r);
+ NumberingPlan np = token.equals(NULL) ? null :
NumberingPlan.valueOf(token);
+
+ l = r + 1;
+ r = s.indexOf('#', l);
+
+ token = s.substring(l, r);
+ NatureOfAddress noa = token.equals(NULL) ? null :
NatureOfAddress.valueOf(token);
+
+ l = r + 1;
+ r = s.indexOf('#', l);
+
+ token = s.substring(l, r);
+ String digits = token.equals(NULL) ? null : token;
+
+ l = r + 1;
+ r = s.length();
+
+ token = s.substring(l, r);
+ int ssn = (token.length() == 0 || token.equals(NULL)) ? -1 :
Integer.parseInt(token);
+
+ return new AddressInformation(tt, np, noa, digits, ssn);
+ }
+
+ /**
+ * Gets the translation type.
+ *
+ * @return translation type indcator.
+ */
+ public int getTranslationType() {
+ return tt;
+ }
+
+ /**
+ * Gets the numbering plan indicator.
+ *
+ * @return numbering plan
+ */
+ public NumberingPlan getNumberingPlan() {
+ return np;
+ }
+
+ /**
+ * Gets the nature of address indicator.
+ *
+ * @return the nature of address
+ */
+ public NatureOfAddress getNatureOfAddress() {
+ return noa;
+ }
+
+ /**
+ * Global title mask
+ *
+ * @return the global title mask
+ */
+ public String getDigits() {
+ return digits;
+ }
+
+ /**
+ * Gets the subsystem number
+ *
+ * @return the subsystem number
+ */
+ public int getSubsystem() {
+ return ssn;
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer buff = new StringBuffer();
+ if (tt != -1) {
+ buff.append(tt);
+ } else {
+ buff.append(NULL);
+ }
+
+ buff.append(SEPARATOR);
+
+ if (np != null) {
+ buff.append(np.toString());
+ } else {
+ buff.append(NULL);
+ }
+ buff.append(SEPARATOR);
+
+ if (noa != null) {
+ buff.append(noa.toString());
+ } else {
+ buff.append(NULL);
+ }
+ buff.append(SEPARATOR);
+
+ if (digits != null) {
+ buff.append(digits);
+ } else {
+ buff.append(NULL);
+ }
+ buff.append(SEPARATOR);
+
+ if (ssn != -1) {
+ buff.append(ssn);
+ } else {
+ buff.append(NULL);
+ }
+
+ return buff.toString();
+ }
+}
=======================================
--- /dev/null
+++
/trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/router/MTPInfo.java
Tue Oct 26 06:17:56 2010
@@ -0,0 +1,145 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and individual contributors as
indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a full listing
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License, v. 2.0.
+ * This program is distributed in the hope that it will be useful, but
WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License,
+ * v. 2.0 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+package org.mobicents.protocols.ss7.sccp.impl.router;
+
+/**
+ * Carries the MTP information.
+ *
+ * @author kulikov
+ */
+public class MTPInfo {
+ private final static String SEPARATOR = "#";
+
+ /** The identifier of MTP-SAP */
+ private String name;
+ /** destination point code */
+ private int dpc;
+ /** originated point code */
+ private int opc;
+ /** signaling link selection */
+ private int sls;
+
+ /**
+ * Creates new MTPInfo object.
+ *
+ * @param name the name of MTP-SAP
+ * @param opc the originated point code
+ * @param dpc the destination point code
+ * @param sls the signaling link selection.
+ */
+ public MTPInfo(String name, int opc, int dpc, int sls) {
+ //name can not be null
+ if (name == null) {
+ throw new IllegalArgumentException("MTP-SAP can not be NULL");
+ }
+
+ //remove any extra white spaces
+ this.name = name.trim();
+
+ //name can not be empty string
+ if (this.name.length() == 0) {
+ throw new IllegalArgumentException("MTP-SAP name not
specified");
+ }
+
+ //check and assign originated point code
+ if (opc <= 0) {
+ throw new IllegalArgumentException("Originated point code less
of equal to zero");
+ }
+ this.opc = opc;
+
+ //check and assign destination point code
+ if (dpc <= 0) {
+ throw new IllegalArgumentException("Destination point code
less of equal to zero");
+ }
+ this.dpc = dpc;
+
+ //check and assign signaling link selection
+ if (sls < 0) {
+ throw new IllegalArgumentException("Signaling link code can
not be less then zero");
+ }
+ this.sls = sls;
+ }
+
+ /**
+ * Gets the name of the MTP-SAP
+ * @return
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Gets the originated point code used for routing
+ *
+ * @return point code in decimal format
+ */
+ public int getOpc() {
+ return opc;
+ }
+
+ /**
+ * Gets the destination point code which will be used for MTP_TRANSFER
+ *
+ * @return the point code in decimal format.
+ */
+ public int getDpc() {
+ return dpc;
+ }
+
+ /**
+ * Gets the signaling link selection.
+ *
+ * @return
+ */
+ public int getSls() {
+ return sls;
+ }
+
+ public static MTPInfo getInstance(String s) {
+ //use white space as separator
+ String[] tokens = s.split(SEPARATOR);
+
+ //we are expecting 4 params
+ if (tokens.length != 4) {
+ throw new IllegalArgumentException("Incorrect format: " + s);
+ }
+
+ //parse params
+ String name = tokens[0];
+ int opc = Integer.parseInt(tokens[1]);
+ int dpc = Integer.parseInt(tokens[2]);
+ int sls = Integer.parseInt(tokens[3]);
+
+ //generate new object
+ return new MTPInfo(name, opc, dpc, sls);
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer buff = new StringBuffer();
+ buff.append(name);
+ buff.append(SEPARATOR);
+ buff.append(opc);
+ buff.append(SEPARATOR);
+ buff.append(dpc);
+ buff.append(SEPARATOR);
+ buff.append(sls);
+ return buff.toString();
+ }
+}
=======================================
--- /dev/null
+++
/trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/router/Route.java
Tue Oct 26 06:17:56 2010
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and individual contributors as
indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a full listing
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License, v. 2.0.
+ * This program is distributed in the hope that it will be useful, but
WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License,
+ * v. 2.0 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+package org.mobicents.protocols.ss7.sccp.impl.router;
+
+import org.mobicents.protocols.ss7.sccp.parameter.SccpAddress;
+
+/**
+ * Presents the routing information.
+ *
+ * @author kulikov
+ */
+public class Route {
+ /** translated address */
+ protected SccpAddress address;
+ /** mtp routing info */
+ protected MTPInfo mtpInfo;
+
+ /**
+ * Gets the translated address.
+ *
+ * @return SCCP address.
+ */
+ public SccpAddress getAddress() {
+ return address;
+ }
+
+ /**
+ * MTP information.
+ *
+ * @return MTP info object.
+ */
+ public MTPInfo getMTPInfo() {
+ return mtpInfo;
+ }
+}
=======================================
--- /dev/null
+++
/trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/router/RouterImpl.java
Tue Oct 26 06:17:56 2010
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and individual contributors as
indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a full listing
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License, v. 2.0.
+ * This program is distributed in the hope that it will be useful, but
WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License,
+ * v. 2.0 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+package org.mobicents.protocols.ss7.sccp.impl.router;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import org.mobicents.protocols.ss7.sccp.parameter.SccpAddress;
+
+/**
+ * The default implementation for the SCCP router.
+ *
+ * The SCCP router allows to add/remove/list routing rules and implements
persistance for
+ * the routing rules.
+ *
+ * @author kulikov
+ */
+public class RouterImpl {
+ private final static String STORAGE = "/sccp-routing.cfg";
+ private Route route;
+
+ private File file;
+
+ //rule list
+ private ArrayList rules = new ArrayList();
+
+ /**
+ * Adds new rule for routing.
+ *
+ * @param rule the new rule to be added.
+ */
+ public void add(Rule rule) {
+ rule.no = rules.size();
+ rules.add(rule);
+ //TODO add persistance
+ }
+
+ /**
+ * Removes routing rule from router.
+ *
+ * @param rule
+ */
+ public void remove(int no) {
+ rules.remove(no);
+ //TODO add persistance
+ }
+
+ /**
+ * Gets the list of all rules.
+ *
+ * @return list of rules.
+ */
+ public Collection<Rule> list() {
+ return rules;
+ }
+
+ public Route route(SccpAddress calledPartyAddress) {
+ return route;
+ }
+
+ private void store(Rule rule) throws IOException {
+ BufferedWriter writer = new BufferedWriter(new FileWriter(file));
+ writer.write(rule.toString());
+ }
+}
=======================================
--- /dev/null
+++
/trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/router/Rule.java
Tue Oct 26 06:17:56 2010
@@ -0,0 +1,229 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and individual contributors as
indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a full listing
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License, v. 2.0.
+ * This program is distributed in the hope that it will be useful, but
WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License,
+ * v. 2.0 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.mobicents.protocols.ss7.sccp.impl.router;
+
+import org.mobicents.protocols.ss7.indicator.GlobalTitleIndicator;
+import org.mobicents.protocols.ss7.indicator.RoutingIndicator;
+import org.mobicents.protocols.ss7.sccp.parameter.GT0001;
+import org.mobicents.protocols.ss7.sccp.parameter.GT0010;
+import org.mobicents.protocols.ss7.sccp.parameter.GT0011;
+import org.mobicents.protocols.ss7.sccp.parameter.GT0100;
+import org.mobicents.protocols.ss7.sccp.parameter.SccpAddress;
+
+/**
+ *
+ * @author kulikov
+ */
+public class Rule {
+ private final static String SEPARATOR = ";";
+
+ /** the number of the rule */
+ protected int no;
+ /** Pattern used for selecting rule */
+ private AddressInformation pattern;
+ /** Translation method */
+ private AddressInformation translation;
+ /** Additional MTP info */
+ private MTPInfo mtpInfo;
+
+ /**
+ * Creeates new routing rule.
+ *
+ * @param the order number of the rule.
+ * @param pattern pattern for rule selection.
+ * @param translation translation method.
+ * @param mtpInfo MTP routing info
+ */
+ public Rule(AddressInformation pattern, AddressInformation
translation, MTPInfo mtpInfo) {
+ this.pattern = pattern;
+ this.translation = translation;
+ this.mtpInfo = mtpInfo;
+ }
+
+ protected Rule(int no, AddressInformation pattern, AddressInformation
translation, MTPInfo mtpInfo) {
+ this.no = no;
+ this.pattern = pattern;
+ this.translation = translation;
+ this.mtpInfo = mtpInfo;
+ }
+
+ public static Rule getInstance(String s) {
+ String[] tokens = s.trim().split(";");
+
+ int no = Integer.parseInt(tokens[0]);
+ String addressInfo = tokens[1];
+ String translation = tokens[2];
+ String mtpInfo = tokens[3];
+
+ return new Rule(no, AddressInformation.getInstance(addressInfo),
+ AddressInformation.getInstance(translation),
+ MTPInfo.getInstance(mtpInfo));
+ }
+
+ public int getNo() {
+ return no;
+ }
+ /**
+ * Gets the pattern for rule selection.
+ *
+ * @return address information object.
+ */
+ public AddressInformation getPattern() {
+ return pattern;
+ }
+
+ /**
+ * Get the translation rules.
+ *
+ * @return the address information object
+ */
+ public AddressInformation getTranslation() {
+ return translation;
+ }
+
+ /**
+ * Gets the MTP routing info.
+ *
+ * @return MTP info object.
+ */
+ public MTPInfo getMTPInfo() {
+ return mtpInfo;
+ }
+
+ public boolean matches(SccpAddress address) {
+ //consider routing based on global title only
+ if (address.getAddressIndicator().getRoutingIndicator() ==
RoutingIndicator.ROUTING_BASED_ON_DPC_AND_SSN) {
+ return false;
+ }
+
+ GlobalTitleIndicator gti =
address.getAddressIndicator().getGlobalTitleIndicator();
+ switch (gti) {
+ case GLOBAL_TITLE_INCLUDES_NATURE_OF_ADDRESS_INDICATOR_ONLY :
+ GT0001 gt = (GT0001) address.getGlobalTitle();
+ //translation type should not be specified
+ if (pattern.getTranslationType() != -1) {
+ return false;
+ }
+ //numbering plan should not be specified
+ if (pattern.getNumberingPlan() != null) {
+ return false;
+ }
+
+ //nature of address must match
+ if (pattern.getNatureOfAddress() != gt.getNoA()) {
+ return false;
+ }
+
+ //digits must match
+ if (!gt.getDigits().matches(pattern.getDigits())) {
+ return false;
+ }
+
+ //all conditions passed
+ return true;
+ case
GLOBAL_TITLE_INCLUDES_TRANSLATION_TYPE_NUMBERING_PLAN_AND_ENCODING_SCHEME :
+ GT0011 gt1 = (GT0011) address.getGlobalTitle();
+ //translation type should match
+ if (pattern.getTranslationType() !=
gt1.getTranslationType()) {
+ return false;
+ }
+
+ //numbering plan should match
+ if (pattern.getNumberingPlan() != gt1.getNp()) {
+ return false;
+ }
+
+ //nature must not be specified
+ if (pattern.getNatureOfAddress() != null) {
+ return false;
+ }
+
+ //digits must match
+ if (!gt1.getDigits().matches(pattern.getDigits())) {
+ return false;
+ }
+
+ //all conditions passed
+ return true;
+ case
GLOBAL_TITLE_INCLUDES_TRANSLATION_TYPE_NUMBERING_PLAN_ENCODING_SCHEME_AND_NATURE_OF_ADDRESS :
+ GT0100 gt2 = (GT0100) address.getGlobalTitle();
+ //translation type should match
+ if (pattern.getTranslationType() !=
gt2.getTranslationType()) {
+ return false;
+ }
+
+ //numbering plan should match
+ if (pattern.getNumberingPlan() != gt2.getNumberingPlan()) {
+ return false;
+ }
+
+ //nature of address must match
+ if (pattern.getNatureOfAddress() !=
gt2.getNatureOfAddress()) {
+ return false;
+ }
+
+ //digits must match
+ if (!gt2.getDigits().matches(pattern.getDigits())) {
+ return false;
+ }
+
+ //all conditions passed
+ return true;
+ case GLOBAL_TITLE_INCLUDES_TRANSLATION_TYPE_ONLY :
+ GT0010 gt3 = (GT0010) address.getGlobalTitle();
+ //translation type should match
+ if (pattern.getTranslationType() !=
gt3.getTranslationType()) {
+ return false;
+ }
+
+ //numbering plan not specified
+ if (pattern.getNumberingPlan() != null) {
+ return false;
+ }
+
+ //nature of address not specified
+ if (pattern.getNatureOfAddress() != null) {
+ return false;
+ }
+
+ //digits must match
+ if (!gt3.getDigits().matches(pattern.getDigits())) {
+ return false;
+ }
+
+ //all conditions passed
+ return true;
+ default :
+ return false;
+ }
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer buff = new StringBuffer();
+ buff.append(no);
+ buff.append(SEPARATOR);
+ buff.append(pattern.toString());
+ buff.append(SEPARATOR);
+ buff.append(translation.toString());
+ buff.append(SEPARATOR);
+ buff.append(mtpInfo.toString());
+ buff.append("\n");
+ return buff.toString();
+ }
+}
=======================================
--- /dev/null
+++
/trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/router/Translation.java
Tue Oct 26 06:17:56 2010
@@ -0,0 +1,27 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and individual contributors as
indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a full listing
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License, v. 2.0.
+ * This program is distributed in the hope that it will be useful, but
WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License,
+ * v. 2.0 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+package org.mobicents.protocols.ss7.sccp.impl.router;
+
+/**
+ *
+ * @author kulikov
+ */
+public class Translation {
+
+}