def runTest(self): ing_port = config["port_map"].keys()[0] out_port1 = config["port_map"].keys()[1] out_port2 = config["port_map"].keys()[2] pkt = testutils.simple_tcp_packet() testutils.delete_all_flows(self.controller, logging) fm_orig = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=out_port1) fm_new = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=out_port2) fm_new.command = ofp.OFPFC_MODIFY_STRICT rv = self.controller.message_send(fm_orig) self.assertEqual(rv, 0, "Failed to insert 1st flow_mod") testutils.do_barrier(self.controller) rv = self.controller.message_send(fm_new) testutils.do_barrier(self.controller) self.assertEqual(rv, 0, "Failed to insert 2nd flow_mod") flow_stats = testutils.flow_stats_get(self) self.assertEqual(len(flow_stats.entries), 1, "Expected only one flow_mod") stat = flow_stats.entries[0] def canonicalize_match(match): match.oxm_list.sort(key=lambda x: x.type_len) canonicalize_match(stat.match) canonicalize_match(fm_new.match) self.assertEqual(stat.match, fm_new.match) self.assertEqual(stat.instructions, fm_new.instructions)
def runTest(self): ing_port = config["port_map"].keys()[0] out_port1 = config["port_map"].keys()[1] out_port2 = config["port_map"].keys()[2] pkt = testutils.simple_tcp_packet() testutils.delete_all_flows(self.controller, logging) fm_orig = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=out_port1) fm_new = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=out_port2) fm_new.command = ofp.OFPFC_MODIFY_STRICT rv = self.controller.message_send(fm_orig) self.assertEqual(rv, 0, "Failed to insert 1st flow_mod") testutils.do_barrier(self.controller) rv = self.controller.message_send(fm_new) testutils.do_barrier(self.controller) self.assertEqual(rv, 0, "Failed to insert 2nd flow_mod") flow_stats = testutils.flow_stats_get(self) self.assertEqual(len(flow_stats.entries),1, "Expected only one flow_mod") stat = flow_stats.entries[0] def canonicalize_match(match): match.oxm_list.sort(key=lambda x: x.type_len) canonicalize_match(stat.match) canonicalize_match(fm_new.match) self.assertEqual(stat.match, fm_new.match) self.assertEqual(stat.instructions, fm_new.instructions)
def runTest(self): of_ports = config["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, logging) self.assertEqual(rc, 0, "Failed to delete all flows") # Add entry match request = ofp.message.flow_mod() request.match.type = ofp.OFPMT_OXM port = ofp.match.in_port(of_ports[0]) eth_type = ofp.match.eth_type(IPV6_ETHERTYPE) ipv6_src = ofp.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 = ofp.match.ipv6_dst(ipaddr.IPv6Address('fe80::2420:52ff:fe8f:DDDD')) act_setfield = ofp.action.set_field() act_setfield.field = field_2b_set # TODO: insert action set field properly act_out = ofp.action.output() act_out.port = of_ports[3] inst = ofp.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 logging.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') logging.info("Sending IPv6 packet to " + str(ing_port)) logging.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) logging.debug("Response" + response.show()) #Remove flows rc = testutils.delete_all_flows(self.controller, logging) self.assertEqual(rc, 0, "Failed to delete all flows")
def runTest(self): # Config of_ports = config["port_map"].keys() of_ports.sort() ing_port = of_ports[0] egr_port = of_ports[3] # Remove flows rc = testutils.delete_all_flows(self.controller, logging) self.assertEqual(rc, 0, "Failed to delete all flows") # Add entry match request = ofp.message.flow_add() request.match.type = ofp.OFPMT_OXM port = ofp.oxm.in_port(of_ports[0]) eth_type = ofp.oxm.eth_type(IPV6_ETHERTYPE) ipv6_src = ofp.oxm.ipv6_src( oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:5189')) ip_proto = ofp.oxm.ip_proto(TCP_PROTOCOL) tcp_port = ofp.oxm.tcp_src(80) request.match.oxm_list.append(port) request.match.oxm_list.append(eth_type) request.match.oxm_list.append(ipv6_src) request.match.oxm_list.append(ip_proto) request.match.oxm_list.append(tcp_port) act = ofp.action.output() act.port = of_ports[3] inst = ofp.instruction.apply_actions() inst.actions.append(act) request.instructions.append(inst) request.buffer_id = 0xffffffff request.priority = 1000 logging.debug("Adding flow ") rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Failed to send test flow") #Send packet pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080) logging.info("Sending IPv6 packet to " + str(ing_port)) logging.debug("Data: " + str(pkt).encode('hex')) self.dataplane.send(ing_port, str(pkt)) #Receive packet exp_pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080) testutils.receive_pkt_verify(self, egr_port, exp_pkt) #Remove flows rc = testutils.delete_all_flows(self.controller, logging) self.assertEqual(rc, 0, "Failed to delete all flows")
def runTest(self): # Config of_ports = config["port_map"].keys() of_ports.sort() ing_port = of_ports[0] egr_port = of_ports[3] # Remove flows rc = testutils.delete_all_flows(self.controller, logging) self.assertEqual(rc, 0, "Failed to delete all flows") # Add entry match request = ofp.message.flow_add() request.match.type = ofp.OFPMT_OXM port = ofp.oxm.in_port(of_ports[0]) eth_type = ofp.oxm.eth_type(IPV6_ETHERTYPE) ipv6_src = ofp.oxm.ipv6_src(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:5189')) ip_proto = ofp.oxm.ip_proto(TCP_PROTOCOL) tcp_port = ofp.oxm.tcp_src(80) request.match.oxm_list.append(port) request.match.oxm_list.append(eth_type) request.match.oxm_list.append(ipv6_src) request.match.oxm_list.append(ip_proto) request.match.oxm_list.append(tcp_port) act = ofp.action.output() act.port = of_ports[3] inst = ofp.instruction.apply_actions() inst.actions.append(act) request.instructions.append(inst) request.buffer_id = 0xffffffff request.priority = 1000 logging.debug("Adding flow ") rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Failed to send test flow") #Send packet pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080) logging.info("Sending IPv6 packet to " + str(ing_port)) logging.debug("Data: " + str(pkt).encode('hex')) self.dataplane.send(ing_port, str(pkt)) #Receive packet exp_pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080) testutils.receive_pkt_verify(self, egr_port, exp_pkt) #Remove flows rc = testutils.delete_all_flows(self.controller, logging) self.assertEqual(rc, 0, "Failed to delete all flows")
def runTest(self): of_ports = config["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, logging) self.assertEqual(rc, 0, "Failed to delete all flows") # Add entry match request = ofp.message.flow_mod() request.match.type = ofp.OFPMT_OXM port = ofp.match.in_port(of_ports[0]) eth_type = ofp.match.eth_type(IPV6_ETHERTYPE) ipv6_src = ofp.match.ipv6_src(ipaddr.IPv6Address('fe80::2420:52ff:fe8f:5189')) ip_proto = ofp.match.ip_proto(ICMPV6_PROTOCOL) icmpv6_type = ofp.match.icmpv6_type(128) request.match_fields.tlvs.append(port) request.match_fields.tlvs.append(eth_type) request.match_fields.tlvs.append(ipv6_src) request.match_fields.tlvs.append(ip_proto) request.match_fields.tlvs.append(icmpv6_type) act = ofp.action.output() act.port = of_ports[3] inst = ofp.instruction.instruction_apply_actions() inst.actions.add(act) request.instructions.add(inst) request.buffer_id = 0xffffffff request.priority = 1000 logging.debug("Adding flow ") rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Failed to insert test flow") #Send packet pkt = testutils.simple_icmpv6_packet() logging.info("Sending IPv6 packet to " + str(ing_port)) logging.debug("Data: " + str(pkt).encode('hex')) self.dataplane.send(ing_port, str(pkt)) #Receive packet exp_pkt = testutils.simple_icmpv6_packet() testutils.receive_pkt_verify(self, egr_port, exp_pkt) #Remove flows rc = testutils.delete_all_flows(self.controller, logging) self.assertEqual(rc, 0, "Failed to delete all flows")
def runTest(self): # Construct packet to send to dataplane # Send packet to dataplane, once to each port # Poll controller with expect message type packet in rc = testutils.delete_all_flows(self.controller, logging) self.assertEqual(rc, 0, "Failed to delete all flows") for of_port in config["port_map"].keys(): logging.info("PKT IN test, port " + str(of_port)) pkt = testutils.simple_tcp_packet() self.dataplane.send(of_port, str(pkt)) #@todo Check for unexpected messages? (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN) self.assertTrue(response is not None, 'Packet in message not received on port ' + str(of_port)) if str(pkt) != response.data: logging.debug("pkt len " + str(len(str(pkt))) + ": " + str(pkt)) logging.debug("resp len " + str(len(str(response.data))) + ": " + str(response.data)) self.assertEqual(str(pkt), response.data, 'Response packet does not match send packet' + ' for port ' + str(of_port))
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, logging) self.assertEqual(rc, 0, "Failed to delete all flows") # These will get put into function outpkt = testutils.simple_tcp_packet() of_ports = config["port_map"].keys() of_ports.sort() for dp_port in of_ports: msg = ofp.message.packet_out() msg.in_port = ofp.OFPP_CONTROLLER msg.buffer_id = 0xffffffff msg.data = str(outpkt) act = ofp.action.output() act.port = dp_port msg.actions.append(act) logging.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') logging.info("PacketOut: got pkt from " + str(of_port)) if of_port is not None: self.assertEqual(of_port, dp_port, "Unexpected receive port") self.assertEqual(str(outpkt), str(pkt), 'Response packet does not match send packet')
def runTest(self): logging.info("Running StatsGet") logging.info("Inserting trial flow") request = ofp.message.flow_add() request.buffer_id = 0xffffffff for i in range(1,5): request.priority = i*1000 logging.debug("Adding flow %d" % i) rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Failed to insert test flow %d" % i) logging.info("Removing all flows") testutils.delete_all_flows(self.controller, logging) logging.info("Sending flow request") request = ofp.message.flow_stats_request() request.out_port = ofp.OFPP_ANY request.out_group = ofp.OFPG_ANY request.table_id = 0xff response, _ = self.controller.transact(request, timeout=2) self.assertTrue(response is not None, "Did not get response") self.assertTrue(isinstance(response,ofp.message.flow_stats_reply),"Not a flow_stats_reply") self.assertEqual(len(response.entries),0) logging.debug(response.show())
def clear_switch(self): testutils.delete_all_flows(self.controller, logging) testutils.delete_all_groups(self.controller, logging)
def runTest(self): of_ports = config["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, logging) self.assertEqual(rc, 0, "Failed to delete all flows") # Add entry match request = ofp.message.flow_add() port = ofp.oxm.in_port(of_ports[0]) eth_type = ofp.oxm.eth_type(IPV6_ETHERTYPE) ipv6_src = ofp.oxm.ipv6_src( oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:5189')) request.match.oxm_list.append(port) request.match.oxm_list.append(eth_type) request.match.oxm_list.append(ipv6_src) field_2b_set = ofp.oxm.ipv6_dst( oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:DDDD')) act_setfield = ofp.action.set_field() act_setfield.field = field_2b_set.pack() # HACK # TODO: insert action set field properly act_out = ofp.action.output() act_out.port = of_ports[3] inst = ofp.instruction.apply_actions() inst.actions.append(act_setfield) inst.actions.append(act_out) request.instructions.append(inst) request.buffer_id = 0xffffffff request.priority = 1000 logging.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') logging.info("Sending IPv6 packet to " + str(ing_port)) logging.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) logging.debug("Response" + response.show()) #Remove flows rc = testutils.delete_all_flows(self.controller, logging) self.assertEqual(rc, 0, "Failed to delete all flows")