Ask Your Question
0

Java library to find if 2 CIDR's overlap

asked 2013-06-06 05:57:13 -0500

ritesh-s-shetty gravatar image

Assuming Quantum doesnt have a mechanism to query and see if a new subnet CIDR that i want to create doesnt overlaps with the existing subnet CIDR's. I want to do this before creating a subnet, i want to find if an overlapping subnet cidr exists.

If above is true then..

I know this is not directly related to the Quantum work, I need a Java library or Algorithm to find if 2 CIDR's overlap.

Any help is greatly appreciated

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-06-06 06:18:43 -0500

gongysh gravatar image

this is python one quantum is using: def _validate_subnet_cidr(self, context, network, new_subnet_cidr): """Validate the CIDR for a subnet.

    Verifies the specified CIDR does not overlap with the ones defined
    for the other subnets specified for this network, or with any other
    CIDR if overlapping IPs are disabled.
    """
    new_subnet_ipset = netaddr.IPSet([new_subnet_cidr])
    if cfg.CONF.allow_overlapping_ips:
        subnet_list = network.subnets
    else:
        subnet_list = self._get_all_subnets(context)
    for subnet in subnet_list:
        if (netaddr.IPSet([subnet.cidr]) & new_subnet_ipset):
            # don't give out details of the overlapping subnet
            err_msg = (_("Requested subnet with cidr: %(cidr)s for "
                         "network: %(network_id)s overlaps with another "
                         "subnet") %
                       {'cidr': new_subnet_cidr,
                        'network_id': network.id})
            LOG.error(_("Validation for CIDR: %(new_cidr)s failed - "
                        "overlaps with subnet %(subnet_id)s "
                        "(CIDR: %(cidr)s)"),
                      {'new_cidr': new_subnet_cidr,
                       'subnet_id': subnet.id,
                       'cidr': subnet.cidr})
            raise q_exc.InvalidInput(error_message=err_msg)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2013-06-06 05:57:13 -0500

Seen: 712 times

Last updated: Jun 06 '13