Skip to content

Commit

Permalink
Prepared support of NDN wireformat for nfn-scala as well as cli suppo…
Browse files Browse the repository at this point in the history
…rt instead of using jni

- Added configuration for both wireformat and library type
- renamed current ccnb jni native lib from CCNLiteInterface to CCNLiteInterfaceCCNbJni
  • Loading branch information
basilkohler committed Sep 3, 2014
1 parent cbb8459 commit 911b453
Show file tree
Hide file tree
Showing 18 changed files with 358 additions and 114 deletions.
52 changes: 52 additions & 0 deletions 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

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Expand Up @@ -3,7 +3,7 @@
#define CCNL_NFN

#include <stdio.h>
#include "ccnliteinterface_CCNLiteInterface.h"
#include "ccnliteinterface_jni_CCNLiteInterfaceCCNbJni.h"

#include "../../../../../../ccnl.h"
#include "../../../../../../pkt-ccnb.h"
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions nfn-scala/ccnliteinterface/src/main/c/ccn-lite-bridge/make.sh
Expand Up @@ -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
Expand All @@ -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
Expand Down
@@ -1,36 +1,32 @@
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 "<native>..." 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
* @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]
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"]:
* <interest>
Expand Down Expand Up @@ -94,25 +90,24 @@ 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.
* 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]

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)
Expand Down
@@ -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"]:
* <interest>
* <name>
* <component>
* <data size="4" dt="string">
* cmp1
* </data>
* </component>
* <component>
* <data size="4" dt="string">
* cmp2
* </data>
* </component>
* </name>
* <scope>
* <data size="0" dt="string">
*
* </data>
* </scope>
* <nonce>
* <data size="4" dt="string">
* '%0d0S
* </data>
* </nonce>
* </interest>
*
* Content(["cmp1", "cmp2"], "content"):
* <contentobj>
* <name>
* <component>
* <data size="4" dt="string">
* "cmp1"
* </data>
* </component>
* <component>
* <data size="4" dt="string">
* "cmp2"
* </data>
* </component>
* </name>
* <timestamp>
* <data size="6" dt="string">
* S0%0d'%07/
* </data>
* </timestamp>
* <signedinfo>
* <publisherPubKeyDigest>
* <data size="0" dt="string">
* </data>
* </publisherPubKeyDigest>
* </signedinfo>
* <content>
* <data size="8" dt="string">
* content
* </data>
* </content>
* <contentobj>
*
* @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]


}
4 changes: 4 additions & 0 deletions nfn-scala/src/main/resources/reference.conf
Expand Up @@ -6,4 +6,8 @@ nfn-scala {
debuglevel = "DEBUG"

defaulttimeoutmillis = 5000

packetformat = "ccnb"

ccnlitelibrarytype = "jni"
}

0 comments on commit 911b453

Please sign in to comment.