Esempio n. 1
0
    def testRuleEqualityReflexive(self):
        pat1 = Pattern(nw_src="10.0.0.1")
        act1 = Action("modify", ["vlan", 1])
        act2 = Action("forward", [2])

        r1 = Rule(pat1, [act1, act2])
        r2 = Rule(pat1, [act1, act2])

        self.assertEqual(r1, r2)
Esempio n. 2
0
    def testRuleInequality(self):
        pat1 = Pattern(nw_dst="192.168.2.1", in_port=1)
        act1 = Action("modify", ["nw_dst", "192.168.2.2"])
        act2 = Action("forward", [2])

        r1 = Rule(pat1, [act1,act2])
        r2 = Rule(pat1, [act1])

        self.assertNotEqual(r1, r2)
Esempio n. 3
0
    def testRuleEquality(self):
        pat1 = Pattern(in_port=3, dl_type=2048, nw_src="10.0.0.2", nw_dst="10.0.0.12")
        act1 = Action("forward", [1])

        pat2 = Pattern(in_port=3, dl_type=2048, nw_src="10.0.0.2", nw_dst="10.0.0.12")
        act2 = Action("forward", [1])

        r1 = Rule(pat1, [act1])
        r2 = Rule(pat2, [act2])

        self.assertEqual(r1, r2)
Esempio n. 4
0
    def testConfigMembership(self):
        pat1 = Pattern(in_port=3, dl_type=2048, nw_src="10.0.0.2", nw_dst="10.0.0.12")
        act1 = Action("forward", [1])
        r1 = Rule(pat1, [act1])
        c = SwitchConfiguration([r1])

        self.assertTrue(r1 in c)
Esempio n. 5
0
    def testPolicyBool(self):
        pat1 = Pattern(in_port=2)
        act1 = Action("forward", [3])
        r1 = Rule(pat1, [act1])
        c1 = SwitchConfiguration([r1])
        pol1 = NetworkPolicy({1:c1})

        self.assertTrue(pol1)
Esempio n. 6
0
    def testPolicyNotEmpty(self):
        pat1 = Pattern(in_port=2)
        act1 = Action("forward", [3])
        r1 = Rule(pat1, [act1])
        c1 = SwitchConfiguration([r1])
        pol1 = NetworkPolicy({1:c1})

        self.assertFalse(pol1.is_empty())
Esempio n. 7
0
    def testPolicyGetConfig(self):
        pat1 = Pattern(in_port=2)
        act1 = Action("forward", [3])
        r1 = Rule(pat1, [act1])
        c1 = SwitchConfiguration([r1])
        pol1 = NetworkPolicy({1:c1})

        self.assertEqual(c1, pol1[1])
Esempio n. 8
0
    def testConfigAddRule(self):
        pat1 = Pattern(in_port=3, dl_type=2048, nw_src="10.0.0.2", nw_dst="10.0.0.12")
        act1 = Action("forward", [1])
        r1 = Rule(pat1, [act1])

        c1 = SwitchConfiguration([r1])
        c2 = SwitchConfiguration()
        c2.add_rule(r1)

        self.assertEqual(c1,c2)
Esempio n. 9
0
    def testConfigDiff(self):
        pat1 = Pattern(in_port=3, nw_src="10.0.0.2", nw_dst="10.0.0.12")
        act1 = Action("forward", [3])
        r1 = Rule(pat1, [act1])
        pat2 = Pattern(nw_src="10.0.0.1", nw_dst="10.0.0.10")
        r2 = Rule(pat2, [])

        c1 = SwitchConfiguration([r1,r2])        
        c2 = SwitchConfiguration([r1])
        c3 = SwitchConfiguration([r2])

        self.assertEqual(c1 - c2, c3)
Esempio n. 10
0
    def testPatternIntersect(self):
        pat1 = Pattern(dl_vlan=1)
        pat2 = Pattern(dl_vlan=2)
        act = Action("forward", [3])

        r1 = Rule(pat1, [act])
        r2 = Rule(pat2, [act])

        c1 = SwitchConfiguration([r1])
        c2 = SwitchConfiguration([r2])

        pol1 = NetworkPolicy({1: c1})
        pol2 = NetworkPolicy({1: c2})

        self.assertEqual(pol1.pattern_intersect(pol2), NetworkPolicy())
Esempio n. 11
0
    def testPolicySum2(self):
        pat1 = Pattern(in_port=2)
        act1 = Action("forward", [3])
        r1 = Rule(pat1, [act1])
        c1 = SwitchConfiguration([r1])
        pol1 = NetworkPolicy({1:c1})

        pat2 = Pattern(in_port=3)
        r2 = Rule(pat2, [])
        c2 = SwitchConfiguration([r2])
        pol2 = NetworkPolicy({1:c2})

        pol3 = NetworkPolicy({1: c1 + c2})

        self.assertEqual(pol1 + pol2, pol3)
Esempio n. 12
0
 def transition_prob(self, state, action, state_prime):
     """
         Given a state obj, action (direction), and state',
         return the probability [0, 1] of a successful action
     """
     prime_dir = self.grid.get_dir(state, state_prime)
     if action == Action.NONE and prime_dir == action:
         return 1.0
     elif action == Action.NONE:
         return 0.0
     
     if prime_dir == Action.NONE:
         return 0.0
     elif action == prime_dir:
         return 0.8
         #return 0.6
     elif Action.arePerpendicular(action, prime_dir):
         return 0.1
         #return 0.2
     else:
         return 0.0
Esempio n. 13
0
    def testActionInequal(self):
        act1 = Action("modify", ["srcip", "10.0.0.1"])
        act2 = Action("modify", ["srcip", "10.0.0.2"])

        self.assertNotEqual(act1, act2)
Esempio n. 14
0
    def testActionEqual(self):
        act1 = Action("strip", ["vlan"])
        act2 = Action("strip", ["vlan"])

        self.assertEqual(act1, act2)
Esempio n. 15
0
    def testActionConvertToNox(self):
        act = Action("forward", [1])

        self.assertEqual(act.convert_to_nox_action(),
                         [openflow.OFPAT_OUTPUT, [0, 1]])