240 likes | 432 Views
EMOS Group 3. 組員 :郭柏宏 郭建漢 蕭鼎亞 黃雍文 黃博奕. Current Status Networking. User. Router. User. User. Router. User. Router. User. User. Current Status of Crowded Networking. User. Router. User. User. Router. …. Router. User. User. Motivation.
E N D
EMOS Group 3 組員:郭柏宏 郭建漢 蕭鼎亞 黃雍文 黃博奕
Current Status Networking User Router User User Router User Router User User
Current Status of Crowded Networking User Router User User Router … Router User User
Motivation • 通訊Bandwidth浪費在重覆註冊連線上 • 階層化(Hierarchy) 的網路連線與頻寬分配 • Web-Browser 的網路UI • 頻寬分配之監控
Concept User (S) User (M) User (S) Router User User User User Router … User User User Router User User User User User
System Blocks Raspberry Pi App. & Driver (含Bandwidth monitoring)
To monitor the network usage 1. A web server - apache 2. A program language build in Pi - Python
web server Common Gateway interface GPIO To access the hardware resources, we should use GPIO on Pi to get the information. Then we can monitor the usage of wifi and manage the bandwidth which is shared with users.
Reference • http://pingbin.com/2012/12/setup-wifi-raspberry-pi/ • http://wwssllabcd.github.io/blog/2013/01/31/how-to-setup-raspberry-pi/ • http://www.maketecheasier.com/set-up-raspberry-pi-as-wireless-access-point/
Source Code: Configure the wireless adapter sudonano /etc/network/interfaces • auto lo • iface lo inetloopback • iface eth0 inetdhcp • allow-hotplug wlan0 • iface wlan0 inet manual • address 192.168.0.100 • netmask 255.255.255.0 • gateway 192.168.0.1 • wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
Source Code: Install and configure a DHCP server sudoapt-getinstallisc-dhcp-server sudonano/etc/dhcp/dhcpd.conf • subnet 192.168.42.0 netmask 255.255.255.0 { • range 192.168.42.10 192.168.42.50; • option broadcast-address 192.168.42.255; • option routers 192.168.42.1; • default-lease-time 600; • max-lease-time 7200; • option domain-name "local"; • option domain-name-servers 8.8.8.8, 8.8.4.4; • } sudonano/etc/default/isc-dhcp-server Change “INTERFACES=""” to “INTERFACES="wlan0"” sudoserviceisc-dhcp-server restart
Source Code: Install and configure the access point daemon sudoapt-getinstallhostapd sudonano/etc/hostapd/hostapd.conf • interface=wlan0 • driver=nl80211 • #driver=rtl871xdrv • ssid=MyPi • hw_mode=g • channel=6 • macaddr_acl=0 • auth_algs=1 • ignore_broadcast_ssid=0 • wpa=2 • wpa_passphrase=raspberry • wpa_key_mgmt=WPA-PSK • wpa_pairwise=TKIP • rsn_pairwise=CCMP sudonano/etc/default/hostapd Remove the “#” in front of “DAEMON_CONF” and alter the line to read: DAEMON_CONF="/etc/hostapd/hostapd.conf"
Source Code: Configure IP routing between the wireless and Ethernet (or 2 Wireless Adapters) sudonano/etc/sysctl.conf Find the line which reads “Uncomment the next line to enable packet forwarding for IPv4” and uncomment the next line like this: # Uncomment the next line to enable packet forwarding for IPv4 net.ipv4.ip_forward=1 Run the following command to activate forwarding now: sudosh -c "echo 1 > /proc/sys/net/ipv4/ip_forward" Now turn the Pi into a router with the follow commands: sudoiptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE sudoiptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT sudoiptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT (如果要用兩張網卡一收一發, 就把eth0 & wlan0 改成wlan0 & wlan1) And save the routing tables into the file “/etc/iptables.ipv4.nat” sudosh -c "iptables-save > /etc/iptables.ipv4.nat” Edit “/etc/network/interfaces“: sudonano/etc/network/interfaces And add the following line to the end of the file. This line will restore the routing table whenever the Pi is booted: pre-up iptables-restore </etc/iptables.ipv4.nat