Esempio n. 1
0
    def runTest(self):
        logging.info("")
        flow_stats = get_flow_stats(self, ofp.match())
        in_port, out_port = openflow_ports(2)
        # Clear Switch State
        delete_all_flows(self.controller)

        flow_entry_num = 10
        table_num = 5
        for i in range(table_num):
            for j in range(flow_entry_num):
                FuncUtils.flow_entry_install(
                    self.controller,
                    "flow_add",
                    table_id=i,
                    match=ofp.match([ofp.oxm.in_port(in_port)]),
                    instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])],
                    prio=j,
                )
        # test
        request = ofp.message.table_stats_request()
        (reply, pkt) = self.controller.transact(request)

        active_entry = 0
        for obj in reply.entries:
            active_entry += obj.active_count
        self.assertEqual(flow_entry_num * table_num, active_entry, "Active entry error")
Esempio n. 2
0
    def runTest(self):
        logging.info("Running Forward_Table test")

        # delete all entries
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)
        # add flow
        FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(out_port)])
            ])
        # Create a packet out message
        pkt = str(simple_tcp_packet())
        pkt_out = ofp.message.packet_out()
        pkt_out.data = pkt
        pkt_out.in_port = in_port
        pkt_out.buffer_id = ofp.OFP_NO_BUFFER
        act = ofp.action.output()
        act.port = ofp.OFPP_TABLE
        pkt_out.actions.append(act)
        self.controller.message_send(pkt_out)

        # Verifying packet out message recieved on the expected dataplane port.
        verify_packets(self, pkt, [out_port])
Esempio n. 3
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)

        # flow add
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])],
                                     hard_timeout=1,
                                     flags=ofp.OFPFF_SEND_FLOW_REM
                                     )
        # send packet to in_port and verify
        start_time = time.time()
        dura_time = 6
        while True:
            if time.time() - start_time > dura_time:
                break
            pkt = str(simple_tcp_packet())
            self.dataplane.send(in_port, pkt)
        time.sleep(5)

        msg, _ = self.controller.poll(ofp.message.flow_removed)
        self.assertTrue(msg is not None, "Error message was not received")
        self.assertEqual(msg.duration_sec, 1, "Time is not correct")
Esempio n. 4
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port1, out_port2 = openflow_ports(3)

        # flow add
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port1)])],
                                     prio = 10
                                     )
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port2)])],
                                     prio = 11
                                     )
        # send packet to in_port and verify
        flow_stats = get_flow_stats(self, ofp.match())
        self.assertEqual(len(flow_stats), 2)

        pkt = str(simple_tcp_packet())
        self.dataplane.send(in_port, pkt)
        verify_packets(self, pkt, [out_port2])
        verify_no_packet(self, pkt, out_port1)
Esempio n. 5
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)

        FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(out_port)])
            ])
        # test
        delete_all_flows(self.controller)
        error_msg, _ = self.controller.poll(ofp.message.flow_removed)
        self.assertTrue(error_msg is None, "Error message was received")

        FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(out_port)])
            ],
            flags=ofp.OFPFF_SEND_FLOW_REM)
        # test
        delete_all_flows(self.controller)
        error_msg, _ = self.controller.poll(ofp.message.flow_removed)
        self.assertTrue(error_msg is not None,
                        "Error message was not received")
Esempio n. 6
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port1, out_port2 = openflow_ports(3)

        # flow add
        FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(out_port1)])
            ],
            prio=10)
        FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(out_port2)])
            ],
            prio=11)
        # send packet to in_port and verify
        flow_stats = get_flow_stats(self, ofp.match())
        self.assertEqual(len(flow_stats), 2)

        pkt = str(simple_tcp_packet())
        self.dataplane.send(in_port, pkt)
        verify_packets(self, pkt, [out_port2])
        verify_no_packet(self, pkt, out_port1)
Esempio n. 7
0
    def runTest(self):
        delete_all_flows(self.controller)

        logging.info(
            "Inserting flow: flow-mod cmd=add,table=0,prio=15 in_port=1 apply:output=2"
        )
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(2)]),
                                     instructions=[
                                         ofp.instruction.apply_actions(
                                             [ofp.action.output(1)]),
                                     ])

        logging.info(
            "Inserting flow:  flow-mod cmd=add,table=0,prio=15,flags=0x2 apply:output=1"
        )
        FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(2)]),
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(1)]),
            ],
            flags=ofp.OFPFF_CHECK_OVERLAP,
        )

        # Verify the correct error message is returned
        response, _ = self.controller.poll(
            exp_msg=ofp.message.flow_mod_failed_error_msg)
        self.assertTrue(response is not None,
                        "No Flow Mod Failed Error message was received")
        self.assertEqual(response.code, ofp.OFPFMFC_OVERLAP,
                         "Error message error code is not OFPFMFC_OVERLAP")
