Introduce an option for testing binary API
[one.git] / tests / data_plane / vpp_lite_topo / scripts / cmd_mappings.py
1
2 mappings = {}
3
4 class SimpleMapping(object):
5
6   def __init__(self, cmd, cli, vat):
7     if cmd in mappings:
8       raise Exception('{} already in cmd db!'.format(cmd))
9
10     self.cmd = cmd
11     self.cli = cli
12     self.vat = vat
13     mappings[cmd] = self
14
15   def generate(self, mode, args):
16     s = ''
17     # simply append arguments string to right command
18     if mode == 'vat':
19       s = self.vat + ' ' + args
20     else:
21       s = self.cli + ' ' + args
22     return s
23
24
25 class CustomMapping(SimpleMapping):
26
27   def generate(self, mode, args):
28     s = ''
29     if mode == 'vat':
30       s = self.vat
31     else:
32       s = self.cli
33
34     args = args.split(' ')
35     return s.format(*args)
36
37
38 class RepeatableLocators(SimpleMapping):
39
40   def append_locs(self, locs):
41     pass
42
43   def generate(self, mode, args):
44     name = args[:args.index(' ')]  # first word is ls name
45     locs = args[args.index(' '):]
46
47     if mode == 'vat':
48       s = self.vat
49     else:
50       s = self.cli
51
52     s = s + ' ' + name + locs
53     return s
54
55
56 SimpleMapping('lisp_state', 'lisp', 'lisp_enable_disable')
57 SimpleMapping('lisp_map_resolver', 'lisp map-resolver', 'lisp_add_del_map_resolver')
58 SimpleMapping('lisp_local_eid', 'lisp eid-table', 'lisp_add_del_local_eid')
59 SimpleMapping('lisp_remote_mapping', 'lisp remote-mapping', 'lisp_add_del_remote_mapping')
60 SimpleMapping('lisp_pitr', 'lisp pitr ls', 'lisp_pitr_set_locator_set locator-set')
61 SimpleMapping('set_if_ip', 'set int ip address', 'sw_interface_add_del_address')
62
63 CustomMapping('lisp_eid_map_bd',
64               'lisp eid-table map vni {0} bd {1}',
65               'lisp_eid_table_add_del_map vni {0} bd_index {1}')
66 CustomMapping('lisp_eid_map_vrf',
67               'lisp eid-table map vni {0} vrf {1}',
68               'lisp_eid_table_add_del_map vni {0} vrf {1}')
69 CustomMapping('set_if_l2_bridge', 'set interface l2 bridge {0} {1}',
70               'sw_interface_set_l2_bridge {0} bd_id {1}')
71 CustomMapping('set_if_ip_table', 'set interface ip table {0} {1}',
72               'sw_interface_set_table {0} vrf {1}')
73 CustomMapping('lisp_locator_set_with_locator',
74               'lisp locator-set add {0} iface {1} p {2} w {3}',
75               'lisp_add_del_locator_set locator-set {0} iface {1} p {2} w {3}')
76 CustomMapping('create_host_iface',
77     'create host-interface name {0}\n'
78     'set int state host-{0} up\n'
79     'set int ip address host-{0} {1}',
80
81     'af_packet_create name {0}\n'
82     'sw_interface_set_flags host-{0} admin-up link-up\n'
83     'sw_interface_add_del_address host-{0} {1}')
84
85 CustomMapping('create_host_iface_vrf',
86     'create host-interface name {0}\n'
87     'set int state host-{0} up\n'
88     'set interface ip table host-{0} {2}\n'
89     'set int ip address host-{0} {1}',
90
91     'af_packet_create name {0}\n'
92     'sw_interface_set_flags host-{0} admin-up link-up\n'
93     'sw_interface_set_table host-{0} vrf {2}\n'
94     'sw_interface_add_del_address host-{0} {1}')
95
96 CustomMapping('create_host_iface_vrf_v6',
97     'create host-interface name {0}\n'
98     'set int state host-{0} up\n'
99     'set interface ip6 table host-{0} {2}\n'
100     'set int ip address host-{0} {1}',
101
102     'af_packet_create name {0}\n'
103     'sw_interface_set_flags host-{0} admin-up link-up\n'
104     'sw_interface_set_table host-{0} vrf {2} ipv6\n'
105     'sw_interface_add_del_address host-{0} {1}')
106
107 RepeatableLocators('lisp_ls_multiple_locs',
108                    'lisp locator-set add',
109                    'lisp_add_del_locator_set locator-set')
110