Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/cisco_node_utils/cisco_cmn_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,12 @@ def self.delta_add_remove(should, current=[], opt=nil)
end
delta
end # delta_add_remove

# Helper to 0-pad a mac address.
def self.zero_pad_macaddr(mac)
return nil if mac.nil? || mac.empty?
o1, o2, o3 = mac.split('.').map { |o| o.to_i(16).to_s(10) }
sprintf('%04x.%04x.%04x', o1, o2, o3)
end
end # class Utils
end # module Cisco
5 changes: 4 additions & 1 deletion lib/cisco_node_utils/overlay_global.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require_relative 'cisco_cmn_utils'
require_relative 'feature'
require_relative 'node_util'

Expand Down Expand Up @@ -125,7 +126,9 @@ def default_dup_host_mac_detection_timeout
# anycast-gateway-mac
def anycast_gateway_mac
return nil unless Feature.nv_overlay_evpn_enabled?
config_get('overlay_global', 'anycast_gateway_mac')
mac = config_get('overlay_global', 'anycast_gateway_mac')
# This value gets 0-padded when nvgened, so we need to convert it.
Utils.zero_pad_macaddr(mac).nil? ? default_anycast_gateway_mac : mac
end

def anycast_gateway_mac=(mac_addr)
Expand Down
11 changes: 7 additions & 4 deletions tests/test_overlay_global.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

require_relative 'ciscotest'
require_relative '../lib/cisco_node_utils/cisco_cmn_utils'
require_relative '../lib/cisco_node_utils/feature'
require_relative '../lib/cisco_node_utils/overlay_global'

Expand Down Expand Up @@ -91,9 +92,11 @@ def test_anycast_gateway_mac
overlay_global.anycast_gateway_mac)
assert(Feature.nv_overlay_evpn_enabled?)

# Set to non-default value
mac_addr = '1223.3445.5668'
overlay_global.anycast_gateway_mac = mac_addr
assert_equal(mac_addr, overlay_global.anycast_gateway_mac)
# Set to various non-default values
%w(1.1.1 55.a10.ffff 1223.3445.5668).each do |mac|
overlay_global.anycast_gateway_mac = mac
assert_equal(Utils.zero_pad_macaddr(mac),
overlay_global.anycast_gateway_mac)
end
end
end