Esempio n. 8
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port1, out_port2 = openflow_ports(3)

        # flow add
        FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(out_port1)])
            ],
            hard_timeout=1,
        )
        FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(out_port2)])
            ],
            hard_timeout=100)
        # tests
        time.sleep(5)
        stats = get_flow_stats(self, ofp.match())
        self.assertEqual(len(stats), 1, "Expected empty flow stats reply")
Esempio n. 9
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)

        # flow add
        FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(out_port)])
            ],
            hard_timeout=1,
            flags=ofp.OFPFF_SEND_FLOW_REM)
        # send packet to in_port and verify
        start_time = time.time()
        dura_time = 6
        while True:
            if time.time() - start_time > dura_time:
                break
            pkt = str(simple_tcp_packet())
            self.dataplane.send(in_port, pkt)
        time.sleep(5)

        msg, _ = self.controller.poll(ofp.message.flow_removed)
        self.assertTrue(msg is not None, "Error message was not received")
        self.assertEqual(msg.duration_sec, 1, "Time is not correct")
Esempio n. 10
0
    def runTest(self):
        in_port = openflow_ports(1)[0]
        pkt = str(simple_tcp_packet())

        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     instructions=[
                                         ofp.instruction.apply_actions([
                                             ofp.action.output(
                                                 port=ofp.OFPP_CONTROLLER,
                                                 max_len=2000)
                                         ])
                                     ])

        pkt = str(simple_tcp_packet())
        self.dataplane.send(in_port, pkt)
        response, _ = self.controller.poll(ofp.message.packet_in)

        msg = ofp.message.packet_out(in_port=ofp.OFPP_CONTROLLER,
                                     actions=[ofp.action.output(port=in_port)],
                                     buffer_id=response.buffer_id,
                                     data=pkt)
        self.controller.message_send(msg)

        response, _ = self.controller.poll(ofp.message.bad_request_error_msg)
        self.assertEqual(
            response.code, ofp.OFPBRC_BUFFER_EMPTY,
            "Error message error code is not OFPBRC_BUFFER_EMPTY")
Esempio n. 11
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)
        request1 = FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(out_port)])
            ])

        request2 = FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(out_port)])
            ])

        # Verify the correct error message is returned
        response, _ = self.controller.poll(
            exp_msg=ofp.message.flow_mod_failed_error_msg)
        self.assertTrue(response is None,
                        "Flow Mod Failed Error message was received")

        # read flow entries to ensure the new entry is inserted
        flow_stats = get_flow_stats(self, ofp.match())
        self.assertEqual(len(flow_stats), 2)
        self.assertTrue(request1.instructions, flow_stats[0].instructions)
        self.assertTrue(request2.instructions, flow_stats[1].instructions)
Esempio n. 12
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port1, out_port2 = openflow_ports(3)

        request = FuncUtils.flow_entry_install(self.controller,
                                               "flow_add",
                                               match=ofp.match([ofp.oxm.in_port(in_port)]),
                                               instructions=[
                                                   ofp.instruction.apply_actions([ofp.action.output(out_port1)])
                                               ])

        pkg_num = 10
        FuncUtils.send_packets(self, simple_icmp_packet(), in_port, pkg_num)

        FuncUtils.flow_entry_install(self.controller,
                                     "flow_mods",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     instructions=[
                                         ofp.instruction.apply_actions([ofp.action.output(out_port2)])
                                     ])

        # verify flow entry pkg num
        flow_stats = get_flow_stats(self, ofp.match())
        self.assertEqual(len(flow_stats), 1)
        verify_flow_stats(self, request.match, pkts=pkg_num)
Esempio n. 13
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)

        # flow add
        FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(out_port)])
            ],
        )
        pkt = str(simple_tcp_packet())
        self.dataplane.send(in_port, pkt)
        verify_packets(self, pkt, [out_port])
        # flow del
        FuncUtils.flow_entry_install(
            self.controller,
            "flow_del",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
        )
        # verify the num of flow entry is 0
        flow_stats = get_flow_stats(self, ofp.match())
        self.assertEqual(len(flow_stats), 0)
        self.dataplane.send(in_port, pkt)
        verify_packets(self, pkt, [])
