Revision: 15682
Author: vladimir.ralev
Date: Wed Dec 8 15:00:17 2010
Log: Update Issue 2191
Hudson test image
http://code.google.com/p/mobicents/source/detail?r=15682
Added:
/trunk/tools/sip-balancer/jar/src/main/java/org/mobicents/tools/sip/balancer/test
/trunk/tools/sip-balancer/jar/src/main/java/org/mobicents/tools/sip/balancer/test/BlackholeAppServer.java
/trunk/tools/sip-balancer/jar/src/main/java/org/mobicents/tools/sip/balancer/test/ProtocolObjects.java
/trunk/tools/sip-balancer/jar/src/main/java/org/mobicents/tools/sip/balancer/test/SipBalancerUdpTest.java
Modified:
/trunk/tools/sip-balancer/jar/src/test/java/org/mobicents/tools/sip/balancer/performance/UdpForwardingPerformanceTest.java
/trunk/tools/sip-balancer/pom.xml
=======================================
--- /dev/null
+++
/trunk/tools/sip-balancer/jar/src/main/java/org/mobicents/tools/sip/balancer/test/BlackholeAppServer.java
Wed Dec 8 15:00:17 2010
@@ -0,0 +1,141 @@
+package org.mobicents.tools.sip.balancer.test;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+import java.util.ArrayList;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import javax.sip.SipProvider;
+
+import org.mobicents.tools.sip.balancer.NodeRegisterRMIStub;
+import org.mobicents.tools.sip.balancer.SIPNode;
+
+public class BlackholeAppServer {
+ public ProtocolObjects protocolObjects;
+ Timer timer;
+ int port;
+ String name;
+ SIPNode appServerNode;
+ public boolean sendHeartbeat = true;
+ String lbAddress;
+ int lbRMIport;
+ int lbSIPext;
+ int lbSIPint;
+ public SipProvider sipProvider;
+
+ public BlackholeAppServer(String appServer, int port, String lbAddress,
int lbRMI, int lbSIPext, int lbSIPint) {
+ this.port = port;
+ this.name = appServer;
+ this.lbAddress = lbAddress;
+ this.lbRMIport = lbRMI;
+ this.lbSIPext = lbSIPext;
+ this.lbSIPint = lbSIPint;
+ }
+
+ public BlackholeAppServer(String appServer, int port) {
+ this(appServer, port, "127.0.0.1");
+
+ }
+
+ public BlackholeAppServer(String appServer, int port, String address) {
+ this(appServer, port, address, 2000, 5060, 5065);
+
+ }
+
+ DatagramSocket socket;
+ public long numPacketsReceived;
+ DatagramPacket packet = new DatagramPacket(new byte[1000], 1000);
+ Thread thread;
+ public void start() {
+ timer = new Timer();
+ try {
+ socket = new DatagramSocket(port,
InetAddress.getByName(lbAddress));
+ thread = new Thread() {
+ public void run() {
+ try {
+ while(true) {
+ socket.receive(packet);
+ numPacketsReceived++;
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch
block
+ e.printStackTrace();
+ }
+ }
+ };
+ thread.start();
+ } catch (SocketException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (UnknownHostException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ appServerNode = new SIPNode(name, "127.0.0.1");
+ appServerNode.getProperties().put("udpPort", port);
+ timer.schedule(new TimerTask() {
+
+ @Override
+ public void run() {
+ ArrayList<SIPNode> nodes = new
ArrayList<SIPNode>();
+ nodes.add(appServerNode);
+ sendKeepAliveToBalancers(nodes);
+ }
+ }, 1000, 1000);
+ }
+
+ public void stop() {
+ try {
+ thread.interrupt();
+ thread.stop();
+ } catch (Exception e) {}
+
+ timer.cancel();
+ socket.close();
+ if(protocolObjects != null)
+ protocolObjects.sipStack.stop();
+ protocolObjects=null;
+ //sendCleanShutdownToBalancers();
+ }
+
+ private void sendKeepAliveToBalancers(ArrayList<SIPNode> info) {
+ if(sendHeartbeat) {
+
Thread.currentThread().setContextClassLoader(NodeRegisterRMIStub.class.getClassLoader());
+ try {
+ Registry registry =
LocateRegistry.getRegistry(lbAddress, lbRMIport);
+ NodeRegisterRMIStub reg=(NodeRegisterRMIStub)
registry.lookup("SIPBalancer");
+ reg.handlePing(info);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ }
+ public void sendCleanShutdownToBalancers() {
+ ArrayList<SIPNode> nodes = new ArrayList<SIPNode>();
+ nodes.add(appServerNode);
+ sendCleanShutdownToBalancers(nodes);
+ }
+
+ public void sendCleanShutdownToBalancers(ArrayList<SIPNode> info) {
+
Thread.currentThread().setContextClassLoader(NodeRegisterRMIStub.class.getClassLoader());
+ try {
+ Registry registry =
LocateRegistry.getRegistry(lbAddress, lbRMIport);
+ NodeRegisterRMIStub reg=(NodeRegisterRMIStub)
registry.lookup("SIPBalancer");
+ reg.forceRemoval(info);
+ stop();
+ Thread.sleep(2000); // delay the OK for a while
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+
+}
=======================================
--- /dev/null
+++
/trunk/tools/sip-balancer/jar/src/main/java/org/mobicents/tools/sip/balancer/test/ProtocolObjects.java
Wed Dec 8 15:00:17 2010
@@ -0,0 +1,150 @@
+/*
+ * 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.test;
+
+import java.util.HashSet;
+import java.util.Properties;
+
+import javax.sip.ObjectInUseException;
+import javax.sip.SipException;
+import javax.sip.SipFactory;
+import javax.sip.SipProvider;
+import javax.sip.SipStack;
+import javax.sip.address.AddressFactory;
+import javax.sip.header.HeaderFactory;
+import javax.sip.message.MessageFactory;
+
+
+
+/**
+ * @author M. Ranganathan
+ *
+ */
+public class ProtocolObjects {
+ public final AddressFactory addressFactory;
+
+ public final MessageFactory messageFactory;
+
+ public final HeaderFactory headerFactory;
+
+ public final SipStack sipStack;
+
+ private int logLevel = 32;
+
+ String logFileDirectory = "logs/";
+
+ public final String transport;
+
+ private boolean isStarted;
+
+ public ProtocolObjects(String stackname, String pathname, String
transport,
+ boolean autoDialog, String outboundProxy) {
+
+ this.transport = transport;
+ SipFactory sipFactory = SipFactory.getInstance();
+ sipFactory.resetFactory();
+ sipFactory.setPathName(pathname);
+ Properties properties = new Properties();
+ properties.setProperty("javax.sip.STACK_NAME", stackname);
+
+ if(outboundProxy != null) {
+ properties.setProperty("javax.sip.OUTBOUND_PROXY", outboundProxy
+ "/"
+ + transport);
+ }
+ // The following properties are specific to nist-sip
+ // and are not necessarily part of any other jain-sip
+ // implementation.
+ properties.setProperty("gov.nist.javax.sip.DEBUG_LOG",
logFileDirectory
+ + stackname + "debuglog.txt");
+ properties.setProperty("gov.nist.javax.sip.SERVER_LOG",
+ logFileDirectory + stackname + "log.xml");
+
+ properties.setProperty("javax.sip.AUTOMATIC_DIALOG_SUPPORT",
+ (autoDialog ? "on" : "off"));
+
+ // For the forked subscribe notify test
+ properties.setProperty("javax.sip.FORKABLE_EVENTS", "foo");
+
+
+ // Dont use the router for all requests.
+// properties.setProperty("javax.sip.USE_ROUTER_FOR_ALL_URIS",
"false");
+
+ properties.setProperty("gov.nist.javax.sip.THREAD_POOL_SIZE",
"4");
+ properties.setProperty("gov.nist.javax.sip.REENTRANT_LISTENER",
"true");
+
+
+ // Set to 0 in your production code for max speed.
+ // 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",
Integer.valueOf(
+ logLevel).toString());
+
+ try {
+ // Create SipStack object
+ sipStack = sipFactory.createSipStack(properties);
+ System.out.println("createSipStack " + sipStack);
+ } catch (Exception e) {
+ // could not find
+ // gov.nist.jain.protocol.ip.sip.SipStackImpl
+ // in the classpath
+ e.printStackTrace();
+ System.err.println(e.getMessage());
+ throw new RuntimeException("Stack failed to
initialize");
+ }
+
+ try {
+ headerFactory = sipFactory.createHeaderFactory();
+ addressFactory = sipFactory.createAddressFactory();
+ messageFactory = sipFactory.createMessageFactory();
+ } catch (SipException ex) {
+ ex.printStackTrace();
+ throw new RuntimeException(ex);
+ }
+ }
+
+ public synchronized void destroy() {
+ HashSet<SipProvider> hashSet = new HashSet<SipProvider>();
+
+ for (SipProvider sipProvider : hashSet) {
+ hashSet.add(sipProvider);
+ }
+
+ for (SipProvider sipProvider : hashSet) {
+ for (int j = 0; j < 5; j++) {
+ try {
+ sipStack.deleteSipProvider(sipProvider);
+ } catch (ObjectInUseException ex) {
+ try {
+ Thread.sleep(1000);
+ } catch (Exception e) {
+ }
+
+ }
+ }
+ }
+
+ sipStack.stop();
+ }
+
+ public void start() throws Exception {
+ if (this.isStarted)
+ return;
+ sipStack.start();
+ this.isStarted = true;
+
+ }
+}
=======================================
--- /dev/null
+++
/trunk/tools/sip-balancer/jar/src/main/java/org/mobicents/tools/sip/balancer/test/SipBalancerUdpTest.java
Wed Dec 8 15:00:17 2010
@@ -0,0 +1,191 @@
+package org.mobicents.tools.sip.balancer.test;
+
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Properties;
+
+import org.mobicents.tools.sip.balancer.BalancerRunner;
+
+public class SipBalancerUdpTest {
+ static final String inviteRequest = "INVITE sip:[email protected]
SIP/2.0\r\n"+
+ "To: sip:[email protected]\r\n"+
+ "From: sip:[email protected] ;tag=1234\r\n"+
+ "Call-ID: [email protected]\r\n"+
+ "CSeq: 9 INVITE\r\n"+
+ "Via: SIP/2.0/UDP 135.180.130.133\r\n"+
+ "Content-Type: application/sdp\r\n"+
+ "\r\n"+
+ "v=0\r\n"+
+ "o=mhandley 29739 7272939 IN IP4 126.5.4.3\r\n" +
+ "c=IN IP4 135.180.130.88\r\n" +
+ "m=video 3227 RTP/AVP 31\r\n" +
+ "m=audio 4921 RTP/AVP 12\r\n" +
+ "a=rtpmap:31 LPC\r\n";
+
+ static byte[] inviteRequestBytes = inviteRequest.getBytes();
+
+ static final String ringing = "SIP/2.0 180 Ringing\n" + "To:
<sip:[email protected]>;tag=5432\n" +
+ "Via: SIP/2.0/UDP
127.0.0.1:5065;branch=z9hG4bK-3530-488ff2840f609639903eff914df9870f202e2zsd,SIP/2.0/UDP
127.0.0.1:5060;branch=z9hG4bK-3530-488ff2840f609639903eff914df9870f202e2,SIP/2.0/UDP
127.0.0.1:5033;branch=z9hG4bK-3530-488ff2840f609639903eff914df9870f\n"+
+ "Record-Route:
<sip:127.0.0.1:5065;transport=udp;lr>,<sip:127.0.0.1:5060;transport=udp;lr>\n"+
+ "CSeq: 1 INVITE\n"+
+ "Call-ID: [email protected]\n"+
+ "From: <sip:[email protected]>;tag=12345\n"+
+ "Content-Length: 0\n";
+
+ static byte[] ringingBytes = ringing.getBytes();
+
+ BalancerRunner balancer;
+ int numNodes = 2;
+ BlackholeAppServer server;
+
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+
+
+ 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", "0");
+ 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",
"100");
+ properties.setProperty("gov.nist.javax.sip.REENTRANT_LISTENER",
"true");
+
properties.setProperty("gov.nist.javax.sip.CANCEL_CLIENT_TRANSACTION_CHECKED", "false");
+
+ properties.setProperty("host", "127.0.0.1");
+ properties.setProperty("externalHost", "127.0.0.1");
+ properties.setProperty("internalHost", "127.0.0.1");
+ properties.setProperty("internalPort", "5065");
+ properties.setProperty("externalPort", "5060");
+ balancer.start(properties);
+
+
+ server = new BlackholeAppServer("blackhole", 18452,
"127.0.0.1");
+ server.start();
+ Thread.sleep(5000);
+
+ }
+ static InetAddress localhost;
+ static int callIdByteStart = -1;
+ static {try {
+ localhost = InetAddress.getByName("127.0.0.1");
+ byte[] callid = "0ha0isn".getBytes();
+ for(int q=0;q<1000; q++) {
+ int found = -1;;
+ for(int w=0;w<callid.length;w++) {
+ if(callid[w] != inviteRequestBytes[q+w]) {
+ break;
+ }
+ found = w;
+ }
+ if(found >0) {callIdByteStart = q; break;}
+ }
+ } catch (UnknownHostException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }}
+ private static long n = 0;
+ private static void modCallId() {
+ n++;
+ inviteRequestBytes[callIdByteStart] = (byte) (n&0xff);
+ inviteRequestBytes[callIdByteStart+1] = (byte) ((n>>8)&0xff);
+ inviteRequestBytes[callIdByteStart+2] = (byte) ((n>>16)&0xff);
+ }
+
+ public void testInvitePerformanceLong() {
+ testMessagePerformance(10*60*1000, 100000, inviteRequestBytes);
+ }
+
+ public void testInvitePerformance10sec() {
+ testMessagePerformance(10*1000, 100, inviteRequestBytes);
+ }
+
+ public void testInvitePerformanceDiffCallId10sec() {
+ testDiffCallIdPerformance(10*1000, 100);
+ }
+
+ public void testRingingPerformance10sec() {
+ testMessagePerformance(10*1000, 100, ringingBytes);
+ }
+
+ private void testMessagePerformance(int timespan, int maxLostPackets,
byte[] bytes) {
+ try {
+ DatagramSocket socket = new DatagramSocket(33276,
localhost);
+ long sentPackets = 0;
+ long startTime = System.currentTimeMillis();
+ while(true) {
+ boolean diffNotTooBig = sentPackets -
server.numPacketsReceived<maxLostPackets;
+ boolean thereIsStillTime =
System.currentTimeMillis()-startTime<timespan;
+ if(!thereIsStillTime) {
+ break;
+ }
+ if(diffNotTooBig) {
+ socket.send(new
DatagramPacket(bytes,bytes.length,localhost, 5060));
+ sentPackets++;
+ } else {
+ Thread.sleep(1);
+ }
+ }
+ System.out.println("Packets sent in " + timespan + " ms are " +
sentPackets + "(making " + sentPackets/((double)(timespan)/1000.) + "
initial requests per second)");
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ private void testDiffCallIdPerformance(int timespan, int
maxLostPackets) {
+ try {
+ DatagramSocket socket = new DatagramSocket(33276,
localhost);
+ long sentPackets = 0;
+ long startTime = System.currentTimeMillis();
+ while(true) {
+ boolean diffNotTooBig = sentPackets -
server.numPacketsReceived<maxLostPackets;
+ boolean thereIsStillTime =
System.currentTimeMillis()-startTime<timespan;
+ if(!thereIsStillTime) {
+ break;
+ }
+ if(diffNotTooBig) {
+ socket.send(new
DatagramPacket(inviteRequestBytes,inviteRequestBytes.length,localhost,
5060));
+ modCallId();
+ sentPackets++;
+ } else {
+ Thread.sleep(1);
+ }
+ }
+ System.out.println("Packets sent in " + timespan + " ms are " +
sentPackets + "(making " + sentPackets/((double)(timespan)/1000.) + "
initial requests per second)");
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ protected void tearDown() throws Exception {
+ server.stop();
+ balancer.stop();
+ }
+
+ public static void main(String[] args) {
+ try {
+ SipBalancerUdpTest test = new SipBalancerUdpTest();
+ test.setUp();
+ Integer time = Integer.parseInt(args[0]);
+ Integer maxDiff = Integer.parseInt(args[0]);
+ test.testMessagePerformance(time*1000, maxDiff,
inviteRequestBytes);
+ test.tearDown();
+ System.exit(0);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
=======================================
---
/trunk/tools/sip-balancer/jar/src/test/java/org/mobicents/tools/sip/balancer/performance/UdpForwardingPerformanceTest.java
Tue Dec 7 18:24:03 2010
+++
/trunk/tools/sip-balancer/jar/src/test/java/org/mobicents/tools/sip/balancer/performance/UdpForwardingPerformanceTest.java
Wed Dec 8 15:00:17 2010
@@ -112,7 +112,7 @@
}
public void testInvitePerformanceLong() {
- testMessagePerformance(1*60*1000, 10, inviteRequestBytes);
+ testMessagePerformance(1*60*1000, 100000, inviteRequestBytes);
}
public void testInvitePerformance10sec() {
@@ -142,7 +142,7 @@
socket.send(new
DatagramPacket(bytes,bytes.length,localhost, 5060));
sentPackets++;
} else {
- //Thread.sleep(1);
+ Thread.sleep(1);
}
}
System.out.println("Packets sent in " + timespan + " ms are " +
sentPackets + "(making " + sentPackets/((double)(timespan)/1000.) + "
initial requests per second)");
@@ -183,4 +183,15 @@
server.stop();
balancer.stop();
}
-}
+
+ public static void main(String[] args) {
+ try {
+ UdpForwardingPerformanceTest test = new
UdpForwardingPerformanceTest();
+ test.setUp();
+ test.testInvitePerformanceLong();
+ test.tearDown();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
=======================================
--- /trunk/tools/sip-balancer/pom.xml Tue Oct 19 14:41:41 2010
+++ /trunk/tools/sip-balancer/pom.xml Wed Dec 8 15:00:17 2010
@@ -5,7 +5,7 @@
<parent>
<artifactId>mobicents-parent</artifactId>
<groupId>org.mobicents</groupId>
- <version>2.13</version>
+ <version>2.15</version>
</parent>
<packaging>pom</packaging>