diff options
Diffstat (limited to 'src/conf_mode/protocols_mpls.py')
-rwxr-xr-x | src/conf_mode/protocols_mpls.py | 231 |
1 files changed, 189 insertions, 42 deletions
diff --git a/src/conf_mode/protocols_mpls.py b/src/conf_mode/protocols_mpls.py index 904d219e2..84948baf4 100755 --- a/src/conf_mode/protocols_mpls.py +++ b/src/conf_mode/protocols_mpls.py @@ -37,60 +37,124 @@ def get_config(config=None): mpls_conf = { 'router_id' : None, 'mpls_ldp' : False, + 'old_parameters' : { + 'no_ttl_propagation' : False, + 'maximum_ttl' : None + }, + 'parameters' : { + 'no_ttl_propagation' : False, + 'maximum_ttl' : None + }, 'old_ldp' : { - 'interfaces' : [], - 'neighbors' : {}, - 'd_transp_ipv4' : None, - 'd_transp_ipv6' : None, - 'hello_holdtime' : None, - 'hello_interval' : None, - 'ses_ipv4_hold' : None, - 'ses_ipv6_hold' : None, - 'export_ipv4_exp' : False, - 'export_ipv6_exp' : False - + 'interfaces' : [], + 'neighbors' : {}, + 'd_transp_ipv4' : None, + 'd_transp_ipv6' : None, + 'hello_ipv4_holdtime' : None, + 'hello_ipv4_interval' : None, + 'hello_ipv6_holdtime' : None, + 'hello_ipv6_interval' : None, + 'ses_ipv4_hold' : None, + 'ses_ipv6_hold' : None, + 'export_ipv4_exp' : False, + 'export_ipv6_exp' : False, + 'cisco_interop_tlv' : False, + 'transport_prefer_ipv4' : False, + 'target_ipv4_addresses' : [], + 'target_ipv6_addresses' : [], + 'target_ipv4_enable' : False, + 'target_ipv6_enable' : False, + 'target_ipv4_hello_int' : None, + 'target_ipv6_hello_int' : None, + 'target_ipv4_hello_hold' : None, + 'target_ipv6_hello_hold' : None }, 'ldp' : { - 'interfaces' : [], - 'neighbors' : {}, - 'd_transp_ipv4' : None, - 'd_transp_ipv6' : None, - 'hello_holdtime' : None, - 'hello_interval' : None, - 'ses_ipv4_hold' : None, - 'ses_ipv6_hold' : None, - 'export_ipv4_exp' : False, - 'export_ipv6_exp' : False - + 'interfaces' : [], + 'neighbors' : {}, + 'd_transp_ipv4' : None, + 'd_transp_ipv6' : None, + 'hello_ipv4_holdtime' : None, + 'hello_ipv4_interval' : None, + 'hello_ipv6_holdtime' : None, + 'hello_ipv6_interval' : None, + 'ses_ipv4_hold' : None, + 'ses_ipv6_hold' : None, + 'export_ipv4_exp' : False, + 'export_ipv6_exp' : False, + 'cisco_interop_tlv' : False, + 'transport_prefer_ipv4' : False, + 'target_ipv4_addresses' : [], + 'target_ipv6_addresses' : [], + 'target_ipv4_enable' : False, + 'target_ipv6_enable' : False, + 'target_ipv4_hello_int' : None, + 'target_ipv6_hello_int' : None, + 'target_ipv4_hello_hold' : None, + 'target_ipv6_hello_hold' : None } } if not (conf.exists('protocols mpls') or conf.exists_effective('protocols mpls')): return None - + + # If LDP is defined then enable LDP portion of code if conf.exists('protocols mpls ldp'): mpls_conf['mpls_ldp'] = True + # Set to MPLS hierarchy configuration level + conf.set_level('protocols mpls') + + # Get no_ttl_propagation + if conf.exists_effective('parameters no-propagate-ttl'): + mpls_conf['old_parameters']['no_ttl_propagation'] = True + + if conf.exists('parameters no-propagate-ttl'): + mpls_conf['parameters']['no_ttl_propagation'] = True + + # Get maximum_ttl + if conf.exists_effective('parameters maximum-ttl'): + mpls_conf['old_parameters']['maximum_ttl'] = conf.return_effective_value('parameters maximum-ttl') + + if conf.exists('parameters maximum-ttl'): + mpls_conf['parameters']['maximum_ttl'] = conf.return_value('parameters maximum-ttl') + + # Set to LDP hierarchy configuration level conf.set_level('protocols mpls ldp') # Get router-id if conf.exists_effective('router-id'): mpls_conf['old_router_id'] = conf.return_effective_value('router-id') + if conf.exists('router-id'): mpls_conf['router_id'] = conf.return_value('router-id') - # Get hello holdtime - if conf.exists_effective('discovery hello-holdtime'): - mpls_conf['old_ldp']['hello_holdtime'] = conf.return_effective_value('discovery hello-holdtime') + # Get hello-ipv4-holdtime + if conf.exists_effective('discovery hello-ipv4-holdtime'): + mpls_conf['old_ldp']['hello_ipv4_holdtime'] = conf.return_effective_value('discovery hello-ipv4-holdtime') - if conf.exists('discovery hello-holdtime'): - mpls_conf['ldp']['hello_holdtime'] = conf.return_value('discovery hello-holdtime') + if conf.exists('discovery hello-ipv4-holdtime'): + mpls_conf['ldp']['hello_ipv4_holdtime'] = conf.return_value('discovery hello-ipv4-holdtime') - # Get hello interval - if conf.exists_effective('discovery hello-interval'): - mpls_conf['old_ldp']['hello_interval'] = conf.return_effective_value('discovery hello-interval') + # Get hello-ipv4-interval + if conf.exists_effective('discovery hello-ipv4-interval'): + mpls_conf['old_ldp']['hello_ipv4_interval'] = conf.return_effective_value('discovery hello-ipv4-interval') - if conf.exists('discovery hello-interval'): - mpls_conf['ldp']['hello_interval'] = conf.return_value('discovery hello-interval') + if conf.exists('discovery hello-ipv4-interval'): + mpls_conf['ldp']['hello_ipv4_interval'] = conf.return_value('discovery hello-ipv4-interval') + + # Get hello-ipv6-holdtime + if conf.exists_effective('discovery hello-ipv6-holdtime'): + mpls_conf['old_ldp']['hello_ipv6_holdtime'] = conf.return_effective_value('discovery hello-ipv6-holdtime') + + if conf.exists('discovery hello-ipv6-holdtime'): + mpls_conf['ldp']['hello_ipv6_holdtime'] = conf.return_value('discovery hello-ipv6-holdtime') + + # Get hello-ipv6-interval + if conf.exists_effective('discovery hello-ipv6-interval'): + mpls_conf['old_ldp']['hello_ipv6_interval'] = conf.return_effective_value('discovery hello-ipv6-interval') + + if conf.exists('discovery hello-ipv6-interval'): + mpls_conf['ldp']['hello_ipv6_interval'] = conf.return_value('discovery hello-ipv6-interval') # Get session-ipv4-holdtime if conf.exists_effective('discovery session-ipv4-holdtime'): @@ -134,6 +198,76 @@ def get_config(config=None): if conf.exists('export ipv6 explicit-null'): mpls_conf['ldp']['export_ipv6_exp'] = True + # Get target_ipv4_addresses + if conf.exists_effective('targeted-neighbor ipv4 address'): + mpls_conf['old_ldp']['target_ipv4_addresses'] = conf.return_effective_values('targeted-neighbor ipv4 address') + + if conf.exists('targeted-neighbor ipv4 address'): + mpls_conf['ldp']['target_ipv4_addresses'] = conf.return_values('targeted-neighbor ipv4 address') + + # Get target_ipv4_enable + if conf.exists_effective('targeted-neighbor ipv4 enable'): + mpls_conf['old_ldp']['target_ipv4_enable'] = True + + if conf.exists('targeted-neighbor ipv4 enable'): + mpls_conf['ldp']['target_ipv4_enable'] = True + + # Get target_ipv4_hello_int + if conf.exists_effective('targeted-neighbor ipv4 hello-interval'): + mpls_conf['old_ldp']['target_ipv4_hello_int'] = conf.return_effective_value('targeted-neighbor ipv4 hello-interval') + + if conf.exists('targeted-neighbor ipv4 hello-interval'): + mpls_conf['ldp']['target_ipv4_hello_int'] = conf.return_value('targeted-neighbor ipv4 hello-interval') + + # Get target_ipv4_hello_hold + if conf.exists_effective('targeted-neighbor ipv4 hello-holdtime'): + mpls_conf['old_ldp']['target_ipv4_hello_hold'] = conf.return_effective_value('targeted-neighbor ipv4 hello-holdtime') + + if conf.exists('targeted-neighbor ipv4 hello-holdtime'): + mpls_conf['ldp']['target_ipv4_hello_hold'] = conf.return_value('targeted-neighbor ipv4 hello-holdtime') + + # Get target_ipv6_addresses + if conf.exists_effective('targeted-neighbor ipv6 address'): + mpls_conf['old_ldp']['target_ipv6_addresses'] = conf.return_effective_values('targeted-neighbor ipv6 address') + + if conf.exists('targeted-neighbor ipv6 address'): + mpls_conf['ldp']['target_ipv6_addresses'] = conf.return_values('targeted-neighbor ipv6 address') + + # Get target_ipv6_enable + if conf.exists_effective('targeted-neighbor ipv6 enable'): + mpls_conf['old_ldp']['target_ipv6_enable'] = True + + if conf.exists('targeted-neighbor ipv6 enable'): + mpls_conf['ldp']['target_ipv6_enable'] = True + + # Get target_ipv6_hello_int + if conf.exists_effective('targeted-neighbor ipv6 hello-interval'): + mpls_conf['old_ldp']['target_ipv6_hello_int'] = conf.return_effective_value('targeted-neighbor ipv6 hello-interval') + + if conf.exists('targeted-neighbor ipv6 hello-interval'): + mpls_conf['ldp']['target_ipv6_hello_int'] = conf.return_value('targeted-neighbor ipv6 hello-interval') + + # Get target_ipv6_hello_hold + if conf.exists_effective('targeted-neighbor ipv6 hello-holdtime'): + mpls_conf['old_ldp']['target_ipv6_hello_hold'] = conf.return_effective_value('targeted-neighbor ipv6 hello-holdtime') + + if conf.exists('targeted-neighbor ipv6 hello-holdtime'): + mpls_conf['ldp']['target_ipv6_hello_hold'] = conf.return_value('targeted-neighbor ipv6 hello-holdtime') + + # Get parameters cisco-interop-tlv + if conf.exists_effective('parameters cisco-interop-tlv'): + mpls_conf['old_ldp']['cisco_interop_tlv'] = True + + if conf.exists('parameters cisco-interop-tlv'): + mpls_conf['ldp']['cisco_interop_tlv'] = True + + # Get parameters transport-prefer-ipv4 + if conf.exists_effective('parameters transport-prefer-ipv4'): + mpls_conf['old_ldp']['transport_prefer_ipv4'] = True + + if conf.exists('parameters transport-prefer-ipv4'): + mpls_conf['ldp']['transport_prefer_ipv4'] = True + # Get interfaces if conf.exists_effective('interface'): mpls_conf['old_ldp']['interfaces'] = conf.return_effective_values('interface') @@ -145,14 +279,18 @@ def get_config(config=None): for neighbor in conf.list_effective_nodes('neighbor'): mpls_conf['old_ldp']['neighbors'].update({ neighbor : { - 'password' : conf.return_effective_value('neighbor {0} password'.format(neighbor)) + 'password' : conf.return_effective_value('neighbor {0} password'.format(neighbor), default=''), + 'ttl_security' : conf.return_effective_value('neighbor {0} ttl-security'.format(neighbor), default=''), + 'session_holdtime' : conf.return_effective_value('neighbor {0} session-holdtime'.format(neighbor), default='') } }) for neighbor in conf.list_nodes('neighbor'): mpls_conf['ldp']['neighbors'].update({ neighbor : { - 'password' : conf.return_value('neighbor {0} password'.format(neighbor)) + 'password' : conf.return_value('neighbor {0} password'.format(neighbor), default=''), + 'ttl_security' : conf.return_value('neighbor {0} ttl-security'.format(neighbor), default=''), + 'session_holdtime' : conf.return_value('neighbor {0} session-holdtime'.format(neighbor), default='') } }) @@ -172,15 +310,15 @@ def verify(mpls): return None if mpls['mpls_ldp']: - # Requre router-id + # Require router-id if not mpls['router_id']: raise ConfigError(f"MPLS ldp router-id is mandatory!") - # Requre discovery transport-address + # Require discovery transport-address if not mpls['ldp']['d_transp_ipv4'] and not mpls['ldp']['d_transp_ipv6']: raise ConfigError(f"MPLS ldp discovery transport address is mandatory!") - # Requre interface + # Require interface if not mpls['ldp']['interfaces']: raise ConfigError(f"MPLS ldp interface is mandatory!") @@ -195,15 +333,24 @@ def apply(mpls): if mpls is None: return None - # Set number of entries in the platform label table + # Set number of entries in the platform label table if mpls['mpls_ldp']: sysctl('net.mpls.platform_labels', '1048575') else: sysctl('net.mpls.platform_labels', '0') - # Do not copy IP TTL to MPLS header - sysctl('net.mpls.ip_ttl_propagate', '0') - + # Choose whether to copy IP TTL to MPLS header TTL + if mpls['parameters']['no_ttl_propagation']: + sysctl('net.mpls.ip_ttl_propagate', '0') + else: + sysctl('net.mpls.ip_ttl_propagate', '1') + + # Choose whether to limit maximum MPLS header TTL + if mpls['parameters']['maximum_ttl']: + sysctl('net.mpls.default_ttl', '%s' %(mpls['parameters']['maximum_ttl'])) + else: + sysctl('net.mpls.default_ttl', '255') + # Allow mpls on interfaces operate_mpls_on_intfc(mpls['ldp']['interfaces'], 1) |