Manual:SimTest: Difference between revisions

From MikroTik Wiki
Jump to navigation Jump to search
Line 32: Line 32:
</pre>
</pre>


'''include''' works only from 'tests' directory. So, for example, if file test.cfg is in 'tests/lala/ and 'host.cfg' is in the same dir, then include should be <code>#include "lala/host.cfg"
'''include''' works only from 'tests' directory. So, for example, if file test.cfg is in 'tests/lala/ and 'host.cfg' is in the same dir, then include should be <code>#include "lala/host.cfg"</code>


{{Note | './' and '../' does not work}}
{{Note | './' and '../' does not work}}

Revision as of 07:55, 3 April 2012

Configuration Syntax Explained

Version definition

Version always should be defined at the beginning of the file.

Syntax:

version 1;


Description

Description is used to show detailed description of what this simulation do.

Syntax:

desc {
 ...
}

Include

Allows to include parts of configuration located in another files. For example include common host information or common network configuration.

Syntax:

#include "host.cfg"

include works only from 'tests' directory. So, for example, if file test.cfg is in 'tests/lala/ and 'host.cfg' is in the same dir, then include should be #include "lala/host.cfg"

Icon-note.png

Note: './' and '../' does not work


Host

Defines host login information, where tester application should log in and add virtual network.

Host should always be at the same broadcast network as tester, since ipv6 link-local addresses are used to connect to virtual guests from the tester.

Syntax:

host <name> {
    <param> <value>;
}


Host configuration allows following parameters:

Param Description
desc (string) Simple description, can be left blank
addr (ipv4 | ipv6) IP/IPv6 address of the host
port (integer | string) API port on the host
user (string) Username used to login
pass (string) Password used to login
bridge (string) Name of the bridge where management interfaces of guests are added. This is needed for tester to be able to connect to the guest routers and apply configuration.


Network

Define all routers and links between routers in virtual network.

network <name> {
  <param> <value>;
  
  router <ref_name> {
    META {
        <api_commands>
    }
  }
}

Network configuration allows following parameters:

Param Description
desc (string) Simple description, can be left blank
host (string) Which of the defined hosts to use
vlans (integer [0..1]) Whether to use vlans for link simulations instead of virtual interfaces. Vlans should be used in MetaROUTER mode, since metarouters has limited amount of available virtual ethernets
routers (list of router names separated by comma (R1, R2;)) Define all routers in virtual network. All routers are separated by comma
link (list of routers (R1 R2;)) Define links between routers. It is possible to define point to point and broadcast links. Link definition will also make an interface name for the guest interface.

For example link R1 R2 will make point to point link between router with name R1 and router with name R2:

  • on router R1 interface will be called R1_R2
  • on router R2 interface will be called R2_R1

Another example, link R1 R2 R3 will make broadcast network between three routers. Interfaces on routers will be named as follows:

  • on R1 interface will be called R1_R2_R3
  • on R2 interface will be called R2_R1
  • on R3 interface will be called 'R3_R2


router scope allows to define two sub-scopes:
* META - this scope should contain configuration in API syntax which will be applied to the router.
* KVM - this scope should contain configuration in RouterOS CLI syntax which will be applied during KVM image creation process.


Simulation

sim <name> {
  <param> <value>;

  events {
    ...
  }
}


Simulation Events

Possible Events:

  • print
 print "Hello World\n";
  • delay
 delay 4; 
  • wait
  • config_set
config_set {
  id {
    <API CMD>
  }
  cmd {
    <API CMD>
  }
}
  • config_check


Sample Configuration

host.cfg
version 1;

// host login information
host "default" {
	desc "Default host";
	addr "10.5.101.14";
	port "8728";
	user "admin";
	pass "";

	bridge "bypass";
} 
network_2_routers.cfg
/* Configuration template for two interconnected routers
*
*              R1 ---- R2 
*
*/

version 1;

#include "host.cfg"

network "2_router_network" {
	desc		"";
	host 		"default";
	
	vlans		0;

	routers 	R1, R2;

	link 		R1 R2;

	router "R1" {
		META {
			/ip/address/add
			=address=1.1.1.1/30
			=interface=R1_R2
		}
	}

	router "R2" {
		META {
			/ip/address/add
			=address=1.1.1.2/30
			=interface=R2_R1
		}
	}

}


bgp/001-auth.cfg
version 1;

desc {
+===================================================================
| BGP connection establishment with authentication
| 
+===================================================================
.
.Test setup creates a simple link between 2 routers
.
.                   
.              R1------R2
.
.  Simulator actions:
.	* Check if BGP connection is established
.	* Change to incorrect MD5 key
.	* Check if BGP connection is NOT established
.	* Change back to correct MD5 key
.	* Check if BGP connection is established
}

#include "network_2_routers.cfg"


sim "simple"{
	desc		"MD5 authentication test";
	network 	"2_router_network";

	events {
		print "Set initial config...\n";
		config_set "R1" {
			cmd {
				/routing/bgp/peer/add
				=name=R2
				=remote-address=1.1.1.2
				=remote-as=65530
				=tcp-md5-key=helloworld
			}
		}
		config_set "R2" {
			cmd {
				/routing/bgp/peer/add
				=name=R1
				=remote-address=1.1.1.1
				=remote-as=65530
				=tcp-md5-key=helloworld
			}
		}
		delay 7;

		print "Check if BGP session is established..\n";
		config_check "R1" {
			cmd {
				/routing/bgp/peer/print
				?state=established
				=.proplist=.id
			}
			status	inconclusive; 
		}

		print "Change MD5 key..\n";
		config_set "R1" {
			// id can be only one and should contain only one command
			id {
				/routing/bgp/peer/print
				?name=R2
				=.proplist=.id
			}
			cmd {
				/routing/bgp/peer/set
				=tcp-md5-key=lalala
			}
		}

		print "Waiting...\n";
		delay 3;

		print "Check if BGP session is NOT established..\n";
		config_check "R1" {
			cmd {
				/routing/bgp/peer/print
				?state=established
				=.proplist=.id
			}
			data	yes; // failure if returns any entries
			status	failed; 
		}


		print "Change MD5 key..\n";
		config_set "R1" {
			// id can be only one and should contain only one command
			id {
				/routing/bgp/peer/print
				?name=R2
				=.proplist=.id
			}
			cmd {
				/routing/bgp/peer/set
				=tcp-md5-key=helloworld
			}
		}

		print "Waiting...\n";
		delay 3;

		print "Check if BGP session is established..\n";
		config_check "R1" {
			cmd {
				/routing/bgp/peer/print
				?state=established
				=.proplist=.id
			}
			data	no;
			status	failed; 
		}

	}
}