예제 #1
0
 def test_apply_global_cookie_modifiers(self):
     cookies.add_global_cookie_modifier('t1', 4, lambda x: 6)
     cookies.add_global_cookie_modifier('t2', 3, lambda x: 3)
     cookie, mask = cookies.apply_global_cookie_modifiers(
         2 << 32, 3 << 32, None)
     self.assertEqual(2 << 32 | 3 << 4 | 6, cookie)
     self.assertEqual(0x3 << 32 | 0x7 << 4 | 0xf, mask)
예제 #2
0
    def mod_flow(self,
                 datapath=None,
                 cookie=0,
                 cookie_mask=0,
                 table_id=0,
                 command=None,
                 idle_timeout=0,
                 hard_timeout=0,
                 priority=0xff,
                 buffer_id=0xffffffff,
                 match=None,
                 actions=None,
                 inst_type=None,
                 out_port=None,
                 out_group=None,
                 flags=0,
                 inst=None):

        if datapath is None:
            datapath = self.datapath

        if command is None:
            command = datapath.ofproto.OFPFC_ADD

        if inst is None:
            if inst_type is None:
                inst_type = datapath.ofproto.OFPIT_APPLY_ACTIONS

            inst = []
            if actions is not None:
                inst = [
                    datapath.ofproto_parser.OFPInstructionActions(
                        inst_type, actions)
                ]

        if out_port is None:
            out_port = datapath.ofproto.OFPP_ANY

        if out_group is None:
            out_group = datapath.ofproto.OFPG_ANY

        cookie, cookie_mask = cookies.apply_global_cookie_modifiers(
            cookie, cookie_mask, self)

        message = datapath.ofproto_parser.OFPFlowMod(
            datapath, cookie, cookie_mask, table_id, command, idle_timeout,
            hard_timeout, priority, buffer_id, out_port, out_group, flags,
            match, inst)

        datapath.send_msg(message)