ShreyaPandita | 055102a | 2012-11-28 11:43:45 -0500 | [diff] [blame] | 1 | """ Defined Some common functions used by Conformance tests -- OF-SWITCH 1.0.0 Testcases """ |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 2 | |
| 3 | import sys |
| 4 | import copy |
| 5 | import random |
| 6 | |
| 7 | import oftest.controller as controller |
Rich Lane | d7b0ffa | 2013-03-08 15:53:42 -0800 | [diff] [blame] | 8 | import ofp |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 9 | import oftest.dataplane as dataplane |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 10 | import oftest.parse as parse |
| 11 | import logging |
| 12 | import types |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 13 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 14 | import oftest.base_tests as base_tests |
Rich Lane | da3b5ad | 2012-10-03 09:05:32 -0700 | [diff] [blame] | 15 | from oftest.testutils import * |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 16 | from time import sleep |
| 17 | |
| 18 | #################### Functions for various types of flow_mod ########################################################################################## |
| 19 | |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 20 | def match_send_flowadd(self, match, priority, port): |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 21 | msg = ofp.message.flow_mod() |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 22 | msg.out_port = ofp.OFPP_NONE |
| 23 | msg.command = ofp.OFPFC_ADD |
| 24 | # msg.cookie = random.randint(0,9007199254740992) |
| 25 | msg.buffer_id = 0xffffffff |
| 26 | msg.match = match |
| 27 | if priority != None : |
| 28 | msg.priority = priority |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 29 | act = ofp.action.output() |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 30 | act.port = port |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame] | 31 | msg.actions.append(act) |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 32 | self.controller.message_send(msg) |
| 33 | do_barrier(self.controller) |
| 34 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 35 | def exact_match(self,of_ports,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 36 | # Generate ExactMatch flow . |
| 37 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 38 | #Create a simple tcp packet and generate exact flow match from it. |
| 39 | pkt_exactflow = simple_tcp_packet() |
| 40 | match = parse.packet_to_flow_match(pkt_exactflow) |
| 41 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 42 | match.in_port = of_ports[0] |
| 43 | #match.nw_src = 1 |
| 44 | match.wildcards=0 |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 45 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 46 | return (pkt_exactflow,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 47 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 48 | def exact_match_with_prio(self,of_ports,priority=None): |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 49 | # Generate ExactMatch with action output to port 2 |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 50 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 51 | #Create a simple tcp packet and generate exact flow match from it. |
| 52 | pkt_exactflow = simple_tcp_packet() |
| 53 | match = parse.packet_to_flow_match(pkt_exactflow) |
| 54 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 55 | match.in_port = of_ports[0] |
| 56 | #match.nw_src = 1 |
| 57 | match.wildcards=0 |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 58 | match_send_flowadd(self, match, priority, of_ports[2]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 59 | return (pkt_exactflow,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 60 | |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 61 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 62 | def match_all_except_source_address(self,of_ports,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 63 | # Generate Match_All_Except_Source_Address flow |
| 64 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 65 | #Create a simple tcp packet and generate match all except src address flow. |
| 66 | pkt_wildcardsrc= simple_tcp_packet() |
| 67 | match1 = parse.packet_to_flow_match(pkt_wildcardsrc) |
| 68 | self.assertTrue(match1 is not None, "Could not generate flow match from pkt") |
| 69 | match1.in_port = of_ports[0] |
| 70 | #match1.nw_src = 1 |
| 71 | match1.wildcards = ofp.OFPFW_DL_SRC |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 72 | match_send_flowadd(self, match1, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 73 | return (pkt_wildcardsrc,match1) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 74 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 75 | def match_ethernet_src_address(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 76 | #Generate Match_Ethernet_SrC_Address flow |
| 77 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 78 | #Create a simple tcp packet and generate match on ethernet src address flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 79 | pkt_MatchSrc = simple_eth_packet(dl_src='00:01:01:01:01:01') |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 80 | match = parse.packet_to_flow_match(pkt_MatchSrc) |
| 81 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 82 | match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_SRC |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 83 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 84 | return (pkt_MatchSrc,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 85 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 86 | def match_ethernet_dst_address(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 87 | #Generate Match_Ethernet_Dst_Address flow |
| 88 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 89 | #Create a simple tcp packet and generate match on ethernet dst address flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 90 | pkt_matchdst = simple_eth_packet(dl_dst='00:01:01:01:01:01') |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 91 | match = parse.packet_to_flow_match(pkt_matchdst) |
| 92 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 93 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 94 | match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_DST |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 95 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 96 | return (pkt_matchdst,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 97 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 98 | def wildcard_all(self,of_ports,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 99 | # Generate a Wildcard_All Flow |
| 100 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 101 | #Create a simple tcp packet and generate wildcard all flow match from it. |
| 102 | pkt_wildcard = simple_tcp_packet() |
| 103 | match2 = parse.packet_to_flow_match(pkt_wildcard) |
| 104 | self.assertTrue(match2 is not None, "Could not generate flow match from pkt") |
| 105 | match2.wildcards=ofp.OFPFW_ALL |
| 106 | match2.in_port = of_ports[0] |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 107 | match_send_flowadd(self, match2, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 108 | return (pkt_wildcard,match2) |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 109 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 110 | def wildcard_all_except_ingress(self,of_ports,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 111 | # Generate Wildcard_All_Except_Ingress_port flow |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 112 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 113 | #Create a simple tcp packet and generate wildcard all except ingress_port flow. |
| 114 | pkt_matchingress = simple_tcp_packet() |
| 115 | match3 = parse.packet_to_flow_match(pkt_matchingress) |
| 116 | self.assertTrue(match3 is not None, "Could not generate flow match from pkt") |
| 117 | match3.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT |
| 118 | match3.in_port = of_ports[0] |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 119 | match_send_flowadd(self, match3, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 120 | return (pkt_matchingress,match3) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 121 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 122 | def wildcard_all_except_ingress1(self,of_ports,priority=None): |
ShreyaPandita | da75f75 | 2012-10-26 16:26:35 -0400 | [diff] [blame] | 123 | # Generate Wildcard_All_Except_Ingress_port flow with action output to port egress_port 2 |
ShreyaPandita | da75f75 | 2012-10-26 16:26:35 -0400 | [diff] [blame] | 124 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 125 | #Create a simple tcp packet and generate wildcard all except ingress_port flow. |
| 126 | pkt_matchingress = simple_tcp_packet() |
| 127 | match3 = parse.packet_to_flow_match(pkt_matchingress) |
| 128 | self.assertTrue(match3 is not None, "Could not generate flow match from pkt") |
| 129 | match3.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT |
| 130 | match3.in_port = of_ports[0] |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 131 | match_send_flowadd(self, match3, priority, of_ports[2]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 132 | return (pkt_matchingress,match3) |
ShreyaPandita | da75f75 | 2012-10-26 16:26:35 -0400 | [diff] [blame] | 133 | |
| 134 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 135 | def match_vlan_id(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 136 | #Generate Match_Vlan_Id |
| 137 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 138 | #Create a simple tcp packet and generate match on ethernet dst address flow |
| 139 | pkt_matchvlanid = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=1) |
| 140 | match = parse.packet_to_flow_match(pkt_matchvlanid) |
| 141 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 142 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 143 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_DL_VLAN |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 144 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 145 | return (pkt_matchvlanid,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 146 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 147 | def match_vlan_pcp(self,of_ports,priority=None): |
ShreyaPandita | 055102a | 2012-11-28 11:43:45 -0500 | [diff] [blame] | 148 | #Generate Match_Vlan_Priority |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 149 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 150 | #Create a simple tcp packet and generate match on ethernet dst address flow |
Rich Lane | ba9eee8 | 2012-12-07 22:44:24 -0800 | [diff] [blame] | 151 | pkt_matchvlanpcp = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=1,dl_vlan_pcp=5) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 152 | match = parse.packet_to_flow_match(pkt_matchvlanpcp) |
| 153 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 154 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 155 | match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE^ofp.OFPFW_DL_VLAN^ofp.OFPFW_DL_VLAN_PCP |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 156 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 157 | return (pkt_matchvlanpcp,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 158 | |
| 159 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 160 | def match_mul_l2(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 161 | #Generate Match_Mul_L2 flow |
| 162 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 163 | #Create a simple eth packet and generate match on ethernet protocol flow |
| 164 | pkt_mulL2 = simple_eth_packet(dl_type=0x88cc,dl_src='00:01:01:01:01:01',dl_dst='00:01:01:01:01:02') |
| 165 | match = parse.packet_to_flow_match(pkt_mulL2) |
| 166 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 167 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 168 | match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_DL_DST ^ofp.OFPFW_DL_SRC |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 169 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 170 | return (pkt_mulL2,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 171 | |
| 172 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 173 | def match_mul_l4(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 174 | #Generate Match_Mul_L4 flow |
| 175 | |
| 176 | #Create a simple tcp packet and generate match on tcp protocol flow |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 177 | pkt_mulL4 = simple_tcp_packet(tcp_sport=111,tcp_dport=112) |
| 178 | match = parse.packet_to_flow_match(pkt_mulL4) |
| 179 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 180 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_NW_PROTO^ofp.OFPFW_TP_SRC ^ofp.OFPFW_TP_DST |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 181 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 182 | return (pkt_mulL4,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 183 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 184 | def match_ip_tos(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 185 | #Generate a Match on IP Type of service flow |
| 186 | |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 187 | #Create a simple tcp packet and generate match on Type of service |
Rich Lane | b5c7379 | 2012-12-03 17:12:32 -0800 | [diff] [blame] | 188 | pkt_iptos = simple_tcp_packet(ip_tos=28) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 189 | match = parse.packet_to_flow_match(pkt_iptos) |
| 190 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 191 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 192 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE^ofp.OFPFW_NW_PROTO ^ofp.OFPFW_NW_TOS |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 193 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 194 | return (pkt_iptos,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 195 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 196 | def match_ip_protocol(self,of_ports,priority=None): |
| 197 | #Generate a Match on IP Protocol |
| 198 | |
| 199 | #Create a simple tcp packet and generate match on Type of service |
| 200 | pkt_iptos = simple_tcp_packet() |
| 201 | match = parse.packet_to_flow_match(pkt_iptos) |
| 202 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 203 | |
| 204 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE^ofp.OFPFW_NW_PROTO |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 205 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 206 | return (pkt_iptos,match) |
| 207 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 208 | def match_tcp_src(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 209 | #Generate Match_Tcp_Src |
| 210 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 211 | #Create a simple tcp packet and generate match on tcp source port flow |
| 212 | pkt_matchtSrc = simple_tcp_packet(tcp_sport=111) |
| 213 | match = parse.packet_to_flow_match(pkt_matchtSrc) |
| 214 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 215 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 216 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_NW_PROTO ^ofp.OFPFW_TP_SRC |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 217 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 218 | return (pkt_matchtSrc,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 219 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 220 | def match_tcp_dst(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 221 | #Generate Match_Tcp_Dst |
| 222 | |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 223 | #Create a simple tcp packet and generate match on tcp destination port flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 224 | pkt_matchdst = simple_tcp_packet(tcp_dport=112) |
| 225 | match = parse.packet_to_flow_match(pkt_matchdst) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 226 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 227 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 228 | match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE^ofp.OFPFW_NW_PROTO^ofp.OFPFW_TP_DST |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 229 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 230 | return (pkt_matchdst,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 231 | |
ShreyaPandita | 055102a | 2012-11-28 11:43:45 -0500 | [diff] [blame] | 232 | |
Shudong Zhou | c2f1876 | 2013-01-11 00:12:44 -0800 | [diff] [blame] | 233 | def match_udp_src(self,of_ports,priority=None): |
| 234 | #Generate Match_Udp_Src |
| 235 | |
| 236 | #Create a simple udp packet and generate match on udp source port flow |
| 237 | pkt_matchtSrc = simple_udp_packet(udp_sport=111) |
| 238 | match = parse.packet_to_flow_match(pkt_matchtSrc) |
| 239 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 240 | |
| 241 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_NW_PROTO ^ofp.OFPFW_TP_SRC |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 242 | match_send_flowadd(self, match, priority, of_ports[1]) |
Shudong Zhou | c2f1876 | 2013-01-11 00:12:44 -0800 | [diff] [blame] | 243 | return (pkt_matchtSrc,match) |
| 244 | |
| 245 | def match_udp_dst(self,of_ports,priority=None): |
| 246 | #Generate Match_Udp_Dst |
| 247 | |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 248 | #Create a simple udp packet and generate match on udp destination port flow |
Shudong Zhou | c2f1876 | 2013-01-11 00:12:44 -0800 | [diff] [blame] | 249 | pkt_matchdst = simple_udp_packet(udp_dport=112) |
| 250 | match = parse.packet_to_flow_match(pkt_matchdst) |
| 251 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 252 | |
| 253 | match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE^ofp.OFPFW_NW_PROTO^ofp.OFPFW_TP_DST |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 254 | match_send_flowadd(self, match, priority, of_ports[1]) |
Shudong Zhou | c2f1876 | 2013-01-11 00:12:44 -0800 | [diff] [blame] | 255 | return (pkt_matchdst,match) |
| 256 | |
| 257 | |
| 258 | def match_icmp_type(self,of_ports,priority=None): |
| 259 | #Generate Match_Icmp_Type |
| 260 | |
| 261 | #Create a simple icmp packet and generate match on icmp type flow |
| 262 | pkt_match = simple_icmp_packet(icmp_type=1) |
| 263 | match = parse.packet_to_flow_match(pkt_match) |
| 264 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 265 | |
| 266 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_NW_PROTO ^ofp.OFPFW_TP_SRC |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 267 | match_send_flowadd(self, match, priority, of_ports[1]) |
Shudong Zhou | c2f1876 | 2013-01-11 00:12:44 -0800 | [diff] [blame] | 268 | return (pkt_match, match) |
| 269 | |
| 270 | def match_icmp_code(self,of_ports,priority=None): |
| 271 | #Generate Match_Icmp_Code |
| 272 | |
| 273 | #Create a simple icmp packet and generate match on icmp code flow |
| 274 | pkt_match = simple_icmp_packet(icmp_code=3) |
| 275 | match = parse.packet_to_flow_match(pkt_match) |
| 276 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 277 | |
| 278 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_NW_PROTO ^ofp.OFPFW_TP_DST |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 279 | match_send_flowadd(self, match, priority, of_ports[1]) |
Shudong Zhou | c2f1876 | 2013-01-11 00:12:44 -0800 | [diff] [blame] | 280 | return (pkt_match, match) |
| 281 | |
Shudong Zhou | dceec93 | 2013-02-06 01:12:54 -0800 | [diff] [blame] | 282 | def match_arp_sender(self,of_ports,priority=None): |
| 283 | #Generate Match_Arp_Sender |
| 284 | |
| 285 | #Create a simple icmp packet and generate match on arp sender flow |
| 286 | pkt_match = simple_arp_packet() |
| 287 | match = parse.packet_to_flow_match(pkt_match) |
| 288 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 289 | |
| 290 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_NW_PROTO ^ofp.OFPFW_NW_SRC_MASK |
| 291 | match_send_flowadd(self, match, priority, of_ports[1]) |
| 292 | return (pkt_match, match) |
| 293 | |
| 294 | def match_arp_target(self,of_ports,priority=None): |
| 295 | #Generate Match_Arp_Target |
| 296 | |
| 297 | #Create a simple icmp packet and generate match on arp target flow |
| 298 | pkt_match = simple_arp_packet() |
| 299 | match = parse.packet_to_flow_match(pkt_match) |
| 300 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 301 | |
| 302 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_NW_PROTO ^ofp.OFPFW_NW_DST_MASK |
| 303 | match_send_flowadd(self, match, priority, of_ports[1]) |
| 304 | return (pkt_match, match) |
| 305 | |
Shudong Zhou | c2f1876 | 2013-01-11 00:12:44 -0800 | [diff] [blame] | 306 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 307 | def match_ethernet_type(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 308 | #Generate a Match_Ethernet_Type flow |
| 309 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 310 | #Create a simple tcp packet and generate match on ethernet type flow |
| 311 | pkt_matchtype = simple_eth_packet(dl_type=0x88cc) |
| 312 | match = parse.packet_to_flow_match(pkt_matchtype) |
| 313 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 314 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 315 | match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 316 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 317 | return (pkt_matchtype,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 318 | |
| 319 | |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 320 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 321 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 322 | def strict_modify_flow_action(self,egress_port,match,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 323 | # Strict Modify the flow Action |
| 324 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 325 | #Create a flow_mod message , command MODIFY_STRICT |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 326 | msg5 = ofp.message.flow_mod() |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 327 | msg5.match = match |
| 328 | msg5.cookie = random.randint(0,9007199254740992) |
| 329 | msg5.command = ofp.OFPFC_MODIFY_STRICT |
| 330 | msg5.buffer_id = 0xffffffff |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 331 | act5 = ofp.action.output() |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 332 | act5.port = egress_port |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame] | 333 | msg5.actions.append(act5) |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 334 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 335 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 336 | msg5.priority = priority |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 337 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 338 | # Send the flow with action A' |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 339 | self.controller.message_send (msg5) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 340 | do_barrier(self.controller) |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 341 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 342 | def modify_flow_action(self,of_ports,match,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 343 | # Modify the flow action |
| 344 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 345 | #Create a flow_mod message , command MODIFY |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 346 | msg8 = ofp.message.flow_mod() |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 347 | msg8.match = match |
| 348 | msg8.cookie = random.randint(0,9007199254740992) |
| 349 | msg8.command = ofp.OFPFC_MODIFY |
| 350 | #out_port will be ignored for flow adds and flow modify (here for test-case Add_Modify_With_Outport) |
| 351 | msg8.out_port = of_ports[3] |
| 352 | msg8.buffer_id = 0xffffffff |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 353 | act8 = ofp.action.output() |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 354 | act8.port = of_ports[2] |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame] | 355 | msg8.actions.append(act8) |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 356 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 357 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 358 | msg8.priority = priority |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 359 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 360 | # Send the flow with action A' |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 361 | self.controller.message_send (msg8) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 362 | do_barrier(self.controller) |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 363 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 364 | def enqueue(self,ingress_port,egress_port,egress_queue_id): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 365 | #Generate a flow with enqueue action i.e output to a queue configured on a egress_port |
| 366 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 367 | pkt = simple_tcp_packet() |
| 368 | match = packet_to_flow_match(self, pkt) |
| 369 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 370 | self.assertTrue(match is not None, |
| 371 | "Could not generate flow match from pkt") |
| 372 | |
| 373 | match.in_port = ingress_port |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 374 | request = ofp.message.flow_mod() |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 375 | request.match = match |
| 376 | request.buffer_id = 0xffffffff |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 377 | act = ofp.action.enqueue() |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 378 | act.port = egress_port |
| 379 | act.queue_id = egress_queue_id |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame] | 380 | request.actions.append(act) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 381 | |
| 382 | logging.info("Inserting flow") |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 383 | self.controller.message_send(request) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 384 | do_barrier(self.controller) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 385 | return (pkt,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 386 | |
| 387 | |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 388 | ########################### Verify Stats Functions ########################################################################################### |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 389 | def get_flowstats(self,match): |
| 390 | # Generate flow_stats request |
| 391 | |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 392 | stat_req = ofp.message.flow_stats_request() |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 393 | stat_req.match = match |
| 394 | stat_req.table_id = 0xff |
| 395 | stat_req.out_port = ofp.OFPP_NONE |
| 396 | |
| 397 | logging.info("Sending stats request") |
| 398 | response, pkt = self.controller.transact(stat_req, |
| 399 | timeout=5) |
| 400 | self.assertTrue(response is not None,"No response to stats request") |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 401 | |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 402 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 403 | def get_portstats(self,port_num): |
| 404 | |
| 405 | # Return all the port counters in the form a tuple |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 406 | port_stats_req = ofp.message.port_stats_request() |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 407 | port_stats_req.port_no = port_num |
| 408 | response,pkt = self.controller.transact(port_stats_req) |
| 409 | self.assertTrue(response is not None,"No response received for port stats request") |
| 410 | rx_pkts=0 |
| 411 | tx_pkts=0 |
| 412 | rx_byts=0 |
| 413 | tx_byts=0 |
| 414 | rx_drp =0 |
| 415 | tx_drp = 0 |
| 416 | rx_err=0 |
| 417 | tx_err =0 |
| 418 | rx_fr_err=0 |
| 419 | rx_ovr_err=0 |
| 420 | rx_crc_err=0 |
| 421 | collisions = 0 |
| 422 | tx_err=0 |
| 423 | |
| 424 | |
| 425 | for obj in response.stats: |
| 426 | rx_pkts += obj.rx_packets |
| 427 | tx_pkts += obj.tx_packets |
| 428 | rx_byts += obj.rx_bytes |
| 429 | tx_byts += obj.tx_bytes |
| 430 | rx_drp += obj.rx_dropped |
| 431 | tx_drp += obj.tx_dropped |
| 432 | rx_err += obj.rx_errors |
| 433 | rx_fr_err += obj.rx_frame_err |
| 434 | rx_ovr_err += obj.rx_over_err |
| 435 | rx_crc_err += obj.rx_crc_err |
| 436 | collisions+= obj.collisions |
| 437 | tx_err += obj.tx_errors |
| 438 | |
| 439 | return (rx_pkts,tx_pkts,rx_byts,tx_byts,rx_drp,tx_drp,rx_err,tx_err,rx_fr_err,rx_ovr_err,rx_crc_err,collisions,tx_err) |
| 440 | |
| 441 | def get_queuestats(self,port_num,queue_id): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 442 | #Generate Queue Stats request |
| 443 | |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 444 | request = ofp.message.queue_stats_request() |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 445 | request.port_no = port_num |
| 446 | request.queue_id = queue_id |
| 447 | (queue_stats, p) = self.controller.transact(request) |
| 448 | self.assertNotEqual(queue_stats, None, "Queue stats request failed") |
| 449 | |
| 450 | return (queue_stats,p) |
| 451 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 452 | def get_tablestats(self): |
| 453 | # Send Table_Stats request (retrieve current table counters ) |
| 454 | |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 455 | stat_req = ofp.message.table_stats_request() |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 456 | response, pkt = self.controller.transact(stat_req, |
| 457 | timeout=5) |
| 458 | self.assertTrue(response is not None, |
| 459 | "No response to stats request") |
| 460 | current_lookedup = 0 |
| 461 | current_matched = 0 |
| 462 | current_active = 0 |
| 463 | |
| 464 | for obj in response.stats: |
| 465 | current_lookedup += obj.lookup_count |
| 466 | current_matched += obj.matched_count |
| 467 | current_active += obj.active_count |
| 468 | |
| 469 | return (current_lookedup,current_matched,current_active) |
| 470 | |
| 471 | |
| 472 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 473 | def verify_tablestats(self,expect_lookup=None,expect_match=None,expect_active=None): |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 474 | |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 475 | stat_req = ofp.message.table_stats_request() |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 476 | |
Rich Lane | 90b3d73 | 2012-12-31 10:03:50 -0800 | [diff] [blame] | 477 | for i in range(0,100): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 478 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 479 | logging.info("Sending stats request") |
| 480 | # TODO: move REPLY_MORE handling to controller.transact? |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 481 | response, pkt = self.controller.transact(stat_req, |
| 482 | timeout=5) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 483 | self.assertTrue(response is not None,"No response to stats request") |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 484 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 485 | lookedup = 0 |
| 486 | matched = 0 |
| 487 | active = 0 |
| 488 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 489 | for item in response.stats: |
| 490 | lookedup += item.lookup_count |
| 491 | matched += item.matched_count |
| 492 | active += item.active_count |
| 493 | |
Rich Lane | afcd0dd | 2013-01-03 20:54:56 -0800 | [diff] [blame] | 494 | logging.info("Packets Looked up: %d", lookedup) |
| 495 | logging.info("Packets matched: %d", matched) |
| 496 | logging.info("Active flow entries: %d", active) |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 497 | |
Rich Lane | 175f956 | 2013-01-03 20:58:40 -0800 | [diff] [blame] | 498 | if (expect_lookup == None or lookedup >= expect_lookup) and \ |
| 499 | (expect_match == None or matched >= expect_match) and \ |
| 500 | (expect_active == None or active >= expect_active): |
Rich Lane | 90b3d73 | 2012-12-31 10:03:50 -0800 | [diff] [blame] | 501 | break |
| 502 | |
| 503 | sleep(0.1) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 504 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 505 | if expect_lookup != None : |
Rich Lane | 3e77779 | 2013-01-03 21:30:30 -0800 | [diff] [blame] | 506 | self.assertEqual(expect_lookup, lookedup, "lookup counter is not incremented properly") |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 507 | if expect_match != None : |
Rich Lane | 3e77779 | 2013-01-03 21:30:30 -0800 | [diff] [blame] | 508 | self.assertEqual(expect_match, matched, "matched counter is not incremented properly") |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 509 | if expect_active != None : |
Rich Lane | 3e77779 | 2013-01-03 21:30:30 -0800 | [diff] [blame] | 510 | self.assertEqual(expect_active, active ,"active counter is not incremented properly") |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 511 | |
| 512 | |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 513 | ############################## Various delete commands ############################################################################################# |
| 514 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 515 | def strict_delete(self,match,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 516 | # Issue Strict Delete |
| 517 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 518 | #Create flow_mod message, command DELETE_STRICT |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 519 | msg4 = ofp.message.flow_mod() |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 520 | msg4.out_port = ofp.OFPP_NONE |
| 521 | msg4.command = ofp.OFPFC_DELETE_STRICT |
| 522 | msg4.buffer_id = 0xffffffff |
| 523 | msg4.match = match |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 524 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 525 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 526 | msg4.priority = priority |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 527 | self.controller.message_send(msg4) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 528 | do_barrier(self.controller) |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 529 | |
| 530 | |
| 531 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 532 | def nonstrict_delete(self,match,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 533 | # Issue Non_Strict Delete |
| 534 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 535 | #Create flow_mod message, command DELETE |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 536 | msg6 = ofp.message.flow_mod() |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 537 | msg6.out_port = ofp.OFPP_NONE |
| 538 | msg6.command = ofp.OFPFC_DELETE |
| 539 | msg6.buffer_id = 0xffffffff |
| 540 | msg6.match = match |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 541 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 542 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 543 | msg6.priority = priority |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 544 | |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 545 | self.controller.message_send(msg6) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 546 | do_barrier(self.controller) |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 547 | |
| 548 | |
| 549 | ########################################################################################################################################################### |
| 550 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 551 | def send_packet(obj, pkt, ingress_port, egress_port): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 552 | #Send Packets on a specified ingress_port and verify if its recieved on correct egress_port. |
| 553 | |
| 554 | obj.dataplane.send(ingress_port, str(pkt)) |
| 555 | exp_pkt_arg = pkt |
| 556 | exp_port = egress_port |
| 557 | |
| 558 | (rcv_port, rcv_pkt, pkt_time) = obj.dataplane.poll(timeout=2, |
| 559 | port_number=exp_port, |
| 560 | exp_pkt=exp_pkt_arg) |
| 561 | obj.assertTrue(rcv_pkt is not None, |
| 562 | "Packet not received on port " + str(egress_port)) |
| 563 | obj.assertEqual(rcv_port, egress_port, |
| 564 | "Packet received on port " + str(rcv_port) + |
| 565 | ", expected port " + str(egress_port)) |
| 566 | obj.assertEqual(str(pkt), str(rcv_pkt), |
| 567 | 'Response packet does not match send packet') |
| 568 | |
| 569 | |
ShreyaPandita | 572e64b | 2012-09-28 14:41:06 -0400 | [diff] [blame] | 570 | def sw_supported_actions(parent,use_cache=False): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 571 | #Returns the switch's supported actions |
| 572 | |
| 573 | cache_supported_actions = None |
| 574 | if cache_supported_actions is None or not use_cache: |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 575 | request = ofp.message.features_request() |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 576 | (reply, pkt) = parent.controller.transact(request) |
| 577 | parent.assertTrue(reply is not None, "Did not get response to ftr req") |
| 578 | cache_supported_actions = reply.actions |
| 579 | return cache_supported_actions |
| 580 | |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 581 | ############################################################################################################################################################## |
| 582 | |