svn commit: r234254 - projects/net80211_testsuite/wtap/006

Monthadar Al Jaberi monthadar at FreeBSD.org
Sat Apr 14 00:36:13 UTC 2012


Author: monthadar
Date: Sat Apr 14 00:36:13 2012
New Revision: 234254
URL: http://svn.freebsd.org/changeset/base/234254

Log:
  * Added a new test which verifies that when a node is configured as a ROOT
  and a Mesh Gate the corresponding flag in the period proactive PREQ is set
  for Mesh Gate;
  * This test uses a C program that opens a bpf device and return 0 on success
  otherwise failure;
  
  Approved by: adrian (mentor)

Added:
  projects/net80211_testsuite/wtap/006/
  projects/net80211_testsuite/wtap/006/bpf.c   (contents, props changed)
  projects/net80211_testsuite/wtap/006/test.sh   (contents, props changed)

Added: projects/net80211_testsuite/wtap/006/bpf.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/net80211_testsuite/wtap/006/bpf.c	Sat Apr 14 00:36:13 2012	(r234254)
@@ -0,0 +1,168 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <net/bpf.h>
+#include <net/ethernet.h>
+
+#include <net80211/ieee80211.h>
+#include <net80211/ieee80211_mesh.h>
+#include <net80211/ieee80211_radiotap.h>
+
+extern int errno;
+static int fd = -1;
+static int BUF_SIZE = 0;
+static int packets_rcv = 0;
+static int install_filter();
+
+static int
+hwmp_recv_action_meshpath(const struct ieee80211_frame *wh,
+    const uint8_t *frm, const uint8_t *efrm)
+{
+	struct ieee80211_meshpreq_ie *preq;
+	const uint8_t *iefrm = frm + 2; /* action + code */
+	const uint8_t *iefrm_t = iefrm; /* temporary pointer */
+	int found = 0;
+
+	while (efrm - iefrm > 1) {
+		if((efrm - iefrm) < (iefrm[1] + 2)) {
+			return 0;
+		}
+		switch (*iefrm) {
+		case IEEE80211_ELEMID_MESHPREQ:
+		{
+			printf("PREQ with ");
+			preq = (struct ieee80211_meshpreq_ie *)iefrm;
+			if (preq->preq_flags & IEEE80211_MESHPREQ_FLAGS_PR) {
+				printf("GateAnnouncement!\n");
+				return 0;
+			} else {
+				printf("NO GateAnnouncement!\n");
+				return -1;
+			}
+			found++;
+			break;
+		}
+		}
+		iefrm += iefrm[1] + 2;
+	}
+	if (!found) {
+		printf("MESH HWMP action without any IEs!\n");
+	}
+	return -1;
+}
+
+/* If assertion passes return 0 otherwise -1 */
+static int
+assertion(struct ieee80211_frame_min *whmin, uint8_t *ep)
+{
+#define	WH_TYPE(wh) (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK)
+#define	WH_SUBTYPE(wh) (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK)
+	const struct ieee80211_frame *wh;
+
+	if (WH_TYPE(whmin) == IEEE80211_FC0_TYPE_MGT &&
+	    WH_SUBTYPE(whmin) == IEEE80211_FC0_SUBTYPE_ACTION) {
+		wh = (const struct ieee80211_frame *) whmin;
+		printf("RA %s, ",
+		    ether_ntoa((const struct ether_addr *)wh->i_addr1));
+		printf("TA(SA) %s, ",
+		    ether_ntoa((const struct ether_addr *)wh->i_addr2));
+		return hwmp_recv_action_meshpath(wh,
+		    (const uint8_t *)((uint8_t *)whmin +
+		    sizeof(struct ieee80211_frame)), ep);
+
+	}
+	return -1;
+#undef	WH_TYPE
+#undef	WH_SUBTYPE
+}
+
+int main(){
+	struct ifreq req;
+	int error = 0;
+	int assert_result = -1; /* 0 means success, -1 failure */
+	fd = open("/dev/bpf0", O_RDWR);
+
+	if(fd < 0){
+		perror("can't opening /dev/bpf0");
+		return -1;
+	}
+	strcpy(req.ifr_name, "wlan0");
+	error =  ioctl(fd, BIOCSETIF, &req);
+	if(error < 0){
+		perror("error setting network interface");
+		return -1;
+	}
+
+	if(ioctl(fd, BIOCGBLEN, &BUF_SIZE)){
+		perror("error getting BIOCGBLEN\n");
+	}
+	uint32_t iftype = DLT_IEEE802_11_RADIO;
+	if(ioctl(fd, BIOCSDLT, &iftype)){
+		perror("error setting BIOCSDLT\n");
+	}
+
+	if(install_filter() != 0){
+		printf("error cant install filter\n");
+		return -1;
+	}
+	uint8_t *buf = malloc(sizeof(uint8_t)*BUF_SIZE);
+	struct bpf_hdr *hdr;
+	struct ether_header *eh;
+	struct ieee80211_frame_min *whmin;
+	struct ieee80211_radiotap_header *rdtap;
+	int i, failed = 0;
+	while(1){
+		ssize_t size;
+		if((size = read(fd, buf, BUF_SIZE, 0)) < 0){
+			perror("error reading from /dev/bpf0");
+		}
+		uint8_t *p = buf;
+		uint8_t *c = p;
+		uint8_t radiotap_length = 0;
+		while(p < buf + sizeof(uint8_t)*size){
+			hdr = (struct bpf_hdr *)p;
+			c = p + BPF_WORDALIGN(hdr->bh_hdrlen);
+			rdtap = (struct ieee80211_radiotap_header *)
+			    (p + BPF_WORDALIGN(hdr->bh_hdrlen));
+			whmin = (struct ieee80211_frame_min *)
+			    (c + rdtap->it_len);
+			assert_result = assertion(whmin,
+			    (uint8_t *)(p +
+			    BPF_WORDALIGN(hdr->bh_hdrlen + hdr->bh_caplen)));
+			if (assert_result == 0)
+				return (0); /* sucess */
+			failed++;
+			if(failed == 10) /* XXX: magic number */
+				return (-1);
+			p=(uint8_t *)p + BPF_WORDALIGN(hdr->bh_hdrlen +
+			    hdr->bh_caplen);
+		}
+	}
+
+	if(close(fd) != 0){
+		perror("cant close /dev/bpf0");
+	}
+	return -1;
+}
+
+int install_filter(){
+	struct bpf_program prg;
+	struct bpf_insn insns[] = {
+             BPF_STMT(BPF_RET+BPF_K, sizeof(uint8_t)*128),
+	};
+	prg.bf_len = 1;
+
+	prg.bf_insns = insns;
+
+	if(ioctl(fd, BIOCSETF, &prg)){
+		perror("error setting BIOCSETF");
+	}
+	return 0;
+}

