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

2023/8/11 10:36:35 作者:信而泰发布企业:北京信而泰科技有限公司 市场部[打印]

为什么要仿真随机路由

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

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

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

 


下面给大家讲解一下:

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

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


导入相关库

import time

from import *

from import *

import logging

import random

import re

初始化Python环境及定义参数


初始化Renix相关Python参数外,定义生成BGP路由的相关参数,其中包括IPv4/IPv6相关变化点路由数量、起始路由、掩码/前缀、AsPath、Community,设备各变化点取值范围。

api = MiscAPI()

    initialize(log=True, log_level=, log_handle=_FILE)

    chassis_DY = ""

    port_DY_1 = "///3/1"

    start_ip1 = ""

    start_ipv61 = "2023::"

    BgpSessionCount = 20

    BgpRouteBlock = 10

    BgpRouteBlockv6 = 10

    ipv4routecount = 100000

    ipv6routecount = 100000

    MaskMin = 20

    MaskMax = 30

    PrefixMin = 80

    PrefixMax = 120

    AsPathMaxLength = 8

    CommunityMaxLength = 8

    Ipv4RoutePerSession = int(ipv4routecount / BgpSessionCount)

    ipv6PrefixPerSession = int(ipv6routecount / BgpSessionCount)

    Ipv4CountRandonMax = int(Ipv4RoutePerSession / BgpRouteBlock)

    Ipv4CountRandonMin = int(Ipv4CountRandonMax * 0.5)

    Ipv6CountRandonMax = int(ipv6PrefixPerSession / BgpRouteBlockv6)

Ipv6CountRandonMin = int(Ipv6CountRandonMax * 0.5)


创建端口及映射机箱


如有对应仪表机框时,可按以下执行,如生成离线配置,可注释e()和BringPortsOnlineCommand(PortList=[]).execute()语句。

    sys_entry = get_sys_entry()

    (ProductType=1)

    chassis = ConnectChassisCommand(chassis_DY)

    e()

    port_1 = Port(upper=sys_entry, Location=port_DY_1, name=39;port_139;)

    BringPortsOnlineCommand(PortList=[]).execute()


参数生成器定义


主要定义RouterId、IPv6RouterId、Mac、IPv4、IPv6生成器,接口相关参数均按偏移(Offset)变化。RouterId、IPv6RouterId、Mac均按递增1变化( Offset=0,Step=1),IPv4按掩码24位递增1变化( Offset=8,Step=1),IPv6按掩码80位递增1变化( Offset=80,Step=1)

    GeneratorRouteridv4 = s_modifier(Start=r39;39;, Step=1, Count=1000, Offset=0)

    GeneratorRouteridv6 = s_modifier(Start=r39;192:168::139;, Step=1, Count=1000, Offset=0)

    GeneratorMacAddress = s_modifier(Start=r39;00:10:94:00:00:0139;, Step=1, Count=1000, Offset=0)

    GeneratorIPv4Address = s_modifier(Start=r39;39;, Step=1, Count=1000, Offset=8)

GeneratorIPv6Address = s_modifier(Start=r39;2000::239;, Step=1, Count=1000, Offset=80)


接口生成interface&BgpSession

接口生成时,主要变化点为RouterId、IPv6RouterId、Mac、IPV4、IPv6、IPv4GW、IPv6GW变化,接口数量与BGPSessionCount一一对应,注意单接口下生成多个interface时,启用子接口模式,对应仪表变化则为Vlan变化
实现代码参数以下,相关生成器定义已在上文讨论,本循环使用tor_next()生成对连接变化点。

for x in range(BgpSessionCount):

#Interface生成部分代码

        Routeridv4 = tor_next(GeneratorRouteridv4)

        Routeridv6 = tor_next(GeneratorRouteridv6)

        MacAddr = tor_next(GeneratorMacAddress)

        IPv4Addr = tor_next(GeneratorIPv4Address)

        IPv6Addr = tor_next(GeneratorIPv6Address)

        IPv4GWAddr = 4_address_hopping(IPv4Addr, Mask=32, Type=39;decrement39;, Step=1)

        IPv6GWAddr = 6_address_hopping(IPv6Addr, Mask=128, Type=39;decrement39;, Step=1)

        interface = Interface(upper=port_1, RouterId = Routeridv4, Ipv6RouterId = Routeridv6)

        Interface_temp = "Interface_" + str(x+1)

        build_Dual = BuildInterfaceCommand(InterfaceList=Interface_temp, NetworkLayers=[39;eth39;, 39;vlan39;], TopLayers=[39;ipv439;, 39;ipv639;])

        e()

        eth_layer = _children(39;EthIILayer39;)[0]

        (Address = MacAddr)

        vlan_layer = _children(39;VlanLayer39;)[0]

        (VlanId = x+1 )

        ipv4_layer = _children(39;Ipv4Layer39;)[0]

        (Address = IPv4Addr , Gateway=IPv4GWAddr)

        ipv6_layer = _children(39;Ipv6Layer39;)[0]

        (Address = IPv6Addr , Gateway=IPv6GWAddr)

★生成Interface效果下图所示:


BepSession生成


由于BgpSession与interface存在一一对应关系,所以可在同一个循环下生成BgpSession并绑定Interface。以下代码以上部分代码同处一个循环(for x in range(BgpSessionCount):)。

