Revision: 7287
Author: baranowb
Date: Mon Aug  3 07:46:14 2009
Log: change:
- rework Rtp - now we use single socket, just like mms, jitter shows difference between packet arrival, not sure if its proper, since there is no JitterBuffer.
 - fix start script


 TODO:
 - wiki+doco
 - generalize, now it toooo mgcp oriented.
http://code.google.com/p/mobicents/source/detail?r=7287

Added:
/trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/Timer.java /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/TimerImpl.java /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/TimerThreadFactory.java /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/rtp/RtpSocket.java /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/rtp/RtpSocketFactory.java /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/rtp/RtpSocketFactoryImpl.java /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/rtp/RtpSocketImpl.java /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/rtp/RtpSocketListener.java /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/rtp/Transceiver.java
Modified:
 /trunk/servers/media/test-suite/core/bin/run.sh
/trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/cli/CLIRunner.java /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/AbstractCall.java /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/AbstractTestCase.java /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/CallDisplayInterface.java /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/ann/AnnCall.java /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/rtp/RtpPacket.java /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/gui/MainGUIView.java

=======================================
--- /dev/null
+++ /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/Timer.java Mon Aug 3 07:46:14 2009
@@ -0,0 +1,58 @@
+/*
+ * Mobicents, Communications Middleware
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party
+ * contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program 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 distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ *
+ * Boston, MA  02110-1301  USA
+ */
+package org.mobicents.media.server.testsuite.general;
+
+import java.util.concurrent.ScheduledFuture;
+
+/**
+ *
+ * @author kulikov
+ */
+public interface Timer {
+    /**
+     * Gets value of interval between timer ticks.
+     *
+     * @return the int value in milliseconds.
+     */
+    public int getHeartBeat();
+
+    /**
+     * Modify interval between timer tick
+     *
+     * @param heartBeat the new value of interval in milliseconds.
+     */
+    public void setHeartBeat(int heartBeat);
+
+    /**
+     * Synchronizes task from this timer.
+     *
+     * @param task the task to be synchronized.
+     * @return the action which can be canceled to unsynchronize previously
+     * synchronized task
+     */
+    public ScheduledFuture synchronize(Runnable task);
+}
=======================================
--- /dev/null
+++ /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/TimerImpl.java Mon Aug 3 07:46:14 2009
@@ -0,0 +1,72 @@
+/*
+ * Mobicents Media Gateway
+ *
+ * The source code contained in this file is in in the public domain.
+ * It can be used in any project or product without prior permission,
+ * license or royalty payments. There is  NO WARRANTY OF ANY KIND,
+ * EXPRESS, IMPLIED OR STATUTORY, INCLUDING, WITHOUT LIMITATION,
+ * THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+ * AND DATA ACCURACY.  We do not warrant or make any representations
+ * regarding the use of the software or the  results thereof, including
+ * but not limited to the correctness, accuracy, reliability or
+ * usefulness of the software.
+ */
+package org.mobicents.media.server.testsuite.general;
+
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicLong;
+
+
+/**
+ * Provides repited execution at a reqular time intervals.
+ *
+ * @author Oleg Kulikov
+ */
+public class TimerImpl implements Timer {
+       public static final int _DEFAULT_T_PRIORITY = Thread.MAX_PRIORITY;
+ private transient final ScheduledExecutorService timer = Executors.newSingleThreadScheduledExecutor(new TimerThreadFactory());
+       private int heartBeat = 20;
+
+       /**
+        * Creates new instance of the timer.
+        */
+       public TimerImpl() {
+       }
+
+       /**
+        * Gets value of interval between timer ticks.
+        *
+        * @return the int value in milliseconds.
+        */
+       public int getHeartBeat() {
+               return heartBeat;
+       }
+
+       /**
+        * Modify interval between timer tick
+        *
+        * @param heartBeat
+        *            the new value of interval in milliseconds.
+        */
+       public void setHeartBeat(int heartBeat) {
+               this.heartBeat = heartBeat;
+       }
+
+       /**
+        * Synchronizes task from this timer.
+        *
+        * @param task
+        *            the task to be synchronized.
+        * @return the action which can be canceled to unsynchronize previously
+        *         synchronized task
+        */
+       public ScheduledFuture synchronize(Runnable task) {
+ return timer.scheduleAtFixedRate(task, 0, heartBeat, TimeUnit.MILLISECONDS);
+       }
+
+}
+
=======================================
--- /dev/null
+++ /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/TimerThreadFactory.java Mon Aug 3 07:46:14 2009
@@ -0,0 +1,32 @@
+/**
+ * Start time:12:14:30 2009-08-03<br>
+ * Project: mobicents-media-server-test-suite<br>
+ *
+ * @author <a href="mailto:[email protected]";>Bartosz Baranowski </a>
+ */
+package org.mobicents.media.server.testsuite.general;
+
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicLong;
+
+
+/**
+ * Start time:12:14:30 2009-08-03<br>
+ * Project: mobicents-media-server-test-suite<br>
+ *
+ * @author <a href="mailto:[email protected]";>Bartosz Baranowski
+ *         </a>
+ */
+public class TimerThreadFactory implements ThreadFactory {
+       public static final int _DEFAULT_T_PRIORITY = Thread.MAX_PRIORITY;
+       public static final AtomicLong sequence = new AtomicLong(0);
+ private ThreadGroup factoryThreadGroup = new ThreadGroup("MMSToolClockThreadGroup[" + sequence.incrementAndGet() + "]");
+
+       public Thread newThread(Runnable r) {
+               Thread t = new Thread(this.factoryThreadGroup, r);
+               t.setPriority(_DEFAULT_T_PRIORITY);
+               // ??
+               //t.start();
+               return t;
+       }
+}
=======================================
--- /dev/null
+++ /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/rtp/RtpSocket.java Mon Aug 3 07:46:14 2009
@@ -0,0 +1,57 @@
+/**
+ * Start time:09:28:08 2009-08-03<br>
+ * Project: mobicents-media-server-test-suite<br>
+ *
+ * @author <a href="mailto:[email protected]";>Bartosz Baranowski </a>
+ */
+package org.mobicents.media.server.testsuite.general.rtp;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.SocketException;
+
+/**
+ * Start time:09:28:08 2009-08-03<br>
+ * Project: mobicents-media-server-test-suite<br>
+ *
+ * @author <a href="mailto:[email protected]";>Bartosz Baranowski </a>
+ */
+public interface RtpSocket {
+
+       /**
+        *
+        */
+       void close();
+
+
+
+
+       public void setPeer(InetAddress address, int port) throws IOException;
+
+       public void addListener(RtpSocketListener listener);
+
+       public void removeListener(RtpSocketListener listener);
+
+
+
+       /**
+        * Gets address to which this socked is bound.
+        *
+        * @return either local address to which this socket is bound
+        */
+       public String getLocalAddress();
+
+       /**
+        * Returns port number to which this socked is bound.
+        *
+        * @return port number or -1 if socket not bound.
+        */
+       public int getLocalPort();
+
+       public void notify(Exception e);
+
+       /**
+        * @param rtpPacket
+        */
+       void receive(RtpPacket rtpPacket);
+}
=======================================
--- /dev/null
+++ /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/rtp/RtpSocketFactory.java Mon Aug 3 07:46:14 2009
@@ -0,0 +1,88 @@
+/**
+ * Start time:09:34:34 2009-08-03<br>
+ * Project: mobicents-media-server-test-suite<br>
+ *
+ * @author <a href="mailto:[email protected]";>Bartosz Baranowski </a>
+ */
+package org.mobicents.media.server.testsuite.general.rtp;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.util.Map;
+import java.util.Vector;
+import java.util.concurrent.ScheduledExecutorService;
+
+import javax.sdp.Attribute;
+
+import org.mobicents.media.server.testsuite.general.Timer;
+
+/**
+ * Start time:09:34:34 2009-08-03<br>
+ * Project: mobicents-media-server-test-suite<br>
+ * This interface defines RtpSocketFacctory - similar can be found in mms,
+ * however tool should be independent so we cant reuse mms components.
+ *
+ * @author <a href="mailto:[email protected]";>Bartosz Baranowski </a>
+ */
+public interface RtpSocketFactory {
+
+       public RtpSocket createSocket() throws SocketException, IOException;
+
+       public void releaseSocket(RtpSocket socket);
+
+       /**
+ * Terminates execution of created sockets, this is hard stop method, which
+        * will propably break calls.
+        */
+       public void stop();
+
+       public void start() throws SocketException, IOException;
+       /**
+        * Set execturo, this will read data from sockets
+        *
+        * @param executor
+        */
+       public void setTimer(Timer executor);
+
+       public Timer getTimer();
+
+       /**
+        * Gets the IP address to which trunk is bound. All endpoints of the 
trunk
+        * use this address for RTP connection.
+        *
+        * @return the IP address string to which this trunk is bound.
+        */
+       public String getBindAddress();
+
+       /**
+ * Modify the bind address. All endpoints of the trunk use this address for
+        * RTP connection.
+        *
+        * @param bindAddress
+        *            IP address as string or host name.
+        */
+ public void setBindAddress(String bindAddress) throws UnknownHostException;
+
+       /**
+        * Gets the available port range.
+        *
+        * @return the string in format "lowPort-highPort".
+        */
+       public int getPort();
+
+       /**
+        * Modify port used to create RTP stream.
+        *
+        * @param portRange
+        *            the string in format "lowPort-highPort"
+        */
+       public void setPort(int port);
+
+       // FIXME: should we reuse org.mobicents.media.Format?
+
+       public Vector<Attribute> getFormatMap();
+
+       public void setFormatMap(Vector<Attribute> originalFormatMap);
+}
=======================================
--- /dev/null
+++ /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/rtp/RtpSocketFactoryImpl.java Mon Aug 3 07:46:14 2009
@@ -0,0 +1,176 @@
+/**
+ * Start time:09:56:52 2009-08-03<br>
+ * Project: mobicents-media-server-test-suite<br>
+ *
+ * @author <a href="mailto:[email protected]";>Bartosz Baranowski </a>
+ */
+package org.mobicents.media.server.testsuite.general.rtp;
+
+import java.io.IOException;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.nio.ByteBuffer;
+import java.nio.channels.DatagramChannel;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.nio.channels.spi.SelectorProvider;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Vector;
+import java.util.concurrent.ScheduledExecutorService;
+
+import javax.sdp.Attribute;
+
+import org.apache.log4j.Logger;
+
+import org.mobicents.media.server.testsuite.general.Timer;
+
+/**
+ * Start time:09:56:52 2009-08-03<br>
+ * Project: mobicents-media-server-test-suite<br>
+ *
+ * @author <a href="mailto:[email protected]";>Bartosz Baranowski </a>
+ */
+public class RtpSocketFactoryImpl implements RtpSocketFactory {
+
+ private static final Logger log = Logger.getLogger(RtpSocketFactoryImpl.class);
+
+       private InetAddress bindAddress;
+
+       private int localPort=6006;
+
+
+       private Timer timer;
+       private Vector<Attribute> formatMap;
+
+ protected volatile HashMap<SocketAddress, RtpSocket> rtpSockets = new HashMap<SocketAddress, RtpSocket>();
+       private Transceiver transceiver;
+
+       public RtpSocket createSocket() throws SocketException, IOException {
+ RtpSocket rtpSocket = new RtpSocketImpl(transceiver, timer, formatMap, this);
+               return rtpSocket;
+       }
+
+       public void releaseSocket(RtpSocket rtpSocket) {
+               rtpSockets.remove(((RtpSocketImpl)rtpSocket).remoteAddress);
+       }
+
+       /*
+        * (non-Javadoc)
+        *
+        * 
@seeorg.mobicents.media.server.testsuite.general.rtp.RtpSocketFactory#
+        * getFormatMap()
+        */
+       public Vector<Attribute> getFormatMap() {
+               return this.formatMap;
+       }
+
+
+
+       /*
+        * (non-Javadoc)
+        *
+        * @see
+ * org.mobicents.media.server.testsuite.general.rtp.RtpSocketFactory#getTimer
+        * ()
+        */
+       public Timer getTimer() {
+               return this.timer;
+       }
+
+       /*
+        * (non-Javadoc)
+        *
+        * 
@seeorg.mobicents.media.server.testsuite.general.rtp.RtpSocketFactory#
+        * setBindAddress(java.lang.String)
+        */
+ public void setBindAddress(String bindAddress) throws UnknownHostException {
+               this.bindAddress = InetAddress.getByName(bindAddress);
+
+       }
+
+       /*
+        * (non-Javadoc)
+        *
+        * 
@seeorg.mobicents.media.server.testsuite.general.rtp.RtpSocketFactory#
+        * setFormatMap(java.util.Map)
+        */
+       public void setFormatMap(Vector<Attribute> originalFormatMap) {
+               this.formatMap = originalFormatMap;
+
+       }
+
+
+       /*
+        * (non-Javadoc)
+        *
+        * @see
+ * org.mobicents.media.server.testsuite.general.rtp.RtpSocketFactory#setTimer
+        * (java.util.concurrent.ScheduledExecutorService)
+        */
+       public void setTimer(Timer executor) {
+               this.timer = executor;
+       }
+
+       /*
+        * (non-Javadoc)
+        *
+        * @see
+ * org.mobicents.media.server.testsuite.general.rtp.RtpSocketFactory#stop()
+        */
+       public void stop() {
+               if(this.transceiver!=null)
+               {
+                       this.transceiver.stop();
+                       this.transceiver = null;
+               }
+               log.info("Stopped RTP Factory");
+
+       }
+
+       /* (non-Javadoc)
+ * @see org.mobicents.media.server.testsuite.general.rtp.RtpSocketFactory#getBindAddress()
+        */
+       public String getBindAddress() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       /* (non-Javadoc)
+ * @see org.mobicents.media.server.testsuite.general.rtp.RtpSocketFactory#start()
+        */
+       public void start() throws SocketException, IOException {
+ InetSocketAddress address = new InetSocketAddress(bindAddress, localPort);
+
+ log.info("Binding RTP transceiver to " + bindAddress + ":" + localPort);
+
+        transceiver = new Transceiver(rtpSockets, bindAddress, localPort);
+        transceiver.start();
+
+       }
+
+       /* (non-Javadoc)
+ * @see org.mobicents.media.server.testsuite.general.rtp.RtpSocketFactory#getPort()
+        */
+       public int getPort() {
+               return this.localPort;
+       }
+
+       /* (non-Javadoc)
+ * @see org.mobicents.media.server.testsuite.general.rtp.RtpSocketFactory#setPort(int)
+        */
+       public void setPort(int port) {
+               this.localPort = port;
+
+       }
+
+
+
+
+}
=======================================
--- /dev/null
+++ /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/rtp/RtpSocketImpl.java Mon Aug 3 07:46:14 2009
@@ -0,0 +1,166 @@
+/**
+ * Start time:10:17:34 2009-08-03<br>
+ * Project: mobicents-media-server-test-suite<br>
+ *
+ * @author <a href="mailto:[email protected]";>Bartosz Baranowski </a>
+ */
+package org.mobicents.media.server.testsuite.general.rtp;
+
+import java.io.IOException;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.SocketException;
+import java.nio.ByteBuffer;
+import java.nio.channels.DatagramChannel;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Vector;
+import java.util.concurrent.ScheduledFuture;
+
+import javax.sdp.Attribute;
+
+import org.apache.log4j.Logger;
+import org.mobicents.media.Buffer;
+import org.mobicents.media.Format;
+import org.mobicents.media.server.impl.rtp.RtpHeader;
+import org.mobicents.media.server.testsuite.general.Timer;
+
+/**
+ * Start time:10:17:34 2009-08-03<br>
+ * Project: mobicents-media-server-test-suite<br>
+ *
+ * @author <a href="mailto:[email protected]";>Bartosz Baranowski</a>
+ */
+public class RtpSocketImpl implements RtpSocket {
+
+ private static final transient Logger log = Logger.getLogger(RtpSocketImpl.class);
+
+
+
+       private int localPort;
+       private String localAddress;
+
+       private int remotePort;
+       String remoteAddress;
+       private InetSocketAddress remoteInetSocketAddress = null;
+
+       // holder for dynamic payloads.
+       private Vector<Attribute> rtpMap = new Vector<Attribute>();
+
+ private final List<RtpSocketListener> dataSinks = new ArrayList<RtpSocketListener>();
+
+       private RtpSocketFactoryImpl rtpSocketFactoryImpl;
+       private Timer timer;
+
+       /**
+        *
+        * @param transceiver
+        * @param timer
+        * @param formatMap
+        * @param rtpSocketFactoryImpl2
+        */
+ public RtpSocketImpl(Transceiver transceiver, Timer timer, Vector<Attribute> formatMap, RtpSocketFactoryImpl rtpSocketFactory) {
+               this.rtpSocketFactoryImpl = rtpSocketFactory;
+               this.timer = timer;
+               this.rtpMap.addAll(formatMap);
+
+               this.localAddress = this.rtpSocketFactoryImpl.getBindAddress();
+               this.localPort = this.rtpSocketFactoryImpl.getPort();
+       }
+
+
+
+
+       /*
+        * (non-Javadoc)
+        *
+        * @see
+        * 
org.mobicents.media.server.testsuite.general.rtp.RtpSocket#addListener
+        * (org.mobicents.media.server.testsuite.general.rtp.RtpSocketListener)
+        */
+       public void addListener(RtpSocketListener listener) {
+               this.dataSinks.add(listener);
+
+       }
+
+       /*
+        * (non-Javadoc)
+        *
+        * @see
+ * org.mobicents.media.server.testsuite.general.rtp.RtpSocket#removeListener
+        * (org.mobicents.media.server.testsuite.general.rtp.RtpSocketListener)
+        */
+       public void removeListener(RtpSocketListener listener) {
+               this.dataSinks.remove(listener);
+
+       }
+
+       public void resetRtpMap() {
+               this.rtpMap.clear();
+               this.rtpMap.addAll(this.rtpSocketFactoryImpl.getFormatMap());
+       }
+
+       /*
+        * (non-Javadoc)
+        *
+        * @see 
org.mobicents.media.server.testsuite.general.rtp.RtpSocket#close()
+        */
+       public void close() {
+               
this.rtpSocketFactoryImpl.rtpSockets.remove(remoteInetSocketAddress);
+
+       }
+
+       /**
+        * Assigns remote end.
+        *
+        * @param address
+        *            the address of the remote party.
+        * @param port
+        *            the port number of the remote party.
+        */
+       public void setPeer(InetAddress address, int port) throws IOException {
+               remoteAddress = address.getHostAddress();
+               remotePort = port;
+ remoteInetSocketAddress = new InetSocketAddress(remoteAddress, remotePort);
+               
this.rtpSocketFactoryImpl.rtpSockets.put(remoteInetSocketAddress, this);
+
+               if (log.isDebugEnabled()) {
+ log.debug("Connect RTP socket[" + localAddress + ":" + localPort + " to " + remoteAddress + ":" + remotePort);
+               }
+
+       }
+
+       /**
+        * Gets address to which this socked is bound.
+        *
+        * @return either local address to which this socket is bound
+        */
+       public String getLocalAddress() {
+               return localAddress;
+       }
+
+       /**
+        * Returns port number to which this socked is bound.
+        *
+        * @return port number or -1 if socket not bound.
+        */
+       public int getLocalPort() {
+               return localPort;
+       }
+
+       public void notify(Exception e) {
+               for (RtpSocketListener l : this.dataSinks)
+                       l.error(e);
+       }
+
+       /* (non-Javadoc)
+ * @see org.mobicents.media.server.testsuite.general.rtp.RtpSocket#receive(org.mobicents.media.server.testsuite.general.rtp.RtpPacket)
+        */
+       public void receive(RtpPacket rtpPacket) {
+               for (RtpSocketListener l : this.dataSinks)
+                       l.receive(rtpPacket);
+
+       }
+
+}
=======================================
--- /dev/null
+++ /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/rtp/RtpSocketListener.java Mon Aug 3 07:46:14 2009
@@ -0,0 +1,21 @@
+/**
+ * Start time:10:22:09 2009-08-03<br>
+ * Project: mobicents-media-server-test-suite<br>
+ *
+ * @author <a href="mailto:[email protected]";>Bartosz Baranowski </a>
+ */
+package org.mobicents.media.server.testsuite.general.rtp;
+
+/**
+ * Start time:10:22:09 2009-08-03<br>
+ * Project: mobicents-media-server-test-suite<br>
+ *
+ * @author <a href="mailto:[email protected]";>Bartosz Baranowski
+ *         </a>
+ */
+public interface RtpSocketListener {
+
+       public void receive(RtpPacket packet);
+       public void error(Exception e);
+
+}
=======================================
--- /dev/null
+++ /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/rtp/Transceiver.java Mon Aug 3 07:46:14 2009
@@ -0,0 +1,119 @@
+/**
+ * Start time:14:52:37 2009-08-03<br>
+ * Project: mobicents-media-server-test-suite<br>
+ *
+ * @author <a href="mailto:[email protected]";>Bartosz Baranowski </a>
+ */
+package org.mobicents.media.server.testsuite.general.rtp;
+
+import java.io.IOException;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.net.SocketException;
+import java.nio.ByteBuffer;
+import java.nio.channels.DatagramChannel;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.nio.channels.spi.SelectorProvider;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+
+/**
+ * Start time:14:52:37 2009-08-03<br>
+ * Project: mobicents-media-server-test-suite<br>
+ *
+ * @author <a href="mailto:[email protected]";>Bartosz Baranowski
+ *         </a>
+ */
+public class Transceiver implements Runnable {
+       private DatagramSocket socket;
+       protected DatagramChannel channel;
+       private Selector readSelector;
+       private InetAddress bindAddress;
+       private int localPort;
+       private int bufferSize = 8196;
+       private ByteBuffer readerBuffer = ByteBuffer.allocate(bufferSize);
+       private volatile boolean started = false;
+       private HashMap<SocketAddress, RtpSocket> rtpSockets;
+
+ public Transceiver(HashMap<SocketAddress, RtpSocket> rtpSockets, InetAddress bindAddress, int localPort) throws SocketException, IOException {
+               this.rtpSockets = rtpSockets;
+               this.bindAddress = bindAddress;
+               this.localPort = localPort;
+
+               channel = DatagramChannel.open();
+               channel.configureBlocking(false);
+
+               socket = channel.socket();
+
+               // creating local address and trying to bind socket to this
+               // address
+ InetSocketAddress address = new InetSocketAddress(bindAddress, localPort);
+               socket.bind(address);
+
+               readSelector = SelectorProvider.provider().openSelector();
+               channel.register(readSelector, SelectionKey.OP_READ);
+       }
+
+       public void start() {
+               started = true;
+               new Thread(this, "RTP Transceiver").start();
+       }
+
+       public void stop() {
+               started = false;
+               try {
+                       channel.disconnect();
+                       channel.close();
+                       socket.disconnect();
+                       socket.close();
+                       readSelector.close();
+               } catch (Exception e) {
+               }
+       }
+
+       private void notifyError(Exception e) {
+               Collection<RtpSocket> list = rtpSockets.values();
+               for (RtpSocket s : list) {
+                       s.notify(e);
+               }
+       }
+
+ public void send(byte[] data, int len, SocketAddress remoteAddress) throws IOException {
+               ByteBuffer byteBuffer1 = ByteBuffer.wrap(data);
+               int count = 0;
+
+               while (count < len) {
+                       count += channel.send(byteBuffer1, remoteAddress);
+                       byteBuffer1.compact();
+                       byteBuffer1.flip();
+               }
+       }
+
+       public void run() {
+               while (started) {
+                       try {
+                               readSelector.select();
+                               SocketAddress remoteAddress = 
channel.receive(readerBuffer);
+
+                               readerBuffer.flip();
+                               RtpSocket rtpSocket = 
rtpSockets.get(remoteAddress);
+
+                               if (rtpSocket != null) {
+                                       RtpPacket rtpPacket = new 
RtpPacket(readerBuffer);
+                                       rtpPacket.setTime(new 
Date(System.currentTimeMillis()));
+                                       rtpSocket.receive(rtpPacket);
+                               }
+
+                               readerBuffer.clear();
+                       } catch (IOException e) {
+                               if (started) {
+                                       notifyError(e);
+                               }
+                       }
+               }
+       }
+}
=======================================
--- /trunk/servers/media/test-suite/core/bin/run.sh     Sun Jul 26 11:36:12 2009
+++ /trunk/servers/media/test-suite/core/bin/run.sh     Mon Aug  3 07:46:14 2009
@@ -162,7 +162,7 @@

       "$JAVA" $JAVA_OPTS \
        -classpath "$RUN_CLASSPATH" \
