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