cisco_node_utils 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -0
  3. data/README.md +2 -1
  4. data/docs/cisco_node_utils.yaml.example +6 -0
  5. data/lib/cisco_node_utils/cisco_cmn_utils.rb +6 -15
  6. data/lib/cisco_node_utils/client/nxapi/client.rb +19 -1
  7. data/lib/cisco_node_utils/client/utils.rb +1 -1
  8. data/lib/cisco_node_utils/cmd_ref/README_YAML.md +1 -1
  9. data/lib/cisco_node_utils/cmd_ref/interface.yaml +25 -0
  10. data/lib/cisco_node_utils/cmd_ref/radius_global.yaml +1 -1
  11. data/lib/cisco_node_utils/cmd_ref/radius_server.yaml +1 -1
  12. data/lib/cisco_node_utils/cmd_ref/route_map.yaml +592 -0
  13. data/lib/cisco_node_utils/cmd_ref/snmp_community.yaml +40 -12
  14. data/lib/cisco_node_utils/cmd_ref/tacacs_global.yaml +1 -1
  15. data/lib/cisco_node_utils/cmd_ref/tacacs_server.yaml +1 -1
  16. data/lib/cisco_node_utils/cmd_ref/tacacs_server_host.yaml +1 -1
  17. data/lib/cisco_node_utils/cmd_ref/upgrade.yaml +38 -0
  18. data/lib/cisco_node_utils/dhcp_relay_global.rb +6 -2
  19. data/lib/cisco_node_utils/dns_domain.rb +2 -2
  20. data/lib/cisco_node_utils/environment.rb +1 -0
  21. data/lib/cisco_node_utils/interface.rb +58 -0
  22. data/lib/cisco_node_utils/itd_service.rb +5 -2
  23. data/lib/cisco_node_utils/node.rb +26 -13
  24. data/lib/cisco_node_utils/radius_global.rb +6 -1
  25. data/lib/cisco_node_utils/radius_server.rb +7 -1
  26. data/lib/cisco_node_utils/route_map.rb +2558 -0
  27. data/lib/cisco_node_utils/tacacs_global.rb +5 -2
  28. data/lib/cisco_node_utils/tacacs_server.rb +5 -2
  29. data/lib/cisco_node_utils/tacacs_server_host.rb +10 -4
  30. data/lib/cisco_node_utils/upgrade.rb +118 -0
  31. data/lib/cisco_node_utils/version.rb +1 -1
  32. data/spec/environment_spec.rb +16 -2
  33. data/tests/test_bgp_af.rb +8 -1
  34. data/tests/test_dhcp_relay_global.rb +3 -2
  35. data/tests/test_evpn_vni.rb +2 -2
  36. data/tests/test_feature.rb +4 -1
  37. data/tests/test_interface.rb +93 -0
  38. data/tests/test_interface_svi.rb +1 -0
  39. data/tests/test_itd_service.rb +4 -0
  40. data/tests/test_radius_global.rb +2 -2
  41. data/tests/test_radius_server.rb +6 -6
  42. data/tests/test_route_map.rb +1489 -0
  43. data/tests/test_router_bgp.rb +2 -0
  44. data/tests/test_snmpcommunity.rb +12 -0
  45. data/tests/test_snmpserver.rb +1 -1
  46. data/tests/test_snmpuser.rb +6 -9
  47. data/tests/test_tacacs_server.rb +2 -2
  48. data/tests/test_tacacs_server_host.rb +2 -2
  49. data/tests/test_upgrade.rb +106 -0
  50. data/tests/test_vlan.rb +2 -4
  51. data/tests/upgrade_info.yaml.example +3 -0
  52. data/tests/yum_package.yaml +13 -3
  53. metadata +9 -2
@@ -1,32 +1,50 @@
1
1
  # snmp_community
2
2
  ---
3
3
 
4
+ _template:
5
+ N3k: &template_structured
6
+ get_data_format: nxapi_structured
7
+ get_command: "show snmp community"
8
+ get_context: ["TABLE_snmp_community", "ROW_snmp_community"]
9
+ N9k: *template_structured
10
+ N9k-F: *template_structured
11
+
4
12
  acl:
5
- nexus:
6
- get_command: "show running snmp all"
7
- get_value: '/^snmp-server community <name> use-acl (.*)$/'
13
+ N3k: &acl_structured_get
14
+ kind: string
15
+ get_value: ["community_name <name>", "aclfilter", '/^(?:ACL mapped:\s+)?(\S+)/']
8
16
  set_value: "<state> snmp-server community <name> use-acl <acl>"
9
- default_value: ""
17
+ N9k: *acl_structured_get
18
+ N9k-F: *acl_structured_get
10
19
  ios_xr:
11
20
  get_command: "show running snmp"
12
21
  get_value: '/^snmp-server community <name> IPv4 (.*)$/'
13
22
  set_value: "<state> snmp-server community <name> <acl>"
14
- default_value: ""
23
+ N5k: &acl_cli_get
24
+ get_command: "show running snmp all"
25
+ get_value: '/^snmp-server community <name> use-acl (.*)$/'
26
+ set_value: "<state> snmp-server community <name> use-acl <acl>"
27
+ N6k: *acl_cli_get
28
+ N7k: *acl_cli_get
29
+ default_value: ""
15
30
 
16
31
  all_communities:
17
- nexus:
18
- multiple: true
32
+ multiple: true
33
+ N3k: &all_structured
34
+ get_value: 'community_name'
35
+ N9k: *all_structured
36
+ N9k-F: *all_structured
37
+ N5k: &all_cli
19
38
  get_command: "show running snmp all"
20
39
  get_value: '/^snmp-server community (\S+) /'
40
+ N6k: *all_cli
41
+ N7k: *all_cli
21
42
  ios_xr:
22
- multiple: true
23
43
  get_command: "show running-config snmp"
24
44
  get_value: '/^snmp-server community (\S+)/'
25
45
 
26
46
  community:
27
47
  nexus:
28
- get_command: "show running snmp all"
29
- get_value: '/^snmp-server community (%s) group .*$/'
30
48
  set_value: "<state> snmp-server community <name> group <group>"
31
49
  ios_xr:
32
50
  get_command: "show running-config snmp"
@@ -34,10 +52,20 @@ community:
34
52
  set_value: "<state> snmp-server community <name>"
35
53
 
36
54
  group:
55
+ N3k: &group_structured_get
56
+ kind: string
57
+ get_value: ["community_name <name>", "grouporaccess", '/^(?:Community groupname:\s+)?(\S+)/']
58
+ N9k: *group_structured_get
59
+ N9k-F: *group_structured_get
60
+ ios_xr: &group_cli_based_get
61
+ kind: string
37
62
  get_command: "show running snmp all"
38
63
  get_value: '/^snmp-server community <name> group (.*)$/'
39
- set_value: "snmp-server community <name> group <group>"
40
- default_value: "network-operator"
64
+ N5k: *group_cli_based_get
65
+ N6k: *group_cli_based_get
66
+ N7k: *group_cli_based_get
67
+ set_value: "snmp-server community <name> group <group>"
68
+ default_value: "network-operator"
41
69
 
42
70
  group_community_mapping:
43
71
  get_command: "show running snmp"
@@ -4,7 +4,7 @@ encryption:
4
4
  set_value: "<state> tacacs-server key <option> <key>"
5
5
 
6
6
  key:
7
- get_value: '/^tacacs-server key (\d+)\s+(\S+)/'
7
+ get_value: '/^tacacs-server key (\d+)\s+(.*)/'
8
8
  default_value: ""
9
9
  nexus:
10
10
  get_command: "show run tacacs all"
@@ -22,7 +22,7 @@ encryption:
22
22
  set_value: "<state> tacacs-server key <option> <key>"
23
23
 
24
24
  encryption_password:
25
- get_value: '/^tacacs-server key (\d+)\s+(\S+)/'
25
+ get_value: '/^tacacs-server key (\d+)\s+(.*)/'
26
26
  default_value: ""
27
27
  nexus:
28
28
  get_command: "show run tacacs all"
@@ -16,7 +16,7 @@ encryption:
16
16
  encryption_password:
17
17
  default_value: ""
18
18
  nexus:
19
- get_value: '/^tacacs-server host <ip> key \d+\s+(\S+)/'
19
+ get_value: '/^tacacs-server host <ip> key \d+\s+(.*)/'
20
20
  ios_xr:
21
21
  context: ["tacacs-server host <ip> port <port>"]
22
22
  get_value: '/key \d+\s+(\S+)$/'
@@ -0,0 +1,38 @@
1
+ # upgrade
2
+ ---
3
+ _exclude: [ios_xr, N5k, N6k, N7k]
4
+
5
+ clear_status:
6
+ set_value: "clear install status"
7
+
8
+ delete:
9
+ set_context: ['terminal dont-ask']
10
+ set_value: "delete <uri><image>"
11
+
12
+ delete_boot:
13
+ set_context: ['terminal dont-ask', 'allow delete boot-image']
14
+ set_value: "delete <uri><image>"
15
+
16
+ image_version:
17
+ get_command: "show version image <uri><image>"
18
+ get_value: '/NXOS:\s+version\s(\S+)/'
19
+
20
+ is_box_online:
21
+ set_context: ['conf t']
22
+ set_value: "sh clock"
23
+
24
+ save_config:
25
+ set_value: "copy running-config startup-config"
26
+
27
+ upgrade:
28
+ set_context: ['terminal dont-ask']
29
+ set_value: "install all nxos <uri><image>"
30
+
31
+ upgrade_force:
32
+ set_context: ['terminal dont-ask']
33
+ set_value: "install force-all nxos <uri><image>"
34
+
35
+ upgraded:
36
+ kind: boolean
37
+ get_command: 'show install all status'
38
+ get_value: '/Finishing the upgrade, switch will reboot|Install has been successful/'
@@ -206,8 +206,11 @@ module Cisco
206
206
 
207
207
  def ipv4_sub_option_circuit_id_string
208
208
  str = config_get('dhcp_relay_global', 'ipv4_sub_option_circuit_id_string')
209
- # Normalize by removing white space
210
- str.strip! if str
209
+ # Normalize by removing white space and add quotes
210
+ if str
211
+ str.strip!
212
+ str = Utils.add_quotes(str)
213
+ end
211
214
  str
212
215
  end
213
216
 
@@ -215,6 +218,7 @@ module Cisco
215
218
  state = val == default_ipv4_sub_option_circuit_id_string ? 'no' : ''
216
219
  format = val == default_ipv4_sub_option_circuit_id_string ? '' : 'format'
217
220
  word = val == default_ipv4_sub_option_circuit_id_string ? '' : val
221
+ word = Utils.add_quotes(word) unless word.empty?
218
222
  set_args_keys(state: state, format: format, word: word)
219
223
  config_set('dhcp_relay_global', 'ipv4_sub_option_circuit_id_string',
220
224
  @set_args)
@@ -61,9 +61,9 @@ module Cisco
61
61
  else
62
62
  # On some platforms attempts to create a new domain-list results
63
63
  # in the error. 'ERROR: Deletion of VRF test in progresswait
64
- # for it to complete'. We handle this by trying up to 10 times
64
+ # for it to complete'. We handle this by trying up to 20 times
65
65
  # with a 1 second delay between attempts before giving up.
66
- tries = 10
66
+ tries = 20
67
67
  begin
68
68
  config_set('dnsclient', 'domain_list_vrf',
69
69
  state: '', name: @name, vrf: @vrf)
@@ -39,6 +39,7 @@ module Cisco
39
39
  port: nil, # only applicable to gRPC
40
40
  username: nil,
41
41
  password: nil,
42
+ cookie: nil, # only applicable to nxapi
42
43
  }
43
44
 
44
45
  def self.environments
@@ -271,6 +271,7 @@ module Cisco
271
271
  end
272
272
 
273
273
  def hsrp_bfd=(val)
274
+ return if val == hsrp_bfd
274
275
  state = val ? '' : 'no'
275
276
  if val
276
277
  Feature.hsrp_enable
@@ -806,6 +807,62 @@ module Cisco
806
807
  config_set('interface', 'feature_lacp', state: val ? '' : 'no')
807
808
  end
808
809
 
810
+ def load_interval_counter_1_delay
811
+ return nil if @name[/loop/] || @name[/ethernet.*\S+\.\d+$/]
812
+ config_get('interface', 'load_interval_counter_1_delay', name: @name)
813
+ end
814
+
815
+ def load_interval_counter_1_delay=(val)
816
+ fail ArgumentError, 'Interface cannot be sub-intf or loopback' if
817
+ @name[/loop/] || @name[/ethernet.*\S+\.\d+$/]
818
+ config_set('interface', 'load_interval_counter_1_delay',
819
+ name: @name, delay: val)
820
+ end
821
+
822
+ def default_load_interval_counter_1_delay
823
+ # for vlan and bdi the default is 60
824
+ if @name[/(vlan|bdi)/i]
825
+ config_get_default('interface',
826
+ 'load_interval_counter_1_delay_vlan_bdi')
827
+ else
828
+ config_get_default('interface', 'load_interval_counter_1_delay')
829
+ end
830
+ end
831
+
832
+ def load_interval_counter_2_delay
833
+ return nil if @name[/loop/] || @name[/ethernet.*\S+\.\d+$/]
834
+ config_get('interface', 'load_interval_counter_2_delay', name: @name)
835
+ end
836
+
837
+ def load_interval_counter_2_delay=(val)
838
+ fail ArgumentError, 'Interface cannot be sub-intf or loopback' if
839
+ @name[/loop/] || @name[/ethernet.*\S+\.\d+$/]
840
+ config_set('interface', 'load_interval_counter_2_delay',
841
+ name: @name, delay: val)
842
+ end
843
+
844
+ def default_load_interval_counter_2_delay
845
+ config_get_default('interface', 'load_interval_counter_2_delay')
846
+ end
847
+
848
+ def load_interval_counter_3_delay
849
+ return nil if @name[/loop/] || @name[/ethernet.*\S+\.\d+$/]
850
+ config_get('interface', 'load_interval_counter_3_delay', name: @name)
851
+ end
852
+
853
+ def load_interval_counter_3_delay=(val)
854
+ fail ArgumentError, 'Interface cannot be sub-intf or loopback' if
855
+ @name[/loop/] || @name[/ethernet.*\S+\.\d+$/]
856
+ state = val ? '' : 'no'
857
+ delay = val ? val : ''
858
+ config_set('interface', 'load_interval_counter_3_delay',
859
+ name: @name, state: state, delay: delay)
860
+ end
861
+
862
+ def default_load_interval_counter_3_delay
863
+ config_get_default('interface', 'load_interval_counter_3_delay')
864
+ end
865
+
809
866
  def mtu_lookup_string
810
867
  case @name
811
868
  when /loopback/i
@@ -925,6 +982,7 @@ module Cisco
925
982
  end
926
983
 
927
984
  def pim_bfd=(val)
985
+ return if val == pim_bfd
928
986
  state = val ? '' : 'no'
929
987
  if val
930
988
  Feature.pim_enable
@@ -192,12 +192,15 @@ module Cisco
192
192
  # so translate back to the input format
193
193
  def ingress_interface
194
194
  list = config_get('itd_service', 'ingress_interface', @get_args)
195
- list.each do |intf, _next_hop|
195
+ rlist = []
196
+ list.each do |intf, next_hop|
196
197
  intf.gsub!('Eth', 'ethernet ')
