def set_ip_unreach_cb(methods, params): obj = cps_object.CPSObject(obj=params['change']) if params['operation'] != 'rpc': log_err('oper is not RPC') return False operation = ip_unreach_attr('operation') enable = ip_unreach_attr('enable') af = ip_unreach_attr('af') ifname = ip_unreach_attr('ifname') vrf_name = ip_unreach_attr('vrf-name') dev = None vrf = None try: operation = obj.get_attr_data(operation) af = obj.get_attr_data(af) enable = obj.get_attr_data(enable) except ValueError as e: log_msg = 'Missing mandatory attribute ' + e.args[0] log_err(log_msg) return False try: vrf = obj.get_attr_data(vrf_name) except: pass vrf = 'default' # Operation types #BASE_CMN_OPERATION_TYPE_CREATE=1 #BASE_CMN_OPERATION_TYPE_DELETE=2 #BASE_CMN_OPERATION_TYPE_UPDATE=3 is_add = True; if operation == 3: log_msg = 'Update operation is not supported!' log_err(log_msg) return False elif operation == 2: is_add = False; if af != socket.AF_INET and af != socket.AF_INET6: log_msg = 'Invalid address family' + str(af) log_err(log_msg) return False try: dev = obj.get_attr_data(ifname) except: pass log_info('Ifname is not present in the object') if dn_base_ip_tbl_tool.ip_tables_unreach_rule(vrf, is_add, enable, af, dev): return True log_msg = 'Failed to execute IP unreachable request ' + str(is_add) + str(af) \ + 'enable' + str(enable) + 'ifname' + ifname log_err(log_msg) return False
def set_proxy_arp_cb(methods, params): obj = cps_object.CPSObject(obj=params['change']) vrf_name = proxy_arp_attr('vrf-name') ifname = proxy_arp_attr('ifname') vrf = None dev = None try: vrf = obj.get_attr_data(vrf_name) dev = obj.get_attr_data(ifname) except ValueError as e: log_msg = 'Missing mandatory attribute ' + e.args[0] log_err(log_msg) return False log_info("Proxy ARP configuration on VRF:%s intf:%s operation:%s" % (vrf, dev, params['operation'])) try: if params['operation'] == 'create': if dn_base_ip_tool.proxy_arp_config(dev, 1, vrf): return True if params['operation'] == 'delete': if dn_base_ip_tool.proxy_arp_config(dev, 0, vrf): return True except Exception as e: log_err("Faild to commit operation exception:%s params:%s" % (e, params)) log_err("Proxy ARP configuration failed on VRF:%s intf:%s operation:%s" % (vrf, dev, params['operation'])) return False
def flush_ip_neigh_cb(methods, params): obj = cps_object.CPSObject(obj=params['change']) if params['operation'] != 'rpc': log_err('oper is not RPC') return False vrf_name = ip_neigh_flush_attr('vrf-name') af = ip_neigh_flush_attr('af') ifname = ip_neigh_flush_attr('ifname') ip_addr = ip_neigh_flush_attr('ip') prefix_len = ip_neigh_flush_attr('prefix-len') dev = None try: vrf_name = obj.get_attr_data(vrf_name) except ValueError as e: log_msg = 'Missing mandatory attribute ' + e.args[0] log_err(log_msg) return False try: af = obj.get_attr_data(af) except: pass af = socket.AF_INET log_info('Address family is not present in the object') if af != socket.AF_INET and af != socket.AF_INET6: log_msg = 'Invalid address family' + str(af) log_err(log_msg) return False try: dev = obj.get_attr_data(ifname) except: pass dev = None log_info('Ifname is not present in the object') try: ip_addr = obj.get_attr_data(ip_addr) except: pass ip_addr = None try: prefix_len = obj.get_attr_data(prefix_len) except: pass prefix_len = None addr = None if ip_addr is not None: addr = _create_neigh_flush_ip_and_prefix_from_attr( ip_addr, prefix_len, af) log_msg = 'IP neigh flush request vrf-name:' + str(vrf_name)\ + ' af:' + str(af) + ' ifname:' + str(dev)\ + ' to addr:' + str(addr) log_info(log_msg) if dev is not None: for ifname in dev: if dn_base_ip_tool.is_intf_exist_in_vrf(str(vrf_name), ifname): val = dn_base_ip_tool.flush_ip_neigh(_ip_af[af], ifname, addr, str(vrf_name)) else: val = _nbr_flush_handle(str(vrf_name), af, ifname) else: val = dn_base_ip_tool.flush_ip_neigh(_ip_af[af], dev, addr, str(vrf_name)) if val is False: log_err("IP neigh flush on VRF:%s af:%s addr:%s failed"% (str(vrf_name),\ str(af), str(addr))) val = _nbr_flush_handle(str(vrf_name), af, dev) return val
def trans_cb(methods, params): obj = cps_object.CPSObject(obj=params['change']) af = _get_af_from_obj(obj) name = _get_key_from_obj(obj) if name is None: print "Missing keys for request ", obj return False vrf_name = 'default' try: vrf_name = obj.get_attr_data('base-ip/' + af + '/vrf-name') except: # VRF-name is optional attribute. pass addr = "" try: if params['operation'] == 'set' and obj.get_key() == _keys['base-ip/' + af]: if af == 'ipv6': try: enabled = obj.get_attr_data('base-ip/' + af + '/enabled') if enabled == 1: disable_ipv6 = 0 else: disable_ipv6 = 1 _ipv6_enable_status[name] = enabled if vrf_name == 'default': ret_val = _set_proc_variable(_get_proc_disable_ipv6_entry(name),\ str(disable_ipv6)) else: ret_val = dn_base_ip_tool.disable_ipv6_config( name, str(disable_ipv6), vrf_name) log_msg = 'CPS set for VRF:' + vrf_name + 'intf-name:' + name + ' ipv6 status:' +\ str(enabled) + 'ret_val:' + str(ret_val) log_info(log_msg) if ret_val == -1: return False except: pass try: autoconf = obj.get_attr_data('base-ip/' + af + '/autoconf') if vrf_name == 'default': ret_val = _set_proc_variable( _get_proc_ipv6_autoconf_entry(name), str(autoconf)) else: ret_val = dn_base_ip_tool.ipv6_autoconf_config( name, autoconf, vrf_name) log_msg = 'CPS set for VRF:' + vrf_name + 'intf-name:' + name + ' ipv6 auto conf status:'\ + str(autoconf) + 'ret_val:' + str(ret_val) log_info(log_msg) if ret_val == -1: return False except: pass try: accept_dad = obj.get_attr_data('base-ip/' + af + '/accept-dad') # Check the valid enum values if accept_dad not in [1, 2, 3]: return False # CPS enum starts from 1 but kernel enum starts from 0 accept_dad = accept_dad - 1 if vrf_name == 'default': ret_val = _set_proc_variable( _get_proc_ipv6_accept_dad_entry(name), str(accept_dad)) else: ret_val = dn_base_ip_tool.ipv6_accept_dad_config( name, str(accept_dad), vrf_name) log_msg = 'CPS set for VRF:' + vrf_name + 'intf-name:' + name + ' ipv6 accept DAD status:'\ + str(accept_dad) + 'ret_val:' + str(ret_val) log_info(log_msg) if ret_val == -1: return False except: pass try: fwd = obj.get_attr_data('base-ip/' + af + '/forwarding') if vrf_name == 'default': ret_val = _set_proc_variable(_get_proc_fwd_entry(name, af), str(fwd)) else: ret_val = dn_base_ip_tool.ip_forwarding_config( af, name, str(fwd), vrf_name) log_msg = 'CPS set for VRF:' + vrf_name + 'intf-name:' + name + ' fwd status:' + str(fwd)\ + 'ret_val:' + str(ret_val) log_info(log_msg) if ret_val == -1: return False except: pass return True if params['operation'] == 'create' and obj.get_key() == _keys[ 'base-ip/' + af + '/address']: addr = _create_ip_and_prefix_from_obj(obj, af) log_info("Attempting to add address:%s intf:%s vrf:%s" % (addr, name, vrf_name)) if dn_base_ip_tool.add_ip_addr(addr, name, af, vrf_name): return True log_err("Attempting to add address:%s intf:%s vrf:%s failed" % (addr, name, vrf_name)) if params['operation'] == 'delete' and obj.get_key() == _keys[ 'base-ip/' + af + '/address']: addr = _create_ip_and_prefix_from_obj(obj, af) log_info("Attempting to del address:%s intf:%s vrf:%s" % (addr, name, vrf_name)) if dn_base_ip_tool.del_ip_addr(addr, name, vrf_name): return True log_err("Attempting to del address:%s intf:%s vrf:%s failed" % (addr, name, vrf_name)) except Exception as e: log_err("Faild to commit operation exception:%s params:%s" % (e, params)) return False