From 8ce8be2cc811c09b9617b6760f3cc278acbc903b Mon Sep 17 00:00:00 2001 From: emcho Date: Tue, 18 May 2010 07:24:58 +0000 Subject: [PATCH] Adds to new test applications that allow testing ice4j on separate work stations --- test/test/Ice.java | 90 +++++------------------------- test/test/IceDistributed.java | 101 ++++++++++++++++++++++++++++++++++ test/test/IceLite.java | 69 +++++++++++++++++++++++ test/test/SdpUtils.java | 13 +++-- 4 files changed, 190 insertions(+), 83 deletions(-) create mode 100644 test/test/IceDistributed.java create mode 100644 test/test/IceLite.java diff --git a/test/test/Ice.java b/test/test/Ice.java index 8ebc875..2abe89a 100644 --- a/test/test/Ice.java +++ b/test/test/Ice.java @@ -8,7 +8,6 @@ package test; import java.beans.*; -import java.io.*; import java.util.*; import org.ice4j.*; @@ -16,7 +15,9 @@ import org.ice4j.ice.*; import org.ice4j.ice.harvest.*; /** - * Simple ice4j testing scenarios. + * Simple ice4j testing scenario. The sample application would create and start + * both agents and make one of them and make one of them run checks against the + * other. * * @author Emil Ivov */ @@ -27,47 +28,13 @@ public class Ice */ static long startTime; - /** - * Runs a test application that allocates streams, generates an SDP, dumps - * it on stdout, waits for a remote peer SDP on stdin, then feeds that - * to our local agent and starts ICE processing. - * - * @param args none currently handled - * @throws Throwable every now and then. - */ - public static void main(String[] args) throws Throwable - { - startTime = System.currentTimeMillis(); - - Agent localAgent = createAgent(9090); - localAgent.setNominationStrategy( - NominationStrategy.NOMINATE_HIGHEST_PRIO); - - localAgent.addStateChangeListener(new IceProcessingListener()); - - //let them fight ... fights forge character. - localAgent.setControlling(true); - String localSDP = SdpUtils.createSDPDescription(localAgent); - System.out.println(localSDP); - - String sdp = readSDP(); - - SdpUtils.parseSDP(localAgent, sdp); - - localAgent.startConnectivityEstablishment(); - - //Give processing enough time to finish. We'll System.exit() anyway - //as soon as localAgent enters a final state. - Thread.sleep(60000); - } - /** * Runs the test * @param args command line arguments * * @throws Throwable if bad stuff happens. */ - public static void main2(String[] args) throws Throwable + public static void main(String[] args) throws Throwable { startTime = System.currentTimeMillis(); @@ -130,8 +97,7 @@ public class Ice System.out.println("Agent entered the " + evt.getNewValue() + " state."); - if(evt.getNewValue() == IceProcessingState.COMPLETED - || evt.getNewValue() == IceProcessingState.FAILED) + if(evt.getNewValue() == IceProcessingState.COMPLETED) { System.out.println("Total ICE processing time: " + (processingEndTime - startTime) + "ms"); @@ -163,7 +129,8 @@ public class Ice System.out.println(stream.getCheckList()); } } - else if(evt.getNewValue() == IceProcessingState.TERMINATED) + else if(evt.getNewValue() == IceProcessingState.TERMINATED + || evt.getNewValue() == IceProcessingState.FAILED) { System.exit(0); } @@ -265,7 +232,7 @@ public class Ice * * @throws Throwable if anything goes wrong. */ - private static Agent createAgent(int rtpPort) + protected static Agent createAgent(int rtpPort) throws Throwable { Agent agent = new Agent(); @@ -276,11 +243,11 @@ public class Ice new TransportAddress("ipv6.sip-communicator.net", 3478, Transport.UDP)); - agent.addCandidateHarvester(stunHarv); - agent.addCandidateHarvester(stun6Harv); + //agent.addCandidateHarvester(stunHarv); + //agent.addCandidateHarvester(stun6Harv); createStream(rtpPort, "audio", agent); - createStream(rtpPort + 2, "video", agent); + //createStream(rtpPort + 2, "video", agent); return agent; } @@ -320,8 +287,8 @@ public class Ice + (endTime - startTime) +" ms"); startTime = endTime; //rtcpComp - agent.createComponent( - stream, Transport.UDP, rtpPort + 1, rtpPort + 1, rtpPort + 101); + //agent.createComponent( + // stream, Transport.UDP, rtpPort + 1, rtpPort + 1, rtpPort + 101); endTime = System.currentTimeMillis(); System.out.println("RTCP Component created in " @@ -330,36 +297,5 @@ public class Ice return stream; } - /** - * Reads an SDP description from the standard input. We expect descriptions - * provided to this method to be originating from instances of this - * application running on remote computers. - * - * @return whatever we got on stdin (hopefully an SDP description. - * - * @throws Throwable if something goes wrong with console reading. - */ - private static String readSDP() throws Throwable - { - System.out.println("Paste SDP here. Enter an empty line to proceed:"); - System.out.println("(we don't mind the [java] prefix in SDP intput)"); - BufferedReader reader - = new BufferedReader(new InputStreamReader(System.in)); - StringBuffer buff = new StringBuffer(); - String line = new String(); - - while ( (line = reader.readLine()) != null) - { - line = line.replace("[java]", ""); - line = line.trim(); - if(line.length() == 0) - break; - - buff.append(line); - buff.append("\r\n"); - } - - return buff.toString(); - } } diff --git a/test/test/IceDistributed.java b/test/test/IceDistributed.java new file mode 100644 index 0000000..93f0c1d --- /dev/null +++ b/test/test/IceDistributed.java @@ -0,0 +1,101 @@ +/* + * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal. + * Maintained by the SIP Communicator community (http://sip-communicator.org). + * + * Distributable under LGPL license. See terms of license at gnu.org. + */ +package test; + +import java.io.*; + +import org.ice4j.ice.*; + +/** + * A slightly more complicated ICE use sample. The sample would create an + * agent, make it print its SDP, then wait for a similar SDP to be fed through + * standard input. Once this happens, we make our agent start checks against the + * peer described in the SDP we fed through stdin. + *

+ * This sample is easily used in conjunction with another instance of the same + * sample application or against our {@link IceLite} sample app. + * + * @author Emil Ivov + */ +public class IceDistributed + extends Ice +{ + /** + * Runs a test application that allocates streams, generates an SDP, dumps + * it on stdout, waits for a remote peer SDP on stdin, then feeds that + * to our local agent and starts ICE processing. + * + * @param args none currently handled + * @throws Throwable every now and then. + */ + public static void main(String[] args) throws Throwable + { + startTime = System.currentTimeMillis(); + + Agent localAgent = createAgent(2020); + localAgent.setNominationStrategy( + NominationStrategy.NOMINATE_HIGHEST_PRIO); + + localAgent.addStateChangeListener(new IceProcessingListener()); + + //let them fight ... fights forge character. + localAgent.setControlling(true); + String localSDP = SdpUtils.createSDPDescription(localAgent); + + System.out.println("=================== feed the following" + +" to the remote agent ==================="); + + System.out.println(localSDP); + + System.out.println("======================================" + +"========================================\n"); + + String sdp = readSDP(); + + SdpUtils.parseSDP(localAgent, sdp); + + localAgent.startConnectivityEstablishment(); + + //Give processing enough time to finish. We'll System.exit() anyway + //as soon as localAgent enters a final state. + Thread.sleep(60000); + } + + /** + * Reads an SDP description from the standard input. We expect descriptions + * provided to this method to be originating from instances of this + * application running on remote computers. + * + * @return whatever we got on stdin (hopefully an SDP description. + * + * @throws Throwable if something goes wrong with console reading. + */ + static String readSDP() throws Throwable + { + System.out.println("Paste remote SDP here. Enter an empty " + +"line to proceed:"); + System.out.println("(we don't mind the [java] prefix in SDP intput)"); + BufferedReader reader + = new BufferedReader(new InputStreamReader(System.in)); + + StringBuffer buff = new StringBuffer(); + String line = new String(); + + while ( (line = reader.readLine()) != null) + { + line = line.replace("[java]", ""); + line = line.trim(); + if(line.length() == 0) + break; + + buff.append(line); + buff.append("\r\n"); + } + + return buff.toString(); + } +} diff --git a/test/test/IceLite.java b/test/test/IceLite.java new file mode 100644 index 0000000..932086d --- /dev/null +++ b/test/test/IceLite.java @@ -0,0 +1,69 @@ +/* + * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal. + * Maintained by the SIP Communicator community (http://sip-communicator.org). + * + * Distributable under LGPL license. See terms of license at gnu.org. + */ +package test; + +import java.util.logging.*; + +import org.ice4j.ice.*; + + +/** + * An ICE sample that kind of works like ICE lite. The sample would create an + * agent, make it print its SDP, then wait for a similar SDP to be fed through + * standard input. Once this happens, it would also answer incoming connectivity + * checks without making checks of its own. + *

+ * This sample is easily used in conjunction with our {@link IceDistributed} + * sample app. + * + * @author Emil Ivov + */ +public class IceLite + extends IceDistributed +{ + /** + * The Logger used by the IceLite + * class and its instances for logging output. + */ + private static final Logger logger = Logger.getLogger(IceLite.class + .getName()); + /** + * Runs a test application that allocates streams, generates an SDP, dumps + * it on stdout, waits for a remote peer SDP on stdin, then feeds that + * to our local agent and starts ICE processing. + * + * @param args none currently handled + * @throws Throwable every now and then. + */ + public static void main(String[] args) throws Throwable + { + logger.severe("Start"); + startTime = System.currentTimeMillis(); + + Agent localAgent = createAgent(3030); + localAgent.setControlling(false); + localAgent.setNominationStrategy( + NominationStrategy.NOMINATE_HIGHEST_PRIO); + + localAgent.addStateChangeListener(new IceProcessingListener()); + + String localSDP = SdpUtils.createSDPDescription(localAgent); + + System.out.println("=================== feed the following" + +" to the remote agent ==================="); + + System.out.println(localSDP); + + System.out.println("======================================" + +"========================================\n"); + + //Give processing enough time to finish. We'll System.exit() anyway + //as soon as localAgent enters a final state. + Thread.sleep(60000); + } + +} diff --git a/test/test/SdpUtils.java b/test/test/SdpUtils.java index 0c03a32..17d654c 100644 --- a/test/test/SdpUtils.java +++ b/test/test/SdpUtils.java @@ -18,8 +18,6 @@ import org.ice4j.*; import org.ice4j.ice.*; import org.ice4j.ice.Agent; -import sun.management.*; - /** * Utilities for manipulating SDP. The utilities This method do not try * to act smart and make a lot of assumptions (e.g. at least one media stream @@ -176,11 +174,14 @@ public class SdpUtils Candidate defaultRtpCandidate = rtpComponent.findRemoteCandidate(defaultRtpAddress); - Candidate defaultRtcpCandidate - = rtcpComponent.findRemoteCandidate(defaultRtcpAddress); - rtpComponent.setDefaultRemoteCandidate(defaultRtpCandidate); - rtcpComponent.setDefaultRemoteCandidate(defaultRtcpCandidate); + + if(rtcpComponent != null) + { + Candidate defaultRtcpCandidate + = rtcpComponent.findRemoteCandidate(defaultRtcpAddress); + rtcpComponent.setDefaultRemoteCandidate(defaultRtcpCandidate); + } } }