diff --git a/lib/cisco_node_utils/cisco_cmn_utils.rb b/lib/cisco_node_utils/cisco_cmn_utils.rb index a4c40b03..c7e01e48 100644 --- a/lib/cisco_node_utils/cisco_cmn_utils.rb +++ b/lib/cisco_node_utils/cisco_cmn_utils.rb @@ -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 diff --git a/lib/cisco_node_utils/overlay_global.rb b/lib/cisco_node_utils/overlay_global.rb index f5333c31..57196998 100644 --- a/lib/cisco_node_utils/overlay_global.rb +++ b/lib/cisco_node_utils/overlay_global.rb @@ -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' @@ -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) diff --git a/tests/test_overlay_global.rb b/tests/test_overlay_global.rb index eab70d41..d304be78 100755 --- a/tests/test_overlay_global.rb +++ b/tests/test_overlay_global.rb @@ -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' @@ -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