-       org.mobicents.media.server.testsuite.cli.CLIRunner "$*"
+       org.mobicents.media.server.testsuite.cli.CLIRunner $*



=======================================
--- /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/cli/CLIRunner.java Sun Jul 26 11:36:12 2009 +++ /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/cli/CLIRunner.java Mon Aug 3 07:46:14 2009
@@ -14,9 +14,11 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.InetAddress;
+import java.net.SocketException;
 import java.net.URL;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Properties;
 import java.util.Set;
@@ -122,7 +124,7 @@
sb.append("--concurrentcalls : concurrent calls, default is -1, which means unbound\n"); sb.append("--maxcalls : max calls, default is -1, which means unbound\n"); sb.append("--datadir : data dump directory, default is ./datadump\n"); - sb.append("--audiofile : audio file url, if requried, default is file:/...../target/audio/ulaw_13s.wav\n"); + sb.append("--audiofile : audio file url, if requried, default is file:/./../../target/audio/ulaw_13s.wav\n"); sb.append("--audiocodec : audio codec to be used if requried, default is \'0 pcmu/8000\', value should be specifiedd in \'\'\n"); sb.append("--testtype : test type, currently there is only one available: AnnTest\n"); sb.append("--maxfail : specifies how many calls may fail until testtool will stop sending requests to server, default is -1, which means unbound\n");
@@ -180,7 +182,7 @@
* org.mobicents.media.server.testsuite.general.CallDisplayInterface#getCodec
         * ()
         */
