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 | |
Shudong Zhou | c2f1876 | 2013-01-11 00:12:44 -0800 | [diff] [blame^] | 457 | def match_udp_src(self,of_ports,priority=None): |
| 458 | #Generate Match_Udp_Src |
| 459 | |
| 460 | #Create a simple udp packet and generate match on udp source port flow |
| 461 | pkt_matchtSrc = simple_udp_packet(udp_sport=111) |
| 462 | match = parse.packet_to_flow_match(pkt_matchtSrc) |
| 463 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 464 | |
| 465 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_NW_PROTO ^ofp.OFPFW_TP_SRC |
| 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 |
| 471 | if priority != None : |
| 472 | msg.priority = priority |
| 473 | |
| 474 | act = action.action_output() |
| 475 | act.port = of_ports[1] |
| 476 | msg.actions.add(act) |
| 477 | |
| 478 | self.controller.message_send(msg) |
| 479 | do_barrier(self.controller) |
| 480 | |
| 481 | return (pkt_matchtSrc,match) |
| 482 | |
| 483 | def match_udp_dst(self,of_ports,priority=None): |
| 484 | #Generate Match_Udp_Dst |
| 485 | |
| 486 | #Create a simple udp packet and generate match on udp destination port flow |
| 487 | pkt_matchdst = simple_udp_packet(udp_dport=112) |
| 488 | match = parse.packet_to_flow_match(pkt_matchdst) |
| 489 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 490 | |
| 491 | match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE^ofp.OFPFW_NW_PROTO^ofp.OFPFW_TP_DST |
| 492 | msg = message.flow_mod() |
| 493 | msg.out_port = ofp.OFPP_NONE |
| 494 | msg.command = ofp.OFPFC_ADD |
| 495 | msg.buffer_id = 0xffffffff |
| 496 | msg.match = match |
| 497 | if priority != None : |
| 498 | msg.priority = priority |
| 499 | act = action.action_output() |
| 500 | act.port = of_ports[1] |
| 501 | msg.actions.add(act) |
| 502 | |
| 503 | self.controller.message_send(msg) |
| 504 | do_barrier(self.controller) |
| 505 | |
| 506 | return (pkt_matchdst,match) |
| 507 | |
| 508 | |
| 509 | def match_icmp_type(self,of_ports,priority=None): |
| 510 | #Generate Match_Icmp_Type |
| 511 | |
| 512 | #Create a simple icmp packet and generate match on icmp type flow |
| 513 | pkt_match = simple_icmp_packet(icmp_type=1) |
| 514 | match = parse.packet_to_flow_match(pkt_match) |
| 515 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 516 | |
| 517 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_NW_PROTO ^ofp.OFPFW_TP_SRC |
| 518 | msg = message.flow_mod() |
| 519 | msg.out_port = ofp.OFPP_NONE |
| 520 | msg.command = ofp.OFPFC_ADD |
| 521 | msg.buffer_id = 0xffffffff |
| 522 | msg.match = match |
| 523 | if priority != None : |
| 524 | msg.priority = priority |
| 525 | |
| 526 | act = action.action_output() |
| 527 | act.port = of_ports[1] |
| 528 | msg.actions.add(act) |
| 529 | |
| 530 | self.controller.message_send(msg) |
| 531 | do_barrier(self.controller) |
| 532 | |
| 533 | return (pkt_match, match) |
| 534 | |
| 535 | def match_icmp_code(self,of_ports,priority=None): |
| 536 | #Generate Match_Icmp_Code |
| 537 | |
| 538 | #Create a simple icmp packet and generate match on icmp code flow |
| 539 | pkt_match = simple_icmp_packet(icmp_code=3) |
| 540 | match = parse.packet_to_flow_match(pkt_match) |
| 541 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 542 | |
| 543 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_NW_PROTO ^ofp.OFPFW_TP_DST |
| 544 | msg = message.flow_mod() |
| 545 | msg.out_port = ofp.OFPP_NONE |
| 546 | msg.command = ofp.OFPFC_ADD |
| 547 | msg.buffer_id = 0xffffffff |
| 548 | msg.match = match |
| 549 | if priority != None : |
| 550 | msg.priority = priority |
| 551 | |
| 552 | act = action.action_output() |
| 553 | act.port = of_ports[1] |
| 554 | msg.actions.add(act) |
| 555 | |
| 556 | self.controller.message_send(msg) |
| 557 | do_barrier(self.controller) |
| 558 | |
| 559 | return (pkt_match, match) |
| 560 | |
| 561 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 562 | def match_ethernet_type(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 563 | #Generate a Match_Ethernet_Type flow |
| 564 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 565 | #Create a simple tcp packet and generate match on ethernet type flow |
| 566 | pkt_matchtype = simple_eth_packet(dl_type=0x88cc) |
| 567 | match = parse.packet_to_flow_match(pkt_matchtype) |
| 568 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 569 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 570 | match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE |
| 571 | msg = message.flow_mod() |
| 572 | msg.out_port = ofp.OFPP_NONE |
| 573 | msg.command = ofp.OFPFC_ADD |
| 574 | msg.buffer_id = 0xffffffff |
| 575 | msg.match = match |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 576 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 577 | msg.priority = priority |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 578 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 579 | act = action.action_output() |
| 580 | act.port = of_ports[1] |
Rich Lane | e30455b | 2013-01-03 16:24:44 -0800 | [diff] [blame] | 581 | msg.actions.add(act) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 582 | |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 583 | self.controller.message_send(msg) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 584 | do_barrier(self.controller) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 585 | return (pkt_matchtype,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 586 | |
| 587 | |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 588 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 589 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 590 | def strict_modify_flow_action(self,egress_port,match,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 591 | # Strict Modify the flow Action |
| 592 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 593 | #Create a flow_mod message , command MODIFY_STRICT |
| 594 | msg5 = message.flow_mod() |
| 595 | msg5.match = match |
| 596 | msg5.cookie = random.randint(0,9007199254740992) |
| 597 | msg5.command = ofp.OFPFC_MODIFY_STRICT |
| 598 | msg5.buffer_id = 0xffffffff |
| 599 | act5 = action.action_output() |
| 600 | act5.port = egress_port |
Rich Lane | e30455b | 2013-01-03 16:24:44 -0800 | [diff] [blame] | 601 | msg5.actions.add(act5) |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 602 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 603 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 604 | msg5.priority = priority |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 605 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 606 | # Send the flow with action A' |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 607 | self.controller.message_send (msg5) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 608 | do_barrier(self.controller) |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 609 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 610 | def modify_flow_action(self,of_ports,match,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 611 | # Modify the flow action |
| 612 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 613 | #Create a flow_mod message , command MODIFY |
| 614 | msg8 = message.flow_mod() |
| 615 | msg8.match = match |
| 616 | msg8.cookie = random.randint(0,9007199254740992) |
| 617 | msg8.command = ofp.OFPFC_MODIFY |
| 618 | #out_port will be ignored for flow adds and flow modify (here for test-case Add_Modify_With_Outport) |
| 619 | msg8.out_port = of_ports[3] |
| 620 | msg8.buffer_id = 0xffffffff |
| 621 | act8 = action.action_output() |
| 622 | act8.port = of_ports[2] |
Rich Lane | e30455b | 2013-01-03 16:24:44 -0800 | [diff] [blame] | 623 | msg8.actions.add(act8) |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 624 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 625 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 626 | msg8.priority = priority |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 627 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 628 | # Send the flow with action A' |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 629 | self.controller.message_send (msg8) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 630 | do_barrier(self.controller) |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 631 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 632 | def enqueue(self,ingress_port,egress_port,egress_queue_id): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 633 | #Generate a flow with enqueue action i.e output to a queue configured on a egress_port |
| 634 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 635 | pkt = simple_tcp_packet() |
| 636 | match = packet_to_flow_match(self, pkt) |
| 637 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 638 | self.assertTrue(match is not None, |
| 639 | "Could not generate flow match from pkt") |
| 640 | |
| 641 | match.in_port = ingress_port |
| 642 | request = message.flow_mod() |
| 643 | request.match = match |
| 644 | request.buffer_id = 0xffffffff |
| 645 | act = action.action_enqueue() |
| 646 | act.port = egress_port |
| 647 | act.queue_id = egress_queue_id |
Rich Lane | e30455b | 2013-01-03 16:24:44 -0800 | [diff] [blame] | 648 | request.actions.add(act) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 649 | |
| 650 | logging.info("Inserting flow") |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 651 | self.controller.message_send(request) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 652 | do_barrier(self.controller) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 653 | return (pkt,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 654 | |
| 655 | |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 656 | ########################### Verify Stats Functions ########################################################################################### |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 657 | def get_flowstats(self,match): |
| 658 | # Generate flow_stats request |
| 659 | |
| 660 | stat_req = message.flow_stats_request() |
| 661 | stat_req.match = match |
| 662 | stat_req.table_id = 0xff |
| 663 | stat_req.out_port = ofp.OFPP_NONE |
| 664 | |
| 665 | logging.info("Sending stats request") |
| 666 | response, pkt = self.controller.transact(stat_req, |
| 667 | timeout=5) |
| 668 | self.assertTrue(response is not None,"No response to stats request") |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 669 | |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 670 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 671 | def get_portstats(self,port_num): |
| 672 | |
| 673 | # Return all the port counters in the form a tuple |
| 674 | port_stats_req = message.port_stats_request() |
| 675 | port_stats_req.port_no = port_num |
| 676 | response,pkt = self.controller.transact(port_stats_req) |
| 677 | self.assertTrue(response is not None,"No response received for port stats request") |
| 678 | rx_pkts=0 |
| 679 | tx_pkts=0 |
| 680 | rx_byts=0 |
| 681 | tx_byts=0 |
| 682 | rx_drp =0 |
| 683 | tx_drp = 0 |
| 684 | rx_err=0 |
| 685 | tx_err =0 |
| 686 | rx_fr_err=0 |
| 687 | rx_ovr_err=0 |
| 688 | rx_crc_err=0 |
| 689 | collisions = 0 |
| 690 | tx_err=0 |
| 691 | |
| 692 | |
| 693 | for obj in response.stats: |
| 694 | rx_pkts += obj.rx_packets |
| 695 | tx_pkts += obj.tx_packets |
| 696 | rx_byts += obj.rx_bytes |
| 697 | tx_byts += obj.tx_bytes |
| 698 | rx_drp += obj.rx_dropped |
| 699 | tx_drp += obj.tx_dropped |
| 700 | rx_err += obj.rx_errors |
| 701 | rx_fr_err += obj.rx_frame_err |
| 702 | rx_ovr_err += obj.rx_over_err |
| 703 | rx_crc_err += obj.rx_crc_err |
| 704 | collisions+= obj.collisions |
| 705 | tx_err += obj.tx_errors |
| 706 | |
| 707 | 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) |
| 708 | |
| 709 | def get_queuestats(self,port_num,queue_id): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 710 | #Generate Queue Stats request |
| 711 | |
| 712 | request = message.queue_stats_request() |
| 713 | request.port_no = port_num |
| 714 | request.queue_id = queue_id |
| 715 | (queue_stats, p) = self.controller.transact(request) |
| 716 | self.assertNotEqual(queue_stats, None, "Queue stats request failed") |
| 717 | |
| 718 | return (queue_stats,p) |
| 719 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 720 | def get_tablestats(self): |
| 721 | # Send Table_Stats request (retrieve current table counters ) |
| 722 | |
| 723 | stat_req = message.table_stats_request() |
| 724 | response, pkt = self.controller.transact(stat_req, |
| 725 | timeout=5) |
| 726 | self.assertTrue(response is not None, |
| 727 | "No response to stats request") |
| 728 | current_lookedup = 0 |
| 729 | current_matched = 0 |
| 730 | current_active = 0 |
| 731 | |
| 732 | for obj in response.stats: |
| 733 | current_lookedup += obj.lookup_count |
| 734 | current_matched += obj.matched_count |
| 735 | current_active += obj.active_count |
| 736 | |
| 737 | return (current_lookedup,current_matched,current_active) |
| 738 | |
| 739 | |
| 740 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 741 | def verify_tablestats(self,expect_lookup=None,expect_match=None,expect_active=None): |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 742 | |
| 743 | stat_req = message.table_stats_request() |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 744 | |
Rich Lane | 90b3d73 | 2012-12-31 10:03:50 -0800 | [diff] [blame] | 745 | for i in range(0,100): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 746 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 747 | logging.info("Sending stats request") |
| 748 | # TODO: move REPLY_MORE handling to controller.transact? |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 749 | response, pkt = self.controller.transact(stat_req, |
| 750 | timeout=5) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 751 | self.assertTrue(response is not None,"No response to stats request") |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 752 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 753 | lookedup = 0 |
| 754 | matched = 0 |
| 755 | active = 0 |
| 756 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 757 | for item in response.stats: |
| 758 | lookedup += item.lookup_count |
| 759 | matched += item.matched_count |
| 760 | active += item.active_count |
| 761 | |
Rich Lane | afcd0dd | 2013-01-03 20:54:56 -0800 | [diff] [blame] | 762 | logging.info("Packets Looked up: %d", lookedup) |
| 763 | logging.info("Packets matched: %d", matched) |
| 764 | logging.info("Active flow entries: %d", active) |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 765 | |
Rich Lane | 175f956 | 2013-01-03 20:58:40 -0800 | [diff] [blame] | 766 | if (expect_lookup == None or lookedup >= expect_lookup) and \ |
| 767 | (expect_match == None or matched >= expect_match) and \ |
| 768 | (expect_active == None or active >= expect_active): |
Rich Lane | 90b3d73 | 2012-12-31 10:03:50 -0800 | [diff] [blame] | 769 | break |
| 770 | |
| 771 | sleep(0.1) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 772 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 773 | if expect_lookup != None : |
Rich Lane | 3e77779 | 2013-01-03 21:30:30 -0800 | [diff] [blame] | 774 | self.assertEqual(expect_lookup, lookedup, "lookup counter is not incremented properly") |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 775 | if expect_match != None : |
Rich Lane | 3e77779 | 2013-01-03 21:30:30 -0800 | [diff] [blame] | 776 | self.assertEqual(expect_match, matched, "matched counter is not incremented properly") |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 777 | if expect_active != None : |
Rich Lane | 3e77779 | 2013-01-03 21:30:30 -0800 | [diff] [blame] | 778 | self.assertEqual(expect_active, active ,"active counter is not incremented properly") |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 779 | |
| 780 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 781 | def verify_flowstats(self,match,byte_count=None,packet_count=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 782 | # Verify flow counters : byte_count and packet_count |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 783 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 784 | stat_req = message.flow_stats_request() |
| 785 | stat_req.match = match |
| 786 | stat_req.table_id = 0xff |
| 787 | stat_req.out_port = ofp.OFPP_NONE |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 788 | |
Rich Lane | 90b3d73 | 2012-12-31 10:03:50 -0800 | [diff] [blame] | 789 | for i in range(0,100): |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 790 | logging.info("Sending stats request") |
| 791 | # TODO: move REPLY_MORE handling to controller.transact? |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 792 | response, pkt = self.controller.transact(stat_req, |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 793 | timeout=5) |
| 794 | self.assertTrue(response is not None,"No response to stats request") |
| 795 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 796 | packet_counter = 0 |
| 797 | byte_counter = 0 |
| 798 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 799 | for item in response.stats: |
| 800 | packet_counter += item.packet_count |
| 801 | byte_counter += item.byte_count |
| 802 | |
Rich Lane | c9e4184 | 2013-01-03 21:31:42 -0800 | [diff] [blame] | 803 | logging.info("Received %d packets", packet_counter) |
| 804 | logging.info("Received %d bytes", byte_counter) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 805 | |
Rich Lane | c9e4184 | 2013-01-03 21:31:42 -0800 | [diff] [blame] | 806 | if (packet_count == None or packet_counter >= packet_count) and \ |
| 807 | (byte_count == None or byte_counter >= byte_count): |
Rich Lane | 90b3d73 | 2012-12-31 10:03:50 -0800 | [diff] [blame] | 808 | break |
| 809 | |
| 810 | sleep(0.1) |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 811 | |
| 812 | if packet_count != None : |
Rich Lane | c9e4184 | 2013-01-03 21:31:42 -0800 | [diff] [blame] | 813 | self.assertEqual(packet_count, packet_counter, "packet_count counter is not incremented correctly") |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 814 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 815 | if byte_count != None : |
Rich Lane | c9e4184 | 2013-01-03 21:31:42 -0800 | [diff] [blame] | 816 | self.assertEqual(byte_count, byte_counter, "byte_count counter is not incremented correctly") |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 817 | |
| 818 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 819 | 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] | 820 | |
| 821 | |
| 822 | stat_req = message.port_stats_request() |
| 823 | stat_req.port_no = port |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 824 | |
Rich Lane | 90b3d73 | 2012-12-31 10:03:50 -0800 | [diff] [blame] | 825 | for i in range(0,100): |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 826 | logging.info("Sending stats request") |
| 827 | response, pkt = self.controller.transact(stat_req, |
| 828 | timeout=5) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 829 | self.assertTrue(response is not None, |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 830 | "No response to stats request") |
| 831 | self.assertTrue(len(response.stats) == 1, |
| 832 | "Did not receive port stats reply") |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 833 | |
| 834 | sentp = recvp = 0 |
| 835 | sentb = recvb = 0 |
| 836 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 837 | for item in response.stats: |
| 838 | sentp += item.tx_packets |
| 839 | recvp += item.rx_packets |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 840 | recvb += item.rx_bytes |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 841 | sentb += item.tx_bytes |
| 842 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 843 | |
| 844 | logging.info("Sent " + str(sentp) + " packets") |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 845 | logging.info("Received " + str(recvp) + " packets") |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 846 | logging.info("Received " + str(recvb) + "bytes") |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 847 | logging.info("Sent" + str(sentb) + "bytes") |
Rich Lane | 90b3d73 | 2012-12-31 10:03:50 -0800 | [diff] [blame] | 848 | |
| 849 | if (tx_packets == None or tx_packets == sentp) and \ |
| 850 | (rx_packets == None or rx_packets == recvp) and \ |
| 851 | (tx_byte == None or tx_byte == sentb) and \ |
| 852 | (rx_byte == None or rx_byte == recvb): |
| 853 | break |
| 854 | |
| 855 | sleep(0.1) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 856 | |
ShreyaPandita | a6dfbfc | 2012-11-05 17:45:22 -0500 | [diff] [blame] | 857 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 858 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 859 | if (tx_packets != None): |
| 860 | self.assertEqual(tx_packets,item.tx_packets,"rx_packets counter is not incremented correctly") |
| 861 | if (rx_packets != None): |
| 862 | self.assertEqual(rx_packets,item.rx_packets,"tx_packets counter is not incremented correctly") |
| 863 | if (rx_byte != None): |
| 864 | self.assertEqual(rx_byte,item.rx_bytes,"rx_bytes counter is not incremented correctly") |
| 865 | if (tx_byte != None): |
| 866 | 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] | 867 | |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 868 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 869 | def verify_queuestats(self,port_num,queue_id,expect_packet=None,expect_byte=None): |
| 870 | |
| 871 | # Verify queue counters : tx_packets and tx_bytes |
| 872 | |
| 873 | request = message.queue_stats_request() |
| 874 | request.port_no = port_num |
| 875 | request.queue_id = queue_id |
| 876 | |
Rich Lane | 90b3d73 | 2012-12-31 10:03:50 -0800 | [diff] [blame] | 877 | for i in range(0,100): |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 878 | |
| 879 | logging.info("Sending stats request") |
| 880 | |
| 881 | (queue_stats, p) = self.controller.transact(request) |
| 882 | self.assertNotEqual(queue_stats, None, "Queue stats request failed") |
| 883 | packet_counter = 0 |
| 884 | byte_counter = 0 |
| 885 | |
ShreyaPandita | a6dfbfc | 2012-11-05 17:45:22 -0500 | [diff] [blame] | 886 | for item in queue_stats.stats: |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 887 | packet_counter += item.tx_packets |
| 888 | byte_counter += item.tx_bytes |
| 889 | |
| 890 | logging.info("Transmitted" + str(packet_counter) + " packets") |
| 891 | logging.info("Transmitted" + str(byte_counter) + "bytes") |
| 892 | |
Rich Lane | 90b3d73 | 2012-12-31 10:03:50 -0800 | [diff] [blame] | 893 | if (expect_packet == None or packet_counter == expect_packet) and \ |
| 894 | (expect_byte == None or byte_counter == expect_byte): |
| 895 | break |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 896 | |
Rich Lane | 90b3d73 | 2012-12-31 10:03:50 -0800 | [diff] [blame] | 897 | sleep(0.1) |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 898 | |
| 899 | if expect_packet != None : |
| 900 | self.assertEqual(packet_counter,expect_packet,"tx_packets counter is not incremented correctly") |
| 901 | |
| 902 | if expect_byte != None : |
| 903 | self.assertEqual(byte_counter,expect_byte,"tx_bytes counter is not incremented correctly") |
| 904 | |
| 905 | |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 906 | ############################## Various delete commands ############################################################################################# |
| 907 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 908 | def strict_delete(self,match,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 909 | # Issue Strict Delete |
| 910 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 911 | #Create flow_mod message, command DELETE_STRICT |
| 912 | msg4 = message.flow_mod() |
| 913 | msg4.out_port = ofp.OFPP_NONE |
| 914 | msg4.command = ofp.OFPFC_DELETE_STRICT |
| 915 | msg4.buffer_id = 0xffffffff |
| 916 | msg4.match = match |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 917 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 918 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 919 | msg4.priority = priority |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 920 | self.controller.message_send(msg4) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 921 | do_barrier(self.controller) |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 922 | |
| 923 | |
| 924 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 925 | def nonstrict_delete(self,match,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 926 | # Issue Non_Strict Delete |
| 927 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 928 | #Create flow_mod message, command DELETE |
| 929 | msg6 = message.flow_mod() |
| 930 | msg6.out_port = ofp.OFPP_NONE |
| 931 | msg6.command = ofp.OFPFC_DELETE |
| 932 | msg6.buffer_id = 0xffffffff |
| 933 | msg6.match = match |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 934 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 935 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 936 | msg6.priority = priority |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 937 | |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 938 | self.controller.message_send(msg6) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 939 | do_barrier(self.controller) |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 940 | |
| 941 | |
| 942 | ########################################################################################################################################################### |
| 943 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 944 | def send_packet(obj, pkt, ingress_port, egress_port): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 945 | #Send Packets on a specified ingress_port and verify if its recieved on correct egress_port. |
| 946 | |
| 947 | obj.dataplane.send(ingress_port, str(pkt)) |
| 948 | exp_pkt_arg = pkt |
| 949 | exp_port = egress_port |
| 950 | |
| 951 | (rcv_port, rcv_pkt, pkt_time) = obj.dataplane.poll(timeout=2, |
| 952 | port_number=exp_port, |
| 953 | exp_pkt=exp_pkt_arg) |
| 954 | obj.assertTrue(rcv_pkt is not None, |
| 955 | "Packet not received on port " + str(egress_port)) |
| 956 | obj.assertEqual(rcv_port, egress_port, |
| 957 | "Packet received on port " + str(rcv_port) + |
| 958 | ", expected port " + str(egress_port)) |
| 959 | obj.assertEqual(str(pkt), str(rcv_pkt), |
| 960 | 'Response packet does not match send packet') |
| 961 | |
| 962 | |
ShreyaPandita | 572e64b | 2012-09-28 14:41:06 -0400 | [diff] [blame] | 963 | def sw_supported_actions(parent,use_cache=False): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 964 | #Returns the switch's supported actions |
| 965 | |
| 966 | cache_supported_actions = None |
| 967 | if cache_supported_actions is None or not use_cache: |
| 968 | request = message.features_request() |
| 969 | (reply, pkt) = parent.controller.transact(request) |
| 970 | parent.assertTrue(reply is not None, "Did not get response to ftr req") |
| 971 | cache_supported_actions = reply.actions |
| 972 | return cache_supported_actions |
| 973 | |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 974 | ############################################################################################################################################################## |
| 975 | |