Esempio n. 14
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)

        FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(out_port)])
            ])

        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     instructions=[
                                         ofp.instruction.apply_actions(
                                             [ofp.action.output(out_port)])
                                     ],
                                     flags=ofp.OFPFF_CHECK_OVERLAP)

        # Verify the correct error message is returned
        response, _ = self.controller.poll(
            exp_msg=ofp.message.flow_mod_failed_error_msg)
        self.assertTrue(response is not None,
                        "No Flow Mod Failed Error message was received")
Esempio n. 15
0
    def runTest(self):
        in_port = openflow_ports(1)[0]
        pkt = str(simple_tcp_packet())

        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     instructions=[ofp.instruction.apply_actions(
                                         [ofp.action.output(
                                             port=ofp.OFPP_CONTROLLER,
                                             max_len=2000
                                         )])])

        pkt = str(simple_tcp_packet())
        self.dataplane.send(in_port, pkt)
        response, _ = self.controller.poll(ofp.message.packet_in)

        msg = ofp.message.packet_out(
            in_port=ofp.OFPP_CONTROLLER,
            actions=[ofp.action.output(port=in_port)],
            buffer_id=response.buffer_id,
            data=pkt)
        self.controller.message_send(msg)

        response, _ = self.controller.poll(ofp.message.bad_request_error_msg)
        self.assertEqual(response.code, ofp.OFPBRC_BUFFER_EMPTY,
                         "Error message error code is not OFPBRC_BUFFER_EMPTY")
Esempio n. 16
0
    def runTest(self):
        delete_all_flows(self.controller)

        # config
        in_port, out_port = openflow_ports(2)
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     instructions=[ofp.instruction.apply_actions(
                                         [ofp.action.output(
                                             port=ofp.OFPP_CONTROLLER,
                                             max_len=1000
                                         )])])
        # test
        request = ofp.message.get_config_request()
        response, _ = self.controller.transact(request)
        print(response.show() + "num=" + str(response.miss_send_len))

        pkt = str(simple_tcp_packet(pktlen=80, ip_ttl=1))
        self.dataplane.send(in_port, pkt)
        response, _ = self.controller.poll(ofp.message.packet_in)
        self.assertTrue(response is not None, "No packetin received")
        logging.info(response.show())
        logging.info(len(response.data))

        self.assertEqual(response.reason, ofp.OFPR_NO_MATCH,
                         "Packetin reason field is not NO_MATCH")
Esempio n. 17
0
    def runTest(self):
        delete_all_flows(self.controller)

        logging.info("Inserting flow: flow-mod cmd=add,table=0,prio=15 in_port=1 apply:output=2")
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(2)]),
                                     instructions=[
                                         ofp.instruction.apply_actions([ofp.action.output(1)]),
                                     ])

        logging.info("Inserting flow:  flow-mod cmd=add,table=0,prio=15,flags=0x2 apply:output=1")
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(2)]),
                                     instructions=[
                                         ofp.instruction.apply_actions([ofp.action.output(1)]),
                                     ],
                                     flags=ofp.OFPFF_CHECK_OVERLAP, )

        # Verify the correct error message is returned
        response, _ = self.controller.poll(exp_msg=ofp.message.flow_mod_failed_error_msg)
        self.assertTrue(response is not None,
                        "No Flow Mod Failed Error message was received")
        self.assertEqual(response.code, ofp.OFPFMFC_OVERLAP,
                         "Error message error code is not OFPFMFC_OVERLAP")
Esempio n. 18
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port1, out_port2 = openflow_ports(3)

        request = FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(out_port1)])
            ])

        pkg_num = 10
        FuncUtils.send_packets(self, simple_icmp_packet(), in_port, pkg_num)

        FuncUtils.flow_entry_install(
            self.controller,
            "flow_mods",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(out_port2)])
            ])

        # verify flow entry pkg num
        flow_stats = get_flow_stats(self, ofp.match())
        self.assertEqual(len(flow_stats), 1)
        verify_flow_stats(self, request.match, pkts=pkg_num)
