Adds to new test applications that allow testing ice4j on separate work stations
This commit is contained in:
parent
1060228133
commit
8ce8be2cc8
@ -8,7 +8,6 @@
|
|||||||
package test;
|
package test;
|
||||||
|
|
||||||
import java.beans.*;
|
import java.beans.*;
|
||||||
import java.io.*;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
@ -16,7 +15,9 @@ import org.ice4j.ice.*;
|
|||||||
import org.ice4j.ice.harvest.*;
|
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
|
* @author Emil Ivov
|
||||||
*/
|
*/
|
||||||
@ -27,47 +28,13 @@ public class Ice
|
|||||||
*/
|
*/
|
||||||
static long startTime;
|
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
|
* Runs the test
|
||||||
* @param args command line arguments
|
* @param args command line arguments
|
||||||
*
|
*
|
||||||
* @throws Throwable if bad stuff happens.
|
* @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();
|
startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
@ -130,8 +97,7 @@ public class Ice
|
|||||||
|
|
||||||
System.out.println("Agent entered the " + evt.getNewValue()
|
System.out.println("Agent entered the " + evt.getNewValue()
|
||||||
+ " state.");
|
+ " state.");
|
||||||
if(evt.getNewValue() == IceProcessingState.COMPLETED
|
if(evt.getNewValue() == IceProcessingState.COMPLETED)
|
||||||
|| evt.getNewValue() == IceProcessingState.FAILED)
|
|
||||||
{
|
{
|
||||||
System.out.println("Total ICE processing time: "
|
System.out.println("Total ICE processing time: "
|
||||||
+ (processingEndTime - startTime) + "ms");
|
+ (processingEndTime - startTime) + "ms");
|
||||||
@ -163,7 +129,8 @@ public class Ice
|
|||||||
System.out.println(stream.getCheckList());
|
System.out.println(stream.getCheckList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(evt.getNewValue() == IceProcessingState.TERMINATED)
|
else if(evt.getNewValue() == IceProcessingState.TERMINATED
|
||||||
|
|| evt.getNewValue() == IceProcessingState.FAILED)
|
||||||
{
|
{
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
@ -265,7 +232,7 @@ public class Ice
|
|||||||
*
|
*
|
||||||
* @throws Throwable if anything goes wrong.
|
* @throws Throwable if anything goes wrong.
|
||||||
*/
|
*/
|
||||||
private static Agent createAgent(int rtpPort)
|
protected static Agent createAgent(int rtpPort)
|
||||||
throws Throwable
|
throws Throwable
|
||||||
{
|
{
|
||||||
Agent agent = new Agent();
|
Agent agent = new Agent();
|
||||||
@ -276,11 +243,11 @@ public class Ice
|
|||||||
new TransportAddress("ipv6.sip-communicator.net",
|
new TransportAddress("ipv6.sip-communicator.net",
|
||||||
3478, Transport.UDP));
|
3478, Transport.UDP));
|
||||||
|
|
||||||
agent.addCandidateHarvester(stunHarv);
|
//agent.addCandidateHarvester(stunHarv);
|
||||||
agent.addCandidateHarvester(stun6Harv);
|
//agent.addCandidateHarvester(stun6Harv);
|
||||||
|
|
||||||
createStream(rtpPort, "audio", agent);
|
createStream(rtpPort, "audio", agent);
|
||||||
createStream(rtpPort + 2, "video", agent);
|
//createStream(rtpPort + 2, "video", agent);
|
||||||
|
|
||||||
return agent;
|
return agent;
|
||||||
}
|
}
|
||||||
@ -320,8 +287,8 @@ public class Ice
|
|||||||
+ (endTime - startTime) +" ms");
|
+ (endTime - startTime) +" ms");
|
||||||
startTime = endTime;
|
startTime = endTime;
|
||||||
//rtcpComp
|
//rtcpComp
|
||||||
agent.createComponent(
|
//agent.createComponent(
|
||||||
stream, Transport.UDP, rtpPort + 1, rtpPort + 1, rtpPort + 101);
|
// stream, Transport.UDP, rtpPort + 1, rtpPort + 1, rtpPort + 101);
|
||||||
|
|
||||||
endTime = System.currentTimeMillis();
|
endTime = System.currentTimeMillis();
|
||||||
System.out.println("RTCP Component created in "
|
System.out.println("RTCP Component created in "
|
||||||
@ -330,36 +297,5 @@ public class Ice
|
|||||||
return stream;
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
101
test/test/IceDistributed.java
Normal file
101
test/test/IceDistributed.java
Normal file
@ -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.
|
||||||
|
* <p>
|
||||||
|
* 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
69
test/test/IceLite.java
Normal file
69
test/test/IceLite.java
Normal file
@ -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.
|
||||||
|
* <p>
|
||||||
|
* This sample is easily used in conjunction with our {@link IceDistributed}
|
||||||
|
* sample app.
|
||||||
|
*
|
||||||
|
* @author Emil Ivov
|
||||||
|
*/
|
||||||
|
public class IceLite
|
||||||
|
extends IceDistributed
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The <tt>Logger</tt> used by the <tt>IceLite</tt>
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -18,8 +18,6 @@ import org.ice4j.*;
|
|||||||
import org.ice4j.ice.*;
|
import org.ice4j.ice.*;
|
||||||
import org.ice4j.ice.Agent;
|
import org.ice4j.ice.Agent;
|
||||||
|
|
||||||
import sun.management.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities for manipulating SDP. The utilities This method <b>do not</b> try
|
* Utilities for manipulating SDP. The utilities This method <b>do not</b> try
|
||||||
* to act smart and make a lot of assumptions (e.g. at least one media stream
|
* 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
|
Candidate defaultRtpCandidate
|
||||||
= rtpComponent.findRemoteCandidate(defaultRtpAddress);
|
= rtpComponent.findRemoteCandidate(defaultRtpAddress);
|
||||||
Candidate defaultRtcpCandidate
|
|
||||||
= rtcpComponent.findRemoteCandidate(defaultRtcpAddress);
|
|
||||||
|
|
||||||
rtpComponent.setDefaultRemoteCandidate(defaultRtpCandidate);
|
rtpComponent.setDefaultRemoteCandidate(defaultRtpCandidate);
|
||||||
rtcpComponent.setDefaultRemoteCandidate(defaultRtcpCandidate);
|
|
||||||
|
if(rtcpComponent != null)
|
||||||
|
{
|
||||||
|
Candidate defaultRtcpCandidate
|
||||||
|
= rtcpComponent.findRemoteCandidate(defaultRtcpAddress);
|
||||||
|
rtcpComponent.setDefaultRemoteCandidate(defaultRtcpCandidate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user