Revision: 14958
Author: oleg.kulikoff
Date: Tue Nov  2 00:19:53 2010
Log: Add toString() methods for debugging and logger output
http://code.google.com/p/mobicents/source/detail?r=14958

Modified:
/trunk/protocols/ss7/sccp/sccp-api/src/main/java/org/mobicents/protocols/ss7/sccp/parameter/GT0100.java /trunk/protocols/ss7/sccp/sccp-api/src/main/java/org/mobicents/protocols/ss7/sccp/parameter/GlobalTitle.java /trunk/protocols/ss7/sccp/sccp-api/src/main/java/org/mobicents/protocols/ss7/sccp/parameter/SccpAddress.java /trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/SccpProviderImpl.java /trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/SccpService.java /trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/SccpStackImpl.java /trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/message/UnitDataImpl.java /trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/message/XUnitDataImpl.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/test/java/org/mobicents/protocols/ss7/sccp/impl/router/RuleTest.java

=======================================
--- /trunk/protocols/ss7/sccp/sccp-api/src/main/java/org/mobicents/protocols/ss7/sccp/parameter/GT0100.java Thu Oct 7 03:41:34 2010 +++ /trunk/protocols/ss7/sccp/sccp-api/src/main/java/org/mobicents/protocols/ss7/sccp/parameter/GT0100.java Tue Nov 2 00:19:53 2010
@@ -34,10 +34,10 @@

     private final static GlobalTitleIndicator gti =
GlobalTitleIndicator.GLOBAL_TITLE_INCLUDES_TRANSLATION_TYPE_NUMBERING_PLAN_ENCODING_SCHEME_AND_NATURE_OF_ADDRESS;
-    private int translationType;
-    private NumberingPlan numberingPlan;
+    private int tt;
+    private NumberingPlan np;
     private EncodingScheme encodingScheme;
-    private NatureOfAddress natureOfAddress;
+    private NatureOfAddress na;
     private String digits = "";

     /** Creates a new instance of GT0100 */
@@ -46,9 +46,9 @@

     public GT0100(int translationType, NumberingPlan numberingPlan,
             NatureOfAddress natureOfAddress, String digits) {
-        this.translationType = translationType;
-        this.numberingPlan = numberingPlan;
-        this.natureOfAddress = natureOfAddress;
+        this.tt = translationType;
+        this.np = numberingPlan;
+        this.na = natureOfAddress;
         this.digits = digits;
this.encodingScheme = digits.length() % 2 == 0 ? EncodingScheme.BCD_EVEN : EncodingScheme.BCD_ODD;
     }
@@ -58,37 +58,37 @@
         int b2 = in.read() & 0xff;
         int b3 = in.read() & 0xff;

-        translationType = b1;
+        tt = b1;

         encodingScheme = EncodingScheme.valueOf(b2 & 0x0f);
-        numberingPlan = NumberingPlan.valueOf((b2 & 0xf0) >> 4);
-        natureOfAddress = NatureOfAddress.valueOf(b3 & 0x7f);
+        np = NumberingPlan.valueOf((b2 & 0xf0) >> 4);
+        na = NatureOfAddress.valueOf(b3 & 0x7f);

         digits = encodingScheme.decodeDigits(in);
     }

     public void encode(OutputStream out) throws IOException {
-        out.write((byte) translationType);
-
- byte b = (byte) ((numberingPlan.getValue() << 4) | (encodingScheme.getValue()));
+        out.write((byte) tt);
+
+ byte b = (byte) ((np.getValue() << 4) | (encodingScheme.getValue()));
         out.write(b);

-        b = (byte) (natureOfAddress.getValue() & 0x7f);
+        b = (byte) (na.getValue() & 0x7f);
         out.write(b);

         encodingScheme.encodeDigits(digits, out);
     }

     public int getTranslationType() {
-        return translationType;
+        return tt;
     }

     public NumberingPlan getNumberingPlan() {
-        return numberingPlan;
+        return np;
     }

     public NatureOfAddress getNatureOfAddress() {
-        return natureOfAddress;
+        return na;
     }

     public String getDigits() {
@@ -111,18 +111,22 @@
         }

         GT0100 gt1 = (GT0100)gt;
