diff --git a/examples/java/LearningSwitch13.java b/examples/java/LearningSwitch13.java new file mode 100644 index 0000000..2848ecd --- /dev/null +++ b/examples/java/LearningSwitch13.java @@ -0,0 +1,59 @@ +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.Map; +import java.util.Arrays; + +import fluid.base.*; +import fluid.msg13.*; + +public class LearningSwitch13 extends OFServer { + static { + System.loadLibrary("fluid_base"); + System.loadLibrary("fluid_msg_of10"); + System.loadLibrary("fluid_msg_of13"); + } + + static short test(short bytes) { + return bytes; + } + + static Map> table = new HashMap>(); + + @Override + public void connection_callback(OFConnection conn, + OFConnection.Event event_type) { + System.out.println("## Connection id=" + conn.get_id() + " event=" + + event_type); + } + + private Long get_long_mac(byte[] mac) { + ByteBuffer br = ByteBuffer.allocate(8); + br.put(mac); + br.putShort((short) 0x0000); + br.flip(); + return br.getLong(); + } + + + private void flood(OFConnection conn, PacketIn pi) { + // TODO: implement this method + + } + + @Override + public void message_callback(OFConnection conn, short type, byte[] data, + long len) { + + System.out.println("Type Packet: "+type + " Version Protcol: "+conn.get_version()); + } + + public LearningSwitch13(String address, int port, int nthreads) { + super(address, port, nthreads,false,new OFServerSettings().supported_version((short)1).supported_version((short)4).keep_data_ownership(false)); + } + + public static void main(String argv[]) { + LearningSwitch13 l2 = new LearningSwitch13("0.0.0.0", 6653, 1); + l2.start(true); + } +} diff --git a/examples/java/Makefile b/examples/java/Makefile index 9f3024b..a3a19b7 100644 --- a/examples/java/Makefile +++ b/examples/java/Makefile @@ -2,14 +2,14 @@ CXX=c++ SWIG=swig JAVA_INCLUDE_PATH=/usr/lib/jvm/java-7-openjdk-amd64/include -LearningSwitch: libfluid_base libfluid_msg_of10 +LearningSwitch: libfluid_base libfluid_msg_of10 libfluid_msg_of13 javac LearningSwitch.java libfluid_base: mkdir -p fluid/base cd swig;\ - $(SWIG) -c++ -java -package fluid.base -I/usr/include libfluid_base.i;\ - $(CXX) -c libfluid_base_wrap.cxx -I$(JAVA_INCLUDE_PATH) -fPIC;\ + $(SWIG) -c++ -java -package fluid.base -I/usr/local/include libfluid_base.i;\ + $(CXX) -c libfluid_base_wrap.cxx -I$(JAVA_INCLUDE_PATH) -I$(JAVA_INCLUDE_PATH)/linux -fPIC;\ $(CXX) libfluid_base_wrap.o -o libfluid_base.so -shared -lfluid_base -fPIC;\ mv *.java ../fluid/base;\ mv *.so ../fluid; @@ -17,12 +17,21 @@ libfluid_base: libfluid_msg_of10: mkdir -p fluid/msg cd swig;\ - $(SWIG) -c++ -java -package fluid.msg -I/usr/include libfluid_msg_of10.i;\ - $(CXX) -c libfluid_msg_of10_wrap.cxx -I$(JAVA_INCLUDE_PATH) -fPIC;\ + $(SWIG) -c++ -java -package fluid.msg -I/usr/local/include libfluid_msg_of10.i;\ + $(CXX) -c libfluid_msg_of10_wrap.cxx -I$(JAVA_INCLUDE_PATH) -I$(JAVA_INCLUDE_PATH)/linux -fPIC;\ $(CXX) libfluid_msg_of10_wrap.o -o libfluid_msg_of10.so -shared -lfluid_msg -fPIC;\ mv *.java ../fluid/msg;\ mv *.so ../fluid; +libfluid_msg_of13: + mkdir -p fluid/msg13 + cd swig;\ + $(SWIG) -c++ -java -package fluid.msg13 -I/usr/local/include libfluid_msg_of13.i;\ + $(CXX) -c libfluid_msg_of13_wrap.cxx -I$(JAVA_INCLUDE_PATH) -I$(JAVA_INCLUDE_PATH)/linux -fPIC;\ + $(CXX) libfluid_msg_of13_wrap.o -o libfluid_msg_of13.so -shared -lfluid_msg -fPIC;\ + mv *.java ../fluid/msg13;\ + mv *.so ../fluid; + clean: cd swig;\ ls | grep -v "\.i$$" | xargs rm -f; diff --git a/examples/java/README.md b/examples/java/README.md index 33513e7..0a3bc1e 100644 --- a/examples/java/README.md +++ b/examples/java/README.md @@ -8,12 +8,22 @@ Swig 2.0 and the JDK (`openjdk-7-jdk` package on Ubuntu 12.04). So do what's needed first, and then run: ~~~{.sh} $ make +OpenFlow 1.0 $ LD_LIBRARY_PATH=./fluid:$LD_LIBRARY_PATH java LearningSwitch +OR OpenFlow 1.3 +$ LD_LIBRARY_PATH=./fluid:$LD_LIBRARY_PATH java LearningSwitch13 ~~~ It is an OpenFlow 1.0 learning switch test application. The Java code is in `LearningSwitch.java`. +It is an OpenFlow 1.3 learning switch test application. +The Java code is in `LearningSwitch13.java`. + > This example uses the new, IANA-defined OpenFlow port: **6653** instead of > the previous, non-standard default (6633). +> Exemple Conection Mininet Openflow Protocolo Version 1.0: +> > sudo mn -v output --topo linear,5 --switch ovs,protocols=OpenFlow10 --controller remote,ip=[IP],port=6653 + Or Version 1.3 +> > sudo mn -v output --topo linear,5 --switch ovs,protocols=OpenFlow13 --controller remote,ip=[IP],port=6653 diff --git a/examples/java/swig/libfluid_msg_of13.i b/examples/java/swig/libfluid_msg_of13.i new file mode 100644 index 0000000..0b0d796 --- /dev/null +++ b/examples/java/swig/libfluid_msg_of13.i @@ -0,0 +1,65 @@ +/* File: example.i */ +%module(directors="1") libfluid_msg_of13 +#pragma SWIG nowarn=362,503,509 +%{ +/* Includes the header in the wrapper code */ +typedef unsigned int of_error; +#include +%} +%include "stdint.i" +%include "cdata.i" +%include "various.i" + +%typemap(jni) (uint8_t *) "jbyteArray" +%typemap(jni) (void *) "jbyteArray" +%typemap(jtype) (uint8_t *) "byte[]" +%typemap(jtype) (void *) "byte[]" +%typemap(jstype) (uint8_t *) "byte[]" +%typemap(jstype) (void *) "byte[]" + +%typemap(in) void* { + $1 = (void *) JCALL2(GetByteArrayElements, jenv, $input, 0); +} + +%typemap(in) uint8_t* { + $1 = (uint8_t *) JCALL2(GetByteArrayElements, jenv, $input, 0); +} + +%typemap(javain) (uint8_t *) "$javainput" +%typemap(javain) (void *) "$javainput" + +%typemap(out, descriptor="[B") void* data() { + $result = (jenv)->NewByteArray(arg1->data_len()); + (jenv)->SetByteArrayRegion($result, 0, arg1->data_len(), (jbyte*) $1); +} + +%typemap(out, descriptor="[B") uint8_t* { + int len = htons(*((uint16_t*) $1 + 1)); + $result = (jenv)->NewByteArray(len); + (jenv)->SetByteArrayRegion($result, 0, len, (jbyte*) $1); +} + +%typemap(javaout) (uint8_t *) { + return $jnicall; +} + +%typemap(javaout) (void *) { + return $jnicall; +} + +%include "fluid/util/ethaddr.hh" +%include "fluid/util/ipaddr.hh" + +%include "fluid/ofcommon/action.hh" +%include "fluid/ofcommon/common.hh" +%include "fluid/ofcommon/msg.hh" + +%include "fluid/of13/of13match.hh" +%include "fluid/of13/of13instruction.hh" +%include "fluid/of13/of13action.hh" +%include "fluid/of13/of13common.hh" +%include "fluid/of13/of13meter.hh" + +%include "fluid/of13msg.hh" + +typedef unsigned int of_error;