Skip to content

Commit

Permalink
Ospf parameters for interfaces (#460)
Browse files Browse the repository at this point in the history
* Add feature ospf enable

* review comments

* Fix interface_ospf

* added pri, tx delay, shut and mtu to int ospf

* changelog
  • Loading branch information
saichint authored and mikewiebe committed Aug 9, 2016
1 parent 4753922 commit 2dd5c27
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ Changelog
* `bfd_echo`
* Extend interface_ospf with attributes:
* `bfd`
* `mtu_ignore`
* `network_type`
* `priority`
* `shutdown`
* `transmit_delay`
* Extend interface_portchannel with attributes:
* `bfd_per_link`
* Extend router_ospf_vrf with attributes:
Expand Down
24 changes: 24 additions & 0 deletions lib/cisco_node_utils/cmd_ref/interface_ospf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ message_digest_password:
default_value: ~
get_value: '/^\s*ip ospf message-digest-key \d+ \S+ \d+ (\S+)/'

mtu_ignore:
kind: boolean
get_value: '/^\s*ip ospf mtu-ignore/'
set_value: "%s ip ospf mtu-ignore"
default_value: false

network_type:
get_value: '/^\s*ip ospf network (\S+)$/'
set_value: "%s ip ospf network %s"
Expand All @@ -79,3 +85,21 @@ passive_interface:
get_value: '/^\s*ip ospf passive-interface/'
set_value: "%s ip ospf passive-interface"
default_value: false

priority:
kind: int
get_value: '/^\s*ip ospf priority (\d+)/'
set_value: "%s ip ospf priority %s"
default_value: 1

shutdown:
kind: boolean
get_value: '/^\s*ip ospf shutdown/'
set_value: "%s ip ospf shutdown"
default_value: false

transmit_delay:
kind: int
get_value: '/^\s*ip ospf transmit-delay (\d+)/'
set_value: "%s ip ospf transmit-delay %s"
default_value: 1
68 changes: 68 additions & 0 deletions lib/cisco_node_utils/interface_ospf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ def destroy
config_set('interface_ospf', 'dead_interval',
@interface.name, 'no', '')
self.bfd = default_bfd
self.mtu_ignore = default_mtu_ignore
self.priority = default_priority
self.network_type = default_network_type
self.passive_interface = default_passive_interface if passive_interface
self.shutdown = default_shutdown
self.transmit_delay = default_transmit_delay
end

def default_message_digest
Expand Down Expand Up @@ -250,6 +254,21 @@ def default_network_type
config_get_default('interface_ospf', lookup)
end

def mtu_ignore
config_get('interface_ospf', 'mtu_ignore', @interface.name)
end

# interface %s
# %s ip ospf mtu-ignore
def mtu_ignore=(enable)
config_set('interface_ospf', 'mtu_ignore', @interface.name,
enable ? '' : 'no')
end

def default_mtu_ignore
config_get_default('interface_ospf', 'mtu_ignore')
end

def network_type
type = config_get('interface_ospf', 'network_type', @interface.name)
return 'p2p' if type == 'point-to-point'
Expand Down Expand Up @@ -282,5 +301,54 @@ def passive_interface=(enable)
config_set('interface_ospf', 'passive_interface', @interface.name,
enable ? '' : 'no')
end

def priority
config_get('interface_ospf', 'priority', @interface.name)
end

# interface %s
# ip ospf priority %d
def priority=(val)
no_cmd = (val == default_priority) ? 'no' : ''
pri = (val == default_priority) ? '' : val
config_set('interface_ospf', 'priority',
@interface.name, no_cmd, pri)
end

def default_priority
config_get_default('interface_ospf', 'priority')
end

def shutdown
config_get('interface_ospf', 'shutdown', @interface.name)
end

# interface %s
# %s ip ospf shutdown
def shutdown=(state)
config_set('interface_ospf', 'shutdown', @interface.name,
state ? '' : 'no')
end

def default_shutdown
config_get_default('interface_ospf', 'shutdown')
end

def transmit_delay
config_get('interface_ospf', 'transmit_delay', @interface.name)
end

# interface %s
# ip ospf transmit-delay %d
def transmit_delay=(val)
no_cmd = (val == default_transmit_delay) ? 'no' : ''
delay = (val == default_transmit_delay) ? '' : val
config_set('interface_ospf', 'transmit_delay',
@interface.name, no_cmd, delay)
end

def default_transmit_delay
config_get_default('interface_ospf', 'transmit_delay')
end
end
end
70 changes: 70 additions & 0 deletions tests/test_interface_ospf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,26 @@ def test_collection_not_empty
'bfd'),
interface.bfd,
'Error: bfd get failed')
assert_equal(node.config_get_default('interface_ospf',
'mtu_ignore'),
interface.mtu_ignore,
'Error: mtu_ignore get failed')
assert_equal(node.config_get_default('interface_ospf',
'priority'),
interface.priority,
'Error: priority get failed')
assert_equal(node.config_get_default('interface_ospf',
'network_type_default'),
interface.network_type,
'Error: network type get failed')
assert_equal(node.config_get_default('interface_ospf',
'shutdown'),
interface.shutdown,
'Error: shutdown get failed')
assert_equal(node.config_get_default('interface_ospf',
'transmit_delay'),
interface.transmit_delay,
'Error: transmit_delay get failed')
assert_equal(node.config_get_default('interface_ospf',
'passive_interface'),
interface.passive_interface,
Expand Down Expand Up @@ -222,6 +238,18 @@ def test_destroy
refute_show_match(pattern: /^\s+ip ospf bfd \S+/,
msg: "'bfd' not removed")

refute_show_match(pattern: /^\s+ip ospf mtu-ignore \S+/,
msg: "'mtu_ignore' not removed")

refute_show_match(pattern: /^\s+ip ospf shutdown \S+/,
msg: "'shutdown' not removed")

refute_show_match(pattern: /^\s+ip ospf transmit-delay \S+/,
msg: "'transmit_delay' not removed")

refute_show_match(pattern: /^\s+ip ospf priority \S+/,
msg: "'priority' not removed")

refute_show_match(pattern: /^\s+ip ospf network point-to-point/,
msg: "'network_type' not removed")

Expand Down Expand Up @@ -340,6 +368,16 @@ def test_bfd
assert_equal(interface.default_bfd, interface.bfd)
end

def test_mtu_ignore
ospf = create_routerospf
interface = create_interfaceospf(ospf)
assert_equal(interface.default_mtu_ignore, interface.mtu_ignore)
interface.mtu_ignore = true
assert_equal(true, interface.mtu_ignore)
interface.mtu_ignore = interface.default_mtu_ignore
assert_equal(interface.default_mtu_ignore, interface.mtu_ignore)
end

def test_network_type
ospf = create_routerospf
interface = create_interfaceospf(ospf)
Expand Down Expand Up @@ -379,6 +417,36 @@ def test_passive
msg: 'default passive interface set failed')
end

