def make_match(dl_type=MT_TEST_DL_TYPE, ip_src=MT_TEST_IP): """ Make matching entry template """ match = ofp.ofp_match() match.length = ofp.OFPMT_STANDARD_LENGTH testutils.wildcard_all_set(match) match.wildcards -= ofp.OFPFW_DL_TYPE match.nw_src = parse.parse_ip(ip_src) match.nw_src_mask = 0 # Match nw_src match.dl_type = dl_type return match
def scenario3(self, first_table=0, second_table=1, third_table=2): """ Add three flow entries: First Table; Match IP Src A; goto Second Table Second Table; Match IP Src A; send to 1, goto Third Table Third Table; Match TCP port B; send to 2 Then send in 2 packets: IP A, TCP C; expect out port 1 IP A, TCP B; expect out port 2 @param self object instance @param first_table first table @param second_table second table @param third_table third table """ of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger) # Set up first match write_goto(self, first_table, second_table) # Set up second match write_goto_output(self, second_table, third_table, of_ports[0]) # Set up third match match = ofp.ofp_match() match.length = ofp.OFPMT_STANDARD_LENGTH testutils.wildcard_all_set(match) match.wildcards -= ofp.OFPFW_DL_TYPE match.wildcards -= ofp.OFPFW_TP_SRC match.dl_type = MT_TEST_DL_TYPE match.nw_proto = 6 #TCP match.tp_src = 80 write_output(self, third_table, of_ports[1], match=match) # Generate a packet matching only flow 1 and 2; rcv on port[0] reply_check_dp(self, tcp_sport=10, ing_port=of_ports[2], egr_port=of_ports[0]) # Generate a packet matching both flow 1, 2 and 3; rcv on port[1] reply_check_dp(self, tcp_sport=80, ing_port=of_ports[2], egr_port=of_ports[1])
def scenario3(self, first_table = 0, second_table = 1, third_table = 2): """ Add three flow entries: First Table; Match IP Src A; goto Second Table Second Table; Match IP Src A; send to 1, goto Third Table Third Table; Match TCP port B; send to 2 Then send in 2 packets: IP A, TCP C; expect out port 1 IP A, TCP B; expect out port 2 @param self object instance @param first_table first table @param second_table second table @param third_table third table """ of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger) # Set up first match write_goto(self, first_table, second_table) # Set up second match write_goto_output(self, second_table, third_table, of_ports[0]) # Set up third match match = ofp.ofp_match() match.length = ofp.OFPMT_STANDARD_LENGTH testutils.wildcard_all_set(match) match.wildcards -= ofp.OFPFW_DL_TYPE match.wildcards -= ofp.OFPFW_NW_PROTO match.wildcards -= ofp.OFPFW_TP_SRC match.dl_type = MT_TEST_DL_TYPE match.nw_proto = 6 #TCP match.tp_src = 80 write_output(self, third_table, of_ports[1], match=match) # Generate a packet matching only flow 1 and 2; rcv on port[0] reply_check_dp(self, tcp_sport=10, ing_port = of_ports[2], egr_port = of_ports[0]) # Generate a packet matching both flow 1, 2 and 3; rcv on port[1] reply_check_dp(self, tcp_sport=80, ing_port = of_ports[2], egr_port = of_ports[1])
def runTest(self): of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 2, "Not enough ports for test") # Clear flow table rv = testutils.initialize_table_config(self.controller, pa_logger) self.assertEqual(rv, 0, "Failed to initialize table config") rv = testutils.delete_all_flows(self.controller, pa_logger) self.assertEqual(rv, 0, "Failed to delete all flows") # Set up first match match = ofp.ofp_match() match.length = ofp.OFPMT_STANDARD_LENGTH testutils.wildcard_all_set(match) match.wildcards -= ofp.OFPFW_DL_TYPE match.nw_src_mask = 0 # Match nw_src match.dl_type = 0x800 match.nw_src = parse.parse_ip("192.168.1.10") act = action.action_output() act.port = of_ports[0] request = message.flow_mod() request.match = match request.buffer_id = 0xffffffff request.table_id = 0 inst = instruction.instruction_write_actions() self.assertTrue(inst.actions.add(act), "Could not add action") self.assertTrue(request.instructions.add(inst), "Could not add inst1") inst = instruction.instruction_goto_table() inst.table_id = 1 self.assertTrue(request.instructions.add(inst), "Could not add inst2") pa_logger.info("Inserting flow 1") rv = self.controller.message_send(request) # pa_logger.debug(request.show()) self.assertTrue(rv != -1, "Error installing flow mod") # Set up second match match = ofp.ofp_match() match.length = ofp.OFPMT_STANDARD_LENGTH testutils.wildcard_all_set(match) match.wildcards -= ofp.OFPFW_DL_TYPE match.wildcards -= ofp.OFPFW_TP_SRC match.dl_type = 0x800 match.nw_proto = 6 # TCP match.tp_src = 80 act = action.action_output() act.port = of_ports[1] request = message.flow_mod() request.match = match request.buffer_id = 0xffffffff request.table_id = 1 inst = instruction.instruction_write_actions() self.assertTrue(inst.actions.add(act), "Could not add action") self.assertTrue(request.instructions.add(inst), "Could not add inst3") pa_logger.info("Inserting flow 2") # pa_logger.debug(request.show()) rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Error installing flow mod") testutils.do_barrier(self.controller) # Generate a packet matching only flow 1; rcv on port[0] pkt = testutils.simple_tcp_packet(ip_src='192.168.1.10', tcp_sport=10) self.dataplane.send(of_ports[2], str(pkt)) (rcv_port, rcv_pkt, _) = self.dataplane.poll(timeout=5) self.assertTrue(rcv_pkt is not None, "Did not receive packet") pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " + str(rcv_port)) self.assertEqual(rcv_port, of_ports[0], "Unexpected receive port") # Generate a packet matching both flow 1 and flow 2; rcv on port[1] pkt = testutils.simple_tcp_packet(ip_src='192.168.1.10', tcp_sport=80) self.dataplane.send(of_ports[2], str(pkt)) (rcv_port, rcv_pkt, _) = self.dataplane.poll(timeout=5) self.assertTrue(rcv_pkt is not None, "Did not receive packet") pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " + str(rcv_port)) self.assertEqual(rcv_port, of_ports[1], "Unexpected receive port")