2 new revisions:

Revision: fe8ae0685ba6
Author:   Vladimir Ralev <[email protected]>
Date:     Thu Jun 28 08:51:49 2012
Log:      Update Issue 3...
http://code.google.com/p/commscale/source/detail?r=fe8ae0685ba6&repo=load-balancer

Revision: f600b87ec919
Author:   Vladimir Ralev <[email protected]>
Date:     Thu Jun 28 08:56:42 2012
Log: Merge branch 'ts1' of https://code.google.com/p/commscale.load-balance...
http://code.google.com/p/commscale/source/detail?r=f600b87ec919&repo=load-balancer

==============================================================================
Revision: fe8ae0685ba6
Author:   Vladimir Ralev <[email protected]>
Date:     Thu Jun 28 08:51:49 2012
Log:      Update Issue 3

Custom heartbeats for the SIP LB
http://code.google.com/p/commscale/source/detail?r=fe8ae0685ba6&repo=load-balancer

Modified:
 /docs/sources/src/main/resources/en-US/concept-section-SS_Load_Balancer.xml
/jar/src/main/java/org/mobicents/tools/sip/balancer/ClusterSubdomainAffinityAlgorithm.java /jar/src/main/java/org/mobicents/tools/sip/balancer/HeaderConsistentHashBalancerAlgorithm.java /jar/src/main/java/org/mobicents/tools/sip/balancer/PersistentConsistentHashBalancerAlgorithm.java /jar/src/main/java/org/mobicents/tools/sip/balancer/PureConsistentHashBalancerAlgorithm.java /jar/src/main/java/org/mobicents/tools/sip/balancer/SIPBalancerForwarder.java
 /jar/src/test/java/org/mobicents/tools/sip/balancer/NodeRegisterTest.java
/jar/src/test/java/org/mobicents/tools/sip/balancer/algorithms/PureConsistentHashNodeDeathTest.java /jar/src/test/java/org/mobicents/tools/sip/balancer/operation/InviteTransactionFailover.java
 /jar/src/test/java/org/mobicents/tools/sip/balancer/operation/Shootist.java

=======================================
--- /docs/sources/src/main/resources/en-US/concept-section-SS_Load_Balancer.xml Thu Mar 24 06:50:56 2011 +++ /docs/sources/src/main/resources/en-US/concept-section-SS_Load_Balancer.xml Thu Jun 28 08:51:49 2012
@@ -533,5 +533,33 @@
         </imageobject>
       </mediaobject>
     </figure>
+  </section>
+  <section>
+    <title>Using the Load Balancer with Third-Party SIP Servers</title>
+ <para>The load balancer only forwards requests to servers that send heartbeat signals. A third party server can send metadata using a SIP OPTIONS or SIP INFO message towards the internal port of the SIP load balancer. For security reasons heartbeat messages arriving at the external entry-point will be ignored and using a single internal and external entry-point is not allowed. The third party SIP server must advertise it's metadata in the SIP message contents.</para> + <para>For example, this request will advertise a SIP server listening on 127.0.0.1:5070, both TCP and UDP .</para><programlisting linenumbering="unnumbered"><![CDATA[
+OPTIONS sip:[email protected]:5065;lr SIP/2.0
+Call-ID: [email protected]
+CSeq: 1 OPTIONS
+From: <sip:[email protected]>;tag=4481411
+To: <sip:[email protected]>
+Via: SIP/2.0/UDP 127.0.0.1:5070;branch=z9hG4bK-373335-ec2c7452cfd0130bd409ba4f8ea5f54e
+Max-Forwards: 70
+Contact: <sip:[email protected]:4060;transport=udp;lr>
+Route: <sip:[email protected]:5065;node_host=127.0.0.1;node_port=5070;lr>
+Content-Type: text/plain;charset=UTF-8
+Mobicents-Heartbeat: 1
+Content-Length: 54
+
+tcpPort=5070
+udpPort=5070
+hostname=sipHeartbeat
+ip=127.0.0.1
+    ]]></programlisting>
+ <para>The important headers to be filled in this request are <literal>Mobicents-Heartbeat</literal>, the Route header with <literal>;node_host=127.0.0.1;node_port=5070</literal> and the message contents. The message contents are interpreted as properties of the <literal>SIPNode</literal> object representing the node in the load balancer and can be further interpreted by load balancing algorithms for load balancing purposes. The value of the <literal>Mobicents-Heartbeat</literal> header is arbitrary and reserved for future use, the presence of the header is sufficient to instruct the load balancer how to process the request.</para> + <para>All requests initiated by the SIP Server must have the following hint in their Route header <literal>;node_host=127.0.0.1;node_port=5070</literal>. This hint instructs the SIP load balancer that the dialog initated by the application server must stay on the node advertised in the hint. This function is cruicial when the direction of the requests withing the dialog is reversed.</para> + <para>Since this SIP request represents a heartbeat signal, it must be sent regularly at least once every 5 seconds (by default). Sending this request is responsibility of the third party server. The load balancer will respond to every heartbeat request with 200 OK immediately. The third party server must expect the OK response. If no response if received within a threshhold time then the third party SIP server must assume the SIP load balancer is not available and use another (backup) load balancer.</para> + <para>The regular SIP load balancer setting are still in effect for third party servers and you can expect the same behavior as the Mobicents-specific RMI heartbeat configuration.</para> + <para>If you are desgning a pluggable algorithm using the SIP metadata, you can access the properties passed in the SIP message contents using <literal>SIPNode.getProperties()</literal></para>
   </section>
 </chapter>