Esempio n. 19
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)

        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     instructions=[
                                         ofp.instruction.apply_actions([ofp.action.output(out_port)])
                                     ])
        # test
        delete_all_flows(self.controller)
        error_msg, _ = self.controller.poll(ofp.message.flow_removed)
        self.assertTrue(error_msg is None, "Error message was received")

        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     instructions=[
                                         ofp.instruction.apply_actions([ofp.action.output(out_port)])
                                     ],
                                     flags=ofp.OFPFF_SEND_FLOW_REM)
        # test
        delete_all_flows(self.controller)
        error_msg, _ = self.controller.poll(ofp.message.flow_removed)
        self.assertTrue(error_msg is not None, "Error message was not received")
Esempio n. 20
0
 def runTest(self):
     FuncUtils.flow_entry_install(self.controller,
                                  "flow_add",
                                  instructions=[ofp.instruction.apply_actions(
                                      [ofp.action.push_vlan(ethertype=0x0081)])])
     response, _ = self.controller.poll(ofp.message.bad_action_error_msg)
     self.assertTrue(response is not None,
                     "No Error message was received")
     self.assertEqual(response.code, ofp.OFPBAC_BAD_ARGUMENT,
                      "Error message error code is not OFPBAC_BAD_ARGUMENT")
Esempio n. 21
0
def exec_query_operation(operation, epsilon, budget, lower, upper):
    os.chdir(Const.ROOT_PATH + Const.DIFF_PRIV_MASTER_PATH)
    try:
        subprocess.check_output(['%s %s%s:priv_%s -- %f %f %f %f' % (Const.BAZEL_RUN, Const.DIFF_PRIV_PATH,
                                                                     Const.OPERATIONS_PATH, operation, epsilon, budget,
                                                                     lower, upper)], shell=True, stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError:
        # Execution failed
        os.chdir(Const.PARENT_DIR)
        fu.log(fu.get_current_time() + Const.NO_RESULT[0] + '\n')
        return Const.NO_RESULT
    os.chdir(Const.PARENT_DIR)
    if os.path.exists(Const.RESULT_PATH):
        data = pd.read_csv(Const.RESULT_PATH, header=None)
        # Extract results
        true_value = str(data[0].values[0])
        anon_value = str(data[1].values[0])
        fu.log(fu.get_current_time() + 'Result of ' + operation + ' has true value = ' + true_value +
               ' and anonymized value = ' + anon_value + '\n')
        # Remove result file
        os.remove(Const.RESULT_PATH)
        return anon_value, Const.OK
    # Execution failed
    fu.log(fu.get_current_time() + Const.NO_RESULT[0] + '\n')
    return Const.NO_RESULT
Esempio n. 22
0
 def runTest(self):
     action = ofp.action.output(port=ofp.OFPP_CONTROLLER,
                                max_len=ofp.OFPCML_NO_BUFFER)
     action.type = 100
     FuncUtils.flow_entry_install(
         self.controller,
         "flow_add",
         instructions=[ofp.instruction.apply_actions([action])])
     response, _ = self.controller.poll(ofp.message.bad_action_error_msg)
     self.assertTrue(response is not None, "No Error message was received")
     self.assertEqual(response.code, ofp.OFPBAC_BAD_TYPE,
                      "Error message error code is not OFPBRC_BAD_TYPE")
Esempio n. 23
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)

        # add flow
        FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])],
        )
        stat = get_port_stats(self, in_port)[0]
        self.assertTrue(stat.rx_dropped is not None, "No rx_dropped field")
Esempio n. 24
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)

        FuncUtils.flow_entry_install(self.controller,
                                     "flow_del",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     instructions=[
                                         ofp.instruction.apply_actions([ofp.action.output(out_port)])
                                     ])
        # test
        error_msg, _ = self.controller.poll(ofp.OFPT_ERROR)
        self.assertTrue(error_msg is None, "Error message was received")
Esempio n. 25
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)

        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     instructions=[
                                         ofp.instruction.apply_actions([ofp.action.output(ofp.OFPP_IN_PORT)])])
        # send packets
        pkt = str(simple_tcp_packet())
        self.dataplane.send(in_port, pkt)
        verify_packets(self, pkt, [in_port])
Esempio n. 26
0
 def runTest(self):
     FuncUtils.flow_entry_install(
         self.controller,
         "flow_add",
         instructions=[
             ofp.instruction.apply_actions(
                 [ofp.action.push_vlan(ethertype=0x0081)])
         ])
     response, _ = self.controller.poll(ofp.message.bad_action_error_msg)
     self.assertTrue(response is not None, "No Error message was received")
     self.assertEqual(
         response.code, ofp.OFPBAC_BAD_ARGUMENT,
         "Error message error code is not OFPBAC_BAD_ARGUMENT")
