项目作者: steven112163

项目描述 :
Computer Science Project
高级语言: Java
项目地址: git://github.com/steven112163/ID-based-revised.git
创建时间: 2019-05-05T09:43:23Z
项目社区:https://github.com/steven112163/ID-based-revised

开源协议:

下载


Captive Portal for ID-based Network on mininet

Files

  1. Apache server IP: Add “ServerName 192.168.44.200” in apache2.conf and default-ssl.conf.
    ```
    $ sudo vim /etc/apache2/apache2.conf
    in /etc/apache2/apache2.conf
    219 # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
    220 ServerName 192.168.44.200

$ sudo vim /etc/apache2/sites-available/default-ssl.conf
in /etc/apache2/sites-available/default-ssl.conf
3 ServerAdmin webmaster@localhost
4 ServerName 192.168.44.200
5 DocumentRoot /var/www/html

  1. 2. Replace the content of 000-default.conf, with that of httpd.conf.

$ sudo cp ~/ID-based-master/httpd.conf /etc/apache2/sites-available/httpd.conf
$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/000-default.conf.bak
$ sudo cp /etc/apache2/sites-available/httpd.conf /etc/apache2/sites-available/000-default.conf

  1. You can find how to setup the environment in step 1 and 2 on
  2. (https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04),
  3. (https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-apache-in-ubuntu-16-04),
  4. and (https://www.digitalocean.com/community/tutorials/how-to-create-a-ssl-certificate-on-apache-for-ubuntu-14-04).
  5. 3. Copy Login directory to /var/www/html.

$ cd ID-based-master
$ sudo cp -r Login /var/www/html/Login

  1. 4. Create database and tables.

mysql> CREATE DATABASE portal CHARACTER SET utf8 COLLATE utf8_general_ci;
$ mysql -uroot -p -Dportal<~/ID-based-master/portal.sql

  1. ## Usage
  2. 1. Start ONOS.

$ cd $ONOS_ROOT
$ bazel run onos-local — clean # ok clean

  1. 2. Compile all ID-based applications and install them.

$ cd iacl-app/ # take iacl-app for example
$ mvn clean install -DskipTests
$ onos-app localhost install target/iacl-app-1.10.0.oar

  1. 3. Tell the ovsdb server to start listening on port 6640.

$ sudo ovs-vsctl set-manager tcp:127.0.0.1:6640

  1. 4. Activate `ovsdb` app and driver on ONOS.

onos> app activate org.onosproject.ovsdb org.onosproject.drivers.ovsdb

  1. You can find step 3 and 4 on [ONOS Wiki](https://wiki.onosproject.org/display/ONOS/OVSDB+interaction+and+ONOS+cli+example).
  2. 5. Modify default drivers for OVSDB (`$ONOS_ROOT/drivers/ovsdb/src/main/resources/ovsdb-drivers.xml`) to enable QoS and Queue API. Add following line at the default driver.
  1. <behaviour api="org.onosproject.net.behaviour.QosConfigBehaviour"
  2. impl="org.onosproject.drivers.ovsdb.OvsdbQosConfig"></behaviour>
  3. <behaviour api="org.onosproject.net.behaviour.QueueConfigBehaviour"
  4. impl="org.onosproject.drivers.ovsdb.OvsdbQueueConfig"></behaviour>
  1. Step 3 to 5 are required by the `ibwd-app` application.
  2. 6. Activate all ID-based applications on ONOS.

onos> app activate iacl.app ibwd.app ifwd.app

  1. 7. Configure ONOS.

$ onos-netcfg localhost net_config.json

  1. 8. Run access_db.

$ sudo python access_db.py

  1. 9. Run mininet.

$ sudo python topo.py

  1. # Captive Portal for ID-based Network on multiple VMs and physical switch
  2. There are seven virtaul machines and one switch.
  3. 1. ID-based-web (ct) IP = 192.168.20.xxx vlan 20 (for Internet) IP = 192.168.44.101 (for Intranet)
  4. 2. ID-based-service (ct) IP = 192.168.44.202
  5. 3. ID-based-portal (ct) IP = 192.168.44.200
  6. 4. ID-based-dhcp (ct) IP = 192.168.44.201
  7. 5. ID-based-controller (vm) IP = 192.168.20.xxx vlan 20 (for controll plane) IP = 192.168.44.128 (for data plane)
  8. 6. ID-based-host1 (vm) IP = dynamic IP
  9. 7. ID-based-host2 (vm) IP = dynamic IP
  10. 8. Switch (switch) IP = 192.168.20.203 ID = "of:000078321bdf7000"
  11. ## ID-based-web
  12. It's a web server and a router.
  13. 1. Configure iptables

$ iptables -t nat -A POSTROUTING -s 192.168.44.0/24 -o eth1 -j MASQUERADE
$ iptables -t filter -A FORWARD -i eth0 -o eth1 -j ACCEPT
$ iptables -t filter -A FORWARD -i eth1 -o eth0 -j ACCEPT

  1. 2. Save iptables

$ iptables-save > /etc/iptables_rules

  1. 3. Make web always start iptables and IPv4 routing on boot

$ vim /etc/rc.local
in /etc/rc.local
14 echo “1” > /proc/sys/net/ipv4/ip_forward
15 /sbin/iptables-restore < /etc/iptables_rules
16
17 exit 0

  1. 4. Copy directory Website into /var/www/html

$ cp -R ~/ID-based-revised/Website /var/www/html/Website

  1. 5. Configure apache server's document root

$ vim /etc/apache2/sites-available/000-default.conf
in /etc/apache2/sites-available/000-default.conf
11 ServerAdmin webmaster@localhost
12 DocumentRoot /var/www/html/Website

  1. 6. Restart apache server

$ systemctl restart apache2

  1. ## ID-based-service
  2. 1. Copy directory Registered into /var/www/html

$ cp -R ~/ID-based-revised/Registered /var/www/html/Registered

  1. 2. Configure apache server's document root

$ vim /etc/apache2/sites-available/000-default.conf
in /etc/apache2/sites-available/000-default.conf
11 ServerAdmin webmaster@localhost
12 DocumentRoot /var/www/html/Registered

  1. 3. Restart apaceh server

$ systemctl restart apache2

  1. ## ID-based-portal
  2. 1. Enable SSL on the apache server.

$ vim /etc/apache2/sites-available/default-ssl.conf
in /etc/apache2/sites-available/default-ssl.conf
3 ServerAdim webmaster@localhost
4 ServerName 192.168.44.200
5 DocumentRoot /var/www/html
.
.
.
25 SSLEngine on
26
27 SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
28 SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
.
.
.
105 BrowserMatch “MSIE [2-6]”\
106 nokeepalive ssl-unclean-shotdown\
107 downgrade-1.0 force-response-1.0

  1. You can find step 1 on (https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-apache-in-ubuntu-16-04).
  2. 2. Copy httpd.conf to replace 000-default.conf

$ cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/000-default.conf.bak
$ cp /etc/apache2/sites-available/httpd.conf /etc/apache2/sites-available/000-default.conf

  1. 3. Make apache server listen on port 3000

$ vim /etc/apache2/ports.conf
in /etc/apache2/ports.conf
5 Listen 80
6 Listen 3000

  1. 4. Open port 3000 on firewall

$ ufw allow 3000/tcp

  1. 5. Restart apache server

$ systemctl restart apache2

  1. ## ID-based-dhcp
  2. 1. Create a subnet for DHCP server.

$ vim /etc/dhcp/dhcpd.conf
in /etc/dhcp/dhcpd.conf
63 subnet 192.168.44.0 netmask 255.255.255.0 {
64 range 192.168.44.160 192.168.44.180;
65 option domain-name-servers 8.8.8.8;
66 option subnet-mask 255.255.255.0;
67 option routers 192.168.44.101;
68 option broadcast-address 192.168.44.255;
69 default-lease-time 20;
70 max-lease-time 60;
71 }

  1. 2. Configure which interface it should serve.

$ vim /etc/default/isc-dhcp-server
in /etc/default/isc-dhcp-server
21 INTERFACES=”eth0”

  1. 3. Restart DHCP server.

$ systemctl restart isc-dhcp-server

  1. ## ID-based-controller
  2. 1. Grant remote access privilege to 'root' for mysql.

mysql> GRANT ALL PRIVILEGES ON . TO ‘root’@’192.168.44.200’ IDENTIFIED BY ‘root’ WITH GRANT OPTION;
mysql> flush privileges;

  1. 2. Create database and tables.

mysql> CREATE DATABASE portal CHARACTER SET utf8 COLLATE utf8_general_ci;

mysql> USE portal;

mysql> CREATE TABLE IF NOT EXISTS Access_control (

  1. > `ACL_ID` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  2. > `Src_attr` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  3. > `Src_ID` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  4. > `Dst_IP` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
  5. > `Dst_port` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  6. > `Protocol` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  7. > `Permission` tinyint(1) NOT NULL,
  8. > `Priority` int(11) NOT NULL,
  9. > PRIMARY KEY (`ACL_ID`)
  10. > ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

mysql> CREATE TABLE IF NOT EXISTS Area_flow (

  1. > `ID` int(11) NOT NULL,
  2. > `Week` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
  3. > `Time_period` int(11) NOT NULL,
  4. > `Building` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  5. > `Kbps` double NOT NULL,
  6. > `Percentage` double NOT NULL,
  7. > PRIMARY KEY (`ID`)
  8. > ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

mysql> CREATE TABLE IF NOT EXISTS Flow_classification (

  1. > `ID` int(11) NOT NULL,
  2. > `User_ID` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  3. > `Week` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  4. > `Time_period` int(11) NOT NULL,
  5. > `Building` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  6. > `Room` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  7. > `Kbps` double NOT NULL,
  8. > `Day_counts` int(11) NOT NULL,
  9. > `Bwd_req` varchar(5) COLLATE utf8_unicode_ci NOT NULL,
  10. > PRIMARY KEY (`ID`)
  11. > ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

mysql> CREATE TABLE IF NOT EXISTS Group (

  1. > `Group_ID` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  2. > `Name` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
  3. > PRIMARY KEY (`Group_ID`)
  4. > ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

mysql> CREATE TABLE IF NOT EXISTS IP_MAC (

  1. > `IP` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
  2. > `MAC` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
  3. > `Time` datetime NOT NULL,
  4. > PRIMARY KEY (`IP`)
  5. > ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

mysql> CREATE TABLE IF NOT EXISTS Registered_MAC (

  1. > `MAC` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
  2. > `User_ID` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  3. > `Group_ID` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  4. > `Enable` tinyint(1) NOT NULL,
  5. > PRIMARY KEY (`MAC`)
  6. > ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

mysql> CREATE TABLE IF NOT EXISTS Switch (

  1. > `Switch_ID` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
  2. > `Building` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  3. > `Room` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  4. > PRIMARY KEY (`Switch_ID`)
  5. > ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

mysql> CREATE TABLE IF NOT EXISTS User (

  1. > `User_ID` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  2. > `Name` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
  3. > `Group_ID` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  4. > `Account` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
  5. > `Password` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
  6. > PRIMARY KEY (`User_ID`)
  7. > ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
  1. 3. Insert values into tables.

mysql> INSERT INTO Group (Group_ID, Name) VALUES

  1. > ('Guest', 'Guest'),
  2. > ('Staff', 'Staff'),
  3. > ('Student', 'Student'),
  4. > ('Teacher', 'Teacher');

mysql> INSERT INTO Switch (Switch_ID, Building, Room) VALUES

  1. > ('of:000078321bdf7000', 'Building1', 'Room1');

mysql> INSERT INTO User (User_ID, Name, Group_ID, Account, Password) VALUES

  1. > ('A', 'A', 'Teacher', 'teacher', 'teacherA'),
  2. > ('B', 'B', 'Teacher', 'teacherB', 'teacherB'),
  3. > ('C', 'C', 'Staff', 'staff', 'staffC'),
  4. > ('D', 'D', 'Student', 'student', 'studentD'),
  5. > ('E', 'E', 'Student', 'student', 'studentE'),
  6. > ('F', 'F', 'Guest', 'guest', 'guestF');

mysql> INSERT INTO Registered_MAC (MAC, User_ID, Group_ID, Enable) VALUES

  1. > ('EA:E9:78:FB:FD:00', '', '', 1),
  2. > ('EA:E9:78:FB:FD:2E', '', '', 1);
  1. 4. Enable event scheduler in mysql setting

$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
in /etc/mysql/mysql.conf.d/mysqld.cnf
27 [mysqld]
28 # add Event scheduler
29 event_scheduler = ON
30 #
31 # * Basic Settings
32 #

  1. 5. Eable event scheduler in mysql

mysql> set global event_scheduler = 1;

  1. 6. Create procedure

mysql> delimiter //
mysql> CREATE PROCEDURE login_proce

  1. > begin
  2. > DELETE FROM Registered_MAC WHERE MAC != 'EA:E9:78:FB:FD:00' OR MAC != 'EA:E9:78:FB:FD:2E';
  3. > end//

mysql> delimiter ;

  1. 7. Create event

mysql> CREATE EVENT relogin_event

  1. > ON SCHEDULE every 1 hour
  2. > ON COMPLETION PRESERVE ENABLE
  3. > DO call login_proce();
  1. 8. Modify default driver in ovsdb.

$ sudo vim $ONOS_ROOT/drivers/ovsdb/src/main/resources/ovsdb-drivers.xml
in $ONOS_ROOT/drivers/ovsdb/src/main/resources/ovsdb-drivers.xml
26
28

  1. 9. Run onos.

$ cd $ONOS_ROOT
$ bazel run onos-local — clean debug # ok clean debug

  1. 10. Tell the ovsdb to start listening on port 6640.

$ sudo ovs-vsctl set-manager tcp:127.0.0.1:6640

  1. 11. Build ifwd, ibwd, iacl and install them

$ cd ~/ID-based-revised/ifwd
$ maven clean install -DskipTests # mci -DskipTests
$ onos-app localhost install target/ifwd-app-1.10.0.oar
$ cd ~/ID-based-revised/ibwd
$ maven clean install -DskipTests # mci -DskipTests
$ onos-app localhost install target/ibwd-app-1.10.0.oar
$ cd ~/ID-based-revised/iacl
$ maven clean install -DskipTests # mci -DskipTests
$ onos-app localhost install target/iacl-app-1.10.0.oar

  1. 12. Activate three apps and ovsdb

$ onos localhost app activate org.onosproject.ovsdb org.onosproject.drivers.ovsdb org.ifwd.app org.ibwd.app org.iacl.app

  1. 13. Upload configuration JSON file

$ onos-netcfg localhost new_net_config.json

  1. 14. Start accessdb api

$ sudo python ID-based-revised/accessdb.py

  1. 15. Start shell script
  2. This script can replace step 10 to 14.

$ sh ~/ID-based-revised/installApps.sh
```

ID-based-host1 and ID-based-host2

  1. Use browser connect to www.nctu.edu.tw
  2. It will be redirected to portal(http://192.168.44.200:3000)
  3. Enter username and password(ex: teacher, teacherA)
  4. If authentication is successful, then you can access any website
  5. There is a simple website on web container(http://192.168.44.101)