def runTest(self): logging.info("Outport1 test begins") of_ports = config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") #Clear switch state rc = delete_all_flows(self.controller) self.assertEqual(rc, 0, "Failed to delete all flows") logging.info("Inserting a flow with output action --> of_port[1]") logging.info("Deleting the flow but with out_port set to of_port[2]") logging.info("Expecting switch to filter the delete command") #Build and send Flow-1 with action output to of_port[1] (pkt,match) = Wildcard_All_Except_Ingress(self,of_ports) # Verify active_entries in table_stats_request = 1 Verify_TableStats(self,active_entries=1) #Send delete command matching the flow-1 but with contraint out_port = of_port[2] msg7 = message.flow_mod() msg7.out_port = of_ports[2] msg7.command = ofp.OFPFC_DELETE msg7.buffer_id = 0xffffffff msg7.match = match rv = self.controller.message_send(msg7) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") # Verify flow will not get deleted, active_entries in table_stats_request = 1 Verify_TableStats(self,active_entries=1) logging.info("Deleting the flow with out_port set to of_port[1]") logging.info("Expecting switch to delete the flow") #Send Delete command with contraint out_port = of_ports[1] msg7 = message.flow_mod() msg7.out_port = of_ports[1] msg7.command = ofp.OFPFC_DELETE msg7.buffer_id = 0xffffffff msg7.match = match rv = self.controller.message_send(msg7) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") #Verify flow gets deleted. Verify_TableStats(self,active_entries=0)
def runTest(self): logging.info("Outport1 test begins") of_ports = config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") #Clear switch state rc = delete_all_flows(self.controller) self.assertEqual(rc, 0, "Failed to delete all flows") logging.info("Inserting a flow with output action --> of_port[1]") logging.info("Deleting the flow but with out_port set to of_port[2]") logging.info("Expecting switch to filter the delete command") #Build and send Flow-1 with action output to of_port[1] (pkt, match) = Wildcard_All_Except_Ingress(self, of_ports) # Verify active_entries in table_stats_request = 1 Verify_TableStats(self, active_entries=1) #Send delete command matching the flow-1 but with contraint out_port = of_port[2] msg7 = message.flow_mod() msg7.out_port = of_ports[2] msg7.command = ofp.OFPFC_DELETE msg7.buffer_id = 0xffffffff msg7.match = match rv = self.controller.message_send(msg7) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") # Verify flow will not get deleted, active_entries in table_stats_request = 1 Verify_TableStats(self, active_entries=1) logging.info("Deleting the flow with out_port set to of_port[1]") logging.info("Expecting switch to delete the flow") #Send Delete command with contraint out_port = of_ports[1] msg7 = message.flow_mod() msg7.out_port = of_ports[1] msg7.command = ofp.OFPFC_DELETE msg7.buffer_id = 0xffffffff msg7.match = match rv = self.controller.message_send(msg7) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") #Verify flow gets deleted. Verify_TableStats(self, active_entries=0)
def runTest(self): logging.info("Outport1 test begins") of_ports = config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") #Clear switch state delete_all_flows(self.controller) logging.info("Inserting a flow with output action --> of_port[1]") logging.info("Deleting the flow but with out_port set to of_port[2]") logging.info("Expecting switch to filter the delete command") #Build and send Flow-1 with action output to of_port[1] (pkt,match) = wildcard_all_except_ingress(self,of_ports) # Verify active_entries in table_stats_request = 1 verify_tablestats(self,expect_active=1) #Send delete command matching the flow-1 but with contraint out_port = of_port[2] msg7 = message.flow_mod() msg7.out_port = of_ports[2] msg7.command = ofp.OFPFC_DELETE msg7.buffer_id = 0xffffffff msg7.match = match self.controller.message_send(msg7) do_barrier(self.controller) # Verify flow will not get deleted, active_entries in table_stats_request = 1 verify_tablestats(self,expect_active=1) logging.info("Deleting the flow with out_port set to of_port[1]") logging.info("Expecting switch to delete the flow") #Send Delete command with contraint out_port = of_ports[1] msg7 = message.flow_mod() msg7.out_port = of_ports[1] msg7.command = ofp.OFPFC_DELETE msg7.buffer_id = 0xffffffff msg7.match = match self.controller.message_send(msg7) do_barrier(self.controller) #Verify flow gets deleted. verify_tablestats(self,expect_active=0)
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 Exact_Match(self,of_ports,priority=0): # Generate ExactMatch flow . #Create a simple tcp packet and generate exact flow match from it. Pkt_ExactFlow = simple_tcp_packet() match = parse.packet_to_flow_match(Pkt_ExactFlow) self.assertTrue(match is not None, "Could not generate flow match from pkt") match.in_port = of_ports[0] #match.nw_src = 1 match.wildcards=0 msg = message.flow_mod() msg.out_port = ofp.OFPP_NONE msg.command = ofp.OFPFC_ADD msg.buffer_id = 0xffffffff msg.match = match if priority != 0 : msg.priority = priority act = action.action_output() act.port = of_ports[1] self.assertTrue(msg.actions.add(act), "could not add action") rv = self.controller.message_send(msg) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") return (Pkt_ExactFlow,match)
def match_ethernet_type(self, of_ports, priority=None): #Generate a Match_Ethernet_Type flow #Create a simple tcp packet and generate match on ethernet type flow pkt_matchtype = simple_eth_packet(dl_dst='AC:81:12:99:47:0F', dl_src='da:c9:f1:19:72:cf', dl_type=0x88cc) match = parse.packet_to_flow_match(pkt_matchtype) self.assertTrue(match is not None, "Could not generate flow match from pkt") match.wildcards = ofp.OFPFW_ALL ^ ofp.OFPFW_DL_TYPE msg = message.flow_mod() msg.out_port = ofp.OFPP_NONE msg.command = ofp.OFPFC_ADD msg.buffer_id = 0xffffffff msg.match = match if priority != None: msg.priority = priority act = action.action_output() act.port = of_ports[1] self.assertTrue(msg.actions.add(act), "could not add action") rv = self.controller.message_send(msg) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") return (pkt_matchtype, match)
def Exact_Match(self, of_ports, priority=0): # Generate ExactMatch flow . #Create a simple tcp packet and generate exact flow match from it. Pkt_ExactFlow = simple_tcp_packet() match = parse.packet_to_flow_match(Pkt_ExactFlow) self.assertTrue(match is not None, "Could not generate flow match from pkt") match.in_port = of_ports[0] #match.nw_src = 1 match.wildcards = 0 msg = message.flow_mod() msg.out_port = ofp.OFPP_NONE msg.command = ofp.OFPFC_ADD msg.buffer_id = 0xffffffff msg.match = match if priority != 0: msg.priority = priority act = action.action_output() act.port = of_ports[1] self.assertTrue(msg.actions.add(act), "could not add action") rv = self.controller.message_send(msg) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") return (Pkt_ExactFlow, match)
def runTest(self): logging = get_logger() logging.info("Running FlowModFailed Ordering not possible Grp70No240 test") of_ports = config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") rc = delete_all_flows(self.controller) self.assertTrue(rc != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") msg = message.flow_mod() msg.command = ofp.OFPFC_ADD act1 = action.action_output() act2 = action.action_set_tp_src() act1.port = of_ports[0] act2.tp_port = 8080 self.assertTrue(msg.actions.add(act1), "Could not add action") self.assertTrue(msg.actions.add(act2), "Could not add action") packed=msg.pack() rv=self.controller.message_send(packed) self.assertTrue(rv==0,"Unable to send the message") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") (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_FLOW_MOD_FAILED,"Unexpected Error type. Expected OFPET_FLOW_MOD_FAILED error type got {0}".format(response.type)) self.assertTrue(response.code==ofp.OFPFMFC_UNSUPPORTED," Unexpected error code, Expected ofp.OFPFMFC_UNSUPPORTED error code got {0}" .format(response.code))
def match_mul_l2(self,of_ports,priority=None): #Generate Match_Mul_L2 flow #Create a simple eth packet and generate match on ethernet protocol flow pkt_mulL2 = simple_tcp_packet(dl_vlan_enable=True, dl_src= '00:00:00:01:01:01', dl_dst= '00:00:00:01:01:02', dl_vlan=3) match = parse.packet_to_flow_match(pkt_mulL2) self.assertTrue(match is not None, "Could not generate flow match from pkt") match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_IN_PORT ^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_DL_DST ^ofp.OFPFW_DL_SRC ^ofp.OFPFW_DL_VLAN match.in_port=of_ports[0] msg = message.flow_mod() msg.out_port = ofp.OFPP_NONE msg.command = ofp.OFPFC_ADD msg.buffer_id = 0xffffffff msg.match = match if priority != None : msg.priority = priority act = action.action_output() act.port = of_ports[1] self.assertTrue(msg.actions.add(act), "could not add action") rv = self.controller.message_send(msg) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") return (pkt_mulL2,match)
def runTest(self): basic_logger.info("Running " + str(self)) request = message.flow_mod() request.match.wildcards = ofp.OFPFW_ALL request.buffer_id = 0xffffffff rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Error installing flow mod")
def match_vlan_pcp(self,of_ports,priority=None): #Generate Match_Vlan_Priority #Create a simple tcp packet and generate match on ethernet dst address flow pkt_matchvlanpcp = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=3,dl_vlan_pcp=1) match = parse.packet_to_flow_match(pkt_matchvlanpcp) self.assertTrue(match is not None, "Could not generate flow match from pkt") match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE^ofp.OFPFW_DL_VLAN^ofp.OFPFW_DL_VLAN_PCP msg = message.flow_mod() msg.out_port = ofp.OFPP_NONE msg.command = ofp.OFPFC_ADD msg.buffer_id = 0xffffffff msg.match = match if priority != None : msg.priority = priority act = action.action_output() act.port = of_ports[1] self.assertTrue(msg.actions.add(act), "could not add action") rv = self.controller.message_send(msg) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") return (pkt_matchvlanpcp,match)
def match_ethernet_dst_address(self,of_ports,priority=None): #Generate Match_Ethernet_Dst_Address flow #Create a simple tcp packet and generate match on ethernet dst address flow pkt_matchdst = simple_eth_packet(dl_src='08:00:27:00:d0:07',dl_dst ='78:84:3c:89:fb:5a', dl_type = 0x88cc) match = parse.packet_to_flow_match(pkt_matchdst) self.assertTrue(match is not None, "Could not generate flow match from pkt") match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_DST msg = message.flow_mod() msg.out_port = ofp.OFPP_NONE msg.command = ofp.OFPFC_ADD msg.buffer_id = 0xffffffff msg.match = match if priority != None : msg.priority = priority act = action.action_output() act.port = of_ports[1] self.assertTrue(msg.actions.add(act), "could not add action") rv = self.controller.message_send(msg) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") return (pkt_matchdst,match)
def exact_match(self,of_ports,priority=None): ''' Generates and installs a flow message with all match fields set that are defined for the current conformance profile. The conformance profile is defined as oft optional argument --conformance ["l2", "l3", "full"] ''' pkt_exactflow = simple_tcp_packet() match = parse.packet_to_flow_match(pkt_exactflow) self.assertTrue(match is not None, "Could not generate flow match from pkt") # in_port is not automatically set in parse.packet_to_flow_match match.in_port = of_ports[0] match.wildcards &= ~ofp.OFPFW_IN_PORT #match.nw_src = 1 #match.wildcards=0 msg = message.flow_mod() msg.out_port = ofp.OFPP_NONE msg.command = ofp.OFPFC_ADD msg.buffer_id = 0xffffffff msg.match = match if priority != None : msg.priority = priority act = action.action_output() act.port = of_ports[1] self.assertTrue(msg.actions.add(act), "could not add action") rv = self.controller.message_send(msg) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") return (pkt_exactflow,match)
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_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): logging = get_logger() logging.info( "Running FlowModFailed Unsupported action list Grp100No250 test") msg = message.flow_mod() act1 = action.action_output() act2 = action.action_set_dl_src() act1.port = 99 act2.dl_addr = [11, 11, 11, 11, 11, 11] self.assertTrue(msg.actions.add(act1), "Could not add action") self.assertTrue(msg.actions.add(act2), "Could not add action") packed = msg.pack() rv = self.controller.message_send(packed) self.assertTrue(rv == 0, "Unable to send the 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_FLOW_MOD_FAILED, "Unexpected Error type. Expected OFPET_FLOW_MOD_FAILED error type") self.assertTrue( response.code == ofp.OFPFMFC_UNSUPPORTED or response.code == ofp.OFPFMFC_EPERM, " Unexpected error code, Expected ofp.OFPFMFC_UNSUPPORTED or ofp.OFPFMFC_EPERM error code got{0}" .format(response.code))
def Wildcard_All(self,of_ports,priority=0): # Generate a Wildcard_All Flow #Create a simple tcp packet and generate wildcard all flow match from it. Pkt_Wildcard = simple_tcp_packet() match2 = parse.packet_to_flow_match(Pkt_Wildcard) self.assertTrue(match2 is not None, "Could not generate flow match from pkt") match2.wildcards=ofp.OFPFW_ALL match2.in_port = of_ports[0] msg2 = message.flow_mod() msg2.out_port = ofp.OFPP_NONE msg2.command = ofp.OFPFC_ADD msg2.buffer_id = 0xffffffff msg2.match = match2 act2 = action.action_output() act2.port = of_ports[1] self.assertTrue(msg2.actions.add(act2), "could not add action") if priority != 0 : msg2.priority = priority rv = self.controller.message_send(msg2) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") return (Pkt_Wildcard,match2)
def runTest(self): basic_logger.info("Running StatsGet") basic_logger.info("Inserting trial flow") request = message.flow_mod() request.match.wildcards = ofp.OFPFW_ALL request.buffer_id = 0xffffffff for i in range(1, 5): request.priority = i * 1000 basic_logger.debug("Adding flow %d" % i) rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Failed to insert test flow %d" % i) 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_ALL 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 match_tcp_dst(self,of_ports,priority=None): #Generate Match_Tcp_Dst #Create a simple tcp packet and generate match on tcp destination port flow pkt_matchdst = simple_tcp_packet(tcp_dport=112) match = parse.packet_to_flow_match(pkt_matchdst) self.assertTrue(match is not None, "Could not generate flow match from pkt") match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE^ofp.OFPFW_NW_PROTO^ofp.OFPFW_TP_DST msg = message.flow_mod() msg.out_port = ofp.OFPP_NONE msg.command = ofp.OFPFC_ADD msg.buffer_id = 0xffffffff msg.match = match if priority != None : msg.priority = priority act = action.action_output() act.port = of_ports[1] self.assertTrue(msg.actions.add(act), "could not add action") rv = self.controller.message_send(msg) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") return (pkt_matchdst,match)
def match_arp(self, of_ports, srcb=0, dstb=0, priority=None): arp_pkt = simple_arp_packet() match = parse.packet_to_flow_match(arp_pkt, match_on_arp=True) self.assertTrue(match is not None, "Could not create a match from the packet") if srcb==1: match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE ^(63<<ofp.OFPFW_NW_SRC_SHIFT) elif dstb==1: match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE ^(63<<ofp.OFPFW_NW_DST_SHIFT) else : match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE msg = message.flow_mod() msg.outport = ofp.OFPP_NONE msg.command = ofp.OFPFC_ADD msg.buffer_id = 0xffffffff msg.match=match if priority != None: msg.priority = priority act = action.action_output() act.port = of_ports[1] self.assertTrue(msg.actions.add(act), "could not add action") rv = self.controller.message_send(msg) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") return (arp_pkt,match)
def Wildcard_All(self, of_ports, priority=0): # Generate a Wildcard_All Flow #Create a simple tcp packet and generate wildcard all flow match from it. Pkt_Wildcard = simple_tcp_packet() match2 = parse.packet_to_flow_match(Pkt_Wildcard) self.assertTrue(match2 is not None, "Could not generate flow match from pkt") match2.wildcards = ofp.OFPFW_ALL match2.in_port = of_ports[0] msg2 = message.flow_mod() msg2.out_port = ofp.OFPP_NONE msg2.command = ofp.OFPFC_ADD msg2.buffer_id = 0xffffffff msg2.match = match2 act2 = action.action_output() act2.port = of_ports[1] self.assertTrue(msg2.actions.add(act2), "could not add action") if priority != 0: msg2.priority = priority rv = self.controller.message_send(msg2) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") return (Pkt_Wildcard, match2)
def Wildcard_All_Except_Ingress(self, of_ports, priority=0): # Generate Wildcard_All_Except_Ingress_port flow #Create a simple tcp packet and generate wildcard all except ingress_port flow. Pkt_MatchIngress = simple_tcp_packet() match3 = parse.packet_to_flow_match(Pkt_MatchIngress) self.assertTrue(match3 is not None, "Could not generate flow match from pkt") match3.wildcards = ofp.OFPFW_ALL - ofp.OFPFW_IN_PORT match3.in_port = of_ports[0] msg3 = message.flow_mod() msg3.command = ofp.OFPFC_ADD msg3.match = match3 msg3.out_port = of_ports[2] # ignored by flow add,flow modify msg3.cookie = random.randint(0, 9007199254740992) msg3.buffer_id = 0xffffffff msg3.idle_timeout = 0 msg3.hard_timeout = 0 msg3.buffer_id = 0xffffffff act3 = action.action_output() act3.port = of_ports[1] self.assertTrue(msg3.actions.add(act3), "could not add action") if priority != 0: msg3.priority = priority rv = self.controller.message_send(msg3) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") return (Pkt_MatchIngress, match3)
def Match_All_Except_Source_Address(self, of_ports, priority=0): # Generate Match_All_Except_Source_Address flow #Create a simple tcp packet and generate match all except src address flow. Pkt_WildcardSrc = simple_tcp_packet() match1 = parse.packet_to_flow_match(Pkt_WildcardSrc) self.assertTrue(match1 is not None, "Could not generate flow match from pkt") match1.in_port = of_ports[0] #match1.nw_src = 1 match1.wildcards = ofp.OFPFW_DL_SRC msg1 = message.flow_mod() msg1.out_port = ofp.OFPP_NONE msg1.command = ofp.OFPFC_ADD msg1.buffer_id = 0xffffffff msg1.match = match1 if priority != 0: msg1.priority = priority act1 = action.action_output() act1.port = of_ports[1] self.assertTrue(msg1.actions.add(act1), "could not add action") rv = self.controller.message_send(msg1) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") return (Pkt_WildcardSrc, match1)
def flow_stats_get(self, flow_stats_request, groups): """ Takes an OFMatch structure as parameter and returns a list of the flow_mods that match that structure (implicitly including their stats) Used by pipeline to collect stats on each flow table @todo Decide if we really need to lock the flow_table before processing """ self.flow_sync.acquire() stats = [] fake_flow_mod = message.flow_mod() fake_flow_mod.match = flow_stats_request.match fake_flow_mod.command = ofp.OFPFC_MODIFY # non-strict! for flow in self.flow_entries: # match the out_port if ofps_flow.flow_has_out_port(flow, flow_stats_request.out_port, groups) and \ ofps_flow.flow_has_cookie(flow, flow_stats_request.cookie) and \ flow.match_flow_mod(fake_flow_mod, groups): # found a valid match, now fill in the stats stat = flow.flow_stat_get() stat.table_id = self.table_id stats.append(stat) self.flow_sync.release() return stats
def create_flow_msg(packet = None, in_port = None, match = None, apply_action_list = []): apply_inst = instruction.instruction_apply_actions() if apply_action_list is not None: for act in apply_action_list: apply_inst.actions.add(act) request = message.flow_mod() request.match.type = ofp.OFPMT_OXM if match is None: match = parse.packet_to_flow_match(packet) request.match_fields = match if in_port != None: match_port = testutils.oxm_field.in_port(in_port) request.match_fields.tlvs.append(match_port) request.buffer_id = 0xffffffff request.priority = 1000 request.instructions.add(apply_inst) return request
def exact_match_with_prio(self,of_ports,priority=None): # Generate ExactMatch with action output to port 2 #Create a simple tcp packet and generate exact flow match from it. pkt_exactflow = simple_tcp_packet() match = parse.packet_to_flow_match(pkt_exactflow) self.assertTrue(match is not None, "Could not generate flow match from pkt") match.in_port = of_ports[0] #match.nw_src = 1 match.wildcards=0 msg = message.flow_mod() msg.out_port = ofp.OFPP_NONE msg.command = ofp.OFPFC_ADD msg.buffer_id = 0xffffffff msg.match = match if priority != None : msg.priority = priority act = action.action_output() act.port = of_ports[2] msg.actions.add(act) self.controller.message_send(msg) do_barrier(self.controller) return (pkt_exactflow,match)
def match_ethernet_type(self,of_ports,priority=None): #Generate a Match_Ethernet_Type flow #Create a simple tcp packet and generate match on ethernet type flow pkt_matchtype = simple_eth_packet(dl_type=0x88cc) match = parse.packet_to_flow_match(pkt_matchtype) self.assertTrue(match is not None, "Could not generate flow match from pkt") match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE msg = message.flow_mod() msg.out_port = ofp.OFPP_NONE msg.command = ofp.OFPFC_ADD msg.buffer_id = 0xffffffff msg.match = match if priority != None : msg.priority = priority act = action.action_output() act.port = of_ports[1] self.assertTrue(msg.actions.add(act), "could not add action") rv = self.controller.message_send(msg) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") return (pkt_matchtype,match)
def match_icmp_code(self,of_ports,priority=None): #Generate Match_Icmp_Code #Create a simple icmp packet and generate match on icmp code flow pkt_match = simple_icmp_packet(icmp_code=3) match = parse.packet_to_flow_match(pkt_match) self.assertTrue(match is not None, "Could not generate flow match from pkt") match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_NW_PROTO ^ofp.OFPFW_TP_DST msg = message.flow_mod() msg.out_port = ofp.OFPP_NONE msg.command = ofp.OFPFC_ADD msg.buffer_id = 0xffffffff msg.match = match if priority != None : msg.priority = priority act = action.action_output() act.port = of_ports[1] msg.actions.add(act) self.controller.message_send(msg) do_barrier(self.controller) return (pkt_match, match)
def Wildcard_All_Except_Ingress(self,of_ports,priority=0): # Generate Wildcard_All_Except_Ingress_port flow #Create a simple tcp packet and generate wildcard all except ingress_port flow. Pkt_MatchIngress = simple_tcp_packet() match3 = parse.packet_to_flow_match(Pkt_MatchIngress) self.assertTrue(match3 is not None, "Could not generate flow match from pkt") match3.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT match3.in_port = of_ports[0] msg3 = message.flow_mod() msg3.command = ofp.OFPFC_ADD msg3.match = match3 msg3.out_port = of_ports[2] # ignored by flow add,flow modify msg3.cookie = random.randint(0,9007199254740992) msg3.buffer_id = 0xffffffff msg3.idle_timeout = 0 msg3.hard_timeout = 0 msg3.buffer_id = 0xffffffff act3 = action.action_output() act3.port = of_ports[1] self.assertTrue(msg3.actions.add(act3), "could not add action") if priority != 0 : msg3.priority = priority rv = self.controller.message_send(msg3) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") return (Pkt_MatchIngress,match3)
def match_all_except_source_address(self,of_ports,priority=None): # Generate Match_All_Except_Source_Address flow #Create a simple tcp packet and generate match all except src address flow. pkt_wildcardsrc= simple_tcp_packet() match1 = parse.packet_to_flow_match(pkt_wildcardsrc) self.assertTrue(match1 is not None, "Could not generate flow match from pkt") match1.in_port = of_ports[0] #match1.nw_src = 1 match1.wildcards = ofp.OFPFW_DL_SRC msg1 = message.flow_mod() msg1.out_port = ofp.OFPP_NONE msg1.command = ofp.OFPFC_ADD msg1.buffer_id = 0xffffffff msg1.match = match1 if priority != None : msg1.priority = priority act1 = action.action_output() act1.port = of_ports[1] msg1.actions.add(act1) self.controller.message_send(msg1) do_barrier(self.controller) return (pkt_wildcardsrc,match1)
def Match_All_Except_Source_Address(self,of_ports,priority=0): # Generate Match_All_Except_Source_Address flow #Create a simple tcp packet and generate match all except src address flow. Pkt_WildcardSrc= simple_tcp_packet() match1 = parse.packet_to_flow_match(Pkt_WildcardSrc) self.assertTrue(match1 is not None, "Could not generate flow match from pkt") match1.in_port = of_ports[0] #match1.nw_src = 1 match1.wildcards = ofp.OFPFW_DL_SRC msg1 = message.flow_mod() msg1.out_port = ofp.OFPP_NONE msg1.command = ofp.OFPFC_ADD msg1.buffer_id = 0xffffffff msg1.match = match1 if priority != 0 : msg1.priority = priority act1 = action.action_output() act1.port = of_ports[1] self.assertTrue(msg1.actions.add(act1), "could not add action") rv = self.controller.message_send(msg1) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") return (Pkt_WildcardSrc,match1)
def match_vlan_pcp(self,of_ports,priority=None): #Generate Match_Vlan_Priority #Create a simple tcp packet and generate match on ethernet dst address flow pkt_matchvlanpcp = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=1,dl_vlan_pcp=5) match = parse.packet_to_flow_match(pkt_matchvlanpcp) self.assertTrue(match is not None, "Could not generate flow match from pkt") match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE^ofp.OFPFW_DL_VLAN^ofp.OFPFW_DL_VLAN_PCP msg = message.flow_mod() msg.out_port = ofp.OFPP_NONE msg.command = ofp.OFPFC_ADD msg.buffer_id = 0xffffffff msg.match = match if priority != None : msg.priority = priority act = action.action_output() act.port = of_ports[1] self.assertTrue(msg.actions.add(act), "could not add action") rv = self.controller.message_send(msg) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") return (pkt_matchvlanpcp,match)
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): 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): global fe_port_map # TODO: set from command-line parameter test_timeout = 60 of_ports = fe_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") rc = delete_all_flows(self.controller, fe_logger) self.assertEqual(rc, 0, "Failed to delete all flows") 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") act = action.action_output() of_ports = fe_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] fe_logger.info("Ingress " + str(ingress_port) + " to egress " + str(egress_port)) match.in_port = ingress_port request = message.flow_mod() request.match = match request.cookie = random.randint(0, 9007199254740992) request.buffer_id = 0xffffffff request.idle_timeout = 1 request.flags |= ofp.OFPFF_SEND_FLOW_REM act.port = egress_port self.assertTrue(request.actions.add(act), "Could not add action") fe_logger.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") (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED, timeout=test_timeout) self.assertTrue(response is not None, 'Did not receive flow removed message ') self.assertEqual(request.cookie, response.cookie, 'Cookies do not match') self.assertEqual( ofp.OFPRR_IDLE_TIMEOUT, response.reason, 'Flow table entry removal reason is not idle_timeout') self.assertEqual(match, response.match, 'Flow table entry does not match')
def runTest(self): logging = get_logger() logging.info("Running FlowModFailed Unsupported action list Grp100No250 test") msg = message.flow_mod() act1 = action.action_output() act2 = action.action_set_dl_src() act1.port = 99 act2.dl_addr = [11, 11, 11, 11, 11, 11] self.assertTrue(msg.actions.add(act1), "Could not add action") self.assertTrue(msg.actions.add(act2), "Could not add action") packed = msg.pack() rv = self.controller.message_send(packed) self.assertTrue(rv == 0, "Unable to send the 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_FLOW_MOD_FAILED, "Unexpected Error type. Expected OFPET_FLOW_MOD_FAILED error type", ) self.assertTrue( response.code == ofp.OFPFMFC_UNSUPPORTED or response.code == ofp.OFPFMFC_EPERM, " Unexpected error code, Expected ofp.OFPFMFC_UNSUPPORTED or ofp.OFPFMFC_EPERM error code got{0}".format( response.code ), )
def runTest(self): logging.info("Delete_NonExisting_Flow test begins") of_ports = config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") #Clear switch state rc = delete_all_flows(self.controller) self.assertEqual(rc, 0, "Failed to delete all flows") logging.info("Deleting a non-existing flow") logging.info( "Expecting switch to ignore the command , without generating errors" ) # Issue a delete command msg = message.flow_mod() msg.match.wildcards = ofp.OFPFW_ALL msg.out_port = ofp.OFPP_NONE msg.command = ofp.OFPFC_DELETE msg.buffer_id = 0xffffffff # Verify no message or error is generated by polling the the control plane (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR, timeout=2) self.assertTrue(response is None, 'Recieved Error for deleting non-exiting flow ')
def runTest(self): logging.info("Running Missing_Modify_Add test") of_ports = config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") logging.info("Inserting a flow-modify that does not match an existing flow") logging.info("Expecting flow to get added i.e OFPFC_MODIFY command should be taken as OFPFC_ADD ") #Clear Switch State rc = delete_all_flows(self.controller) self.assertEqual(rc, 0, "Failed to delete all flows") #Generate a flow-mod,command OFPC_MODIFY request = message.flow_mod() request.command = ofp.OFPFC_MODIFY request.match.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT request.match.in_port = of_ports[0] request.cookie = random.randint(0,9007199254740992) request.buffer_id = 0xffffffff act3 = action.action_output() act3.port = of_ports[1] self.assertTrue(request.actions.add(act3), "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") #Verify the flow gets added i.e. active_count= 1 Verify_TableStats(self,active_entries=1)
def runTest(self): logging.info("Delete_NonExisting_Flow test begins") of_ports = config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") #Clear switch state rc = delete_all_flows(self.controller) self.assertEqual(rc, 0, "Failed to delete all flows") logging.info("Deleting a non-existing flow") logging.info("Expecting switch to ignore the command , without generating errors") # Issue a delete command msg = message.flow_mod() msg.match.wildcards = ofp.OFPFW_ALL msg.out_port = ofp.OFPP_NONE msg.command = ofp.OFPFC_DELETE msg.buffer_id = 0xffffffff # Verify no message or error is generated by polling the the control plane (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR, timeout=2) self.assertTrue(response is None, 'Recieved Error for deleting non-exiting flow ')
def runTest(self): logging = get_logger() logging.info("Delete_NonExisting_Flow Grp40No110 test begins") of_ports = config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") #Clear switch state rc = delete_all_flows(self.controller) self.assertEqual(rc, 0, "Failed to delete all flows") logging.info("Deleting a non-existing flow") # Issue a delete command msg = message.flow_mod() msg.match.wildcards = ofp.OFPFW_ALL msg.out_port = ofp.OFPP_NONE msg.command = ofp.OFPFC_DELETE msg.buffer_id = 0xffffffff rv=self.controller.message_send(msg) self.assertTrue(rv != -1, "Flow deletion message could not be sent.") # Verify no message or error is generated by polling the the control plane logging.info("Verifying the Controller doesnt receive any ERROR message") (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR, timeout=2) self.assertTrue(response is None, 'Recieved Error for deleting non-exiting flow ')
def runTest(self): logging = get_logger() logging.info("Running Grp100No160 BadActionBadArgument test") rc = delete_all_flows(self.controller) self.assertEqual(rc, 0, "Failed to delete all flows") of_ports=config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports)>1, "not enough ports for test") # flow with modifed arguments flow_mod_msg = message.flow_mod() flow_mod_msg.match.in_port = of_ports[0] flow_mod_msg.match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_SRC act = action.action_set_vlan_vid() act.type = ofp.OFPAT_SET_VLAN_VID act.len = 8 act.port = of_ports[1] act.vlan_vid = 5000 # 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") (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 {0}. Expected OFPET_BAD_ACTION error type" .format(response.type)) self.assertTrue(response.code==ofp.OFPBAC_BAD_ARGUMENT or response.code == ofp.OFPBAC_EPERM," Unexpected error code, Expected ofp.OFPBAC_BAD_ARGUMENT or ofp.OFPBAC_EPERM error code got {0}" .format(response.code))
def runTest(self): logging = get_logger() logging.info("Running Grp40No220 Idle_Timeout test ") of_ports = config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") #Clear switch state rc = delete_all_flows(self.controller) self.assertEqual(rc, 0, "Failed to delete all flows") logging.info("Inserting flow entry with idle_timeout set. Also send_flow_removed_message flag set") #Insert a flow entry with idle_timeout=2.Send_Flow_Rem flag set msg9 = message.flow_mod() msg9.match.wildcards = ofp.OFPFW_ALL msg9.cookie = random.randint(0,9007199254740992) msg9.buffer_id = 0xffffffff msg9.idle_timeout = 2 msg9.flags |= ofp.OFPFF_SEND_FLOW_REM rv1 = self.controller.message_send(msg9) self.assertTrue(rv1 != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") # Verify flow removed message is recieved. logging.info("Verifying whether OFPT_FLOW_REMOVED message is received") (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED, timeout=5) self.assertTrue(response is not None, 'Did not receive flow removed message ') self.assertEqual(ofp.OFPRR_IDLE_TIMEOUT, response.reason, 'Flow table entry removal reason is not idle_timeout') self.assertEqual(2, response.duration_sec, 'Flow was not alive for 1 sec')
def runTest(self): logging = get_logger() logging.info("Running Grp40No80 Missing_Modify_Add test") of_ports = config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") #Clear Switch State rc = delete_all_flows(self.controller) self.assertEqual(rc, 0, "Failed to delete all flows") #Generate a flow-mod,command OFPC_MODIFY logging.info("Sending a flow_mod message to the switch") request = message.flow_mod() request.command = ofp.OFPFC_MODIFY request.match.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT request.match.in_port = of_ports[0] request.cookie = random.randint(0,9007199254740992) request.buffer_id = 0xffffffff act3 = action.action_output() act3.port = of_ports[1] self.assertTrue(request.actions.add(act3), "could not add action") rv = self.controller.message_send(request) logging.info("expecting the fow_mod to add a flow in the absence of a matching flow entry") self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") logging.info("Verifying whether the flow_mod message has added a flow") rv=all_stats_get(self) self.assertTrue(rv["flows"]==1,"Flow_mod message did not install the flow in the absence of a matching flow entry")
def runTest(self): msg, pkt = self.controller.transact(message.table_stats_request()) num_flows = msg.stats[0].max_entries requests = [] for i in range(num_flows): match = ofp.ofp_match() match.wildcards = ofp.OFPFW_ALL & ~ofp.OFPFW_DL_VLAN & ~ofp.OFPFW_DL_DST match.dl_vlan = ofp.OFP_VLAN_NONE match.dl_dst = [0, 1, 2, 3, i / 256, i % 256] act = action.action_output() act.port = ofp.OFPP_CONTROLLER request = message.flow_mod() request.command = ofp.OFPFC_ADD request.buffer_id = 0xffffffff request.priority = num_flows - i request.out_port = ofp.OFPP_NONE request.match = match request.actions.add(act) requests.append(request) for i in range(5): logging.info("Iteration %d: delete all flows" % i) self.assertEqual(delete_all_flows(self.controller), 0, "Failed to delete all flows") self.checkBarrier() logging.info("Iteration %d: add %s flows" % (i, num_flows)) for request in requests: self.assertNotEqual(self.controller.message_send(request), -1, "Error installing flow mod") self.checkBarrier()
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 runTest(self): logging = get_logger() logging.info("Running Grp30No10 Flood testcase") of_ports = config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports) > 2, "Not enough ports for test") logging.info("Setting all ports to no_flood") for i in range(len(of_ports)): (hw_addr, port_config, advert) = \ port_config_get(self.controller, of_ports[i]) logging.info("Extracting the port configuration from the reply") self.assertTrue( port_config is not None, "Did not get port config of port {0}".format(of_ports[i])) if ((port_config & ofp.OFPPC_NO_FLOOD) == 0): rv = port_config_set(self.controller, of_ports[i], port_config ^ ofp.OFPPC_NO_FLOOD, ofp.OFPPC_NO_FLOOD) self.assertTrue(rv != -1, "could not send the port config set message") (hw_addr, port_config, advert) = \ port_config_get(self.controller, of_ports[1]) logging.info("Extracting the port configuration from the reply") self.assertTrue(port_config is not None, "Did not get port config") rv = port_config_set(self.controller, of_ports[1], port_config ^ ofp.OFPPC_NO_FLOOD, ofp.OFPPC_NO_FLOOD) self.assertTrue(rv != -1, "Could not send the port config message") pkt_exactflow = simple_tcp_packet() match = parse.packet_to_flow_match(pkt_exactflow) self.assertTrue(match is not None, "Could not generate flow match from pkt") match.in_port = of_ports[0] match.wildcards = 0 msg = message.flow_mod() msg.out_port = ofp.OFPP_NONE msg.command = ofp.OFPFC_ADD msg.buffer_id = 0xffffffff msg.match = match act = action.action_output() act.port = ofp.OFPP_FLOOD self.assertTrue(msg.actions.add(act), "could not add action") rv = self.controller.message_send(msg) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") self.dataplane.send(of_ports[0], str(pkt_exactflow)) receive_pkt_check(self.dataplane, pkt_exactflow, [of_ports[1]], set(of_ports).difference([of_ports[1]]), self) # Set ports back to default flood behavior for port in of_ports: rv = port_config_set(self.controller, port, port_config & ~ofp.OFPPC_NO_FLOOD, ofp.OFPPC_NO_FLOOD) self.assertTrue(rv != -1, "Could not send the port config message")
def runTest(self): logging = get_logger() logging.info("Delete_NonExisting_Flow Grp40No110 test begins") of_ports = config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") #Clear switch state rc = delete_all_flows(self.controller) self.assertEqual(rc, 0, "Failed to delete all flows") logging.info("Deleting a non-existing flow") # Issue a delete command msg = message.flow_mod() msg.match.wildcards = ofp.OFPFW_ALL msg.out_port = ofp.OFPP_NONE msg.command = ofp.OFPFC_DELETE msg.buffer_id = 0xffffffff rv = self.controller.message_send(msg) self.assertTrue(rv != -1, "Flow deletion message could not be sent.") # Verify no message or error is generated by polling the the control plane logging.info( "Verifying the Controller doesnt receive any ERROR message") (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR, timeout=2) self.assertTrue(response is None, 'Recieved Error for deleting non-exiting flow ')
def runTest(self): of_ports = ipv6_port_map.keys() of_ports.sort() ing_port = of_ports[0] egr_port = of_ports[3] # Remove all entries Add entry match all rc = testutils.delete_all_flows(self.controller, ipv6_logger) self.assertEqual(rc, 0, "Failed to delete all flows") # Add entry match request = message.flow_mod() request.match.type = ofp.OFPMT_OXM port = match.in_port(of_ports[0]) eth_type = match.eth_type(IPV6_ETHERTYPE) ipv6_src = match.ipv6_src(ipaddr.IPv6Address('fe80::2420:52ff:fe8f:5189')) request.match_fields.tlvs.append(port) request.match_fields.tlvs.append(eth_type) request.match_fields.tlvs.append(ipv6_src) field_2b_set = match.ipv6_dst(ipaddr.IPv6Address('fe80::2420:52ff:fe8f:DDDD')) act_setfield = action.action_set_field() act_setfield.field = field_2b_set # TODO: insert action set field properly act_out = action.action_output() act_out.port = of_ports[3] inst = instruction.instruction_apply_actions() inst.actions.add(act_setfield) inst.actions.add(act_out) request.instructions.add(inst) request.buffer_id = 0xffffffff request.priority = 1000 ipv6_logger.debug("Adding flow ") rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Failed to insert test flow") #Send packet pkt = testutils.simple_ipv6_packet(ip_src='fe80::2420:52ff:fe8f:5189',ip_dst='fe80::2420:52ff:fe8f:5190') ipv6_logger.info("Sending IPv6 packet to " + str(ing_port)) ipv6_logger.debug("Data: " + str(pkt).encode('hex')) self.dataplane.send(ing_port, str(pkt)) #Receive packet exp_pkt = testutils.simple_ipv6_packet(ip_dst='fe80::2420:52ff:fe8f:DDDD') testutils.receive_pkt_verify(self, egr_port, exp_pkt) #See flow match response = testutils.flow_stats_get(self) ipv6_logger.debug("Response" + response.show()) #Remove flows rc = testutils.delete_all_flows(self.controller, ipv6_logger) self.assertEqual(rc, 0, "Failed to delete all flows")
def runTest(self): logging.info("Running FlowModFailed Unsupported action list Grp100No250 test") msg = message.flow_mod() act1 = action.action_output() act2 = action.action_set_dl_src() act1.port = 99 act2.dl_addr = [11, 11, 11, 11, 11, 11] self.assertTrue(msg.actions.add(act1), "Could not add action") self.assertTrue(msg.actions.add(act2), "Could not add action") packed = msg.pack() rv = self.controller.message_send(packed) self.assertTrue(rv == 0, "Unable to send the message") (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR) count = 0 while True: (response, raw) = self.controller.poll(ofp.OFPT_ERROR) if not response: # Timeout break if not response.type == ofp.OFPET_FLOW_MOD_FAILED: logging.info("Error Type is not as expected") break if response.code == ofp.OFPFMFC_UNSUPPORTED | ofp.OFPFMFC_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): 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 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 = get_logger() logging.info("Running Grp30No80 Flood bits Test") of_ports = config["port_map"].keys() of_ports.sort() for i in range(len(of_ports)): #Retrieve Port Configuration --- logging.info("Sending Features Request") (hw_addr, port_config, advert) = \ port_config_get(self.controller, of_ports[i]) #Modify Port Configuration logging.info("Setting OFPPC_NO_FLOOD bit to 0 on %s" % str(of_ports[i])) logging.info("Port config is set to: {0}".format( bin(port_config & ~ofp.OFPPC_NO_FLOOD))) if (i % 2): rv = port_config_set(self.controller, of_ports[i], port_config & ~ofp.OFPPC_NO_FLOOD, ofp.OFPPC_NO_FLOOD) else: rv = port_config_set(self.controller, of_ports[i], port_config | ofp.OFPPC_NO_FLOOD, ofp.OFPPC_NO_FLOOD) self.assertTrue(rv != -1, "Error sending port mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") #Sending a flow with output action on flood ports logging.info("Sending flow_mod message..") pkt = simple_tcp_packet() match = parse.packet_to_flow_match(pkt) self.assertTrue(match is not None, "Could not generate flow match from pkt") match.wildcards = ofp.OFPFW_ALL ^ ofp.OFPFW_NW_DST_MASK match.nw_dst = parse.parse_ip("244.0.0.1") flow_mod_msg = message.flow_mod() flow_mod_msg.match = match flow_mod_msg.command = ofp.OFPFC_ADD act = action.action_output() act.port = ofp.OFPP_FLOOD 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") #Sending packet to check if flood ports respond pkt_check = simple_tcp_packet(ip_dst="244.0.0.1") self.dataplane.send(of_ports[0], str(pkt_check)) yes_ports = no_ports = set(of_ports) for i in range(len(of_ports)): if (i % 2): no_ports = no_ports.difference([of_ports[i]]) else: yes_ports = yes_ports.difference([of_ports[i]]) receive_pkt_check(self.dataplane, pkt_check, yes_ports, no_ports, self)
def runTest(self): logging = get_logger() logging.info("Running Grp40No10 Overlap_Checking test") of_ports = config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") #Clear Switch State rc = delete_all_flows(self.controller) self.assertEqual(rc, 0, "Failed to delete all flows") logging.info("Installing an all wildcarded flow") #Insert a flow F with wildcarded all fields (pkt, match) = wildcard_all(self, of_ports) #Verify flow is active #verify_tablestats(self,expect_active=1) # Build a overlapping flow F'-- Wildcard All except ingress with check overlap bit set logging.info( "Installing a overlapping flow with check_overlap bit set") pkt_matchingress = simple_tcp_packet() match3 = parse.packet_to_flow_match(pkt_matchingress) self.assertTrue(match3 is not None, "Could not generate flow match from pkt") match3.wildcards = ofp.OFPFW_ALL - ofp.OFPFW_IN_PORT match3.in_port = of_ports[0] msg3 = message.flow_mod() msg3.command = ofp.OFPFC_ADD msg3.match = match3 msg3.flags |= ofp.OFPFF_CHECK_OVERLAP msg3.cookie = random.randint(0, 9007199254740992) msg3.buffer_id = 0xffffffff act3 = action.action_output() act3.port = of_ports[1] self.assertTrue(msg3.actions.add(act3), "could not add action") rv = self.controller.message_send(msg3) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") # Verify Flow does not get inserted #verify_tablestats(self,expect_active=1) #Verify OFPET_FLOW_MOD_FAILED/OFPFMFC_OVERLAP error is recieved on the control plane logging.info("waiting for the switch to respond with an error") (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR, timeout=5) self.assertTrue(response is not None, 'Switch did not reply with error message') self.assertTrue(response.type == ofp.OFPET_FLOW_MOD_FAILED, 'Error message type is not flow mod failed ') self.assertTrue(response.code == ofp.OFPFMFC_OVERLAP, 'Error Message code is not overlap') logging.info("Flow_mod error received")
def runTest(self): logging = get_logger() logging.info("Running Grp40No210 Flow_Timeout test ") of_ports = config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") #Clear switch state rc = delete_all_flows(self.controller) self.assertEqual(rc, 0, "Failed to delete all flows") logging.info( "Inserting flow entry with hard_timeout set and send_flow_removed_message flag set" ) # Insert a flow with hard_timeout = 1 but no Send_Flow_Rem flag set pkt = simple_tcp_packet() match3 = parse.packet_to_flow_match(pkt) self.assertTrue(match3 is not None, "Could not generate flow match from pkt") match3.wildcards = ofp.OFPFW_ALL - ofp.OFPFW_IN_PORT match3.in_port = of_ports[0] msg3 = message.flow_mod() #msg3.out_port = of_ports[1] # ignored by flow add,flow modify msg3.command = ofp.OFPFC_ADD msg3.cookie = random.randint(0, 9007199254740992) msg3.buffer_id = 0xffffffff msg3.hard_timeout = 1 msg3.flags |= ofp.OFPFF_SEND_FLOW_REM msg3.match = match3 act3 = action.action_output() act3.port = of_ports[1] self.assertTrue(msg3.actions.add(act3), "could not add action") rv = self.controller.message_send(msg3) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") pkt = str(simple_tcp_packet()) #Send data plane traffic in background t = Thread(target=self.background_traffic, args=( of_ports[0], pkt, )) t.start() #Verify no flow removed message is generated logging.info( "Verifying that there is OFPT_FLOW_REMOVED message received") (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED, timeout=3) self.assertTrue(response is not None, 'Did not receive the flow removed message') # Verify flow was alive for 1 sec self.assertEqual(response.duration_sec, 1, 'Flow was not alive for 1 sec') t.join()