Commit 420861b8 authored by J. M. Bailey's avatar J. M. Bailey
Browse files

git init

parents
/test/
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="LiFiBenchmark" default="default" basedir=".">
<description>Builds, tests, and runs the project LiFiBenchmark.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="LiFiBenchmark-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
<target name="make-fat-jar" depends="jar">
<property name="store.jar.name" value="LiFiBenchmarkFat"/>
<property name="store.dir" value="dist"/>
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
<echo message="Packaging ${application.title} into a single JAR at {${store.jar}"/>
<!--<delete dir="${store.dir}"/>
<mkdir dir="${store.dir}"/> -->
<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
<zip destfile="${store.jar}">
<zipfileset src="${store.dir}/temp_final.jar" excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
</zip>
<delete file="${store.dir}/temp_final.jar"/>
<copy todir="dist" overwrite="true">
<fileset dir="runscripts">
</fileset>
</copy>
<chmod dir="dist" perm="u=rwx,go=rx" includes="**/*.sh"/>
</target>
</project>
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
This diff is collapsed.
build.xml.data.CRC32=87f24324
build.xml.script.CRC32=99e7b57b
build.xml.stylesheet.CRC32=8064a381@1.80.1.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=87f24324
nbproject/build-impl.xml.script.CRC32=4b2cf80d
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=LiFiBenchmark
application.vendor=mike
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.test.classpath=\
${run.test.classpath}
# Files in build.classes.dir which should be excluded from distribution jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/LiFiBenchmark.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
file.reference.commons-cli-1.4.jar=libs/commons-cli-1.4.jar
includes=**
jar.compress=true
javac.classpath=\
${file.reference.commons-cli-1.4.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.external.vm=true
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
main.class=edu.nps.moves.lifi.LiFiBenchmark
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>LiFiBenchmark</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>
#!/bin/bash
java -jar LiFiBenchmarkFat.jar -help
#!/bin/bash
java -jar LiFiBenchmarkFat.jar -targetip 172.20.82.180
#!/bin/bash
java -jar LiFiBenchmarkFat.jar -server
/*
* Copyright (c) 1995-2017 held by the author(s). All rights reserved. Redistribution and use
* in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. Neither the names of the Naval Postgraduate School (NPS)
* Modeling Virtual Environments and Simulation (MOVES) Institute (http://www.nps.edu and
* http://www.MovesInstitute.org) nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package edu.nps.moves.lifi;
import java.io.IOException;
import java.net.Inet4Address;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Arrays;
import org.apache.commons.cli.*;
/**
* LiFiBenchmark.java created on May 15, 2018 MOVES Institute Naval Postgraduate School, Monterey, CA, USA www.nps.edu
*
* @author Mike Bailey, jmbailey@nps.edu
* @version $Id$
*/
public class LiFiBenchmark
{
public static String DEFAULT_IP = "127.0.0.1";
public static int DEFAULT_PORT = 8500;
public static int READ_BUFFER_SIZE = 10*1024;
public static int WRITE_BUFFER_SIZE = 5*1024;
public static int READ_LIMIT = 1500000 * 1024;
private String targetIp = DEFAULT_IP;
private int targetPort = DEFAULT_PORT;
private boolean isServer = false;
private CommandLine cline;
private Options opts;
public static void main(String[] args)
{
LiFiBenchmark bm = new LiFiBenchmark(args);
bm.start();
}
public LiFiBenchmark(String[] args)
{
cline = parseCL(args);
if (cline.hasOption("h")) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("hello", opts);
System.exit(0);
}
if (cline.hasOption("targetip"))
targetIp = cline.getOptionValue("targetip", DEFAULT_IP);
if (cline.hasOption("targetport"))
targetPort = Integer.parseInt(cline.getOptionValue("targetport", "" + DEFAULT_PORT));
isServer = cline.hasOption("server");
}
private CommandLine parseCL(String[] args)
{
opts = new Options();
opts.addOption(Option.builder("ip")
.hasArg()
.required(false)
.longOpt("targetip")
.desc("The server address from which to read data, in dot-decimal format")
.build());
opts.addOption(Option.builder("port")
.hasArg()
.required(false)
.longOpt("targetport")
.desc("The server port number to connect to, decimal integer")
.build());
opts.addOption(Option.builder("h")
.hasArg(false)
.required(false)
.longOpt("help")
.desc("Print this message")
.build());
opts.addOption(Option.builder("server")
.hasArg(false)
.required(false)
.desc("Run in server mode, targetip option N/A")
.build());
try {
return new DefaultParser().parse(opts, args);
}
catch (ParseException ex) {
System.out.println("Parsing failed: " + ex.getMessage());
System.exit(1);
return null;
}
}
public void start()
{
if (isServer)
doServer();
else
networkRead();
}
private void networkRead()
{
System.out.println("Enter networkRead() with " + targetIp + " and " + targetPort);
long startms = System.currentTimeMillis();
try {
int readAcc;
try (Socket sock = new Socket(targetIp, targetPort)) {
readAcc = 0;
System.out.println("Reading " + READ_LIMIT);
byte[] buff = new byte[READ_BUFFER_SIZE];
while (true) {
int read = sock.getInputStream().read(buff);
if (read == -1)
break;
readAcc += read;
if (readAcc >= READ_LIMIT)
break;
}
}
long endms = System.currentTimeMillis();
long span = endms-startms;
double spansecs = (double)span / 1000.d;
System.out.println("Read " + readAcc + " bytes in "+span+" msec.");
//System.out.format("Rate: %.2e bytes/msec%n",((double)readAcc/(double)span));
//System.out.format("Rate: %.2e bytes/sec%n",((double)readAcc/spansecs));
double bits = (double)readAcc * 8.d;
//System.out.format("Rate: %.2e bits/sec%n",(bits/spansecs));
System.out.format("Rate: %.2e Mbit/s%n", ((bits/1000000.d)/spansecs));
System.out.format("Rate: %.2f Gbit/s%n", ((bits/1000000000.d)/spansecs));
}
catch (IOException ex) {
System.out.println("Exception "+ex.getClass().getSimpleName()+ " in networkRead(): "+ex.getMessage());
System.exit(-1);
}
}
private void doServer()
{
try {
ServerSocket ssock = new ServerSocket(targetPort);
System.out.println("Serving from "+Inet4Address.getLocalHost().getHostAddress());
System.out.println("Waiting on port "+targetPort);
Socket cliSock;
while ((cliSock = ssock.accept()) != null) {
System.out.println("Connected to " + cliSock.getRemoteSocketAddress());
handleConnection(cliSock);
}
}
catch (IOException ex) {
System.out.println("Exception waiting for connections: "+ex.getMessage());
System.exit(-1);
}
}
private void handleConnection(Socket sock)
{
new Thread(() -> {
byte[] ba = new byte[WRITE_BUFFER_SIZE];
int wrote=0;
byte fill = 0;
try {
while (true) {
Arrays.fill(ba, fill++);
sock.getOutputStream().write(ba);
wrote+=ba.length;
}
}
catch (IOException ex) {
System.out.println("Shutting down: " + ex.getClass().getSimpleName() + ": " + ex.getLocalizedMessage());
System.out.println("Wrote "+wrote);
}
}).start();
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment