def runTest(self): logging=get_logger() logging.info("Running Grp70No110 forward Enqueue test") of_ports=config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports)>1,"Not enough ports for test") rv=delete_all_flows(self.controller) self.assertTrue(rv==0, "Could not send the delete flow_mod") self.assertEqual(do_barrier(self.controller),0,"Barrier Failed") logging.info("Installing a flow with output action Enqueue") pkt=simple_tcp_packet() match=parse.packet_to_flow_match(pkt) match.wildcards = ofp.OFPFW_ALL msg=message.flow_mod() msg.command = ofp.OFPFC_ADD msg.match=match msg.buffer_id = 0xffffffff act=action.action_enqueue() act.port=of_ports[1] act.queue_id=50 self.assertTrue(msg.actions.add(act),"could not add action to the flow_mod") rc=self.controller.message_send(msg) self.assertTrue(rc!=-1,"Could not send the flow_mod") self.assertEqual(do_barrier(self.controller),0,"Barrier failed") self.dataplane.send(of_ports[0], str(pkt)) receive_pkt_check(self.dataplane, pkt, [of_ports[1]], set(of_ports).difference([of_ports[1]]), self)
def runTest(self): logging.info("Running BadActionTooMany Grp100No190 test") # Clear switch state rc = delete_all_flows(self.controller) self.assertEqual(rc, 0, "Failed to delete all flows") # Create flow_mod message with lot of actions flow_mod_msg = message.flow_mod() # add a lot of actions no = random.randint(2000, 4000) for i in range(0, no): act = action.action_enqueue() self.assertTrue(flow_mod_msg.actions.add(act), "Could not add action") logging.info("Sending flow_mod message...") rv = self.controller.message_send(flow_mod_msg) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") logging.info("Waiting for OFPT_ERROR message...") (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR, timeout=5) self.assertTrue(response is not None, "Switch did not replay with error messge") self.assertTrue(response.type == ofp.OFPET_BAD_ACTION, "Error type is not OFPET_BAD_ACTION") self.assertTrue(response.code == ofp.OFPBAC_TOO_MANY, "Error code is not OFPBAC_TOO_MANY")
def flow_msg_create(parent, pkt, ing_port=None, action_list=None, wildcards=None, egr_ports=None, egr_queue=None, check_expire=False, in_band=False): """ Create a flow message Match on packet with given wildcards. See flow_match_test for other parameter descriptoins @param egr_queue if not None, make the output an enqueue action @param in_band if True, do not wildcard ingress port @param egr_ports None (drop), single port or list of ports """ match = parse.packet_to_flow_match(pkt) parent.assertTrue(match is not None, "Flow match from pkt failed") if wildcards is None: wildcards = required_wildcards(parent) if in_band: wildcards &= ~ofp.OFPFW_IN_PORT match.wildcards = wildcards match.in_port = ing_port if type(egr_ports) == type([]): egr_port_list = egr_ports else: egr_port_list = [egr_ports] request = message.flow_mod() request.match = match request.buffer_id = 0xffffffff if check_expire: request.flags |= ofp.OFPFF_SEND_FLOW_REM request.hard_timeout = 1 if action_list is not None: for act in action_list: logging.debug("Adding action " + act.show()) rv = request.actions.add(act) parent.assertTrue(rv, "Could not add action" + act.show()) # Set up output/enqueue action if directed if egr_queue is not None: parent.assertTrue(egr_ports is not None, "Egress port not set") act = action.action_enqueue() for egr_port in egr_port_list: act.port = egr_port act.queue_id = egr_queue rv = request.actions.add(act) parent.assertTrue(rv, "Could not add enqueue action " + str(egr_port) + " Q: " + str(egr_queue)) elif egr_ports is not None: for egr_port in egr_port_list: act = action.action_output() act.port = egr_port rv = request.actions.add(act) parent.assertTrue(rv, "Could not add output action " + str(egr_port)) logging.debug(request.show()) return request
def flow_msg_create(parent, pkt, ing_port=None, action_list=None, wildcards=None, egr_ports=None, egr_queue=None, check_expire=False, in_band=False): """ Create a flow message Match on packet with given wildcards. See flow_match_test for other parameter descriptoins @param egr_queue if not None, make the output an enqueue action @param in_band if True, do not wildcard ingress port @param egr_ports None (drop), single port or list of ports """ match = parse.packet_to_flow_match(pkt) parent.assertTrue(match is not None, "Flow match from pkt failed") if wildcards is None: wildcards = required_wildcards(parent) if in_band: wildcards &= ~ofp.OFPFW_IN_PORT match.wildcards = wildcards match.in_port = ing_port if type(egr_ports) == type([]): egr_port_list = egr_ports else: egr_port_list = [egr_ports] request = message.flow_mod() request.match = match request.buffer_id = 0xffffffff if check_expire: request.flags |= ofp.OFPFF_SEND_FLOW_REM request.hard_timeout = 1 if action_list is not None: for act in action_list: parent.logger.debug("Adding action " + act.show()) rv = request.actions.add(act) parent.assertTrue(rv, "Could not add action" + act.show()) # Set up output/enqueue action if directed if egr_queue is not None: parent.assertTrue(egr_ports is not None, "Egress port not set") act = action.action_enqueue() for egr_port in egr_port_list: act.port = egr_port act.queue_id = egr_queue rv = request.actions.add(act) parent.assertTrue(rv, "Could not add enqueue action " + str(egr_port) + " Q: " + str(egr_queue)) elif egr_ports is not None: for egr_port in egr_port_list: act = action.action_output() act.port = egr_port rv = request.actions.add(act) parent.assertTrue(rv, "Could not add output action " + str(egr_port)) parent.logger.debug(request.show()) return request
def runTest(self): logging.info("Running Grp100No170 BadActionBadArgument test") rc = delete_all_flows(self.controller) self.assertEqual(rc, 0, "Failed to delete all flows") flow_mod_msg = message.flow_mod() act = action.action_enqueue() act.type = ofp.OFPAT_ENQUEUE act.port = ofp.OFPP_ALL act.queue_id = 1 self.assertTrue(flow_mod_msg.actions.add(act), "Could not add action") rv = self.controller.message_send(flow_mod_msg) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") # flow with modifed arguments flow_mod_msg = message.flow_mod() act = action.action_set_vlan_vid() act.type = ofp.OFPAT_SET_VLAN_VID act.len = 8 act.port = ofp.OFPP_ALL act.vlan_vid = -2 # incorrect vid act.pad = [0, 0] self.assertTrue(flow_mod_msg.actions.add(act), "Could not add action") rv = self.controller.message_send(flow_mod_msg.pack()) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") count = 0 while True: (response, raw) = self.controller.poll(ofp.OFPT_ERROR) if not response: # Timeout break if not response.type == ofp.OFPET_BAD_ACTION: logging.info("Error type not as expected") break if not response.code == ofp.OFPBAC_BAD_ARGUMENT | ofp.OFPBAC_EPERM: logging.info("Error code is not as expected") break if not config["relax"]: # Only one attempt to match break count += 1 if count > 10: # Too many tries break
def runTest(self): logging.info("Running BadActionQueue test") of_ports = config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") #Clear switch state rv = delete_all_flows(self.controller) self.assertEqual(rv, 0, "Failed to delete all flows") #Create a flow with enqueue action pkt = simple_tcp_packet() match = packet_to_flow_match(self, pkt) match.wildcards &= ~ofp.OFPFW_IN_PORT self.assertTrue(match is not None, "Could not generate flow match from pkt") match.in_port = of_ports[0] logging.info("Sending flow_mod message...") request = message.flow_mod() request.match = match act = action.action_enqueue() act.port = of_ports[1] act.queue_id = -1 #Invalid queue_id self.assertTrue(request.actions.add(act), "Could not add action") rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Error installing flow mod") count = 0 logging.info("Waiting for OFPT_ERROR message...") while True: (response, raw) = self.controller.poll(ofp.OFPT_ERROR) if not response: # Timeout break if not response.type == ofp.OFPET_BAD_ACTION: logging.info("Error type not as expected") break if not response.code == ofp.OFPQOFC_BAD_QUEUE: logging.info("Error code is not as expected") break if not config["relax"]: # Only one attempt to match break count += 1 if count > 10: # Too many tries break
def runTest(self): logging = get_logger() logging.info("Running BadActionQueue Grp100No190 test") of_ports = config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") #Clear switch state rv = delete_all_flows(self.controller) self.assertEqual(rv, 0, "Failed to delete all flows") #Create a flow with enqueue action pkt = simple_tcp_packet() match = packet_to_flow_match(self, pkt) match.wildcards &= ~ofp.OFPFW_IN_PORT self.assertTrue(match is not None, "Could not generate flow match from pkt") match.in_port = of_ports[0] logging.info("Sending flow_mod message...") request = message.flow_mod() request.match = match act = action.action_enqueue() act.port = of_ports[1] act.queue_id = 4294967290 #Invalid queue_id self.assertTrue(request.actions.add(act), "Could not add action") rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Error installing flow mod") count = 0 logging.info("Waiting for OFPT_ERROR message...") (response, raw) = self.controller.poll(ofp.OFPT_ERROR, timeout=10) self.assertTrue(response is not None, "Did not receive an error") self.assertTrue( response.type == ofp.OFPET_BAD_ACTION, "Unexpected Error type. Expected OFPET_BAD_ACTION error type") self.assertTrue( response.code == ofp.OFPBAC_BAD_QUEUE, " Unexpected error code, Expected ofp.OFPBAC_BAD_QUEUE error code")
def runTest(self): logging = get_logger() logging.info("Running BadActionQueue Grp100No190 test") of_ports = config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") # Clear switch state rv = delete_all_flows(self.controller) self.assertEqual(rv, 0, "Failed to delete all flows") # Create a flow with enqueue action pkt = simple_tcp_packet() match = packet_to_flow_match(self, pkt) match.wildcards &= ~ofp.OFPFW_IN_PORT self.assertTrue(match is not None, "Could not generate flow match from pkt") match.in_port = of_ports[0] logging.info("Sending flow_mod message...") request = message.flow_mod() request.match = match act = action.action_enqueue() act.port = of_ports[1] act.queue_id = 4294967290 # Invalid queue_id self.assertTrue(request.actions.add(act), "Could not add action") rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Error installing flow mod") count = 0 logging.info("Waiting for OFPT_ERROR message...") (response, raw) = self.controller.poll(ofp.OFPT_ERROR, timeout=10) self.assertTrue(response is not None, "Did not receive an error") self.assertTrue( response.type == ofp.OFPET_BAD_ACTION, "Unexpected Error type. Expected OFPET_BAD_ACTION error type" ) self.assertTrue( response.code == ofp.OFPBAC_BAD_QUEUE, " Unexpected error code, Expected ofp.OFPBAC_BAD_QUEUE error code" )
def enqueue(self,ingress_port,egress_port,egress_queue_id): #Generate a flow with enqueue action i.e output to a queue configured on a egress_port pkt = simple_tcp_packet() match = packet_to_flow_match(self, pkt) match.wildcards &= ~ofp.OFPFW_IN_PORT self.assertTrue(match is not None, "Could not generate flow match from pkt") match.in_port = ingress_port request = message.flow_mod() request.match = match request.buffer_id = 0xffffffff act = action.action_enqueue() act.port = egress_port act.queue_id = egress_queue_id request.actions.add(act) logging.info("Inserting flow") self.controller.message_send(request) do_barrier(self.controller) return (pkt,match)
def enqueue(self,ingress_port,egress_port,egress_queue_id): #Generate a flow with enqueue action i.e output to a queue configured on a egress_port pkt = simple_tcp_packet() match = parse.packet_to_flow_match(pkt) match.wildcards &= ~ofp.OFPFW_IN_PORT self.assertTrue(match is not None, "Could not generate flow match from pkt") match.in_port = ingress_port request = message.flow_mod() request.match = match request.buffer_id = 0xffffffff act = action.action_enqueue() act.port = egress_port act.queue_id = egress_queue_id self.assertTrue(request.actions.add(act), "Could not add action") logging.info("Inserting flow") rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") return (pkt,match)