diff --git a/nfn-scala-experiments/.gitignore b/nfn-scala-experiments/.gitignore new file mode 100644 index 000000000000..8a051ca3f71b --- /dev/null +++ b/nfn-scala-experiments/.gitignore @@ -0,0 +1,52 @@ +.DS_Store +*.class +*.log + +# sbt specific +.cache/ +.history/ +.lib/ +dist/* +target/ +lib_managed/ +src_managed/ +project/boot/ +project/plugins/project/ + +# Scala-IDE specific +.scala_dependencies + +# IntelliJ +.idea/ +*.iml + +# Sublime +*.sublime-project +*.sublime-workspace + +# Vim +*.swp + +# omnet +*.tkenvlog +omnetreplay/.tkenvrc +omnetreplay/Makefile +omnetreplay/contentto_m.cc +omnetreplay/contentto_m.h +omnetreplay/interestto_m.cc +omnetreplay/interestto_m.h +omnetreplay/omnetintegration +omnetreplay/omnetreplay +omnetreplay/out* +omnetreplay/NFNNetwork.ned +omnetreplay/transmittedPackets.json + +*.dSYM/* + +# Scala NFN +*.jno +*.so +*c_xml.txt +failed-messages +service-library +temp-bytecode-content diff --git a/nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/ccnliteinterface_CCNLiteInterface.h b/nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/ccnliteinterface_CCNLiteInterface.h deleted file mode 100644 index ca83816346ac..000000000000 --- a/nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/ccnliteinterface_CCNLiteInterface.h +++ /dev/null @@ -1,45 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include -/* Header for class ccnliteinterface_CCNLiteInterface */ - -#ifndef _Included_ccnliteinterface_CCNLiteInterface -#define _Included_ccnliteinterface_CCNLiteInterface -#ifdef __cplusplus -extern "C" { -#endif -/* - * Class: ccnliteinterface_CCNLiteInterface - * Method: mkBinaryInterest - * Signature: (Ljava/lang/String;)[B - */ -JNIEXPORT jbyteArray JNICALL Java_ccnliteinterface_CCNLiteInterface_mkBinaryInterest - (JNIEnv *, jobject, jstring); - -/* - * Class: ccnliteinterface_CCNLiteInterface - * Method: mkBinaryContent - * Signature: (Ljava/lang/String;[B)[B - */ -JNIEXPORT jbyteArray JNICALL Java_ccnliteinterface_CCNLiteInterface_mkBinaryContent - (JNIEnv *, jobject, jstring, jbyteArray); - -/* - * Class: ccnliteinterface_CCNLiteInterface - * Method: mkAddToCacheInterest - * Signature: (Ljava/lang/String;)[B - */ -JNIEXPORT jbyteArray JNICALL Java_ccnliteinterface_CCNLiteInterface_mkAddToCacheInterest - (JNIEnv *, jobject, jstring); - -/* - * Class: ccnliteinterface_CCNLiteInterface - * Method: ccnbToXml - * Signature: ([B)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_ccnliteinterface_CCNLiteInterface_ccnbToXml - (JNIEnv *, jobject, jbyteArray); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/ccnliteinterface_jni_CCNLiteInterfaceCCNbJni.h b/nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/ccnliteinterface_jni_CCNLiteInterfaceCCNbJni.h new file mode 100644 index 000000000000..95038229bb1f --- /dev/null +++ b/nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/ccnliteinterface_jni_CCNLiteInterfaceCCNbJni.h @@ -0,0 +1,45 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class ccnliteinterface_jni_CCNLiteInterfaceCCNbJni */ + +#ifndef _Included_ccnliteinterface_jni_CCNLiteInterfaceCCNbJni +#define _Included_ccnliteinterface_jni_CCNLiteInterfaceCCNbJni +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: ccnliteinterface_jni_CCNLiteInterfaceCCNbJni + * Method: mkBinaryInterest + * Signature: (Ljava/lang/String;)[B + */ +JNIEXPORT jbyteArray JNICALL Java_ccnliteinterface_jni_CCNLiteInterfaceCCNbJni_mkBinaryInterest + (JNIEnv *, jobject, jstring); + +/* + * Class: ccnliteinterface_jni_CCNLiteInterfaceCCNbJni + * Method: mkBinaryContent + * Signature: (Ljava/lang/String;[B)[B + */ +JNIEXPORT jbyteArray JNICALL Java_ccnliteinterface_jni_CCNLiteInterface_mkBinaryContent + (JNIEnv *, jobject, jstring, jbyteArray); + +/* + * Class: ccnliteinterface_jni_CCNLiteInterfaceCCNbJni + * Method: mkAddToCacheInterest + * Signature: (Ljava/lang/String;)[B + */ +JNIEXPORT jbyteArray JNICALL Java_ccnliteinterface_jni_CCNLiteInterface_mkAddToCacheInterest + (JNIEnv *, jobject, jstring); + +/* + * Class: ccnliteinterface_jni_CCNLiteInterfaceCCNbJni + * Method: ccnbToXml + * Signature: ([B)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_ccnliteinterface_jni_CCNLiteInterfaceCCNbJni_ccnbToXml + (JNIEnv *, jobject, jbyteArray); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/libCCNLiteInterface.c b/nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/libCCNLiteInterfaceCCNbJni.c similarity index 94% rename from nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/libCCNLiteInterface.c rename to nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/libCCNLiteInterfaceCCNbJni.c index f63b526aa4e2..8ce483b123be 100644 --- a/nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/libCCNLiteInterface.c +++ b/nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/libCCNLiteInterfaceCCNbJni.c @@ -3,7 +3,7 @@ #define CCNL_NFN #include -#include "ccnliteinterface_CCNLiteInterface.h" +#include "ccnliteinterface_jni_CCNLiteInterfaceCCNbJni.h" #include "../../../../../../ccnl.h" #include "../../../../../../pkt-ccnb.h" @@ -17,7 +17,7 @@ // #endif JNIEXPORT jstring JNICALL -Java_ccnliteinterface_CCNLiteInterface_ccnbToXml(JNIEnv *env, jobject obj, jbyteArray binaryInterest) +Java_ccnliteinterface_jni_CCNLiteInterfaceCCNbJni_ccnbToXml(JNIEnv *env, jobject obj, jbyteArray binaryInterest) { jbyte* jInterestData = (*env)->GetByteArrayElements(env, binaryInterest, NULL); jsize len = (*env)->GetArrayLength(env, binaryInterest); @@ -94,7 +94,7 @@ Java_ccnliteinterface_CCNLiteInterface_ccnbToXml(JNIEnv *env, jobject obj, jbyte // } JNIEXPORT jbyteArray JNICALL -Java_ccnliteinterface_CCNLiteInterface_mkBinaryContent(JNIEnv *env, +Java_ccnliteinterface_jni_CCNLiteInterfaceCCNbJni_mkBinaryContent(JNIEnv *env, jobject obj, jobjectArray nameComponentStringArray, jbyteArray j_content) @@ -164,7 +164,7 @@ Java_ccnliteinterface_CCNLiteInterface_mkBinaryContent(JNIEnv *env, } JNIEXPORT jbyteArray JNICALL -Java_ccnliteinterface_CCNLiteInterface_mkBinaryInterest(JNIEnv *env, +Java_ccnliteinterface_jni_CCNLiteInterfaceCCNbJni_mkBinaryInterest(JNIEnv *env, jobject obj, jobjectArray nameComponentStringArray) { @@ -223,7 +223,7 @@ Java_ccnliteinterface_CCNLiteInterface_mkBinaryInterest(JNIEnv *env, } JNIEXPORT jbyteArray JNICALL -Java_ccnliteinterface_CCNLiteInterface_mkAddToCacheInterest(JNIEnv *env, +Java_ccnliteinterface_jni_CCNLiteInterfaceCCNbJni_mkAddToCacheInterest(JNIEnv *env, jobject obj, jstring ccnbContentFilename) { diff --git a/nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/libCCNLiteInterface.jnilib b/nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/libCCNLiteInterfaceCCNbJni.jnilib similarity index 88% rename from nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/libCCNLiteInterface.jnilib rename to nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/libCCNLiteInterfaceCCNbJni.jnilib index afb0e9e38510..60acaeb9bb00 100755 Binary files a/nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/libCCNLiteInterface.jnilib and b/nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/libCCNLiteInterfaceCCNbJni.jnilib differ diff --git a/nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/make.sh b/nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/make.sh index 5acce9f48496..81d2814a4963 100755 --- a/nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/make.sh +++ b/nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/make.sh @@ -5,7 +5,7 @@ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. if [ "$(uname)" == "Darwin" ]; then # Do something under Mac OS X platform - gcc -dynamiclib -o libCCNLiteInterface.jnilib ./libCCNLiteInterface.c ./open_memstream.c -lcrypto -I$JAVA_HOME/include -I$JAVA_HOME/include/darwin -framework JavaVM + gcc -dynamiclib -o libCCNLiteInterfaceCCNbJni.jnilib ./libCCNLiteInterfaceCCNbJni.c ./open_memstream.c -lcrypto -I$JAVA_HOME/include -I$JAVA_HOME/include/darwin -framework JavaVM if [ $? -eq 0 ]; then echo "compiled libCCNLiteInterface.jnilib for osx" else @@ -14,7 +14,7 @@ if [ "$(uname)" == "Darwin" ]; then fi elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then # Do something under Linux platform - gcc --std=c99 -fPIC -shared -o libCCNLiteInterface.so ./libCCNLiteInterface.c -lm -lcrypto -I$JAVA_HOME/include -I$JAVA_HOME/include/linux/ + gcc --std=c99 -fPIC -shared -o libCCNLiteInterfaceCCNbJni.so ./libCCNLiteInterfaceCCNbJni.c -lm -lcrypto -I$JAVA_HOME/include -I$JAVA_HOME/include/linux/ if [ $? -eq 0 ]; then echo "compiled libCCNLiteInterface.so for linux" else diff --git a/nfn-scala/ccnliteinterface/src/main/scala/ccnliteinterface/CCNLiteInterface.scala b/nfn-scala/ccnliteinterface/src/main/scala/ccnliteinterface/CCNLiteInterface.scala index 241952829a8e..6e9e49d19f7d 100644 --- a/nfn-scala/ccnliteinterface/src/main/scala/ccnliteinterface/CCNLiteInterface.scala +++ b/nfn-scala/ccnliteinterface/src/main/scala/ccnliteinterface/CCNLiteInterface.scala @@ -1,23 +1,19 @@ package ccnliteinterface +import ccnliteinterface.jni.CCNLiteInterfaceCCNbJni + /** -* To call these functions the natively compiled library must exist and added to the classpath. -* Call ./make.sh in the folder ./ccnliteinterface/src/main/c/ccn-lite-bridge (currently only works for OSX) -* and then add: -* -Djava.library.path=./ccnliteinterface/src/main/c/ccn-lite-bridge -* when executing the final code. -* -* These functions are somewhat fragile and might result in a JVM crash. Check stderr for "..." messages. -*/ -class CCNLiteInterface { - System.loadLibrary("CCNLiteInterface") + * Abstracts the packet wire format and the ccn-lite mangement commands to a common interface. + * Implementation can either use the native ccn-lite library or the cli tools. + */ +trait CCNLiteInterface { /** * Native call to create a binary interest for name components * @param nameCmps Each element of this array is a seperate component for the interest name * @return Binary data of interest in ccnb format */ - @native def mkBinaryInterest(nameCmps: Array[String]): Array[Byte] + def mkBinaryInterest(nameCmps: Array[String]): Array[Byte] /** * Native call to create a binary content object for name compoents and given data @@ -25,12 +21,12 @@ class CCNLiteInterface { * @param data Binary data of the content object * @return Binary data of the content in ccnb format */ - @native def mkBinaryContent(name: Array[String], data: Array[Byte]): Array[Byte] + def mkBinaryContent(name: Array[String], data: Array[Byte]): Array[Byte] /** - * Creates an xml representation for ccnb formated data. + * Creates an xml representation for interest and content object. * attribute dt for the data element represents the encoding of the data. Currently "string" or "base64" is supported. - * String is fragile because it can contain unescaped characters. + * String is fragile and should only be used for debugging because it can contain unescaped xml-characters. * * Interest(["cmp1", "cmp2"]: * @@ -94,7 +90,7 @@ class CCNLiteInterface { * @param binaryPacket Data in ccnb format * @return A string containing the xml representation of the ccnb data */ - @native def ccnbToXml(binaryPacket: Array[Byte]): String + def ccnbToXml(binaryPacket: Array[Byte]): String /** * Creates an ccnb format interest to add a content object to the localAbstractMachine ccn cache. @@ -102,17 +98,16 @@ class CCNLiteInterface { * @param ccnbAbsoluteFilename Filename of the file containing the content object formated in ccnb * @return Binary data of the interest in ccnb format */ - @native def mkAddToCacheInterest(ccnbAbsoluteFilename: String): Array[Byte] - + def mkAddToCacheInterest(ccnbAbsoluteFilename: String): Array[Byte] } object CCNLiteInterface { - private val ccnIf = new CCNLiteInterface() + private val ccnIf = new CCNLiteInterfaceCCNbJni() def main(args: Array[String]) = { - val ccnIf = new CCNLiteInterface() + val ccnIf = new CCNLiteInterfaceCCNbJni() val ccnbInterest: Array[Byte] = ccnIf.mkBinaryInterest(Array("/contentname/interest", "NFN")) val xmlInterest:String = ccnIf.ccnbToXml(ccnbInterest) diff --git a/nfn-scala/ccnliteinterface/src/main/scala/ccnliteinterface/jni/CCNLiteInterfaceCCNbJni.scala b/nfn-scala/ccnliteinterface/src/main/scala/ccnliteinterface/jni/CCNLiteInterfaceCCNbJni.scala new file mode 100644 index 000000000000..9e0ae4fde74b --- /dev/null +++ b/nfn-scala/ccnliteinterface/src/main/scala/ccnliteinterface/jni/CCNLiteInterfaceCCNbJni.scala @@ -0,0 +1,104 @@ +package ccnliteinterface.jni + +import ccnliteinterface.CCNLiteInterface + +/** + * Created by basil on 03/09/14. + */ +class CCNLiteInterfaceCCNbJni extends CCNLiteInterface { + System.loadLibrary("CCNLiteInterfaceCCNbJni") + + /** + * Native call to create a binary interest for name components + * @param nameCmps Each element of this array is a seperate component for the interest name + * @return Binary data of interest in ccnb format + */ + @native def mkBinaryInterest(nameCmps: Array[String]): Array[Byte] + + /** + * Native call to create a binary content object for name compoents and given data + * @param name Each elemet of this array is a separate component for the content name + * @param data Binary data of the content object + * @return Binary data of the content in ccnb format + */ + @native def mkBinaryContent(name: Array[String], data: Array[Byte]): Array[Byte] + + /** + * Creates an xml representation for ccnb formated data. + * attribute dt for the data element represents the encoding of the data. Currently "string" or "base64" is supported. + * String is fragile because it can contain unescaped characters. + * + * Interest(["cmp1", "cmp2"]: + * + * + * + * + * cmp1 + * + * + * + * + * cmp2 + * + * + * + * + * + * + * + * + * + * + * '%0d0S + * + * + * + * + * Content(["cmp1", "cmp2"], "content"): + * + * + * + * + * "cmp1" + * + * + * + * + * "cmp2" + * + * + * + * + * + * S0%0d'%07/ + * + * + * + * + * + + * + * + * + * + * + * content + * + * + * + * + * @param binaryPacket Data in ccnb format + * @return A string containing the xml representation of the ccnb data + */ + @native def ccnbToXml(binaryPacket: Array[Byte]): String + + /** + * Creates an ccnb format interest to add a content object to the localAbstractMachine ccn cache. + * The content object itself must formated in ccnb and stored in a file. + * @param ccnbAbsoluteFilename Filename of the file containing the content object formated in ccnb + * @return Binary data of the interest in ccnb format + */ + @native def mkAddToCacheInterest(ccnbAbsoluteFilename: String): Array[Byte] + + +} diff --git a/nfn-scala/lambdacalc/src/main/resources/logback.xml b/nfn-scala/lambdacalc/src/main/resources/logback.xml deleted file mode 100644 index 01c0ea98bb5f..000000000000 --- a/nfn-scala/lambdacalc/src/main/resources/logback.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/nfn-scala/lambdacalc/src/main/scala/lambdacalculus/REPL.scala b/nfn-scala/lambdacalc/src/main/scala/lambdacalculus/REPL.scala index 020a66f20e8a..fc2cb6dd69a0 100644 --- a/nfn-scala/lambdacalc/src/main/scala/lambdacalculus/REPL.scala +++ b/nfn-scala/lambdacalc/src/main/scala/lambdacalculus/REPL.scala @@ -40,7 +40,6 @@ object REPL { def main(args: Array[String]) { -// val console = new ConsoleReader() if(args.size == 1) { REPLState.lambdaCalculus.substituteParseCompileExecute(args(0)) match { case Success(res) => println(res) @@ -75,8 +74,6 @@ object REPL { case "cbn" => REPLState.execOrder(ExecutionOrder.CallByName) case "cbv" => REPLState.execOrder(ExecutionOrder.CallByValue) } -// case Array("intermediate" | "im") => Rep -// case Array("notintermediate" | "nim") => ar case Array("help" | "h") => println( @@ -91,19 +88,12 @@ object REPL { } -// def handleDef(input: String) = -// parseInput(parser.definitions, input) { defs => -// println("Defined: " + defs.keys.mkString(", ")) -// bind = new Binder(bind.defs ++ defs)} - def handleExpr(input: String, stepByStep: Boolean = false) = { val lambdaCalculus = REPLState.lambdaCalculus -// try { lambdaCalculus.substituteParseCompileExecute(input) match { case Success(resultStack: List[Value]) => { - // TODO: enable print intermediate - // if(lambdaCalculus.machine.storeIntermediateSteps) machine.printIntermediateSteps() + // if(lambdaCalculus.machine.storeIntermediateSteps) machine.printIntermediateSteps() println(s"resultstack: $resultStack") val strResult: List[String] = resultStack.map(ValuePrettyPrinter(_, Some(lambdaCalculus.compiler))) println(consolePrefix(resultPrefix) + strResult.mkString(",")) //resultStack.map(ValuePrettyPrinter(_, Some(lambdaCalculus.compiler))).mkString(",")) @@ -112,36 +102,8 @@ object REPL { System.err.println(errorPrefix + error) } } - -// } catch { -// // TODO catch all exception during runtine in repl, print error + help message -// case e @ (_: Throwable) => System.err.println("!!!" + e) -// } } - -// def parseCompileExecute(code: String): Option[List[Value]] = { -// parse(code) match { -// case Some(parsed) => compile(parsed) match { -// case Some(compiled) => execute(compiled) -// case None => None -// } -// case None => None -// } -// } - -// def parse(code: String):Option[Expr] = { -// import parser.{ Success, NoSuccess } -// parser.parse(code) match { -// case Success(res: Expr, _) => Some(res) -// case NoSuccess(err, _) => println(err); None -// } -// } -// -// def compile(code: Expr): Option[List[CBVInstruction]] = Some(compiler(code)) -// -// def execute(code: List[CBVInstruction]): Option[List[Value]] = Some(machine(code)) - def inputPrefix = ">" def resultPrefix = "=" def errorPrefix = "!" diff --git a/nfn-scala/lambdacalc/src/main/scala/lambdacalculus/compiler/Binder.scala b/nfn-scala/lambdacalc/src/main/scala/lambdacalculus/compiler/Binder.scala index 7c6fd1363b4a..8cb78edd77f5 100644 --- a/nfn-scala/lambdacalc/src/main/scala/lambdacalculus/compiler/Binder.scala +++ b/nfn-scala/lambdacalc/src/main/scala/lambdacalculus/compiler/Binder.scala @@ -1,10 +1,8 @@ package lambdacalculus.compiler import lambdacalculus.parser.ast._ -import lambdacalculus.machine.CommandInstruction object Binder { -// def applyWithCommands(ast: Expr, cmds: List[CommandInstruction]): Expr = bind(ast, List(cmds.map(_.name).reverse)) def apply(ast: Expr): Expr = bind(ast, List()) @@ -14,11 +12,7 @@ object Binder { case Clos(name, body) => { val (head, tail) = if(scope.isEmpty) (Nil, Nil) else (scope.head, scope.tail) - body match { - case _ => Clos(name, bind(body, (name :: head) :: tail)) - // TODO is this needed? -// case _ => Clos(name, bind(body, List(name) :: scope)) - } + Clos(name, bind(body, (name :: head) :: tail)) } case v @ Variable(name, _) => { val accessValue = scope.flatten.view.takeWhile(n => n != name).size diff --git a/nfn-scala/lambdacalc/src/main/scala/lambdacalculus/machine/AbstractMachine.scala b/nfn-scala/lambdacalc/src/main/scala/lambdacalculus/machine/AbstractMachine.scala index 7a83fad0b0ac..8ccab57f23d9 100644 --- a/nfn-scala/lambdacalc/src/main/scala/lambdacalculus/machine/AbstractMachine.scala +++ b/nfn-scala/lambdacalc/src/main/scala/lambdacalculus/machine/AbstractMachine.scala @@ -24,12 +24,6 @@ abstract class AbstractMachine(val storeIntermediateSteps:Boolean = false) exten var _intermediateConfigurations: List[AbstractConfiguration] = List() -// def applyWithCommands(code:List[Instruction], cmds: List[CommandInstruction]):List[Value] = { -// info(s"Executing: $code (lib: $cmds") -// val cmdsCode = cmds.map(cmdsInstr => cmdsInstr.instructions).flatten -// result(step(startCfg(cmdsCode ++ code))) -// } - def apply(code:List[Instruction]):List[Value] = { logger.info(s"Executing code: $code") result(step(startCfg(code))) diff --git a/nfn-scala/lambdacalc/src/main/scala/lambdacalculus/machine/CommandLibrary.scala b/nfn-scala/lambdacalc/src/main/scala/lambdacalculus/machine/CommandLibrary.scala index ca184681adea..55208cec18f2 100644 --- a/nfn-scala/lambdacalc/src/main/scala/lambdacalculus/machine/CommandLibrary.scala +++ b/nfn-scala/lambdacalc/src/main/scala/lambdacalculus/machine/CommandLibrary.scala @@ -8,18 +8,6 @@ case class CommandInstruction(name: String, instructions: List[Instruction]) case class CommandLibrary(compiler: Compiler) { -// private val parsedLib:List[Let] = { -// val parser = new StandardLambdaParser() -// parser.definitions(lib) match { -// case parser.Success(defs:List[Let], _) => defs -// case parser.NoSuccess(msg, input) => throw new Exception("Error parsing command library: " + msg) -// } -// } -// private val compiledLib:List[CommandInstruction] = { -// parsedLib map { let => CommandInstruction(let.name, compiler.compile(let)) } -// } -// def commands = compiledLib - def apply(code: String): String = substitudeCommands(code) diff --git a/nfn-scala/lambdacalc/src/main/scala/lambdacalculus/machine/Instruction.scala b/nfn-scala/lambdacalc/src/main/scala/lambdacalculus/machine/Instruction.scala index 91b31fcbf66e..888b6e87c6eb 100644 --- a/nfn-scala/lambdacalc/src/main/scala/lambdacalculus/machine/Instruction.scala +++ b/nfn-scala/lambdacalc/src/main/scala/lambdacalculus/machine/Instruction.scala @@ -6,7 +6,6 @@ import lambdacalculus.parser.ast.UnaryOp trait Instruction extends Tokens { -// override def toString = stringRepr def stringRepr: String } @@ -14,10 +13,6 @@ case class LET(defName: String, clos: List[Instruction]) extends Instruction { def stringRepr: String = s"LET(${clos.mkString(",")}" } -//case class ENDLET() extends Instruction { -// def stringRepr: String = "ENDLET" -//} - case class IF(test: List[Instruction]) extends Instruction { def stringRepr: String = s"IF(${test.mkString(", ")}" } @@ -65,19 +60,3 @@ case class CALL(name: String, nArgs: Int) extends Instruction { override def stringRepr: String = s"CALL($name: $nArgs)" } -//sealed abstract class UnaryOp(name: String) { -// override def toString = name -// -// def apply(v: Value):Value = ??? -//} - -//case class ATOM() extends UnaryOp("ATOM") - -//case class NULL() extends UnaryOp("NULL") - -//// head -//case class CAR() extends UnaryOp("CAR") -// -//// tail -//case class CDR() extends UnaryOp("CDR") - diff --git a/nfn-scala/lambdacalc/src/test/resources/logback-test.xml b/nfn-scala/lambdacalc/src/test/resources/logback-test.xml deleted file mode 100644 index 450b059066cf..000000000000 --- a/nfn-scala/lambdacalc/src/test/resources/logback-test.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/nfn-scala/src/main/scala/evaluation/PaperExperiment.scala b/nfn-scala/nfn-scala-experiments/src/main/scala/evaluation/PaperExperiment.scala similarity index 100% rename from nfn-scala/src/main/scala/evaluation/PaperExperiment.scala rename to nfn-scala/nfn-scala-experiments/src/main/scala/evaluation/PaperExperiment.scala diff --git a/nfn-scala/src/main/scala/evaluation/SingeLocalAMNode.scala b/nfn-scala/nfn-scala-experiments/src/main/scala/evaluation/SingeLocalAMNode.scala similarity index 100% rename from nfn-scala/src/main/scala/evaluation/SingeLocalAMNode.scala rename to nfn-scala/nfn-scala-experiments/src/main/scala/evaluation/SingeLocalAMNode.scala diff --git a/nfn-scala/src/main/scala/evaluation/usecase/LambdaExpressionTester.scala b/nfn-scala/nfn-scala-experiments/src/main/scala/evaluation/usecase/LambdaExpressionTester.scala similarity index 100% rename from nfn-scala/src/main/scala/evaluation/usecase/LambdaExpressionTester.scala rename to nfn-scala/nfn-scala-experiments/src/main/scala/evaluation/usecase/LambdaExpressionTester.scala diff --git a/nfn-scala/src/main/scala/evaluation/usecase/cdn/CDN.scala b/nfn-scala/nfn-scala-experiments/src/main/scala/evaluation/usecase/cdn/CDN.scala similarity index 100% rename from nfn-scala/src/main/scala/evaluation/usecase/cdn/CDN.scala rename to nfn-scala/nfn-scala-experiments/src/main/scala/evaluation/usecase/cdn/CDN.scala diff --git a/nfn-scala/project/Build.scala b/nfn-scala/project/Build.scala index 1847ef9d6bd2..93fb5b27ec40 100644 --- a/nfn-scala/project/Build.scala +++ b/nfn-scala/project/Build.scala @@ -3,10 +3,12 @@ import java.io._ import sbt.File import sbt._ import Keys._ +import sbtassembly.Plugin.AssemblyKeys._ +import sbtassembly.Plugin.assemblySettings object BuildSettings { val paradiseVersion = "2.0.0-M3" - val buildSettings = Defaults.defaultSettings ++ Seq ( + val buildSettings = Defaults.defaultSettings ++ assemblySettings ++ Seq ( version := "0.1-SNAPSHOT", scalaVersion := "2.10.3", scalacOptions ++= Seq("-unchecked", "-deprecation", "-encoding", "UTF-8"), @@ -14,12 +16,9 @@ object BuildSettings { resolvers += Resolver.sonatypeRepo("releases"), resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/", addCompilerPlugin("org.scalamacros" % "paradise" % paradiseVersion cross CrossVersion.full), - MainBuild.compileJNI + MainBuild.compileJNI, + test in assembly := {} ) - - // important to use ~= so that any other initializations aren't dropped - // the _ discards the meaningless () value previously assigned to 'initialize' - } object MainBuild extends Build { @@ -73,6 +72,11 @@ object MainBuild extends Build { ) ).dependsOn(lambdaCalculus) + lazy val nfnScalaExperiments: Project = Project( + "nfn-scala-experiments", + file("nfn-scala-experiments"), + settings = buildSettings + ).dependsOn(nfn) lazy val testservice: Project = Project( "testservice", diff --git a/nfn-scala/project/assembly.sbt b/nfn-scala/project/assembly.sbt new file mode 100644 index 000000000000..fa67f4a087b0 --- /dev/null +++ b/nfn-scala/project/assembly.sbt @@ -0,0 +1 @@ +addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2") \ No newline at end of file diff --git a/nfn-scala/src/main/resources/logback.xml b/nfn-scala/src/main/resources/logback.xml index 079043d52e50..c172941bba20 100644 --- a/nfn-scala/src/main/resources/logback.xml +++ b/nfn-scala/src/main/resources/logback.xml @@ -3,7 +3,7 @@ - [%-5level][%d{dd/mm/YYYY HH:mm:ss.SSS}] [%thread] [%logger{36}] %n + [%-5level][%d{dd/mm/YYYY HH:mm:ss.SSS}] [%thread] [%logger{36}] %msg%n diff --git a/nfn-scala/src/main/resources/reference.conf b/nfn-scala/src/main/resources/reference.conf index bdf36f08e2b6..c3deb144f669 100644 --- a/nfn-scala/src/main/resources/reference.conf +++ b/nfn-scala/src/main/resources/reference.conf @@ -6,4 +6,8 @@ nfn-scala { debuglevel = "DEBUG" defaulttimeoutmillis = 5000 + + packetformat = "ccnb" + + ccnlitelibrarytype = "jni" } \ No newline at end of file diff --git a/nfn-scala/src/main/scala/ccn/CCNLiteProcess.scala b/nfn-scala/src/main/scala/ccn/CCNLiteProcess.scala index 103a2b2b022f..aefd1a7c8e87 100644 --- a/nfn-scala/src/main/scala/ccn/CCNLiteProcess.scala +++ b/nfn-scala/src/main/scala/ccn/CCNLiteProcess.scala @@ -53,7 +53,8 @@ case class CCNLiteProcess(nodeConfig: RouterConfig) extends Logging { case class NetworkFace(toHost: String, toPort: Int) { private val cmdUDPFace = s"../util/ccn-lite-ctrl -x $sockName newUDPface any $toHost $toPort" - println(s"CCNLiteProcess-$prefix: executing '$cmdUDPFace") + logger.debug(s"CCNLiteProcess-$prefix: executing '$cmdUDPFace") + Runtime.getRuntime.exec(cmdUDPFace.split(" ")) udpFaces += (toHost -> toPort) -> this @@ -62,7 +63,7 @@ case class CCNLiteProcess(nodeConfig: RouterConfig) extends Logging { def registerPrefix(prefixToRegister: String) = { val cmdPrefixReg = s"../util/ccn-lite-ctrl -x $sockName prefixreg $prefixToRegister $networkFaceId" -// println(s"CCNLiteProcess-$prefix: executing '$cmdPrefixReg") + logger.debug(s"CCNLiteProcess-$prefix: executing '$cmdPrefixReg") Runtime.getRuntime.exec(cmdPrefixReg.split(" ")) globalFaceId += 1 } @@ -82,13 +83,10 @@ case class CCNLiteProcess(nodeConfig: RouterConfig) extends Logging { val processName = if(nodeConfig.isCCNOnly) "CCNLiteNFNProcess" else "CCNLiteProcess" def start() = { -// if(port != 10050) { - - val ccnliteExecutableName = if(nodeConfig.isCCNOnly) "../ccn-lite-relay" else "../ccn-nfn-relay" val ccnliteExecutable = ccnliteExecutableName + (if(StaticConfig.isNackEnabled) "-nack" else "") val cmd = s"$ccnliteExecutable -v 99 -u $port -x $sockName" - println(s"$processName-$prefix: executing: '$cmd'") + logger.debug(s"$processName-$prefix: executing: '$cmd'") val processBuilder = new ProcessBuilder(cmd.split(" "): _*) processBuilder.redirectErrorStream(true) process = processBuilder.start @@ -97,13 +95,10 @@ case class CCNLiteProcess(nodeConfig: RouterConfig) extends Logging { val thread = new Thread(lsr, s"LogStreamReader-$prefix") thread.start() -// getOrCreateNetworkFace(host, port) -// } globalFaceId = 2 } def stop() = { -// println(s"$processName-$prefix: stop") if (process != null) { process.destroy() } diff --git a/nfn-scala/src/main/scala/ccn/ccnlite/CCNLite.scala b/nfn-scala/src/main/scala/ccn/ccnlite/CCNLiteInterfaceWrapper.scala similarity index 60% rename from nfn-scala/src/main/scala/ccn/ccnlite/CCNLite.scala rename to nfn-scala/src/main/scala/ccn/ccnlite/CCNLiteInterfaceWrapper.scala index d07754c17861..228650a98ec7 100644 --- a/nfn-scala/src/main/scala/ccn/ccnlite/CCNLite.scala +++ b/nfn-scala/src/main/scala/ccn/ccnlite/CCNLiteInterfaceWrapper.scala @@ -1,18 +1,61 @@ package ccn.ccnlite import ccn.NFNCCNLiteParser -import ccnliteinterface.CCNLiteInterface import ccn.packet._ import java.io.{FileReader, FileOutputStream, File} +import ccnliteinterface.CCNLiteInterface +import ccnliteinterface.jni.CCNLiteInterfaceCCNbJni import com.typesafe.scalalogging.slf4j.Logging import myutil.IOHelper +object CCNLiteWireFormat { + def fromName(possibleFormatName: String): Option[CCNLiteWireFormat] = { + possibleFormatName match { + case "ccnb" => Some(CCNbWireFormat()) + case "ndn" => Some(NDNWireFormat()) + case _ => None + } + } +} +trait CCNLiteWireFormat +case class CCNbWireFormat() extends CCNLiteWireFormat +case class NDNWireFormat() extends CCNLiteWireFormat + + + +object CCNLiteInterfaceType { + def fromName(possibleName: String): Option[CCNLiteInterfaceType] = { + possibleName match { + case "jni" => Some(CCNLiteJniInterface()) + case "cli" => Some(CCNLiteCliInterface()) + case _ => None + } + } +} +trait CCNLiteInterfaceType +case class CCNLiteJniInterface() extends CCNLiteInterfaceType +case class CCNLiteCliInterface() extends CCNLiteInterfaceType + +object CCNLiteInterfaceWrapper{ + + case class CCNLiteInterfaceException(msg: String) extends Exception + + def createCCNLiteInterface (wireFormat: CCNLiteWireFormat, ccnLiteInterfaceType: CCNLiteInterfaceType) : CCNLiteInterfaceWrapper = { + + val ccnLiteIf = + (wireFormat, ccnLiteInterfaceType) match { + case (CCNbWireFormat(), CCNLiteJniInterface()) => new CCNLiteInterfaceCCNbJni() + case _ => throw new CCNLiteInterfaceException(s"Currently only CCNb wire format and JNI interface is implemented and not $wireFormat with $ccnLiteInterfaceType") + } + CCNLiteInterfaceWrapper(ccnLiteIf) + } +} + /** * Wrapper for the [[CCNLiteInterface]] */ -object CCNLite extends Logging { - val ccnIf = new CCNLiteInterface() +case class CCNLiteInterfaceWrapper(ccnIf: CCNLiteInterface) extends Logging { def ccnbToXml(ccnbData: Array[Byte]): String = { // This synchronized is required because currently ccnbToXml writes to the local file c_xml.txt @@ -82,7 +125,7 @@ object CCNLite extends Logging { } def base64CCNBToPacket(base64ccnb: String): Option[CCNPacket] = { - val xml = CCNLite.ccnbToXml(NFNCCNLiteParser.decodeBase64(base64ccnb)) + val xml = ccnIf.ccnbToXml(NFNCCNLiteParser.decodeBase64(base64ccnb)) val pkt = NFNCCNLiteParser.parseCCNPacket(xml) pkt } @@ -90,4 +133,7 @@ object CCNLite extends Logging { private def mkAddToCacheInterest(ccnbAbsoluteFilename: String): Array[Byte] = { ccnIf.mkAddToCacheInterest(ccnbAbsoluteFilename) } + def byteStringToPacket(byteArr: Array[Byte]): Option[Packet] = { + NFNCCNLiteParser.parseCCNPacket(ccnbToXml(byteArr)) + } } diff --git a/nfn-scala/src/main/scala/monitor/OmnetIntegration.scala b/nfn-scala/src/main/scala/monitor/OmnetIntegration.scala index 3298ef2ce36b..63020e159431 100644 --- a/nfn-scala/src/main/scala/monitor/OmnetIntegration.scala +++ b/nfn-scala/src/main/scala/monitor/OmnetIntegration.scala @@ -62,6 +62,7 @@ case class OmnetIntegration(nodes: Set[NodeLog], import IOHelper.printToFile val nedContent = createNed() + val nedFilename = "./omnetreplay/NFNNetwork.ned" printToFile(new File(nedFilename), nedContent) diff --git a/nfn-scala/src/main/scala/monitor/TestApp.scala b/nfn-scala/src/main/scala/monitor/TestApp.scala index c69641530680..022e72bdb0f9 100644 --- a/nfn-scala/src/main/scala/monitor/TestApp.scala +++ b/nfn-scala/src/main/scala/monitor/TestApp.scala @@ -4,7 +4,7 @@ import ccn.NFNCCNLiteParser import nfn.NodeConfig import monitor.Monitor.{ContentInfoLog, InterestInfoLog, PacketLog, NodeLog} import ccn.packet.Interest -import ccn.ccnlite.CCNLite +import ccn.ccnlite.CCNLiteInterfaceWrapper import ccnliteinterface.CCNLiteInterface /** diff --git a/nfn-scala/src/main/scala/nfn/ComputeWorker.scala b/nfn-scala/src/main/scala/nfn/ComputeWorker.scala index 8d861827f075..4711570c278a 100644 --- a/nfn-scala/src/main/scala/nfn/ComputeWorker.scala +++ b/nfn-scala/src/main/scala/nfn/ComputeWorker.scala @@ -3,7 +3,7 @@ package nfn import akka.actor.{Actor, ActorRef} import akka.event.Logging import akka.util.Timeout -import ccn.ccnlite.CCNLite +import ccn.ccnlite.CCNLiteInterfaceWrapper import ccn.packet.{CCNName, Interest, Content} import scala.concurrent.Future import scala.concurrent.ExecutionContext.Implicits.global @@ -23,7 +23,7 @@ object ComputeWorker { case class ComputeWorker(ccnServer: ActorRef) extends Actor { val logger = Logging(context.system, this) - val ccnIf = CCNLite + val ccnIf = CCNLiteInterfaceWrapper var maybeFutCallable: Option[Future[CallableNFNService]] = None diff --git a/nfn-scala/src/main/scala/nfn/NFNServer.scala b/nfn-scala/src/main/scala/nfn/NFNServer.scala index 1648d05311c0..335d3dbbbe1b 100644 --- a/nfn-scala/src/main/scala/nfn/NFNServer.scala +++ b/nfn-scala/src/main/scala/nfn/NFNServer.scala @@ -5,11 +5,14 @@ import java.net.InetSocketAddress import akka.actor._ import akka.event.Logging +import akka.event.Logging import akka.pattern._ import akka.util.Timeout import ccn._ -import ccn.ccnlite.CCNLite +import ccn.ccnlite.CCNLiteInterfaceWrapper import ccn.packet._ +import ccnliteinterface.CCNLiteInterface +import com.typesafe.scalalogging.slf4j.Logging import config.AkkaConfig import monitor.Monitor import monitor.Monitor.PacketLogWithoutConfigs @@ -24,9 +27,6 @@ import scala.concurrent.duration._ object NFNServer { - def byteStringToPacket(byteArr: Array[Byte]): Option[Packet] = { - NFNCCNLiteParser.parseCCNPacket(CCNLite.ccnbToXml(byteArr)) - } case class ComputeResult(content: Content) @@ -44,16 +44,24 @@ object NFNApi { } -object NFNServerFactory { - def nfnServer(context: ActorRefFactory, nfnNodeConfig: RouterConfig, computeNodeConfig: ComputeNodeConfig) = { - context.actorOf(networkProps(nfnNodeConfig, computeNodeConfig), name = "NFNServer") +object NFNServerFactory extends Logging { + def nfnServer(context: ActorRefFactory, nfnRouterConfig: RouterConfig, computeNodeConfig: ComputeNodeConfig) = { + + val wireFormat = StaticConfig.packetformat + val ccnLiteIfType = StaticConfig.ccnlitelibrarytype + + val ccnLiteIf = CCNLiteInterfaceWrapper.createCCNLiteInterface(wireFormat, ccnLiteIfType) + + context.actorOf(networkProps(nfnRouterConfig, computeNodeConfig, ccnLiteIf), name = "NFNServer") } - def networkProps(nfnNodeConfig: RouterConfig, computeNodeConfig: ComputeNodeConfig) = Props(classOf[NFNServer], nfnNodeConfig, computeNodeConfig) + def networkProps(nfnNodeConfig: RouterConfig, computeNodeConfig: ComputeNodeConfig, ccnIf: CCNLiteInterfaceWrapper) = + Props(classOf[NFNServer], nfnNodeConfig, computeNodeConfig, ccnIf) } class UDPConnectionContentInterest(local:InetSocketAddress, - target:InetSocketAddress) extends UDPConnection(local, Some(target)) { + target:InetSocketAddress, + ccnLite: CCNLiteInterfaceWrapper) extends UDPConnection(local, Some(target)) { def logPacket(packet: CCNPacket) = { val ccnPacketLog = packet match { @@ -67,13 +75,13 @@ class UDPConnectionContentInterest(local:InetSocketAddress, def handlePacket(packet: CCNPacket, senderCopy: ActorRef) = packet match { case i: Interest => - val binaryInterest = CCNLite.mkBinaryInterest(i) + val binaryInterest = ccnLite.mkBinaryInterest(i) self.tell(UDPConnection.Send(binaryInterest), senderCopy) case c: Content => - val binaryContent = CCNLite.mkBinaryContent(c) + val binaryContent = ccnLite.mkBinaryContent(c) self.tell(UDPConnection.Send(binaryContent), senderCopy) case n: NAck => - val binaryContent = CCNLite.mkBinaryContent(Content(n.name, n.content.getBytes)) + val binaryContent = ccnLite.mkBinaryContent(Content(n.name, n.content.getBytes)) self.tell(UDPConnection.Send(binaryContent), senderCopy) } @@ -102,14 +110,15 @@ class UDPConnectionContentInterest(local:InetSocketAddress, * - the [[ComputeServer]] or [[ComputeWorker]]can make use of the pit * - any interest with the help of the akka "ask" pattern * All connection, interest and content request are logged to the [[Monitor]]. - * A NFNServer also maintains a socket which is connected to the actual CCNNetwork, usually an CCNLite instance encapsulated in a [[CCNLiteProcess]]. + * A NFNServer also maintains a socket which is connected to the actual CCNNetwork, usually an CCNLiteInterfaceWrapper instance encapsulated in a [[CCNLiteProcess]]. */ //case class NFNServer(maybeNFNNodeConfig: Option[RouterConfig], maybeComputeNodeConfig: Option[ComputeNodeConfig]) extends Actor { -case class NFNServer(nfnNodeConfig: RouterConfig, computeNodeConfig: ComputeNodeConfig) extends Actor { +case class NFNServer(nfnNodeConfig: RouterConfig, computeNodeConfig: ComputeNodeConfig, ccnIf: CCNLiteInterfaceWrapper) extends Actor { val logger = Logging(context.system, this) - val ccnIf = CCNLite +// nfnNodeConfig.config +// val ccnIf = new CCNLiteInterfaceWrapper() val cacheContent: Boolean = true @@ -126,10 +135,15 @@ case class NFNServer(nfnNodeConfig: RouterConfig, computeNodeConfig: ComputeNode var cs: ActorRef = context.actorOf(Props(classOf[ContentStore]), name = "ContentStore") val nfnGateway: ActorRef = - context.actorOf(Props(classOf[UDPConnectionContentInterest], - new InetSocketAddress(computeNodeConfig.host, computeNodeConfig.port), - new InetSocketAddress(nfnNodeConfig.host, nfnNodeConfig.port)), - name = s"udpsocket-${computeNodeConfig.host}-${nfnNodeConfig.port}") + context.actorOf( + Props( + classOf[UDPConnectionContentInterest], + new InetSocketAddress(computeNodeConfig.host, computeNodeConfig.port), + new InetSocketAddress(nfnNodeConfig.host, nfnNodeConfig.port), + ccnIf + ), + name = s"udpsocket-${computeNodeConfig.host}-${nfnNodeConfig.port}" + ) override def preStart() = { nfnGateway ! UDPConnection.Handler(self) @@ -231,7 +245,6 @@ case class NFNServer(nfnNodeConfig: RouterConfig, computeNodeConfig: ComputeNode } else { maybeLocalAbstractMachine match { case Some(localAbstractMachine) => { - // TODO send to localAbstractMachine AM localAbstractMachine ! i } case None => { @@ -299,7 +312,7 @@ case class NFNServer(nfnNodeConfig: RouterConfig, computeNodeConfig: ComputeNode // If it is an interest, start a compute request case packet:CCNPacket => handlePacket(packet, sender) case UDPConnection.Received(data, sendingRemote) => { - val maybePacket = byteStringToPacket(data) + val maybePacket = ccnIf.byteStringToPacket(data) maybePacket match { // Received an interest from the network (byte format) -> spawn a new worker which handles the messages (if it crashes we just assume a timeout at the moment) case Some(packet: CCNPacket) => handlePacket(packet, sender) diff --git a/nfn-scala/src/main/scala/nfn/NodeConfig.scala b/nfn-scala/src/main/scala/nfn/NodeConfig.scala index 37d4beeaabf7..dcd8cbbb5926 100644 --- a/nfn-scala/src/main/scala/nfn/NodeConfig.scala +++ b/nfn-scala/src/main/scala/nfn/NodeConfig.scala @@ -2,23 +2,27 @@ package nfn import java.util.concurrent.TimeUnit +import ccn.ccnlite.{CCNLiteInterfaceType, CCNLiteWireFormat, CCNbWireFormat} +import ccnliteinterface.CCNLiteInterface +import com.typesafe.config.ConfigException.BadValue import com.typesafe.config.{ConfigFactory, Config} import monitor.Monitor.NodeLog import ccn.packet.CCNName import scala.concurrent.duration.Duration +case class ConfigException(msg: String) extends Exception(msg) + object StaticConfig { private var maybeConfig: Option[Config] = None def config: Config = maybeConfig match { case Some(config) => config - case None => { + case None => val conf = ConfigFactory.load() maybeConfig = Some(conf) conf - } } def isNackEnabled = config.getBoolean("nfn-scala.usenacks") @@ -28,6 +32,30 @@ object StaticConfig { def defaultTimeoutDuration = Duration(config.getInt("nfn-scala.defaulttimeoutmillis"), TimeUnit.MILLISECONDS) def debugLevel = config.getString("nfn-scala.debuglevel") + + def packetformat: CCNLiteWireFormat = { + val path = "nfn-scala.packetformat" + val wfName = config.getString(path) + CCNLiteWireFormat.fromName(wfName) match { + case Some(wf) => wf + case None => throw new BadValue(path, + s""" + | can only be "ccnb" or "ndn" and not "$wfName" + """.stripMargin) + } + } + + def ccnlitelibrarytype: CCNLiteInterfaceType = { + val path = "nfn-scala.ccnlitelibrarytype" + val ltName = config.getString(path) + CCNLiteInterfaceType.fromName(ltName) match { + case Some(lt) => lt + case None => throw new BadValue(path, + s""" + | can only be "jni" or "native" and not "$ltName" + """.stripMargin) + } + } } trait NodeConfig { @@ -43,13 +71,11 @@ trait NodeConfig { case class CombinedNodeConfig(maybeNFNNodeConfig: Option[RouterConfig], maybeComputeNodeConfig: Option[ComputeNodeConfig]) -case class RouterConfig(host: String, port: Int, prefix: CCNName, isCCNOnly: Boolean = false)(implicit conf: Config) extends NodeConfig { +case class RouterConfig(host: String, port: Int, prefix: CCNName, isCCNOnly: Boolean = false) extends NodeConfig { def toNodeLog: NodeLog = NodeLog(host, port, Some(if(isCCNOnly) "CCNNode" else "NFNNode"), Some(prefix.toString)) - def config = conf } -case class ComputeNodeConfig(host: String, port: Int, prefix: CCNName, withLocalAM: Boolean = false)(implicit conf: Config) extends NodeConfig { +case class ComputeNodeConfig(host: String, port: Int, prefix: CCNName, withLocalAM: Boolean = false) extends NodeConfig { def toNodeLog: NodeLog = NodeLog(host, port, Some("ComputeNode"), Some(prefix + "compute")) - def config = conf } diff --git a/nfn-scala/src/main/scala/nfn/service/Main.scala b/nfn-scala/src/main/scala/nfn/service/Main.scala index 4e38c3b007e3..2860d6012b86 100644 --- a/nfn-scala/src/main/scala/nfn/service/Main.scala +++ b/nfn-scala/src/main/scala/nfn/service/Main.scala @@ -4,7 +4,7 @@ import java.io.{File, FileOutputStream} import akka.actor.ActorRef import bytecode.BytecodeLoader -import ccn.ccnlite.CCNLite +import ccn.ccnlite.CCNLiteInterfaceWrapper import ccn.packet._ import com.typesafe.scalalogging.slf4j.Logging import nfn.NFNApi diff --git a/nfn-scala/src/main/scala/node/LocalNode.scala b/nfn-scala/src/main/scala/node/LocalNode.scala index bdff69d8c5c1..090e581ad565 100644 --- a/nfn-scala/src/main/scala/node/LocalNode.scala +++ b/nfn-scala/src/main/scala/node/LocalNode.scala @@ -244,7 +244,6 @@ case class LocalNode(routerConfig: RouterConfig, maybeComputeNodeConfig: Option[ /** * Advertises the services to the network. - * TODO: this should be changed to advertise the service by setting up faces instead of adding them to the cache */ def publishServices = NFNServiceLibrary.nfnPublish(nfnMaster) diff --git a/nfn-scala/src/test/scala/ccn/ccnlite/CCNLiteInterfaceTest.scala b/nfn-scala/src/test/scala/ccn/ccnlite/CCNLiteInterfaceWrapperInterfaceTest.scala similarity index 74% rename from nfn-scala/src/test/scala/ccn/ccnlite/CCNLiteInterfaceTest.scala rename to nfn-scala/src/test/scala/ccn/ccnlite/CCNLiteInterfaceWrapperInterfaceTest.scala index 8151a0c69cd0..7b620f6c27a4 100644 --- a/nfn-scala/src/test/scala/ccn/ccnlite/CCNLiteInterfaceTest.scala +++ b/nfn-scala/src/test/scala/ccn/ccnlite/CCNLiteInterfaceWrapperInterfaceTest.scala @@ -11,8 +11,8 @@ import ccn.packet._ /** * Created by basil on 05/03/14. */ -class CCNLiteInterfaceTest extends FlatSpec with Matchers with GivenWhenThen { - val ccnIf = new CCNLiteInterface() +class CCNLiteInterfaceWrapperInterfaceTest extends FlatSpec with Matchers with GivenWhenThen { + val ccnIf = CCNLiteInterfaceWrapper.createCCNLiteInterface(CCNbWireFormat(), CCNLiteJniInterface()) val interest = Interest("name", "interest") s"Interest $interest" should "be converted to ccnb back to xml into interest object" in { @@ -40,10 +40,11 @@ class CCNLiteInterfaceTest extends FlatSpec with Matchers with GivenWhenThen { resultContent.get.asInstanceOf[Content].data should be ("testcontent".getBytes) } - s"Content $content" should "be converted to ccnb for an addToCache requeest" in { - val f = new File("./testfile") - val fw = new FileWriter(f) - fw.write("test") - val ccnAddToCacheReq = ccnIf.mkAddToCacheInterest(f.getCanonicalPath) - } +// s"Content $content" should "be converted to ccnb for an addToCache requeest" in { +// val f = new File("./testfile") +// val fw = new FileWriter(f) +// fw.write("test") +// ccnIf.mkAddToCacheInterest() +// val ccnAddToCacheReq = ccnIf.mkAddToCacheInterest(f.getCanonicalPath) +// } } diff --git a/nfn-scala/src/test/scala/nfn/NFNMasterSpec.scala b/nfn-scala/src/test/scala/nfn/NFNMasterSpec.scala index 6080a45f80ce..48a63ffcf4ac 100644 --- a/nfn-scala/src/test/scala/nfn/NFNMasterSpec.scala +++ b/nfn-scala/src/test/scala/nfn/NFNMasterSpec.scala @@ -2,6 +2,7 @@ package nfn import akka.actor._ import akka.testkit._ +import ccn.ccnlite.{CCNLiteJniInterface, CCNbWireFormat, CCNLiteInterfaceWrapper} import ccn.packet._ import com.typesafe.config.ConfigFactory import lambdacalculus.LambdaCalculus @@ -22,7 +23,8 @@ with WordSpecLike with Matchers with BeforeAndAfterEach with BeforeAndAfterAll w val nfnMasterNetworkRef: TestActorRef[NFNServer] = TestActorRef(NFNServerFactory.networkProps( RouterConfig("127.0.0.1", 10010, nodePrefix), - computeNodeConfig + computeNodeConfig, + CCNLiteInterfaceWrapper.createCCNLiteInterface(CCNbWireFormat(), CCNLiteJniInterface()) )) val nfnMasterNetworkInstance = nfnMasterNetworkRef.underlyingActor diff --git a/nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/libCCNLiteInterface.h b/nfn-scala/testfile similarity index 100% rename from nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/libCCNLiteInterface.h rename to nfn-scala/testfile