summaryrefslogtreecommitdiffstats
path: root/tests/data_plane/vpp_lite_topo/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/data_plane/vpp_lite_topo/scripts')
-rw-r--r--tests/data_plane/vpp_lite_topo/scripts/cmd_mappings.py110
-rwxr-xr-xtests/data_plane/vpp_lite_topo/scripts/generate_config.py80
2 files changed, 190 insertions, 0 deletions
diff --git a/tests/data_plane/vpp_lite_topo/scripts/cmd_mappings.py b/tests/data_plane/vpp_lite_topo/scripts/cmd_mappings.py
new file mode 100644
index 0000000..87ec8cb
--- /dev/null
+++ b/tests/data_plane/vpp_lite_topo/scripts/cmd_mappings.py
@@ -0,0 +1,110 @@
+
+mappings = {}
+
+class SimpleMapping(object):
+
+ def __init__(self, cmd, cli, vat):
+ if cmd in mappings:
+ raise Exception('{} already in cmd db!'.format(cmd))
+
+ self.cmd = cmd
+ self.cli = cli
+ self.vat = vat
+ mappings[cmd] = self
+
+ def generate(self, mode, args):
+ s = ''
+ # simply append arguments string to right command
+ if mode == 'vat':
+ s = self.vat + ' ' + args
+ else:
+ s = self.cli + ' ' + args
+ return s
+
+
+class CustomMapping(SimpleMapping):
+
+ def generate(self, mode, args):
+ s = ''
+ if mode == 'vat':
+ s = self.vat
+ else:
+ s = self.cli
+
+ args = args.split(' ')
+ return s.format(*args)
+
+
+class RepeatableLocators(SimpleMapping):
+
+ def append_locs(self, locs):
+ pass
+
+ def generate(self, mode, args):
+ name = args[:args.index(' ')] # first word is ls name
+ locs = args[args.index(' '):]
+
+ if mode == 'vat':
+ s = self.vat
+ else:
+ s = self.cli
+
+ s = s + ' ' + name + locs
+ return s
+
+
+SimpleMapping('lisp_state', 'lisp', 'lisp_enable_disable')
+SimpleMapping('lisp_map_resolver', 'lisp map-resolver', 'lisp_add_del_map_resolver')
+SimpleMapping('lisp_local_eid', 'lisp eid-table', 'lisp_add_del_local_eid')
+SimpleMapping('lisp_remote_mapping', 'lisp remote-mapping', 'lisp_add_del_remote_mapping')
+SimpleMapping('lisp_pitr', 'lisp pitr ls', 'lisp_pitr_set_locator_set locator-set')
+SimpleMapping('set_if_ip', 'set int ip address', 'sw_interface_add_del_address')
+
+CustomMapping('lisp_eid_map_bd',
+ 'lisp eid-table map vni {0} bd {1}',
+ 'lisp_eid_table_add_del_map vni {0} bd_index {1}')
+CustomMapping('lisp_eid_map_vrf',
+ 'lisp eid-table map vni {0} vrf {1}',
+ 'lisp_eid_table_add_del_map vni {0} vrf {1}')
+CustomMapping('set_if_l2_bridge', 'set interface l2 bridge {0} {1}',
+ 'sw_interface_set_l2_bridge {0} bd_id {1}')
+CustomMapping('set_if_ip_table', 'set interface ip table {0} {1}',
+ 'sw_interface_set_table {0} vrf {1}')
+CustomMapping('lisp_locator_set_with_locator',
+ 'lisp locator-set add {0} iface {1} p {2} w {3}',
+ 'lisp_add_del_locator_set locator-set {0} iface {1} p {2} w {3}')
+CustomMapping('create_host_iface',
+ 'create host-interface name {0}\n'
+ 'set int state host-{0} up\n'
+ 'set int ip address host-{0} {1}',
+
+ 'af_packet_create name {0}\n'
+ 'sw_interface_set_flags host-{0} admin-up link-up\n'
+ 'sw_interface_add_del_address host-{0} {1}')
+
+CustomMapping('create_host_iface_vrf',
+ 'create host-interface name {0}\n'
+ 'set int state host-{0} up\n'
+ 'set interface ip table host-{0} {2}\n'
+ 'set int ip address host-{0} {1}',
+
+ 'af_packet_create name {0}\n'
+ 'sw_interface_set_flags host-{0} admin-up link-up\n'
+ 'sw_interface_set_table host-{0} vrf {2}\n'
+ 'sw_interface_add_del_address host-{0} {1}')
+
+CustomMapping('create_host_iface_vrf_v6',
+ 'create host-interface name {0}\n'
+ 'set int state host-{0} up\n'
+ 'set interface ip6 table host-{0} {2}\n'
+ 'set int ip address host-{0} {1}',
+
+ 'af_packet_create name {0}\n'
+ 'sw_interface_set_flags host-{0} admin-up link-up\n'
+ 'sw_interface_set_table host-{0} vrf {2} ipv6\n'
+ 'sw_interface_add_del_address host-{0} {1}')
+
+RepeatableLocators('lisp_ls_multiple_locs',
+ 'lisp locator-set add',
+ 'lisp_add_del_locator_set locator-set')
+
diff --git a/tests/data_plane/vpp_lite_topo/scripts/generate_config.py b/tests/data_plane/vpp_lite_topo/scripts/generate_config.py
new file mode 100755
index 0000000..87204a6
--- /dev/null
+++ b/tests/data_plane/vpp_lite_topo/scripts/generate_config.py
@@ -0,0 +1,80 @@
+#!/usr/bin/env python
+
+"""
+generate_config.py - Generate specific configuration file for VPP from
+ generic config file
+
+Usage:
+ ./generate_config.py <directory> <output-file-type>
+
+where <directory> is a system directory containing generic config file(s)
+ (suffixed with *.config)
+ <output-file-type> is one of 'vat' or 'cli'
+
+This script looks for *.config files in provided directory and for each
+generates a specific configuration file based on output file type in form
+'<filename>.cli' or '<filename>.vat' respectively.
+"""
+
+import sys
+import glob
+import cmd_mappings
+
+
+def generate_config(file_name, mode):
+ """
+ param file_name:
+ param mode: one of 'vat' or 'cli'
+ """
+ s = ''
+ f = open(file_name, 'r')
+ line_num = 0
+
+ for line in f:
+ line_num += 1
+ line = line.strip()
+ if line == '' or line[0] == '#':
+ continue
+
+ kw = line[: line.index(' ')]
+ args = line[ line.index(' ') + 1:]
+
+ if kw not in cmd_mappings.mappings:
+ raise Exception('Conversion error at {}:{}:\n > {}\nKeyword not found:'
+ ' {}'.format(file_name, line_num, line, kw))
+
+ mapping = cmd_mappings.mappings[kw]
+ try:
+ s = s + mapping.generate(mode, args) + '\n'
+ except Exception as e:
+ raise Exception('Conversion error at {}:{}:\n > {}'
+ .format(file_name, line_num, line))
+
+ return s
+
+
+def main():
+ if len(sys.argv) != 3:
+ print('Error: expected 2 arguments!')
+ sys.exit(1)
+
+ dir_name = sys.argv[1]
+ config_type = sys.argv[2]
+
+ if config_type != 'vat' and config_type != 'cli':
+ print('Error: expected second parameter one of "vat" or "cli"!')
+ sys.exit(1)
+
+ for f in glob.glob(dir_name + "/*.config"):
+ config = generate_config(f, config_type)
+
+ output_fname = f.replace('.config', '.' + config_type)
+ print('\n* Generated config from {}:'.format(f))
+ print(config)
+ print ('* Saving to {}'.format(output_fname))
+
+ fout = open(output_fname, 'w')
+ fout.write(config);
+
+
+main()