def test_priority
ospf = create_routerospf
interface = create_interfaceospf(ospf)
assert_equal(interface.default_priority, interface.priority)
interface.priority = 100
assert_equal(100, interface.priority)
interface.priority = interface.default_priority
assert_equal(interface.default_priority, interface.priority)
end

def test_shutdown
ospf = create_routerospf
interface = create_interfaceospf(ospf)
assert_equal(interface.default_shutdown, interface.shutdown)
interface.shutdown = true
assert_equal(true, interface.shutdown)
interface.shutdown = interface.default_shutdown
assert_equal(interface.default_shutdown, interface.shutdown)
end

def test_transmit_delay
ospf = create_routerospf
interface = create_interfaceospf(ospf)
assert_equal(interface.default_transmit_delay, interface.transmit_delay)
interface.transmit_delay = 400
assert_equal(400, interface.transmit_delay)
interface.transmit_delay = interface.default_transmit_delay
assert_equal(interface.default_transmit_delay, interface.transmit_delay)
end

def test_mult
# ospf and interfaces[0]
ospf = create_routerospf
Expand Down Expand Up @@ -501,6 +569,7 @@ def test_collect_mult_intf
# enable feature ospf
config('no feature ospf',
'feature ospf',
'feature bfd',
'feature interface-vlan',
"default interface #{interfaces[0]}",
"default interface #{interfaces[1]}",
Expand Down Expand Up @@ -544,6 +613,7 @@ def test_collect_mult_intf

# disable feature interface-vlan
config('no feature interface-vlan')
config('no feature bfd')
# clean up port channel
ospf_h.each_value do |v|
v.each_key do |k1|
Expand Down

0 comments on commit 2dd5c27

Please sign in to comment.