197
198
  intf.gsub!('Po', 'port-channel ')
198
199
  intf.gsub!('Vlan', 'vlan ')
200
+ next_hop = '' if next_hop.nil?
201
+ rlist << [intf, next_hop]
199
202
  end
200
- list
203
+ rlist
201
204
  end
202
205
 
203
206
  def ingress_interface_cleanup
@@ -57,11 +57,11 @@ module Cisco
57
57
  return ref.default_value if ref.default_value? && !ref.getter?
58
58
 
59
59
  get_args, ref = massage_structured(ref.getter(*args).clone, ref)
60
- massage(get(command: ref.get_command,
61
- data_format: get_args[:data_format],
62
- context: get_args[:context],
63
- value: get_args[:value]),
64
- ref)
60
+ data = get(command: get_args[:command],
61
+ data_format: get_args[:data_format],
62
+ context: get_args[:context],
63
+ value: get_args[:value])
64
+ massage(data, ref)
65
65
  end
66
66
 
67
67
  # The yaml file may specifiy an Array as the get_value to drill down into
@@ -80,6 +80,8 @@ module Cisco
80
80
  # Example: Get vlanshowbr-vlanname in the row that contains a specific
81
81
  # vlan_id.
82
82
  # "get_value"=>["vlanshowbr-vlanid-utf <vlan_id>", "vlanshowbr-vlanname"]
83
+ #
84
+ # TBD: Why do we need to check is_a?(Array) here?
83
85
  if ref.hash['get_value'].is_a?(Array) && ref.hash['get_value'].size >= 2
84
86
  # Replace the get_value hash entry with the value after any tokens
85
87
  # specified in the yaml file have been replaced and set get_args[:value]
@@ -87,8 +89,8 @@ module Cisco
87
89
  ref.hash['get_value'] = get_args[:value]
88
90
  ref.hash['drill_down'] = true
89
91
  get_args[:value] = nil
92
+ cache_flush
90
93
  end
91
- cache_flush
92
94
  [get_args, ref]
93
95
  end
94
96
 
@@ -108,17 +110,22 @@ module Cisco
108
110
  row_index = ref.hash['get_value'][0][/\S+$/]
109
111
  data_key = ref.hash['get_value'][1]
110
112
  regexp_filter = nil
111
- regexp_filter = ref.hash['get_value'][2] if ref.hash['get_value'][2]
113
+ if ref.hash['get_value'][2]
114
+ regexp_filter = Regexp.new ref.hash['get_value'][2][1..-2]
115
+ end
112
116
 
113
117
  # Get the value using the row_key, row_index and data_key
114
118
  value = value.is_a?(Hash) ? [value] : value
115
- data = value.find { |item| item[row_key].to_s[/#{row_index}/] }
119
+ data = nil
120
+ value.each do |row|
121
+ data = row[data_key] if row[row_key].to_s.include? row_index.to_s
122
+ end
116
123
  return value if data.nil?
117
124
  if regexp_filter
118
- filtered = regexp_filter.match(data[data_key])
119
- return filtered.nil? ? filtered : filtered[0]
125
+ filtered = regexp_filter.match(data)
126
+ return filtered.nil? ? filtered : filtered[filtered.size - 1]
120
127
  end
121
- data[data_key]
128
+ data
122
129
  end
123
130
 
124
131
  # Attempt to massage the given value into the format specified by the
@@ -136,9 +143,16 @@ module Cisco
136
143
  return ref.default_value
137
144
  end
138
145
  if ref.multiple && ref.hash['get_data_format'] == :nxapi_structured
139
- value = [value.to_s] if value.size == 1
146
+ return value if value.nil?
147
+ value = [value.to_s] if value.is_a?(String) || value.is_a?(Fixnum)
140
148
  end
141
149
  return value unless ref.kind
150
+ value = massage_kind(value, ref)
151
+ Cisco::Logger.debug "Massaged to '#{value}'"
152
+ value
153
+ end
154
+
155
+ def massage_kind(value, ref)
142
156
  case ref.kind
143
157
  when :boolean
144
158
  if value.nil? || value.empty?
@@ -158,7 +172,6 @@ module Cisco
158
172
  when :symbol
159
173
  value = value.to_sym unless value.nil?
160
174
  end
161
- Cisco::Logger.debug "Massaged to '#{value}'"
162
175
  value
163
176
  end
164
177
 
@@ -101,7 +101,10 @@ module Cisco
101
101
  end
102
102
 
103
103
  def key
104
- config_get('radius_global', 'key')
104
+ str = config_get('radius_global', 'key')
105
+ return if str.nil?
106
+ str = str.strip
107
+ Utils.add_quotes(str)
105
108
  end
106
109
 
107
110
  def key_set(value, format)
@@ -121,11 +124,13 @@ module Cisco
121
124
  state: 'no',
122
125
  key: "#{key_format} #{key}")
123
126
  elsif !format.nil?
127
+ value = Utils.add_quotes(value)
124
128
  config_set('radius_global',
125
129
  'key',
126
130
  state: '',
127
131
  key: "#{format} #{value}")
128
132
  else
133
+ value = Utils.add_quotes(value)
129
134
  config_set('radius_global',
130
135
  'key',
131
136
  state: '',
@@ -369,7 +369,11 @@ module Cisco
369
369
  acct_port: @acct_port)
370
370
 
371
371
  val = val[0] if val.is_a?(Array)
372
- val
372
+ return if val.nil? || val.empty?
373
+ index = val.index('auth-port')
374
+ val = val[0..index - 2] unless index.nil?
375
+ val = val.strip
376
+ Utils.add_quotes(val)
373
377
  end
374
378
 
375
379
  def key_set(value, format)
@@ -395,6 +399,7 @@ module Cisco
395
399
  acct_port: @acct_port,
396
400
  key: "#{key_format} #{key}")
397
401
  elsif !format.nil?
402
+ value = Utils.add_quotes(value)
398
403
  config_set('radius_server',
399
404
  'key',
400
405
  state: '',
@@ -403,6 +408,7 @@ module Cisco
403
408
  acct_port: @acct_port,
404
409
  key: "#{format} #{value}")
405
410
  else
