2 new revisions:

Revision: e051ed196156
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=e051ed196156&repo=load-balancer

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

==============================================================================
Revision: e051ed196156
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=e051ed196156&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: 6831a9b38f0f
Author:   Vladimir Ralev <[email protected]>
Date:     Thu Jun 28 09:08:25 2012
Log:      Update Issue 3

test

http://code.google.com/p/commscale/source/detail?r=6831a9b38f0f&repo=load-balancer

Added:
/jar/src/test/java/org/mobicents/tools/sip/balancer/operation/CustomHeartbeatTest.java

=======================================
--- /dev/null
+++ /jar/src/test/java/org/mobicents/tools/sip/balancer/operation/CustomHeartbeatTest.java Thu Jun 28 09:08:25 2012
@@ -0,0 +1,166 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat, Inc. 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.tools.sip.balancer.operation;
+
+import java.util.List;
+import java.util.Properties;
+
+import javax.sip.address.SipURI;
+import javax.sip.header.RecordRouteHeader;
+
+import junit.framework.TestCase;
+
+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.SIPNode;
+
+public class CustomHeartbeatTest extends TestCase{
+       BalancerRunner balancer;
+       int numNodes = 2;
+       AppServer[] servers = new AppServer[numNodes];
+       Shootist shootist;
+
+
+       /* (non-Javadoc)
+        * @see junit.framework.TestCase#setUp()
+        */
+       protected void setUp() throws Exception {
+               super.setUp();
+               shootist = new Shootist();
+
+               balancer = new BalancerRunner();
+               Properties properties = new Properties();
+               properties.setProperty("javax.sip.STACK_NAME", 
"SipBalancerForwarder");
+               properties.setProperty("javax.sip.AUTOMATIC_DIALOG_SUPPORT", 
"off");
+               // You need 16 for logging traces. 32 for debug + traces.
+               // Your code will limp at 32 but it is best for debugging.
+               properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", 
"LOG4J");
+               properties.setProperty("gov.nist.javax.sip.DEBUG_LOG",
+                               "logs/sipbalancerforwarderdebug.txt");
+               properties.setProperty("gov.nist.javax.sip.SERVER_LOG",
+                               "logs/sipbalancerforwarder.xml");
+               properties.setProperty("gov.nist.javax.sip.THREAD_POOL_SIZE", 
"2");
+               properties.setProperty("gov.nist.javax.sip.REENTRANT_LISTENER", 
"true");
+ properties.setProperty("gov.nist.javax.sip.CANCEL_CLIENT_TRANSACTION_CHECKED", "false");
+               properties.setProperty("internalHost", "127.0.0.1");
+               properties.setProperty("externalHost", "127.0.0.1");
+               properties.setProperty("internalPort", "5065");
+               properties.setProperty("externalPort", "5060");
+               balancer.start(properties);
+
+
+               for(int q=0;q<servers.length;q++) {
+ servers[q] = new AppServer("node" + q,4060+q, "127.0.0.1", 2000, 5060, 5060, "0");
+                       servers[q].start();
+               }
+               Thread.sleep(5000);
+       }
+
+       /* (non-Javadoc)
+        * @see junit.framework.TestCase#tearDown()
+        */
+       protected void tearDown() throws Exception {
+               super.tearDown();
+               for(int q=0;q<servers.length;q++) {
+                       servers[q].stop();
+               }
+               shootist.stop();
+               balancer.stop();
+       }
+
+       AppServer ringingAppServer;
+       AppServer okAppServer;
+       public void testCustomHeartbeat() 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
+                       public void uacAfterResponse(int statusCode, AppServer 
source) {
+                               if(statusCode == 180) {
+                                       ringingAppServer = source;
+                               } else {
+                                       okAppServer = source;
+
+                               }
+                       }
+               };
+               for(AppServer as:servers) 
as.setEventListener(failureEventListener);
+               shootist.callerSendsBye = true;
+
+               String fromName = "sender";
+               String fromHost = "sip-servlets.com";
+ SipURI fromAddress = servers[0].protocolObjects.addressFactory.createSipURI(
+                               fromName, fromHost);
+
+               String toUser = "replaces";
+               String toHost = "sip-servlets.com";
+ SipURI toAddress = servers[0].protocolObjects.addressFactory.createSipURI(
+                               toUser, toHost);
+
+               SipURI ruri = 
servers[0].protocolObjects.addressFactory.createSipURI(
+                               "usera", "127.0.0.1:5033");
+               ruri.setLrParam();
+               SipURI route = 
servers[0].protocolObjects.addressFactory.createSipURI(
+                               "lbaddress_InternalPort", "127.0.0.1:5065");
+               route.setParameter("node_host", "127.0.0.1");
+               route.setParameter("node_port", "4060");
+               route.setLrParam();
+               shootist.start();
+ //servers[0].sipListener.sendSipRequest("INVITE", fromAddress, toAddress, null, null, false);
+               servers[0].sendHeartbeat = false;
+               servers[1].sendHeartbeat = false;
+ servers[0].sipListener.sendSipRequest("OPTIONS", fromAddress, toAddress, "tcpPort=1\nudpPort=2\nhostname=sipHeartbeat\nip=127.0.0.1", route, false, new String[]{"Mobicents-Heartbeat"}, new String[]{"1"}, ruri);
+               Thread.sleep(4000);
+ servers[0].sipListener.sendSipRequest("OPTIONS", fromAddress, toAddress, "tcpPort=1\nudpPort=2\nhostname=sipHeartbeat\nip=127.0.0.1", route, false, new String[]{"Mobicents-Heartbeat"}, new String[]{"1"}, ruri);
+               Thread.sleep(4000);
+ servers[0].sipListener.sendSipRequest("OPTIONS", fromAddress, toAddress, "tcpPort=1\nudpPort=2\nhostname=sipHeartbeat\nip=127.0.0.1", route, false, new String[]{"Mobicents-Heartbeat"}, new String[]{"1"}, ruri);
+               Thread.sleep(4000);
+ servers[0].sipListener.sendSipRequest("OPTIONS", fromAddress, toAddress, "tcpPort=1\nudpPort=2\nhostname=sipHeartbeat\nip=127.0.0.1", route, false, new String[]{"Mobicents-Heartbeat"}, new String[]{"1"}, ruri);
+               Thread.sleep(4000);
+ servers[0].sipListener.sendSipRequest("OPTIONS", fromAddress, toAddress, "tcpPort=1\nudpPort=2\nhostname=sipHeartbeat\nip=127.0.0.1", route, false, new String[]{"Mobicents-Heartbeat"}, new String[]{"1"}, ruri);
+               List<SIPNode> list = balancer.getNodes();
+               SIPNode node = list.get(0);
+               assertEquals(node.getHostName(), "sipHeartbeat");
+               assertEquals(1, list.size());
+       }
+
+}

Reply via email to