Esempio n. 27
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)

        # flow add and delete
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])],
                                     prio=15)
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_del",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     )
        # flow add and delete strict
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])],
                                     prio=125)
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_dels",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     prio=125)

        # verify the num of flow entry is 0
        flow_stats = get_flow_stats(self, ofp.match())
        self.assertEqual(len(flow_stats), 0)
Esempio n. 28
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)

        FuncUtils.flow_entry_install(
            self.controller,
            "flow_del",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(out_port)])
            ])
        # test
        error_msg, _ = self.controller.poll(ofp.OFPT_ERROR)
        self.assertTrue(error_msg is None, "Error message was received")
 def post(self):
     """
     Store sent file
     :return: Success or fail
     """
     # Get file from request content
     fin = request.files[Const.FILE + '[0]']
     file_name = str(fin).split('\'')[1].split('\'')[0]
     fu.log(fu.get_current_time() + '[' + Const.SEND_CSV + ' ' +
            request.method + '] Received request to store csv file:' +
            file_name + '\n')
     # Store file
     result = csvh.add_file(fin, file_name)
     return result[0], result[1]
Esempio n. 30
0
 def runTest(self):
     action = ofp.action.output(
         port=ofp.OFPP_CONTROLLER,
         max_len=ofp.OFPCML_NO_BUFFER
     )
     action.type = 100
     FuncUtils.flow_entry_install(self.controller,
                                  "flow_add",
                                  instructions=[ofp.instruction.apply_actions(
                                      [action])])
     response, _ = self.controller.poll(ofp.message.bad_action_error_msg)
     self.assertTrue(response is not None,
                     "No Error message was received")
     self.assertEqual(response.code, ofp.OFPBAC_BAD_TYPE,
                      "Error message error code is not OFPBRC_BAD_TYPE")
Esempio n. 31
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)

        request = FuncUtils.flow_entry_install(self.controller,
                                               "flow_add",
                                               match=ofp.match([ofp.oxm.in_port(in_port)]),
                                               instructions=[
                                                   ofp.instruction.apply_actions([ofp.action.output(out_port)])])
        # send matching packets
        pkt = str(simple_icmp_packet())
        times = 10
        for i in range(times):
            self.dataplane.send(in_port, pkt)

        # send same flow into the table to reset counters
        self.controller.message_send(request)

        # check result
        flow_stats = get_flow_stats(self, ofp.match())
        for entry in flow_stats:
            logging.debug(entry.show())

        self.assertEqual(len(flow_stats), 1)
        self.assertEqual(flow_stats[0].packet_count, 0)
Esempio n. 32
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)

        FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[
                ofp.instruction.apply_actions(
                    [ofp.action.output(ofp.OFPP_IN_PORT)])
            ])
        # send packets
        pkt = str(simple_tcp_packet())
        self.dataplane.send(in_port, pkt)
        verify_packets(self, pkt, [in_port])
Esempio n. 33
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)

        request = FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(out_port)])
            ])
        # send matching packets
        pkt = str(simple_icmp_packet())
        times = 10
        for i in range(times):
            self.dataplane.send(in_port, pkt)

        # send same flow into the table to reset counters
        self.controller.message_send(request)

        # check result
        flow_stats = get_flow_stats(self, ofp.match())
        for entry in flow_stats:
            logging.debug(entry.show())

        self.assertEqual(len(flow_stats), 1)
        self.assertEqual(flow_stats[0].packet_count, 0)
Esempio n. 34
0
    def runTest(self):
        delete_all_flows(self.controller)

        # config
        in_port, out_port = openflow_ports(2)
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     instructions=[ofp.instruction.apply_actions(
                                         [ofp.action.output(
                                             port=ofp.OFPP_CONTROLLER,
                                             max_len=ofp.OFPCML_NO_BUFFER
                                         )])])
        # test
        pkt = str(simple_tcp_packet(pktlen=70))
        self.dataplane.send(in_port, pkt)
        verify_packet_in(self, pkt, in_port, ofp.OFPR_NO_MATCH)
