def runTest(self): ing_port = flow_mods_port_map.keys()[0] out_port1 = flow_mods_port_map.keys()[1] out_port2 = flow_mods_port_map.keys()[2] pkt = testutils.simple_tcp_packet() testutils.delete_all_flows(self.controller, self.logger) fm_orig = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=out_port1) inst = None inst = instruction.instruction_write_actions( ) #instruct is the same, action is different act = action.action_output() act.port = out_port2 rv = inst.actions.add(act) self.assertTrue(rv, "Could not add action" + act.show()) fm_orig.instructions.add(inst) #print(fm_orig.show()) testutils.ofmsg_send(self, fm_orig) (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 5) self.assertTrue(response is not None, 'No error message received') self.assertEqual( ofp.OFPET_BAD_INSTRUCTION, response.type, 'Error message type mismatch: ' + str(ofp.OFPET_BAD_INSTRUCTION, ) + " != " + str(response.type)) self.assertEqual( ofp.OFPBIC_UNKNOWN_INST, response.code, 'Error message code mismatch: ' + str(ofp.OFPBIC_UNKNOWN_INST) + " != " + str(response.code))
def runTest(self): ing_port = flow_mods_port_map.keys()[0] out_port1 = flow_mods_port_map.keys()[1] testutils.delete_all_flows(self.controller, self.logger) flow_add = message.flow_mod() flow_add.buffer_id = 0xffffffff flow_add.header.xid = 123 flow_add.table_id = 0 flow_add.command = ofp.OFPFC_ADD flow_add.match_fields.add(match.eth_type(value=0x86dd)) flow_add.match_fields.add(match.ipv4_src(value=3232235521)) flow_add.match_fields.add(match.ipv4_dst(value=3232235522)) flow_add.match_fields.add(match.metadata(value=0)) "new a instruction" inst = instruction.instruction_write_actions() "new a output actions" act = action.action_output() act.port = out_port1 inst.actions.add(act) flow_add.instructions.add(inst) #self.controller.message_send(flow_add) #print(flow_add.show()) testutils.ofmsg_send(self, flow_add) (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 2) self.assertTrue(response is not None, 'No error message received') self.assertEqual( ofp.OFPET_BAD_MATCH, response.type, 'Error message type mismatch: ' + str(ofp.OFPET_BAD_MATCH) + " != " + str(response.type)) self.assertEqual( ofp.OFPBMC_BAD_PREREQ, response.code, 'Error message code mismatch: ' + str(ofp.OFPBMC_BAD_PREREQ) + " != " + str(response.code))
def runTest(self): of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") pkt = testutils.simple_tcp_packet() act_all = action.action_output() act_all.port = ofp.OFPP_ALL act_ing = action.action_output() act_ing.port = ofp.OFPP_IN_PORT actions = [act_all, act_ing] for ingress_port in of_ports: rv = testutils.delete_all_flows(self.controller, pa_logger) self.assertEqual(rv, 0, "Failed to delete all flows") pa_logger.info("Ingress " + str(ingress_port) + " to all ports") flow_mod = testutils.flow_msg_create( self, pkt, ing_port=ingress_port, action_list=actions, inst_app_flag=testutils.APPLY_ACTIONS_INSTRUCTION) pa_logger.info(flow_mod.show()) pa_logger.info("Inserting flow") testutils.ofmsg_send(self, flow_mod) pa_logger.info("Sending packet to dp port " + str(ingress_port)) self.dataplane.send(ingress_port, str(pkt)) testutils.receive_pkt_check(self.dataplane, pkt, of_ports, [], self, pa_logger)
def runTest(self): ing_port = flow_mods_port_map.keys()[0] out_port1 = ofp.OFPP_ALL pkt = testutils.simple_tcp_packet() testutils.delete_all_flows(self.controller, self.logger) fm_orig = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=out_port1) #flood inst = None inst = instruction.instruction_apply_actions() act = action.action_output() act.port = ofp.OFPP_IN_PORT #fwd to ingress rv = inst.actions.add(act) self.assertTrue(rv, "Could not add action" + act.show()) fm_orig.instructions.add(inst) #print(fm_orig.show()) testutils.ofmsg_send(self, fm_orig) (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 2) self.assertTrue(response is None, 'Receive error message') #user sends packet self.dataplane.send(ing_port, str(pkt)) testutils.do_barrier(self.controller) #verify pkt for of_port in flow_mods_port_map.keys(): testutils.receive_pkt_verify(self, of_port, pkt)
def runTest(self): ing_port = flow_mods_port_map.keys()[0] out_port1 = ofp.OFPP_ALL pkt = testutils.simple_tcp_packet() testutils.delete_all_flows(self.controller, self.logger) fm_orig = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=out_port1)#flood inst = None inst = instruction.instruction_apply_actions() act = action.action_output() act.port = ofp.OFPP_IN_PORT #fwd to ingress rv = inst.actions.add(act) self.assertTrue(rv, "Could not add action" + act.show()) fm_orig.instructions.add(inst) #print(fm_orig.show()) testutils.ofmsg_send(self, fm_orig) (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 2) self.assertTrue(response is None, 'Receive error message') #user sends packet self.dataplane.send(ing_port, str(pkt)) testutils.do_barrier(self.controller) #verify pkt for of_port in flow_mods_port_map.keys(): testutils.receive_pkt_verify(self, of_port, pkt)
def runTest(self): of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") pkt = testutils.simple_tcp_packet() act_all = action.action_output() act_all.port = ofp.OFPP_ALL act_ing = action.action_output() act_ing.port = ofp.OFPP_IN_PORT actions = [ act_all, act_ing] for ingress_port in of_ports: rv = testutils.delete_all_flows(self.controller, pa_logger) self.assertEqual(rv, 0, "Failed to delete all flows") pa_logger.info("Ingress " + str(ingress_port) + " to all ports") flow_mod = testutils.flow_msg_create(self, pkt, ing_port=ingress_port, action_list=actions, inst_app_flag=testutils.APPLY_ACTIONS_INSTRUCTION ) pa_logger.info(flow_mod.show()) pa_logger.info("Inserting flow") testutils.ofmsg_send(self, flow_mod) pa_logger.info("Sending packet to dp port " + str(ingress_port)) self.dataplane.send(ingress_port, str(pkt)) testutils.receive_pkt_check(self.dataplane, pkt, of_ports, [], self, pa_logger)
def runTest(self): # Construct packet to send to dataplane # Send packet to dataplane # Poll controller with expect message type packet in of_ports = testutils.clear_switch(self, basic_port_map.keys(), basic_logger) # These will get put into function outpkt = testutils.simple_tcp_packet() of_ports = basic_port_map.keys() of_ports.sort() for dp_port in of_ports: msg = message.packet_out() msg.in_port = ofp.OFPP_CONTROLLER msg.data = str(outpkt) act = action.action_output() act.port = dp_port self.assertTrue(msg.actions.add(act), 'Could not add action to msg') basic_logger.info("PacketOut to: " + str(dp_port)) testutils.ofmsg_send(self, msg) (of_port, pkt, _) = self.dataplane.poll(timeout=1) self.assertTrue(pkt is not None, 'Packet not received') basic_logger.info("PacketOut: got pkt from " + str(of_port)) if of_port is not None: self.assertEqual(of_port, dp_port, "Unexpected receive port") self.assertEqual(str(outpkt), str(pkt), 'Response packet does not match send packet')
def runTest(self): of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") pkt = testutils.simple_tcp_packet() for ingress_port in of_ports: rv = testutils.delete_all_flows(self.controller, pa_logger) self.assertEqual(rv, 0, "Failed to delete all flows") pa_logger.info("Ingress " + str(ingress_port) + " to all ports") request = testutils.flow_msg_create(self, pkt, ing_port=ingress_port, egr_port=ofp.OFPP_ALL) pa_logger.info("Inserting flow") testutils.ofmsg_send(self, request) pa_logger.info("Sending packet to dp port " + str(ingress_port)) self.dataplane.send(ingress_port, str(pkt)) yes_ports = set(of_ports).difference([ingress_port]) testutils.receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port], self, pa_logger)
def runTest(self): of_ports = exact_port_map.keys() ing_port = of_ports[0] egr_port = of_ports[1] table_id = testutils.EX_ACL_TABLE "clear swtich;" testutils.delete_all_flows(self.controller, self.logger) "make test packet;" pkt = testutils.simple_tcp_packet() "construct flow entry" match_ls = testutils.packet_to_exact_flow_match( pkt, None, table_id, ing_port) flow_add = testutils.flow_msg_create(self, pkt, match_fields=match_ls, egr_port=egr_port, table_id=table_id) testutils.ofmsg_send(self, flow_add) "read flow back;" response = testutils.flow_stats_get(self, match_ls, table_id) self.assertTrue(len(response.stats) != 0, "stats len is 0") "send a packet from ing_port " self.dataplane.send(ing_port, str(pkt)) "poll from the egr_port port" testutils.receive_pkt_verify(self, egr_port, pkt)
def runTest(self): of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 2, "Not enough ports for test") pkt = testutils.simple_tcp_packet() for ingress_port in of_ports: rv = testutils.delete_all_flows(self.controller, pa_logger) self.assertEqual(rv, 0, "Failed to delete all flows") pa_logger.info("Ingress " + str(ingress_port) + " all non-ingress ports") actions = [] for egress_port in of_ports: act = action.action_output() if egress_port == ingress_port: continue act.port = egress_port actions.append(act) request = testutils.flow_msg_create(self, pkt, ing_port=ingress_port, action_list=actions, inst_app_flag=testutils.APPLY_ACTIONS_INSTRUCTION) pa_logger.info("Inserting flow") testutils.ofmsg_send(self, request) pa_logger.info("Sending packet to dp port " + str(ingress_port)) self.dataplane.send(ingress_port, str(pkt)) yes_ports = set(of_ports).difference([ingress_port]) testutils.receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port], self, pa_logger)
def runTest(self): table_id = testutils.EX_L2_TABLE of_ports = exact_port_map.keys() egr_port1 = of_ports[len(of_ports)-1] egr_port2 = of_ports[0] pkt = testutils.simple_tcp_packet(dl_src='99:33:11:11:11:55', dl_dst='33:33:11:11:77:66') pkt_metadata = {'metadata_val':0x99999999, 'metadata_msk':0xFFFFFFFFFFFFFFFF} request = testutils.flow_msg_create(self, pkt, pkt_metadata, egr_port = egr_port1, table_id = table_id) testutils.flow_msg_install(self, request) #"mod it ,add outport 1" request_mod = testutils.flow_msg_create(self, pkt, match_fields = request.match_fields, egr_port = egr_port2, table_id = table_id) request_mod.command = ofp.OFPFC_MODIFY testutils.ofmsg_send(self, request_mod) #print(flow_mod.show()) #"read it back;" stat_req = message.flow_stats_request() stat_req.buffer_id = 0xffffffff stat_req.table_id = table_id stat_req.out_port = ofp.OFPP_ANY stat_req.out_group = ofp.OFPG_ANY stat_req.match_fields = request.match_fields response, _ = self.controller.transact(stat_req, timeout=2) #print(response.show()) self.assertTrue(isinstance(response,message.flow_stats_reply),"Not a flow_stats_reply") self.assertEqual(len(response.stats),1, "len of stats is:"+str(len(response.stats))) self.assertEqual(response.stats[0].instructions.items[0].actions.items[0].port, request_mod.instructions.items[0].actions.items[0].port, "action error:"+str(response.stats[0].instructions.items[0].actions.items[0].port))
def runTest(self): ing_port = flow_mods_port_map.keys()[0] out_port1 = flow_mods_port_map.keys()[1] out_port2 = flow_mods_port_map.keys()[2] pkt = testutils.simple_tcp_packet() testutils.delete_all_flows(self.controller, self.logger) fm_orig = testutils.flow_msg_create(self, pkt, ing_port=ofp.OFPP_ANY, egr_port=out_port1, table_id=2) fm_new = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=out_port2, table_id=2) fm_new.command = ofp.OFPFC_MODIFY_STRICT testutils.ofmsg_send(self, fm_orig) testutils.ofmsg_send(self, fm_new) flow_stats = testutils.flow_stats_get(self) #print(flow_stats.show()) self.assertEqual(len(flow_stats.stats), 1, "Expected only one flow_mod") #fail to modify and instruction will remain the same stat = flow_stats.stats[0] self.assertEqual(stat.match, fm_orig.match) self.assertEqual(stat.instructions, fm_orig.instructions)
def exact_table_goto_table(parent = None, first_table = 0, second_table = 1, match_ls = None, actions = []): """ exact table goto table """ if parent == None or match_ls == None: print("parent == None or match_ls == None") return if first_table >= second_table : print( "first_table >= second_table") return request = message.flow_mod() request.table_id = first_table request.command = ofp.OFPFC_ADD request.match_fields = match_ls if(len(actions) != 0): inst = instruction.instruction_write_actions(); inst.actions = actions request.instructions.add(inst) inst_goto = instruction.instruction_goto_table(); inst_goto.table_id = second_table request.instructions.add(inst_goto) testutils.ofmsg_send(parent,request)
def exact_table_output(parent = None, table_id = None, match_ls = None, actions = [], egr_port = None): """ exact table output """ if parent == None or table_id == None or match_ls == None: print( "parent == None or table_id == None or match_ls == None:") return if egr_port is None: of_ports = exact_port_map.keys() egr_port = of_ports[len(of_ports)-1] request = message.flow_mod() request.table_id = table_id request.command = ofp.OFPFC_ADD request.match_fields = match_ls inst = instruction.instruction_write_actions(); for item in actions: inst.actions.add(item) #print( inst.actions.show()) #inst.actions.actions = actions act_out = action.action_output() act_out.port = egr_port inst.actions.add(act_out) request.instructions.add(inst) testutils.ofmsg_send(parent, request)
def exact_table_output(parent=None, table_id=None, match_ls=None, actions=[], egr_port=None): """ exact table output """ if parent == None or table_id == None or match_ls == None: print("parent == None or table_id == None or match_ls == None:") return if egr_port is None: of_ports = exact_port_map.keys() egr_port = of_ports[len(of_ports) - 1] request = message.flow_mod() request.table_id = table_id request.command = ofp.OFPFC_ADD request.match_fields = match_ls inst = instruction.instruction_write_actions() for item in actions: inst.actions.add(item) #print( inst.actions.show()) #inst.actions.actions = actions act_out = action.action_output() act_out.port = egr_port inst.actions.add(act_out) request.instructions.add(inst) testutils.ofmsg_send(parent, request)
def runTest(self): table_id = testutils.EX_L2_TABLE of_ports = exact_port_map.keys() egr_port = of_ports[0] pkt = testutils.simple_tcp_packet(dl_src='22:22:22:22:22:22', dl_dst='22:22:22:22:22:22') pkt_metadata = {'metadata_val':0x1122334455667788, 'metadata_msk':0xFFFFFFFFFFFFFFFF} request = testutils.flow_msg_create(self, pkt, pkt_metadata, egr_port = egr_port, table_id = table_id) testutils.flow_msg_install(self, request) #"delete it" request_del = testutils.flow_msg_create(self, pkt, match_fields = request.match_fields, egr_port = egr_port, table_id = table_id) request_del.command = ofp.OFPFC_DELETE testutils.ofmsg_send(self, request_del) #'read it back , returns blank;' stat_req = message.flow_stats_request() stat_req.buffer_id = 0xffffffff stat_req.table_id = table_id stat_req.out_port = ofp.OFPP_ANY stat_req.out_group = ofp.OFPG_ANY stat_req.match_fields = request.match_fields response, _ = self.controller.transact(stat_req, timeout=2) self.assertTrue(isinstance(response,message.flow_stats_reply),"Not a flow_stats_reply") self.assertEqual(len(response.stats),0, "len of stats is:"+str(len(response.stats)))
def runTest(self): ing_port = flow_mods_port_map.keys()[0] out_port1 = flow_mods_port_map.keys()[1] testutils.delete_all_flows(self.controller, self.logger) flow_add = message.flow_mod() flow_add.buffer_id = 0xffffffff; flow_add.header.xid = 123 flow_add.table_id = 0 flow_add.command = ofp.OFPFC_ADD flow_add.match_fields.add(match.eth_type(value = 0x86dd)) flow_add.match_fields.add(match.ipv4_src(value = 3232235521)) flow_add.match_fields.add(match.ipv4_dst(value = 3232235522)) flow_add.match_fields.add(match.metadata(value = 0)) "new a instruction" inst = instruction.instruction_write_actions() "new a output actions" act = action.action_output() act.port = out_port1 inst.actions.add(act) flow_add.instructions.add(inst) #self.controller.message_send(flow_add) #print(flow_add.show()) testutils.ofmsg_send(self, flow_add) (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 2) self.assertTrue(response is not None, 'No error message received') self.assertEqual(ofp.OFPET_BAD_MATCH, response.type, 'Error message type mismatch: ' + str(ofp.OFPET_BAD_MATCH) + " != " + str(response.type)) self.assertEqual(ofp.OFPBMC_BAD_PREREQ, response.code, 'Error message code mismatch: ' + str(ofp.OFPBMC_BAD_PREREQ) + " != " + str(response.code))
def runTest(self): ing_port = flow_mods_port_map.keys()[0] out_port1 = flow_mods_port_map.keys()[1] out_port2 = flow_mods_port_map.keys()[2] pkt = testutils.simple_tcp_packet() testutils.delete_all_flows(self.controller, self.logger) fm_orig = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=out_port1) inst = None inst = instruction.instruction_write_actions()#instruct is the same, action is different act = action.action_output() act.port = out_port2 rv = inst.actions.add(act) self.assertTrue(rv, "Could not add action" + act.show()) fm_orig.instructions.add(inst) #print(fm_orig.show()) testutils.ofmsg_send(self, fm_orig) (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 5) self.assertTrue(response is not None, 'No error message received') self.assertEqual(ofp.OFPET_BAD_INSTRUCTION, response.type, 'Error message type mismatch: ' + str(ofp.OFPET_BAD_INSTRUCTION,) + " != " + str(response.type)) self.assertEqual(ofp.OFPBIC_UNKNOWN_INST, response.code, 'Error message code mismatch: ' + str(ofp.OFPBIC_UNKNOWN_INST) + " != " + str(response.code))
def exact_table_goto_table(parent=None, first_table=0, second_table=1, match_ls=None, actions=[]): """ exact table goto table """ if parent == None or match_ls == None: print("parent == None or match_ls == None") return if first_table >= second_table: print("first_table >= second_table") return request = message.flow_mod() request.table_id = first_table request.command = ofp.OFPFC_ADD request.match_fields = match_ls if (len(actions) != 0): inst = instruction.instruction_write_actions() inst.actions = actions request.instructions.add(inst) inst_goto = instruction.instruction_goto_table() inst_goto.table_id = second_table request.instructions.add(inst_goto) testutils.ofmsg_send(parent, request)
def runTest(self): ing_port = flow_mods_port_map.keys()[0] out_port1 = flow_mods_port_map.keys()[1] out_port2 = flow_mods_port_map.keys()[2] pkt = testutils.simple_tcp_packet() testutils.delete_all_flows(self.controller, self.logger) fm_orig = testutils.flow_msg_create(self, pkt, ing_port=ofp.OFPP_ANY, egr_port=out_port1, table_id=2) fm_new = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=out_port2, table_id=2) fm_new.command = ofp.OFPFC_MODIFY_STRICT testutils.ofmsg_send(self, fm_orig) testutils.ofmsg_send(self, fm_new) flow_stats = testutils.flow_stats_get(self) #print(flow_stats.show()) self.assertEqual(len(flow_stats.stats),1, "Expected only one flow_mod") #fail to modify and instruction will remain the same stat = flow_stats.stats[0] self.assertEqual(stat.match, fm_orig.match) self.assertEqual(stat.instructions, fm_orig.instructions)
def runTest(self): of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 2, "Not enough ports for test") pkt = testutils.simple_tcp_packet() for ingress_port in of_ports: rv = testutils.delete_all_flows(self.controller, pa_logger) self.assertEqual(rv, 0, "Failed to delete all flows") pa_logger.info("Ingress " + str(ingress_port) + " all non-ingress ports") actions = [] for egress_port in of_ports: act = action.action_output() if egress_port == ingress_port: continue act.port = egress_port actions.append(act) request = testutils.flow_msg_create( self, pkt, ing_port=ingress_port, action_list=actions, inst_app_flag=testutils.APPLY_ACTIONS_INSTRUCTION) pa_logger.info("Inserting flow") testutils.ofmsg_send(self, request) pa_logger.info("Sending packet to dp port " + str(ingress_port)) self.dataplane.send(ingress_port, str(pkt)) yes_ports = set(of_ports).difference([ingress_port]) testutils.receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port], self, pa_logger)
def runTest(self): #async_logger.info("Running " + str(self)) #step 0:clear switch of_ports = testutils.clear_switch(self, async_port_map.keys(), async_logger) (response, _) = self.controller.poll(ofp.OFPT_PORT_STATUS, 2) (response, _) = self.controller.poll(ofp.OFPT_PORT_STATUS, 2) (response, _) = self.controller.poll(ofp.OFPT_PORT_STATUS, 2) #step 1:controller sends set_async_request msg async_logger.info("Sending set_async_request") mask = 0xffffffff ^ (1 << ofp.OFPPR_MODIFY) request_set = create_set_async(port_st_mstr = mask) testutils.ofmsg_send(self, request_set) #result 1: contrller sends msg successfully #step 2: set the first port's config to the other way async_logger.info("testcase executed on port: " + str(of_ports[0])) async_logger.debug("No flood bit port " + str(of_ports[0]) + " is now " + str(ofp.OFPPC_NO_PACKET_IN)) rv = testutils.port_config_set(self.controller, of_ports[0], ofp.OFPPC_NO_PACKET_IN, ofp.OFPPC_NO_PACKET_IN, async_logger) #result 2:set the first port's config to the other way successfully self.assertTrue(rv != -1, "Error sending port mod") testutils.do_barrier(self.controller) #step 3: after the port's attribute changed, PORT_STATUS msg sended to controller (response, _) = self.controller.poll(ofp.OFPT_PORT_STATUS, 2) #result 3: no packetin msg sended to controller self.assertTrue(response is None, 'PORT_STATUS message received unexpected') #step 4: Verify change took place with same feature request _,config,_ = testutils.port_config_get(self.controller, of_ports[0], async_logger) async_logger.debug("No packet_in bit port " + str(of_ports[0]) + " is now " + str(config & ofp.OFPPC_NO_PACKET_IN)) self.assertTrue(config is not None, "Did not get port config") self.assertTrue(config & ofp.OFPPC_NO_PACKET_IN != 0, "Bit change did not take") #step 5: Set it back mask = 1 << ofp.OFPPR_MODIFY request_set = create_set_async(port_st_mstr = mask) testutils.ofmsg_send(self, request_set) rv = testutils.port_config_set(self.controller, of_ports[0], 0, ofp.OFPPC_NO_PACKET_IN, async_logger) self.assertTrue(rv != -1, "Error sending port mod") (response, _) = self.controller.poll(ofp.OFPT_PORT_STATUS, 2) #result 3: no packetin msg sended to controller self.assertTrue(response is not None, 'PORT_STATUS message not received') testutils.clear_switch(self, async_port_map, async_logger) msg = create_set_async() set_async_verify(self, msg)
def runTest(self): basic_logger.info("Running StatsGet") basic_logger.info("Inserting trial flow") request = message.flow_mod() request.match.wildcards = OFPFW_ALL request.buffer_id = 0xffffffff testutils.ofmsg_send(self, request) basic_logger.info("Sending flow request") response = testutils.flow_stats_get(self) basic_logger.debug(response.show())
def runTest(self): global pa_port_map of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") ingress_port = of_ports[0] egress_port = of_ports[1] rc = testutils.delete_all_flows(self.controller, pa_logger) self.assertEqual(rc, 0, "Failed to delete all flows") #controller send flow_mod to switch pkt = testutils.simple_tcp_packet() flow_mod_add = testutils.flow_msg_create( self, pkt, ing_port=ingress_port, egr_port=egress_port, table_id=testutils.EX_ACL_TABLE) testutils.flow_msg_install(self, flow_mod_add) #user send pkt to switch, switch transfer to eng_port pa_logger.info("Sending packet to dp port " + str(ingress_port)) self.dataplane.send(ingress_port, str(pkt)) (rcv_port, rcv_pkt, _) = self.dataplane.poll(egress_port, timeout=2) self.assertTrue(rcv_pkt is not None, "Did not receive packet") pa_logger.debug("Packet len " + str(len(pkt)) + " in on " + str(rcv_port)) self.assertEqual(rcv_port, egress_port, "Unexpected receive port") self.assertEqual(str(pkt), str(rcv_pkt), 'Response packet does not match send packet') #check the stats msg stat_req = message.flow_stats_request() stat_req.match_fields = flow_mod_add.match_fields stat_req.table_id = 0xff stat_req.out_port = ofp.OFPP_ANY stat_req.out_group = ofp.OFPG_ANY pa_logger.info("Sending stats request") testutils.ofmsg_send(self, stat_req) (response, _) = self.controller.poll(ofp.OFPT_MULTIPART_REPLY, 2) self.assertTrue(response, "No Flow_stats reply") #print "YYY: Stats reply is \n%s" % (response.show()) self.assertEqual(len(response.stats), 1, "Did not receive flow stats reply") self.assertEqual(response.stats[0].packet_count, 1) self.assertEqual(response.stats[0].byte_count, len(rcv_pkt))
def runTest(self): request = message.role_request() request.role = ofp.OFPCR_ROLE_SLAVE gener_id = GetGenerationID(self.controller) self.assertTrue(gener_id is not None, "Did not get generation_id") request.generation_id = gener_id response,_ = self.controller.transact(request) self.assertEqual(response.header.type, ofp.OFPT_ROLE_REPLY, 'response is not role_reply') self.assertEqual(response.role, ofp.OFPCR_ROLE_SLAVE, 'response is not OFPCR_ROLE_SLAVE') request = message.role_request() request.role = ofp.OFPCR_ROLE_MASTER request.generation_id = gener_id + 1 testutils.ofmsg_send(self, request)
def runTest(self): request = message.role_request() request.role = ofp.OFPCR_ROLE_SLAVE gener_id = GetGenerationID(self.controller) self.assertTrue(gener_id is not None, "Did not get generation_id") request.generation_id = gener_id response, _ = self.controller.transact(request) self.assertEqual(response.header.type, ofp.OFPT_ROLE_REPLY, 'response is not role_reply') self.assertEqual(response.role, ofp.OFPCR_ROLE_SLAVE, 'response is not OFPCR_ROLE_SLAVE') request = message.role_request() request.role = ofp.OFPCR_ROLE_MASTER request.generation_id = gener_id + 1 testutils.ofmsg_send(self, request)
def runTest(self): # Construct packet to send to dataplane # Send packet to dataplane # Poll controller with expect message type packet in of_ports = testutils.clear_switch(self, basic_port_map.keys(), basic_logger) max_len = 40 testutils.set_flow_miss_entry(self, ofp.OFPTC_TABLE_MISS_CONTROLLER, max_len, 0) # These will get put into function outpkt = testutils.simple_tcp_packet() of_ports = basic_port_map.keys() of_ports.sort() #_,miss_send_len = testutils.get_config_reply_verify(self) #testutils.set_config_verify(self, max_len = 40) for dp_port in of_ports: (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) for egr_port in of_ports: if egr_port != dp_port: break #_,max_len = testutils.get_config_reply_verify(self) self.dataplane.send(egr_port, str(outpkt)) testutils.do_barrier(self.controller) buffer_id = testutils.packetin_verify(self, outpkt, max_len) response, _ = self.controller.poll(ofp.OFPT_PACKET_IN, 1) while response != None: response, _ = self.controller.poll(ofp.OFPT_PACKET_IN, 1) msg = message.packet_out() msg.in_port = ofp.OFPP_CONTROLLER msg.buffer_id = buffer_id act = action.action_output() act.port = dp_port self.assertTrue(msg.actions.add(act), 'Could not add action to msg') basic_logger.info("PacketOut to: " + str(dp_port)) testutils.ofmsg_send(self, msg) (of_port, pkt, _) = self.dataplane.poll(timeout=3) self.assertTrue(pkt is not None, 'Packet not received') basic_logger.info("PacketOut: got pkt from " + str(of_port)) if of_port is not None: self.assertEqual(of_port, dp_port, "Unexpected receive port") self.assertEqual(str(outpkt), str(pkt), 'Response packet does not match send packet')
def runTest(self): table_id = testutils.EX_L2_TABLE of_ports = exact_port_map.keys() egr_port1 = of_ports[len(of_ports) - 1] egr_port2 = of_ports[0] pkt = testutils.simple_tcp_packet(dl_src='99:33:11:11:11:55', dl_dst='33:33:11:11:77:66') pkt_metadata = { 'metadata_val': 0x99999999, 'metadata_msk': 0xFFFFFFFFFFFFFFFF } request = testutils.flow_msg_create(self, pkt, pkt_metadata, egr_port=egr_port1, table_id=table_id) testutils.flow_msg_install(self, request) #"mod it ,add outport 1" request_mod = testutils.flow_msg_create( self, pkt, match_fields=request.match_fields, egr_port=egr_port2, table_id=table_id) request_mod.command = ofp.OFPFC_MODIFY testutils.ofmsg_send(self, request_mod) #print(flow_mod.show()) #"read it back;" stat_req = message.flow_stats_request() stat_req.buffer_id = 0xffffffff stat_req.table_id = table_id stat_req.out_port = ofp.OFPP_ANY stat_req.out_group = ofp.OFPG_ANY stat_req.match_fields = request.match_fields response, _ = self.controller.transact(stat_req, timeout=2) #print(response.show()) self.assertTrue(isinstance(response, message.flow_stats_reply), "Not a flow_stats_reply") self.assertEqual(len(response.stats), 1, "len of stats is:" + str(len(response.stats))) self.assertEqual( response.stats[0].instructions.items[0].actions.items[0].port, request_mod.instructions.items[0].actions.items[0].port, "action error:" + str(response.stats[0].instructions.items[0].actions.items[0].port))
def runExpireTest(self, idle_timeout=0, hard_timeout=0): global pa_port_map of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") rc = delete_all_flows(self.controller, pa_logger) self.assertEqual(rc, 0, "Failed to delete all flows") pkt = simple_tcp_packet() ingress_port = pa_config["base_of_port"] egress_port = (pa_config["base_of_port"] + 1) % len(of_ports) pa_logger.info("Ingress " + str(ingress_port) + " to egress " + str(egress_port)) request = testutils.flow_msg_create(self, pkt, ing_port=ingress_port, egr_port=egress_port, check_expire=True) request.cookie = random.randint(0, 9007199254740992) request.buffer_id = 0xffffffff request.idle_timeout = idle_timeout request.hard_timeout = hard_timeout request.flags |= ofp.OFPFF_SEND_FLOW_REM match_fields = request.match_fields pa_logger.info("Inserting flow") testutils.ofmsg_send(self, request) (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 8) self.assertTrue(response is not None, 'Did not receive flow removed message ') self.assertEqual(request.cookie, response.cookie, 'Cookies do not match') if idle_timeout == 0: self.assertEqual( ofp.OFPRR_HARD_TIMEOUT, response.reason, 'Flow table entry removal reason is not idle_timeout') elif hard_timeout == 0: self.assertEqual( ofp.OFPRR_IDLE_TIMEOUT, response.reason, 'Flow table entry removal reason is not idle_timeout')
def runTest(self): global pa_port_map of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") ingress_port = of_ports[0]; egress_port = of_ports[1]; rc = testutils.delete_all_flows(self.controller, pa_logger) self.assertEqual(rc, 0, "Failed to delete all flows") #controller send flow_mod to switch pkt = testutils.simple_tcp_packet() flow_mod_add = testutils.flow_msg_create(self, pkt, ing_port=ingress_port, egr_port=egress_port, table_id=testutils.EX_ACL_TABLE) testutils.flow_msg_install(self, flow_mod_add) #user send pkt to switch, switch transfer to eng_port pa_logger.info("Sending packet to dp port " + str(ingress_port)) self.dataplane.send(ingress_port, str(pkt)) (rcv_port, rcv_pkt, _) = self.dataplane.poll(egress_port, timeout=2) self.assertTrue(rcv_pkt is not None, "Did not receive packet") pa_logger.debug("Packet len " + str(len(pkt)) + " in on " + str(rcv_port)) self.assertEqual(rcv_port, egress_port, "Unexpected receive port") self.assertEqual(str(pkt), str(rcv_pkt), 'Response packet does not match send packet') #check the stats msg stat_req = message.flow_stats_request() stat_req.match_fields = flow_mod_add.match_fields stat_req.table_id = 0xff stat_req.out_port = ofp.OFPP_ANY; stat_req.out_group = ofp.OFPG_ANY; pa_logger.info("Sending stats request") testutils.ofmsg_send(self, stat_req) (response, _) = self.controller.poll(ofp.OFPT_MULTIPART_REPLY, 2) self.assertTrue(response, "No Flow_stats reply") #print "YYY: Stats reply is \n%s" % (response.show()) self.assertEqual(len(response.stats), 1, "Did not receive flow stats reply") self.assertEqual(response.stats[0].packet_count,1) self.assertEqual(response.stats[0].byte_count,len(rcv_pkt))
def runTest(self): # Construct packet to send to dataplane # Send packet to dataplane # Poll controller with expect message type packet in of_ports = testutils.clear_switch(self, basic_port_map.keys(), basic_logger) max_len = 40 testutils.set_flow_miss_entry(self, ofp.OFPTC_TABLE_MISS_CONTROLLER, max_len, 0) # These will get put into function outpkt = testutils.simple_tcp_packet() of_ports = basic_port_map.keys() of_ports.sort() #_,miss_send_len = testutils.get_config_reply_verify(self) #testutils.set_config_verify(self, max_len = 40) for dp_port in of_ports: (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) for egr_port in of_ports: if egr_port != dp_port: break #_,max_len = testutils.get_config_reply_verify(self) self.dataplane.send(egr_port, str(outpkt)) testutils.do_barrier(self.controller) buffer_id = testutils.packetin_verify(self, outpkt, max_len) response,_ = self.controller.poll(ofp.OFPT_PACKET_IN, 1) while response != None: response,_ = self.controller.poll(ofp.OFPT_PACKET_IN, 1) msg = message.packet_out() msg.in_port = ofp.OFPP_CONTROLLER msg.buffer_id = buffer_id act = action.action_output() act.port = dp_port self.assertTrue(msg.actions.add(act), 'Could not add action to msg') basic_logger.info("PacketOut to: " + str(dp_port)) testutils.ofmsg_send(self, msg) (of_port, pkt, _) = self.dataplane.poll(timeout=3) self.assertTrue(pkt is not None, 'Packet not received') basic_logger.info("PacketOut: got pkt from " + str(of_port)) if of_port is not None: self.assertEqual(of_port, dp_port, "Unexpected receive port") self.assertEqual(str(outpkt), str(pkt), 'Response packet does not match send packet')
def runExpireTest(self, idle_timeout=0, hard_timeout=0): global pa_port_map of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") rc = delete_all_flows(self.controller, pa_logger) self.assertEqual(rc, 0, "Failed to delete all flows") pkt = simple_tcp_packet() ingress_port = pa_config["base_of_port"] egress_port = (pa_config["base_of_port"] + 1) % len(of_ports) pa_logger.info("Ingress " + str(ingress_port) + " to egress " + str(egress_port)) request = testutils.flow_msg_create(self, pkt, ing_port=ingress_port, egr_port=egress_port, check_expire=True) request.cookie = random.randint(0,9007199254740992) request.buffer_id = 0xffffffff request.idle_timeout = idle_timeout request.hard_timeout = hard_timeout request.flags |= ofp.OFPFF_SEND_FLOW_REM match_fields = request.match_fields pa_logger.info("Inserting flow") testutils.ofmsg_send(self, request) (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 8) self.assertTrue(response is not None, 'Did not receive flow removed message ') self.assertEqual(request.cookie, response.cookie, 'Cookies do not match') if idle_timeout == 0: self.assertEqual(ofp.OFPRR_HARD_TIMEOUT, response.reason, 'Flow table entry removal reason is not idle_timeout') elif hard_timeout == 0: self.assertEqual(ofp.OFPRR_IDLE_TIMEOUT, response.reason, 'Flow table entry removal reason is not idle_timeout')
def set_async_verify(parent, msg): async_logger.info("Sending set_async_request") testutils.ofmsg_send(parent, msg) #step 2:controller sends get_async_request msg async_logger.info("Sending get_async_request") request = message.get_async_request() response, _ = parent.controller.transact(request, timeout=2) #print(response.show()) #result 2: contrller receives msg successfully,set==get parent.assertTrue(response is not None, "Did not get response") async_logger.debug(response.show()) parent.assertEqual(response.header.type, ofp.OFPT_GET_ASYNC_REPLY, 'response is not OFPT_GET_ASYNC_REPLY') parent.assertEqual(msg.packet_in_mask, response.packet_in_mask, 'request.packet_in_mask != response.packet_in_mask') parent.assertEqual(msg.port_status_mask, response.port_status_mask, 'request.port_status_mask != response.port_status_mask') parent.assertEqual(msg.flow_removed_mask, response.flow_removed_mask, 'request.flow_removed_mask != response.flow_removed_mask')
def runTest(self): of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 2, "Not enough ports for test") pkt = testutils.simple_tcp_packet() match_fields = testutils.packet_to_exact_flow_match(pkt) self.assertTrue(match_fields is not None, "Could not generate flow match from pkt") act1 = action.action_output() act2 = action.action_output() for idx in range(len(of_ports)): rv = testutils.delete_all_flows(self.controller, pa_logger) self.assertEqual(rv, 0, "Failed to delete all flows") ingress_port = of_ports[idx] egress_port1 = of_ports[(idx + 1) % len(of_ports)] egress_port2 = of_ports[(idx + 2) % len(of_ports)] pa_logger.info("Ingress " + str(ingress_port) + " to egress " + str(egress_port1) + " and " + str(egress_port2)) act1.port = egress_port1 act2.port = egress_port2 request = testutils.flow_msg_create( self, pkt, ing_port=ingress_port, action_list=[act1, act2], inst_app_flag=testutils.APPLY_ACTIONS_INSTRUCTION) pa_logger.info("Inserting flow") testutils.ofmsg_send(self, request) pa_logger.info("Sending packet to dp port " + str(ingress_port)) self.dataplane.send(ingress_port, str(pkt)) yes_ports = set([egress_port1, egress_port2]) no_ports = set(of_ports).difference(yes_ports) testutils.receive_pkt_check(self.dataplane, pkt, yes_ports, no_ports, self, pa_logger)
def runTest(self): ing_port = flow_mods_port_map.keys()[0] out_port1 = flow_mods_port_map.keys()[1] out_port2 = flow_mods_port_map.keys()[2] pkt = testutils.simple_tcp_packet() testutils.delete_all_flows(self.controller, self.logger) fm_orig = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=out_port1) fm_new = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=out_port2) fm_new.command = ofp.OFPFC_MODIFY_STRICT testutils.ofmsg_send(self, fm_orig) testutils.ofmsg_send(self, fm_new) flow_stats = testutils.flow_stats_get(self) self.assertEqual(len(flow_stats.stats),1, "Expected only one flow_mod") stat = flow_stats.stats[0] #self.assertEqual(stat.match_fields, fm_new.match_fields) self.assertEqual(stat.instructions, fm_new.instructions, "instructions not equal !")
def runTest(self): table_id = testutils.EX_L2_TABLE of_ports = exact_port_map.keys() egr_port = of_ports[0] pkt = testutils.simple_tcp_packet(dl_src='22:22:22:22:22:22', dl_dst='22:22:22:22:22:22') pkt_metadata = { 'metadata_val': 0x1122334455667788, 'metadata_msk': 0xFFFFFFFFFFFFFFFF } request = testutils.flow_msg_create(self, pkt, pkt_metadata, egr_port=egr_port, table_id=table_id) testutils.flow_msg_install(self, request) #"delete it" request_del = testutils.flow_msg_create( self, pkt, match_fields=request.match_fields, egr_port=egr_port, table_id=table_id) request_del.command = ofp.OFPFC_DELETE testutils.ofmsg_send(self, request_del) #'read it back , returns blank;' stat_req = message.flow_stats_request() stat_req.buffer_id = 0xffffffff stat_req.table_id = table_id stat_req.out_port = ofp.OFPP_ANY stat_req.out_group = ofp.OFPG_ANY stat_req.match_fields = request.match_fields response, _ = self.controller.transact(stat_req, timeout=2) self.assertTrue(isinstance(response, message.flow_stats_reply), "Not a flow_stats_reply") self.assertEqual(len(response.stats), 0, "len of stats is:" + str(len(response.stats)))
def set_async_verify(parent, msg): async_logger.info("Sending set_async_request") testutils.ofmsg_send(parent, msg) #step 2:controller sends get_async_request msg async_logger.info("Sending get_async_request") request = message.get_async_request() response, _ = parent.controller.transact(request, timeout=2) #print(response.show()) #result 2: contrller receives msg successfully,set==get parent.assertTrue(response is not None, "Did not get response") async_logger.debug(response.show()) parent.assertEqual(response.header.type, ofp.OFPT_GET_ASYNC_REPLY, 'response is not OFPT_GET_ASYNC_REPLY') parent.assertEqual(msg.packet_in_mask, response.packet_in_mask, 'request.packet_in_mask != response.packet_in_mask') parent.assertEqual( msg.port_status_mask, response.port_status_mask, 'request.port_status_mask != response.port_status_mask') parent.assertEqual( msg.flow_removed_mask, response.flow_removed_mask, 'request.flow_removed_mask != response.flow_removed_mask')
def runTest(self): of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 2, "Not enough ports for test") pkt = testutils.simple_tcp_packet() match_fields = testutils.packet_to_exact_flow_match(pkt) self.assertTrue(match_fields is not None, "Could not generate flow match from pkt") act1 = action.action_output() act2 = action.action_output() for idx in range(len(of_ports)): rv = testutils.delete_all_flows(self.controller, pa_logger) self.assertEqual(rv, 0, "Failed to delete all flows") ingress_port = of_ports[idx] egress_port1 = of_ports[(idx + 1) % len(of_ports)] egress_port2 = of_ports[(idx + 2) % len(of_ports)] pa_logger.info("Ingress " + str(ingress_port) + " to egress " + str(egress_port1) + " and " + str(egress_port2)) act1.port = egress_port1 act2.port = egress_port2 request = testutils.flow_msg_create(self, pkt, ing_port=ingress_port, action_list=[act1, act2], inst_app_flag=testutils.APPLY_ACTIONS_INSTRUCTION) pa_logger.info("Inserting flow") testutils.ofmsg_send(self, request) pa_logger.info("Sending packet to dp port " + str(ingress_port)) self.dataplane.send(ingress_port, str(pkt)) yes_ports = set([egress_port1, egress_port2]) no_ports = set(of_ports).difference(yes_ports) testutils.receive_pkt_check(self.dataplane, pkt, yes_ports, no_ports, self, pa_logger)
def runTest(self): basic_logger.info("Running StatsGet") basic_logger.info("Inserting trial flow") request = message.flow_mod() request.match.wildcards = OFPFW_ALL request.buffer_id = 0xffffffff for i in range(1,5): request.priority = i*1000 basic_logger.debug("Adding flow %d" % i) testutils.ofmsg_send(self, request) basic_logger.info("Removing all flows") testutils.delete_all_flows(self.controller, basic_logger) basic_logger.info("Sending flow request") request = message.flow_stats_request() request.out_port = ofp.OFPP_ANY request.out_group = ofp.OFPG_ANY request.table_id = 0xff request.match.wildcards = 0 # ofp.OFPFW response, _ = self.controller.transact(request, timeout=2) self.assertTrue(response is not None, "Did not get response") self.assertTrue(isinstance(response,message.flow_stats_reply),"Not a flow_stats_reply") self.assertEqual(len(response.stats),0) basic_logger.debug(response.show())
def runTest(self): ing_port = flow_mods_port_map.keys()[0] out_port1 = flow_mods_port_map.keys()[1] out_port2 = flow_mods_port_map.keys()[2] pkt = testutils.simple_tcp_packet() testutils.delete_all_flows(self.controller, self.logger) fm_orig = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=out_port1) fm_new = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=out_port2) fm_new.command = ofp.OFPFC_MODIFY_STRICT testutils.ofmsg_send(self, fm_orig) testutils.ofmsg_send(self, fm_new) flow_stats = testutils.flow_stats_get(self) self.assertEqual(len(flow_stats.stats), 1, "Expected only one flow_mod") stat = flow_stats.stats[0] #self.assertEqual(stat.match_fields, fm_new.match_fields) self.assertEqual(stat.instructions, fm_new.instructions, "instructions not equal !")
def runTest(self): of_ports = exact_port_map.keys() ing_port = of_ports[0] egr_port = of_ports[1] table_id = testutils.EX_ACL_TABLE "clear swtich;" testutils.delete_all_flows(self.controller, self.logger) "make test packet;" pkt = testutils.simple_tcp_packet() "construct flow entry" match_ls = testutils.packet_to_exact_flow_match(pkt, None, table_id, ing_port) flow_add = testutils.flow_msg_create(self, pkt, match_fields = match_ls, egr_port = egr_port, table_id = table_id) testutils.ofmsg_send(self, flow_add) "read flow back;" response = testutils.flow_stats_get(self, match_ls, table_id) self.assertTrue(len(response.stats) != 0, "stats len is 0") "send a packet from ing_port " self.dataplane.send(ing_port, str(pkt)) "poll from the egr_port port" testutils.receive_pkt_verify(self, egr_port, pkt)
def runTest(self): basic_logger.info("Running StatsGet") basic_logger.info("Inserting trial flow") request = message.flow_mod() request.match.wildcards = OFPFW_ALL request.buffer_id = 0xffffffff for i in range(1, 5): request.priority = i * 1000 basic_logger.debug("Adding flow %d" % i) testutils.ofmsg_send(self, request) basic_logger.info("Removing all flows") testutils.delete_all_flows(self.controller, basic_logger) basic_logger.info("Sending flow request") request = message.flow_stats_request() request.out_port = ofp.OFPP_ANY request.out_group = ofp.OFPG_ANY request.table_id = 0xff request.match.wildcards = 0 # ofp.OFPFW response, _ = self.controller.transact(request, timeout=2) self.assertTrue(response is not None, "Did not get response") self.assertTrue(isinstance(response, message.flow_stats_reply), "Not a flow_stats_reply") self.assertEqual(len(response.stats), 0) basic_logger.debug(response.show())
def runTest(self): basic_logger.info("Running TableStats") testutils.delete_all_flows(self.controller, self.logger) basic_logger.info("Sending table stats request") request = message.table_stats_request() response, _ = self.controller.transact(request, timeout=2) # delete everything, so there should be no entries self.assertEqual(self.get_first_table_active_entries(response), 0) # add two entries to first table m1 = testutils.match_all_generate() m1.add(match.eth_type(0x800)) # m1.wildcards ^= OFPFW_DL_TYPE fm1 = testutils.flow_msg_create(self, None, match_fields=m1, egr_port=2) testutils.ofmsg_send(self, fm1) m2 = testutils.match_all_generate() m2.add(match.eth_type(0x806)) # m2.wildcards ^= ofp.OFPFW_DL_TYPE fm2 = testutils.flow_msg_create(self, None, match_fields=m2, egr_port=2) testutils.ofmsg_send(self, fm2) response, _ = self.controller.transact(request, timeout=2) self.assertEqual(self.get_first_table_active_entries(response), 2)
def runTest(self): basic_logger.info("Running TableStats") testutils.delete_all_flows(self.controller, self.logger) basic_logger.info("Sending table stats request") request = message.table_stats_request() response, _ = self.controller.transact(request, timeout=2) # delete everything, so there should be no entries self.assertEqual(self.get_first_table_active_entries(response), 0) # add two entries to first table m1 = testutils.match_all_generate() m1.add(match.eth_type(0x800)) #m1.wildcards ^= OFPFW_DL_TYPE fm1 = testutils.flow_msg_create(self, None, match_fields=m1, egr_port=2) testutils.ofmsg_send(self, fm1) m2 = testutils.match_all_generate() m2.add(match.eth_type(0x806)) #m2.wildcards ^= ofp.OFPFW_DL_TYPE fm2 = testutils.flow_msg_create(self, None, match_fields=m2, egr_port=2) testutils.ofmsg_send(self, fm2) response, _ = self.controller.transact(request, timeout=2) self.assertEqual(self.get_first_table_active_entries(response), 2)
def runTest(self): basic_logger.info("Running " + str(self)) request = message.flow_mod() request.match.wildcards = OFPFW_ALL request.buffer_id = 0xffffffff testutils.ofmsg_send(self, request)
def runTest(self): #async_logger.info("Running " + str(self)) #step 0:clear switch of_ports = testutils.clear_switch(self, async_port_map.keys(), async_logger) (response, _) = self.controller.poll(ofp.OFPT_PORT_STATUS, 2) (response, _) = self.controller.poll(ofp.OFPT_PORT_STATUS, 2) (response, _) = self.controller.poll(ofp.OFPT_PORT_STATUS, 2) #step 1:controller sends set_async_request msg async_logger.info("Sending set_async_request") mask = 0xffffffff ^ (1 << ofp.OFPPR_MODIFY) request_set = create_set_async(port_st_mstr=mask) testutils.ofmsg_send(self, request_set) #result 1: contrller sends msg successfully #step 2: set the first port's config to the other way async_logger.info("testcase executed on port: " + str(of_ports[0])) async_logger.debug("No flood bit port " + str(of_ports[0]) + " is now " + str(ofp.OFPPC_NO_PACKET_IN)) rv = testutils.port_config_set(self.controller, of_ports[0], ofp.OFPPC_NO_PACKET_IN, ofp.OFPPC_NO_PACKET_IN, async_logger) #result 2:set the first port's config to the other way successfully self.assertTrue(rv != -1, "Error sending port mod") testutils.do_barrier(self.controller) #step 3: after the port's attribute changed, PORT_STATUS msg sended to controller (response, _) = self.controller.poll(ofp.OFPT_PORT_STATUS, 2) #result 3: no packetin msg sended to controller self.assertTrue(response is None, 'PORT_STATUS message received unexpected') #step 4: Verify change took place with same feature request _, config, _ = testutils.port_config_get(self.controller, of_ports[0], async_logger) async_logger.debug("No packet_in bit port " + str(of_ports[0]) + " is now " + str(config & ofp.OFPPC_NO_PACKET_IN)) self.assertTrue(config is not None, "Did not get port config") self.assertTrue(config & ofp.OFPPC_NO_PACKET_IN != 0, "Bit change did not take") #step 5: Set it back mask = 1 << ofp.OFPPR_MODIFY request_set = create_set_async(port_st_mstr=mask) testutils.ofmsg_send(self, request_set) rv = testutils.port_config_set(self.controller, of_ports[0], 0, ofp.OFPPC_NO_PACKET_IN, async_logger) self.assertTrue(rv != -1, "Error sending port mod") (response, _) = self.controller.poll(ofp.OFPT_PORT_STATUS, 2) #result 3: no packetin msg sended to controller self.assertTrue(response is not None, 'PORT_STATUS message not received') testutils.clear_switch(self, async_port_map, async_logger) msg = create_set_async() set_async_verify(self, msg)
def runTest(self): #async_logger.info("Running InvalidTTL_NoPacketIn") #"verifying without set_async_request, switch will packet in" #step 1-1:clear all flow entries for unmatching rc = testutils.delete_all_flows(self.controller, async_logger) self.assertEqual(rc, 0, "Failed to delete all flows") #step 2-1:controller sends set_async_request msg async_logger.info("Sending set_async_request") mask = 1 << ofp.OFPR_INVALID_TTL request_set = create_set_async(pkt_in_mstr = mask) testutils.ofmsg_send(self, request_set) #result 2-1: contrller sends msg successfully #step 3-1: install default mismatch flow entry ,action=output; testutils.set_table_config(self) pkt = testutils.simple_tcp_packet(ip_ttl=0) flow_add = testutils.flow_msg_create(self, pkt, egr_port = ofp.OFPP_CONTROLLER, table_id = testutils.WC_L3_TABLE) testutils.flow_msg_install(self, flow_add) #send data(invalid ttl) to port for of_port in async_port_map.keys(): async_logger.info("PKT IN test, port " + str(of_port)) self.dataplane.send(of_port, str(pkt)) #@todo Check for unexpected messages? (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) self.assertTrue(response is not None, 'Can not receive packet in message') #dataplane receive nothing (port_rec, pkt_rec, _) = self.dataplane.poll(of_port,1) self.assertTrue(pkt_rec is None, "dataplane not receive packet") (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) #"verifying with set_async_request, switch will not packet in" #step 1-2:clear all flow entries for unmatching rc = testutils.delete_all_flows(self.controller, async_logger) self.assertEqual(rc, 0, "Failed to delete all flows") #step 2-2:controller sends set_async_request msg async_logger.info("Sending set_async_request") mask = 0xffffffff ^ (1 << ofp.OFPR_INVALID_TTL) request_set = create_set_async(pkt_in_mstr = mask) testutils.ofmsg_send(self, request_set) #result 2-2: contrller sends msg successfully #step 3-2: install default mismatch flow entry ,action=output; testutils.set_table_config(self) pkt = testutils.simple_tcp_packet(ip_ttl=0) flow_add = testutils.flow_msg_create(self, pkt, egr_port = ofp.OFPP_CONTROLLER, table_id = testutils.WC_L3_TABLE) testutils.flow_msg_install(self, flow_add) #(response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) #send data(invalid ttl) to port for of_port in async_port_map.keys(): async_logger.info("PKT IN test, port " + str(of_port)) self.dataplane.send(of_port, str(pkt)) #@todo Check for unexpected messages? (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) self.assertTrue(response is None, 'Packet in message received unexpected') #dataplane receive nothing (port_rec, pkt_rec, _) = self.dataplane.poll(of_port,1) self.assertTrue(pkt_rec is None, "dataplane rec packet") msg = create_set_async() set_async_verify(self, msg)
def runTest(self): #"verifying with set_async_request, switch will not send flow removed" #step 1-1:controller sends set_async_request msg async_logger.info("Sending set_async_request") of_ports = async_port_map.keys() of_ports.sort() ing_port = of_ports[0] egr_port = of_ports[1] mask = 1 << ofp.OFPRR_DELETE request_set = create_set_async(flow_rm_mstr=mask) testutils.ofmsg_send(self, request_set) #result 1-1: contrller sends msg successfully #"step 2-1:clear all flow entry" testutils.delete_all_flows(self.controller, async_logger) response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) pkt = testutils.simple_tcp_packet(vlan_tags=[{ 'type': 0x8100, 'vid': 5, 'pcp': 1 }]) request = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=egr_port, table_id=testutils.EX_VLAN_TABLE, check_expire=True) request.cookie = random.randint(0, 0xffffffffffffffff) testutils.flow_msg_install(self, request) "delete it" request.command = ofp.OFPFC_DELETE testutils.flow_msg_install(self, request) #"receive flow removed msg" (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) self.assertTrue(response is not None, 'Not receive flow removed message ') self.assertTrue(response.reason == ofp.OFPRR_DELETE, 'Not OFPRR_DELETE reason') self.assertTrue(response.cookie == request.cookie, 'Cookie is not equal') #self.assertTrue(response.match_fields == request.match_fields, # 'Match_fields is not equal') #'read it back , returns blank;' response = testutils.flow_stats_get(self, request.match_fields, request.table_id) self.assertEqual(len(response.stats), 0, "len of stats is:" + str(len(response.stats))) #print(response.show()) #"verifying with set_async_request, switch will not send flow removed" "step 1-2:controller sends set_async_request msg" async_logger.info("Sending set_async_request") mask = 0xffffffff ^ (1 << ofp.OFPRR_DELETE) request_set = create_set_async(flow_rm_mstr=mask) testutils.ofmsg_send(self, request_set) "result 1-2: contrller sends msg successfully" "step 2-2:clear all flow entry" testutils.delete_all_flows(self.controller, async_logger) response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) #table_id = 3 "add a flow entry" request.command = ofp.OFPFC_ADD testutils.flow_msg_install(self, request) "delete it" request.command = ofp.OFPFC_DELETE testutils.flow_msg_install(self, request) "receive no flow removed msg" (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) self.assertTrue(response is None, 'Receive flow removed message ') 'read it back , returns blank;' response = testutils.flow_stats_get(self, request.match_fields, request.table_id) self.assertEqual(len(response.stats), 0, "len of stats is:" + str(len(response.stats))) #print(response.show()) msg = create_set_async() set_async_verify(self, msg)
def runTest(self): #self.clean_switch() #print("AsyncGroupDelNoFlowRemoved") #"verifying without set_async, switch will send flow removed" #step 1-1:controller sends set_async msg async_logger.info("Sending set_async") mask = 1 << ofp.OFPRR_GROUP_DELETE request_set = create_set_async(flow_rm_mstr=mask) testutils.ofmsg_send(self, request_set) #result 1-1: contrller sends msg successfully "step 2-1:clear all flow entry" testutils.delete_all_flows(self.controller, async_logger) response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) "step 3-1:add goup entry" group_add_msg = \ groups.create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 10, buckets = [ groups.create_bucket(0, 0, 0, [ groups.create_action(action= ofp.OFPAT_OUTPUT, port= 1) ]) ]) testutils.ofmsg_send(self, group_add_msg) "step 4-1: add an flow entry ,install default mismatch flow entry;" pkt = testutils.simple_tcp_packet() act = groups.create_action(action=ofp.OFPAT_GROUP, group_id=10) request = testutils.flow_msg_create(self, pkt, action_list=[act], table_id=testutils.WC_L3_TABLE, check_expire=True) request.cookie = random.randint(0, 0xffffffffffffffff) testutils.flow_msg_install(self, request) "step 5-1: delete goup entry" group_del_msg = \ groups.create_group_mod_msg(ofp.OFPGC_DELETE, ofp.OFPGT_ALL, group_id = 10, buckets = [ ]) testutils.ofmsg_send(self, group_del_msg) "step 5-1:receive flow removed msg" (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) self.assertTrue(response is not None, 'Receive flow removed message ') self.assertTrue(response.reason == ofp.OFPRR_GROUP_DELETE, 'Not OFPRR_DELETE reason') self.assertTrue(response.cookie == request.cookie, 'Cookie is not equal') #self.assertTrue(response.match_fields == request.match_fields, # 'Match_fields is not equal') #"verifying with set_async, switch will not send flow removed" "step 1-2:controller sends set_async msg" async_logger.info("Sending set_async") mask = 0xffffffff ^ (1 << ofp.OFPRR_GROUP_DELETE) request_set = create_set_async(flow_rm_mstr=mask) testutils.ofmsg_send(self, request_set) "result 1-2: contrller sends msg successfully" "step 2-2:clear all flow entry" testutils.delete_all_flows(self.controller, async_logger) response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) "step 3-2:add goup entry" testutils.ofmsg_send(self, group_add_msg) "step 4-2: add an flow entry ,install default mismatch flow entry;" testutils.flow_msg_install(self, request) "step 5-2: delete goup entry" testutils.ofmsg_send(self, group_del_msg) "step 6-2: receive no flow removed msg" (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) self.assertTrue(response is None, 'Receive flow removed message ') msg = create_set_async() set_async_verify(self, msg)
def runTest(self): #self.clean_switch() #print("AsyncGroupDelNoFlowRemoved") #"verifying without set_async, switch will send flow removed" #step 1-1:controller sends set_async msg async_logger.info("Sending set_async") mask = 1 << ofp.OFPRR_GROUP_DELETE request_set = create_set_async(flow_rm_mstr = mask) testutils.ofmsg_send(self, request_set) #result 1-1: contrller sends msg successfully "step 2-1:clear all flow entry" testutils.delete_all_flows(self.controller, async_logger) response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) "step 3-1:add goup entry" group_add_msg = \ groups.create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 10, buckets = [ groups.create_bucket(0, 0, 0, [ groups.create_action(action= ofp.OFPAT_OUTPUT, port= 1) ]) ]) testutils.ofmsg_send(self, group_add_msg) "step 4-1: add an flow entry ,install default mismatch flow entry;" pkt = testutils.simple_tcp_packet() act = groups.create_action(action= ofp.OFPAT_GROUP, group_id = 10) request = testutils.flow_msg_create(self, pkt, action_list = [act], table_id = testutils.WC_L3_TABLE, check_expire=True) request.cookie = random.randint(0,0xffffffffffffffff) testutils.flow_msg_install(self, request) "step 5-1: delete goup entry" group_del_msg = \ groups.create_group_mod_msg(ofp.OFPGC_DELETE, ofp.OFPGT_ALL, group_id = 10, buckets = [ ]) testutils.ofmsg_send(self, group_del_msg) "step 5-1:receive flow removed msg" (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) self.assertTrue(response is not None, 'Receive flow removed message ') self.assertTrue(response.reason == ofp.OFPRR_GROUP_DELETE, 'Not OFPRR_DELETE reason') self.assertTrue(response.cookie == request.cookie, 'Cookie is not equal') #self.assertTrue(response.match_fields == request.match_fields, # 'Match_fields is not equal') #"verifying with set_async, switch will not send flow removed" "step 1-2:controller sends set_async msg" async_logger.info("Sending set_async") mask = 0xffffffff ^ (1 << ofp.OFPRR_GROUP_DELETE) request_set = create_set_async(flow_rm_mstr = mask) testutils.ofmsg_send(self, request_set) "result 1-2: contrller sends msg successfully" "step 2-2:clear all flow entry" testutils.delete_all_flows(self.controller, async_logger) response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) "step 3-2:add goup entry" testutils.ofmsg_send(self, group_add_msg) "step 4-2: add an flow entry ,install default mismatch flow entry;" testutils.flow_msg_install(self, request) "step 5-2: delete goup entry" testutils.ofmsg_send(self, group_del_msg) "step 6-2: receive no flow removed msg" (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) self.assertTrue(response is None, 'Receive flow removed message ') msg = create_set_async() set_async_verify(self, msg)
def runTest(self): of_ports = async_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") #"verifying without set_async_request, switch will send flow removed" #step 1-1:controller sends set_async_request msg async_logger.info("Sending set_async_request") mask = 1 << ofp.OFPRR_HARD_TIMEOUT request_set = create_set_async(flow_rm_mstr=mask) testutils.ofmsg_send(self, request_set) #result 1-1: contrller sends msg successfully #step 2-1:clear all flow entry testutils.delete_all_flows(self.controller, async_logger) response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) #step 3-1:insert a flow entry: idle_timeout=1 pkt = testutils.simple_tcp_packet() ing_port = of_ports[0] egr_port = of_ports[1] async_logger.info("Ingress " + str(ing_port) + " to egress " + str(egr_port)) request = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=egr_port, table_id=testutils.WC_ALL_TABLE, check_expire=True) request.cookie = random.randint(0, 0xffffffffffffffff) testutils.flow_msg_install(self, request) #step 4-1: wait for 2sec, make sure no ofp_flow_removed msg (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 5) self.assertTrue(response is not None, 'Not receive flow removed message') self.assertTrue(response.reason == ofp.OFPRR_HARD_TIMEOUT, 'Not OFPRR_HARD_TIMEOUT reason') self.assertTrue(response.cookie == request.cookie, 'Cookie is not equal') #self.assertTrue(response.match_fields == request.match_fields, # 'Match_fields is not equal') #step 5-1: verify there is no flow entry async_logger.info("Sending flow request") response = testutils.flow_stats_get(self, request.match_fields, request.table_id) async_logger.debug(response.show()) self.assertEqual(len(response.stats), 0, "len of stats is:" + str(len(response.stats))) #"verifying with set_async_request, switch will not send flow removed" #step 1-2:controller sends set_async_request msg async_logger.info("Sending set_async_request") mask = 0xffffffff ^ (1 << ofp.OFPRR_HARD_TIMEOUT) request_set = create_set_async(flow_rm_mstr=mask) testutils.ofmsg_send(self, request_set) #result 1-2: contrller sends msg successfully #step 2-2:clear all flow entry testutils.delete_all_flows(self.controller, async_logger) response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) #step 3-2:insert a flow entry: idle_timeout=1 async_logger.info("Ingress " + str(ing_port) + " to egress " + str(egr_port)) testutils.flow_msg_install(self, request) #step 4-2: wait for 2sec, make sure no ofp_flow_removed msg (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 5) self.assertTrue(response is None, 'Receive flow removed message ') #step 5-2: verify there is no flow entry async_logger.info("Sending flow request") response = testutils.flow_stats_get(self) async_logger.debug(response.show()) self.assertEqual(len(response.stats), 0, "len of stats is:" + str(len(response.stats))) msg = create_set_async() set_async_verify(self, msg)
def runTest(self): #"verifying with set_async_request, switch will not send flow removed" #step 1-1:controller sends set_async_request msg async_logger.info("Sending set_async_request") of_ports = async_port_map.keys() of_ports.sort() ing_port = of_ports[0] egr_port = of_ports[1] mask = 1 << ofp.OFPRR_DELETE request_set = create_set_async(flow_rm_mstr = mask) testutils.ofmsg_send(self, request_set) #result 1-1: contrller sends msg successfully #"step 2-1:clear all flow entry" testutils.delete_all_flows(self.controller, async_logger) response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) pkt = testutils.simple_tcp_packet( vlan_tags=[{'type': 0x8100, 'vid': 5, 'pcp': 1}]) request = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=egr_port, table_id = testutils.EX_VLAN_TABLE, check_expire=True) request.cookie = random.randint(0,0xffffffffffffffff) testutils.flow_msg_install(self, request) "delete it" request.command = ofp.OFPFC_DELETE testutils.flow_msg_install(self, request) #"receive flow removed msg" (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) self.assertTrue(response is not None, 'Not receive flow removed message ') self.assertTrue(response.reason == ofp.OFPRR_DELETE, 'Not OFPRR_DELETE reason') self.assertTrue(response.cookie == request.cookie, 'Cookie is not equal') #self.assertTrue(response.match_fields == request.match_fields, # 'Match_fields is not equal') #'read it back , returns blank;' response = testutils.flow_stats_get(self, request.match_fields, request.table_id) self.assertEqual(len(response.stats),0, "len of stats is:"+str(len(response.stats))) #print(response.show()) #"verifying with set_async_request, switch will not send flow removed" "step 1-2:controller sends set_async_request msg" async_logger.info("Sending set_async_request") mask = 0xffffffff ^ (1 << ofp.OFPRR_DELETE) request_set = create_set_async(flow_rm_mstr = mask) testutils.ofmsg_send(self, request_set) "result 1-2: contrller sends msg successfully" "step 2-2:clear all flow entry" testutils.delete_all_flows(self.controller, async_logger) response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) #table_id = 3 "add a flow entry" request.command = ofp.OFPFC_ADD testutils.flow_msg_install(self, request) "delete it" request.command = ofp.OFPFC_DELETE testutils.flow_msg_install(self, request) "receive no flow removed msg" (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) self.assertTrue(response is None, 'Receive flow removed message ') 'read it back , returns blank;' response = testutils.flow_stats_get(self, request.match_fields, request.table_id) self.assertEqual(len(response.stats),0, "len of stats is:"+str(len(response.stats))) #print(response.show()) msg = create_set_async() set_async_verify(self, msg)
def runTest(self): #async_logger.info("Running InvalidTTL_NoPacketIn") #"verifying without set_async_request, switch will packet in" #step 1-1:clear all flow entries for unmatching rc = testutils.delete_all_flows(self.controller, async_logger) self.assertEqual(rc, 0, "Failed to delete all flows") #step 2-1:controller sends set_async_request msg async_logger.info("Sending set_async_request") mask = 1 << ofp.OFPR_INVALID_TTL request_set = create_set_async(pkt_in_mstr=mask) testutils.ofmsg_send(self, request_set) #result 2-1: contrller sends msg successfully #step 3-1: install default mismatch flow entry ,action=output; testutils.set_table_config(self) pkt = testutils.simple_tcp_packet(ip_ttl=0) flow_add = testutils.flow_msg_create(self, pkt, egr_port=ofp.OFPP_CONTROLLER, table_id=testutils.WC_L3_TABLE) testutils.flow_msg_install(self, flow_add) #send data(invalid ttl) to port for of_port in async_port_map.keys(): async_logger.info("PKT IN test, port " + str(of_port)) self.dataplane.send(of_port, str(pkt)) #@todo Check for unexpected messages? (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) self.assertTrue(response is not None, 'Can not receive packet in message') #dataplane receive nothing (port_rec, pkt_rec, _) = self.dataplane.poll(of_port, 1) self.assertTrue(pkt_rec is None, "dataplane not receive packet") (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) #"verifying with set_async_request, switch will not packet in" #step 1-2:clear all flow entries for unmatching rc = testutils.delete_all_flows(self.controller, async_logger) self.assertEqual(rc, 0, "Failed to delete all flows") #step 2-2:controller sends set_async_request msg async_logger.info("Sending set_async_request") mask = 0xffffffff ^ (1 << ofp.OFPR_INVALID_TTL) request_set = create_set_async(pkt_in_mstr=mask) testutils.ofmsg_send(self, request_set) #result 2-2: contrller sends msg successfully #step 3-2: install default mismatch flow entry ,action=output; testutils.set_table_config(self) pkt = testutils.simple_tcp_packet(ip_ttl=0) flow_add = testutils.flow_msg_create(self, pkt, egr_port=ofp.OFPP_CONTROLLER, table_id=testutils.WC_L3_TABLE) testutils.flow_msg_install(self, flow_add) #(response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) #send data(invalid ttl) to port for of_port in async_port_map.keys(): async_logger.info("PKT IN test, port " + str(of_port)) self.dataplane.send(of_port, str(pkt)) #@todo Check for unexpected messages? (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) self.assertTrue(response is None, 'Packet in message received unexpected') #dataplane receive nothing (port_rec, pkt_rec, _) = self.dataplane.poll(of_port, 1) self.assertTrue(pkt_rec is None, "dataplane rec packet") msg = create_set_async() set_async_verify(self, msg)
def runTest(self): of_ports = async_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") #"verifying without set_async_request, switch will send flow removed" #step 1-1:controller sends set_async_request msg async_logger.info("Sending set_async_request") mask = 1 << ofp.OFPRR_HARD_TIMEOUT request_set = create_set_async(flow_rm_mstr = mask) testutils.ofmsg_send(self, request_set) #result 1-1: contrller sends msg successfully #step 2-1:clear all flow entry testutils.delete_all_flows(self.controller, async_logger) response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) #step 3-1:insert a flow entry: idle_timeout=1 pkt = testutils.simple_tcp_packet() ing_port = of_ports[0] egr_port = of_ports[1] async_logger.info("Ingress " + str(ing_port) + " to egress " + str(egr_port)) request = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=egr_port, table_id = testutils.WC_ALL_TABLE, check_expire=True) request.cookie = random.randint(0,0xffffffffffffffff) testutils.flow_msg_install(self, request) #step 4-1: wait for 2sec, make sure no ofp_flow_removed msg (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 5) self.assertTrue(response is not None, 'Not receive flow removed message') self.assertTrue(response.reason == ofp.OFPRR_HARD_TIMEOUT, 'Not OFPRR_HARD_TIMEOUT reason') self.assertTrue(response.cookie == request.cookie, 'Cookie is not equal') #self.assertTrue(response.match_fields == request.match_fields, # 'Match_fields is not equal') #step 5-1: verify there is no flow entry async_logger.info("Sending flow request") response = testutils.flow_stats_get(self, request.match_fields, request.table_id) async_logger.debug(response.show()) self.assertEqual(len(response.stats),0, "len of stats is:"+str(len(response.stats))) #"verifying with set_async_request, switch will not send flow removed" #step 1-2:controller sends set_async_request msg async_logger.info("Sending set_async_request") mask = 0xffffffff ^ (1 << ofp.OFPRR_HARD_TIMEOUT) request_set = create_set_async(flow_rm_mstr = mask) testutils.ofmsg_send(self, request_set) #result 1-2: contrller sends msg successfully #step 2-2:clear all flow entry testutils.delete_all_flows(self.controller, async_logger) response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) #step 3-2:insert a flow entry: idle_timeout=1 async_logger.info("Ingress " + str(ing_port) + " to egress " + str(egr_port)) testutils.flow_msg_install(self, request) #step 4-2: wait for 2sec, make sure no ofp_flow_removed msg (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 5) self.assertTrue(response is None, 'Receive flow removed message ') #step 5-2: verify there is no flow entry async_logger.info("Sending flow request") response = testutils.flow_stats_get(self) async_logger.debug(response.show()) self.assertEqual(len(response.stats),0, "len of stats is:"+str(len(response.stats))) msg = create_set_async() set_async_verify(self, msg)