diff options
author | Reyk Floeter <reyk@cvs.openbsd.org> | 2016-07-19 16:54:27 +0000 |
---|---|---|
committer | Reyk Floeter <reyk@cvs.openbsd.org> | 2016-07-19 16:54:27 +0000 |
commit | 6d847f71578d4d9c57d480ea3f97461faea86af9 (patch) | |
tree | 009a7f341dccce28d1157f54e98e94bbad5d8c59 /usr.sbin/switchd/genmap.sh | |
parent | 5c8c9d126a7f674d0b1909622d4d093e0e5f154d (diff) |
Import switchd(8), a basic WIP OpenFlow implementation for OpenBSD.
switchd consists of two parts:
1. switchd(8) and switchctl(8), an OpenFlow controller or "vswitch".
2. switch(4), an OpenFlow-aware kernel "bridge".
This the 1st part, the driver will be imported later. The code will
remain disabled for a while, but it helps development to have it in
the tree. switchd currently supports partial OpenFlow 1.0, but the
goal is to use OpenFlow 1.3.5 instead (switch(4) already does 1.3.5).
For more background information see:
http://www.openbsd.org/papers/bsdcan2016-switchd.pdf
https://youtu.be/Cuo0qT-lqig
With help from yasuoka@ goda@
Import discussed with deraadt@
Diffstat (limited to 'usr.sbin/switchd/genmap.sh')
-rw-r--r-- | usr.sbin/switchd/genmap.sh | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/usr.sbin/switchd/genmap.sh b/usr.sbin/switchd/genmap.sh new file mode 100644 index 00000000000..76ecee1497c --- /dev/null +++ b/usr.sbin/switchd/genmap.sh @@ -0,0 +1,90 @@ +#!/bin/sh +# $OpenBSD: genmap.sh,v 1.1 2016/07/19 16:54:26 reyk Exp $ + +# Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org> +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +TOKEN="" +MAPFILE="" +INPUT="" +HEADER="" + +args=`getopt i:o:h:t:m: $*` + +if [ $? -ne 0 ]; then + echo "usage: $0 -i input -h header -t token [-m mapfile]" + exit 1 +fi + +set -- $args +while [ $# -ne 0 ]; do + case "$1" in + -i) + INPUT="$2"; shift; shift; + ;; + -h) + HEADER="$2"; shift; shift; + ;; + -t) + TOKEN="$2"; shift; shift; + ;; + -m) + MAPFILE="$2"; shift; shift; + ;; + --) + shift; + break + ;; + esac +done + +if [ -z "$MAPFILE" ]; then + MAPFILE=$INPUT +fi + +TOK=$(echo ${TOKEN} | tr "[:lower:]" "[:upper:]") +tok=$(echo ${TOKEN} | tr "[:upper:]" "[:lower:]") +INC="#include ${HEADER}" + +MAP=$(grep "struct constmap ${tok}_" $MAPFILE | + sed -Ee "s/.*${tok}_([^_]+)_map.*/\1/g") + +# Print license/copyright notice and headers +cat <<EOF +/* Automatically generated from $1, do not edit */ +EOF +sed -n '1,/^ \*\//p' $INPUT +cat <<EOF + +#include <sys/types.h> + +#include "types.h" +${INC} + +EOF + +for i in $MAP; do + lower=$(echo $i | tr "[:upper:]" "[:lower:]") + upper=$(echo $i | tr "[:lower:]" "[:upper:]") + + echo "struct constmap ${tok}_${lower}_map[] = {" + + X="${TOK}_${upper}_" + grep "$X" $INPUT | grep -v '\\' | sed -Ee \ + "s/#define.*${X}([^[:blank:]]+).*\/\* (.+) \*\/$\ +/ { ${X}\1, \"\1\", \"\2\" },/" | grep -v '\#define' + + echo " { 0 }" + echo "};" +done |