Exemplo n.º 1
0
    def test_convert_flow1(self):
        """ Test converting OFPFlowMod and OFPFlowStats from ovs """

        expected_insts = Instructions()
        expected_insts.apply_actions.append("POP_VLAN", None)
        expected_insts.apply_actions.append("SET_FIELD",
                                            ("ETH_DST", 0x101010101010))
        expected_insts.apply_actions.append("OUTPUT", 7)
        expected_insts.goto_table = 4

        expected = Rule(priority=789,
                        cookie=0xABCD,
                        table=3,
                        match=Match([("ETH_TYPE", 0x0800, None),
                                     ("IPV4_SRC", 1, None),
                                     ("VLAN_VID", 0x1100, None)]),
                        instructions=expected_insts)

        handcrafted = (
            "priority=789 cookie=0xABCD table=3 eth_type=0x800,ip_src=0.0.0.1,vlan_vid=0x1100 actions=pop_vlan,set_field:10:10:10:10:10:10->eth_dst,output:7,goto_table:4"
        )

        # After going in and out of OVS, ovs-ofctl -O OpenFlowXX dumpflows br0
        ofctl10 = " cookie=0xabcd, duration=30.907s, table=3, n_packets=0, n_bytes=0, priority=789,ip,dl_vlan=256,nw_src=0.0.0.1 actions=strip_vlan,mod_dl_dst:10:10:10:10:10:10,output:7,resubmit(,4)"
        ofctl13 = " cookie=0xabcd, duration=24.104s, table=3, n_packets=0, n_bytes=0, priority=789,ip,dl_vlan=256,nw_src=0.0.0.1 actions=pop_vlan,set_field:10:10:10:10:10:10->eth_dst,output:7,goto_table:4"
        ofctl13_nostats = " cookie=0xabcd, table=3, priority=789,ip,dl_vlan=256,nw_src=0.0.0.1 actions=pop_vlan,set_field:10:10:10:10:10:10->eth_dst,output:7,goto_table:4"
        ofctl15 = " cookie=0xabcd, duration=28.969s, table=3, n_packets=0, n_bytes=0, idle_age=28, priority=789,ip,dl_vlan=256,nw_src=0.0.0.1 actions=pop_vlan,set_field:10:10:10:10:10:10->eth_dst,output:7,goto_table:4"
        # From ovs-appctl bridge/dumpflows
        appctl = "table_id=3, duration=51s, n_packets=0, n_bytes=0, priority=789,ip,dl_vlan=256,nw_src=0.0.0.1,actions=pop_vlan,set_field:10:10:10:10:10:10->eth_dst,output:7,goto_table:4"

        rule_hand = rule_from_ovs(handcrafted, {})
        rule_10 = rule_from_ovs(ofctl10, {})
        rule_13 = rule_from_ovs(ofctl13, {})
        rule_13nostats = rule_from_ovs(ofctl13_nostats, {})
        rule_15 = rule_from_ovs(ofctl15, {})
        rule_appctl = rule_from_ovs(appctl, {})

        self.assertEqual(rule_hand, expected)
        self.assertEqual(rule_10, expected)
        self.assertEqual(rule_13, expected)
        self.assertEqual(rule_13nostats, expected)
        self.assertEqual(rule_15, expected)

        # appctl output doesn't display cookies
        expected.cookie = None
        self.assertEqual(rule_appctl, expected)
Exemplo n.º 2
0
    def test_convert_flow2(self):
        """ Test converting OFPFlowMod and OFPFlowStats from ovs """

        match = Match([("IPV4_SRC", 1, None), ("ETH_TYPE", 0x800, None),
                       ("VLAN_VID", 0x1100, None)])
        instructions = Instructions()
        instructions.goto_table = 9
        instructions.clear_actions = True
        instructions.write_actions.append("POP_VLAN", None)
        instructions.write_actions.append("SET_FIELD",
                                          ("ETH_DST", 0x101010101010))
        instructions.write_actions.append("OUTPUT", 7)
        instructions.write_metadata = (0x99, 0xff)

        expected = Rule(priority=0x8000,
                        cookie=0xABCD,
                        table=0,
                        match=match,
                        instructions=instructions)

        # Now for write actions and clear actions etc.
        # Note priority=0x8000 is the default priority and ovs omits it,
        # Similarly table 0 is often omitted
        handcrafted = (
            "priority=0x8000 cookie=0xABCD table=0 eth_type=0x800,ip_src=0.0.0.1,vlan_vid=0x1100 actions=clear_actions,write_actions(pop_vlan,set_field:10:10:10:10:10:10->eth_dst,output:7),write_metadata:0x99/0xff,goto_table:9"
        )

        ofctl11 = " cookie=0xabcd, duration=10.778s, table=0, n_packets=0, n_bytes=0, ip,dl_vlan=256,nw_src=0.0.0.1 actions=clear_actions,write_actions(pop_vlan,mod_dl_dst:10:10:10:10:10:10,output:7),write_metadata:0x99/0xff,goto_table:9"
        # Also the same for of12 to of15
        ofctl13 = " cookie=0xabcd, duration=24.097s, table=0, n_packets=0, n_bytes=0, ip,dl_vlan=256,nw_src=0.0.0.1 actions=clear_actions,write_actions(pop_vlan,set_field:10:10:10:10:10:10->eth_dst,output:7),write_metadata:0x99/0xff,goto_table:9"
        # From ovs-appctl bridge/dumpflows
        appctl = "duration=369s, n_packets=0, n_bytes=0, ip,dl_vlan=256,nw_src=0.0.0.1,actions=clear_actions,write_actions(pop_vlan,set_field:10:10:10:10:10:10->eth_dst,output:7),write_metadata:0x99/0xff,goto_table:9"

        rule_hand = rule_from_ovs(handcrafted, {})
        rule_11 = rule_from_ovs(ofctl11, {})
        rule_13 = rule_from_ovs(ofctl13, {})
        rule_appctl = rule_from_ovs(appctl, {})

        self.assertEqual(rule_hand, expected)
        self.assertEqual(rule_11, expected)
        self.assertEqual(rule_13, expected)

        # appctl output doesn't display cookies
        expected.cookie = None
        self.assertEqual(rule_appctl, expected)