Example #1
0
    def test_nary_union(self):
        loc1 = nc.inport(1, 1)
        loc2 = nc.inport(2, 2)
        loc3 = nc.inport(3, 3)

        union = nc.nary_union([loc1, loc2, loc3])
        self.assertTrue(union.match(blank_packet, (1,1)))
        self.assertTrue(union.match(blank_packet, (2,2)))
        self.assertTrue(union.match(blank_packet, (3,3)))
        self.assertFalse(union.match(blank_packet, (-1,-1)))
Example #2
0
def external_to_vlan_policy(slic, policy, vlan):
    """Produce a policy that moves packets along external ports into the vlan.

    Just restricting packets to the vlan means that packets can never enter the
    slice.  To let packets enter, we need to make another copy of the policy,
    restrict it to only entrances, and change the actions to add the vlan.

    ARGS:
        slic:  Slice to produce this policy for
        policy:  Policy to restrict
        vlan:  vlan to enter

    RETURNS:
        A policy that moves packets incoming to external ports into the vlan,
        but only if they satisfy the slice's isolation predicates.
    """
    external_predicates = [external_predicate(loc, pred)
                           for loc, pred in slic.edge_policy.iteritems()]
    predicate = nc.nary_union(external_predicates)
    policy_into_vlan = modify_vlan(policy, vlan)
    return policy_into_vlan % (predicate & nc.Header({'vlan': 0}))