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): 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): 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, wildcards=~ofp.OFPFW_IN_PORT) flow_mod.buffer_id = 0xffffffff pa_logger.info(flow_mod.show()) pa_logger.info("Inserting flow") rv = self.controller.message_send(flow_mod) self.assertTrue(rv != -1, "Error installing flow mod") testutils.do_barrier(self.controller) 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): # Set up flow to send from port 1 to port 2 and copy to CPU # Test parameter gives LB port base (assumes consecutive) lb_port = test_param_get('lb_port', default=1) barrier_count = test_param_get('barrier_count', default=10) # Set controller to filter packet ins self.controller.filter_packet_in = True self.controller.pkt_in_filter_limit = 10 pkt = simple_tcp_packet() match = packet_to_flow_match(self, pkt) match.wildcards &= ~ofp.OFPFW_IN_PORT match.in_port = lb_port act = action.action_output() act.port = lb_port + 1 request = message.flow_mod() request.match = match request.hard_timeout = 2 * barrier_count request.buffer_id = 0xffffffff self.assertTrue(request.actions.add(act), "Could not add action") act = action.action_output() act.port = ofp.OFPP_CONTROLLER self.assertTrue(request.actions.add(act), "Could not add action") rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") # Create packet out and send to port lb_port + 1 msg = message.packet_out() msg.in_port = lb_port msg.data = str(pkt) act = action.action_output() act.port = lb_port + 1 self.assertTrue(msg.actions.add(act), 'Could not add action to msg') logging.info("Sleeping before starting storm") time.sleep(1) # Root causing issue with fast disconnects logging.info("Sending packet out to %d" % (lb_port + 1)) rv = self.controller.message_send(msg) self.assertTrue(rv == 0, "Error sending out message") for idx in range(0, barrier_count): self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") # To do: Add some interesting functionality here logging.info("Barrier %d completed" % idx) # Clear the flow table when done logging.debug("Deleting all flows from switch") rc = delete_all_flows(self.controller) self.assertEqual(rc, 0, "Failed to delete all flows")
def runTest(self): # Set up flow to send from port 1 to port 2 and copy to CPU # Test parameter gives LB port base (assumes consecutive) lb_port = test_param_get(self.config, 'lb_port', default=1) barrier_count = test_param_get(self.config, 'barrier_count', default=10) # Set controller to filter packet ins self.controller.filter_packet_in = True self.controller.pkt_in_filter_limit = 10 pkt = simple_tcp_packet() match = packet_to_flow_match(self, pkt) match.wildcards &= ~ofp.OFPFW_IN_PORT match.in_port = lb_port act = action.action_output() act.port = lb_port + 1 request = message.flow_mod() request.match = match request.hard_timeout = 2 * barrier_count request.buffer_id = 0xffffffff self.assertTrue(request.actions.add(act), "Could not add action") act = action.action_output() act.port = ofp.OFPP_CONTROLLER self.assertTrue(request.actions.add(act), "Could not add action") rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Error installing flow mod") self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") # Create packet out and send to port lb_port + 1 msg = message.packet_out() msg.data = str(pkt) act = action.action_output() act.port = lb_port + 1 self.assertTrue(msg.actions.add(act), 'Could not add action to msg') load_logger.info("Sleeping before starting storm") time.sleep(1) # Root causing issue with fast disconnects load_logger.info("Sending packet out to %d" % (lb_port + 1)) rv = self.controller.message_send(msg) self.assertTrue(rv == 0, "Error sending out message") for idx in range(0, barrier_count): self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") # To do: Add some interesting functionality here load_logger.info("Barrier %d completed" % idx) # Clear the flow table when done load_logger.debug("Deleting all flows from switch") rc = delete_all_flows(self.controller, load_logger) self.assertEqual(rc, 0, "Failed to delete all flows")
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 Grp100No160 BadActionBadPort test") # pick a random bad port number bad_port = ofp.OFPP_MAX pkt = simple_tcp_packet() act = action.action_output() # Send flow_mod message logging.info("Sending flow_mod message..") request = flow_msg_create(self, pkt, ing_port=1, egr_ports=bad_port) rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Unable to send the message") count = 0 # poll for error message logging.info("Waiting for OFPT_ERROR message...") while True: (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR, timeout=5) if not response: # Timeout break if not response.type == ofp.OFPET_BAD_ACTION | ofp.OFPET_FLOW_MOD_FAILED: logging.info("Error type is not as expected") break if not response.code == ofp.OFPPMFC_BAD_PORT | ofp.OFPFMFC_EPERM: logging.info("Error field 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 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 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 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_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 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 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 runTest(self): logging = get_logger() logging.info("Runnign Grp90No150 testcase") of_ports = config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports) >= 1, "Not enough ports for test") msg = message.packet_out() msg.bufer_id = -1 msg.in_port = ofp.OFPP_NONE act = action.action_output() act.port = of_ports[0] msg.actions.add(act) pkt = simple_tcp_packet() msg.data = str(pkt) self.controller.message_send(msg) error, _ = self.controller.poll(exp_msg=ofp.OFPT_ERROR) if error: msg.in_port = ofp.OFPP_CONTROLLER self.controller.message_send(msg) error, _ = self.controller.poll(exp_msg=ofp.OFPT_ERROR) self.assertIsNone( error, "Error sending out packet out message.Got OFPT_ERROR") logging.info("Packet Out sent with in_port as OFPP_CONTROLLER") receive_pkt_check(self.dataplane, pkt, [of_ports[0]], set(of_ports).difference([of_ports[0]]), self)
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 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_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): 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): 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) + " to all ports") actions = [] for egress_port in of_ports: act = action.action_output() if egress_port == ingress_port: act.port = ofp.OFPP_IN_PORT else: act.port = egress_port actions.append(act) request = testutils.flow_msg_create(self, pkt, ingress_port, action_list=actions) request.buffer_id = 0xffffffff # pa_logger.info(request.show()) pa_logger.info("Inserting flow") rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Error installing flow mod") testutils.do_barrier(self.controller) 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 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 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 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_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_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 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 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): 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 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): 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): 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 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 runTest(self): # Construct packet to send to dataplane # Send packet to dataplane # Poll controller with expect message type packet in rc = delete_all_flows(self.controller, basic_logger) self.assertEqual(rc, 0, "Failed to delete all flows") # These will get put into function of_ports = basic_port_map.keys() random.shuffle(of_ports) for num_ports in range(1,len(of_ports)+1): for outpkt, opt in [ (simple_tcp_packet(), "simple TCP packet"), (simple_eth_packet(), "simple Ethernet packet"), (simple_eth_packet(pktlen=40), "tiny Ethernet packet")]: dp_ports = of_ports[0:num_ports] basic_logger.info("PKT OUT test with " + opt + ", ports " + str(dp_ports)) msg = message.packet_out() msg.data = str(outpkt) act = action.action_output() for i in range(0,num_ports): act.port = dp_ports[i] self.assertTrue(msg.actions.add(act), 'Could not add action to msg') basic_logger.info("PacketOut to: " + str(dp_ports)) rv = self.controller.message_send(msg) self.assertTrue(rv == 0, "Error sending out message") receive_pkt_check(self.dataplane, outpkt, dp_ports, set(of_ports).difference(dp_ports), self, basic_logger, basic_config)
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 = 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 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): # Construct packet to send to dataplane # Send packet to dataplane # Poll controller with expect message type packet in rc = testutils.delete_all_flows(self.controller, basic_logger) self.assertEqual(rc, 0, "Failed to delete all flows") # 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)) rv = self.controller.message_send(msg) self.assertTrue(rv == 0, "Error sending out message") (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 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 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): 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): logging = get_logger() logging.info("Running Grp70No60 Forward_Table 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") logging.info("Insert a flow F with output action port set to some egress_port") logging.info("Send packet out message (matching flow F) with action.port = OFP.TABLE") logging.info("Expecting packet on the egress_port") #Insert a all wildcarded flow (pkt,match) = wildcard_all(self,of_ports) #Create a packet out message pkt_out =message.packet_out(); pkt_out.data = str(pkt) pkt_out.in_port = of_ports[0] act = action.action_output() act.port = ofp.OFPP_TABLE pkt_out.actions.add(act) rv = self.controller.message_send(pkt_out) self.assertTrue(rv == 0, "Error sending out message") #Verifying packet out message recieved on the expected dataplane port. (of_port, pkt, pkt_time) = self.dataplane.poll(port_number=of_ports[1], exp_pkt=pkt,timeout=3) self.assertTrue(pkt is not None, 'Packet not received')
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 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): # Construct packet to send to dataplane # Send packet to dataplane # Poll controller with expect message type packet in rc = delete_all_flows(self.controller) self.assertEqual(rc, 0, "Failed to delete all flows") # These will get put into function of_ports = config["port_map"].keys() random.shuffle(of_ports) for num_ports in range(1, len(of_ports) + 1): for outpkt, opt in [ (simple_tcp_packet(), "simple TCP packet"), (simple_eth_packet(), "simple Ethernet packet"), (simple_eth_packet(pktlen=40), "tiny Ethernet packet") ]: dp_ports = of_ports[0:num_ports] logging.info("PKT OUT test with " + opt + ", ports " + str(dp_ports)) msg = message.packet_out() msg.data = str(outpkt) act = action.action_output() for i in range(0, num_ports): act.port = dp_ports[i] self.assertTrue(msg.actions.add(act), 'Could not add action to msg') logging.info("PacketOut to: " + str(dp_ports)) rv = self.controller.message_send(msg) self.assertTrue(rv == 0, "Error sending out message") receive_pkt_check(self.dataplane, outpkt, dp_ports, set(of_ports).difference(dp_ports), self)
def runTest(self): logging = get_logger() logging.info("Running Grp100No120 BadActionBadLen test") of_ports = config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") #Sending a flow with output action s.t length field in the action header is incorrect logging.info("Sending flow_mod message..") pkt=simple_tcp_packet() act=action.action_output() request = flow_msg_create(self, pkt, ing_port=of_ports[0], egr_ports=of_ports[1]) #Actual Length is 8 bytes, changed it to 7 bytes request.actions.actions[0].len=7 rv = self.controller.message_send(request) self.assertTrue(rv != -1,"Unable to send the message") 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 reply with error messge') self.assertTrue(response.type==ofp.OFPET_BAD_ACTION, 'Error type is not OFPET_BAD_ACTION') self.assertTrue(response.code==ofp.OFPBAC_BAD_LEN, 'Error code is not OFPBAC_BAD_LEN')
def runTest(self): logging = get_logger() logging.info("Running Grp100No150 BadActionBadPort test") # pick a random bad port number bad_port=ofp.OFPP_MAX pkt=simple_tcp_packet() act=action.action_output() #Send flow_mod message logging.info("Sending flow_mod message..") request = flow_msg_create(self, pkt, ing_port=1, egr_ports=bad_port) rv = self.controller.message_send(request) self.assertTrue(rv != -1 ,"Unable to send the message") count = 0 # poll for error message logging.info("Waiting for OFPT_ERROR message...") (res, raw) = self.controller.poll(ofp.OFPT_ERROR, timeout=10) self.assertTrue(res is not None,"Did not receive an error") self.assertTrue(res.type==ofp.OFPET_BAD_ACTION or res.type==ofp.OFPET_FLOW_MOD_FAILED,"Unexpected Error type. Expected ofp.OFPET_BAD_ACTION | ofp.OFPET_FLOW_MOD_FAILED error type. Got {0}".format(res.type)) if res.type == ofp.OFPET_BAD_ACTION: self.assertTrue(res.code == ofp.OFPBAC_BAD_OUT_PORT," Unexpected error code, Expected ofp.OFPBAC_BAD_OUT_PORT, got {0}".format(res.type)) elif res.type == ofp.OFPET_FLOW_MOD_FAILED: self.assertTrue(res.code == ofp.OFPFMFC_EPERM," Unexpected error code, Expected ofp.OFPFMFC_EPERM, got {0}".format(res.type)) else: print "This shouldn't have happened."
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): logging = get_logger() logging.info("Running Grp100No100 BadRequestBufferUnknown test") of_ports = config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") msg = message.packet_out() msg.in_port = ofp.OFPP_CONTROLLER msg.buffer_id = 173 #Random buffer_id act = action.action_output() act.port = of_ports[1] self.assertTrue(msg.actions.add(act), 'Could not add action to msg') logging.info("PacketOut to: " + str(of_ports[1])) rv = self.controller.message_send(msg) self.assertTrue(rv == 0, "Error sending out message") (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR, timeout=5) self.assertTrue(response is not None, 'Switch did not reply with error messge') self.assertTrue(response.type==ofp.OFPET_BAD_REQUEST, 'Message field type is not OFPET_BAD_REQUEST') self.assertTrue(response.code==ofp.OFPBRC_BUFFER_UNKNOWN, 'Message field code is not OFPBRC_BUFFER_UNKNOWN')
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): logging = get_logger() logging.info("Running Grp40No50 NeverValidPort test") # pick a random bad port number bad_port=ofp.OFPP_MAX pkt=simple_tcp_packet() act=action.action_output() #Send flow_mod message logging.info("Sending flow_mod message with output action to an invalid port..") request = flow_msg_create(self, pkt, ing_port=1, egr_ports=bad_port) rv = self.controller.message_send(request) self.assertTrue(rv != -1 ,"Unable to send the message") count = 0 # poll for error message logging.info("Waiting for OFPT_ERROR message...") while True: (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR, timeout=5) if not response: # Timeout break self.assertTrue(response.type == ofp.OFPET_BAD_ACTION or response.type == ofp.OFPET_FLOW_MOD_FAILED, "Error type is not as expected") if response.type == ofp.OFPET_BAD_ACTION: self.assertTrue(response.code == ofp.OFPBAC_BAD_OUT_PORT, "Expected response code OFPBAC_BAD_OUT_PORT, but received {0}".format(response.code)) else: self.assertTrue(response.code == ofp.OFPFMFC_EPERM, "Expected response code OFPFMFC_EPERM, but received {0}".format(response.code)) if not config["relax"]: # Only one attempt to match break count += 1 if count > 10: # Too many tries break self.assertTrue(count<10,"Did not receive any error message") logging.info("Received the expected OFPT_ERROR message")
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 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 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): of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 2, "Not enough ports for test") # For making the test simpler... ing_port = of_ports[0] egr_port = of_ports[1] pktlen = 104 mpls_label = 0xa5f05 # no specific meaning mpls_tc = 5 mpls_ttl = 129 pkt = testutils.simple_tcp_packet_w_mpls(pktlen=pktlen, mpls_label=mpls_label, mpls_tc=mpls_tc, mpls_ttl=mpls_ttl) match = parse.packet_to_flow_match(pkt) wildcards = 0 new_mpls_ttl = mpls_ttl+1 exp_pkt = testutils.simple_tcp_packet_w_mpls(pktlen=pktlen, mpls_label=mpls_label, mpls_tc=mpls_tc, mpls_ttl=new_mpls_ttl) # Create parameters for each table act_list = [] next_avail = [] chk_expire = [] #Table 0 act = action.action_output() act.port = egr_port act_list.append([act]) next_avail.append(True) chk_expire.append(False) #Table 1 act = action.action_set_mpls_ttl() act.mpls_ttl = new_mpls_ttl act_list.append([act]) next_avail.append(True) chk_expire.append(False) #Table 2 act = action.action_dec_mpls_ttl() act_list.append([act]) next_avail.append(False) chk_expire.append(False) write_action_test_multi_tables(self, ing_port, egr_port, match = match, wildcards = wildcards, act_list = act_list, next_avail = next_avail, chk_expire = chk_expire, pkt = pkt, exp_pkt = exp_pkt)