summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYAMAMOTO Takashi <yamamoto@valinux.co.jp>2015-04-01 13:37:57 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-04-03 17:51:29 +0900
commita85fbc9694a20fead84b4b1f67872a44394795c8 (patch)
tree42d3a93551ab2601ea16681b239a4e3203a5b24e
parent8fc25ca6c8c3f4510980b14db2604e62af043a2d (diff)
packet_data_generator2: another packet data generator using libofproto
For OpenFlow 1.5. Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/tests/packet_data_generator2/Makefile35
-rw-r--r--ryu/tests/packet_data_generator2/gen.c132
2 files changed, 167 insertions, 0 deletions
diff --git a/ryu/tests/packet_data_generator2/Makefile b/ryu/tests/packet_data_generator2/Makefile
new file mode 100644
index 00000000..a6319c42
--- /dev/null
+++ b/ryu/tests/packet_data_generator2/Makefile
@@ -0,0 +1,35 @@
+# Copyright (C) 2015 Nippon Telegraph and Telephone Corporation.
+# Copyright (C) 2015 YAMAMOTO Takashi <yamamoto at valinux co jp>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# OVS: openvswitch installed directory (used to look for libraries)
+# OVS_SRC: openvswitch source directory
+
+OVS?=${HOME}/ovs
+OVS_SRC?=/disks/774373a2-e180-11e3-9fa1-08606e7f74e7/git/openvswitch
+
+CPPFLAGS+=-I${OVS}/include -I${OVS_SRC}
+LDFLAGS+=-L${OVS}/lib -Wl,-R${OVS}/lib -lofproto -lopenvswitch
+
+PROG=gen
+NOMAN=
+
+all: generate
+
+generate: ${PROG}
+ ${_MKMSG} "generate packet_data"
+ cd ${.CURDIR} && ${.OBJDIR}/${PROG}
+
+.include <bsd.prog.mk>
diff --git a/ryu/tests/packet_data_generator2/gen.c b/ryu/tests/packet_data_generator2/gen.c
new file mode 100644
index 00000000..ddab81ea
--- /dev/null
+++ b/ryu/tests/packet_data_generator2/gen.c
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2015 Nippon Telegraph and Telephone Corporation.
+ * Copyright (C) 2015 YAMAMOTO Takashi <yamamoto at valinux co jp>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <lib/ofpbuf.h>
+#include <lib/ofp-actions.h>
+#include <lib/ofp-util.h>
+#include <lib/packets.h>
+
+#include <err.h>
+#include <stdio.h>
+
+void
+dump_ofpbuf(const char *name, const struct ofpbuf *buf)
+{
+ FILE *fp;
+ size_t written;
+
+ fp = fopen(name, "wb");
+ if (fp == NULL) {
+ err(1, "fopen");
+ }
+ written = fwrite(buf->data, buf->size, 1, fp);
+ if (written != 1) {
+ err(1, "fwrite");
+ }
+ if (fclose(fp) != 0) {
+ err(1, "fclose");
+ }
+}
+
+void
+fill_match(struct match *match)
+{
+ match_init_catchall(match);
+ match_set_in_port(match, 0xabcd);
+ match_set_dl_vlan(match, htons(999));
+ match_set_dl_dst(match, "\xaa\xbb\xcc\x99\x88\x77");
+ match_set_dl_type(match, htons(ETH_TYPE_IP));
+ match_set_nw_dst(match, inet_addr("192.168.2.1"));
+ match_set_tun_src(match, inet_addr("192.168.2.3"));
+ match_set_tun_dst(match, inet_addr("192.168.2.4"));
+ match_set_tun_id(match, htonll(50000));
+}
+
+struct ofpbuf *
+packet_in(enum ofputil_protocol proto)
+{
+ struct ofputil_packet_in pin;
+ struct match match;
+ struct ofpbuf *buf;
+
+ memset(&pin, 0, sizeof(pin));
+ pin.packet = "hoge";
+ pin.packet_len = 4;
+ pin.total_len = 1000;
+ pin.table_id = 100;
+ pin.buffer_id = 200;
+
+ fill_match(&match);
+ flow_get_metadata(&match.flow, &pin.fmd);
+
+ return ofputil_encode_packet_in(&pin, proto, NXPIF_OPENFLOW10);
+}
+
+struct protocol_version {
+ const char *name;
+ const char *dir_name;
+ enum ofp_version version;
+};
+
+#define P(v) {.name = "OFP" #v, .dir_name = "of" #v, \
+ .version = OFP ## v ## _VERSION,}
+
+const struct protocol_version protocols[] = {
+ P(15),
+};
+
+
+struct message {
+ const char *name;
+ struct ofpbuf *(*gen)(enum ofputil_protocol);
+};
+
+#define M(m) {.name = #m, .gen = m,}
+
+const struct message messages[] = {
+ M(packet_in),
+};
+
+#if !defined(__arraycount)
+#define __arraycount(a) (sizeof(a) / sizeof(a[0]))
+#endif
+
+int
+main(int argc, char *argv[])
+{
+ struct ofpbuf *buf;
+ unsigned int i, j;
+
+ for (j = 0; j < __arraycount(protocols); j++) {
+ const struct protocol_version * const p = &protocols[j];
+ const enum ofputil_protocol proto =
+ ofputil_protocol_from_ofp_version(p->version);
+
+ for (i = 0; i < __arraycount(messages); i++) {
+ const struct message * const m = &messages[i];
+ char name[255];
+
+ buf = (*m->gen)(proto);
+ snprintf(name, sizeof(name),
+ "../packet_data/%s/libofproto-%s-%s.packet",
+ p->dir_name, p->name, m->name);
+ dump_ofpbuf(name, buf);
+ ofpbuf_delete(buf);
+ }
+ }
+}