利用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

相关文章

pycharm远程连接服务器运行pytorch的过程详解

《pycharm远程连接服务器运行pytorch的过程详解》:本文主要介绍在Linux环境下使用Anaconda管理不同版本的Python环境,并通过PyCharm远程连接服务器来运行PyTorc... 目录linux部署pytorch背景介绍Anaconda安装Linux安装pytorch虚拟环境安装cu

SpringBoot项目注入 traceId 追踪整个请求的日志链路(过程详解)

《SpringBoot项目注入traceId追踪整个请求的日志链路(过程详解)》本文介绍了如何在单体SpringBoot项目中通过手动实现过滤器或拦截器来注入traceId,以追踪整个请求的日志链... SpringBoot项目注入 traceId 来追踪整个请求的日志链路,有了 traceId, 我们在排

Spring Boot 3 整合 Spring Cloud Gateway实践过程

《SpringBoot3整合SpringCloudGateway实践过程》本文介绍了如何使用SpringCloudAlibaba2023.0.0.0版本构建一个微服务网关,包括统一路由、限... 目录引子为什么需要微服务网关实践1.统一路由2.限流防刷3.登录鉴权小结引子当前微服务架构已成为中大型系统的标

Java中对象的创建和销毁过程详析

《Java中对象的创建和销毁过程详析》:本文主要介绍Java中对象的创建和销毁过程,对象的创建过程包括类加载检查、内存分配、初始化零值内存、设置对象头和执行init方法,对象的销毁过程由垃圾回收机... 目录前言对象的创建过程1. 类加载检查2China编程. 分配内存3. 初始化零值4. 设置对象头5. 执行

SpringBoot整合easy-es的详细过程

《SpringBoot整合easy-es的详细过程》本文介绍了EasyES,一个基于Elasticsearch的ORM框架,旨在简化开发流程并提高效率,EasyES支持SpringBoot框架,并提供... 目录一、easy-es简介二、实现基于Spring Boot框架的应用程序代码1.添加相关依赖2.添

SpringBoot中整合RabbitMQ(测试+部署上线最新完整)的过程

《SpringBoot中整合RabbitMQ(测试+部署上线最新完整)的过程》本文详细介绍了如何在虚拟机和宝塔面板中安装RabbitMQ,并使用Java代码实现消息的发送和接收,通过异步通讯,可以优化... 目录一、RabbitMQ安装二、启动RabbitMQ三、javascript编写Java代码1、引入

JavaScript中的reduce方法执行过程、使用场景及进阶用法

《JavaScript中的reduce方法执行过程、使用场景及进阶用法》:本文主要介绍JavaScript中的reduce方法执行过程、使用场景及进阶用法的相关资料,reduce是JavaScri... 目录1. 什么是reduce2. reduce语法2.1 语法2.2 参数说明3. reduce执行过程

redis群集简单部署过程

《redis群集简单部署过程》文章介绍了Redis,一个高性能的键值存储系统,其支持多种数据结构和命令,它还讨论了Redis的服务器端架构、数据存储和获取、协议和命令、高可用性方案、缓存机制以及监控和... 目录Redis介绍1. 基本概念2. 服务器端3. 存储和获取数据4. 协议和命令5. 高可用性6.

PLsql Oracle 下载安装图文过程详解

《PLsqlOracle下载安装图文过程详解》PL/SQLDeveloper是一款用于开发Oracle数据库的集成开发环境,可以通过官网下载安装配置,并通过配置tnsnames.ora文件及环境变... 目录一、PL/SQL Developer 简介二、PL/SQL Developer 安装及配置详解1.下

在Java中使用ModelMapper简化Shapefile属性转JavaBean实战过程

《在Java中使用ModelMapper简化Shapefile属性转JavaBean实战过程》本文介绍了在Java中使用ModelMapper库简化Shapefile属性转JavaBean的过程,对比... 目录前言一、原始的处理办法1、使用Set方法来转换2、使用构造方法转换二、基于ModelMapper