利用Mininet环境-交换机转发实验整个过程
目錄
1.寫在前面
2.安裝工作
2.1.mininet安裝
2.2 cmake安裝
2.3 xterm安裝
?2.4 wireshark安裝
3.作業要求:(交換機轉發實驗)
?
4.C語言完成函數編寫工作
附件展示:
4.1??iface_info_t *lookup_port(u8 mac[ETH_ALEN]);?
4.2?void insert_mac_port(u8 mac[ETH_ALEN], iface_info_t *iface);?
4.3??int sweep_aged_mac_port_entry();?
4.4?void broadcast_packet(iface_info_t *iface, const char *packet, int len);?
4.5?void handle_packet(iface_info_t *iface, char *packet, int len);
5.驗證函數,檢驗實驗結果
5.1 在當前目錄下執行命令make,會生成一些必要的文件包括最重要的switch文件
5.2 打開mininet
5.3? 利用xterm打開s1終端,并且在s1終端中執行switch(上面生成的那個)
5.4 wireshark分別監聽h2和h3兩個主機(&表示后臺運行)
5.5 用h1 分別ping h2和h3 如果在wireshark監聽中只看到了自己節點和h1節點發送的數據,表明我們實驗成功了
1.寫在前面
這個是我們的一個課程大作業,需要組隊完成,但是奈何沒找到隊友,只有自己solo了,這個作業時間大概給了五周還是六周,但是實際上沒有太多工作量,這個是好幾個實驗選擇做的,我就多做了幾個,寫博客記錄一下自己的實驗過程。mininet這個工具我以前沒有用過,所以也出了不少問題。也算是調試的一個心理路程。
github:https://github.com/Suyebiubiu/Switch-based-Mininet
2.安裝工作
這個實驗主要是需要在linux中運行的,我的系統用的Ubuntu,mininet應該是必須要在linux中運行,可以快速搭建模擬網絡的平臺,推薦使用Ubuntu系統,版本號從14.04到最新的都可以,64位或者32位都行。如果物理機是windows系統的話,可以使用虛擬機方式安裝 Linux系統,推薦使用VirtualBox虛擬機 。運行Mininet環境時需要root權限,Mininet腳本只能使用 Python2來解釋運行
2.1.mininet安裝
?
2.2 cmake安裝
sudo apt install cmake2.3 xterm安裝
sudo apt install xterm?2.4 wireshark安裝
sudo apt install wireshark3.作業要求:(交換機轉發實驗)
?
?
?
?
4.C語言完成函數編寫工作
附件展示:
4.1??iface_info_t *lookup_port(u8 mac[ETH_ALEN]);?
mac.c中的方法
// lookup the mac address in mac_port table // FDB中尋找目的地址+port是否存在? iface_info_t *lookup_port(u8 mac[ETH_ALEN]) {// iface_info_t *iface = NULL;// fprintf(stdout, "TODO: implement this function please.\n");// return iface;iface_info_t *iface = NULL;mac_port_entry_t *entry,*q;for (int i = 0; i < HASH_8BITS; i++) {list_for_each_entry_safe(entry, q, &mac_port_map.hash_table[i], list) {int cmp = memcmp((void*)entry->mac,(void*)mac,sizeof(u8)*ETH_ALEN); //ETH_ALEN==6if(cmp==0) return entry->iface;}}return iface; }4.2?void insert_mac_port(u8 mac[ETH_ALEN], iface_info_t *iface);?
mac.c中的方法
// insert the mac -> iface mapping into mac_port table //FDB插入packet源地址+port void insert_mac_port(u8 mac[ETH_ALEN], iface_info_t *iface) {// fprintf(stdout, "TODO: implement this function please.\n");'mac_port_entry_t *entry = malloc(sizeof(mac_port_entry_t));bzero(entry, sizeof(mac_port_entry_t));time_t now = time(NULL);entry->visited = now;memcpy(entry->mac,mac,sizeof(u8)*ETH_ALEN);// memcpy(entry->iface,iface,sizeof(iface_info_t));entry->iface=iface;list_add_tail(&entry->list,&mac_port_map.hash_table[0]); //我加在第一張hash table可以? 為什么hash_table存儲了所有的entry?}4.3??int sweep_aged_mac_port_entry();?
mac.c中的方法
// sweeping mac_port table, remove the entry which has not been visited in the // last 30 seconds. int sweep_aged_mac_port_entry() {// int n = 0;// fprintf(stdout, "TODO: implement this function please.\n");// return n;int n=0;mac_port_entry_t *entry, *q;time_t now = time(NULL);for (int i = 0; i < HASH_8BITS; i++) {list_for_each_entry_safe(entry,q, &mac_port_map.hash_table[i],list) {if((int)(now - entry->visited) >= MAC_PORT_TIMEOUT){n = entry->iface->index;list_delete_entry(&entry->list);free(entry);return n;}}}return n; }4.4?void broadcast_packet(iface_info_t *iface, const char *packet, int len);?
packet.c中的方法
// broadcast the packet among all the interfaces except the one receiving the // packet, and free memory of the packet //在所有的接口中廣播(不包含當前接口) void broadcast_packet(iface_info_t *iface, char *packet, int len) {iface_info_t *tx_iface = NULL;list_for_each_entry(tx_iface, &instance->iface_list, list) {if (tx_iface->index == iface->index)continue;iface_send_packet(tx_iface, packet, len);} }4.5?void handle_packet(iface_info_t *iface, char *packet, int len);
main.c中的方法
// handle packet // 1. if the dest mac address is found in mac_port table, forward it; otherwise, // broadcast it. // 2. put the src mac -> iface mapping into mac hash table. void handle_packet(iface_info_t *iface, char *packet, int len) {//得到頭部信息struct ether_header *eh = (struct ether_header *)packet;//fdb中尋找目的地址maciface_info_t *tx_iface = lookup_port(eh->ether_dhost);if (tx_iface) {iface_send_packet(tx_iface, packet, len);}else {broadcast_packet(iface, packet, len);}//存入源mac+portif (!lookup_port(eh->ether_shost)) {insert_mac_port(eh->ether_shost, iface);} }?
5.驗證函數,檢驗實驗結果
5.1 在當前目錄下執行命令make,會生成一些必要的文件包括最重要的switch文件
5.2 打開mininet
5.3? 利用xterm打開s1終端,并且在s1終端中執行switch(上面生成的那個)
5.4 wireshark分別監聽h2和h3兩個主機(&表示后臺運行)
5.5 用h1 分別ping h2和h3 如果在wireshark監聽中只看到了自己節點和h1節點發送的數據,表明我們實驗成功了
?
大功告成!撒花??ヽ(°▽°)ノ?!!!!!!!!!!!!!!!!!
?
總結
以上是生活随笔為你收集整理的利用Mininet环境-交换机转发实验整个过程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Red5 java项目创建
- 下一篇: mediawiki php7,cento