-       public Vector<Attribute> getCodec() {
+       public Vector<Attribute> getCodecs() {
                return this.codec;
        }

@@ -406,12 +408,14 @@
                        log.info("Starting test case, prest 'q' to exit test");
                } catch (UnknownHostException ex) {
                        log.log(Level.SEVERE, null, ex);
+                       return ;
                } catch (Exception e) {
                        log.log(Level.SEVERE, null, e);
                        return;
                }

                try {
+
                        this.testCase.start();
                        while (this.testCase.getTestState() != 
TestState.Stoped) {
                                try {
@@ -459,7 +463,6 @@

Getopt getOpt = new Getopt("CLIRunner", args, _GETOPT_PARAMS_STRING, _LONG_OPTS);
                getOpt.setOpterr(true);
-
                int c = -1;
                String v = null;

@@ -668,7 +671,7 @@
throw new RuntimeException("There is no such test type, valid are: " + AnnTest + ", value passed:" + v);
        }

- public AbstractTestCase getTestCaseForType(CallDisplayInterface cdi) throws UnknownHostException { + public AbstractTestCase getTestCaseForType(CallDisplayInterface cdi) throws IllegalStateException, SocketException, IOException {
                if (this.toString().equals(AnnTest.toString())) {

                        AnnouncementTest at = new AnnouncementTest();
=======================================
--- /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/AbstractCall.java Wed Jul 29 06:11:26 2009 +++ /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/AbstractCall.java Mon Aug 3 07:46:14 2009
@@ -6,6 +6,7 @@

 import jain.protocol.ip.mgcp.message.parms.CallIdentifier;
 import jain.protocol.ip.mgcp.message.parms.EndpointIdentifier;
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -13,19 +14,9 @@
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
-import java.net.DatagramSocket;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-import java.net.SocketException;
-import java.nio.ByteBuffer;
-import java.nio.channels.DatagramChannel;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 import java.util.Vector;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.atomic.AtomicLong;

@@ -37,6 +28,9 @@

 import org.apache.log4j.Logger;
 import org.mobicents.media.server.testsuite.general.rtp.RtpPacket;
+import org.mobicents.media.server.testsuite.general.rtp.RtpSocket;
+import org.mobicents.media.server.testsuite.general.rtp.RtpSocketFactory;
+import org.mobicents.media.server.testsuite.general.rtp.RtpSocketListener;
 import org.mobicents.mgcp.stack.JainMgcpExtendedListener;
 import org.mobicents.mgcp.stack.JainMgcpStackProviderImpl;

@@ -44,7 +38,7 @@
  *
  * @author baranowb
  */
-public abstract class AbstractCall implements JainMgcpExtendedListener, Runnable, Serializable { +public abstract class AbstractCall implements JainMgcpExtendedListener, Serializable, RtpSocketListener {

        protected transient Logger logger = 
Logger.getLogger(AbstractCall.class);
        // We are serializable, just in case.
@@ -74,12 +68,8 @@
        // Below is part we dont want to propagate to other side :)
        protected transient AbstractTestCase testCase;
        // RTP part
-       protected transient DatagramChannel datagramChannel;
-       // protected transient DatagramSocket socket = null;
-       protected transient final ScheduledExecutorService readerThread;
-       protected transient ScheduledFuture readerTask;
-       protected transient boolean receiveRTP;
-
+
+    protected transient RtpSocket socket;
        // MGCP part
        protected transient JainMgcpStackProviderImpl provider;

@@ -96,7 +86,7 @@
                try {

                        this.sequence = _GLOBAL_SEQ.incrementAndGet();
- this.readerThread = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("CallThreadFactory-"+this.getClass().getName()+"-"+this.sequence));
+
                        this.setDumpDir(this.testCase.getTestDumpDirectory());
                        this.fos = new FileOutputStream(dataFileName);
                        this.dataDumpChannel = new ObjectOutputStream(fos);
@@ -106,18 +96,7 @@
                        finished = true;
                } finally {
                        if (!finished) {
-                               try {
-                                       if (datagramChannel.isConnected() || 
datagramChannel.isOpen()) {
-                                               datagramChannel.close();
-                                               // This will close socket.
-                                       }
-                                       this.datagramChannel = null;
-                               } catch (Exception e) {
-                               }
-                               // if (socket != null && (socket.isBound() ||
-                               // socket.isConnected())) {
-                               // socket.close();
-                               // }
+
                                try {
                                        if (dataDumpChannel != null) {
                                                dataDumpChannel.close();
@@ -148,32 +127,29 @@
this.graphDataFileName = new File(testDumpDirectory, this.sequence + "_graph.txt");
        }

-
-
        public java.io.File getGraphDataFileName() {
                return graphDataFileName;
        }

        protected void initSocket() throws IOException {
-               this.datagramChannel = DatagramChannel.open();
-               this.datagramChannel.configureBlocking(false);
-               DatagramSocket socket = this.datagramChannel.socket();
-
-               InetAddress bindAddress = 
this.testCase.getClientTestNodeAddress();
-               // this.socket = new DatagramSocket();
-               for (int i = 1024; i < 65535; i++) {
-                       try {
-                               SocketAddress address = new 
InetSocketAddress(bindAddress, i);
-                               // socket = new DatagramSocket(address);
-                               socket.bind(address);
- logger.debug("Socket created port = " + socket.getLocalPort() + " address = " + socket.getLocalAddress());
-                               return;
-                       } catch (SocketException e) {
-                               // e.printStackTrace();
-                               continue;
-                       }
-               }
-               throw new SocketException();
+               if (this.testCase != null && this.testCase.getSocketFactory() 
!= null) {
+                       RtpSocketFactory factory = 
this.testCase.getSocketFactory();
+                       this.socket = factory.createSocket();
+                       socket.addListener(this);
+
+               }
+       }
+
+       protected void releaseSocket() {
+               try {
+                       if (this.socket != null) {
+                               this.socket.close();
+                               this.socket = null;
+                       }
+
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
        }

        public List<RtpPacket> getRtp() throws IOException {
@@ -238,34 +214,20 @@
                case ENDED:
                case IN_ERROR:
                case TIMED_OUT:
-                       this.receiveRTP = false;
-                       try {
- if (datagramChannel != null && (datagramChannel.isConnected() || datagramChannel.isOpen())) {
-                                       datagramChannel.close();
-                               }
-                               this.datagramChannel = null;
-                       } catch (Exception e) {
-                       }
-
-                       if (rtpTraffic != null && rtpTraffic.size()>0) {
-//                             try {
-//                                     if (graphDataDumpChannel != null) {
-// graphDataDumpChannel.write(("Call ID: "+this.getCallID()+AbstractTestCase._LINE_SEPARATOR).getBytes());
-//                                     }
-//                             } catch (IOException ex) {
-//                                     logger.error(ex);
-//                             }
-
+                       this.releaseSocket();
+
+                       if (rtpTraffic != null && rtpTraffic.size() > 0) {
+
                                for (int i = 0; i < rtpTraffic.size() - 1; i++) 
{
                                        RtpPacket p1 = rtpTraffic.get(i);
                                        RtpPacket p2 = rtpTraffic.get(i + 1);
int localJitter = (int) (p2.getTime().getTime() - p1.getTime().getTime());
-                                       if(localJitter> this.peakJitter)
-                                        this.peakJitter = localJitter;
-                                       //Aprox
-                                       this.avgJitter+=localJitter;
-                                       this.avgJitter/=2;
-
+                                       if (localJitter > this.peakJitter)
+                                               this.peakJitter = localJitter;
+                                       // Aprox
+                                       this.avgJitter += localJitter;
+                                       this.avgJitter /= 2;
+
                                }
                                try {
                                        if (graphDataDumpChannel != null) {
@@ -273,11 +235,11 @@
graphDataDumpChannel.write((avgJitter + AbstractTestCase._LINE_SEPARATOR).getBytes()); graphDataDumpChannel.write((peakJitter + AbstractTestCase._LINE_SEPARATOR).getBytes());
                                        }
-
+
                                } catch (IOException ex) {
                                        logger.error(ex);
                                }
-
+
                                for (int i = 0; i < rtpTraffic.size() - 1; i++) 
{
                                        RtpPacket p1 = rtpTraffic.get(i);
                                        RtpPacket p2 = rtpTraffic.get(i + 1);
@@ -293,11 +255,10 @@
                                        try {
                                                if (graphDataDumpChannel != 
null) {
int localJitter = (int) (p2.getTime().getTime() - p1.getTime().getTime());
-
-
+
graphDataDumpChannel.write((localJitter + AbstractTestCase._LINE_SEPARATOR).getBytes());
                                                }
-
+
                                        } catch (IOException ex) {
                                                logger.error(ex);
                                        }
@@ -305,7 +266,7 @@
                                }
                                try {
                                        if (dataDumpChannel != null) {
-                                               RtpPacket p1 = 
rtpTraffic.get(rtpTraffic.size()-1);
+                                               RtpPacket p1 = 
rtpTraffic.get(rtpTraffic.size() - 1);
                                                dataDumpChannel.writeObject(p1);
                                        }
                                } catch (IOException ex) {
@@ -313,28 +274,9 @@
                                }
                                this.rtpTraffic.clear();
                        }
-                       // for (int index = 0; index < this.rtpTraffic.size(); 
index++) {
-                       // // for(RtpPacket packet:this.rtpTraffic){
-                       // RtpPacket packet = this.rtpTraffic.remove(0);
-                       // // logger.info("Dumping data to file: "+packet);
-                       //
-                       // try {
-                       // if (dataDumpChannel != null) {
-                       // dataDumpChannel.writeObject(packet);
-                       // }
-                       // } catch (IOException ex) {
-                       // logger.error(ex);
-                       // }
-                       // }
-                       // This is cause here we get like 60 packets, dunno 
why....
-
+
                        this.rtpTraffic = null;

-                       // receiveRTP = false;
-                       // if (socket != null && (socket.isBound() || 
socket.isConnected()))
-                       // {
-                       // socket.close();
-                       // }
                        try {
                                if (dataDumpChannel != null) {
                                        dataDumpChannel.close();
@@ -351,13 +293,9 @@
                                }
                        } catch (Exception e) {
                                logger.error(e);
-                       }finally
-                        {
-                            if(this.readerThread!=null)
-                            {
-                                this.readerThread.shutdownNow();
-                            }
-                        }
+                       } finally {
+
+                       }
                        break;

                default:
@@ -406,62 +344,9 @@
                } catch (SdpException e) {
                        e.printStackTrace();
                }
-
-               // System.out.println("Local SDP: " + localSDP.toString());

                return localSDP.toString();
        }
-
-       // Run method for read, we are run in readerThread
-       public void run() {
-               try {
-                       if (receiveRTP) {
-
-                               // byte[] buffer = new byte[172];
-                               // DatagramPacket packet = new 
DatagramPacket(buffer,
-                               // buffer.length);
-                               ByteBuffer packetBuffer = 
ByteBuffer.allocate(172);
-                               try {
-                                       // socket.receive(packet);
-                                       long received = 0;
-                                       int readCount = 0;
-                                       int readMaxCount = 4;
-                                       while (received != 172 && readCount < 
readMaxCount) {
-                                               received += 
datagramChannel.read(packetBuffer);
-                                               readCount++;
-                                       }
-
-                                       // RtpPacket rtp = new 
RtpPacket(packetBuffer.array());
-
-                                       packetBuffer.flip();
-                                       RtpPacket rtp = new 
RtpPacket(packetBuffer.array());
-                                       rtp.setTime(new 
Date(System.currentTimeMillis()));
-
-
-                                       if (rtpTraffic != null) {
-                                               rtpTraffic.add(rtp);
-                                       } else {
-
-                                       }
-
-                                       // FIXME: add calcualtion of jiiter 
stuff
-                               } catch (SocketException e) {
-                                       // This will happen on read, as we odnt 
sync it can be that
-                                       // flag receiveRTP is fale but read 
thread is already in
-                                       // while block.
-                                       e.printStackTrace();
-
-                               } catch (IOException e) {
-                                       e.printStackTrace();
-                               } catch 
(java.nio.channels.NotYetConnectedException e) {
-                                       e.printStackTrace();
-                               }
-                       }
-
-               } finally {
-
-               }
-       }

        public abstract void start();

@@ -476,5 +361,23 @@
        public void setTimeoutHandle(ScheduledFuture<?> timeoutHandle) {
                this.timeoutHandle = timeoutHandle;
        }
-
-}
+    ////////////////////
+       // SOCKET METHODS //
+       ////////////////////
+
+       public void error(Exception e) {
+               //FIXME?
+
+
+       }
+
+       public void receive(RtpPacket packet) {
+               if(this.rtpTraffic!=null)
+               {
+                       this.rtpTraffic.add(packet);
+               }
+
+       }
+
+
+}
=======================================
--- /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/AbstractTestCase.java Sun Jul 26 11:36:12 2009 +++ /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/AbstractTestCase.java Mon Aug 3 07:46:14 2009
@@ -19,6 +19,7 @@
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.net.InetAddress;
+import java.net.SocketException;
 import java.net.UnknownHostException;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -36,6 +37,8 @@
 import javax.sdp.SdpFactory;

 import org.mobicents.media.server.testsuite.general.file.FileUtils;
+import org.mobicents.media.server.testsuite.general.rtp.RtpSocketFactory;
+import org.mobicents.media.server.testsuite.general.rtp.RtpSocketFactoryImpl;
 import org.mobicents.media.server.testsuite.gui.ext.CallStateTableModel;
 import org.mobicents.mgcp.stack.JainMgcpExtendedListener;
 import org.mobicents.mgcp.stack.JainMgcpStackImpl;
@@ -62,17 +65,15 @@
        protected transient SdpFactory sdpFactory;
        protected transient CallDisplayInterface callDisplay;
        protected Map<Long, AbstractCall> callSequenceToCall;
+
        // We mix view, but this is easier to achieve perf with that.
        protected transient CallStateTableModel model;
        // protected part - some variables that we might use.
        protected InetAddress clientTestNodeAddress;
        protected InetAddress serverJbossBindAddress;
-       // some mgcp magic
-       protected transient JainMgcpStackImpl stack;
-       protected transient JainMgcpStackProviderImpl provider;
-       // We need this to map TXID to Call :)
- protected transient Map<Integer, AbstractCall> mgcpTransactionToProxy = new HashMap<Integer, AbstractCall>(); - protected transient Map<String, AbstractCall> requestIdIdToProxy = new HashMap<String, AbstractCall>();
+
+
+
        // timestamp :), its used for files
        protected long testTimesTamp = System.currentTimeMillis();
        protected transient File testDumpDirectory;
@@ -90,6 +91,17 @@
        protected long totalCalls;
        protected long maxErrorCallNumber;

+
+       protected transient RtpSocketFactory socketFactory;
+
+       //FIXME: this will go into MGCP test case, will be removed from here
+       // some mgcp magic
+       protected transient JainMgcpStackImpl stack;
+       protected transient JainMgcpStackProviderImpl provider;
+       // We need this to map TXID to Call :)
+ protected transient Map<Integer, AbstractCall> mgcpTransactionToProxy = new HashMap<Integer, AbstractCall>(); + protected transient Map<String, AbstractCall> requestIdIdToProxy = new HashMap<String, AbstractCall>();
+
        public AbstractTestCase() {
                this.callSequenceToCall = new HashMap<Long, AbstractCall>();
                // model = new CallStateTableModel(this.callSequenceToCall);
@@ -101,7 +113,7 @@

        }

- public AbstractTestCase(CallDisplayInterface cdi) throws UnknownHostException, IllegalStateException { + public AbstractTestCase(CallDisplayInterface cdi) throws IllegalStateException, SocketException, IOException {
                setCallDisplay(cdi);
                model = new CallStateTableModel(this.callSequenceToCall);
                AbstractCall.resetSequence();
@@ -109,8 +121,32 @@
NamedThreadFactory timeGuardThreadFactory = new NamedThreadFactory("GuardThreadFactoryTestCaseFactory"); executors = Executors.newScheduledThreadPool(3,executorsThreadFactory); timeGuard = Executors.newScheduledThreadPool(5,timeGuardThreadFactory);
+                this.init();
+
+
        }

+       private void init() throws SocketException, IOException
+       {
+               if(this.socketFactory==null)
+               {
+                       this.socketFactory = new RtpSocketFactoryImpl();
+                       this.socketFactory.setTimer(new TimerImpl());
+                       //this.socketFactory.setPortRange("5000-10000");
+
+               }
+
+               if(this.socketFactory!=null)
+               {
+
+                       
this.socketFactory.setBindAddress(this.callDisplay.getLocalAddress());
+                       
this.socketFactory.setFormatMap(this.callDisplay.getCodecs());
+                       this.socketFactory.start();
+               }
+       }
+
+
+
        protected void incrementOngoignCall() {
                this.ongoingCallNumber++;
                this.totalCalls++;
@@ -206,6 +242,8 @@
                return this.totalCalls;
        }

+
+
        public void stop(boolean onGracefull) {

                synchronized (this.testState) {
@@ -254,7 +292,12 @@
                                        } catch (Exception e) {
                                                e.printStackTrace();
                                        }
-
+                                       try {
+                                               this.socketFactory.stop();
+
+                                       } catch (Exception e) {
+                                               e.printStackTrace();
+                                       }
                                        // Now lets serialize.

                                        serialize();
@@ -319,15 +362,20 @@
                return this.testState;
        }

- public void setCallDisplay(CallDisplayInterface cdi) throws UnknownHostException, IllegalStateException {
+       public RtpSocketFactory getSocketFactory() {
+               return socketFactory;
+       }
+
+ public void setCallDisplay(CallDisplayInterface cdi) throws IllegalStateException, SocketException, IOException {
                this.callDisplay = cdi;

this.clientTestNodeAddress = InetAddress.getByName(this.callDisplay.getRemoteAddress()); this.serverJbossBindAddress = InetAddress.getByName(this.callDisplay.getRemoteAddress());

+
                this.sdpFactory = SdpFactory.getInstance();
this.testDumpDirectory = new File(cdi.getDefaultDataDumpDirectory(), "" + this.testTimesTamp);
-
+
                if (!this.testDumpDirectory.exists()) {

                        if (!this.testDumpDirectory.mkdirs()) {
@@ -342,6 +390,8 @@
                        }
                }

+               this.init();
+
        }

        // This method is used on loaded test case
@@ -383,7 +433,7 @@
        public abstract AbstractCall getNewCall();

        Vector<Attribute> getSDPAttributes() {
-               return this.callDisplay.getCodec();
+               return this.callDisplay.getCodecs();
        }

        public SdpFactory getSdpFactory() {
=======================================
--- /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/CallDisplayInterface.java Tue Jul 21 09:36:05 2009 +++ /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/CallDisplayInterface.java Mon Aug 3 07:46:14 2009
@@ -40,7 +40,7 @@
      * Get codec Vector used to create SDP
      * @return
      */
-    public Vector<Attribute> getCodec();
+    public Vector<Attribute> getCodecs();

     public void updateCallView();
     public File getDefaultDataDumpDirectory();
=======================================
--- /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/ann/AnnCall.java Tue Jul 7 06:50:23 2009 +++ /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/ann/AnnCall.java Mon Aug 3 07:46:14 2009
@@ -191,12 +191,7 @@
                                                                cd.toString());
                                                this.connectToPeer(sessionDesc);

-                                               this.receiveRTP = true;
-                                               // for now we do that like that 
this will go away with
-                                               // rtp socket
- super.readerTask = this.readerThread.scheduleAtFixedRate(this, 0, super._READ_PERIOD,
-                                                               
TimeUnit.MILLISECONDS);
-
+
                                                ri = 
provider.getUniqueRequestIdentifier();
NotificationRequest notificationRequest = new NotificationRequest(this,
                                                                
super.endpointIdentifier, ri);
@@ -323,8 +318,10 @@

CreateConnection crcx = new CreateConnection(this, this.callIdentifier, ei, ConnectionMode.SendRecv);
                        // int localPort = 
this.datagramChannel.socket().getLocalPort();
-                       int localPort = 
super.datagramChannel.socket().getLocalPort();
- crcx.setRemoteConnectionDescriptor(new ConnectionDescriptor(super.getLocalDescriptor(localPort)));
+                       int localPort = super.socket.getLocalPort();
+                       String sdp = super.getLocalDescriptor(localPort);
+                       System.err.println(sdp);
+                       crcx.setRemoteConnectionDescriptor(new 
ConnectionDescriptor(sdp));
                        
crcx.setTransactionHandle(this.provider.getUniqueTransactionHandler());

                        super.testCase.addCall(crcx, this);
@@ -357,13 +354,10 @@
                if (ri != null) {
                        super.testCase.removeCall(ri.toString());
                }
-               this.receiveRTP = false;
-
-               if (this.readerTask != null) {
-                       this.readerTask.cancel(true);
-               }
-               if (this.state == CallState.IN_ERROR) {
-
+
+
+ if (this.state == CallState.IN_ERROR || this.state == CallState.TIMED_OUT) {
+                       this.setLocalFlowState(AnnCallState.TERMINATED);
                } else {

                        // FIXME: Should in case of forced stop this indicate 
error?
@@ -403,7 +397,12 @@
                int port = md.getMedia().getMediaPort();

SocketAddress sa = new InetSocketAddress(InetAddress.getAllByName(cAddress)[0], port);
-               super.datagramChannel.connect(sa);
+
+               // for now we do that like that this will go away with
+               // rtp socket
+               super.socket.setPeer(InetAddress.getAllByName(cAddress)[0], 
port);
+
+

        }
 }
=======================================
--- /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/rtp/RtpPacket.java Mon May 11 06:38:14 2009 +++ /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/general/rtp/RtpPacket.java Mon Aug 3 07:46:14 2009
@@ -20,6 +20,7 @@
 import java.io.DataInputStream;
 import java.io.IOException;
 import java.io.Serializable;
+import java.nio.ByteBuffer;
 import java.util.Date;

 /**
@@ -43,6 +44,30 @@

     private Date time;

+    public RtpPacket(ByteBuffer readerBuffer) {
+        int len = readerBuffer.limit();
+        int b = readerBuffer.get() & 0xff;
+
+        version = (b & 0x0C) >> 6;
+        padding = (b & 0x20) == 0x020;
+        extensions = (b & 0x10) == 0x10;
+        cc = b & 0x0F;
+
+        b = readerBuffer.get() & 0xff;
+        marker = (b & 0x80) == 0x80;
+        payloadType = b & 0x7F;
+
+        seqNumber = (readerBuffer.get() & 0xff) << 8;
+        seqNumber = seqNumber | (readerBuffer.get() & 0xff);
+
+        timestamp = readerBuffer.getInt();
+        ssrc = readerBuffer.getInt();
+
+        payload = new byte[len - 12];
+        readerBuffer.get(payload, 0, payload.length);
+    }
+
+
     /** Creates a new instance of RtpPacket */
     public RtpPacket(byte[] data) throws IOException {
DataInputStream in = new DataInputStream(new ByteArrayInputStream(data));
=======================================
--- /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/gui/MainGUIView.java Tue Jul 21 09:36:05 2009 +++ /trunk/servers/media/test-suite/core/src/main/java/org/mobicents/media/server/testsuite/gui/MainGUIView.java Mon Aug 3 07:46:14 2009
@@ -979,7 +979,7 @@
         }
     }

-    public Vector<Attribute> getCodec() {
+    public Vector<Attribute> getCodecs() {
         return attributerMap.get(this.fieldCodecBox.getSelectedItem());
     }

Reply via email to