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