def _get_router_ip(self, cidr, ip_count, ip_ver):
        """For a given IP subnet and IP version type, generate IP for router.

        This method takes the network address (cidr) and selects an
        IP address that should be assigned to virtual router running
        on multiple switches. It uses upper addresses in a subnet address
        as IP for the router. Each instace of the router, on each switch,
        requires uniqe IP address. For example in IPv4 case, on a 255
        subnet, it will pick X.X.X.254 as first addess, X.X.X.253 for next,
        and so on.
        """
        start_ip = MLAG_SWITCHES + ip_count
        network_addr, prefix = cidr.split('/')
        if ip_ver == 4:
            bits = IPV4_BITS
            ip = self._get_binary_from_ipv4(network_addr)
        elif ip_ver == 6:
            bits = IPV6_BITS
            ip = self._get_binary_from_ipv6(network_addr)

        mask = (pow(2, bits) - 1) << (bits - int(prefix))

        network_addr = ip & mask

        router_ip = pow(2, bits - int(prefix)) - start_ip

        router_ip = network_addr | router_ip
        if ip_ver == 4:
            return self._get_ipv4_from_binary(router_ip) + '/' + prefix
        else:
            return self._get_ipv6_from_binary(router_ip) + '/' + prefix
def _get_router_ip ( self , cidr , ip_count , ip_ver ) : start_ip = MLAG_SWITCHES + ip_count network_addr , prefix = cidr . split ( '/' ) if ip_ver == 4 : bits = IPV4_BITS ip = self . _get_binary_from_ipv4 ( network_addr ) elif ip_ver == 6 : bits = IPV6_BITS ip = self . _get_binary_from_ipv6 ( network_addr ) mask = ( pow ( 2 , bits ) - 1 ) << ( bits - int ( prefix ) ) network_addr = ip & mask router_ip = pow ( 2 , bits - int ( prefix ) ) - start_ip router_ip = network_addr | router_ip if ip_ver == 4 : return self . _get_ipv4_from_binary ( router_ip ) + '/' + prefix else : return self . _get_ipv6_from_binary ( router_ip ) + '/' + prefix
For a given IP subnet and IP version type, generate IP for router.

        This method takes the network address (cidr) and selects an
        IP address that should be assigned to virtual router running
        on multiple switches. It uses upper addresses in a subnet address
        as IP for the router. Each instace of the router, on each switch,
        requires uniqe IP address. For example in IPv4 case, on a 255
        subnet, it will pick X.X.X.254 as first addess, X.X.X.253 for next,
        and so on.