Revision: 16129
Author: [email protected]
Date: Thu Dec 30 22:59:50 2010
Log: Added LinksetExecutor and fixed bug in MessageFactroy
http://code.google.com/p/mobicents/source/detail?r=16129
Added:
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinksetExecutor.java
/trunk/protocols/ss7/management/shell/src/test/java/org/mobicents/ss7/management/transceiver/MessageFactoryTest.java
Modified:
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinkOAMMessages.java
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinksetManager.java
/trunk/protocols/ss7/management/shell/src/main/java/org/mobicents/ss7/management/transceiver/Message.java
/trunk/protocols/ss7/management/shell/src/main/java/org/mobicents/ss7/management/transceiver/MessageFactory.java
=======================================
--- /dev/null
+++
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinksetExecutor.java
Thu Dec 30 22:59:50 2010
@@ -0,0 +1,101 @@
+package org.mobicents.ss7.linkset.oam;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Provides executor service for {...@link LinksetManager}
+ *
+ * @author amit bhayani
+ *
+ */
+public class LinksetExecutor {
+
+ private static final Logger logger = Logger
+ .getLogger(LinksetExecutor.class);
+
+ private LinksetManager linksetManager = null;
+
+ public LinksetExecutor() {
+
+ }
+
+ public LinksetManager getLinksetManager() {
+ return linksetManager;
+ }
+
+ public void setLinksetManager(LinksetManager linksetManager) {
+ this.linksetManager = linksetManager;
+ }
+
+ public String execute(String[] options) {
+
+ if (this.linksetManager == null) {
+ logger
+ .warn("LinksetManager not set. Command will not be
executed ");
+ return LinkOAMMessages.SERVER_ERROR;
+ }
+
+ try {
+ // Atleast 1 option is passed?
+ if (options == null || options.length < 2) {
+ return LinkOAMMessages.INVALID_COMMAND;
+ }
+
+ String firstOption = options[1];
+
+ if (firstOption == null) {
+ return LinkOAMMessages.INVALID_COMMAND;
+ }
+
+ if (firstOption.compareTo("show") == 0) {
+ // Show
+ return this.linksetManager.showLinkset(options);
+ } else if (firstOption.compareTo("create") == 0) {
+ // Create Linkset
+ return this.linksetManager.createLinkset(options);
+ } else if (firstOption.compareTo("delete") == 0) {
+ // Delete Linkset
+ return this.linksetManager.deleteLinkset(options);
+
+ } else if (firstOption.compareTo("activate") == 0) {
+ // noshutdown Linkset
+ return this.linksetManager.activateLinkset(options);
+
+ } else if (firstOption.compareTo("deactivate") == 0) {
+ // shutdown Linkset
+ return this.linksetManager.deactivateLinkset(options);
+
+ } else if (firstOption.compareTo("link") == 0) {
+ // Operation for Link
+
+ // Check do we have more options
+ if (options.length < 3) {
+ return LinkOAMMessages.INVALID_COMMAND;
+ }
+
+ // Check if its create, delete, shutdown or noshutdown
+ firstOption = options[2];
+ if (firstOption == null) {
+ return LinkOAMMessages.INVALID_COMMAND;
+ }
+
+ if (firstOption.compareTo("create") == 0) {
+ return this.linksetManager.createLink(options);
+ } else if (firstOption.compareTo("delete") == 0) {
+ return this.linksetManager.deleteLink(options);
+ } else if (firstOption.compareTo("deactivate") == 0) {
+ return this.linksetManager.deactivateLink(options);
+ } else if (firstOption.compareTo("activate") == 0) {
+ return this.linksetManager.activateLink(options);
+ }
+ }
+ } catch (Exception e) {
+ logger.error("Error while executing command ", e);
+ return e.toString();
+ } catch (Throwable t) {
+ return t.toString();
+ }
+ return LinkOAMMessages.INVALID_COMMAND;
+ }
+
+}
=======================================
--- /dev/null
+++
/trunk/protocols/ss7/management/shell/src/test/java/org/mobicents/ss7/management/transceiver/MessageFactoryTest.java
Thu Dec 30 22:59:50 2010
@@ -0,0 +1,133 @@
+package org.mobicents.ss7.management.transceiver;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ *
+ * @author amit bhayani
+ *
+ */
+public class MessageFactoryTest {
+
+ private MessageFactory messageFactory = null;
+
+ public MessageFactoryTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+ messageFactory = new MessageFactory();
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ @Test
+ public void testLongMessage() throws IOException {
+
+ String message = new StringBuffer()
+ .append(
+ "linkset1 dahdi opc=1
apc=2 ni=3 state=UNAVAILABLE\n")
+ .append(
+ " link1 span=1 channelId=1 code=1
state=UNAVAILABLE\n")
+ .append(
+ " link2 span=2 channelId=2 code=3
state=UNAVAILABLE\n")
+ .append("\n")
+ .append(
+ "linkset2 dahdi opc=123
apc=45678 ni=3 state=UNAVAILABLE\n")
+ .toString();
+ byte[] data = { 0x00, 0x00, 0x01, 0x2a, 0x6c, 0x69, 0x6e, 0x6b,
0x73,
+ 0x65, 0x74, 0x31, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x64,
+ 0x61, 0x68, 0x64, 0x69, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x70,
+ 0x63, 0x3d, 0x31, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x61, 0x70, 0x63, 0x3d, 0x32, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x6e, 0x69, 0x3d, 0x33, 0x20, 0x20, 0x20, 0x20, 0x73, 0x74,
+ 0x61, 0x74, 0x65, 0x3d, 0x55, 0x4e, 0x41, 0x56, 0x41, 0x49,
+ 0x4c, 0x41, 0x42, 0x4c, 0x45, 0x0a, 0x20, 0x20, 0x20, 0x20,
+ 0x6c, 0x69, 0x6e, 0x6b, 0x31, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x73, 0x70, 0x61, 0x6e, 0x3d, 0x31, 0x20, 0x20,
+ 0x20, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, 0x64,
+ 0x3d, 0x31, 0x20, 0x20, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x3d,
+ 0x31, 0x20, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x3d, 0x55,
+ 0x4e, 0x41, 0x56, 0x41, 0x49, 0x4c, 0x41, 0x42, 0x4c, 0x45,
+ 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6c, 0x69, 0x6e, 0x6b, 0x32,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x70, 0x61,
+ 0x6e, 0x3d, 0x32, 0x20, 0x20, 0x20, 0x63, 0x68, 0x61, 0x6e,
+ 0x6e, 0x65, 0x6c, 0x49, 0x64, 0x3d, 0x32, 0x20, 0x20, 0x20,
+ 0x63, 0x6f, 0x64, 0x65, 0x3d, 0x33, 0x20, 0x20, 0x73, 0x74,
+ 0x61, 0x74, 0x65, 0x3d, 0x55, 0x4e, 0x41, 0x56, 0x41, 0x49,
+ 0x4c, 0x41, 0x42, 0x4c, 0x45, 0x0a, 0x0a, 0x6c, 0x69, 0x6e,
+ 0x6b, 0x73, 0x65, 0x74, 0x32, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x64, 0x61, 0x68, 0x64, 0x69, 0x20, 0x20, 0x20, 0x20,
+ 0x6f, 0x70, 0x63, 0x3d, 0x31, 0x32, 0x33, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x61, 0x70, 0x63, 0x3d,
+ 0x34, 0x35, 0x36, 0x37, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x6e, 0x69, 0x3d, 0x33, 0x20, 0x20, 0x20, 0x20,
+ 0x73, 0x74, 0x61, 0x74, 0x65, 0x3d, 0x55, 0x4e, 0x41, 0x56,
+ 0x41, 0x49, 0x4c, 0x41, 0x42, 0x4c, 0x45, 0x0a, 0x0a };
+
+ ByteBuffer buffer = ByteBuffer.wrap(data);
+
+ Message msg = messageFactory.createMessage(buffer);
+
+ // 4 bytes are for length
+ for (int i = 0; i < msg.data.length; i++) {
+ assertEquals(data[4 + i], msg.data[i]);
+ }
+
+ }
+
+ public final static String dump(ByteBuffer buff, int size, boolean
asBits) {
+ String s = "";
+ buff.rewind();
+
+ while (buff.position() < size) {
+ String ss = null;
+ if (!asBits) {
+ ss = Integer.toHexString(buff.get() & 0xff);
+ } else {
+ ss = Integer.toBinaryString(buff.get() & 0xff);
+ }
+ ss = fillInZeroPrefix(ss, asBits);
+ s += " " + ss;
+ }
+ return s;
+ }
+
+ public final static String fillInZeroPrefix(String ss, boolean asBits)
{
+ if (asBits) {
+ if (ss.length() < 8) {
+ for (int j = ss.length(); j < 8; j++) {
+ ss = "0" + ss;
+ }
+ }
+ } else {
+ // hex
+ if (ss.length() < 2) {
+
+ ss = "0" + ss;
+ }
+ }
+
+ return ss;
+ }
+}
=======================================
---
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinkOAMMessages.java
Wed Dec 29 10:30:02 2010
+++
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinkOAMMessages.java
Thu Dec 30 22:59:50 2010
@@ -64,5 +64,7 @@
public static final String LINK_NOT_CONFIGURED = "Not all mandatory
parameters are set";
- public static String OPERATION_NOT_SUPPORTED = "Operation not
supported";
-}
+ public static final String OPERATION_NOT_SUPPORTED = "Operation not
supported";
+
+ public static final String SERVER_ERROR = "Server Error";
+}
=======================================
---
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinksetManager.java
Thu Dec 30 02:47:32 2010
+++
/trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinksetManager.java
Thu Dec 30 22:59:50 2010
@@ -158,7 +158,11 @@
.tail(); (e = e.getNext()) != end;) {
Linkset linkset = e.getValue();
linkset.print(sb, 0, 4);
- }
+ sb.append(FormatterHelp.NEW_LINE);
+ }
+
+ System.out.println(sb.toString());
+
return sb.toString();
}
=======================================
---
/trunk/protocols/ss7/management/shell/src/main/java/org/mobicents/ss7/management/transceiver/Message.java
Wed Dec 29 07:51:28 2010
+++
/trunk/protocols/ss7/management/shell/src/main/java/org/mobicents/ss7/management/transceiver/Message.java
Thu Dec 30 22:59:50 2010
@@ -9,7 +9,7 @@
*
*/
public class Message {
- private byte[] data = null;
+ protected byte[] data = null;
protected Message() {
@@ -35,6 +35,7 @@
* @param txBuffer
*/
protected void encode(ByteBuffer txBuffer) {
+
txBuffer.position(4); // Length int
txBuffer.put(data);
@@ -51,4 +52,5 @@
public String toString() {
return new String(data);
}
-}
+
+}
=======================================
---
/trunk/protocols/ss7/management/shell/src/main/java/org/mobicents/ss7/management/transceiver/MessageFactory.java
Wed Dec 29 07:51:28 2010
+++
/trunk/protocols/ss7/management/shell/src/main/java/org/mobicents/ss7/management/transceiver/MessageFactory.java
Thu Dec 30 22:59:50 2010
@@ -68,9 +68,13 @@
}
// obtain remaining length of the message and prepare buffer
- length = ((header[0] & 0xff << 24) | (header[1] & 0xff << 16)
- | (header[2] & 0xff << 8) | (header[3] & 0xff)) - 4;
-
+ length = ((header[0] & 0xff) << 24);
+ length += ((header[1] & 0xff) << 16);
+ length += ((header[2] & 0xff) << 8);
+ length += (header[3] & 0xff);
+
+ length-=4;
+
params = new byte[length];
// finally switch cursor position