cmd_mappings.py revision 3db341de
1
2mappings = {}
3
4class 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
25class 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
38class RepeatableLocators(SimpleMapping):
39
40  def generate(self, mode, args):
41    name = args[:args.index(' ')]  # first word is ls name
42    locs = args[args.index(' '):]
43
44    if mode == 'vat':
45      s = self.vat
46    else:
47      s = self.cli
48
49    s = s + ' ' + name + locs
50    return s
51
52
53SimpleMapping('lisp_state', 'one', 'one_enable_disable')
54SimpleMapping('lisp_map_resolver', 'one map-resolver', 'one_add_del_map_resolver')
55SimpleMapping('lisp_map_server', 'one map-server', 'one_add_del_map_server')
56SimpleMapping('lisp_local_eid', 'one eid-table', 'one_add_del_local_eid')
57SimpleMapping('lisp_remote_mapping', 'one remote-mapping', 'one_add_del_remote_mapping')
58SimpleMapping('lisp_pitr', 'one pitr ls', 'one_pitr_set_locator_set locator-set')
59SimpleMapping('lisp_adjacency', 'one adjacency', 'one_add_del_adjacency')
60SimpleMapping('lisp_map_request_mode', 'one map-request mode', 'one_map_request_mode')
61SimpleMapping('set_if_ip', 'set int ip address', 'sw_interface_add_del_address')
62SimpleMapping('lisp_rloc_probe_state', 'one rloc-probe', 'one_rloc_probe_enable_disable')
63SimpleMapping('lisp_map_register_state', 'one map-register', 'one_map_register_enable_disable')
64SimpleMapping('lisp_stats', 'one statistics', 'one_stats_enable_disable')
65SimpleMapping('lisp_l2_arp', 'one l2 arp', 'one_add_del_l2_arp_entry')
66SimpleMapping('lisp_ndp_entry', 'one ndp', 'one_add_del_ndp_entry')
67SimpleMapping('lisp_nsh_set_ls', 'one nsh-mapping', 'one_nsh_set_locator_set')
68
69SimpleMapping('ipsec_sad_add_del_entry', 'TODO', 'ipsec_sad_add_del_entry')
70SimpleMapping('ipsec_spd_add_del', 'todo', 'ipsec_spd_add_del')
71SimpleMapping('ipsec_interface_add_del_spd' , 'todo', 'ipsec_interface_add_del_spd')
72SimpleMapping('ipsec_spd_add_del_entry', 'todo', 'ipsec_spd_add_del_entry')
73
74CustomMapping('lisp_eid_map_bd',
75              'one eid-table map vni {0} bd {1}',
76              'one_eid_table_add_del_map vni {0} bd_index {1}')
77CustomMapping('lisp_eid_map_vrf',
78              'one eid-table map vni {0} vrf {1}',
79              'one_eid_table_add_del_map vni {0} vrf {1}')
80CustomMapping('set_if_l2_bridge', 'set interface l2 bridge {0} {1}',
81              'sw_interface_set_l2_bridge {0} bd_id {1}')
82CustomMapping('set_if_ip_table', 'set interface ip table {0} {1}',
83              'sw_interface_set_table {0} vrf {1}')
84CustomMapping('lisp_locator_set_with_locator',
85              'one locator-set add {0} iface {1} p {2} w {3}',
86              'one_add_del_locator_set locator-set {0} iface {1} p {2} w {3}')
87CustomMapping('create_host_iface',
88    'create host-interface name {0}\n'
89    'set int state host-{0} up\n'
90    'set int ip address host-{0} {1}',
91
92    'af_packet_create name {0}\n'
93    'sw_interface_set_flags host-{0} admin-up link-up\n'
94    'sw_interface_add_del_address host-{0} {1}')
95
96CustomMapping('create_host_iface_vrf',
97    'create host-interface name {0}\n'
98    'set int state host-{0} up\n'
99    'set interface ip 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}\n'
105    'sw_interface_add_del_address host-{0} {1}')
106
107CustomMapping('create_host_iface_vrf_v6',
108    'create host-interface name {0}\n'
109    'set int state host-{0} up\n'
110    'set interface ip6 table host-{0} {2}\n'
111    'set int ip address host-{0} {1}',
112
113    'af_packet_create name {0}\n'
114    'sw_interface_set_flags host-{0} admin-up link-up\n'
115    'sw_interface_set_table host-{0} vrf {2} ipv6\n'
116    'sw_interface_add_del_address host-{0} {1}')
117
118RepeatableLocators('lisp_ls_multiple_locs',
119                   'one locator-set add',
120                   'one_add_del_locator_set locator-set')
121
122