Esempio n. 35
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)

        for i in range(65539):
            FuncUtils.flow_entry_install(self.controller,
                                         "flow_add",
                                         match=ofp.match([ofp.oxm.in_port(in_port)]),
                                         instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])],
                                         prio=i)
            # read error message
            response, _ = self.controller.poll(ofp.message.flow_mod_failed_error_msg, 0.00001)

            if response is not None and (response.code == ofp.OFPFMFC_TABLE_FULL):
                return
        self.assertTrue(False, "No error message was received")
 def post(self):
     """
     Try to execute the given query
     :return: A float number representing the query result or an error message
     """
     # Decrypt data received from Cloud Provider
     content = request.get_json()
     user_id = content[Const.ID]
     file_name = content[Const.FILE]
     query = content[Const.QUERY]
     epsilon = float(content[Const.EPSILON])
     fu.log(fu.get_current_time() + '[' + Const.QUERY + ' ' +
            request.method + '] Received from ' + user_id +
            ' request for query:' + query + ' from ' + file_name +
            ' with epsilon = ' + str(epsilon) + '\n')
     result = qh.check_query(user_id, file_name, query, epsilon)
     return result[0], result[1]
Esempio n. 37
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)
        # add flow
        FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])],
        )
        # test
        pkt_num = 10
        pkt = str(simple_tcp_packet())
        for i in range(pkt_num):
            self.dataplane.send(in_port, pkt)

        verify_port_stats(self, out_port, tx_bytes=pkt_num * len(pkt))
Esempio n. 38
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)

        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])])

        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])],
                                     flags=ofp.OFPFF_CHECK_OVERLAP)

        # Verify the correct error message is returned
        response, _ = self.controller.poll(exp_msg=ofp.message.flow_mod_failed_error_msg)
        self.assertTrue(response is not None,
                        "No Flow Mod Failed Error message was received")
Esempio n. 39
0
    def runTest(self):
        logging.info("TestCase 70.30: Forward: Controller")
        # delete all entries
        delete_all_flows(self.controller)

        in_port, out_port = openflow_ports(2)
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     instructions=[ofp.instruction.apply_actions(
                                         [ofp.action.output(
                                             port=ofp.OFPP_CONTROLLER,
                                             max_len=ofp.OFPCML_NO_BUFFER
                                         )])])

        pkt = str(simple_tcp_packet())
        self.dataplane.send(in_port, pkt)
        verify_packet_in(self, pkt, in_port, ofp.OFPR_ACTION)
Esempio n. 40
0
    def runTest(self):
        delete_all_flows(self.controller)

        # config
        in_port, out_port1, out_port2, out_port3 = openflow_ports(4)
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     instructions=[ofp.instruction.apply_actions(
                                         [ofp.action.output(ofp.OFPP_ALL)])]
                                     )

        # tests
        pkt = str(simple_tcp_packet())
        self.dataplane.send(in_port, pkt)

        verify_no_packet(self, pkt, in_port)
        verify_packets(self, pkt, [out_port1, out_port2, out_port3])
Esempio n. 41
0
    def verify_modify(self, actions, pkt, exp_pkt):
        in_port, out_port = openflow_ports(2)

        actions = actions + [ofp.action.output(out_port)]

        logging.info("Running actions test for %s", pp(actions))

        delete_all_flows(self.controller)

        logging.info("Inserting flow")
        FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=packet_to_flow_match(self, pkt),
            instructions=[ofp.instruction.apply_actions(actions)])

        logging.info("Sending packet, expecting output to port %d", out_port)
        self.dataplane.send(in_port, str(pkt))
        verify_packets(self, str(exp_pkt), [out_port])
Esempio n. 42
0
    def runTest(self):
        delete_all_flows(self.controller)

        # config
        in_port, out_port = openflow_ports(2)
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     instructions=[ofp.instruction.apply_actions(
                                         [ofp.action.output(
                                             port=ofp.OFPP_CONTROLLER,
                                             max_len=ofp.OFPCML_NO_BUFFER
                                         )])])
        # test
        pkt = str(simple_tcp_packet())
        self.dataplane.send(in_port, pkt)
        response, _ = self.controller.poll(ofp.message.packet_in)
        self.assertTrue(response is not None, "No packetin received")
        self.assertEqual(response.reason, ofp.OFPR_NO_MATCH,
                         "Packetin reason field is not NO_MATCH")
