def runTest(self): ing_port = flow_mods_port_map.keys()[0] egr_port = flow_mods_port_map.keys()[1] table_id = testutils.EX_L3_TABLE flow_count = 10 testutils.delete_all_flows_one_table(self.controller, self.logger, table_id) match_fields_ls = [] ipv6_src_addr = 'fe80::2420:52ff:fe8f:5188' metadata_val = 0xaa22334455667788 for i in range(flow_count): match_fields_ls.append(match_list()) match_fields_ls[i].add(match.eth_type(testutils.IPV6_ETHERTYPE)) match_fields_ls[i].add( match.ipv6_src(ipaddr.IPv6Address(ipv6_src_addr))) ipv6_dst_addr = 'fe80::2420:52ff:fe8f:' + str(5190 + i) match_fields_ls[i].add( match.ipv6_dst(ipaddr.IPv6Address(ipv6_dst_addr))) match_fields_ls[i].add(match.metadata(metadata_val)) request = testutils.flow_msg_create( self, None, ing_port=ing_port, match_fields=match_fields_ls[i], egr_port=egr_port, table_id=table_id) testutils.flow_msg_install(self, request, False) match_fields = match_list() match_fields.add(match.eth_type(testutils.IPV6_ETHERTYPE)) match_fields.add(match.ipv6_src(ipaddr.IPv6Address(ipv6_src_addr))) response = testutils.flow_stats_get(self, table_id=table_id) self.assertTrue( len(response.stats) == flow_count, 'Did not add all flows successfully! Get table entry num is %d' % len(response.stats)) request = testutils.flow_msg_create(self, None, None, ing_port, match_fields, table_id=table_id) request.command = ofp.OFPFC_DELETE testutils.flow_msg_install(self, request, False) response = testutils.flow_stats_get(self, table_id=table_id) self.assertTrue( len(response.stats) == 0, 'Switch did not del the flow entry! Current table entry num is %d' % len(response.stats))
def runTest(self): ing_port = flow_mods_port_map.keys()[0] out_port1 = flow_mods_port_map.keys()[1] testutils.delete_all_flows(self.controller, self.logger) flow_add = message.flow_mod() flow_add.buffer_id = 0xffffffff flow_add.header.xid = 123 flow_add.table_id = 0 flow_add.command = ofp.OFPFC_ADD flow_add.match_fields.add(match.eth_type(value=0x86dd)) flow_add.match_fields.add(match.ipv4_src(value=3232235521)) flow_add.match_fields.add(match.ipv4_dst(value=3232235522)) flow_add.match_fields.add(match.metadata(value=0)) "new a instruction" inst = instruction.instruction_write_actions() "new a output actions" act = action.action_output() act.port = out_port1 inst.actions.add(act) flow_add.instructions.add(inst) #self.controller.message_send(flow_add) #print(flow_add.show()) testutils.ofmsg_send(self, flow_add) (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 2) self.assertTrue(response is not None, 'No error message received') self.assertEqual( ofp.OFPET_BAD_MATCH, response.type, 'Error message type mismatch: ' + str(ofp.OFPET_BAD_MATCH) + " != " + str(response.type)) self.assertEqual( ofp.OFPBMC_BAD_PREREQ, response.code, 'Error message code mismatch: ' + str(ofp.OFPBMC_BAD_PREREQ) + " != " + str(response.code))
def runTest(self): 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): 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): # Config of_ports = ipv6_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, 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')) ip_proto = match.ip_proto(TCP_PROTOCOL) tcp_port = match.tcp_src(80) 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(tcp_port) act = action.action_output() act.port = of_ports[3] inst = instruction.instruction_apply_actions() inst.actions.add(act) 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 send test flow") #Send packet pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080) 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(tcp_sport=80, tcp_dport=8080) testutils.receive_pkt_verify(self, egr_port, exp_pkt) #Remove flows rc = testutils.delete_all_flows(self.controller, ipv6_logger) self.assertEqual(rc, 0, "Failed to delete all flows")
def runTest(self): # Config of_ports = ipv6_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, 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')) ip_proto = match.ip_proto(TCP_PROTOCOL) tcp_port = match.tcp_src(80) 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(tcp_port) act = action.action_output() act.port = of_ports[3] inst = instruction.instruction_apply_actions() inst.actions.add(act) 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 send test flow") #Send packet pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080) 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(tcp_sport=80, tcp_dport=8080) testutils.receive_pkt_verify(self, egr_port, exp_pkt) #Remove flows rc = testutils.delete_all_flows(self.controller, ipv6_logger) self.assertEqual(rc, 0, "Failed to delete all flows")
def runTest(self): ing_port = flow_mods_port_map.keys()[0] egr_port = flow_mods_port_map.keys()[1] table_id = testutils.EX_L3_TABLE flow_count = 10 testutils.delete_all_flows_one_table(self.controller, self.logger, table_id) match_fields_ls = [] ipv6_src_addr = 'fe80::2420:52ff:fe8f:5188' metadata_val = 0xaa22334455667788 for i in range(flow_count): match_fields_ls.append(match_list()) match_fields_ls[i].add(match.eth_type(testutils.IPV6_ETHERTYPE)) match_fields_ls[i].add(match.ipv6_src(ipaddr.IPv6Address(ipv6_src_addr))) ipv6_dst_addr = 'fe80::2420:52ff:fe8f:' + str(5190+i) match_fields_ls[i].add(match.ipv6_dst(ipaddr.IPv6Address(ipv6_dst_addr))) match_fields_ls[i].add(match.metadata(metadata_val)) request = testutils.flow_msg_create(self, None, ing_port=ing_port, match_fields = match_fields_ls[i], egr_port = egr_port, table_id = table_id) testutils.flow_msg_install(self, request, False) match_fields = match_list() match_fields.add(match.eth_type(testutils.IPV6_ETHERTYPE)) match_fields.add(match.ipv6_src(ipaddr.IPv6Address(ipv6_src_addr))) response = testutils.flow_stats_get(self, table_id = table_id) self.assertTrue(len(response.stats) == flow_count, 'Did not add all flows successfully! Get table entry num is %d' %len(response.stats)) request = testutils.flow_msg_create(self, None, None, ing_port, match_fields, table_id = table_id) request.command = ofp.OFPFC_DELETE testutils.flow_msg_install(self, request, False) response = testutils.flow_stats_get(self, table_id = table_id) self.assertTrue(len(response.stats) == 0, 'Switch did not del the flow entry! Current table entry num is %d' %len(response.stats))
def runTest(self): basic_logger.info("Running TableStats") testutils.delete_all_flows(self.controller, self.logger) basic_logger.info("Sending table stats request") request = message.table_stats_request() response, _ = self.controller.transact(request, timeout=2) # delete everything, so there should be no entries self.assertEqual(self.get_first_table_active_entries(response), 0) # add two entries to first table m1 = testutils.match_all_generate() m1.add(match.eth_type(0x800)) # m1.wildcards ^= OFPFW_DL_TYPE fm1 = testutils.flow_msg_create(self, None, match_fields=m1, egr_port=2) testutils.ofmsg_send(self, fm1) m2 = testutils.match_all_generate() m2.add(match.eth_type(0x806)) # m2.wildcards ^= ofp.OFPFW_DL_TYPE fm2 = testutils.flow_msg_create(self, None, match_fields=m2, egr_port=2) testutils.ofmsg_send(self, fm2) response, _ = self.controller.transact(request, timeout=2) self.assertEqual(self.get_first_table_active_entries(response), 2)
def runTest(self): basic_logger.info("Running TableStats") testutils.delete_all_flows(self.controller, self.logger) basic_logger.info("Sending table stats request") request = message.table_stats_request() response, _ = self.controller.transact(request, timeout=2) # delete everything, so there should be no entries self.assertEqual(self.get_first_table_active_entries(response), 0) # add two entries to first table m1 = testutils.match_all_generate() m1.add(match.eth_type(0x800)) #m1.wildcards ^= OFPFW_DL_TYPE fm1 = testutils.flow_msg_create(self, None, match_fields=m1, egr_port=2) testutils.ofmsg_send(self, fm1) m2 = testutils.match_all_generate() m2.add(match.eth_type(0x806)) #m2.wildcards ^= ofp.OFPFW_DL_TYPE fm2 = testutils.flow_msg_create(self, None, match_fields=m2, egr_port=2) testutils.ofmsg_send(self, fm2) response, _ = self.controller.transact(request, timeout=2) self.assertEqual(self.get_first_table_active_entries(response), 2)
def packet_to_flow_match(packet): """ Create a flow match that matches packet with the given wildcards @param packet The packet to use as a flow template @param pkt_format Currently only L2 is supported. Will indicate the overall packet type for parsing @return An ofp_match object if successful. None if format is not recognized. The wildcards of the match will be cleared for the values extracted from the packet. @todo check min length of packet @todo Check if packet is other than L2 format @todo implement other fields covered by OpenFlow 1.2 """ match_ls = match_list() if Ether in packet: ether = packet[Ether] eth_type = match.eth_type(ether.type) eth_dst = match.eth_dst(parse_mac(ether.dst)) eth_src = match.eth_src(parse_mac(ether.src)) match_ls.add(eth_type) match_ls.add(eth_dst) match_ls.add(eth_src) else: return match_ls if Dot1Q in packet: #TODO: nicer way to get last vlan tag? vlan = packet[Dot1Q:0] vlan_vid = match.vlan_vid(vlan.vlan) vlan_pcp = match.vlan_pcp(vlan.prio) match_ls.add(vlan_vid) match_ls.add(vlan_pcp) vlan_pl = vlan.payload while vlan_pl is not None and vlan_pl.name == Dot1Q.name: vlan = vlan_pl vlan_pl = vlan.payload #We need to overwrite the already # inserted eth_type eth_index = match.tlvs.index() eth_type = match.eth_type(vlan.type) match_ls.tlvs.insert(vlan.type, eth_index) #TODO ARP if MPLS in packet: mpls = packet[MPLS:0] mpls_label = match.mpls_label(mpls.label) mpls_tc = match.mpls_tc(mpls.cos) match_ls.add(mpls_label) match_ls.add(mpls_tc) return match_ls if IP in packet: ip = packet[IP] ipv4_src = match.ipv4_src(parse_ip(ip.src)) ipv4_dst = match.ipv4_dst(parse_ip(ip.dst)) ip_dscp = match.ip_dscp(ip.tos >> 2) ip_ecn = match.ip_ecn(ip.tos & 0x03) match_ls.add(ipv4_src) match_ls.add(ipv4_dst) match_ls.add(ip_dscp) match_ls.add(ip_ecn) else: return match_ls if TCP in packet: tcp = packet[TCP] ip_proto = match.ip_proto(6) tcp_src = match.tcp_src(tcp.sport) tcp_dst = match.tcp_dst(tcp.dport) match_ls.add(ip_proto) match_ls.add(tcp_src) match_ls.add(tcp_dst) return match_ls if UDP in packet: udp = packet[UDP] ip_proto = match.ip_proto(17) udp_src = match.tcp_src(udp.sport) udp_dst = match.tcp_dst(udp.dport) match_ls.add(ip_proto) match_ls.add(udp_src) match_ls.add(udp_dst) returnmatch_ls if ICMP in packet: icmp = packet[ICMP] ip_proto = match.ip_proto(1) icmp_type = match.icmp_type(icmp.type) icmp_code = match.icmp_code(icmp.code) match_ls.add(icmp_type) match_ls.add(icmp_code) return match_ls return match_ls
def packet_to_flow_match(packet): """ Create a flow match that matches packet with the given wildcards @param packet The packet to use as a flow template @param pkt_format Currently only L2 is supported. Will indicate the overall packet type for parsing @return An ofp_match object if successful. None if format is not recognized. The wildcards of the match will be cleared for the values extracted from the packet. @todo check min length of packet @todo Check if packet is other than L2 format @todo implement other fields covered by OpenFlow 1.2 """ match_ls = match_list() if Ether in packet: ether = packet[Ether] eth_type = match.eth_type(ether.type) eth_dst = match.eth_dst(parse_mac(ether.dst)) eth_src = match.eth_src(parse_mac(ether.src)) match_ls.add(eth_type) match_ls.add(eth_dst) match_ls.add(eth_src) else: return match_ls if Dot1Q in packet: #TODO: nicer way to get last vlan tag? vlan = packet[Dot1Q:0] vlan_vid = match.vlan_vid(vlan.vlan) vlan_pcp = match.vlan_pcp(vlan.prio) match_ls.add(vlan_vid) match_ls.add(vlan_pcp) vlan_pl = vlan.payload while vlan_pl is not None and vlan_pl.name == Dot1Q.name: vlan = vlan_pl vlan_pl = vlan.payload #We need to overwrite the already # inserted eth_type eth_index = match.tlvs.index() eth_type = match.eth_type(vlan.type) match_ls.tlvs.insert(vlan.type,eth_index) #TODO ARP if MPLS in packet: mpls = packet[MPLS:0] mpls_label = match.mpls_label(mpls.label) mpls_tc = match.mpls_tc(mpls.cos) match_ls.add(mpls_label) match_ls.add(mpls_tc) return match_ls if IP in packet: ip = packet[IP] ipv4_src = match.ipv4_src(parse_ip(ip.src)) ipv4_dst = match.ipv4_dst(parse_ip(ip.dst)) ip_dscp = match.ip_dscp(ip.tos >> 2) ip_ecn = match.ip_ecn(ip.tos & 0x03) match_ls.add(ipv4_src) match_ls.add(ipv4_dst) match_ls.add(ip_dscp) match_ls.add(ip_ecn) else: return match_ls if TCP in packet: tcp = packet[TCP] ip_proto = match.ip_proto(6) tcp_src = match.tcp_src(tcp.sport) tcp_dst = match.tcp_dst(tcp.dport) match_ls.add(ip_proto) match_ls.add(tcp_src) match_ls.add(tcp_dst) return match_ls if UDP in packet: udp = packet[UDP] ip_proto = match.ip_proto(17) udp_src = match.tcp_src(udp.sport) udp_dst = match.tcp_dst(udp.dport) match_ls.add(ip_proto) match_ls.add(udp_src) match_ls.add(udp_dst) returnmatch_ls if ICMP in packet: icmp = packet[ICMP] ip_proto = match.ip_proto(1) icmp_type = match.icmp_type(icmp.type) icmp_code = match.icmp_code(icmp.code) match_ls.add(icmp_type) match_ls.add(icmp_code) return match_ls return match_ls
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")