利用Mininet环境-交换机转发实验整个过程

2024-02-28 05:58

本文主要是介绍利用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 cmake

2.3 xterm安装

sudo apt install xterm

 2.4 wireshark安装

sudo apt install wireshark

3.作业要求:(交换机转发实验)

 

 

 

 

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环境-交换机转发实验整个过程的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/754558

相关文章

Django HTTPResponse响应体中返回openpyxl生成的文件过程

《DjangoHTTPResponse响应体中返回openpyxl生成的文件过程》Django返回文件流时需通过Content-Disposition头指定编码后的文件名,使用openpyxl的sa... 目录Django返回文件流时使用指定文件名Django HTTPResponse响应体中返回openp

Linux线程同步/互斥过程详解

《Linux线程同步/互斥过程详解》文章讲解多线程并发访问导致竞态条件,需通过互斥锁、原子操作和条件变量实现线程安全与同步,分析死锁条件及避免方法,并介绍RAII封装技术提升资源管理效率... 目录01. 资源共享问题1.1 多线程并发访问1.2 临界区与临界资源1.3 锁的引入02. 多线程案例2.1 为

批量导入txt数据到的redis过程

《批量导入txt数据到的redis过程》用户通过将Redis命令逐行写入txt文件,利用管道模式运行客户端,成功执行批量删除以Product*匹配的Key操作,提高了数据清理效率... 目录批量导入txt数据到Redisjs把redis命令按一条 一行写到txt中管道命令运行redis客户端成功了批量删除k

分布式锁在Spring Boot应用中的实现过程

《分布式锁在SpringBoot应用中的实现过程》文章介绍在SpringBoot中通过自定义Lock注解、LockAspect切面和RedisLockUtils工具类实现分布式锁,确保多实例并发操作... 目录Lock注解LockASPect切面RedisLockUtils工具类总结在现代微服务架构中,分布

Win10安装Maven与环境变量配置过程

《Win10安装Maven与环境变量配置过程》本文介绍Maven的安装与配置方法,涵盖下载、环境变量设置、本地仓库及镜像配置,指导如何在IDEA中正确配置Maven,适用于Java及其他语言项目的构建... 目录Maven 是什么?一、下载二、安装三、配置环境四、验证测试五、配置本地仓库六、配置国内镜像地址

SpringBoot多环境配置数据读取方式

《SpringBoot多环境配置数据读取方式》SpringBoot通过环境隔离机制,支持properties/yaml/yml多格式配置,结合@Value、Environment和@Configura... 目录一、多环境配置的核心思路二、3种配置文件格式详解2.1 properties格式(传统格式)1.

Python实现网格交易策略的过程

《Python实现网格交易策略的过程》本文讲解Python网格交易策略,利用ccxt获取加密货币数据及backtrader回测,通过设定网格节点,低买高卖获利,适合震荡行情,下面跟我一起看看我们的第一... 网格交易是一种经典的量化交易策略,其核心思想是在价格上下预设多个“网格”,当价格触发特定网格时执行买

python设置环境变量路径实现过程

《python设置环境变量路径实现过程》本文介绍设置Python路径的多种方法:临时设置(Windows用`set`,Linux/macOS用`export`)、永久设置(系统属性或shell配置文件... 目录设置python路径的方法临时设置环境变量(适用于当前会话)永久设置环境变量(Windows系统

python运用requests模拟浏览器发送请求过程

《python运用requests模拟浏览器发送请求过程》模拟浏览器请求可选用requests处理静态内容,selenium应对动态页面,playwright支持高级自动化,设置代理和超时参数,根据需... 目录使用requests库模拟浏览器请求使用selenium自动化浏览器操作使用playwright

Mysql中设计数据表的过程解析

《Mysql中设计数据表的过程解析》数据库约束通过NOTNULL、UNIQUE、DEFAULT、主键和外键等规则保障数据完整性,自动校验数据,减少人工错误,提升数据一致性和业务逻辑严谨性,本文介绍My... 目录1.引言2.NOT NULL——制定某列不可以存储NULL值2.UNIQUE——保证某一列的每一