Esempio n. 43
0
    def runTest(self):
        delete_all_flows(self.controller)

        # search unavalible port
        for port_nonvalid in range(1000):
            FuncUtils.flow_entry_install(self.controller,
                                         "flow_add",
                                         instructions=[
                                             ofp.instruction.apply_actions([ofp.action.output(port_nonvalid)])
                                         ])
            _, port_config, _ = port_config_get(self.controller, port_nonvalid)
            if port_config is None:
                break

        # read error message
        response, _ = self.controller.poll(ofp.message.bad_action_error_msg)
        self.assertTrue(response is not None,
                        "No error message was received")
        self.assertEqual(response.code, ofp.OFPBAC_BAD_OUT_PORT)
Esempio n. 44
0
    def verify_modify(self, actions, pkt, exp_pkt):
        in_port, out_port = openflow_ports(2)

        actions = actions + [ofp.action.output(out_port)]

        logging.info("Running actions test for %s", pp(actions))

        delete_all_flows(self.controller)

        logging.info("Inserting flow")
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=packet_to_flow_match(self, pkt),
                                     instructions=[ofp.instruction.apply_actions(actions)]
                                     )

        logging.info("Sending packet, expecting output to port %d", out_port)
        self.dataplane.send(in_port, str(pkt))
        verify_packets(self, str(exp_pkt), [out_port])
Esempio n. 45
0
    def runTest(self):
        delete_all_flows(self.controller)

        # search unavalible port
        for port_nonvalid in range(1000):
            FuncUtils.flow_entry_install(
                self.controller,
                "flow_add",
                instructions=[
                    ofp.instruction.apply_actions(
                        [ofp.action.output(port_nonvalid)])
                ])
            _, port_config, _ = port_config_get(self.controller, port_nonvalid)
            if port_config is None:
                break

        # read error message
        response, _ = self.controller.poll(ofp.message.bad_action_error_msg)
        self.assertTrue(response is not None, "No error message was received")
        self.assertEqual(response.code, ofp.OFPBAC_BAD_OUT_PORT)
Esempio n. 46
0
    def runTest(self):
        delete_all_flows(self.controller)

        # config
        in_port, out_port1, out_port2, out_port3 = openflow_ports(4)
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match(
                                         [ofp.oxm.in_port(in_port)]),
                                     instructions=[
                                         ofp.instruction.apply_actions(
                                             [ofp.action.output(ofp.OFPP_ALL)])
                                     ])

        # tests
        pkt = str(simple_tcp_packet())
        self.dataplane.send(in_port, pkt)

        verify_no_packet(self, pkt, in_port)
        verify_packets(self, pkt, [out_port1, out_port2, out_port3])
Esempio n. 47
0
    def runTest(self):
        logging.info("TestCase 70.30: Forward: Controller")
        # delete all entries
        delete_all_flows(self.controller)

        in_port, out_port = openflow_ports(2)
        FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[
                ofp.instruction.apply_actions([
                    ofp.action.output(port=ofp.OFPP_CONTROLLER,
                                      max_len=ofp.OFPCML_NO_BUFFER)
                ])
            ])

        pkt = str(simple_tcp_packet())
        self.dataplane.send(in_port, pkt)
        verify_packet_in(self, pkt, in_port, ofp.OFPR_ACTION)
Esempio n. 48
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port1, out_port2 = openflow_ports(3)

        # flow add
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port1)])],
                                     hard_timeout=1,
                                     )
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port2)])],
                                     hard_timeout=100
                                     )
        # tests
        time.sleep(5)
        stats = get_flow_stats(self, ofp.match())
        self.assertEqual(len(stats), 1, "Expected empty flow stats reply")
Esempio n. 49
0
    def runTest(self):
        delete_all_flows(self.controller)

        # config
        in_port, out_port = openflow_ports(2)
        max_len = 100
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     instructions=[ofp.instruction.apply_actions(
                                         [ofp.action.output(
                                             port=ofp.OFPP_CONTROLLER,
                                             max_len=ofp.OFPCML_NO_BUFFER
                                         )])])
        # test
        pkt = str(simple_tcp_packet(pktlen=0))
        self.dataplane.send(in_port, pkt)

        response, _ = self.controller.poll(ofp.message.packet_in)
        logging.info(response.show())
        self.assertTrue(response is not None, "No packetin received")
