adds a NAT mapping harvester test case

This commit is contained in:
emcho 2014-02-21 10:52:08 +00:00
parent 55082823dd
commit 3707dbc975
2 changed files with 107 additions and 0 deletions

View File

@ -272,6 +272,18 @@
</java> </java>
</target> </target>
<!-- runs our sample NAT mapping application -->
<target name="run-map">
<java fork="true"
classname="test.MappingTest"
classpathref="test.class.path">
<!-- Tell java.util.logging about our logging preferences -->
<sysproperty key="java.util.logging.config.file"
value="lib/logging.properties"/>
</java>
</target>
<!-- runs our sample aws application --> <!-- runs our sample aws application -->
<target name="run-aws"> <target name="run-aws">
<java fork="true" <java fork="true"

View File

@ -0,0 +1,95 @@
/*
* 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.*;
import java.util.logging.*;
import javax.sdp.*;
import org.ice4j.*;
import org.ice4j.ice.*;
import org.ice4j.ice.harvest.*;
import org.ice4j.ice.sdp.*;
/**
* An example of using the AWS Harvester.
* <p>
* @author Emil Ivov
*/
public class MappingTest
extends Ice
{
/**
* The <tt>Logger</tt> used by the <tt>TrickleIce</tt>
* class and its instances for logging output.
*/
private static final Logger logger
= Logger.getLogger(TrickleIce.class.getName());
/**
* Runs a test application that creates an agent, attaches an AWS harvester
* as well as a few allocates streams, generates an SDP and dumps
* it on stdout
*
* @param args none currently handled
* @throws Throwable every now and then.
*/
public static void main(String[] args) throws Throwable
{
//if configured, append a mapping harvester.
String localAddressStr = "<your local IP here, e.g. 192.168.0.1>";
String publicAddressStr = "<your public IP here, e.g. 203.0.113.5>";
TransportAddress localAddress;
TransportAddress publicAddress;
try
{
localAddress
= new TransportAddress(localAddressStr, 9, Transport.UDP);
publicAddress
= new TransportAddress(publicAddressStr, 9, Transport.UDP);
logger.info("Will append a NAT harvester for " +
localAddress + "=>" + publicAddress);
}
catch(Exception exc)
{
logger.info("Failed to create a NAT harvester for"
+ " local address=" + localAddressStr
+ " and public address=" + publicAddressStr);
return;
}
MappingCandidateHarvester natHarvester
= new MappingCandidateHarvester(publicAddress, localAddress);
List<CandidateHarvester> harvesters
= new ArrayList<CandidateHarvester>();
harvesters.add(natHarvester);
Agent localAgent = createAgent(2020, false, harvesters);
localAgent.setNominationStrategy(
NominationStrategy.NOMINATE_HIGHEST_PRIO);
String localSDP = SdpUtils.createSDPDescription(localAgent);
//wait a bit so that the logger can stop dumping stuff:
Thread.sleep(500);
logger.info("=================== feed the following"
+" to the remote agent ===================");
logger.info("\n" + localSDP);
logger.info("======================================"
+ "========================================\n");
}
}