如何使用自动化构造随机路由模型

news2025/2/21 23:12:38

为什么要仿真随机路由?

路由器测试中,为了最大程度还原现网路由情况,评估路由器在现网环境下稳定工作各项指标,需要对导入路由进行离散仿真,目前路由仿真可分为导入路由与生成路由两种方式,导入路由需要现网路由表导入,本文讨论重点为生成路由方式。

自动化生成路由能解决什么问题?

使用用户界面生成路由时,可根据离散模型生成路由,但生成路由与现网路由相比,只注重路由段离散,未体现AsPath、Community等BGP路由参数离散,使用自动化生成路由可根据定义规则进行生成。

如何使用自动化生成随机路由

信而泰Renix平台提供了python API接口,可使用python API进行路由灵活定义。假设路由需求如下:配置Port口1个,包含20个IBGP,个IBGP通告10个路由段、共10wIPv4+10wIPv6路由,要求路由掩码随机选择,AsPath随机选择、Connmity随机选择。
本文选择基础API使用信而泰API(renix_py_api、MiscLibrary),不另做定义,使用时需安装相关环境。代码解析如下:

导入相关库

#!/usr/bin/python

-- coding: UTF-8 -

import time
from renix_py_api.renix import *
from MiscLibrary.base import *
import logging
import random
import re

初始化Python环境及定义参数