- return gt1.translationType == translationType && gt1.numberingPlan == numberingPlan && - gt1.natureOfAddress == natureOfAddress && gt1.digits.equals(digits);
+        return gt1.tt == tt && gt1.np == np &&
+                gt1.na == na && gt1.digits.equals(digits);
     }

     @Override
     public int hashCode() {
         int hash = 3;
-        hash = 61 * hash + this.translationType;
- hash = 61 * hash + (this.numberingPlan != null ? this.numberingPlan.hashCode() : 0); - hash = 61 * hash + (this.natureOfAddress != null ? this.natureOfAddress.hashCode() : 0);
+        hash = 61 * hash + this.tt;
+        hash = 61 * hash + (this.np != null ? this.np.hashCode() : 0);
+        hash = 61 * hash + (this.na != null ? this.na.hashCode() : 0);
hash = 61 * hash + (this.digits != null ? this.digits.hashCode() : 0);
         return hash;
     }

-}
+    @Override
+    public String toString() {
+ return "{tt=" + tt + ", np=" + np + ", na=" + na + ", digist=" + digits + "}";
+    }
+}
=======================================
--- /trunk/protocols/ss7/sccp/sccp-api/src/main/java/org/mobicents/protocols/ss7/sccp/parameter/GlobalTitle.java Tue Sep 14 06:07:33 2010 +++ /trunk/protocols/ss7/sccp/sccp-api/src/main/java/org/mobicents/protocols/ss7/sccp/parameter/GlobalTitle.java Tue Nov 2 00:19:53 2010
@@ -91,4 +91,8 @@
         return new GT0100(tt, np,  noa, digits);
     }

-}
+    @Override
+    public String toString() {
+        return getIndicator() + " " + getDigits();
+    }
+}
=======================================
--- /trunk/protocols/ss7/sccp/sccp-api/src/main/java/org/mobicents/protocols/ss7/sccp/parameter/SccpAddress.java Thu Oct 7 03:41:34 2010 +++ /trunk/protocols/ss7/sccp/sccp-api/src/main/java/org/mobicents/protocols/ss7/sccp/parameter/SccpAddress.java Tue Nov 2 00:19:53 2010
@@ -94,4 +94,9 @@
         hash = 37 * hash + (this.ai != null ? this.ai.hashCode() : 0);
         return hash;
     }