Added: projects/net80211_testsuite/wtap/006/test.sh
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/net80211_testsuite/wtap/006/test.sh	Sat Apr 14 00:36:13 2012	(r234254)
@@ -0,0 +1,189 @@
+#!/bin/sh
+
+# This program requires:
+# + wtap - to create/destroy the wtap instances
+# + vis_map - to setup the visibility map between wtap instances
+# + vimage - to configure/destroy vtap nodes
+
+# The name of the test that will be printed in the begining
+TEST_NBR="006"
+TEST_NAME="2 nodes, one of them is ROOT with GateAnnouncement"
+
+# Return value from this test, 0 success failure otherwise
+TEST_RESULT=127
+
+# The number of nodes to test
+NBR_NODES=2
+
+# The subnet prefix
+IP_SUBNET="192.168.2."
+
+cmd()
+{
+	echo "***${TEST_NBR}*** " $*
+	$*
+}
+
+info()
+{
+	echo "***${TEST_NBR}*** " $*
+}
+
+descr()
+{
+	cat <<EOL
+
+This test establishes that when a node is configured as ROOT
+and as a MeshGate it should set the GateAnnouncement bit in the
+proactive PREQ to 1.
+
+It:
+
+* creates two wtap instances
+* creates two vimage instances
+* creates one wlan vap for each wtap instance and places
+  each vap in one of the two vimage instances
+* sets up the visibility to the following:
+
+  A <-> B
+
+* A is configured as both ROOT and MeshGate.
+* Runs a special C progam that checks the PREQ flag.
+
+NB: The program will capture a number of packets and when
+it encounters a Mgmt type, Action subtype, it will check
+for the PREQ flag and return 0 on success otherwise -1.
+NB: The program attaches to node A and it does not care
+about who sent the PREQ (future extension to check for addresses?)
+
+EOL
+}
+
+setup()
+{
+	# Compile bpf.c
+	cmd gcc -o bpf bpf.c
+
+	# Initialize output file
+	info "TEST: ${TEST_NAME}"
+	info `date`
+
+	# Create wtap/vimage nodes
+	for i in `seq 1 ${NBR_NODES}`; do
+		wtap_if="`expr $i - 1`"
+		info "Setup: vimage $i - wtap$wtap_if"
+		cmd vimage -c $i
+		cmd wtap c $wtap_if
+	done
+
+	# Set visibility for each node to see the
+	# next node.
+	n="`expr ${NBR_NODES} - 1`"
+	for i in `seq 0 ${n}`; do
+		j="`expr ${i} + 1`"
+		cmd vis_map a $i $j
+		cmd vis_map a $j $i
+	done
+
+	# Makes the visibility map plugin deliver packets to resp. dest.
+	cmd vis_map o
+
+	# Create each wlan subinterface, place into the correct vnet
+	for i in `seq 0 ${n}`; do
+		vnet="`expr ${i} + 1`"
+		cmd ifconfig wlan${i} create wlandev wtap${i} wlanmode mesh
+		cmd ifconfig wlan${i} meshid mymesh
+		if [ ${i} = 0 ]; then
+			cmd ifconfig wlan${i} hwmprootmode normal
+			cmd ifconfig wlan${i} meshgate
+		fi
+		cmd wlandebug -i wlan${i} hwmp
+		cmd ifconfig wlan${i} vnet ${vnet}
+		cmd jexec ${vnet} ifconfig wlan${i} up
+
+		cmd jexec ${vnet} ifconfig wlan${i} inet ${IP_SUBNET}${vnet}
+	done
+	sleep 5
+}
+
+run()
+{
+	cmd jexec 1 ${PWD}/bpf
+
+	if [ "$?" = "0" ]; then
+		info "TEST SUCCESS"
+		TEST_RESULT=0
+	else
+		info "TEST FAILED"
+	fi
+}
+
+teardown()
+{
+	cmd vis_map c
+	# Unlink all links
+	# XXX: this is a limitation of the current plugin,
+	# no way to reset vis_map without unload wtap.
+	n="`expr ${NBR_NODES} - 1`"
+	for i in `seq 0 ${n}`; do
+		j="`expr ${i} + 1`"
+		cmd vis_map d $i $j
+		cmd vis_map d $j $i
+	done
+	n="`expr ${NBR_NODES} - 1`"
+	for i in `seq 0 ${n}`; do
+		vnet="`expr ${i} + 1`"
+		cmd jexec ${vnet} ifconfig wlan${i} destroy
+	done
+	for i in `seq 1 ${NBR_NODES}`; do
+		wtap_if="`expr $i - 1`"
+		cmd wtap d ${wtap_if}
+		cmd vimage -d ${i}
+	done
+	exit ${TEST_RESULT}
+}
+
+EXEC_SETUP=0
+EXEC_RUN=0
+EXEC_TEARDOWN=0
+while [ "$#" -gt "0" ]
+do
+	case $1 in
+		'all')
+			EXEC_SETUP=1
+			EXEC_RUN=1
+			EXEC_TEARDOWN=1
+		;;
+		'setup')
+			EXEC_SETUP=1
+		;;
+		'run')
+			EXEC_RUN=1
+		;;
+		'teardown')
+			EXEC_TEARDOWN=1
+		;;
+		'descr')
+			descr
+			exit 0
+		;;
+                *)
+			echo "$0 {all | setup | run | teardown | descr}"
+			exit 127
+		;;
+        esac
+        shift
+done
+
+if [ $EXEC_SETUP = 1 ]; then
+	setup
+fi
+if [ $EXEC_RUN = 1 ]; then
+	run
+fi
+if [ $EXEC_TEARDOWN = 1 ]; then
+	teardown
+fi
+
+exit 0
+


More information about the svn-src-projects mailing list