if name == ‘main’:
# 初始化环境
print(‘######################初始化环境######################’)
print(time.strftime(‘%Y-%m-%d %H:%M:%S’, time.localtime(time.time())))
###############################################################
api = MiscAPI()
initialize(log=True, log_level=logging.INFO, log_handle=LogHandle.LOG_FILE)
###############################################################
# 占用测试仪端口
chassis_DY = “10.1.1.7”
port_DY_1 = “//10.1.1.7/3/1”
# 路由起始地址
start_ip1 = “20.0.0.0”
start_ipv61 = “2023::”
#bgp路由参数
RgpSessionCount = 20
BgpRouteBlock = 10
BgpRouteBlockv6 = 10
ipv4routecount = 100000
ipv6routecount = 100000
#ipv4路由掩码
MaskMin = 20
MaskMax = 30
# ipv6路由掩码
PrefixMin = 80
PrefixMax = 120
# bgp as_path&community限制
AsPathMaxLength = 8
CommunityMaxLength = 8
###############################################################
#其它参数
Ipv4RoutePerSession = int(ipv4routecount / RgpSessionCount)
ipv6PrefixPerSession = int(ipv6routecount / RgpSessionCount)
Ipv4CountRandonMax = int(Ipv4RoutePerSession / BgpRouteBlock)
Ipv4CountRandonMin = int(Ipv4CountRandonMax * 0.5)
Ipv6CountRandonMax = int(ipv6PrefixPerSession / BgpRouteBlockv6)
Ipv6CountRandonMin = int(Ipv6CountRandonMax * 0.5)
print(‘######################初始化完成######################’)
print(time.strftime(‘%Y-%m-%d %H:%M:%S’, time.localtime(time.time())))

创建端口及映射机箱

print(‘#######################连接机箱#######################’)
print(time.strftime(‘%Y-%m-%d %H:%M:%S’, time.localtime(time.time())))
sys_entry = get_sys_entry()
sys_entry.edit(ProductType=1)
chassis = ConnectChassisCommand(chassis_DY)
# chassis.execute()
# 占用端口、端口上线
port_1 = Port(upper=sys_entry, Location=port_DY_1, name=‘port_1’)
# BringPortsOnlineCommand(PortList=[port_1.handle,port_2.handle]).execute()
print(‘######################连接成功!######################’)
print(time.strftime(‘%Y-%m-%d %H:%M:%S’, time.localtime(time.time())))
print(‘#######################创建IBGP#######################’)
print(time.strftime(‘%Y-%m-%d %H:%M:%S’, time.localtime(time.time())))
# 参数生成器定义
GeneratorRouteridv4 = api.address_modifier(Start=r’192.168.0.1’, Step=1, Count=1000, Offset=0)
GeneratorRouteridv6 = api.address_modifier(Start=r’192:168::1’, Step=1, Count=1000, Offset=0)
GeneratorMacAddress = api.address_modifier(Start=r’00:10:94:00:00:01’, Step=1, Count=1000, Offset=0)
GeneratorIPv4Address = api.address_modifier(Start=r’10.0.0.2’, Step=1, Count=1000, Offset=8)
GeneratorIPv6Address = api.address_modifier(Start=r’2000::2’, Step=1, Count=1000, Offset=80)
#接口生成interface
for x in range(RgpSessionCount):
#接口参数定义
Routeridv4 = api.generator_next(GeneratorRouteridv4)
Routeridv6 = api.generator_next(GeneratorRouteridv6)
MacAddr = api.generator_next(GeneratorMacAddress)
IPv4Addr = api.generator_next(GeneratorIPv4Address)
IPv6Addr = api.generator_next(GeneratorIPv6Address)
IPv4GWAddr = api.ipv4_address_hopping(IPv4Addr, Mask=32, Type=‘decrement’, Step=1)
IPv6GWAddr = api.ipv6_address_hopping(IPv6Addr, Mask=128, Type=‘decrement’, Step=1)
# 创建IPv4接口
interface = Interface(upper=port_1, RouterId = Routeridv4, Ipv6RouterId = Routeridv6)
Interface_temp = “Interface_” + str(x+1)
build_Dual = BuildInterfaceCommand(InterfaceList=Interface_temp, NetworkLayers=[‘eth’, ‘vlan’], TopLayers=[‘ipv4’, ‘ipv6’])
build_Dual.execute()
eth_layer = interface.get_children(‘EthIILayer’)[0]
eth_layer.edit(Address = MacAddr)
vlan_layer = interface.get_children(‘VlanLayer’)[0]
vlan_layer.edit(VlanId = x+1 )
ipv4_layer = interface.get_children(‘Ipv4Layer’)[0]
ipv4_layer.edit(Address = IPv4Addr , Gateway=IPv4GWAddr)
ipv6_layer = interface.get_children(‘Ipv6Layer’)[0]
ipv6_layer.edit(Address = IPv6Addr , Gateway=IPv6GWAddr)

创建BGP协议及路由

创建BGP协议

    BgpSession = BgpProtocolConfig(upper=port_1)
    BgpSession.edit(AsNumber=65000)
    BgpSession.edit(DutAsNumber=65000)
    BgpSession.edit(UseGatewayAsDutIp=False)
    BgpSession.edit(DutIpv4Address=IPv4GWAddr)
    BgpSession.edit(DutIpv6Address=IPv6GWAddr)
    # 绑定Dual接口和协议
    select_interface = SelectInterfaceCommand(ProtocolList=[BgpSession.handle], InterfaceList=[interface.handle])
    select_interface.execute()
    # IPv4路由block创建
    FirstRoute = start_ip1
    Ipv4RouteCount = 0
    for y in range(BgpRouteBlock):
        mask = random.randint(MaskMin, MaskMax)
        if y == BgpRouteBlock-1:
            RouteCount = Ipv4RoutePerSession - Ipv4RouteCount
        else:
            RouteCount = random.randint(Ipv4CountRandonMin, Ipv4CountRandonMax)
        Ipv4RouteCount = Ipv4RouteCount+RouteCount
        offset = 32 - mask
        if x == 0 and y == 0:
            # bgp参数修改
            BgpRoute = BgpIpv4RoutepoolConfig(upper=BgpSession)
            BgpRoute.get()
            BgpRoute.edit(FirstRoute=FirstRoute)
            BgpRoute.edit(PrefixLength=mask)
            BgpRoute.edit(RouteCount=RouteCount)
            GeneratorIPv4Route = api.address_modifier(Start=FirstRoute, Step=RouteCount, Offset=offset, Count=1000)
            IPv4Route = api.generator_next(GeneratorIPv4Route)
            IPv4Route = api.generator_next(GeneratorIPv4Route)
        else:
            BgpRoute = BgpIpv4RoutepoolConfig(upper=BgpSession)

BgpRoute.get()
BgpRoute.edit(FirstRoute=IPv4Route)
BgpRoute.edit(PrefixLength=mask)
BgpRoute.edit(RouteCount=RouteCount)
Start = IPv4Route
GeneratorIPv4Route = api.address_modifier(Start=Start, Step=RouteCount, Offset=offset, Count=1000)
IPv4Route = api.generator_next(GeneratorIPv4Route)
IPv4Route = api.generator_next(GeneratorIPv4Route)
# bgp参数修改
as_path_length = random.randint(2, AsPathMaxLength)
community_length = random.randint(2, CommunityMaxLength)
as_path_list = list()
community_list = list()
AsPathIncrement_list = list()
as_path_tem = str()
community_tem = str()
communityIncrement_list = list()
for z in range(as_path_length):
as_path = random.randint(300, 64000)
as_path_list.append(as_path)
for z in range(community_length):
community1 = random.randint(1, 65535)
community2 = random.randint(1, 65535)
community = str(community1) + ‘:’ + str(community2)
community_list.append(community)
for i in range(len(community_list) - 1):
community = community_list[i]
community_tem += community
community_tem += ‘,’
community_tem += str(community_list[-1])
AsPathPerBlockCount = int(RouteCount / 6.5)
for z in range(len(as_path_list)):
AsPathIncrement_list.append(1)
for z in range(len(community_list)):
Temp = str(1) + ‘:’ + str(1)
communityIncrement_list.append(Temp)
BgpRoute.edit(AsPath=as_path_list)
BgpRoute.edit(AsPathIncrement=AsPathIncrement_list)
BgpRoute.edit(AsPathPerBlockCount=AsPathPerBlockCount)
BgpRoute.edit(Community=community_tem)
BgpRoute.edit(CommunityIncrement=communityIncrement_list)
BgpRoute.edit(CommunityPerBlockCount=AsPathPerBlockCount)
# IPv6路由block创建
FirstPrefix = start_ipv61
Ipv6PrefixCount = 0
for y in range(BgpRouteBlockv6):
mask = random.randint(PrefixMin, PrefixMax)

        if y == BgpRouteBlockv6 - 1:
            RouteCount = ipv6PrefixPerSession - Ipv6PrefixCount
        else:
            RouteCount = random.randint(Ipv6CountRandonMin, Ipv6CountRandonMax)
        Ipv6PrefixCount = Ipv6PrefixCount + RouteCount
        offset = 128 - mask
        if x == 0 and y == 0:
            # bgp参数修改
            BgpRoute = BgpIpv6RoutepoolConfig(upper=BgpSession)
            BgpRoute.get()
            BgpRoute.edit(FirstIpv6Route=FirstPrefix)
            BgpRoute.edit(PrefixLength=mask)
            BgpRoute.edit(RouteCount=RouteCount)
            GeneratorIPv6Route = api.address_modifier(Start=FirstPrefix, Step=RouteCount, Offset=offset, Count=1000)
            IPv6Prefix = api.generator_next(GeneratorIPv6Route)
            IPv6Prefix = api.generator_next(GeneratorIPv6Route)
              else:
            BgpRoute = BgpIpv6RoutepoolConfig(upper=BgpSession)
            BgpRoute.get()
            BgpRoute.edit(FirstIpv6Route=IPv6Prefix)
            BgpRoute.edit(PrefixLength=mask)
            BgpRoute.edit(RouteCount=RouteCount)
            Start = IPv6Prefix
            GeneratorIPv6Route = api.address_modifier(Start=Start, Step=RouteCount, Offset=offset, Count=1000)
            IPv6Prefix = api.generator_next(GeneratorIPv6Route)
            IPv6Prefix = api.generator_next(GeneratorIPv6Route)
            # bgp参数修改
        as_path_length = random.randint(2, AsPathMaxLength)
        community_length = random.randint(2, CommunityMaxLength)
        as_path_list = list()
        community_list = list()
        AsPathIncrement_list = list()
        as_path_tem = str()
        community_tem = str()
        communityIncrement_list = list()
        for z in range(as_path_length):
            as_path = random.randint(300, 64000)
            as_path_list.append(as_path)
        for z in range(community_length):
            community1 = random.randint(1, 65535)
            community2 = random.randint(1, 65535)
            community = str(community1) + ':' + str(community2)
            community_list.append(community)
        for i in range(len(community_list) - 1):
            community = community_list[i]
            community_tem += community
            community_tem += ','
        community_tem += str(community_list[-1])
        AsPathPerBlockCount = int(RouteCount / 6.5)
         for z in range(len(as_path_list)):
            AsPathIncrement_list.append(1)
        for z in range(len(community_list)):
            Temp = str(1) + ':' + str(1)
            communityIncrement_list.append(Temp)
        BgpRoute.edit(AsPath=as_path_list)
        BgpRoute.edit(AsPathIncrement=AsPathIncrement_list)
        BgpRoute.edit(AsPathPerBlockCount=AsPathPerBlockCount)
        BgpRoute.edit(Community=community_tem)
        BgpRoute.edit(CommunityIncrement=communityIncrement_list)
        BgpRoute.edit(CommunityPerBlockCount=AsPathPerBlockCount)
# Save the test case to D:\ as the name of bgp_random.xcfg
save_case = SaveTestCaseCommand(TestCase='D/:bgp_random.xcfg', ProductType=1)

随机路由生成测试

执行代码后,生成配置如下:

  • 接口参数:
    在这里插入图片描述
    在这里插入图片描述
  • BGP Session
    在这里插入图片描述
  • IPv4路由
    随机变化点:路由数量、路由前缀长度、AsPath、AsPath跳变步长、AsPath数量、Community、Community跳变步长、Community数量
    在这里插入图片描述
    在这里插入图片描述
  • IPv6路由
    随机变化点:路由数量、路由前缀长度、AsPath、AsPath跳变步长、AsPath数量、Community、Community跳变步长、Community数量
    在这里插入图片描述
    在这里插入图片描述

DarYu-X系列测试仪

DarYu-X系列高性能网络测试仪是信而泰推出的面向高端路由器等高端数通设备的测试产品,具有高性能、高密度、高速率等特点,配置信而泰基于PCT架构的新一代测试软件RENIX和X系列测试模块,可为提供路由哭喊组网测试解决方案,为建立一张高SLA保证、确定性时延、业务感知、灵活业务路径调优的下一代网络保驾护航。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/765615.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

S3C2440使用GPIO输入功能控制按键

文章目录 前言一、设置GPIO输入模式二、检测开关1.配置功能2.具体实现 总结 前言 由于上期分享的使用GPIO去控制引脚输出模式点亮LED,那么本期主要介绍一下使用GPIO设置为输入模式,用到的硬件有板载的按键;开发环境也是依赖于S3C2440开发板&…

Hyper-V安装Ubuntu-18.04

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言一、准备工作?二、下载指定的Ubuntu ISO镜像三、开始配置1.点击快速创建2.选择安装源 四、开始安装五、配置启动项总结 前言 最近有个很扯淡的问题…

Linux 学习记录51(ARM篇)

Linux 学习记录51(ARM篇) 本文目录 Linux 学习记录51(ARM篇)一、计算机的组成二、编译的原理三、指令和指令集1. 机器指令2. 汇编指令3. 指令集(1. RISC:精简指令集(2. CISC:复杂指令集(3. 精简指令集补充 四、ARM相关介绍1. Arm发展简介2. ARM架构3. AR…

仓库管理系统到底包括哪些方面?

仓库管理系统到底包括哪些方面? 1)入库 采购产品到货后,需要进行入库处理。填写采购单号,供应商信息,仓库信息,以及入库明细,提交流程完成入库登记。 “入库明细”中选择货品编码后&#xff…

四阶龙格-库塔方法matlab程序与误差对比

四阶龙格-库塔方法matlab程序与误差对比 简介参考code四阶龙格-库塔函数微分方程函数主程序 结果分析 简介 本例子函数参考了【1】中的函数,增加了解析方法的函数与四阶龙格-库塔方法对比,并计算了百分比误差,最大误差在0.3%左右。 参考 【…

网站创建002:head内容

一个html网站&#xff0c;包括html根、head头、body身体 首先来看head&#xff0c;head操作的是页签标题&#xff0c;如下 1、给head添加图标&#xff0c;如下 <link rel"icon" href"C:\Users\86158\Desktop\网站创建\favicon.ico">2、给网站添加搜索…

Python测试框架Pytest的基础入门

Pytest简介 Pytest is a mature full-featured Python testing tool that helps you write better programs.The pytest framework makes it easy to write small tests, yet scales to support complex functional testing for applications and libraries. 通过官方网站介绍…

依赖注入三种方式,以及传统xml文件传参,还包括@Bean方式传参,还有Resource注入(详细版,每步都有提及)

获取bean对象&#xff0c;也称为对象装配&#xff0c;对象注入&#xff0c;依赖注入。 对象装配的实现方法有3种&#xff1a; 1.属性注入&#xff1b; 2.构造方法注入&#xff1b; 3.Setter注入。 再讲本节内容之前&#xff0c;我们先来提两个传参的方式&#xff0c;首先呢…

Twitter重新突围或许借助国产技术是个好办法

Meta公司近期推出的Threads 被网友戏称为“Twitter杀手”&#xff0c;该应用上线仅一天&#xff0c;用户就突破了3000 万人。外界普遍认为&#xff0c;这是推特上线17年来遭遇的最严峻危机。面对扎克伯格来势汹汹的挑战马斯克会如何快速组织反击&#xff1f; 前段时间闹得沸沸扬…

想要提高产品使用率?掌握以下关键策略,让你的用户爱不释手!

如果你的产品已经推出市场&#xff0c;但你发现用户的使用率并不如你预期的那样高。你想知道如何提高产品的使用率&#xff0c;并让更多的用户喜欢和频繁使用你的产品吗&#xff1f;别担心&#xff0c;你可以采取一些策略来提高产品的使用率并让用户更愿意使用它。 1. 了解你的…

el-date-picker组件的picker-options常规属性设置

查询已发生的配置项 // 日期选择器快捷键配置&#xff08;一般过去时&#xff09; pickerOptions: {shortcuts: [{text: 今天,onClick(picker) {let start new Date();let end new Date();picker.$emit(pick, [start, end]);}},{text: 昨天,onClick(picker) {let start new…

【高阶数据结构】——并查集

文章目录 并查集的原理并查集的实现并查集的应用 并查集的原理 在一些应用问题中&#xff0c;需要将n个不同的元素划分成一些不相交的集合。开始时&#xff0c;每个元素自成一个单元素集合, 然后按一定的规律将归于同一组元素的集合合并。在此过程中要反复用到查询某一个元素归…

msvcp140.dll丢失的4种解决方法,快速修复msvcp140.dll文件

msvcp140.dll丢失在所有的dll文件丢失里面&#xff0c;也算是经常丢失的老油条了&#xff0c;我们应该对它都不陌生吧&#xff0c;不过直到今天都还有人不知道怎么修复msvcp140.dll文件&#xff0c;小编觉得非常有必要来给大家详细的说说吧&#xff0c;聊一下msvcp140.dll丢失的…

Linux·gdb调试命令和使用方法

基本命令 调试未运行的程序 $ gdb helloworld Reading symbols from helloWorld...(no debugging symbols found)...done. 如果没有调试信息&#xff0c;会提示no debugging symbols found。 如果是下面的提示&#xff1a; Reading symbols from helloWorld...done. 则可以…

Windows11 环境下 Nginx 安装部署教程

一、Nginx 介绍 Nginx (engine x) 是一个高性能的HTTP和反向代理服务器&#xff0c;也是一个IMAP/POP3/SMTP服务器。Nginx 是一种轻量级的Web服务器&#xff0c;可以作为独立的服务器部署网站&#xff08;类似Tomcat&#xff09;&#xff0c;应用非常广泛&#xff0c;特别是现…

【method】ADMM-CSNet | 一种图像压缩感知重建的深度学习方法(1)- 方法解析

#! https://zhuanlan.zhihu.com/p/644157062 【method】ADMM-CSNet | 一种图像压缩感知重建的深度学习方法&#xff08;1&#xff09;- 方法解析 文章目录 【method】ADMM-CSNet | 一种图像压缩感知重建的深度学习方法&#xff08;1&#xff09;- 方法解析摘要广义压缩感知模型…

用宏定义完成整数的二进制位的奇偶位互换

代码如下&#xff1a; #include <stdio.h> #define SWAP(num) (((num & 0xAAAAAAAA) >> 1) | ((num & 0x55555555) << 1))int main() {int num 1010;printf("%d\n", num);printf("%d\n", SWAP(num));return 0; }思路如下&…

麒麟v10部署Nginx

1.解压&#xff1a;tar -xvf nginx-1.18.0.tar.gz 2.进入目录&#xff1a;cd nginx并执行脚本./configure 3.执行make 4.执行make install 5.安装目录在&#xff1a;/usr/local/nginx&#xff0c;然后再进入/usr/local/nginx/sbin启动nginx服务&#xff0c;执行./nginx&a…

3Ds max材质制作教程:创建金、银、铜金属材质

推荐&#xff1a; NSDT场景编辑器助你快速搭建可二次开发的3D应用场景 如果您不想完成本教程中的所有步骤&#xff0c;可以通过本教程底部的链接下载 3D Studio Max 的 matlib &#xff08;.mat&#xff09; 文件。 注意&#xff1a;单击每个步骤中的缩略图可查看更大的屏幕截…