Package: fake-switches
Fake-switchesFake-switches is a pluggable switch/router command-line simulator. It is meant
to help running integrated tests against network equipment without the burden
of having devices in a lab. This helps testing the communication with the
equipment along with all of its layers for more robust high level tests.  Since
it is meant to be used by other systems and not humans, error handling on
incomplete commands and fail-proofing has been mostly left out and only
relevant errors are shown.The library can easily be extended to react to some changes in the fake switch
configuration and control an actual set of tools to have an environment
behaving like a real one driven by a switch.  For example, you could hook
yourself to the VLAN creation and use vconfig to create an actual vlan on a
machine for some network testing.This library is NOT supported by any vendor, it was built by
reverse-engineering network equipment.Actual supported commandsCommand support has been added in a as-needed manner for the purpose of what
was tested and how.  So see which commands may be used and their supported
behavior, please see the tests section for each model.ModelProtocolsTest locationCiscossh and telnettests/cisco/test_cisco_switch_protocol.pyBrocadesshtests/brocade/test_brocade_switch_protocol.pyJunipernetconf over sshtests/juniper/juniper_base_protocol_test.pyDellssh and telnettests/dell/Using it with Docker$dockerrun-P-dinternap/fake-switches
$dockerps
CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES
6eec86849561internap/fake-switches"/bin/sh -c 'fake-swi"35secondsagoUp13seconds0.0.0.0:32776->22/tcpboring_thompson
$ssh127.0.0.1-p32776-lroot
root@127.0.0.1'spassword:# rootmy_switch>enable
Password:# press <RETURN>my_switch#showrun
Buildingconfiguration...

Currentconfiguration:164bytes
version12.1
!
hostnamemy_switch
!
!
vlan1!
interfaceFastEthernet0/1
!
interfaceFastEthernet0/2
!
interfaceFastEthernet0/3
!
interfaceFastEthernet0/4
!
end

my_switch#Launching with custom parameters$dockerrun-P-d-eSWITCH_MODEL="another_model"internap/fake-switchesSupported parametersNameDefault valueSWITCH_MODELcisco_genericSWITCH_HOSTNAMEswitchSWITCH_USERNAMErootSWITCH_PASSWORDrootLISTEN_HOST0.0.0.0LISTEN_PORT22Building image from source$dockerbuild-tfake-switches.
$dockerrun-P-dfake-switchesExtending functionalityThe SwitchConfiguration class can be extended and given an object factory with
custom classes that can act upon resources changes. For example :fromtwisted.internetimportreactorfromfake_switches.switch_configurationimportSwitchConfiguration,Portfromfake_switches.transports.ssh_serviceimportSwitchSshServicefromfake_switches.cisco.cisco_coreimportCiscoSwitchCoreclassMySwitchConfiguration(SwitchConfiguration):def__init__(self,*args,**kwargs):super(MySwitchConfiguration,self).__init__(objects_overrides={"Port":MyPort},*args,**kwargs)classMyPort(Port):def__init__(self,name):self._access_vlan=Nonesuper(MyPort,self).__init__(name)@propertydefaccess_vlan(self):returnself._access_vlan@access_vlan.setterdefaccess_vlan(self,value):ifself._access_vlan!=value:self._access_vlan=valueprint"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()Then, if you connect to the switch and dossh root@127.0.0.1 -p 11001
    password : root
    > enable
    password:
    # configure terminal
    # vlan 1000
    # interface FastEthernet0/1
    # switchport access vlan 1000Your program should say "This could add vlan to eth0" or do anything you would
want it to do :)Starting a switch from the command linepipinstallfake-switchesfake-switches# On a different shell, type the following:sshroot@127.0.0.1-p22222Command line helpThe --help flag is supported.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)Available switch modelsAt time of writing this document, the following models are available:brocade_genericcisco_genericcisco_2960_24TT_Lcisco_2960_48TT_Ldell_genericdell10g_genericjuniper_genericjuniper_qfx_copper_genericUse the --help flag to find the available models.The generic models are mainly for test purposes. They usually have less ports than a proper switch
model but behave the same otherwise. Once a "core" is available, more specific models can be very
easily added. Send your pull requests :)ContributingFeel free raise issues and send some pull request,
we'll be happy to look at them!