=======================================
--- /jar/src/main/java/org/mobicents/tools/sip/balancer/ClusterSubdomainAffinityAlgorithm.java Tue May 22 06:40:28 2012 +++ /jar/src/main/java/org/mobicents/tools/sip/balancer/ClusterSubdomainAffinityAlgorithm.java Thu Jun 28 08:51:49 2012
@@ -25,7 +25,6 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
 import org.apache.log4j.Logger;

public class ClusterSubdomainAffinityAlgorithm extends CallIDAffinityBalancerAlgorithm {
@@ -47,7 +46,7 @@
                                return check;
                        }
                }
- logger.debug("No alternatives found for " + oldNode + " from " + alternativeNodes); + logger.info("No alternatives found for " + oldNode + " from " + alternativeNodes);

                return super.selectNewNode(oldNode, callId);
        }
=======================================
--- /jar/src/main/java/org/mobicents/tools/sip/balancer/HeaderConsistentHashBalancerAlgorithm.java Tue May 22 06:40:28 2012 +++ /jar/src/main/java/org/mobicents/tools/sip/balancer/HeaderConsistentHashBalancerAlgorithm.java Thu Jun 28 08:51:49 2012
@@ -52,15 +52,19 @@
        // no matter at what order the events arrived
private SortedSet<SIPNode> nodes = (SortedSet<SIPNode>) Collections.synchronizedSortedSet(new TreeSet<SIPNode>()); // And we also keep a copy in the array because it is faster to query by index
-       private Object[] nodesArray;
-
-       private boolean nodesAreDirty = true;
+       protected Object[] nodesArray;
+
+       protected boolean nodesAreDirty = true;

        public HeaderConsistentHashBalancerAlgorithm() {
        }

        public HeaderConsistentHashBalancerAlgorithm(String headerName) {
-               this.sipHeaderAffinityKey = headerName;
+               if(headerName == null) {
+                       this.sipHeaderAffinityKey = "Call-ID";
+               } else {
+                       this.sipHeaderAffinityKey = headerName;
+               }
        }

        public SIPNode processExternalRequest(Request request) {
@@ -182,6 +186,7 @@
     public void init() {
this.httpAffinityKey = getProperties().getProperty("httpAffinityKey", "appsession"); this.sipHeaderAffinityKey = getProperties().getProperty("sipHeaderAffinityKey", "Call-ID"); + logger.info("SIP affinity key = " + sipHeaderAffinityKey + " HTTP key = " + httpAffinityKey);
     }

        public void configurationChanged() {
=======================================
--- /jar/src/main/java/org/mobicents/tools/sip/balancer/PersistentConsistentHashBalancerAlgorithm.java Tue May 22 06:40:28 2012 +++ /jar/src/main/java/org/mobicents/tools/sip/balancer/PersistentConsistentHashBalancerAlgorithm.java Thu Jun 28 08:51:49 2012
@@ -22,28 +22,14 @@

 package org.mobicents.tools.sip.balancer;

-import gov.nist.javax.sip.header.SIPHeader;
-import gov.nist.javax.sip.header.Via;
-
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.Set;
-import java.util.logging.Level;
-import org.apache.log4j.Logger;
-
-import javax.sip.ListeningPoint;
-import javax.sip.address.SipURI;
-import javax.sip.header.FromHeader;
-import javax.sip.header.RouteHeader;
-import javax.sip.header.ToHeader;
-import javax.sip.message.Message;
-import javax.sip.message.Request;
-import javax.sip.message.Response;
-
+
+import org.apache.log4j.Logger;
 import org.jboss.cache.Cache;
 import org.jboss.cache.CacheFactory;
 import org.jboss.cache.DefaultCacheFactory;
@@ -53,7 +39,6 @@
 import org.jboss.cache.notifications.annotation.ViewChanged;
 import org.jboss.cache.notifications.event.Event;
 import org.jboss.cache.notifications.event.ViewChangedEvent;
-import org.jboss.netty.handler.codec.http.HttpRequest;

 /**
* Persistent Consistent Hash algorithm - see http://docs.google.com/present/view?id=dc5jp5vx_89cxdvtxcm Example algorithms section
@@ -64,16 +49,9 @@
public class PersistentConsistentHashBalancerAlgorithm extends HeaderConsistentHashBalancerAlgorithm { private static Logger logger = Logger.getLogger(PersistentConsistentHashBalancerAlgorithm.class.getCanonicalName());

-       protected String sipHeaderAffinityKey;
-       protected String httpAffinityKey;

        protected Cache cache;

- // And we also keep a copy in the array because it is faster to query by index
-       private Object[] nodesArray = new Object[]{};
-
-       private boolean nodesAreDirty = true;
-
        public PersistentConsistentHashBalancerAlgorithm() {
        }

=======================================
--- /jar/src/main/java/org/mobicents/tools/sip/balancer/PureConsistentHashBalancerAlgorithm.java Tue May 22 06:40:28 2012 +++ /jar/src/main/java/org/mobicents/tools/sip/balancer/PureConsistentHashBalancerAlgorithm.java Thu Jun 28 08:51:49 2012
@@ -58,16 +58,11 @@
public class PureConsistentHashBalancerAlgorithm extends HeaderConsistentHashBalancerAlgorithm { private static Logger logger = Logger.getLogger(PureConsistentHashBalancerAlgorithm.class.getCanonicalName());

-       protected String sipHeaderAffinityKey;
-       protected String httpAffinityKey;
-
        MessageDigest md5;

        HashMap<Integer, SIPNode> hashToNode = new HashMap<Integer, SIPNode>();
        HashMap<SIPNode, Integer> nodeToHash = new HashMap<SIPNode, Integer>();

- // And we also keep a copy in the array because it is faster to query by index
-       private Object[] nodesArray = new Object[]{};

        private TreeSet<SIPNode> tmpNodes = new TreeSet<SIPNode>();

=======================================
--- /jar/src/main/java/org/mobicents/tools/sip/balancer/SIPBalancerForwarder.java Tue May 22 06:40:28 2012 +++ /jar/src/main/java/org/mobicents/tools/sip/balancer/SIPBalancerForwarder.java Thu Jun 28 08:51:49 2012
@@ -28,14 +28,13 @@
 import gov.nist.javax.sip.message.SIPResponse;

 import java.text.ParseException;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.atomic.AtomicLong;
-import java.util.logging.Level;
-import org.apache.log4j.Logger;

 import javax.sip.DialogTerminatedEvent;
 import javax.sip.IOExceptionEvent;
@@ -65,6 +64,10 @@
 import javax.sip.message.Request;
 import javax.sip.message.Response;

+import org.apache.log4j.Logger;
+
+import com.sun.xml.internal.messaging.saaj.util.ByteInputStream;
+
 /**
* A transaction stateful UDP Forwarder that listens at a port and forwards to multiple * outbound addresses. It keeps a timer thread around that pings the list of
@@ -443,10 +446,33 @@

                final Request request = requestEvent.getRequest();
                final String requestMethod = request.getMethod();
+
+               if((requestMethod.equals(Request.OPTIONS) ||
+                               requestMethod.equals(Request.INFO)) &&
+                               request.getHeader("Mobicents-Heartbeat") != null 
&&
+                               sipProvider == 
balancerRunner.balancerContext.internalSipProvider) {
+                       byte[] bytes = (byte[]) request.getContent();
+                       Properties prop = new Properties();
+                       try {
+                               prop.load(new ByteInputStream(bytes, 
bytes.length));
+ SIPNode node = new SIPNode(prop.getProperty("hostname"), prop.getProperty("ip"));
+                               for(String id : prop.stringPropertyNames()) {
+                                       node.getProperties().put(id, 
prop.getProperty(id));
+                               }
+                               ArrayList<SIPNode> list = new 
ArrayList<SIPNode>();
+                               list.add(node);
+                               this.register.handlePingInRegister(list);
+ Response response = balancerRunner.balancerContext.messageFactory.createResponse(Response.OK, request);
+                sipProvider.sendResponse(response);
+                               return;
+                       } catch (Exception e) {
+ logger.error("Failure parsing heartbeat properties from this request " + request, e);
+                       }
+               }
                try {
                        updateStats(request);
-            forwardRequest(sipProvider,request);
-        } catch (Throwable throwable) {
+                       forwardRequest(sipProvider,request);
+               } catch (Throwable throwable) {
logger.error("Unexpected exception while forwarding the request " + request, throwable);
             if(!Request.ACK.equalsIgnoreCase(requestMethod)) {
                    try {
=======================================
--- /jar/src/test/java/org/mobicents/tools/sip/balancer/NodeRegisterTest.java Tue May 15 09:31:51 2012 +++ /jar/src/test/java/org/mobicents/tools/sip/balancer/NodeRegisterTest.java Thu Jun 28 08:51:49 2012
@@ -38,8 +38,6 @@
  */
 package org.mobicents.tools.sip.balancer;

-import java.net.InetAddress;
-import java.net.UnknownHostException;
 import java.rmi.RemoteException;
 import java.util.Properties;

=======================================
--- /jar/src/test/java/org/mobicents/tools/sip/balancer/algorithms/PureConsistentHashNodeDeathTest.java Mon Jul 25 05:32:47 2011 +++ /jar/src/test/java/org/mobicents/tools/sip/balancer/algorithms/PureConsistentHashNodeDeathTest.java Thu Jun 28 08:51:49 2012
@@ -32,9 +32,7 @@
 import org.mobicents.tools.sip.balancer.AppServer;
 import org.mobicents.tools.sip.balancer.BalancerRunner;
 import org.mobicents.tools.sip.balancer.EventListener;
-import org.mobicents.tools.sip.balancer.HeaderConsistentHashBalancerAlgorithm; import org.mobicents.tools.sip.balancer.PureConsistentHashBalancerAlgorithm;
-import org.mobicents.tools.sip.balancer.WorstCaseUdpTestAffinityAlgorithm;
 import org.mobicents.tools.sip.balancer.operation.Shootist;

 public class PureConsistentHashNodeDeathTest extends TestCase {
@@ -90,6 +88,7 @@
                balancer.stop();
        }
        static AppServer invite;
+       static AppServer register;
        static AppServer bye;
        static AppServer ack;
        public void testInviteByeLandOnDifferentNodes() throws Exception {
@@ -144,6 +143,42 @@
                assertNotNull(bye);
        }

+       public void testRegister() throws Exception {
+               EventListener failureEventListener = new EventListener() {
+
+                       @Override
+                       public void uasAfterResponse(int statusCode, AppServer 
source) {
+
+                       }
+
+                       @Override
+                       public void uasAfterRequestReceived(String method, 
AppServer source) {
+                               if(method.equals("REGISTER")) register = source;
+
+
+                       }
+
+                       @Override
+                       public void uacAfterRequestSent(String method, 
AppServer source) {
+                               // TODO Auto-generated method stub
+
+                       }
+
+                       @Override
+                       public void uacAfterResponse(int statusCode, AppServer 
source) {
+                               // TODO Auto-generated method stub
+
+                       }
+               };
+               for(AppServer as:servers) 
as.setEventListener(failureEventListener);
+
+
+                               shootist.sendInitial("REGISTER");
+                               Thread.sleep(5000);
+
+                               assertNotNull(register);
+       }
+
        public void testAllNodesDead() throws Exception {
                for(AppServer as:servers) {
                        as.sendCleanShutdownToBalancers();
@@ -156,29 +191,29 @@
                Thread.sleep(5000);
                assertEquals(500, shootist.responses.get(0).getStatusCode());
        }
-
+
        AppServer ringingAppServer;
        AppServer okAppServer;
        public void testOKRingingLandOnDifferentNode() throws Exception {
-
+
                EventListener failureEventListener = new EventListener() {
-
+
                        @Override
                        public void uasAfterResponse(int statusCode, AppServer 
source) {
-
-
-                       }
-
+
+
+                       }
+
                        @Override
                        public void uasAfterRequestReceived(String method, 
AppServer source) {
                                // TODO Auto-generated method stub
-
+
                        }

                        @Override
                        public void uacAfterRequestSent(String method, 
AppServer source) {
                                // TODO Auto-generated method stub
-
+
                        }

                        @Override
=======================================
--- /jar/src/test/java/org/mobicents/tools/sip/balancer/operation/InviteTransactionFailover.java Tue May 15 09:31:51 2012 +++ /jar/src/test/java/org/mobicents/tools/sip/balancer/operation/InviteTransactionFailover.java Thu Jun 28 08:51:49 2012
@@ -116,6 +116,7 @@

                Thread.sleep(5000);
                assertEquals(500, shootist.responses.get(0).getStatusCode());
+               assertNotNull(shootist.responses.get(0).getHeader("Via"));
        }

 //     private void _BAD_testInviteTx() throws Exception {
=======================================
--- /jar/src/test/java/org/mobicents/tools/sip/balancer/operation/Shootist.java Tue Apr 19 04:47:21 2011 +++ /jar/src/test/java/org/mobicents/tools/sip/balancer/operation/Shootist.java Thu Jun 28 08:51:49 2012
@@ -355,7 +355,10 @@

     }

-    public void sendInitialInvite() {
+    public void sendInitialInvite(){
+       sendInitial("INVITE");
+    }
+    public void sendInitial(String method) {
        try{
                if(!started) start();
                String fromName = "BigGuy";
@@ -407,7 +410,7 @@

             // Create a new Cseq header
             CSeqHeader cSeqHeader = headerFactory.createCSeqHeader(1L,
-                    Request.INVITE);
+                    method);

             // Create a new MaxForwardsHeader
             MaxForwardsHeader maxForwards = headerFactory
@@ -415,7 +418,7 @@

             // Create the request.
             Request request = messageFactory.createRequest(requestURI,
-                    Request.INVITE, callIdHeader, cSeqHeader, fromHeader,
+                    method, callIdHeader, cSeqHeader, fromHeader,
                     toHeader, viaHeaders, maxForwards);
             // Create contact headers
             String host = "127.0.0.1";

==============================================================================
Revision: f600b87ec919
Author:   Vladimir Ralev <[email protected]>
Date:     Thu Jun 28 08:56:42 2012
Log: Merge branch 'ts1' of https://code.google.com/p/commscale.load-balancer/ into ts1
http://code.google.com/p/commscale/source/detail?r=f600b87ec919&repo=load-balancer


Reply via email to