Example #1
0
 def runTest(self):
     msg = message.flow_stats_entry()
     match = ofp.ofp_match()
     match.wildcards &= ~ofp.OFPFW_IN_PORT
     act = action.action_output()
     act.port = 3
     msg.match = match
     pkt = msg.pack()
     self.assertEqual(len(pkt), 136)
     inst = instruction.instruction_apply_actions()
     self.assertTrue(inst.actions.add(act), "Could not add action")
     self.assertTrue(msg.instructions.add(inst), "Could not add instructions")
     #self.assertTrue(msg.actions.add(act), "Could not add action")
     pkt = msg.pack()
     # 160 = 136 for flow_stats_entry and 24 for instruction_list
     self.assertEqual(len(pkt), 160)
     rep = message.flow_stats_reply()
     self.assertEqual(len(rep.pack()),12)
     rep.stats.append(msg)
     self.assertEqual(len(rep.pack()),172)
Example #2
0
    def flow_stat_get(self):
        """
        Create a single flow_stat object representing this flow entry
        
        NOTE: the table_id is left blank and needs to be filled in by calling function
        (FlowEntries have no idea which table they're in)

        @todo Check if things like match and instructions should be copies
        """
        stat = message.flow_stats_entry()
        delta = time.time() - self.insert_time
        stat.duration_sec = int(delta)
        # need the extra int() line here because python time might have
        # higher precision
        stat.duration_nsec = int((delta - stat.duration_sec) * 1e9)
        stat.priority = self.flow_mod.priority
        stat.idle_timeout = self.flow_mod.idle_timeout
        stat.hard_timeout = self.flow_mod.hard_timeout
        stat.cookie = self.flow_mod.cookie
        stat.packet_count = self.packets
        stat.byte_count = self.bytes
        stat.match = self.flow_mod.match
        stat.instructions = self.flow_mod.instructions
        return stat