'ofp_match: test the matches_with_wildcards method'

def test_match_with_wildcards(self):

    def create(wildcards=(), **kw):
        m = ofp_match(in_port=1, dl_type=0, dl_src=EthAddr('00:00:00:00:00:01'), dl_dst=EthAddr('00:00:00:00:00:02'), dl_vlan=5, nw_proto=6, nw_src='10.0.0.1', nw_dst='11.0.0.1', tp_src=12345, tp_dst=80)
        if isinstance(wildcards, str):
            wildcards = [wildcards]
        for w in wildcards:
            setattr(m, w, None)
        for (k, v) in kw.iteritems():
            m.__setattr__(k, v)
        return m
    def assertMatch(ref, other, msg=''):
        self.assertTrue(ref.matches_with_wildcards(other), ('%s    -    %s    should    match    %s    ' % (msg, ref.show(), other.show())))
    def assertNoMatch(ref, other, msg=''):
        self.assertFalse(ref.matches_with_wildcards(other), ('%s    -    %s    should    NOT    match    %s    ' % (msg, ref.show(), other.show())))
    ref = create()
    assertMatch(ref, ref)
    assertMatch(ref, create())
    for wildcards in (['in_port'], ['dl_vlan'], ['dl_src', 'dl_dst']):
        wilder = create(wildcards=wildcards)
        assertMatch(wilder, ref)
        assertNoMatch(ref, wilder)
    for changes in ({'in_port': 15}, {'dl_src': '12:34:56:78:90:ab', 'dl_vlan': 7}, {'tp_dst': 22}):
        wild = create()
        concrete = create()
        for (k, v) in changes.iteritems():
            setattr(wild, k, None)
            setattr(concrete, k, v)
        assertMatch(wild, concrete)
        assertNoMatch(concrete, wild)
    assertMatch(create(nw_src='10.0.0.0/24'), ref)
    assertMatch(create(nw_src='10.0.0.0/24'), create(nw_src='10.0.0.0/25'))
    assertNoMatch(create(nw_src='10.0.0.0/25'), create(nw_src='10.0.0.0/24'))
    assertMatch(create(nw_src='10.0.0.0/25'), create(nw_src='10.0.0.127'))
    assertNoMatch(create(nw_src='10.0.0.0/25'), create(nw_src='10.0.0.128'))
