From: dingo Date: Fri, 13 Aug 2010 19:46:41 +0000 (+0000) Subject: [PATCHTEAM] - WING Wireless Mesh Routing Protocol X-Git-Url: http://git.archive.openwrt.org/?a=commitdiff_plain;h=5710e479bbebdb168c76bf9e319858c28190db4e;p=packages.git [PATCHTEAM] - WING Wireless Mesh Routing Protocol Signed-off-by: Roberto Riggio git-svn-id: svn://svn.openwrt.org/openwrt/packages@22627 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- diff --git a/net/wing/Config.in b/net/wing/Config.in new file mode 100644 index 000000000..b95e31c2c --- /dev/null +++ b/net/wing/Config.in @@ -0,0 +1,17 @@ +# Wing configuration + +choice + prompt "Version" + depends on PACKAGE_wing + default WING_STABLE + help + This option allows you to select the version of Wing to be built. + +config WING_STABLE + bool "Use the stable version (multi-interface)" + +config WING_TESTING + bool "Use the unstable version (multi-interfaces w/ ITACA)" + +endchoice + diff --git a/net/wing/Makefile b/net/wing/Makefile new file mode 100644 index 000000000..a5d774051 --- /dev/null +++ b/net/wing/Makefile @@ -0,0 +1,112 @@ +# +# Copyright (C) 2006-2009 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=wing + +ifneq ($(CONFIG_WING_STABLE),) + PKG_VERSION:=20100805 + PKG_RELEASE:=1 + PKG_REV:=21aae2ae5bea85426aded47b055b4fe62c2cea2e +else + PKG_VERSION:=$(shell date +%Y%m%d) + PKG_RELEASE:=1 + PKG_REV:=HEAD +endif + +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2 +PKG_SOURCE_URL:=http://github.com/create-net/click-wing.git +PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) +PKG_SOURCE_VERSION:=$(PKG_REV) +PKG_SOURCE_PROTO:=git + +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) + +include $(INCLUDE_DIR)/package.mk + +define Package/wing + TITLE:=Wireless mesh networking toolkit + SECTION:=net + CATEGORY:=Network + MAINTAINER:=Roberto Riggio (roberto.riggio@create-net.org) + DEPENDS:=+kmod-tun + URL:=http://www.wing-project.org/ +endef + +define Package/wing/Description + Wing is a wireless mesh routing software. The routing protocol + is derived from Roofnet. It supports multiple radio interfaces and + link quality routing using the ETX, ETT, and WCETT metrics. +endef + +define Package/wing/config + source "$(SOURCE)/Config.in" +endef + +define Build/Configure + (cd $(PKG_BUILD_DIR); \ + rm -rf config.{cache,status}; \ + ./configure \ + --prefix=/usr \ + --enable-userlevel \ + --enable-wifi \ + --enable-wing \ + --disable-linuxmodule \ + ); + $(MAKE) -C $(PKG_BUILD_DIR) tools elementmap.xml + (cd $(PKG_BUILD_DIR)/userlevel; \ + ../tools/click-mkmindriver/click-mkmindriver -p $(PKG_NAME) -C .. \ + -f $(PKG_BUILD_DIR)/conf/wing/sample.click \ + -A --all -E Discard -E Print -E Null \ + -E InfiniteSource -E RatedSource -E EtherEncap -E UDPIPEncap \ + -E AthdescEncap -E AthdescDecap -E RadiotapDecap -E RadiotapEncap \ + -E ProbeTXRate -E MadwifiRate -E AutoRateFallback \ + -E RoundRobinSched -E DRRSched; \ + ) + (cd $(PKG_BUILD_DIR); \ + rm -rf config.{cache,status} ; \ + $(TARGET_CONFIGURE_OPTS) \ + CXXFLAGS="-static -O2 -MD" CFLAGS="-static -MD" \ + CPPFLAGS="-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \ + LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib" \ + ./configure \ + --prefix=/usr \ + --target=$(GNU_TARGET_NAME) \ + --host=$(GNU_TARGET_NAME) \ + --build=$(GNU_HOST_NAME) \ + --enable-tools=mixed \ + --enable-userlevel \ + --enable-wifi \ + --enable-wing \ + --disable-linuxmodule \ + ); +endef + +define Build/Compile + $(MAKE) -C $(PKG_BUILD_DIR) \ + MINDRIVER=$(PKG_NAME) \ + DESTDIR="$(PKG_INSTALL_DIR)" \ + all install +endef + +define Package/wing/install + $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_DIR) $(1)/etc/wing + $(INSTALL_DIR) $(1)/usr/share/click + $(CP) ./files/* $(1)/ + $(CP) $(PKG_BUILD_DIR)/conf/wing/click_config $(1)/usr/bin/ + $(CP) $(PKG_BUILD_DIR)/conf/wing/write_handler $(1)/usr/bin/ + $(CP) $(PKG_BUILD_DIR)/conf/wing/read_handler $(1)/usr/bin/ + $(CP) $(PKG_INSTALL_DIR)/usr/bin/$(PKG_NAME)click $(1)/usr/bin/click + $(CP) $(PKG_INSTALL_DIR)/usr/bin/click-align $(1)/usr/bin/click-align + $(CP) $(PKG_BUILD_DIR)/conf/wing/*click $(1)/etc/wing/ + $(CP) $(PKG_INSTALL_DIR)/usr/share/click/elementmap.xml $(1)/usr/share/click/elementmap.xml +endef + +$(eval $(call BuildPackage,wing)) + diff --git a/net/wing/files/etc/uci-defaults/wing b/net/wing/files/etc/uci-defaults/wing new file mode 100644 index 000000000..4471ec6dc --- /dev/null +++ b/net/wing/files/etc/uci-defaults/wing @@ -0,0 +1,26 @@ +uci set network.mesh=interface +uci set network.mesh.proto=wing +uci set network.mesh.profile=bulk +uci set network.mesh.rc=static +uci set network.mesh.ls=fcfs +uci set network.mesh.metric=wcett +uci set network.mesh.prefix=6 +uci set network.mesh.period=36000 +uci set network.mesh.tau=360000 +uci set network.mesh.debug=true + +cfg=$(uci add firewall zone) +uci set firewall.$cfg.name="mesh" +uci set firewall.$cfg.input="ACCEPT" +uci set firewall.$cfg.output="ACCEPT" +uci set firewall.$cfg.forward="REJECT" +uci set firewall.$cfg.masq="1" + +cfg=$(uci add firewall forwarding) +uci set firewall.$cfg.src="lan" +uci set firewall.$cfg.dest="mesh" + +cfg=$(uci add firewall forwarding) +uci set firewall.$cfg.src="mesh" +uci set firewall.$cfg.dest="wan" + diff --git a/net/wing/files/lib/network/wing.sh b/net/wing/files/lib/network/wing.sh new file mode 100644 index 000000000..f1e1167a9 --- /dev/null +++ b/net/wing/files/lib/network/wing.sh @@ -0,0 +1,145 @@ + +scan_wing() { + config_set "$1" device "wing-$1" +} + +coldplug_interface_wing() { + setup_interface_wing "wing-$1" "$1" +} + +stop_interface_wing() { + local config="$1" + local iface="wing-$config" + env -i ACTION="ifdown" INTERFACE="$config" DEVICE="$iface" PROTO=wing /sbin/hotplug-call "iface"& + [ -f "/var/run/$iface.pid" ]&& { + kill -9 $(cat /var/run/$iface.pid) + rm /var/run/$iface.pid + } +} + +setup_interface_wing() { + + local iface="$1" + local config="$2" + + local hwmodes="" + local freqs="" + local ifnames="" + local hwaddrs="" + + config_load wireless + config_foreach wing_list_interfaces wifi-iface + + # start click router + if [ "$hwmodes" = "" -o "$freqs" = "" -o "$ifnames" = "" -o "$hwaddrs" = "" ]; then + logger -t "$config" "No raw interfaces available. Exiting." + exit 1 + fi + + local profile rc ls prefix debug + + config_get profile $config profile "bulk" + config_get rc $config rc "static" + config_get ls $config ls "fcfs" + config_get metric $config metric "wcett" + config_get prefix $config prefix "6" + config_get period $config period "10000" + config_get tau $config tau "100000" + config_get_bool debug $config debug "False" + + local hwaddr=$(echo $hwaddrs | sed 's/ .*//'); + local ipaddr=$(printf "$prefix.%d.%d.%d" $(echo $hwaddr | awk -F: '{printf "0x%s 0x%s 0x%s",$4,$5,$6}')) + local netmask=255.0.0.0 + + if ! wing_template_available "profile" "$profile" "bulk"; then + logger -t "$config" "Unable to configure router. Exiting." + exit 1 + fi + + if ! wing_template_available "rc" "$rc" "static"; then + logger -t "$config" "Unable to configure rate control. Exiting." + exit 1 + fi + + if ! wing_template_available "ls" "$ls" "radiotap"; then + logger -t "$config" "Unable to configure link scheduler. Exiting." + exit 1 + fi + + if [ "$profile" = "" -o "$rc" = "" ]; then + logger -t "$config" "Unable to generate template. Exiting." + exit 1 + fi + + [ "$debug" == 0 ]&& dbg="" || dbg="-d" + + /usr/bin/click_config -p $profile -r $rc -s $ls -l $metric \ + -m "$hwmodes" -c "$freqs" -n "$ifnames" -a "$hwaddrs" $dbg \ + | sed -e "s/__XR_IFNAME__/$iface/g" \ + | sed -e "s/__XR_IP__/$ipaddr/g" \ + | sed -e "s/__XR_NM__/$netmask/g" \ + | sed -e "s/__XR_PERIOD__/$period/g" \ + | sed -e "s/__XR_TAU__/$tau/g"> /tmp/$iface.click + + /usr/bin/click-align /tmp/$iface.click> /tmp/$iface-aligned.click 2>/var/log/$iface.log + [ ! -c /dev/net/tun ]&& { + mkdir -p /dev/net/ + mknod /dev/net/tun c 10 200 + if [ ! -c /dev/net/tun ]; then + logger -t "$config" "Device not available (/dev/net/tun). Exiting." + exit 1 + fi + } + + # creating the tun interface below will trigger a net subsystem event + # prevent it from touching iface by disabling .auto here + uci_set_state network "$config" auto 0 + + (/usr/bin/click /tmp/$iface-aligned.click>> /var/log/$iface.log 2>&1&)& + sleep 2 + ps | grep /usr/bin/click | grep -q -v grep || { + logger -t "$config" "Unable to start click. Exiting." + exit 1 + } + + ps | grep /usr/bin/click | grep -v grep | awk '{print $1}'> /var/run/$iface.pid + + ifconfig "$iface" "$ipaddr" netmask "$netmask" + uci_set_state network $config ipaddr "$ipaddr" + uci_set_state network $config netmask "$netmask" + + env -i ACTION="ifup" INTERFACE="$config" DEVICE="$iface" PROTO=wing /sbin/hotplug-call "iface"& + +} + +wing_template_available() { # prefix, template, default + local template="/etc/wing/$1.$2.click" + [ ! -f $template ]&& { + template="/etc/wing/$1.$3.click" + [ ! -f $template ]&& { + return 1 + } + } + return 0 +} + +wing_list_interfaces() { + local channel freq hwmode hwaddr ifname mode + config_get ifname $1 ifname + config_get mode $1 mode + config_get device $1 device + config_get_bool up $1 up + [ "$up" = "1" -a "$mode" = "monitor" ] || return 0 + config_get hwmode $device hwmode "11b" + config_get channel $device channel "1" + freq=$(iwlist $ifname freq | sed -n "s/^.*Channel 0*$channel : \([0-9.]*\).*/\1/p" | awk '{print $1*1000}') + hwaddr=$(/sbin/ifconfig $ifname 2>&1 | sed -n 's/^.*HWaddr \([0-9A-Za-z\-]*\).*/\1/p' | sed -e 's/\-/:/g' | cut -c1-17) + freqs=${freqs:+"$freqs "}$freq + hwmodes=${hwmodes:+"$hwmodes "}$hwmode + hwaddrs=${hwaddrs:+"$hwaddrs "}$hwaddr + ifnames=${ifnames:+"$ifnames "}$ifname + /sbin/ifconfig $ifname mtu 1900 + /sbin/ifconfig $ifname txqueuelen 5 + /sbin/ifconfig $ifname up +} +