'ofp_match: check IP wildcard magic'

def test_ip_wildcard_magic(self):

    for (attr, bitmask, shift) in (('nw_src', OFPFW_NW_SRC_MASK, OFPFW_NW_SRC_SHIFT), ('nw_dst', OFPFW_NW_DST_MASK, OFPFW_NW_DST_SHIFT)):
        m = ofp_match()
        self.assertEquals(getattr(m, ('get_' + attr))(), (None, 0), ('get_%s    for    unset    %s    should    return    (None,0)' % (attr, attr)))
        self.assertTrue((((m.wildcards & bitmask) >> shift) >= 32))
        for ipnet in ('10.0.0.0/8', '172.16.0.0/16', '192.168.24.0/24', '1.2.3.4/30', '212.11.225.3'):
            parts = ipnet.split('/')
            ip = parts[0]
            bits = (int(parts[1]) if (len(parts) > 1) else 32)
            setattr(m, attr, ipnet)
            self.assertEqual(getattr(m, attr), ip)
            self.assertEqual(getattr(m, ('get_' + attr))(), (ip, bits))
            self.assertEqual(((m.wildcards & bitmask) >> shift), (32 - bits))
        setattr(m, attr, '0.0.0.0/0')
        self.assertEquals(getattr(m, ('get_' + attr))(), (None, 0), ('get_%s    for    unset    %s    should    return    (None,0)' % (attr, attr)))
        self.assertTrue((((m.wildcards & bitmask) >> shift) >= 32))