for x in range(BgpSessionCount):

...

        BgpSession = BgpProtocolConfig(upper=port_1)

        (AsNumber=65000)

        (DutAsNumber=65000)

        (UseGatewayAsDutIp=False)

        (DutIpv4Address=IPv4GWAddr)

        (DutIpv6Address=IPv6GWAddr)

        select_interface = SelectInterfaceCommand(ProtocolList=[], InterfaceList=[])

        e()

★生成Bgp效果下图所示:


IPv4路由生成


为每个BgpSession生成若干条RouteBlock,所以可在同一个循环下生成RouteBlock并绑定BgpSession。以下代码以上部分代码同处一个循环(for x in range(BgpSessionCount):),每个BgpSession生成的RouteBlock数量由BgpRouteBlock决定并循环执行,相关变化点包括路由数量、起始路由、掩码、AsPath、AsPath跳变长度、每个路由组AsPath数量、Community、Community跳变长度、每个路由组Community数量,其中路由数量、掩码、AsPath、Community为Random值,起始路由、AsPath跳变长度、每个路由组AsPath数量、Community跳变长度、每个路由组Community数量为对应变化:

起始路由:第1条路由填入定义的起始路由,2~n条按上一条路由的起始路由、路由数量、掩码生成对应的起始路由,每条路由组路由数量、掩码均使用t生成随机数。

AsPath:按约定的最大AsPath长度生成随机长度,并根据长度生成对应随机AsPath,AsPath跳变长度均为1:1,AsPath跳变长度根据路由数量取值

Community:变化与AsPath类似。

具体实现代码如下:

for x in range(BgpSessionCount):

...

        FirstRoute = start_ip1

        Ipv4RouteCount = 0

        for y in range(BgpRouteBlock):

            mask = t(MaskMin, MaskMax)

            if y == BgpRouteBlock-1:

                RouteCount = Ipv4RoutePerSession - Ipv4RouteCount

            else:

                RouteCount = t(Ipv4CountRandonMin, Ipv4CountRandonMax)

            Ipv4RouteCount = Ipv4RouteCount+RouteCount

            offset = 32 - mask

            if x == 0 and y == 0:

                BgpRoute = BgpIpv4RoutepoolConfig(upper=BgpSession)

                ()

                (FirstRoute=FirstRoute)

                (PrefixLength=mask)

                (RouteCount=RouteCount)

                GeneratorIPv4Route = s_modifier(Start=FirstRoute, Step=RouteCount, Offset=offset, Count=1000)

                IPv4Route = tor_next(GeneratorIPv4Route)

                IPv4Route = tor_next(GeneratorIPv4Route)

            else:

                BgpRoute = BgpIpv4RoutepoolConfig(upper=BgpSession)

                ()

                (FirstRoute=IPv4Route)

                (PrefixLength=mask)

                (RouteCount=RouteCount)

                Start = IPv4Route

                GeneratorIPv4Route = s_modifier(Start=Start, Step=RouteCount, Offset=offset, Count=1000)

                IPv4Route = tor_next(GeneratorIPv4Route)

                IPv4Route = tor_next(GeneratorIPv4Route)

            as_path_length = t(2, AsPathMaxLength)

            community_length = t(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 = t(300, 64000)

                (as_path)

            for z in range(community_length):

                community1 = t(1, 65535)

                community2 = t(1, 65535)

                community = str(community1) + 39;:39; + str(community2)

                (community)

            for i in range(len(community_list) - 1):

                community = community_list[i]

                community_tem += community

                community_tem += 39;,39;

            community_tem += str(community_list[-1])

            AsPathPerBlockCount = int(RouteCount / 6.5)

            for z in range(len(as_path_list)):

                (1)

            for z in range(len(community_list)):

                Temp = str(1) + 39;:39; + str(1)

                (Temp)

            (AsPath=as_path_list)

            (AsPathIncrement=AsPathIncrement_list)

            (AsPathPerBlockCount=AsPathPerBlockCount)

            (Community=community_tem)

            (CommunityIncrement=communityIncrement_list)

            (CommunityPerBlockCount=AsPathPerBlockCount)

       ★生成IPv4路由BgpRouteBlock效果图如下所示:


IPv6路由生成


IPv6路由生成方法与IPv4一致,实现参考上文代码。

    生成IPv6 BgpRouteBlock效果图如下所示:


保存Renix平台对应XCFG

执行以上代循环代码后,用以下代码生成对应配置,其中ProductType=1代表Daryu系列产品

    save_case = SaveTestCaseCommand(TestCase=39;D:\39;, ProductType=1)

    e()


适用产品—DarYu-X系列


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


关键字:自动化测试,网络测试仪,仿真路由
免责声明:以上所展示的信息由网友自行发布,内容的真实性、准确性和合法性由发布者负责。行业信息网对此不承担任何保证责任。任何单位或个人如对以上内容有权利主张(包括但不限于侵犯著作权、商业信誉等),请与我们联系并出示相关证据,我们将按国家相关法规即时移除。

其他新闻

关于我们 | 服务条款 | 网站指南 | 免责声明 | 友情链接 | 给我们留言
红盾
COPYRIGHT @ 2001-2017 CNlinfo.net ALL RIGHTS RESERVED
深圳市信息行业协会商务网站 运营商:深圳市兴讯信息技术有限公司 粤ICP备:05039908
营业执照