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