Esempio n. 50
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)

        # flow T0 add
        FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(out_port)])
            ])

        # flow T1 add
        FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([
                ofp.oxm.in_port(in_port),
                ofp.oxm.eth_dst([0x00, 0x13, 0x3b, 0x0f, 0x42, 0x1c])
            ]),
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(out_port)])
            ])
        # flow del
        FuncUtils.flow_entry_install(
            self.controller,
            "flow_dels",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
        )

        # verify the num of flow entry is 1
        flow_stats = get_flow_stats(self, ofp.match())
        self.assertEqual(len(flow_stats), 1)
Esempio n. 51
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port1, out_port2 = openflow_ports(3)

        # flow add
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port1)])],
                                     prio=15
                                     )
        # flow add
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port2)])],
                                     prio=14
                                     )
        # check
        flow_stats = get_flow_stats(self, ofp.match())
        self.assertEqual(len(flow_stats), 2, "Flow was not inserted correctly")
        # flow del
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_del",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     prio=15,
                                     out_port=out_port1
                                     )
        # verify the num of flow entry is 1 and matching entry is removed
        flow_stats = get_flow_stats(self, ofp.match())
        self.assertEqual(len(flow_stats), 1, len(flow_stats))
Esempio n. 52
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)

        # flow add
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])],
                                     prio=15
                                     )
        # flow add
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])],
                                     prio=14
                                     )
        # flow del
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_dels",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     prio=15
                                     )
        # verify the num of flow entry is 1
        flow_stats = get_flow_stats(self, ofp.match())
        self.assertEqual(len(flow_stats), 1)
        self.assertEqual(flow_stats[0].priority, 14, "Not matching entry is removed")
Esempio n. 53
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)

        # flow T0 add
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])]
                                     )

        # flow T1 add
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(in_port),
                                                      ofp.oxm.eth_dst([0x00, 0x13, 0x3b, 0x0f, 0x42, 0x1c])
                                                      ]),
                                     instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])]
                                     )
        # flow del
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_dels",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     )

        # verify the num of flow entry is 1
        flow_stats = get_flow_stats(self, ofp.match())
        self.assertEqual(len(flow_stats), 1)
Esempio n. 54
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port1, out_port2 = openflow_ports(3)

        # flow add
        FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(out_port1)])
            ],
            prio=15)
        # flow add
        FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(out_port2)])
            ],
            prio=14)
        # check
        flow_stats = get_flow_stats(self, ofp.match())
        self.assertEqual(len(flow_stats), 2, "Flow was not inserted correctly")
        # flow del
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_del",
                                     match=ofp.match(
                                         [ofp.oxm.in_port(in_port)]),
                                     prio=15,
                                     out_port=out_port1)
        # verify the num of flow entry is 1 and matching entry is removed
        flow_stats = get_flow_stats(self, ofp.match())
        self.assertEqual(len(flow_stats), 1, len(flow_stats))
Esempio n. 55
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)

        # flow add
        FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(out_port)])
            ],
            prio=15)
        # flow add
        FuncUtils.flow_entry_install(
            self.controller,
            "flow_add",
            match=ofp.match([ofp.oxm.in_port(in_port)]),
            instructions=[
                ofp.instruction.apply_actions([ofp.action.output(out_port)])
            ],
            prio=14)
        # flow del
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_dels",
                                     match=ofp.match(
                                         [ofp.oxm.in_port(in_port)]),
                                     prio=15)
        # verify the num of flow entry is 1
        flow_stats = get_flow_stats(self, ofp.match())
        self.assertEqual(len(flow_stats), 1)
        self.assertEqual(flow_stats[0].priority, 14,
                         "Not matching entry is removed")
Esempio n. 56
0
    def runTest(self):
        delete_all_flows(self.controller)
        in_port, out_port = openflow_ports(2)

        # flow add
        FuncUtils.flow_entry_install(self.controller,
                                     "flow_add",
                                     match=ofp.match([ofp.oxm.in_port(in_port)]),
                                     instructions=[ofp.instruction.apply_actions([ofp.action.output(out_port)])],
                                     hard_timeout=0,
                                     idle_timeout=0
                                     )
        # send packet to in_port and verify
        pkt = str(simple_tcp_packet())
        self.dataplane.send(in_port, pkt)
        verify_packets(self, pkt, [out_port])
        time.sleep(3)
        self.dataplane.send(in_port, pkt)
        verify_packets(self, pkt, [out_port])

        flow_stats = get_flow_stats(self, ofp.match())
        self.assertEqual(len(flow_stats), 1)