411
+ value = Utils.add_quotes(value)
406
412
  config_set('radius_server',
407
413
  'key',
408
414
  state: '',
@@ -0,0 +1,2558 @@
1
+ #
2
+ # January 2017, Sai Chintalapudi
3
+ #
4
+ # Copyright (c) 2017 Cisco and/or its affiliates.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require_relative 'node_util'
19
+
20
+ module Cisco
21
+ # node_utils class for route_map
22
+ class RouteMap < NodeUtil
23
+ attr_reader :name, :action, :seq
24
+
25
+ def initialize(map_name, sequence, action, instantiate=true)
26
+ fail TypeError unless map_name.is_a?(String)
27
+ fail ArgumentError unless action[/permit|deny/]
28
+ @name = map_name
29
+ @seq = sequence
30
+ @action = action
31
+
32
+ set_args_keys_default
33
+ create if instantiate
34
+ end
35
+
36
+ def self.maps
37
+ hash = {}
38
+ maps = config_get('route_map', 'all_route_maps')
39
+ return hash if maps.nil?
40
+ maps.each do |name, action, seq|
41
+ hash[name] ||= {}
42
+ hash[name][seq] ||= {}
43
+ hash[name][seq][action] = RouteMap.new(name, seq, action, false)
44
+ end
45
+ hash
46
+ end
47
+
48
+ # Helper method to delete @set_args hash keys
49
+ def set_args_keys_default
50
+ @set_args = { name: @name, action: @action, seq: @seq }
51
+ @get_args = @set_args
52
+ end
53
+
54
+ # rubocop:disable Style/AccessorMethodName
55
+ def set_args_keys(hash={})
56
+ set_args_keys_default
57
+ @set_args = @get_args.merge!(hash) unless hash.empty?
58
+ end
59
+
60
+ # Create one route map instance
61
+ def create
62
+ config_set('route_map', 'create', @set_args)
63
+ end
64
+
65
+ def destroy
66
+ config_set('route_map', 'destroy', @set_args)
67
+ end
68
+
69
+ ########################################################
70
+ # PROPERTIES #
71
+ ########################################################
72
+
73
+ # match as-number 12, 13-23, 45
74
+ def match_as_number
75
+ arr = []
76
+ match_array = config_get('route_map', 'match_as_number', @get_args)
77
+ match_array.each do |line|
78
+ next if line.include?('as-path-list')
79
+ arr = line.strip.split(', ')
80
+ end
81
+ arr
82
+ end
83
+
84
+ def match_as_number=(list)
85
+ carr = match_as_number
86
+ cstr = ''
87
+ carr.each do |elem|
88
+ cstr = cstr.concat(elem + ', ')
89
+ end
90
+ unless cstr.empty?
91
+ cstr.chomp!(', ')
92
+ set_args_keys(state: 'no', num: cstr)
93
+ # reset the current config
94
+ config_set('route_map', 'match_as_number', @set_args)
95
+ end
96
+ nstr = ''
97
+ list.each do |elem|
98
+ nstr = nstr.concat(elem + ', ')
99
+ end
100
+ return if nstr.empty?
101
+ nstr.chomp!(', ')
102
+ set_args_keys(state: '', num: nstr)
103
+ config_set('route_map', 'match_as_number', @set_args)
104
+ end
105
+
106
+ def default_match_as_number
107
+ config_get_default('route_map', 'match_as_number')
108
+ end
109
+
110
+ # match as-number as-path-list abc xyz
111
+ def match_as_number_as_path_list
112
+ str = config_get('route_map', 'match_as_number_as_path_list', @get_args)
113
+ str.empty? ? default_match_as_number_as_path_list : str.split
114
+ end
115
+
116
+ def match_as_number_as_path_list=(list)
117
+ carr = match_as_number_as_path_list
118
+ cstr = ''
119
+ carr.each do |elem|
120
+ cstr = cstr.concat(elem + ' ')
121
+ end
122
+ unless cstr.empty?
123
+ set_args_keys(state: 'no', list: cstr)
124
+ # reset the current config
125
+ config_set('route_map', 'match_as_number_as_path_list', @set_args)
126
+ end
127
+ nstr = ''
128
+ list.each do |elem|
129
+ nstr = nstr.concat(elem + ' ')
130
+ end
131
+ return if nstr.empty?
132
+ set_args_keys(state: '', list: nstr)
133
+ config_set('route_map', 'match_as_number_as_path_list', @set_args)
134
+ end
135
+
136
+ def default_match_as_number_as_path_list
137
+ config_get_default('route_map', 'match_as_number_as_path_list')
138
+ end
139
+
140
+ def description
141
+ config_get('route_map', 'description', @get_args)
142
+ end
143
+
144
+ def description=(val)
145
+ state = val ? '' : 'no'
146
+ desc = val ? val : ''
147
+ set_args_keys(state: state, desc: desc)
148
+ config_set('route_map', 'description', @set_args)
149
+ end
150
+
151
+ def default_description
152
+ config_get_default('route_map', 'description')
153
+ end
154
+
155
+ # match community public private exact-match
156
+ def match_community
157
+ str = config_get('route_map', 'match_community', @get_args)
158
+ if str.empty?
159
+ val = default_match_community
160
+ else
161
+ val = str.split
162
+ val.delete('exact-match')
163
+ end
164
+ val
165
+ end
166
+
167
+ def match_community_set(list, exact)
168
+ carr = match_community
169
+ cstr = ''
170
+ carr.each do |elem|
171
+ cstr = cstr.concat(elem + ' ')
172
+ end
173
+ unless cstr.empty?
174
+ set_args_keys(state: 'no', comm: cstr)
175
+ # reset the current config
176
+ config_set('route_map', 'match_community', @set_args)
177
+ end
178
+ nstr = ''
179
+ list.each do |elem|
180
+ nstr = nstr.concat(elem + ' ')
181
+ end
182
+ return if nstr.empty?
183
+ nstr.concat('exact-match') if exact
184
+ set_args_keys(state: '', comm: nstr)
185
+ config_set('route_map', 'match_community', @set_args)
186
+ end
187
+
188
+ def default_match_community
189
+ config_get_default('route_map', 'match_community')
190
+ end
191
+
192
+ # match extcommunity public private exact-match
193
+ def match_community_exact_match
194
+ config_get('route_map', 'match_community',
195
+ @get_args).include?('exact-match')
196
+ end
197
+
198
+ def default_match_community_exact_match
199
+ config_get_default('route_map', 'match_community_exact_match')
200
+ end
201
+
202
+ def match_ext_community
203
+ str = config_get('route_map', 'match_ext_community', @get_args)
204
+ if str.empty?
205
+ val = default_match_ext_community
206
+ else
207
+ val = str.split
208
+ val.delete('exact-match')
209
+ end
210
+ val
211
+ end
212
+
213
+ def match_ext_community_set(list, exact)
214
+ carr = match_ext_community
215
+ cstr = ''
216
+ carr.each do |elem|
217
+ cstr = cstr.concat(elem + ' ')
218
+ end
219
+ unless cstr.empty?
220
+ set_args_keys(state: 'no', comm: cstr)
221
+ # reset the current config
222
+ config_set('route_map', 'match_ext_community', @set_args)
223
+ end
224
+ nstr = ''
225
+ list.each do |elem|
226
+ nstr = nstr.concat(elem + ' ')
227
+ end
228
+ return if nstr.empty?
229
+ nstr.concat('exact-match') if exact
230
+ set_args_keys(state: '', comm: nstr)
231
+ config_set('route_map', 'match_ext_community', @set_args)
232
+ end
233
+
234
+ def default_match_ext_community
235
+ config_get_default('route_map', 'match_ext_community')
236
+ end
237
+
238
+ def match_ext_community_exact_match
239
+ config_get('route_map', 'match_ext_community',
240
+ @get_args).include?('exact-match')
241
+ end
242
+
243
+ def default_match_ext_community_exact_match
244
+ config_get_default('route_map', 'match_ext_community_exact_match')
245
+ end
246
+
247
+ # match interface port-channel1 Null0 (and so on)
248
+ def match_interface
249
+ str = config_get('route_map', 'match_interface', @get_args)
250
+ intf = str.empty? ? default_match_interface : str.split
251
+ # Normalize by downcasing
252
+ intf.map!(&:downcase)
253
+ end
254
+
255
+ def match_interface=(list)
256
+ carr = match_interface
257
+ cstr = ''
258
+ carr.each do |elem|
259
+ cstr = cstr.concat(elem + ' ')
260
+ end
261
+ unless cstr.empty?
262
+ set_args_keys(state: 'no', int: cstr)
263
+ # reset the current config
264
+ config_set('route_map', 'match_interface', @set_args)
265
+ end
266
+ nstr = ''
267
+ list.each do |elem|
268
+ nstr = nstr.concat(elem + ' ')
269
+ end
270
+ return if nstr.empty?
271
+ set_args_keys(state: '', int: nstr)
272
+ config_set('route_map', 'match_interface', @set_args)
273
+ end
274
+
275
+ def default_match_interface
276
+ config_get_default('route_map', 'match_interface')
277
+ end
278
+
279
+ # match tag 11 5 28
280
+ def match_tag
281
+ str = config_get('route_map', 'match_tag', @get_args)
282
+ str.empty? ? default_match_tag : str.split
283
+ end
284
+
285
+ def match_tag=(list)
286
+ carr = match_tag
287
+ cstr = ''
288
+ carr.each do |elem|
289
+ cstr = cstr.concat(elem + ' ')
290
+ end
291
+ unless cstr.empty?
292
+ set_args_keys(state: 'no', tag: cstr)
293
+ # reset the current config
294
+ config_set('route_map', 'match_tag', @set_args)
295
+ end
296
+ nstr = ''
297
+ list.each do |elem|
298
+ nstr = nstr.concat(elem + ' ')
299
+ end
300
+ return if nstr.empty?
301
+ set_args_keys(state: '', tag: nstr)
302
+ config_set('route_map', 'match_tag', @set_args)
303
+ end
304
+
305
+ def default_match_tag
306
+ config_get_default('route_map', 'match_tag')
307
+ end
308
+
309
+ # match source-protocol tcp udp
310
+ def match_src_proto
311
+ str = config_get('route_map', 'match_src_proto', @get_args)
312
+ str.empty? ? default_match_src_proto : str.split
313
+ end
314
+
315
+ def match_src_proto=(list)
316
+ carr = match_src_proto
317
+ cstr = ''
318
+ carr.each do |elem|
319
+ cstr = cstr.concat(elem + ' ')
320
+ end
321
+ unless cstr.empty?
322
+ set_args_keys(state: 'no', proto: cstr)
323
+ # reset the current config
324
+ config_set('route_map', 'match_src_proto', @set_args)
325
+ end
326
+ nstr = ''
327
+ list.each do |elem|
328
+ nstr = nstr.concat(elem + ' ')
329
+ end
330
+ return if nstr.empty?
331
+ set_args_keys(state: '', proto: nstr)
332
+ config_set('route_map', 'match_src_proto', @set_args)
333
+ end
334
+
335
+ def default_match_src_proto
336
+ config_get_default('route_map', 'match_src_proto')
337
+ end
338
+
339
+ def match_ipv4_addr_access_list
340
+ val = default_match_ipv4_addr_access_list
341
+ arr = config_get('route_map', 'match_ipv4_addr_access_list', @get_args)
342
+ if arr
343
+ arr.each do |line|
344
+ next if line.include?('prefix-list')
345
+ val = line.strip
346
+ end
347
+ end
348
+ val
349
+ end
350
+
351
+ def match_ipv4_addr_access_list_set(val)
352
+ cval = match_ipv4_addr_access_list
353
+ return if val == cval
354
+ state = val ? '' : 'no'
355
+ al = val ? val : cval
356
+ set_args_keys(state: state, access: al)
357
+ config_set('route_map', 'match_ipv4_addr_access_list', @set_args)
358
+ end
359
+
360
+ def default_match_ipv4_addr_access_list
361
+ config_get_default('route_map', 'match_ipv4_addr_access_list')
362
+ end
363
+
364
+ # match ip address prefix-list pre1 pre2
365
+ def match_ipv4_addr_prefix_list
366
+ str = config_get('route_map', 'match_ipv4_addr_prefix_list', @get_args)
367
+ str.empty? ? default_match_ipv4_addr_prefix_list : str.split
368
+ end
369
+
370
+ def match_ipv4_addr_prefix_list_set(list)
371
+ carr = match_ipv4_addr_prefix_list
372
+ cstr = ''
373
+ carr.each do |elem|
374
+ cstr = cstr.concat(elem + ' ')
375
+ end
376
+ unless cstr.empty?
377
+ set_args_keys(state: 'no', prefix: cstr)
378
+ # reset the current config
379
+ config_set('route_map', 'match_ipv4_addr_prefix_list', @set_args)
380
+ end
381
+ nstr = ''
382
+ list.each do |elem|
383
+ nstr = nstr.concat(elem + ' ')
384
+ end
385
+ return if nstr.empty?
386
+ set_args_keys(state: '', prefix: nstr)
387
+ config_set('route_map', 'match_ipv4_addr_prefix_list', @set_args)
388
+ end
389
+
390
+ def default_match_ipv4_addr_prefix_list
391
+ config_get_default('route_map', 'match_ipv4_addr_prefix_list')
392
+ end
393
+
394
+ # match ip next-hop prefix-list nhop1 nhop2
395
+ def match_ipv4_next_hop_prefix_list
396
+ str = config_get('route_map', 'match_ipv4_next_hop_prefix_list',
397
+ @get_args)
398
+ str.empty? ? default_match_ipv4_next_hop_prefix_list : str.split
399
+ end
400
+
401
+ def match_ipv4_next_hop_prefix_list=(list)
402
+ carr = match_ipv4_next_hop_prefix_list
403
+ cstr = ''
404
+ carr.each do |elem|
405
+ cstr = cstr.concat(elem + ' ')
406
+ end
407
+ unless cstr.empty?
408
+ set_args_keys(state: 'no', prefix: cstr)
409
+ # reset the current config
410
+ config_set('route_map', 'match_ipv4_next_hop_prefix_list', @set_args)
411
+ end
412
+ nstr = ''
413
+ list.each do |elem|
414
+ nstr = nstr.concat(elem + ' ')
415
+ end
416
+ return if nstr.empty?
417
+ set_args_keys(state: '', prefix: nstr)
418
+ config_set('route_map', 'match_ipv4_next_hop_prefix_list', @set_args)
419
+ end
420
+
421
+ def default_match_ipv4_next_hop_prefix_list
422
+ config_get_default('route_map', 'match_ipv4_next_hop_prefix_list')
423
+ end
424
+
425
+ # match ip route-source prefix-list rs1 rs2
426
+ def match_ipv4_route_src_prefix_list
427
+ str = config_get('route_map', 'match_ipv4_route_src_prefix_list',
428
+ @get_args)
429
+ str.empty? ? default_match_ipv4_route_src_prefix_list : str.split
430
+ end
431
+
432
+ def match_ipv4_route_src_prefix_list=(list)
433
+ carr = match_ipv4_route_src_prefix_list
434
+ cstr = ''
435
+ carr.each do |elem|
436
+ cstr = cstr.concat(elem + ' ')
437
+ end
438
+ unless cstr.empty?
439
+ set_args_keys(state: 'no', prefix: cstr)
440
+ # reset the current config
441
+ config_set('route_map', 'match_ipv4_route_src_prefix_list', @set_args)
442
+ end
443
+ nstr = ''
444
+ list.each do |elem|
445
+ nstr = nstr.concat(elem + ' ')
446
+ end
447
+ return if nstr.empty?
448
+ set_args_keys(state: '', prefix: nstr)
449
+ config_set('route_map', 'match_ipv4_route_src_prefix_list', @set_args)
450
+ end
451
+
452
+ def default_match_ipv4_route_src_prefix_list
453
+ config_get_default('route_map', 'match_ipv4_route_src_prefix_list')
454
+ end
455
+
456
+ # extract value of property from match ip multicast
457
+ def extract_value(type, prop, prefix=nil)
458
+ prefix = prop if prefix.nil?
459
+ match =
460
+ type == 'ipv4' ? match_ipv4_multicast_get : match_ipv6_multicast_get
461
+
462
+ # matching not found
463
+ return nil if match.nil? # no matching found
464
+
465
+ # property not defined for matching
466
+ return nil unless match.names.include?(prop)
467
+
468
+ # extract and return value that follows prefix + <space>
469
+ regexp = Regexp.new("#{Regexp.escape(prefix)} (?<extracted>.*)")
470
+ value_match = regexp.match(match[prop])
471
+ return nil if value_match.nil?
472
+ value_match[:extracted]
473
+ end
474
+
475
+ # prepend property name prefix/keyword to value
476
+ def attach_prefix(val, prop, prefix=nil)
477
+ prefix = prop.to_s if prefix.nil?
478
+ @set_args[prop] = val.to_s.empty? ? val : "#{prefix} #{val}"
479
+ end
480
+
481
+ # match ip multicast source 242.1.1.1/32 group 239.2.2.2/32 rp 242.1.1.1/32
482
+ # rp-type ASM
483
+ # match ip multicast source 242.1.1.1/32 group-range
484
+ # 239.1.1.1 to 239.2.2.2 rp 242.1.1.1/32 rp-type Bidir
485
+ def match_ipv4_multicast_get
486
+ str = config_get('route_map', 'match_ipv4_multicast', @get_args)
487
+ return nil if str.nil?
488
+ regexp = Regexp.new('match ip multicast *(?<src>source \S+)?'\
489
+ ' *(?<grp>group \S+)?'\
490
+ ' *(?<grp_range_start>group-range \S+)?'\
491
+ ' *(?<grp_range_end>to \S+)?'\
492
+ ' *(?<rp>rp \S+)?'\
493
+ ' *(?<rp_type>rp-type \S+)?')
494
+ regexp.match(str)
495
+ end
496
+
497
+ def match_ipv4_multicast_src_addr
498
+ val = extract_value('ipv4', 'src', 'source')
499
+ return default_match_ipv4_multicast_src_addr if val.nil?
500
+ val
501
+ end
502
+
503
+ def match_ipv4_multicast_src_addr=(src_addr)
504
+ attach_prefix(src_addr, :source)
505
+ end
506
+
507
+ def default_match_ipv4_multicast_src_addr
508
+ config_get_default('route_map', 'match_ipv4_multicast_src_addr')
509
+ end
510
+
511
+ def match_ipv4_multicast_group_addr
512
+ val = extract_value('ipv4', 'grp', 'group')
513
+ return default_match_ipv4_multicast_group_addr if val.nil?
514
+ val
515
+ end
516
+
517
+ def match_ipv4_multicast_group_addr=(grp_addr)
518
+ attach_prefix(grp_addr, :group)
519
+ end
520
+
521
+ def default_match_ipv4_multicast_group_addr
522
+ config_get_default('route_map', 'match_ipv4_multicast_group_addr')
523
+ end
524
+
525
+ def match_ipv4_multicast_group_range_begin_addr
526
+ val = extract_value('ipv4', 'grp_range_start', 'group-range')
527
+ return default_match_ipv4_multicast_group_range_begin_addr if val.nil?
528
+ val
529
+ end
530
+
531
+ def match_ipv4_multicast_group_range_begin_addr=(begin_addr)
532
+ attach_prefix(begin_addr, :group_range, :'group-range')
533
+ end
534
+
535
+ def default_match_ipv4_multicast_group_range_begin_addr
536
+ config_get_default('route_map',
537
+ 'match_ipv4_multicast_group_range_begin_addr')
538
+ end
539
+
540
+ def match_ipv4_multicast_group_range_end_addr
541
+ val = extract_value('ipv4', 'grp_range_end', 'to')
542
+ return default_match_ipv4_multicast_group_range_end_addr if val.nil?
543
+ val
544
+ end
545
+
546
+ def match_ipv4_multicast_group_range_end_addr=(end_addr)
547
+ attach_prefix(end_addr, :to)
548
+ end
549
+
550
+ def default_match_ipv4_multicast_group_range_end_addr
551
+ config_get_default('route_map',
552
+ 'match_ipv4_multicast_group_range_end_addr')
553
+ end
554
+
555
+ def match_ipv4_multicast_rp_addr
556
+ val = extract_value('ipv4', 'rp')
557
+ return default_match_ipv4_multicast_rp_addr if val.nil?
558
+ val
559
+ end
560
+
561
+ def match_ipv4_multicast_rp_addr=(rp_addr)
562
+ attach_prefix(rp_addr, :rp)
563
+ end
564
+
565
+ def default_match_ipv4_multicast_rp_addr
566
+ config_get_default('route_map', 'match_ipv4_multicast_rp_addr')
567
+ end
568
+
569
+ def match_ipv4_multicast_rp_type
570
+ val = extract_value('ipv4', 'rp_type', 'rp-type')
571
+ return default_match_ipv4_multicast_rp_type if val.nil?
572
+ val
573
+ end
574
+
575
+ def match_ipv4_multicast_rp_type=(type)
576
+ attach_prefix(type, :rp_type, :'rp-type')
577
+ end
578
+
579
+ def default_match_ipv4_multicast_rp_type
580
+ config_get_default('route_map', 'match_ipv4_multicast_rp_type')
581
+ end
582
+
583
+ def match_ipv4_multicast_enable
584
+ match_ipv4_multicast_get.nil? ? default_match_ipv4_multicast_enable : true
585
+ end
586
+
587
+ def match_ipv4_multicast_enable=(enable)
588
+ @set_args[:state] = enable ? '' : 'no'
589
+ end
590
+
591
+ def default_match_ipv4_multicast_enable
592
+ config_get_default('route_map', 'match_ipv4_multicast_enable')
593
+ end
594
+
595
+ def match_ipv4_multicast_set(attrs)
596
+ set_args_keys(attrs)
597
+ [:match_ipv4_multicast_src_addr,
598
+ :match_ipv4_multicast_group_addr,
599
+ :match_ipv4_multicast_group_range_begin_addr,
600
+ :match_ipv4_multicast_group_range_end_addr,
601
+ :match_ipv4_multicast_rp_addr,
602
+ :match_ipv4_multicast_rp_type,
603
+ :match_ipv4_multicast_enable,
604
+ ].each do |p|
605
+ attrs[p] = '' if attrs[p].nil?
606
+ send(p.to_s + '=', attrs[p])
607
+ end
608
+ @get_args = @set_args
609
+ config_set('route_map', 'match_ipv4_multicast', @set_args)
610
+ end
611
+
612
+ def match_ipv6_addr_access_list
613
+ val = default_match_ipv6_addr_access_list
614
+ arr = config_get('route_map', 'match_ipv6_addr_access_list', @get_args)
615
+ if arr
616
+ arr.each do |line|
617
+ next if line.include?('prefix-list')
618
+ val = line.strip
619
+ end
620
+ end
621
+ val
622
+ end
623
+
624
+ def match_ipv6_addr_access_list_set(val)
625
+ cval = match_ipv6_addr_access_list
626
+ return if val == cval
627
+ state = val ? '' : 'no'
628
+ al = val ? val : cval
629
+ set_args_keys(state: state, access: al)
630
+ config_set('route_map', 'match_ipv6_addr_access_list', @set_args)
631
+ end
632
+
633
+ def default_match_ipv6_addr_access_list
634
+ config_get_default('route_map', 'match_ipv6_addr_access_list')
635
+ end
636
+
637
+ def match_ip_addr_access_list(v4, v6)
638
+ match_ipv4_addr_access_list_set(default_match_ipv4_addr_access_list)
639
+ match_ipv6_addr_access_list_set(default_match_ipv6_addr_access_list)
640
+ match_ipv4_addr_access_list_set(v4)
641
+ match_ipv6_addr_access_list_set(v6)
642
+ end
643
+
644
+ def match_ipv6_addr_prefix_list
645
+ str = config_get('route_map', 'match_ipv6_addr_prefix_list', @get_args)
646
+ str.empty? ? default_match_ipv6_addr_prefix_list : str.split
647
+ end
648
+
649
+ def match_ipv6_addr_prefix_list_set(list)
650
+ carr = match_ipv6_addr_prefix_list
651
+ cstr = ''
652
+ carr.each do |elem|
653
+ cstr = cstr.concat(elem + ' ')
654
+ end
655
+ unless cstr.empty?
656
+ set_args_keys(state: 'no', prefix: cstr)
657
+ # reset the current config
658
+ config_set('route_map', 'match_ipv6_addr_prefix_list', @set_args)
659
+ end
660
+ nstr = ''
661
+ list.each do |elem|
662
+ nstr = nstr.concat(elem + ' ')
663
+ end
664
+ return if nstr.empty?
665
+ set_args_keys(state: '', prefix: nstr)
666
+ config_set('route_map', 'match_ipv6_addr_prefix_list', @set_args)
667
+ end
668
+
669
+ def default_match_ipv6_addr_prefix_list
670
+ config_get_default('route_map', 'match_ipv6_addr_prefix_list')
671
+ end
672
+
673
+ def match_ip_addr_prefix_list(v4, v6)
674
+ match_ipv4_addr_prefix_list_set(default_match_ipv4_addr_prefix_list)
675
+ match_ipv6_addr_prefix_list_set(default_match_ipv6_addr_prefix_list)
676
+ match_ipv4_addr_prefix_list_set(v4)
677
+ match_ipv6_addr_prefix_list_set(v6)
678
+ end
679
+
680
+ def match_ipv6_next_hop_prefix_list
681
+ str = config_get('route_map', 'match_ipv6_next_hop_prefix_list',
682
+ @get_args)
683
+ str.empty? ? default_match_ipv6_next_hop_prefix_list : str.split
684
+ end
685
+
686
+ def match_ipv6_next_hop_prefix_list=(list)
687
+ carr = match_ipv6_next_hop_prefix_list
688
+ cstr = ''
689
+ carr.each do |elem|
690
+ cstr = cstr.concat(elem + ' ')
691
+ end
692
+ unless cstr.empty?
693
+ set_args_keys(state: 'no', prefix: cstr)
694
+ # reset the current config
695
+ config_set('route_map', 'match_ipv6_next_hop_prefix_list', @set_args)
696
+ end
697
+ nstr = ''
698
+ list.each do |elem|
699
+ nstr = nstr.concat(elem + ' ')
700
+ end
701
+ return if nstr.empty?
702
+ set_args_keys(state: '', prefix: nstr)
703
+ config_set('route_map', 'match_ipv6_next_hop_prefix_list', @set_args)
704
+ end
705
+
706
+ def default_match_ipv6_next_hop_prefix_list
707
+ config_get_default('route_map', 'match_ipv6_next_hop_prefix_list')
708
+ end
709
+
710
+ def match_ipv6_route_src_prefix_list
711
+ str = config_get('route_map', 'match_ipv6_route_src_prefix_list',
712
+ @get_args)
713
+ str.empty? ? default_match_ipv6_route_src_prefix_list : str.split
714
+ end
715
+
716
+ def match_ipv6_route_src_prefix_list=(list)
717
+ carr = match_ipv6_route_src_prefix_list
718
+ cstr = ''
719
+ carr.each do |elem|
720
+ cstr = cstr.concat(elem + ' ')
721
+ end
722
+ unless cstr.empty?
723
+ set_args_keys(state: 'no', prefix: cstr)
724
+ # reset the current config
725
+ config_set('route_map', 'match_ipv6_route_src_prefix_list', @set_args)
726
+ end
727
+ nstr = ''
728
+ list.each do |elem|
729
+ nstr = nstr.concat(elem + ' ')
730
+ end
731
+ return if nstr.empty?
732
+ set_args_keys(state: '', prefix: nstr)
733
+ config_set('route_map', 'match_ipv6_route_src_prefix_list', @set_args)
734
+ end
735
+
736
+ def default_match_ipv6_route_src_prefix_list
737
+ config_get_default('route_map', 'match_ipv6_route_src_prefix_list')
738
+ end
739
+
740
+ def match_ipv6_multicast_get
741
+ str = config_get('route_map', 'match_ipv6_multicast', @get_args)
742
+ return nil if str.nil?
743
+ regexp = Regexp.new('match ipv6 multicast *(?<src>source \S+)?'\
744
+ ' *(?<grp>group \S+)?'\
745
+ ' *(?<grp_range_start>group-range \S+)?'\
746
+ ' *(?<grp_range_end>to \S+)?'\
747
+ ' *(?<rp>rp \S+)?'\
748
+ ' *(?<rp_type>rp-type \S+)?')
749
+ regexp.match(str)
750
+ end
751
+
752
+ def match_ipv6_multicast_src_addr
753
+ val = extract_value('ipv6', 'src', 'source')
754
+ return default_match_ipv6_multicast_src_addr if val.nil?
755
+ val
756
+ end
757
+
758
+ def match_ipv6_multicast_src_addr=(src_addr)
759
+ attach_prefix(src_addr, :source)
760
+ end
761
+
762
+ def default_match_ipv6_multicast_src_addr
763
+ config_get_default('route_map', 'match_ipv6_multicast_src_addr')
764
+ end
765
+
766
+ def match_ipv6_multicast_group_addr
767
+ val = extract_value('ipv6', 'grp', 'group')
768
+ return default_match_ipv6_multicast_group_addr if val.nil?
769
+ val
770
+ end
771
+
772
+ def match_ipv6_multicast_group_addr=(grp_addr)
773
+ attach_prefix(grp_addr, :group)
774
+ end
775
+
776
+ def default_match_ipv6_multicast_group_addr
777
+ config_get_default('route_map', 'match_ipv6_multicast_group_addr')
778
+ end
779
+
780
+ def match_ipv6_multicast_group_range_begin_addr
781
+ val = extract_value('ipv6', 'grp_range_start', 'group-range')
782
+ return default_match_ipv6_multicast_group_range_begin_addr if val.nil?
783
+ val
784
+ end
785
+
786
+ def match_ipv6_multicast_group_range_begin_addr=(begin_addr)
787
+ attach_prefix(begin_addr, :group_range, :'group-range')
788
+ end
789
+
790
+ def default_match_ipv6_multicast_group_range_begin_addr
791
+ config_get_default('route_map',
792
+ 'match_ipv6_multicast_group_range_begin_addr')
793
+ end
794
+
795
+ def match_ipv6_multicast_group_range_end_addr
796
+ val = extract_value('ipv6', 'grp_range_end', 'to')
797
+ return default_match_ipv6_multicast_group_range_end_addr if val.nil?
798
+ val
799
+ end
800
+
801
+ def match_ipv6_multicast_group_range_end_addr=(end_addr)
802
+ attach_prefix(end_addr, :to)
803
+ end
804
+
805
+ def default_match_ipv6_multicast_group_range_end_addr
806
+ config_get_default('route_map',
807
+ 'match_ipv6_multicast_group_range_end_addr')
808
+ end
809
+
810
+ def match_ipv6_multicast_rp_addr
811
+ val = extract_value('ipv6', 'rp')
812
+ return default_match_ipv6_multicast_rp_addr if val.nil?
813
+ val
814
+ end
815
+
816
+ def match_ipv6_multicast_rp_addr=(rp_addr)
817
+ attach_prefix(rp_addr, :rp)
818
+ end
819
+
820
+ def default_match_ipv6_multicast_rp_addr
821
+ config_get_default('route_map', 'match_ipv6_multicast_rp_addr')
822
+ end
823
+
824
+ def match_ipv6_multicast_rp_type
825
+ val = extract_value('ipv6', 'rp_type', 'rp-type')
826
+ return default_match_ipv6_multicast_rp_type if val.nil?
827
+ val
828
+ end
829
+
830
+ def match_ipv6_multicast_rp_type=(type)
831
+ attach_prefix(type, :rp_type, :'rp-type')
832
+ end
833
+
834
+ def default_match_ipv6_multicast_rp_type
835
+ config_get_default('route_map', 'match_ipv6_multicast_rp_type')
836
+ end
837
+
838
+ def match_ipv6_multicast_enable
839
+ match_ipv6_multicast_get.nil? ? default_match_ipv6_multicast_enable : true
840
+ end
841
+
842
+ def match_ipv6_multicast_enable=(enable)
843
+ @set_args[:state] = enable ? '' : 'no'
844
+ end
845
+
846
+ def default_match_ipv6_multicast_enable
847
+ config_get_default('route_map', 'match_ipv6_multicast_enable')
848
+ end
849
+
850
+ def match_ipv6_multicast_set(attrs)
851
+ set_args_keys(attrs)
852
+ [:match_ipv6_multicast_src_addr,
853
+ :match_ipv6_multicast_group_addr,
854
+ :match_ipv6_multicast_group_range_begin_addr,
855
+ :match_ipv6_multicast_group_range_end_addr,
856
+ :match_ipv6_multicast_rp_addr,
857
+ :match_ipv6_multicast_rp_type,
858
+ :match_ipv6_multicast_enable,
859
+ ].each do |p|
860
+ attrs[p] = '' if attrs[p].nil?
861
+ send(p.to_s + '=', attrs[p])
862
+ end
863
+ @get_args = @set_args
864
+ config_set('route_map', 'match_ipv6_multicast', @set_args)
865
+ end
866
+
867
+ # match metric 1 8 224 +- 9 23 5 +- 8 6
868
+ def match_metric
869
+ str = config_get('route_map', 'match_metric', @get_args)
870
+ return default_match_metric if str.empty?
871
+ rarr = []
872
+ larr = []
873
+ metrics = str.split
874
+ deviation = false
875
+ metrics.each do |metric|
876
+ deviation = true if metric == '+-'
877
+ if !larr.empty? && !deviation
878
+ larr << '0'
879
+ rarr << larr
880
+ larr = []
881
+ end
882
+ next if metric == '+-'
883
+ if !larr.empty? && deviation
884
+ larr << metric
885
+ rarr << larr
886
+ larr = []
887
+ deviation = false
888
+ next
889
+ end
890
+ larr << metric if larr.empty?
891
+ end
892
+ unless larr.empty?
893
+ larr << '0'
894
+ rarr << larr
895
+ end
896
+ rarr
897
+ end
898
+
899
+ def match_metric=(list)
900
+ clist = match_metric
901
+ # reset first
902
+ unless clist.empty?
903
+ str = ''
904
+ clist.each do |metric, deviation|
905
+ str.concat(metric + ' ')
906
+ str.concat('+ ' + deviation + ' ') unless deviation == '0'
907
+ end
908
+ set_args_keys(state: 'no', metric: str)
909
+ config_set('route_map', 'match_metric', @set_args)
910
+ end
911
+ return if list.empty?
912
+ str = ''
913
+ list.each do |metric, deviation|
914
+ str.concat(metric + ' ')
915
+ str.concat('+ ' + deviation + ' ') unless deviation == '0'
916
+ end
917
+ set_args_keys(state: '', metric: str)
918
+ config_set('route_map', 'match_metric', @set_args)
919
+ end
920
+
921
+ def default_match_metric
922
+ config_get_default('route_map', 'match_metric')
923
+ end
924
+
925
+ # match route-type external internal (and so on)
926
+ # or in some platforms
927
+ # match route-type external
928
+ # match route-type internal
929
+ # etc.
930
+ def match_route_type_get
931
+ hash = {}
932
+ hash[:external] = false
933
+ hash[:inter_area] = false
934
+ hash[:internal] = false
935
+ hash[:intra_area] = false
936
+ hash[:level_1] = false
937
+ hash[:level_2] = false
938
+ hash[:local] = false
939
+ hash[:nssa_external] = false
940
+ hash[:type_1] = false
941
+ hash[:type_2] = false
942
+ str = config_get('route_map', 'match_route_type', @get_args)
943
+ return hash if str.nil?
944
+ str = str[0] if str.length == 1
945
+ hash[:external] = true if str.include?('external')
946
+ hash[:inter_area] = true if str.include?('inter-area')
947
+ hash[:internal] = true if str.include?('internal')
948
+ hash[:intra_area] = true if str.include?('intra-area')
949
+ hash[:level_1] = true if str.include?('level-1')
950
+ hash[:level_2] = true if str.include?('level-2')
951
+ hash[:local] = true if str.include?('local')
952
+ hash[:nssa_external] = true if str.include?('nssa-external')
953
+ hash[:type_1] = true if str.include?('type-1')
954
+ hash[:type_2] = true if str.include?('type-2')
955
+ hash
956
+ end
957
+
958
+ def match_route_type_set(attrs)
959
+ # reset first
960
+ set_args_keys(
961
+ state: 'no',
962
+ external: 'external',
963
+ inter_area: 'inter-area',
964
+ internal: 'internal',
965
+ intra_area: 'intra-area',
966
+ level_1: 'level-1',
967
+ level_2: 'level-2',
968
+ local: 'local',
969
+ nssa_external: 'nssa-external',
970
+ type_1: 'type-1',
971
+ type_2: 'type-2')
972
+ config_set('route_map', 'match_route_type', @set_args)
973
+
974
+ to_set = false
975
+ set_args_keys(attrs)
976
+ [:match_route_type_external,
977
+ :match_route_type_inter_area,
978
+ :match_route_type_internal,
979
+ :match_route_type_intra_area,
980
+ :match_route_type_level_1,
981
+ :match_route_type_level_2,
982
+ :match_route_type_local,
983
+ :match_route_type_nssa_external,
984
+ :match_route_type_type_1,
985
+ :match_route_type_type_2,
986
+ ].each do |p|
987
+ attrs[p] = false if attrs[p].nil?
988
+ send(p.to_s + '=', attrs[p])
989
+ to_set = true if attrs[p] && !to_set
990
+ end
991
+ return unless to_set
992
+ @set_args[:state] = ''
993
+ @get_args = @set_args
994
+ config_set('route_map', 'match_route_type', @set_args)
995
+ end
996
+
997
+ def match_route_type_external
998
+ hash = match_route_type_get
999
+ hash[:external]
1000
+ end
1001
+
1002
+ def match_route_type_external=(val)
1003
+ @set_args[:external] = val ? 'external' : ''
1004
+ end
1005
+
1006
+ def default_match_route_type_external
1007
+ config_get_default('route_map', 'match_route_type_external')
1008
+ end
1009
+
1010
+ def match_route_type_inter_area
1011
+ hash = match_route_type_get
1012
+ hash[:inter_area]
1013
+ end
1014
+
1015
+ def match_route_type_inter_area=(val)
1016
+ @set_args[:inter_area] = val ? 'inter-area' : ''
1017
+ end
1018
+
1019
+ def default_match_route_type_inter_area
1020
+ config_get_default('route_map', 'match_route_type_inter_area')
1021
+ end
1022
+
1023
+ def match_route_type_internal
1024
+ hash = match_route_type_get
1025
+ hash[:internal]
1026
+ end
1027
+
1028
+ def match_route_type_internal=(val)
1029
+ @set_args[:internal] = val ? 'internal' : ''
1030
+ end
1031
+
1032
+ def default_match_route_type_internal
1033
+ config_get_default('route_map', 'match_route_type_internal')
1034
+ end
1035
+
1036
+ def match_route_type_intra_area
1037
+ hash = match_route_type_get
1038
+ hash[:intra_area]
1039
+ end
1040
+
1041
+ def match_route_type_intra_area=(val)
1042
+ @set_args[:intra_area] = val ? 'intra-area' : ''
1043
+ end
1044
+
1045
+ def default_match_route_type_intra_area
1046
+ config_get_default('route_map', 'match_route_type_intra_area')
1047
+ end
1048
+
1049
+ def match_route_type_level_1
1050
+ hash = match_route_type_get
1051
+ hash[:level_1]
1052
+ end
1053
+
1054
+ def match_route_type_level_1=(val)
1055
+ @set_args[:level_1] = val ? 'level-1' : ''
1056
+ end
1057
+
1058
+ def default_match_route_type_level_1
1059
+ config_get_default('route_map', 'match_route_type_level_1')
1060
+ end
1061
+
1062
+ def match_route_type_level_2
1063
+ hash = match_route_type_get
1064
+ hash[:level_2]
1065
+ end
1066
+
1067
+ def match_route_type_level_2=(val)
1068
+ @set_args[:level_2] = val ? 'level-2' : ''
1069
+ end
1070
+
1071
+ def default_match_route_type_level_2
1072
+ config_get_default('route_map', 'match_route_type_level_2')
1073
+ end
1074
+
1075
+ def match_route_type_local
1076
+ hash = match_route_type_get
1077
+ hash[:local]
1078
+ end
1079
+
1080
+ def match_route_type_local=(val)
1081
+ @set_args[:local] = val ? 'local' : ''
1082
+ end
1083
+
1084
+ def default_match_route_type_local
1085
+ config_get_default('route_map', 'match_route_type_local')
1086
+ end
1087
+
1088
+ def match_route_type_nssa_external
1089
+ hash = match_route_type_get
1090
+ hash[:nssa_external]
1091
+ end
1092
+
1093
+ def match_route_type_nssa_external=(val)
1094
+ @set_args[:nssa_external] = val ? 'nssa-external' : ''
1095
+ end
1096
+
1097
+ def default_match_route_type_nssa_external
1098
+ config_get_default('route_map', 'match_route_type_nssa_external')
1099
+ end
1100
+
1101
+ def match_route_type_type_1
1102
+ hash = match_route_type_get
1103
+ hash[:type_1]
1104
+ end
1105
+
1106
+ def match_route_type_type_1=(val)
1107
+ @set_args[:type_1] = val ? 'type-1' : ''
1108
+ end
1109
+
1110
+ def default_match_route_type_type_1
1111
+ config_get_default('route_map', 'match_route_type_type_1')
1112
+ end
1113
+
1114
+ def match_route_type_type_2
1115
+ hash = match_route_type_get
1116
+ hash[:type_2]
1117
+ end
1118
+
1119
+ def match_route_type_type_2=(val)
1120
+ @set_args[:type_2] = val ? 'type-2' : ''
1121
+ end
1122
+
1123
+ def default_match_route_type_type_2
1124
+ config_get_default('route_map', 'match_route_type_type_2')
1125
+ end
1126
+
1127
+ # match ospf-area 10 7
1128
+ def match_ospf_area
1129
+ str = config_get('route_map', 'match_ospf_area', @get_args)
1130
+ return if str.nil?
1131
+ str.empty? ? default_match_ospf_area : str.split
1132
+ end
1133
+
1134
+ def match_ospf_area=(list)
1135
+ carr = match_ospf_area
1136
+ config_set('route_map', 'match_ospf_area', @set_args) if carr.nil?
1137
+ cstr = ''
1138
+ carr.each do |elem|
1139
+ cstr = cstr.concat(elem + ' ')
1140
+ end
1141
+ unless cstr.empty?
1142
+ set_args_keys(state: 'no', area: cstr)
1143
+ # reset the current config
1144
+ config_set('route_map', 'match_ospf_area', @set_args)
1145
+ end
1146
+ nstr = ''
1147
+ list.each do |elem|
1148
+ nstr = nstr.concat(elem + ' ')
1149
+ end
1150
+ return if nstr.empty?
1151
+ set_args_keys(state: '', area: nstr)
1152
+ config_set('route_map', 'match_ospf_area', @set_args)
1153
+ end
1154
+
1155
+ def default_match_ospf_area
1156
+ config_get_default('route_map', 'match_ospf_area')
1157
+ end
1158
+
1159
+ # match mac-list m1 m2
1160
+ def match_mac_list
1161
+ str = config_get('route_map', 'match_mac_list', @get_args)
1162
+ return if str.nil?
1163
+ str.empty? ? default_match_mac_list : str.split
1164
+ end
1165
+
1166
+ def match_mac_list=(list)
1167
+ carr = match_mac_list
1168
+ config_set('route_map', 'match_mac_list', @set_args) if carr.nil?
1169
+ cstr = ''
1170
+ carr.each do |elem|
1171
+ cstr = cstr.concat(elem + ' ')
1172
+ end
1173
+ unless cstr.empty?
1174
+ set_args_keys(state: 'no', mac: cstr)
1175
+ # reset the current config
1176
+ config_set('route_map', 'match_mac_list', @set_args)
1177
+ end
1178
+ nstr = ''
1179
+ list.each do |elem|
1180
+ nstr = nstr.concat(elem + ' ')
1181
+ end
1182
+ return if nstr.empty?
1183
+ set_args_keys(state: '', mac: nstr)
1184
+ config_set('route_map', 'match_mac_list', @set_args)
1185
+ end
1186
+
1187
+ def default_match_mac_list
1188
+ config_get_default('route_map', 'match_mac_list')
1189
+ end
1190
+
1191
+ # match length 45 300
1192
+ def match_length
1193
+ config_get('route_map', 'match_length', @get_args)
1194
+ end
1195
+
1196
+ def match_length=(array)
1197
+ if array.empty?
1198
+ set_args_keys(state: 'no', min: '', max: '')
1199
+ else
1200
+ set_args_keys(state: '', min: array[0], max: array[1])
1201
+ end
1202
+ config_set('route_map', 'match_length', @set_args)
1203
+ end
1204
+
1205
+ def default_match_length
1206
+ config_get_default('route_map', 'match_length')
1207
+ end
1208
+
1209
+ def match_vlan
1210
+ ret = config_get('route_map', 'match_vlan', @get_args)
1211
+ ret.strip if ret
1212
+ end
1213
+
1214
+ def match_vlan=(val)
1215
+ cval = match_vlan
1216
+ # reset first
1217
+ unless cval.nil? || cval.empty?
1218
+ set_args_keys(state: 'no', range: cval)
1219
+ config_set('route_map', 'match_vlan', @set_args)
1220
+ end
1221
+ return if val.empty?
1222
+ set_args_keys(state: '', range: val)
1223
+ config_set('route_map', 'match_vlan', @set_args)
1224
+ end
1225
+
1226
+ def default_match_vlan
1227
+ config_get_default('route_map', 'match_vlan')
1228
+ end
1229
+
1230
+ # match evpn route-type 1
1231
+ # match evpn route-type 2 all
1232
+ # match evpn route-type 2 mac-ip
1233
+ # match evpn route-type 2 mac-only
1234
+ # match evpn route-type 3 etc.
1235
+ def match_evpn_route_type_get
1236
+ arr = config_get('route_map', 'match_evpn_route_type', @get_args)
1237
+ return nil if arr.nil?
1238
+ hash = {}
1239
+ hash[:type1] = false
1240
+ hash[:type3] = false
1241
+ hash[:type4] = false
1242
+ hash[:type5] = false
1243
+ hash[:type6] = false
1244
+ hash[:type_all] = false
1245
+ hash[:type2_all] = false
1246
+ hash[:type2_mac_ip] = false
1247
+ hash[:type2_mac_only] = false
1248
+ return hash if arr.empty?
1249
+ hash[:type1] = true if arr.include?('1')
1250
+ hash[:type3] = true if arr.include?('3')
1251
+ hash[:type4] = true if arr.include?('4')
1252
+ hash[:type5] = true if arr.include?('5')
1253
+ hash[:type6] = true if arr.include?('6')
1254
+ hash[:type_all] = true if arr.include?('all')
1255
+ hash[:type2_all] = true if arr.include?('2 all')
1256
+ hash[:type2_mac_ip] = true if arr.include?('2 mac-ip')
1257
+ hash[:type2_mac_only] = true if arr.include?('2 mac-only')
1258
+ hash
1259
+ end
1260
+
1261
+ def match_evpn_route_type_1
1262
+ hash = match_evpn_route_type_get
1263
+ hash.nil? ? nil : hash[:type1]
1264
+ end
1265
+
1266
+ def match_evpn_route_type_1=(val)
1267
+ state = val ? '' : 'no'
1268
+ set_args_keys(state: state, type: '1')
1269
+ config_set('route_map', 'match_evpn_route_type', @set_args)
1270
+ end
1271
+
1272
+ def default_match_evpn_route_type_1
1273
+ config_get_default('route_map', 'match_evpn_route_type_1')
1274
+ end
1275
+
1276
+ def match_evpn_route_type_3
1277
+ hash = match_evpn_route_type_get
1278
+ hash.nil? ? nil : hash[:type3]
1279
+ end
1280
+
1281
+ def match_evpn_route_type_3=(val)
1282
+ state = val ? '' : 'no'
1283
+ set_args_keys(state: state, type: '3')
1284
+ config_set('route_map', 'match_evpn_route_type', @set_args)
1285
+ end
1286
+
1287
+ def default_match_evpn_route_type_3
1288
+ config_get_default('route_map', 'match_evpn_route_type_3')
1289
+ end
1290
+
1291
+ def match_evpn_route_type_4
1292
+ hash = match_evpn_route_type_get
1293
+ hash.nil? ? nil : hash[:type4]
1294
+ end
1295
+
1296
+ def match_evpn_route_type_4=(val)
1297
+ state = val ? '' : 'no'
1298
+ set_args_keys(state: state, type: '4')
1299
+ config_set('route_map', 'match_evpn_route_type', @set_args)
1300
+ end
1301
+
1302
+ def default_match_evpn_route_type_4
1303
+ config_get_default('route_map', 'match_evpn_route_type_4')
1304
+ end
1305
+
1306
+ def match_evpn_route_type_5
1307
+ hash = match_evpn_route_type_get
1308
+ hash.nil? ? nil : hash[:type5]
1309
+ end
1310
+
1311
+ def match_evpn_route_type_5=(val)
1312
+ state = val ? '' : 'no'
1313
+ set_args_keys(state: state, type: '5')
1314
+ config_set('route_map', 'match_evpn_route_type', @set_args)
1315
+ end
1316
+
1317
+ def default_match_evpn_route_type_5
1318
+ config_get_default('route_map', 'match_evpn_route_type_5')
1319
+ end
1320
+
1321
+ def match_evpn_route_type_6
1322
+ hash = match_evpn_route_type_get
1323
+ hash.nil? ? nil : hash[:type6]
1324
+ end
1325
+
1326
+ def match_evpn_route_type_6=(val)
1327
+ state = val ? '' : 'no'
1328
+ set_args_keys(state: state, type: '6')
1329
+ config_set('route_map', 'match_evpn_route_type', @set_args)
1330
+ end
1331
+
1332
+ def default_match_evpn_route_type_6
1333
+ config_get_default('route_map', 'match_evpn_route_type_6')
1334
+ end
1335
+
1336
+ def match_evpn_route_type_all
1337
+ hash = match_evpn_route_type_get
1338
+ hash.nil? ? nil : hash[:type_all]
1339
+ end
1340
+
1341
+ def match_evpn_route_type_all=(val)
1342
+ state = val ? '' : 'no'
1343
+ set_args_keys(state: state, type: 'all')
1344
+ config_set('route_map', 'match_evpn_route_type', @set_args)
1345
+ end
1346
+
1347
+ def default_match_evpn_route_type_all
1348
+ config_get_default('route_map', 'match_evpn_route_type_all')
1349
+ end
1350
+
1351
+ def match_evpn_route_type_2_all
1352
+ hash = match_evpn_route_type_get
1353
+ hash.nil? ? nil : hash[:type2_all]
1354
+ end
1355
+
1356
+ def match_evpn_route_type_2_all=(val)
1357
+ state = val ? '' : 'no'
1358
+ set_args_keys(state: state, type: '2 all')
1359
+ config_set('route_map', 'match_evpn_route_type', @set_args)
1360
+ end
1361
+
1362
+ def default_match_evpn_route_type_2_all
1363
+ config_get_default('route_map', 'match_evpn_route_type_2_all')
1364
+ end
1365
+
1366
+ def match_evpn_route_type_2_mac_ip
1367
+ hash = match_evpn_route_type_get
1368
+ hash.nil? ? nil : hash[:type2_mac_ip]
1369
+ end
1370
+
1371
+ def match_evpn_route_type_2_mac_ip=(val)
1372
+ state = val ? '' : 'no'
1373
+ set_args_keys(state: state, type: '2 mac-ip')
1374
+ config_set('route_map', 'match_evpn_route_type', @set_args)
1375
+ end
1376
+
1377
+ def default_match_evpn_route_type_2_mac_ip
1378
+ config_get_default('route_map', 'match_evpn_route_type_2_mac_ip')
1379
+ end
1380
+
1381
+ def match_evpn_route_type_2_mac_only
1382
+ hash = match_evpn_route_type_get
1383
+ hash.nil? ? nil : hash[:type2_mac_only]
1384
+ end
1385
+
1386
+ def match_evpn_route_type_2_mac_only=(val)
1387
+ state = val ? '' : 'no'
1388
+ set_args_keys(state: state, type: '2 mac-only')
1389
+ config_set('route_map', 'match_evpn_route_type', @set_args)
1390
+ end
1391
+
1392
+ def default_match_evpn_route_type_2_mac_only
1393
+ config_get_default('route_map', 'match_evpn_route_type_2_mac_only')
1394
+ end
1395
+
1396
+ def set_comm_list
1397
+ config_get('route_map', 'set_comm_list', @get_args)
1398
+ end
1399
+
1400
+ def set_comm_list=(val)
1401
+ state = val ? '' : 'no'
1402
+ list = val ? val : set_comm_list
1403
+ set_args_keys(state: state, list: list)
1404
+ config_set('route_map', 'set_comm_list', @set_args)
1405
+ end
1406
+
1407
+ def default_set_comm_list
1408
+ config_get_default('route_map', 'set_comm_list')
1409
+ end
1410
+
1411
+ def set_extcomm_list
1412
+ config_get('route_map', 'set_extcomm_list', @get_args)
1413
+ end
1414
+
1415
+ def set_extcomm_list=(val)
1416
+ state = val ? '' : 'no'
1417
+ list = val ? val : set_extcomm_list
1418
+ set_args_keys(state: state, list: list)
1419
+ config_set('route_map', 'set_extcomm_list', @set_args)
1420
+ end
1421
+
1422
+ def default_set_extcomm_list
1423
+ config_get_default('route_map', 'set_extcomm_list')
1424
+ end
1425
+
1426
+ def set_forwarding_addr
1427
+ config_get('route_map', 'set_forwarding_addr', @get_args)
1428
+ end
1429
+
1430
+ def set_forwarding_addr=(val)
1431
+ state = val ? '' : 'no'
1432
+ set_args_keys(state: state)
1433
+ config_set('route_map', 'set_forwarding_addr', @set_args)
1434
+ end
1435
+
1436
+ def default_set_forwarding_addr
1437
+ config_get_default('route_map', 'set_forwarding_addr')
1438
+ end
1439
+
1440
+ def set_level
1441
+ config_get('route_map', 'set_level', @get_args)
1442
+ end
1443
+
1444
+ def set_level=(val)
1445
+ state = val ? '' : 'no'
1446
+ level = val ? val : ''
1447
+ set_args_keys(state: state, level: level)
1448
+ config_set('route_map', 'set_level', @set_args)
1449
+ end
1450
+
1451
+ def default_set_level
1452
+ config_get_default('route_map', 'set_level')
1453
+ end
1454
+
1455
+ def set_local_preference
1456
+ config_get('route_map', 'set_local_preference', @get_args)
1457
+ end
1458
+
1459
+ def set_local_preference=(val)
1460
+ state = val ? '' : 'no'
1461
+ pref = val ? val : ''
1462
+ set_args_keys(state: state, pref: pref)
1463
+ config_set('route_map', 'set_local_preference', @set_args)
1464
+ end
1465
+
1466
+ def default_set_local_preference
1467
+ config_get_default('route_map', 'set_local_preference')
1468
+ end
1469
+
1470
+ def set_metric_type
1471
+ config_get('route_map', 'set_metric_type', @get_args)
1472
+ end
1473
+
1474
+ def set_metric_type=(val)
1475
+ state = val ? '' : 'no'
1476
+ type = val ? val : ''
1477
+ set_args_keys(state: state, type: type)
1478
+ config_set('route_map', 'set_metric_type', @set_args)
1479
+ end
1480
+
1481
+ def default_set_metric_type
1482
+ config_get_default('route_map', 'set_metric_type')
1483
+ end
1484
+
1485
+ def set_nssa_only
1486
+ config_get('route_map', 'set_nssa_only', @get_args)
1487
+ end
1488
+
1489
+ def set_nssa_only=(val)
1490
+ state = val ? '' : 'no'
1491
+ set_args_keys(state: state)
1492
+ config_set('route_map', 'set_nssa_only', @set_args)
1493
+ end
1494
+
1495
+ def default_set_nssa_only
1496
+ config_get_default('route_map', 'set_nssa_only')
1497
+ end
1498
+
1499
+ def set_origin
1500
+ config_get('route_map', 'set_origin', @get_args)
1501
+ end
1502
+
1503
+ def set_origin=(val)
1504
+ state = val ? '' : 'no'
1505
+ origin = val ? val : ''
1506
+ set_args_keys(state: state, origin: origin)
1507
+ config_set('route_map', 'set_origin', @set_args)
1508
+ end
1509
+
1510
+ def default_set_origin
1511
+ config_get_default('route_map', 'set_origin')
1512
+ end
1513
+
1514
+ def set_path_selection
1515
+ config_get('route_map', 'set_path_selection', @get_args)
1516
+ end
1517
+
1518
+ def set_path_selection=(val)
1519
+ state = val ? '' : 'no'
1520
+ set_args_keys(state: state)
1521
+ config_set('route_map', 'set_path_selection', @set_args)
1522
+ end
1523
+
1524
+ def default_set_path_selection
1525
+ config_get_default('route_map', 'set_path_selection')
1526
+ end
1527
+
1528
+ def set_tag
1529
+ config_get('route_map', 'set_tag', @get_args)
1530
+ end
1531
+
1532
+ def set_tag=(val)
1533
+ state = val ? '' : 'no'
1534
+ tag = val ? val : ''
1535
+ set_args_keys(state: state, tag: tag)
1536
+ config_set('route_map', 'set_tag', @set_args)
1537
+ end
1538
+
1539
+ def default_set_tag
1540
+ config_get_default('route_map', 'set_tag')
1541
+ end
1542
+
1543
+ def set_vrf
1544
+ vrf = config_get('route_map', 'set_vrf', @get_args)
1545
+ vrf == 'default' ? 'default_vrf' : vrf
1546
+ end
1547
+
1548
+ def set_vrf=(val)
1549
+ state = val ? '' : 'no'
1550
+ vrf = val ? val : ''
1551
+ vrf = vrf == 'default_vrf' ? 'default' : vrf
1552
+ set_args_keys(state: state, vrf: vrf)
1553
+ config_set('route_map', 'set_vrf', @set_args)
1554
+ end
1555
+
1556
+ def default_set_vrf
1557
+ config_get_default('route_map', 'set_vrf')
1558
+ end
1559
+
1560
+ def set_weight
1561
+ config_get('route_map', 'set_weight', @get_args)
1562
+ end
1563
+
1564
+ def set_weight=(val)
1565
+ state = val ? '' : 'no'
1566
+ weight = val ? val : ''
1567
+ set_args_keys(state: state, weight: weight)
1568
+ config_set('route_map', 'set_weight', @set_args)
1569
+ end
1570
+
1571
+ def default_set_weight
1572
+ config_get_default('route_map', 'set_weight')
1573
+ end
1574
+
1575
+ # set metric 44 55 66 77 88
1576
+ # set metric +33
1577
+ def set_metric_get
1578
+ hash = {}
1579
+ hash[:additive] = false
1580
+ hash[:bandwidth] = false
1581
+ hash[:delay] = false
1582
+ hash[:reliability] = false
1583
+ hash[:effective_bandwidth] = false
1584
+ hash[:mtu] = false
1585
+ str = config_get('route_map', 'set_metric', @get_args)
1586
+ return hash if str.nil?
1587
+ arr = str.split
1588
+ hash[:additive] = true if arr[0].include?('+')
1589
+ hash[:bandwidth] = arr[0].delete('+').to_i
1590
+ return hash if arr.size == 1
1591
+ hash[:delay] = arr[1].to_i
1592
+ hash[:reliability] = arr[2].to_i
1593
+ hash[:effective_bandwidth] = arr[3].to_i
1594
+ hash[:mtu] = arr[4].to_i
1595
+ hash
1596
+ end
1597
+
1598
+ def set_metric_set(plus, bndw, del, reliability, eff_bw, mtu)
1599
+ state = bndw ? '' : 'no'
1600
+ additive = plus ? '+' : ''
1601
+ bw = bndw ? bndw : ''
1602
+ delay = del ? del : ''
1603
+ rel = reliability ? reliability : ''
1604
+ eff = eff_bw ? eff_bw : ''
1605
+ lmtu = mtu ? mtu : ''
1606
+ set_args_keys(state: state, additive: additive, bw: bw, delay: delay,
1607
+ rel: rel, eff: eff, mtu: lmtu)
1608
+ config_set('route_map', 'set_metric', @set_args)
1609
+ end
1610
+
1611
+ def set_metric_additive
1612
+ hash = set_metric_get
1613
+ hash[:additive]
1614
+ end
1615
+
1616
+ def default_set_metric_additive
1617
+ config_get_default('route_map', 'set_metric_additive')
1618
+ end
1619
+
1620
+ def set_metric_bandwidth
1621
+ hash = set_metric_get
1622
+ hash[:bandwidth]
1623
+ end
1624
+
1625
+ def default_set_metric_bandwidth
1626
+ config_get_default('route_map', 'set_metric_bandwidth')
1627
+ end
1628
+
1629
+ def set_metric_delay
1630
+ hash = set_metric_get
1631
+ hash[:delay]
1632
+ end
1633
+
1634
+ def default_set_metric_delay
1635
+ config_get_default('route_map', 'set_metric_delay')
1636
+ end
1637
+
1638
+ def set_metric_reliability
1639
+ hash = set_metric_get
1640
+ hash[:reliability]
1641
+ end
1642
+
1643
+ def default_set_metric_reliability
1644
+ config_get_default('route_map', 'set_metric_reliability')
1645
+ end
1646
+
1647
+ def set_metric_effective_bandwidth
1648
+ hash = set_metric_get
1649
+ hash[:effective_bandwidth]
1650
+ end
1651
+
1652
+ def default_set_metric_effective_bandwidth
1653
+ config_get_default('route_map', 'set_metric_effective_bandwidth')
1654
+ end
1655
+
1656
+ def set_metric_mtu
1657
+ hash = set_metric_get
1658
+ hash[:mtu]
1659
+ end
1660
+
1661
+ def default_set_metric_mtu
1662
+ config_get_default('route_map', 'set_metric_mtu')
1663
+ end
1664
+
1665
+ # set dampening 6 22 44 55
1666
+ def set_dampening_get
1667
+ hash = {}
1668
+ hash[:half_life] = false
1669
+ hash[:reuse] = false
1670
+ hash[:suppress] = false
1671
+ hash[:max] = false
1672
+ str = config_get('route_map', 'set_dampening', @get_args)
1673
+ return hash if str.nil?
1674
+ arr = str.split
1675
+ hash[:half_life] = arr[0].to_i
1676
+ hash[:reuse] = arr[1].to_i
1677
+ hash[:suppress] = arr[2].to_i
1678
+ hash[:max] = arr[3].to_i
1679
+ hash
1680
+ end
1681
+
1682
+ def set_dampening_set(half_life, reuse, supp, md)
1683
+ if half_life
1684
+ set_args_keys(state: '', hl: half_life, reuse: reuse, supp: supp,
1685
+ max: md)
1686
+ else
1687
+ set_args_keys(state: 'no', hl: '', reuse: '', supp: '', max: '')
1688
+ end
1689
+ config_set('route_map', 'set_dampening', @set_args)
1690
+ end
1691
+
1692
+ def set_dampening_half_life
1693
+ hash = set_dampening_get
1694
+ hash[:half_life]
1695
+ end
1696
+
1697
+ def default_set_dampening_half_life
1698
+ config_get_default('route_map', 'set_dampening_half_life')
1699
+ end
1700
+
1701
+ def set_dampening_reuse
1702
+ hash = set_dampening_get
1703
+ hash[:reuse]
1704
+ end
1705
+
1706
+ def default_set_dampening_reuse
1707
+ config_get_default('route_map', 'set_dampening_reuse')
1708
+ end
1709
+
1710
+ def set_dampening_suppress
1711
+ hash = set_dampening_get
1712
+ hash[:suppress]
1713
+ end
1714
+
1715
+ def default_set_dampening_suppress
1716
+ config_get_default('route_map', 'set_dampening_suppress')
1717
+ end
1718
+
1719
+ def set_dampening_max_duation
1720
+ hash = set_dampening_get
1721
+ hash[:max]
1722
+ end
1723
+
1724
+ def default_set_dampening_max_duation
1725
+ config_get_default('route_map', 'set_dampening_max_duation')
1726
+ end
1727
+
1728
+ # set distance 1 2 3
1729
+ # set distance 1 2
1730
+ # set distance 1
1731
+ def set_distance_get
1732
+ hash = {}
1733
+ hash[:igp] = false
1734
+ hash[:internal] = false
1735
+ hash[:local] = false
1736
+ str = config_get('route_map', 'set_distance', @get_args)
1737
+ return hash if str.nil?
1738
+ arr = str.split
1739
+ hash[:igp] = arr[0].to_i
1740
+ hash[:internal] = arr[1].to_i if arr[1]
1741
+ hash[:local] = arr[2].to_i if arr[2]
1742
+ hash
1743
+ end
1744
+
1745
+ def set_distance_set(igp, internal, local)
1746
+ state = igp ? '' : 'no'
1747
+ igp_ebgp = igp ? igp : ''
1748
+ int = internal ? internal : ''
1749
+ loc = local ? local : ''
1750
+ set_args_keys(state: state, igp: igp_ebgp, internal: int, local: loc)
1751
+ config_set('route_map', 'set_distance', @set_args)
1752
+ end
1753
+
1754
+ def set_distance_igp_ebgp
1755
+ hash = set_distance_get
1756
+ hash[:igp]
1757
+ end
1758
+
1759
+ def default_set_distance_igp_ebgp
1760
+ config_get_default('route_map', 'set_distance_igp_ebgp')
1761
+ end
1762
+
1763
+ def set_distance_local
1764
+ hash = set_distance_get
1765
+ hash[:local]
1766
+ end
1767
+
1768
+ def default_set_distance_local
1769
+ config_get_default('route_map', 'set_distance_local')
1770
+ end
1771
+
1772
+ def set_distance_internal
1773
+ hash = set_distance_get
1774
+ hash[:internal]
1775
+ end
1776
+
1777
+ def default_set_distance_internal
1778
+ config_get_default('route_map', 'set_distance_internal')
1779
+ end
1780
+
1781
+ def set_as_path_prepend_last_as
1782
+ config_get('route_map', 'set_as_path_prepend_last_as', @get_args)
1783
+ end
1784
+
1785
+ def set_as_path_prepend_last_as=(val)
1786
+ state = val ? '' : 'no'
1787
+ as = val ? val : ''
1788
+ set_args_keys(state: state, as: as)
1789
+ config_set('route_map', 'set_as_path_prepend_last_as', @set_args)
1790
+ end
1791
+
1792
+ def default_set_as_path_prepend_last_as
1793
+ config_get_default('route_map', 'set_as_path_prepend_last_as')
1794
+ end
1795
+
1796
+ def set_as_path_tag
1797
+ config_get('route_map', 'set_as_path_tag', @get_args)
1798
+ end
1799
+
1800
+ def set_as_path_tag=(val)
1801
+ state = val ? '' : 'no'
1802
+ set_args_keys(state: state)
1803
+ config_set('route_map', 'set_as_path_tag', @set_args)
1804
+ end
1805
+
1806
+ def default_set_as_path_tag
1807
+ config_get_default('route_map', 'set_as_path_tag')
1808
+ end
1809
+
1810
+ # set as-path prepend 55.77 44 33.5
1811
+ # set as-path prepend last-as 1
1812
+ def set_as_path_prepend
1813
+ arr = []
1814
+ match = config_get('route_map', 'set_as_path_prepend', @get_args)
1815
+ if arr
1816
+ match.each do |line|
1817
+ next if line.include?('last-as')
1818
+ arr = line.strip.split
1819
+ end
1820
+ end
1821
+ arr
1822
+ end
1823
+
1824
+ def set_as_path_prepend=(list)
1825
+ nstr = ''
1826
+ list.each do |elem|
1827
+ nstr = nstr.concat(elem + ' ')
1828
+ end
1829
+ state = nstr.empty? ? 'no' : ''
1830
+ set_args_keys(state: state, asnum: nstr)
1831
+ config_set('route_map', 'set_as_path_prepend', @set_args)
1832
+ end
1833
+
1834
+ def default_set_as_path_prepend
1835
+ config_get_default('route_map', 'set_as_path_prepend')
1836
+ end
1837
+
1838
+ # set interface Null0
1839
+ def set_interface
1840
+ str = config_get('route_map', 'set_interface', @get_args)
1841
+ str ? str.strip : default_set_interface
1842
+ end
1843
+
1844
+ def set_interface_set(val)
1845
+ cint = set_interface
1846
+ return if cint == val
1847
+ state = val ? '' : 'no'
1848
+ int = val ? val : cint
1849
+ set_args_keys(state: state, int: int)
1850
+ config_set('route_map', 'set_interface', @set_args)
1851
+ end
1852
+
1853
+ def default_set_interface
1854
+ config_get_default('route_map', 'set_interface')
1855
+ end
1856
+
1857
+ def set_ipv4_prefix
1858
+ config_get('route_map', 'set_ipv4_prefix', @get_args)
1859
+ end
1860
+
1861
+ def set_ipv4_prefix=(val)
1862
+ state = val ? '' : 'no'
1863
+ pf = val ? val : set_ipv4_prefix
1864
+ set_args_keys(state: state, pf: pf)
1865
+ config_set('route_map', 'set_ipv4_prefix', @set_args)
1866
+ end
1867
+
1868
+ def default_set_ipv4_prefix
1869
+ config_get_default('route_map', 'set_ipv4_prefix')
1870
+ end
1871
+
1872
+ def set_ipv4_precedence
1873
+ config_get('route_map', 'set_ipv4_precedence', @get_args)
1874
+ end
1875
+
1876
+ def set_ipv4_precedence_set(val)
1877
+ state = val ? '' : 'no'
1878
+ pre = val ? val : ''
1879
+ set_args_keys(state: state, pre: pre)
1880
+ config_set('route_map', 'set_ipv4_precedence', @set_args)
1881
+ end
1882
+
1883
+ def default_set_ipv4_precedence
1884
+ config_get_default('route_map', 'set_ipv4_precedence')
1885
+ end
1886
+
1887
+ # set ip default next-hop 1.1.1.1 2.2.2.2 3.3.3.3
1888
+ def set_ipv4_default_next_hop
1889
+ str = config_get('route_map', 'set_ipv4_default_next_hop', @get_args)
1890
+ return if str.nil?
1891
+ if str.empty?
1892
+ val = default_set_ipv4_default_next_hop
1893
+ else
1894
+ val = str.split
1895
+ val.delete('load-share')
1896
+ end
1897
+ val
1898
+ end
1899
+
1900
+ def set_ipv4_def_next_hop_set(list, share)
1901
+ carr = set_ipv4_default_next_hop
1902
+ fail Cisco::UnsupportedError.new(
1903
+ 'route_map',
1904
+ 'set_ipv4_default_next_hop') if carr.nil?
1905
+ cstr = ''
1906
+ carr.each do |elem|
1907
+ cstr = cstr.concat(elem + ' ')
1908
+ end
1909
+ cstr.concat('load-share')
1910
+ set_args_keys(state: 'no', nh: cstr)
1911
+ # reset the current config
1912
+ config_set('route_map', 'set_ipv4_default_next_hop', @set_args)
1913
+ nstr = ''
1914
+ list.each do |elem|
1915
+ nstr = nstr.concat(elem + ' ')
1916
+ end
1917
+ nstr.concat('load-share') if share
1918
+ return if nstr.empty?
1919
+ set_args_keys(state: '', nh: nstr)
1920
+ config_set('route_map', 'set_ipv4_default_next_hop', @set_args)
1921
+ end
1922
+
1923
+ def default_set_ipv4_default_next_hop
1924
+ config_get_default('route_map', 'set_ipv4_default_next_hop')
1925
+ end
1926
+
1927
+ # set ip default next-hop 1.1.1.1 2.2.2.2 3.3.3.3 load-share
1928
+ # set ip default next-hop load-share
1929
+ def set_ipv4_default_next_hop_load_share
1930
+ match = config_get('route_map', 'set_ipv4_default_next_hop', @get_args)
1931
+ return if match.nil?
1932
+ match.include?('load-share')
1933
+ end
1934
+
1935
+ def default_set_ipv4_default_next_hop_load_share
1936
+ config_get_default('route_map', 'set_ipv4_default_next_hop_load_share')
1937
+ end
1938
+
1939
+ # set ip next-hop 1.1.1.1 2.2.2.2 3.3.3.3
1940
+ def set_ipv4_next_hop
1941
+ arr = config_get('route_map', 'set_ipv4_next_hop', @get_args)
1942
+ val = default_set_ipv4_next_hop
1943
+ arr.each do |str|
1944
+ next if str.empty?
1945
+ next if str.include?('peer-address')
1946
+ next if str.include?('unchanged')
1947
+ next if str.include?('redist-unchanged')
1948
+ val = str.split
1949
+ val.delete('load-share')
1950
+ end
1951
+ val
1952
+ end
1953
+
1954
+ def set_ipv4_next_hop_set(list, share=false)
1955
+ carr = set_ipv4_next_hop
1956
+ cstr = ''
1957
+ carr.each do |elem|
1958
+ cstr = cstr.concat(elem + ' ')
1959
+ end
1960
+ cstr.concat('load-share') unless default_set_ipv4_next_hop_load_share.nil?
1961
+ set_args_keys(state: 'no', nh: cstr)
1962
+ # reset the current config
1963
+ config_set('route_map', 'set_ipv4_next_hop', @set_args) unless
1964
+ cstr.empty?
1965
+ nstr = ''
1966
+ list.each do |elem|
1967
+ nstr = nstr.concat(elem + ' ')
1968
+ end
1969
+ nstr.concat('load-share') if share
1970
+ return if nstr.empty?
1971
+ set_args_keys(state: '', nh: nstr)
1972
+ config_set('route_map', 'set_ipv4_next_hop', @set_args)
1973
+ end
1974
+
1975
+ def default_set_ipv4_next_hop
1976
+ config_get_default('route_map', 'set_ipv4_next_hop')
1977
+ end
1978
+
1979
+ # set ip next-hop 1.1.1.1 2.2.2.2 3.3.3.3 load-share
1980
+ # set ip next-hop load-share
1981
+ def set_ipv4_next_hop_load_share
1982
+ arr = config_get('route_map', 'set_ipv4_next_hop', @get_args)
1983
+ val = default_set_ipv4_next_hop_load_share
1984
+ arr.each do |str|
1985
+ next if str.empty?
1986
+ return true if str.include?('load-share')
1987
+ end
1988
+ val
1989
+ end
1990
+
1991
+ def default_set_ipv4_next_hop_load_share
1992
+ config_get_default('route_map', 'set_ipv4_next_hop_load_share')
1993
+ end
1994
+
1995
+ def set_ipv4_next_hop_peer_addr
1996
+ config_get('route_map', 'set_ipv4_next_hop_peer_addr', @get_args)
1997
+ end
1998
+
1999
+ def set_ipv4_next_hop_peer_addr_set(val)
2000
+ state = val ? '' : 'no'
2001
+ set_args_keys(state: state)
2002
+ config_set('route_map', 'set_ipv4_next_hop_peer_addr', @set_args)
2003
+ end
2004
+
2005
+ def default_set_ipv4_next_hop_peer_addr
2006
+ config_get_default('route_map', 'set_ipv4_next_hop_peer_addr')
2007
+ end
2008
+
2009
+ def set_ipv4_next_hop_redist
2010
+ config_get('route_map', 'set_ipv4_next_hop_redist', @get_args)
2011
+ end
2012
+
2013
+ def set_ipv4_next_hop_redist_set(val)
2014
+ state = val ? '' : 'no'
2015
+ set_args_keys(state: state)
2016
+ config_set('route_map', 'set_ipv4_next_hop_redist', @set_args)
2017
+ end
2018
+
2019
+ def default_set_ipv4_next_hop_redist
2020
+ config_get_default('route_map', 'set_ipv4_next_hop_redist')
2021
+ end
2022
+
2023
+ def set_ipv4_next_hop_unchanged
2024
+ config_get('route_map', 'set_ipv4_next_hop_unchanged', @get_args)
2025
+ end
2026
+
2027
+ def set_ipv4_next_hop_unchanged_set(val)
2028
+ state = val ? '' : 'no'
2029
+ set_args_keys(state: state)
2030
+ config_set('route_map', 'set_ipv4_next_hop_unchanged', @set_args)
2031
+ end
2032
+
2033
+ def default_set_ipv4_next_hop_unchanged
2034
+ config_get_default('route_map', 'set_ipv4_next_hop_unchanged')
2035
+ end
2036
+
2037
+ def set_ipv6_prefix
2038
+ config_get('route_map', 'set_ipv6_prefix', @get_args)
2039
+ end
2040
+
2041
+ def set_ipv6_prefix=(val)
2042
+ state = val ? '' : 'no'
2043
+ pf = val ? val : set_ipv6_prefix
2044
+ set_args_keys(state: state, pf: pf)
2045
+ config_set('route_map', 'set_ipv6_prefix', @set_args)
2046
+ end
2047
+
2048
+ def default_set_ipv6_prefix
2049
+ config_get_default('route_map', 'set_ipv6_prefix')
2050
+ end
2051
+
2052
+ def set_ipv6_precedence
2053
+ config_get('route_map', 'set_ipv6_precedence', @get_args)
2054
+ end
2055
+
2056
+ def set_ipv6_precedence_set(val)
2057
+ state = val ? '' : 'no'
2058
+ pre = val ? val : ''
2059
+ set_args_keys(state: state, pre: pre)
2060
+ config_set('route_map', 'set_ipv6_precedence', @set_args)
2061
+ end
2062
+
2063
+ def default_set_ipv6_precedence
2064
+ config_get_default('route_map', 'set_ipv6_precedence')
2065
+ end
2066
+
2067
+ def set_ip_precedence(v4, v6)
2068
+ set_ipv4_precedence_set(default_set_ipv4_precedence)
2069
+ set_ipv6_precedence_set(default_set_ipv6_precedence)
2070
+ set_ipv4_precedence_set(v4)
2071
+ set_ipv6_precedence_set(v6)
2072
+ end
2073
+
2074
+ # set ipv6 default next-hop 1.1.1.1 2.2.2.2 3.3.3.3
2075
+ def set_ipv6_default_next_hop
2076
+ str = config_get('route_map', 'set_ipv6_default_next_hop', @get_args)
2077
+ return if str.nil?
2078
+ if str.empty?
2079
+ val = default_set_ipv6_default_next_hop
2080
+ else
2081
+ val = str.split
2082
+ val.delete('load-share')
2083
+ end
2084
+ val
2085
+ end
2086
+
2087
+ def set_ipv6_def_next_hop_set(list, share)
2088
+ carr = set_ipv6_default_next_hop
2089
+ fail Cisco::UnsupportedError.new(
2090
+ 'route_map',
2091
+ 'set_ipv6_default_next_hop') if carr.nil?
2092
+ cstr = ''
2093
+ carr.each do |elem|
2094
+ cstr = cstr.concat(elem + ' ')
2095
+ end
2096
+ cstr.concat('load-share')
2097
+ set_args_keys(state: 'no', nh: cstr)
2098
+ # reset the current config
2099
+ config_set('route_map', 'set_ipv6_default_next_hop', @set_args)
2100
+ nstr = ''
2101
+ list.each do |elem|
2102
+ nstr = nstr.concat(elem + ' ')
2103
+ end
2104
+ nstr.concat('load-share') if share
2105
+ return if nstr.empty?
2106
+ set_args_keys(state: '', nh: nstr)
2107
+ config_set('route_map', 'set_ipv6_default_next_hop', @set_args)
2108
+ end
2109
+
2110
+ def default_set_ipv6_default_next_hop
2111
+ config_get_default('route_map', 'set_ipv6_default_next_hop')
2112
+ end
2113
+
2114
+ # set ipv6 default next-hop 1.1.1.1 2.2.2.2 3.3.3.3 load-share
2115
+ # set ipv6 default next-hop load-share
2116
+ def set_ipv6_default_next_hop_load_share
2117
+ match = config_get('route_map', 'set_ipv6_default_next_hop', @get_args)
2118
+ return if match.nil?
2119
+ match.include?('load-share')
2120
+ end
2121
+
2122
+ def default_set_ipv6_default_next_hop_load_share
2123
+ config_get_default('route_map', 'set_ipv6_default_next_hop_load_share')
2124
+ end
2125
+
2126
+ # set ipv6 next-hop 1.1.1.1 2.2.2.2 3.3.3.3
2127
+ def set_ipv6_next_hop
2128
+ arr = config_get('route_map', 'set_ipv6_next_hop', @get_args)
2129
+ val = default_set_ipv6_next_hop
2130
+ arr.each do |str|
2131
+ next if str.empty?
2132
+ next if str.include?('peer-address')
2133
+ next if str.include?('unchanged')
2134
+ next if str.include?('redist-unchanged')
2135
+ val = str.split
2136
+ val.delete('load-share')
2137
+ end
2138
+ val
2139
+ end
2140
+
2141
+ def set_ipv6_next_hop_set(list, share=false)
2142
+ carr = set_ipv6_next_hop
2143
+ cstr = ''
2144
+ carr.each do |elem|
2145
+ cstr = cstr.concat(elem + ' ')
2146
+ end
2147
+ cstr.concat('load-share') unless default_set_ipv6_next_hop_load_share.nil?
2148
+ set_args_keys(state: 'no', nh: cstr)
2149
+ # reset the current config
2150
+ config_set('route_map', 'set_ipv6_next_hop', @set_args) unless
2151
+ cstr.empty?
2152
+ nstr = ''
2153
+ list.each do |elem|
2154
+ nstr = nstr.concat(elem + ' ')
2155
+ end
2156
+ nstr.concat('load-share') if share
2157
+ return if nstr.empty?
2158
+ set_args_keys(state: '', nh: nstr)
2159
+ config_set('route_map', 'set_ipv6_next_hop', @set_args)
2160
+ end
2161
+
2162
+ def default_set_ipv6_next_hop
2163
+ config_get_default('route_map', 'set_ipv6_next_hop')
2164
+ end
2165
+
2166
+ # set ipv6 default next-hop 1.1.1.1 2.2.2.2 3.3.3.3 load-share
2167
+ # set ipv6 default next-hop load-share
2168
+ def set_ipv6_next_hop_load_share
2169
+ arr = config_get('route_map', 'set_ipv6_next_hop', @get_args)
2170
+ val = default_set_ipv6_next_hop_load_share
2171
+ arr.each do |str|
2172
+ next if str.empty?
2173
+ return true if str.include?('load-share')
2174
+ end
2175
+ val
2176
+ end
2177
+
2178
+ def default_set_ipv6_next_hop_load_share
2179
+ config_get_default('route_map', 'set_ipv6_next_hop_load_share')
2180
+ end
2181
+
2182
+ def set_ipv6_next_hop_peer_addr
2183
+ config_get('route_map', 'set_ipv6_next_hop_peer_addr', @get_args)
2184
+ end
2185
+
2186
+ def set_ipv6_next_hop_peer_addr_set(val)
2187
+ state = val ? '' : 'no'
2188
+ set_args_keys(state: state)
2189
+ config_set('route_map', 'set_ipv6_next_hop_peer_addr', @set_args)
2190
+ end
2191
+
2192
+ def default_set_ipv6_next_hop_peer_addr
2193
+ config_get_default('route_map', 'set_ipv6_next_hop_peer_addr')
2194
+ end
2195
+
2196
+ def set_ipv6_next_hop_redist
2197
+ config_get('route_map', 'set_ipv6_next_hop_redist', @get_args)
2198
+ end
2199
+
2200
+ def set_ipv6_next_hop_redist_set(val)
2201
+ state = val ? '' : 'no'
2202
+ set_args_keys(state: state)
2203
+ config_set('route_map', 'set_ipv6_next_hop_redist', @set_args)
2204
+ end
2205
+
2206
+ def default_set_ipv6_next_hop_redist
2207
+ config_get_default('route_map', 'set_ipv6_next_hop_redist')
2208
+ end
2209
+
2210
+ def set_ipv6_next_hop_unchanged
2211
+ config_get('route_map', 'set_ipv6_next_hop_unchanged', @get_args)
2212
+ end
2213
+
2214
+ def set_ipv6_next_hop_unchanged_set(val)
2215
+ state = val ? '' : 'no'
2216
+ set_args_keys(state: state)
2217
+ config_set('route_map', 'set_ipv6_next_hop_unchanged', @set_args)
2218
+ end
2219
+
2220
+ def default_set_ipv6_next_hop_unchanged
2221
+ config_get_default('route_map', 'set_ipv6_next_hop_unchanged')
2222
+ end
2223
+
2224
+ def set_community_additive
2225
+ str = config_get('route_map', 'set_community', @get_args)
2226
+ add = false
2227
+ return add if str.nil?
2228
+ add = true if str.include?('additive') || str == 'set community '
2229
+ add
2230
+ end
2231
+
2232
+ def default_set_community_additive
2233
+ config_get_default('route_map', 'set_community_additive')
2234
+ end
2235
+
2236
+ def set_community_internet
2237
+ str = config_get('route_map', 'set_community', @get_args)
2238
+ str.nil? ? false : str.include?('internet')
2239
+ end
2240
+
2241
+ def default_set_community_internet
2242
+ config_get_default('route_map', 'set_community_internet')
2243
+ end
2244
+
2245
+ def set_community_local_as
2246
+ str = config_get('route_map', 'set_community', @get_args)
2247
+ str.nil? ? false : str.include?('local-AS')
2248
+ end
2249
+
2250
+ def default_set_community_local_as
2251
+ config_get_default('route_map', 'set_community_local_as')
2252
+ end
2253
+
2254
+ def set_community_no_advtertise
2255
+ str = config_get('route_map', 'set_community', @get_args)
2256
+ str.nil? ? false : str.include?('no-advertise')
2257
+ end
2258
+
2259
+ def default_set_community_no_advtertise
2260
+ config_get_default('route_map', 'set_community_no_advtertise')
2261
+ end
2262
+
2263
+ def set_community_no_export
2264
+ str = config_get('route_map', 'set_community', @get_args)
2265
+ str.nil? ? false : str.include?('no-export')
2266
+ end
2267
+
2268
+ def default_set_community_no_export
2269
+ config_get_default('route_map', 'set_community_no_export')
2270
+ end
2271
+
2272
+ def set_community_none
2273
+ str = config_get('route_map', 'set_community', @get_args)
2274
+ str.nil? ? false : str.include?('none')
2275
+ end
2276
+
2277
+ def default_set_community_none
2278
+ config_get_default('route_map', 'set_community_none')
2279
+ end
2280
+
2281
+ def set_community_asn
2282
+ str = config_get('route_map', 'set_community', @get_args)
2283
+ return default_set_community_asn if str.nil? || !str.include?(':')
2284
+ str.sub!('set community', '')
2285
+ str.sub!('internet', '')
2286
+ str.sub!('additive', '')
2287
+ str.sub!('local-AS', '')
2288
+ str.sub!('no-export', '')
2289
+ str.sub!('no-advertise', '')
2290
+ str.split
2291
+ end
2292
+
2293
+ def default_set_community_asn
2294
+ config_get_default('route_map', 'set_community_asn')
2295
+ end
2296
+
2297
+ # set community none
2298
+ # set community (if only additive is configured)
2299
+ # set internet 11:22 22:33 local-AS no-advertise no-export additive
2300
+ # and combinations of the above
2301
+ def set_community_set(none, noadv, noexp, add, local, inter, asn)
2302
+ str = ''
2303
+ # reset first
2304
+ set_args_keys(state: 'no', string: str)
2305
+ config_set('route_map', 'set_community', @set_args)
2306
+ return unless none || noadv || noexp || add ||
2307
+ local || inter || !asn.empty?
2308
+ str.concat('internet ') if inter
2309
+ asn.each do |elem|
2310
+ str.concat(elem + ' ')
2311
+ end
2312
+ str.concat('no-export ') if noexp
2313
+ str.concat('no-advertise ') if noadv
2314
+ str.concat('local-AS ') if local
2315
+ str.concat('additive ') if add
2316
+ str.concat('none') if none
2317
+ set_args_keys(state: '', string: str)
2318
+ config_set('route_map', 'set_community', @set_args)
2319
+ end
2320
+
2321
+ def set_extcommunity_4bytes_additive
2322
+ str = config_get('route_map', 'set_extcommunity_4bytes', @get_args)
2323
+ str.nil? ? false : str.include?('additive')
2324
+ end
2325
+
2326
+ def default_set_extcommunity_4bytes_additive
2327
+ config_get_default('route_map', 'set_extcommunity_4bytes_additive')
2328
+ end
2329
+
2330
+ def set_extcommunity_4bytes_none
2331
+ str = config_get('route_map', 'set_extcommunity_4bytes', @get_args)
2332
+ str.nil? ? false : str.include?('none')
2333
+ end
2334
+
2335
+ def default_set_extcommunity_4bytes_none
2336
+ config_get_default('route_map', 'set_extcommunity_4bytes_none')
2337
+ end
2338
+
2339
+ def set_extcommunity_4bytes_non_transitive
2340
+ str = config_get('route_map', 'set_extcommunity_4bytes', @get_args)
2341
+ return default_set_extcommunity_4bytes_non_transitive if
2342
+ str.nil? || !str.include?('non-transitive')
2343
+ arr = str.split
2344
+ ret_arr = []
2345
+ index = arr.index('non-transitive')
2346
+ while index
2347
+ ret_arr << arr[index + 1]
2348
+ arr.delete_at(index)
2349
+ arr.delete_at(index)
2350
+ index = arr.index('non-transitive')
2351
+ end
2352
+ ret_arr
2353
+ end
2354
+
2355
+ def default_set_extcommunity_4bytes_non_transitive
2356
+ config_get_default('route_map', 'set_extcommunity_4bytes_non_transitive')
2357
+ end
2358
+
2359
+ def set_extcommunity_4bytes_transitive
2360
+ str = config_get('route_map', 'set_extcommunity_4bytes', @get_args)
2361
+ return default_set_extcommunity_4bytes_transitive if str.nil?
2362
+ arr = str.split
2363
+ ret_arr = []
2364
+ index = arr.index('transitive')
2365
+ while index
2366
+ ret_arr << arr[index + 1]
2367
+ arr.delete_at(index)
2368
+ arr.delete_at(index)
2369
+ index = arr.index('transitive')
2370
+ end
2371
+ ret_arr
2372
+ end
2373
+
2374
+ def default_set_extcommunity_4bytes_transitive
2375
+ config_get_default('route_map', 'set_extcommunity_4bytes_transitive')
2376
+ end
2377
+
2378
+ # set extcommunity 4byteas-generic none
2379
+ # set extcommunity 4byteas-generic additive
2380
+ # set extcommunity 4byteas-generic transitive 11:22 transitive 22:33
2381
+ # set extcommunity 4byteas-generic non-transitive 11:22
2382
+ # set extcommunity 4byteas-generic transitive 22:33 non-transitive 11:22
2383
+ def set_extcommunity_4bytes_set(none, transit, non_transit, add)
2384
+ str = ''
2385
+ # reset first
2386
+ set_args_keys(state: 'no', string: str)
2387
+ config_set('route_map', 'set_extcommunity_4bytes', @set_args)
2388
+ return unless none || add || !transit.empty? || !non_transit.empty?
2389
+ str.concat('none') if none
2390
+ transit.each do |elem|
2391
+ str.concat('transitive ' + elem + ' ')
2392
+ end
2393
+ non_transit.each do |elem|
2394
+ str.concat('non-transitive ' + elem + ' ')
2395
+ end
2396
+ str.concat('additive') if add
2397
+ set_args_keys(state: '', string: str)
2398
+ config_set('route_map', 'set_extcommunity_4bytes', @set_args)
2399
+ end
2400
+
2401
+ def set_extcommunity_rt_additive
2402
+ str = config_get('route_map', 'set_extcommunity_rt', @get_args)
2403
+ str.nil? ? false : str.include?('additive')
2404
+ end
2405
+
2406
+ def default_set_extcommunity_rt_additive
2407
+ config_get_default('route_map', 'set_extcommunity_rt_additive')
2408
+ end
2409
+
2410
+ def set_extcommunity_rt_asn
2411
+ str = config_get('route_map', 'set_extcommunity_rt', @get_args)
2412
+ return default_set_extcommunity_rt_asn if str.nil?
2413
+ str.delete!('additive')
2414
+ str.split
2415
+ end
2416
+
2417
+ def default_set_extcommunity_rt_asn
2418
+ config_get_default('route_map', 'set_extcommunity_rt_asn')
2419
+ end
2420
+
2421
+ # set extcommunity rt additive
2422
+ # set extcommunity rt 11:22 12.22.22.22:12 123.256:543
2423
+ # set extcommunity rt 11:22 12.22.22.22:12 123.256:543 additive
2424
+ def set_extcommunity_rt_set(asn, add)
2425
+ str = ''
2426
+ # reset first
2427
+ set_args_keys(state: 'no', string: str)
2428
+ config_set('route_map', 'set_extcommunity_rt', @set_args)
2429
+ return unless add || !asn.empty?
2430
+ asn.each do |elem|
2431
+ str.concat(elem + ' ')
2432
+ end
2433
+ str.concat('additive') if add
2434
+ set_args_keys(state: '', string: str)
2435
+ config_set('route_map', 'set_extcommunity_rt', @set_args)
2436
+ end
2437
+
2438
+ def set_extcommunity_cost_igp
2439
+ str = config_get('route_map', 'set_extcommunity_cost', @get_args)
2440
+ return default_set_extcommunity_cost_igp if
2441
+ str.nil? || !str.include?('igp')
2442
+ arr = str.split
2443
+ ret_arr = []
2444
+ index = arr.index('igp')
2445
+ while index
2446
+ larr = []
2447
+ larr << arr[index + 1]
2448
+ larr << arr[index + 2]
2449
+ ret_arr << larr
2450
+ arr.delete_at(index)
2451
+ arr.delete_at(index)
2452
+ arr.delete_at(index)
2453
+ index = arr.index('igp')
2454
+ end
2455
+ ret_arr
2456
+ end
2457
+
2458
+ def default_set_extcommunity_cost_igp
2459
+ config_get_default('route_map', 'set_extcommunity_cost_igp')
2460
+ end
2461
+
2462
+ def set_extcommunity_cost_pre_bestpath
2463
+ str = config_get('route_map', 'set_extcommunity_cost', @get_args)
2464
+ return default_set_extcommunity_cost_pre_bestpath if
2465
+ str.nil? || !str.include?('pre-bestpath')
2466
+ arr = str.split
2467
+ ret_arr = []
2468
+ index = arr.index('pre-bestpath')
2469
+ while index
2470
+ larr = []
2471
+ larr << arr[index + 1]
2472
+ larr << arr[index + 2]
2473
+ ret_arr << larr
2474
+ arr.delete_at(index)
2475
+ arr.delete_at(index)
2476
+ arr.delete_at(index)
2477
+ index = arr.index('pre-bestpath')
2478
+ end
2479
+ ret_arr
2480
+ end
2481
+
2482
+ def default_set_extcommunity_cost_pre_bestpath
2483
+ config_get_default('route_map', 'set_extcommunity_cost_pre_bestpath')
2484
+ end
2485
+
2486
+ def set_extcommunity_cost_device
2487
+ config_get('route_map', 'set_extcommunity_cost_device', @get_args)
2488
+ end
2489
+
2490
+ # set extcommunity cost igp 0 22 igp 3 23
2491
+ # set extcommunity cost pre-bestpath 1 222 pre-bestpath 2 54
2492
+ # set extcommunity cost pre-bestpath 1 222 pre-bestpath 2 54 igp 0 22
2493
+ def set_extcommunity_cost_set(igp, pre)
2494
+ str = ''
2495
+ # reset first
2496
+ if set_extcommunity_cost_device
2497
+ cpre = set_extcommunity_cost_pre_bestpath
2498
+ cigp = set_extcommunity_cost_igp
2499
+ cpre.each do |id, val|
2500
+ str.concat('pre-bestpath ' + id.to_s + ' ' + val.to_s + ' ')
2501
+ end
2502
+ cigp.each do |id, val|
2503
+ str.concat('igp ' + id.to_s + ' ' + val.to_s + ' ')
2504
+ end
2505
+ end
2506
+ set_args_keys(state: 'no', string: str)
2507
+ config_set('route_map', 'set_extcommunity_cost', @set_args)
2508
+ return if igp.empty? && pre.empty?
2509
+ str = ''
2510
+ pre.each do |id, val|
2511
+ str.concat('pre-bestpath ' + id.to_s + ' ' + val.to_s + ' ')
2512
+ end
2513
+ igp.each do |id, val|
2514
+ str.concat('igp ' + id.to_s + ' ' + val.to_s + ' ')
2515
+ end
2516
+ set_args_keys(state: '', string: str)
2517
+ config_set('route_map', 'set_extcommunity_cost', @set_args)
2518
+ end
2519
+
2520
+ def set_ip_next_hop_reset(attrs)
2521
+ set_interface_set(default_set_interface)
2522
+ v4ls = default_set_ipv4_default_next_hop_load_share
2523
+ set_ipv4_def_next_hop_set(default_set_ipv4_default_next_hop, v4ls) unless
2524
+ default_set_ipv4_default_next_hop.nil?
2525
+ default_set_ipv4_default_next_hop.nil?
2526
+ set_ipv4_next_hop_set(default_set_ipv4_next_hop)
2527
+ set_ipv4_next_hop_peer_addr_set(default_set_ipv4_next_hop_peer_addr)
2528
+ set_ipv4_next_hop_redist_set(default_set_ipv4_next_hop_redist) unless
2529
+ attrs[:v4red].nil?
2530
+ set_ipv4_next_hop_unchanged_set(default_set_ipv4_next_hop_unchanged)
2531
+ v6ls = default_set_ipv4_default_next_hop_load_share
2532
+ set_ipv6_def_next_hop_set(default_set_ipv6_default_next_hop, v6ls) unless
2533
+ default_set_ipv6_default_next_hop.nil?
2534
+ set_ipv6_next_hop_set(default_set_ipv6_next_hop)
2535
+ set_ipv6_next_hop_peer_addr_set(default_set_ipv6_next_hop_peer_addr)
2536
+ set_ipv6_next_hop_redist_set(default_set_ipv6_next_hop_redist) unless
2537
+ attrs[:v6red].nil?
2538
+ set_ipv6_next_hop_unchanged_set(default_set_ipv6_next_hop_unchanged)
2539
+ end
2540
+
2541
+ def set_ip_next_hop_set(attrs)
2542
+ set_ip_next_hop_reset(attrs)
2543
+ set_interface_set(attrs[:intf])
2544
+ set_ipv4_def_next_hop_set(attrs[:v4dnh], attrs[:v4dls]) unless
2545
+ default_set_ipv4_default_next_hop.nil?
2546
+ set_ipv4_next_hop_set(attrs[:v4nh], attrs[:v4ls])
2547
+ set_ipv4_next_hop_peer_addr_set(attrs[:v4peer])
2548
+ set_ipv4_next_hop_redist_set(attrs[:v4red]) unless attrs[:v4red].nil?
2549
+ set_ipv4_next_hop_unchanged_set(attrs[:v4unc])
2550
+ set_ipv6_def_next_hop_set(attrs[:v6dnh], attrs[:v6dls]) unless
2551
+ default_set_ipv6_default_next_hop.nil?
2552
+ set_ipv6_next_hop_set(attrs[:v6nh], attrs[:v6ls])
2553
+ set_ipv6_next_hop_peer_addr_set(attrs[:v6peer])
2554
+ set_ipv6_next_hop_redist_set(attrs[:v6red]) unless attrs[:v6red].nil?
2555
+ set_ipv6_next_hop_unchanged_set(attrs[:v6unc])
2556
+ end
2557
+ end # class
2558
+ end # module