Revision: b3b9eac86c58
Author: [email protected] <[email protected]>
Date: Thu Aug 23 04:29:16 2012
Log: Issue 3:Allow mobicents SS7 stack to be configurable to use 5 or
8 bit
SLS
http://code.google.com/p/jss7/source/detail?r=b3b9eac86c58
Added:
/mtp/mtp-api/src/main/java/org/mobicents/protocols/ss7/mtp/PointCodeFormat.java
Modified:
/mtp/mtp-api/src/main/java/org/mobicents/protocols/ss7/mtp/Mtp3TransferPrimitive.java
/mtp/mtp-api/src/main/java/org/mobicents/protocols/ss7/mtp/Mtp3TransferPrimitiveFactory.java
/mtp/mtp-api/src/main/java/org/mobicents/protocols/ss7/mtp/Mtp3UserPart.java
/mtp/mtp-api/src/test/java/org/mobicents/protocols/ss7/mtp/Mtp3TransferMessageTest.java
/mtp/mtp-impl/src/main/java/org/mobicents/protocols/ss7/mtp/Mtp3UserPartBaseImpl.java
=======================================
--- /dev/null
+++
/mtp/mtp-api/src/main/java/org/mobicents/protocols/ss7/mtp/PointCodeFormat.java
Thu Aug 23 04:29:16 2012
@@ -0,0 +1,63 @@
+/*
+ * TeleStax, Open Source Cloud Communications Copyright 2012.
+ * and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.mobicents.protocols.ss7.mtp;
+
+/**
+ * @author amit bhayani
+ *
+ */
+public enum PointCodeFormat {
+ ANSI("ANSI"), ITU("ITU"), Japan_TTC_DDI("Japan_TTC_DDI"), China("China"),
Japan_NTT("Japan_NTT");
+
+ private final String format;
+
+ private static final String FORMAT_ITU = "ITU";
+ private static final String FORMAT_ANSI = "ANSI";
+ private static final String FORMAT_Japan_TTC_DDI = "Japan_TTC_DDI";
+ private static final String FROMAT_China = "China";
+ private static final String FORMAT_Japan_NTT = "Japan_NTT";
+
+ private PointCodeFormat(String format) {
+ this.format = format;
+ }
+
+ public String getFormat() {
+ return this.format;
+ }
+
+ public static PointCodeFormat getInstance(String format) {
+ if (FORMAT_ITU.equals(format)) {
+ return ITU;
+ } else if (FORMAT_ANSI.equals(format)) {
+ return ANSI;
+ } else if (FORMAT_Japan_TTC_DDI.equals(format)) {
+ return Japan_TTC_DDI;
+ } else if (FROMAT_China.equals(format)) {
+ return China;
+ } else if (FORMAT_Japan_NTT.equals(format)) {
+ return Japan_NTT;
+ }
+
+ return null;
+ }
+
+}
=======================================
---
/mtp/mtp-api/src/main/java/org/mobicents/protocols/ss7/mtp/Mtp3TransferPrimitive.java
Fri Aug 17 04:52:58 2012
+++
/mtp/mtp-api/src/main/java/org/mobicents/protocols/ss7/mtp/Mtp3TransferPrimitive.java
Thu Aug 23 04:29:16 2012
@@ -37,11 +37,10 @@
protected final int sls;
protected final byte[] data;
- private final int pcLength;
+ private final PointCodeFormat pointCodeFormat;
private final int slsLength;
- protected Mtp3TransferPrimitive(int si, int ni, int mp, int opc, int dpc,
int sls, byte[] data, int pcLength,
- int slsLength) {
+ protected Mtp3TransferPrimitive(int si, int ni, int mp, int opc, int dpc,
int sls, byte[] data, PointCodeFormat pointCodeFormat, int slsLength) {
this.si = si;
this.ni = ni;
this.mp = mp;
@@ -50,7 +49,7 @@
this.sls = sls;
this.data = data;
- this.pcLength = pcLength;
+ this.pointCodeFormat = pointCodeFormat;
this.slsLength = slsLength;
}
@@ -87,8 +86,8 @@
byte[] res = null;
int ssi = 0;
- switch (this.pcLength) {
- case Mtp3UserPart.PC_FORMAT_14:
+ switch (this.pointCodeFormat) {
+ case ITU:
res = new byte[this.data.length + 5];
@@ -106,10 +105,8 @@
System.arraycopy(this.data, 0, res, 5,
this.data.length);
break;
- case Mtp3UserPart.PC_FORMAT_16:
- // Not supported yet
- break;
- case Mtp3UserPart.PC_FORMAT_24:
+
+ case ANSI:
res = new byte[this.data.length + 8];
// sio
@@ -131,7 +128,7 @@
break;
default:
- // This should never happen
+ // We don't support rest
break;
}
=======================================
---
/mtp/mtp-api/src/main/java/org/mobicents/protocols/ss7/mtp/Mtp3TransferPrimitiveFactory.java
Fri Aug 17 10:51:26 2012
+++
/mtp/mtp-api/src/main/java/org/mobicents/protocols/ss7/mtp/Mtp3TransferPrimitiveFactory.java
Thu Aug 23 04:29:16 2012
@@ -28,19 +28,17 @@
*/
public class Mtp3TransferPrimitiveFactory {
- private final int pcLength;
+ private final PointCodeFormat pointCodeFormat;
private final int slsLength;
- public Mtp3TransferPrimitiveFactory(int pcLength, int slsLength) {
- this.pcLength = pcLength;
+ public Mtp3TransferPrimitiveFactory(PointCodeFormat pointCodeFormat, int
slsLength) {
+ this.pointCodeFormat = pointCodeFormat;
this.slsLength = slsLength;
}
- public Mtp3TransferPrimitive createMtp3TransferPrimitive(int si, int ni,
int mp, int opc, int dpc, int sls,
- byte[] data) {
- Mtp3TransferPrimitive mtp3TransferPrimitive = new
Mtp3TransferPrimitive(si, ni, mp, opc, dpc, sls, data,
- this.pcLength, this.slsLength);
+ public Mtp3TransferPrimitive createMtp3TransferPrimitive(int si, int ni,
int mp, int opc, int dpc, int sls, byte[] data) {
+ Mtp3TransferPrimitive mtp3TransferPrimitive = new
Mtp3TransferPrimitive(si, ni, mp, opc, dpc, sls, data,
this.pointCodeFormat, this.slsLength);
return mtp3TransferPrimitive;
}
@@ -59,8 +57,8 @@
int sls = 0;
byte[] data = null;
- switch (this.pcLength) {
- case Mtp3UserPart.PC_FORMAT_14:
+ switch (this.pointCodeFormat) {
+ case ITU:
// routing label
byte b1 = msg[1];
byte b2 = msg[2];
@@ -74,7 +72,7 @@
data = new byte[msg.length - 5];
System.arraycopy(msg, 5, data, 0, data.length);
break;
- case Mtp3UserPart.PC_FORMAT_24:
+ case ANSI:
dpc = ((msg[3] & 0xff) << 16) | ((msg[2] & 0xff) << 8) | (msg[1] &
0xff);
opc = ((msg[6] & 0xff) << 16) | ((msg[5] & 0xff) << 8) | (msg[4] &
0xff);
sls = (msg[7] & 0xff);
@@ -83,15 +81,12 @@
data = new byte[msg.length - 8];
System.arraycopy(msg, 8, data, 0, data.length);
break;
- case Mtp3UserPart.PC_FORMAT_16:
- // not implemented yet!
- break;
+
default:
- // Error condition. Should never happen
+ // TODO : We don't support rest justyet
break;
}
- mtp3TransferPrimitive = new Mtp3TransferPrimitive(si, ni, mp, opc, dpc,
sls, data, this.pcLength,
- this.slsLength);
+ mtp3TransferPrimitive = new Mtp3TransferPrimitive(si, ni, mp, opc, dpc,
sls, data, this.pointCodeFormat, this.slsLength);
return mtp3TransferPrimitive;
}
}
=======================================
---
/mtp/mtp-api/src/main/java/org/mobicents/protocols/ss7/mtp/Mtp3UserPart.java
Fri Aug 17 04:52:58 2012
+++
/mtp/mtp-api/src/main/java/org/mobicents/protocols/ss7/mtp/Mtp3UserPart.java
Thu Aug 23 04:29:16 2012
@@ -31,52 +31,37 @@
*/
public interface Mtp3UserPart {
- /**
- * Point Code format for ITU-T 14 bits
- */
- public static final int PC_FORMAT_14 = 14;
-
- /**
- * Point Code format for ITU-T 16 bits
- */
- public static final int PC_FORMAT_16 = 16;
-
- /**
- * Point Code format for ITU-T or ANSI 24 bits
- */
- public static final int PC_FORMAT_24 = 24;
-
public void addMtp3UserPartListener(Mtp3UserPartListener listener);
public void removeMtp3UserPartListener(Mtp3UserPartListener listener);
/**
- * Length of Point Code in number of bits
+ * return PointCodeFormat
*
* @return
*/
- public int getPointCodeLength();
+ public PointCodeFormat getPointCodeFormat();
/**
- * Set length of Point Code in number of bits
+ * Set PointCodeFormat
*
* @param length
*/
- public void setPointCodeLength(int length);
+ public void setPointCodeFormat(PointCodeFormat pointCodeFormat);
/**
* Length of SLS in number of bits
*
* @return
*/
- public int getSLSLength();
+ public int getSlsLength();
/**
* Set length of SLS in number of bits
*
* @param slsLength
*/
- public void setSLSLength(int slsLength);
+ public void setSlsLength(int slsLength);
/**
* Get the Mtp3TransferPrimitiveFactory
=======================================
---
/mtp/mtp-api/src/test/java/org/mobicents/protocols/ss7/mtp/Mtp3TransferMessageTest.java
Fri Aug 17 04:52:58 2012
+++
/mtp/mtp-api/src/test/java/org/mobicents/protocols/ss7/mtp/Mtp3TransferMessageTest.java
Thu Aug 23 04:29:16 2012
@@ -53,7 +53,7 @@
@Test(groups = { "Mtp3TransferMessageTest", "decode" })
public void testDecode() throws Exception {
- Mtp3TransferPrimitiveFactory factory = new
Mtp3TransferPrimitiveFactory(Mtp3UserPart.PC_FORMAT_14, 4);
+ Mtp3TransferPrimitiveFactory factory = new
Mtp3TransferPrimitiveFactory(PointCodeFormat.ITU, 4);
Mtp3TransferPrimitive msg =
factory.createMtp3TransferPrimitive(getMsg());
assertEquals(msg.getSi(), 3);
@@ -68,7 +68,7 @@
@Test(groups = { "Mtp3TransferMessageTest", "encode" })
public void testEncode() throws Exception {
- Mtp3TransferPrimitiveFactory factory = new
Mtp3TransferPrimitiveFactory(Mtp3UserPart.PC_FORMAT_14, 4);
+ Mtp3TransferPrimitiveFactory factory = new
Mtp3TransferPrimitiveFactory(PointCodeFormat.ITU, 4);
Mtp3TransferPrimitive msg = factory.createMtp3TransferPrimitive(3, 2, 0,
2000, 1000, 10, this.getData());
byte[] res = msg.encodeMtp3();
=======================================
---
/mtp/mtp-impl/src/main/java/org/mobicents/protocols/ss7/mtp/Mtp3UserPartBaseImpl.java
Fri Aug 17 04:52:58 2012
+++
/mtp/mtp-impl/src/main/java/org/mobicents/protocols/ss7/mtp/Mtp3UserPartBaseImpl.java
Thu Aug 23 04:29:16 2012
@@ -55,7 +55,8 @@
private ExecutorService msgDeliveryExecutorSystem;
private int slsTable[] = new int[maxSls];
- private int pcLength = PC_FORMAT_14;
+ private PointCodeFormat pointCodeFormat = PointCodeFormat.ITU;
+
private int slsLength = 5;
private Mtp3TransferPrimitiveFactory mtp3TransferPrimitiveFactory =
null;
@@ -88,35 +89,35 @@
*/
@Override
public int getMaxUserDataLength(int dpc) {
- if (this.pcLength == PC_FORMAT_14) {
+ switch (this.pointCodeFormat) {
+ case ITU:
// For PC_FORMAT_14, the MTP3 Routing Label takes 4
bytes - OPC/DPC
// = 16 bits each and SLS = 4 bits
return 272 - 4;
- } else if (this.pcLength == PC_FORMAT_24) {
+ case ANSI:
// For PC_FORMAT_24, the MTP3 Routing Label takes 6
bytes - OPC/DPC
// = 24 bits each and SLS = 8 bits
return 272 - 7;
- } else if (this.pcLength == PC_FORMAT_16) {
- // TODO we don't support this yet
+ default:
+ // TODO : We don't support rest just yet
return -1;
- }
- return -1;
+ }
}
- public int getPointCodeLength() {
- return this.pcLength;
+ public PointCodeFormat getPointCodeFormat() {
+ return this.pointCodeFormat;
}
- public void setPointCodeLength(int length) {
- this.pcLength = length;
+ public void setPointCodeFormat(PointCodeFormat pointCodeFormat) {
+ this.pointCodeFormat = pointCodeFormat;
}
- public int getSLSLength() {
+ public int getSlsLength() {
return this.slsLength;
}
- public void setSLSLength(int slsLength) {
+ public void setSlsLength(int slsLength) {
this.slsLength = slsLength;
}
@@ -129,10 +130,10 @@
if (this.isStarted)
return;
- if (!(this.pcLength == PC_FORMAT_14 || this.pcLength == PC_FORMAT_16 ||
this.pcLength == PC_FORMAT_24)) {
- throw new Exception("Invalid point code length set. Set 14 for ITU-T 14
bits or 16 for ITU-T 16 bits or 24 for ITU-T/ANSI 24 bits");
+ if (!(this.pointCodeFormat == PointCodeFormat.ITU ||
this.pointCodeFormat == PointCodeFormat.ANSI)) {
+ throw new Exception("Invalid PointCodeFormat set. We support only ITU
or ANSI now");
}
-
+
switch (this.slsLength) {
case 4:
this.maxSls = 16;
@@ -150,7 +151,7 @@
throw new Exception("Invalid SLS length set. Set 4 for max SLS to be 16
or 5 for max SLS to be 32 or 8 for max SLS to be 256");
}
- this.mtp3TransferPrimitiveFactory = new
Mtp3TransferPrimitiveFactory(this.pcLength, this.slsLength);
+ this.mtp3TransferPrimitiveFactory = new
Mtp3TransferPrimitiveFactory(this.pointCodeFormat, this.slsLength);
this.createSLSTable(this.deliveryTransferMessageThreadCount);