-}
+
+    @Override
+    public String toString() {
+        return "pc=" + pc + ",ssn=" + ssn + ",gt=" + gt;
+    }
+}
=======================================
--- /trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/SccpProviderImpl.java Sun Oct 24 22:47:27 2010 +++ /trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/SccpProviderImpl.java Tue Nov 2 00:19:53 2010
@@ -78,6 +78,7 @@
         SccpListener listener = listeners.get(address);
         if(listener == null)
         {
+            logger.info("Registere listeners for: " + listeners.keySet());
                if(logger.isEnabledFor(Level.WARN))
                {
                        logger.warn("No listener could be found for address: 
"+address);
=======================================
--- /trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/SccpService.java Tue Oct 26 06:19:15 2010 +++ /trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/SccpService.java Tue Nov 2 00:19:53 2010
@@ -54,6 +54,7 @@
        logger.info("Starting SCCP stack...");
         stack = new SccpStackImpl();
         stack.setLinksets(linksets);
+        stack.start();
         rebind(stack);
     }

=======================================
--- /trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/SccpStackImpl.java Sun Oct 24 22:47:27 2010 +++ /trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/SccpStackImpl.java Tue Nov 2 00:19:53 2010
@@ -108,6 +108,7 @@
         logger.info("Starting ...");
         executor = Executors.newFixedThreadPool(1);
         if (linksets != null) {
+            logger.info("Linksets :" + linksets.size());
             for (MtpProvider linkset : linksets) {
                 linkset.setMtpListener(this);
                 try {
@@ -233,8 +234,7 @@
         private SccpMessage message;

         protected MessageHandler(byte[] msu) {
-            //skip routing label
-            data = new ByteArrayInputStream(msu, 5, msu.length);
+            data = new ByteArrayInputStream(msu);
             message = null;
         }

@@ -245,6 +245,7 @@
         private SccpMessage parse() throws IOException {
             // wrap stream with DataInputStream
             DataInputStream in = new DataInputStream(data);
+
             int sio = 0;
             sio = in.read() & 0xff;

@@ -255,7 +256,10 @@
             if (si != 3) {
                 return null;
             }
-
+
+            //skip remaining 4 bytes
+            in.skip(4);
+
             // determine message type
             int mt = in.readUnsignedByte();
return ((MessageFactoryImpl) sccpProvider.getMessageFactory()).createMessage(mt, in);
@@ -265,6 +269,7 @@
             if (message == null) {
                 try {
                     message = parse();
+                    logger.info("Receive message " + message);
                 } catch (IOException e) {
                     e.printStackTrace();
                     return;
=======================================
--- /trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/message/UnitDataImpl.java Thu Sep 23 02:29:57 2010 +++ /trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/message/UnitDataImpl.java Tue Nov 2 00:19:53 2010
@@ -146,4 +146,9 @@
         this.data = data;
     }

-}
+    @Override
+    public String toString() {
+ return "UDT[calledPartyAddress=" + calledParty + ", callingPartyAddress=" + callingParty + "]";
+    }
+
+}
=======================================
--- /trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/message/XUnitDataImpl.java Thu Sep 23 02:29:57 2010 +++ /trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/message/XUnitDataImpl.java Tue Nov 2 00:19:53 2010
@@ -287,6 +287,10 @@
         this.data = data;
     }

+    @Override
+    public String toString() {
+ return "XUDT[calledPartyAddress=" + calledParty + ", callingPartyAddress=" + callingParty + "]";
+    }
 }


=======================================
--- /trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/router/RouterImpl.java Wed Oct 27 09:37:09 2010 +++ /trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/router/RouterImpl.java Tue Nov 2 00:19:53 2010
@@ -90,6 +90,21 @@
             store(rule);
         }
     }
+
+    /**
+     * Looks up rule for translation.
+     *
+     * @param calledParty called party address
+     * @return the rule with match to the called party address
+     */
+    public Rule find(SccpAddress calledParty) {
+        for (Rule rule : rules) {
+            if (rule.matches(calledParty)) {
+                return rule;
+            }
+        }
+        return null;
+    }

     /**
      * Gets the list of all rules.
=======================================
--- /trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/router/Rule.java Tue Oct 26 20:31:10 2010 +++ /trunk/protocols/ss7/sccp/sccp-impl/src/main/java/org/mobicents/protocols/ss7/sccp/impl/router/Rule.java Tue Nov 2 00:19:53 2010
@@ -23,6 +23,7 @@
 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.GlobalTitle;
 import org.mobicents.protocols.ss7.sccp.parameter.SccpAddress;

 /**
@@ -109,6 +110,33 @@
     public MTPInfo getMTPInfo() {
         return mtpInfo;
     }
+
+    /**
+     * Translate specified address according to the rule.
+     *
+     * @param address the origin address
+     * @return translated address
+     */
+    public SccpAddress translate(SccpAddress address) {
+        //step #1. translate digits
+        //TODO enable expression
+        String digits = this.translation.getDigits();
+
+        //step #2. translate global title
+        GlobalTitle gt = null;
+ if (translation.getNatureOfAddress() != null && translation.getTranslationType() == -1 && translation.getNumberingPlan() == null) { + gt = GlobalTitle.getInstance(translation.getNatureOfAddress(), digits); + } else if (translation.getNatureOfAddress() == null && translation.getTranslationType() != -1 && translation.getNumberingPlan() != null) { + gt = GlobalTitle.getInstance(translation.getTranslationType(), translation.getNumberingPlan(), digits); + } else if (translation.getNatureOfAddress() == null && translation.getTranslationType() != -1 && translation.getNumberingPlan() == null) { + gt = GlobalTitle.getInstance(translation.getTranslationType(), digits); + } else if (translation.getNatureOfAddress() != null && translation.getTranslationType() != -1 && translation.getNumberingPlan() != null) { + gt = GlobalTitle.getInstance(translation.getTranslationType(), translation.getNumberingPlan(), translation.getNatureOfAddress(), digits);
+        }
+
+        //step #3. create new address object
+        return new SccpAddress(gt, translation.getSubsystem());
+    }

     public boolean matches(SccpAddress address) {
         //consider routing based on global title only
=======================================
--- /trunk/protocols/ss7/sccp/sccp-impl/src/test/java/org/mobicents/protocols/ss7/sccp/impl/router/RuleTest.java Tue Oct 26 06:18:25 2010 +++ /trunk/protocols/ss7/sccp/sccp-impl/src/test/java/org/mobicents/protocols/ss7/sccp/impl/router/RuleTest.java Tue Nov 2 00:19:53 2010
@@ -10,8 +10,13 @@
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.mobicents.protocols.ss7.indicator.GlobalTitleIndicator;
 import org.mobicents.protocols.ss7.indicator.NatureOfAddress;
 import org.mobicents.protocols.ss7.indicator.NumberingPlan;
+import org.mobicents.protocols.ss7.sccp.parameter.GT0001;
+import org.mobicents.protocols.ss7.sccp.parameter.GT0100;
+import org.mobicents.protocols.ss7.sccp.parameter.GlobalTitle;
+import org.mobicents.protocols.ss7.sccp.parameter.SccpAddress;
 import static org.junit.Assert.*;

 /**
@@ -19,7 +24,7 @@
  * @author kulikov
  */
 public class RuleTest {
- private final static String RULE = "1; #ISDN_MOBILE#NATIONAL#9023629581# ; #ISDN_MOBILE#INTERNATIONAL#79023629581# ;linkset#14083#14155#0\n"; + private final static String RULE = "1; # #NATIONAL#9023629581# ; # #INTERNATIONAL#79023629581# ;linkset#14083#14155#0\n";

     public RuleTest() {
     }
@@ -40,6 +45,23 @@
     public void tearDown() {
     }

+    @Test
+    public void testMatches() {
+        Rule rule = Rule.getInstance(RULE);
+ SccpAddress address = new SccpAddress(GlobalTitle.getInstance(NatureOfAddress.NATIONAL, "9023629581"), 0);
+        assertTrue(rule.matches(address));
+    }
+
+    @Test
+    public void testTranslation() {
+ SccpAddress a1 = new SccpAddress(GlobalTitle.getInstance(NatureOfAddress.NATIONAL, "9023629581"), 0);
+        Rule rule = Rule.getInstance(RULE);
+
+        SccpAddress a2 = rule.translate(a1);
+ assertEquals(a2.getGlobalTitle().getIndicator(), GlobalTitleIndicator.GLOBAL_TITLE_INCLUDES_NATURE_OF_ADDRESS_INDICATOR_ONLY); + assertEquals(NatureOfAddress.INTERNATIONAL, ((GT0001)a2.getGlobalTitle()).getNoA());
+        assertEquals("79023629581", a2.getGlobalTitle().getDigits());
+    }
     /**
      * Test of getInstance method, of class Rule.
      */
@@ -47,11 +69,11 @@
     public void testGetInstance() {
         Rule rule = Rule.getInstance(RULE);
         assertEquals(1, rule.getNo());
- assertEquals(NumberingPlan.ISDN_MOBILE, rule.getPattern().getNumberingPlan());
+        assertEquals(null, rule.getPattern().getNumberingPlan());
assertEquals(NatureOfAddress.NATIONAL, rule.getPattern().getNatureOfAddress());
         assertEquals("9023629581", rule.getPattern().getDigits());

- assertEquals(NumberingPlan.ISDN_MOBILE, rule.getTranslation().getNumberingPlan());
+        assertEquals(null, rule.getTranslation().getNumberingPlan());
assertEquals(NatureOfAddress.INTERNATIONAL, rule.getTranslation().getNatureOfAddress());
         assertEquals("79023629581", rule.getTranslation().getDigits());

@@ -66,8 +88,8 @@
      */
     @Test
     public void testToString() {
- AddressInformation ai = new AddressInformation(-1, NumberingPlan.ISDN_MOBILE, NatureOfAddress.NATIONAL, "9023629581", -1); - AddressInformation tr = new AddressInformation(-1, NumberingPlan.ISDN_MOBILE, NatureOfAddress.INTERNATIONAL, "79023629581", -1); + AddressInformation ai = new AddressInformation(-1, null, NatureOfAddress.NATIONAL, "9023629581", -1); + AddressInformation tr = new AddressInformation(-1, null, NatureOfAddress.INTERNATIONAL, "79023629581", -1);
         MTPInfo mtpInfo = new MTPInfo("linkset", 14083, 14155, 0);

         Rule rule = new Rule(1, ai, tr, mtpInfo);

Reply via email to