4 class SimpleMapping(object):
6 def __init__(self, cmd, cli, vat):
8 raise Exception('{} already in cmd db!'.format(cmd))
15 def generate(self, mode, args):
17 # simply append arguments string to right command
19 s = self.vat + ' ' + args
21 s = self.cli + ' ' + args
25 class CustomMapping(SimpleMapping):
27 def generate(self, mode, args):
34 args = args.split(' ')
35 return s.format(*args)
38 class RepeatableLocators(SimpleMapping):
40 def append_locs(self, locs):
43 def generate(self, mode, args):
44 name = args[:args.index(' ')] # first word is ls name
45 locs = args[args.index(' '):]
52 s = s + ' ' + name + locs
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')
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}',
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}')
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}',
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}')
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}',
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}')
107 RepeatableLocators('lisp_ls_multiple_locs',
108 'lisp locator-set add',
109 'lisp_add_del_locator_set locator-set')