可插拔的交换机/路由器命令行模拟器
项目描述
Fake-switches
Fake-switches是一个可插拔的交换机/路由器命令行模拟器。它旨在帮助在没有实验室设备负担的情况下运行针对网络设备的集成测试。这有助于测试与设备的通信以及所有层,以进行更健壮的高级测试。由于它是为其他系统而非人类使用而设计的,因此在不完整的命令处理和防故障方面被省略,并且只显示相关错误。
该库可以很容易地扩展以响应模拟交换机配置中的某些更改,并控制一组实际工具,以使环境表现得像由交换机驱动的真实环境。例如,您可以将自己连接到VLAN创建,并使用vconfig在机器上创建实际的vlan,以便进行某些网络测试。
此库不受任何供应商的支持,它是通过逆向工程网络设备构建的。
实际支持的命令
为了测试目的和测试方式,已按需添加了命令支持。因此,请参阅每个型号的测试部分以了解哪些命令可以使用及其支持的行
型号 | 协议 | 测试位置 |
---|---|---|
Cisco | ssh和telnet | tests/cisco/test_cisco_switch_protocol.py |
Brocade | ssh | tests/brocade/test_brocade_switch_protocol.py |
Juniper | 通过ssh的netconf | tests/juniper/juniper_base_protocol_test.py |
Dell | ssh和telnet | tests/dell/ |
与Docker一起使用
$ docker run -P -d internap/fake-switches
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6eec86849561 internap/fake-switches "/bin/sh -c 'fake-swi" 35 seconds ago Up 13 seconds 0.0.0.0:32776->22/tcp boring_thompson
$ ssh 127.0.0.1 -p 32776 -l root
root@127.0.0.1's password: # root
my_switch>enable
Password: # press <RETURN>
my_switch#show run
Building configuration...
Current configuration : 164 bytes
version 12.1
!
hostname my_switch
!
!
vlan 1
!
interface FastEthernet0/1
!
interface FastEthernet0/2
!
interface FastEthernet0/3
!
interface FastEthernet0/4
!
end
my_switch#
使用自定义参数启动
$ docker run -P -d -e SWITCH_MODEL="another_model" internap/fake-switches
支持的参数
名称 | 默认值 |
---|---|
SWITCH_MODEL | cisco_generic |
SWITCH_HOSTNAME | switch |
SWITCH_USERNAME | root |
SWITCH_PASSWORD | root |
LISTEN_HOST | 0.0.0.0 |
LISTEN_PORT | 22 |
从源代码构建镜像
$ docker build -t fake-switches .
$ docker run -P -d fake-switches
扩展功能
SwitchConfiguration类可以扩展,并给对象工厂提供自定义类,以便对资源更改进行操作。例如
from twisted.internet import reactor
from fake_switches.switch_configuration import SwitchConfiguration, Port
from fake_switches.transports.ssh_service import SwitchSshService
from fake_switches.cisco.cisco_core import CiscoSwitchCore
class MySwitchConfiguration(SwitchConfiguration):
def __init__(self, *args, **kwargs):
super(MySwitchConfiguration, self).__init__(objects_overrides={"Port": MyPort}, *args, **kwargs)
class MyPort(Port):
def __init__(self, name):
self._access_vlan = None
super(MyPort, self).__init__(name)
@property
def access_vlan(self):
return self._access_vlan
@access_vlan.setter
def access_vlan(self, value):
if self._access_vlan != value:
self._access_vlan = value
print "This could add vlan to eth0"
if __name__ == '__main__':
ssh_service = SwitchSshService(
ip="127.0.0.1",
ssh_port=11001,
switch_core=CiscoSwitchCore(MySwitchConfiguration("127.0.0.1", "my_switch", ports=[MyPort("FastEthernet0/1")])))
ssh_service.hook_to_reactor(reactor)
reactor.run()
然后,如果您连接到交换机并执行
ssh root@127.0.0.1 -p 11001
password : root
> enable
password:
# configure terminal
# vlan 1000
# interface FastEthernet0/1
# switchport access vlan 1000
您的程序应显示“这可能将vlan添加到eth0”或执行您想要执行的其他任何操作 :)
从命令行启动交换机
pip install fake-switches
fake-switches
# On a different shell, type the following:
ssh root@127.0.0.1 -p 22222
命令行帮助
支持--help标志。
fake-switches --help
usage: fake-switches [-h] [--model MODEL] [--hostname HOSTNAME]
[--username USERNAME] [--password PASSWORD]
[--listen-host LISTEN_HOST] [--listen-port LISTEN_PORT]
Fake-switch simulator launcher
optional arguments:
-h, --help show this help message and exit
--model MODEL Switch model, allowed values are
juniper_qfx_copper_generic, cisco_2960_24TT_L,
dell_generic, dell10g_generic, juniper_generic,
cisco_2960_48TT_L, cisco_generic, brocade_generic
(default: cisco_generic)
--hostname HOSTNAME Switch hostname (default: switch)
--username USERNAME Switch username (default: root)
--password PASSWORD Switch password (default: root)
--listen-host LISTEN_HOST
Listen host (default: 0.0.0.0)
--listen-port LISTEN_PORT
Listen port (default: 2222)
可用的交换机型号
在撰写本文档时,以下型号可用
- brocade_generic
- cisco_generic
- cisco_2960_24TT_L
- cisco_2960_48TT_L
- dell_generic
- dell10g_generic
- juniper_generic
- juniper_qfx_copper_generic
使用--help标志查找可用的型号。
通用模型主要用于测试目的。它们通常比合适的交换机模型端口少,但在其他方面表现相同。一旦有“核心”可用,就可以非常容易地添加更具体的型号。发送您的pull请求 :)
贡献
请随时提出问题并发送一些pull请求,我们将很高兴查看它们!
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源代码发行版
fake-switches-1.5.0.tar.gz (265.9 kB 查看哈希值)
构建发行版
fake_switches-1.5.0-py2.py3-none-any.whl (125.5 kB 查看哈希值)