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] |
| 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 | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 107 | def match_ethernet_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 |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 111 | pkt_MatchSrc = simple_eth_packet(dl_src='00:01:01:01:01:01') |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 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 |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 139 | pkt_matchdst = simple_eth_packet(dl_dst='00:01:01:01:01:01') |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 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 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 257 | def match_vlan_id(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 258 | #Generate Match_Vlan_Id |
| 259 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 260 | #Create a simple tcp packet and generate match on ethernet dst address flow |
| 261 | pkt_matchvlanid = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=1) |
| 262 | match = parse.packet_to_flow_match(pkt_matchvlanid) |
| 263 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 264 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 265 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_DL_VLAN |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 266 | msg = message.flow_mod() |
| 267 | msg.out_port = ofp.OFPP_NONE |
| 268 | msg.command = ofp.OFPFC_ADD |
| 269 | msg.buffer_id = 0xffffffff |
| 270 | msg.match = match |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 271 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 272 | msg.priority = priority |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 273 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 274 | act = action.action_output() |
| 275 | act.port = of_ports[1] |
| 276 | self.assertTrue(msg.actions.add(act), "could not add action") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 277 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 278 | rv = self.controller.message_send(msg) |
| 279 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 280 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 281 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 282 | return (pkt_matchvlanid,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 283 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 284 | def match_vlan_pcp(self,of_ports,priority=None): |
ShreyaPandita | 055102a | 2012-11-28 11:43:45 -0500 | [diff] [blame] | 285 | #Generate Match_Vlan_Priority |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 286 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 287 | #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] | 288 | 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] | 289 | match = parse.packet_to_flow_match(pkt_matchvlanpcp) |
| 290 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 291 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 292 | 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] | 293 | msg = message.flow_mod() |
| 294 | msg.out_port = ofp.OFPP_NONE |
| 295 | msg.command = ofp.OFPFC_ADD |
| 296 | msg.buffer_id = 0xffffffff |
| 297 | msg.match = match |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 298 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 299 | msg.priority = priority |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 300 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 301 | act = action.action_output() |
| 302 | act.port = of_ports[1] |
| 303 | self.assertTrue(msg.actions.add(act), "could not add action") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 304 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 305 | rv = self.controller.message_send(msg) |
| 306 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 307 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 308 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 309 | return (pkt_matchvlanpcp,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 310 | |
| 311 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 312 | def match_mul_l2(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 313 | #Generate Match_Mul_L2 flow |
| 314 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 315 | #Create a simple eth packet and generate match on ethernet protocol flow |
| 316 | pkt_mulL2 = simple_eth_packet(dl_type=0x88cc,dl_src='00:01:01:01:01:01',dl_dst='00:01:01:01:01:02') |
| 317 | match = parse.packet_to_flow_match(pkt_mulL2) |
| 318 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 319 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 320 | match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_DL_DST ^ofp.OFPFW_DL_SRC |
| 321 | msg = message.flow_mod() |
| 322 | msg.out_port = ofp.OFPP_NONE |
| 323 | msg.command = ofp.OFPFC_ADD |
| 324 | msg.buffer_id = 0xffffffff |
| 325 | msg.match = match |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 326 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 327 | msg.priority = priority |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 328 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 329 | act = action.action_output() |
| 330 | act.port = of_ports[1] |
| 331 | self.assertTrue(msg.actions.add(act), "could not add action") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 332 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 333 | rv = self.controller.message_send(msg) |
| 334 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 335 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 336 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 337 | return (pkt_mulL2,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 338 | |
| 339 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 340 | def match_mul_l4(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 341 | #Generate Match_Mul_L4 flow |
| 342 | |
| 343 | #Create a simple tcp packet and generate match on tcp protocol flow |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 344 | pkt_mulL4 = simple_tcp_packet(tcp_sport=111,tcp_dport=112) |
| 345 | match = parse.packet_to_flow_match(pkt_mulL4) |
| 346 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 347 | 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] | 348 | msg = message.flow_mod() |
| 349 | msg.out_port = ofp.OFPP_NONE |
| 350 | msg.command = ofp.OFPFC_ADD |
| 351 | msg.buffer_id = 0xffffffff |
| 352 | msg.match = match |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 353 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 354 | msg.priority = priority |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 355 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 356 | act = action.action_output() |
| 357 | act.port = of_ports[1] |
| 358 | self.assertTrue(msg.actions.add(act), "could not add action") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 359 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 360 | rv = self.controller.message_send(msg) |
| 361 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 362 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 363 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 364 | return (pkt_mulL4,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 365 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 366 | def match_ip_tos(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 367 | #Generate a Match on IP Type of service flow |
| 368 | |
| 369 | #Create a simple tcp packet and generate match on Type of service |
Rich Lane | b5c7379 | 2012-12-03 17:12:32 -0800 | [diff] [blame] | 370 | pkt_iptos = simple_tcp_packet(ip_tos=28) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 371 | match = parse.packet_to_flow_match(pkt_iptos) |
| 372 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 373 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 374 | 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] | 375 | msg = message.flow_mod() |
| 376 | msg.out_port = ofp.OFPP_NONE |
| 377 | msg.command = ofp.OFPFC_ADD |
| 378 | msg.buffer_id = 0xffffffff |
| 379 | msg.match = match |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 380 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 381 | msg.priority = priority |
| 382 | act = action.action_output() |
| 383 | act.port = of_ports[1] |
| 384 | self.assertTrue(msg.actions.add(act), "could not add action") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 385 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 386 | rv = self.controller.message_send(msg) |
| 387 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 388 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 389 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 390 | return (pkt_iptos,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 391 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 392 | def match_ip_protocol(self,of_ports,priority=None): |
| 393 | #Generate a Match on IP Protocol |
| 394 | |
| 395 | #Create a simple tcp packet and generate match on Type of service |
| 396 | pkt_iptos = simple_tcp_packet() |
| 397 | match = parse.packet_to_flow_match(pkt_iptos) |
| 398 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 399 | |
| 400 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE^ofp.OFPFW_NW_PROTO |
| 401 | msg = message.flow_mod() |
| 402 | msg.out_port = ofp.OFPP_NONE |
| 403 | msg.command = ofp.OFPFC_ADD |
| 404 | msg.buffer_id = 0xffffffff |
| 405 | msg.match = match |
| 406 | if priority != None : |
| 407 | msg.priority = priority |
| 408 | act = action.action_output() |
| 409 | act.port = of_ports[1] |
| 410 | self.assertTrue(msg.actions.add(act), "could not add action") |
| 411 | |
| 412 | rv = self.controller.message_send(msg) |
| 413 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 414 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
| 415 | |
| 416 | return (pkt_iptos,match) |
| 417 | |
| 418 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 419 | def match_tcp_src(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 420 | #Generate Match_Tcp_Src |
| 421 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 422 | #Create a simple tcp packet and generate match on tcp source port flow |
| 423 | pkt_matchtSrc = simple_tcp_packet(tcp_sport=111) |
| 424 | match = parse.packet_to_flow_match(pkt_matchtSrc) |
| 425 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 426 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 427 | 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] | 428 | msg = message.flow_mod() |
| 429 | msg.out_port = ofp.OFPP_NONE |
| 430 | msg.command = ofp.OFPFC_ADD |
| 431 | msg.buffer_id = 0xffffffff |
| 432 | msg.match = match |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 433 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 434 | msg.priority = priority |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 435 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 436 | act = action.action_output() |
| 437 | act.port = of_ports[1] |
| 438 | self.assertTrue(msg.actions.add(act), "could not add action") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 439 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 440 | rv = self.controller.message_send(msg) |
| 441 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 442 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 443 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 444 | return (pkt_matchtSrc,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 445 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 446 | def match_tcp_dst(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 447 | #Generate Match_Tcp_Dst |
| 448 | |
| 449 | #Create a simple tcp packet and generate match on tcp destination port flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 450 | pkt_matchdst = simple_tcp_packet(tcp_dport=112) |
| 451 | match = parse.packet_to_flow_match(pkt_matchdst) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 452 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 453 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 454 | 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] | 455 | msg = message.flow_mod() |
| 456 | msg.out_port = ofp.OFPP_NONE |
| 457 | msg.command = ofp.OFPFC_ADD |
| 458 | msg.buffer_id = 0xffffffff |
| 459 | msg.match = match |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 460 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 461 | msg.priority = priority |
| 462 | act = action.action_output() |
| 463 | act.port = of_ports[1] |
| 464 | self.assertTrue(msg.actions.add(act), "could not add action") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 465 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 466 | rv = self.controller.message_send(msg) |
| 467 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 468 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 469 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 470 | return (pkt_matchdst,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 471 | |
ShreyaPandita | 055102a | 2012-11-28 11:43:45 -0500 | [diff] [blame] | 472 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 473 | def match_ethernet_type(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 474 | #Generate a Match_Ethernet_Type flow |
| 475 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 476 | #Create a simple tcp packet and generate match on ethernet type flow |
| 477 | pkt_matchtype = simple_eth_packet(dl_type=0x88cc) |
| 478 | match = parse.packet_to_flow_match(pkt_matchtype) |
| 479 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 480 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 481 | match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE |
| 482 | msg = message.flow_mod() |
| 483 | msg.out_port = ofp.OFPP_NONE |
| 484 | msg.command = ofp.OFPFC_ADD |
| 485 | msg.buffer_id = 0xffffffff |
| 486 | msg.match = match |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 487 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 488 | msg.priority = priority |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 489 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 490 | act = action.action_output() |
| 491 | act.port = of_ports[1] |
| 492 | self.assertTrue(msg.actions.add(act), "could not add action") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 493 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 494 | rv = self.controller.message_send(msg) |
| 495 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 496 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 497 | return (pkt_matchtype,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 498 | |
| 499 | |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 500 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 501 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 502 | def strict_modify_flow_action(self,egress_port,match,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 503 | # Strict Modify the flow Action |
| 504 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 505 | #Create a flow_mod message , command MODIFY_STRICT |
| 506 | msg5 = message.flow_mod() |
| 507 | msg5.match = match |
| 508 | msg5.cookie = random.randint(0,9007199254740992) |
| 509 | msg5.command = ofp.OFPFC_MODIFY_STRICT |
| 510 | msg5.buffer_id = 0xffffffff |
| 511 | act5 = action.action_output() |
| 512 | act5.port = egress_port |
| 513 | self.assertTrue(msg5.actions.add(act5), "could not add action") |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 514 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 515 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 516 | msg5.priority = priority |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 517 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 518 | # Send the flow with action A' |
| 519 | rv = self.controller.message_send (msg5) |
| 520 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 521 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 522 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 523 | def modify_flow_action(self,of_ports,match,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 524 | # Modify the flow action |
| 525 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 526 | #Create a flow_mod message , command MODIFY |
| 527 | msg8 = message.flow_mod() |
| 528 | msg8.match = match |
| 529 | msg8.cookie = random.randint(0,9007199254740992) |
| 530 | msg8.command = ofp.OFPFC_MODIFY |
| 531 | #out_port will be ignored for flow adds and flow modify (here for test-case Add_Modify_With_Outport) |
| 532 | msg8.out_port = of_ports[3] |
| 533 | msg8.buffer_id = 0xffffffff |
| 534 | act8 = action.action_output() |
| 535 | act8.port = of_ports[2] |
| 536 | self.assertTrue(msg8.actions.add(act8), "could not add action") |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 537 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 538 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 539 | msg8.priority = priority |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 540 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 541 | # Send the flow with action A' |
| 542 | rv = self.controller.message_send (msg8) |
| 543 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 544 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 545 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 546 | def enqueue(self,ingress_port,egress_port,egress_queue_id): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 547 | #Generate a flow with enqueue action i.e output to a queue configured on a egress_port |
| 548 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 549 | pkt = simple_tcp_packet() |
| 550 | match = packet_to_flow_match(self, pkt) |
| 551 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 552 | self.assertTrue(match is not None, |
| 553 | "Could not generate flow match from pkt") |
| 554 | |
| 555 | match.in_port = ingress_port |
| 556 | request = message.flow_mod() |
| 557 | request.match = match |
| 558 | request.buffer_id = 0xffffffff |
| 559 | act = action.action_enqueue() |
| 560 | act.port = egress_port |
| 561 | act.queue_id = egress_queue_id |
| 562 | self.assertTrue(request.actions.add(act), "Could not add action") |
| 563 | |
| 564 | logging.info("Inserting flow") |
| 565 | rv = self.controller.message_send(request) |
| 566 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 567 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
| 568 | return (pkt,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 569 | |
| 570 | |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 571 | ########################### Verify Stats Functions ########################################################################################### |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 572 | def get_flowstats(self,match): |
| 573 | # Generate flow_stats request |
| 574 | |
| 575 | stat_req = message.flow_stats_request() |
| 576 | stat_req.match = match |
| 577 | stat_req.table_id = 0xff |
| 578 | stat_req.out_port = ofp.OFPP_NONE |
| 579 | |
| 580 | logging.info("Sending stats request") |
| 581 | response, pkt = self.controller.transact(stat_req, |
| 582 | timeout=5) |
| 583 | self.assertTrue(response is not None,"No response to stats request") |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 584 | |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 585 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 586 | def get_portstats(self,port_num): |
| 587 | |
| 588 | # Return all the port counters in the form a tuple |
| 589 | port_stats_req = message.port_stats_request() |
| 590 | port_stats_req.port_no = port_num |
| 591 | response,pkt = self.controller.transact(port_stats_req) |
| 592 | self.assertTrue(response is not None,"No response received for port stats request") |
| 593 | rx_pkts=0 |
| 594 | tx_pkts=0 |
| 595 | rx_byts=0 |
| 596 | tx_byts=0 |
| 597 | rx_drp =0 |
| 598 | tx_drp = 0 |
| 599 | rx_err=0 |
| 600 | tx_err =0 |
| 601 | rx_fr_err=0 |
| 602 | rx_ovr_err=0 |
| 603 | rx_crc_err=0 |
| 604 | collisions = 0 |
| 605 | tx_err=0 |
| 606 | |
| 607 | |
| 608 | for obj in response.stats: |
| 609 | rx_pkts += obj.rx_packets |
| 610 | tx_pkts += obj.tx_packets |
| 611 | rx_byts += obj.rx_bytes |
| 612 | tx_byts += obj.tx_bytes |
| 613 | rx_drp += obj.rx_dropped |
| 614 | tx_drp += obj.tx_dropped |
| 615 | rx_err += obj.rx_errors |
| 616 | rx_fr_err += obj.rx_frame_err |
| 617 | rx_ovr_err += obj.rx_over_err |
| 618 | rx_crc_err += obj.rx_crc_err |
| 619 | collisions+= obj.collisions |
| 620 | tx_err += obj.tx_errors |
| 621 | |
| 622 | 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) |
| 623 | |
| 624 | def get_queuestats(self,port_num,queue_id): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 625 | #Generate Queue Stats request |
| 626 | |
| 627 | request = message.queue_stats_request() |
| 628 | request.port_no = port_num |
| 629 | request.queue_id = queue_id |
| 630 | (queue_stats, p) = self.controller.transact(request) |
| 631 | self.assertNotEqual(queue_stats, None, "Queue stats request failed") |
| 632 | |
| 633 | return (queue_stats,p) |
| 634 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 635 | def get_tablestats(self): |
| 636 | # Send Table_Stats request (retrieve current table counters ) |
| 637 | |
| 638 | stat_req = message.table_stats_request() |
| 639 | response, pkt = self.controller.transact(stat_req, |
| 640 | timeout=5) |
| 641 | self.assertTrue(response is not None, |
| 642 | "No response to stats request") |
| 643 | current_lookedup = 0 |
| 644 | current_matched = 0 |
| 645 | current_active = 0 |
| 646 | |
| 647 | for obj in response.stats: |
| 648 | current_lookedup += obj.lookup_count |
| 649 | current_matched += obj.matched_count |
| 650 | current_active += obj.active_count |
| 651 | |
| 652 | return (current_lookedup,current_matched,current_active) |
| 653 | |
| 654 | |
| 655 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 656 | def verify_tablestats(self,expect_lookup=None,expect_match=None,expect_active=None): |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 657 | |
| 658 | stat_req = message.table_stats_request() |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 659 | |
Rich Lane | 90b3d73 | 2012-12-31 10:03:50 -0800 | [diff] [blame] | 660 | for i in range(0,100): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 661 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 662 | logging.info("Sending stats request") |
| 663 | # TODO: move REPLY_MORE handling to controller.transact? |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 664 | response, pkt = self.controller.transact(stat_req, |
| 665 | timeout=5) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 666 | self.assertTrue(response is not None,"No response to stats request") |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 667 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 668 | lookedup = 0 |
| 669 | matched = 0 |
| 670 | active = 0 |
| 671 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 672 | for item in response.stats: |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 673 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 674 | lookedup += item.lookup_count |
| 675 | matched += item.matched_count |
| 676 | active += item.active_count |
| 677 | |
| 678 | logging.info("Packets Looked up " + str(lookedup) + " packets") |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 679 | logging.info("Packets matched " + str(matched) + "packets") |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 680 | logging.info("Active flow entries" + str(active) + "flows") |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 681 | |
Rich Lane | 90b3d73 | 2012-12-31 10:03:50 -0800 | [diff] [blame] | 682 | if (expect_lookup == None or expect_lookup == lookedup) and \ |
| 683 | (expect_match == None or expect_match == matched) and \ |
| 684 | (expect_active == None or expect_active == active): |
| 685 | break |
| 686 | |
| 687 | sleep(0.1) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 688 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 689 | if expect_lookup != None : |
| 690 | self.assertEqual(expect_lookup,item.lookup_count,"lookup counter is not incremented properly") |
| 691 | if expect_match != None : |
| 692 | self.assertEqual(expect_match,item.matched_count, "matched counter is not incremented properly") |
| 693 | if expect_active != None : |
| 694 | self.assertEqual(expect_active,item.active_count,"active counter is not incremented properly") |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 695 | |
| 696 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 697 | def verify_flowstats(self,match,byte_count=None,packet_count=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 698 | # Verify flow counters : byte_count and packet_count |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 699 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 700 | stat_req = message.flow_stats_request() |
| 701 | stat_req.match = match |
| 702 | stat_req.table_id = 0xff |
| 703 | stat_req.out_port = ofp.OFPP_NONE |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 704 | |
Rich Lane | 90b3d73 | 2012-12-31 10:03:50 -0800 | [diff] [blame] | 705 | for i in range(0,100): |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 706 | logging.info("Sending stats request") |
| 707 | # TODO: move REPLY_MORE handling to controller.transact? |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 708 | response, pkt = self.controller.transact(stat_req, |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 709 | timeout=5) |
| 710 | self.assertTrue(response is not None,"No response to stats request") |
| 711 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 712 | packet_counter = 0 |
| 713 | byte_counter = 0 |
| 714 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 715 | for item in response.stats: |
| 716 | packet_counter += item.packet_count |
| 717 | byte_counter += item.byte_count |
| 718 | |
| 719 | logging.info("Recieved" + str(item.packet_count) + " packets") |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 720 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 721 | logging.info("Received " + str(item.byte_count) + "bytes") |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 722 | |
Rich Lane | 90b3d73 | 2012-12-31 10:03:50 -0800 | [diff] [blame] | 723 | if (packet_count == None or packet_count == packet_counter) and \ |
| 724 | (byte_count == None or byte_count == byte_counter): |
| 725 | break |
| 726 | |
| 727 | sleep(0.1) |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 728 | |
| 729 | if packet_count != None : |
| 730 | 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] | 731 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 732 | if byte_count != None : |
| 733 | 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] | 734 | |
| 735 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 736 | 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] | 737 | |
| 738 | |
| 739 | stat_req = message.port_stats_request() |
| 740 | stat_req.port_no = port |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 741 | |
Rich Lane | 90b3d73 | 2012-12-31 10:03:50 -0800 | [diff] [blame] | 742 | for i in range(0,100): |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 743 | logging.info("Sending stats request") |
| 744 | response, pkt = self.controller.transact(stat_req, |
| 745 | timeout=5) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 746 | self.assertTrue(response is not None, |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 747 | "No response to stats request") |
| 748 | self.assertTrue(len(response.stats) == 1, |
| 749 | "Did not receive port stats reply") |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 750 | |
| 751 | sentp = recvp = 0 |
| 752 | sentb = recvb = 0 |
| 753 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 754 | for item in response.stats: |
| 755 | sentp += item.tx_packets |
| 756 | recvp += item.rx_packets |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 757 | recvb += item.rx_bytes |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 758 | sentb += item.tx_bytes |
| 759 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 760 | |
| 761 | logging.info("Sent " + str(sentp) + " packets") |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 762 | logging.info("Received " + str(recvp) + " packets") |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 763 | logging.info("Received " + str(recvb) + "bytes") |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 764 | logging.info("Sent" + str(sentb) + "bytes") |
Rich Lane | 90b3d73 | 2012-12-31 10:03:50 -0800 | [diff] [blame] | 765 | |
| 766 | if (tx_packets == None or tx_packets == sentp) and \ |
| 767 | (rx_packets == None or rx_packets == recvp) and \ |
| 768 | (tx_byte == None or tx_byte == sentb) and \ |
| 769 | (rx_byte == None or rx_byte == recvb): |
| 770 | break |
| 771 | |
| 772 | sleep(0.1) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 773 | |
ShreyaPandita | a6dfbfc | 2012-11-05 17:45:22 -0500 | [diff] [blame] | 774 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 775 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 776 | if (tx_packets != None): |
| 777 | self.assertEqual(tx_packets,item.tx_packets,"rx_packets counter is not incremented correctly") |
| 778 | if (rx_packets != None): |
| 779 | self.assertEqual(rx_packets,item.rx_packets,"tx_packets counter is not incremented correctly") |
| 780 | if (rx_byte != None): |
| 781 | self.assertEqual(rx_byte,item.rx_bytes,"rx_bytes counter is not incremented correctly") |
| 782 | if (tx_byte != None): |
| 783 | 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] | 784 | |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 785 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 786 | def verify_queuestats(self,port_num,queue_id,expect_packet=None,expect_byte=None): |
| 787 | |
| 788 | # Verify queue counters : tx_packets and tx_bytes |
| 789 | |
| 790 | request = message.queue_stats_request() |
| 791 | request.port_no = port_num |
| 792 | request.queue_id = queue_id |
| 793 | |
Rich Lane | 90b3d73 | 2012-12-31 10:03:50 -0800 | [diff] [blame] | 794 | for i in range(0,100): |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 795 | |
| 796 | logging.info("Sending stats request") |
| 797 | |
| 798 | (queue_stats, p) = self.controller.transact(request) |
| 799 | self.assertNotEqual(queue_stats, None, "Queue stats request failed") |
| 800 | packet_counter = 0 |
| 801 | byte_counter = 0 |
| 802 | |
ShreyaPandita | a6dfbfc | 2012-11-05 17:45:22 -0500 | [diff] [blame] | 803 | for item in queue_stats.stats: |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 804 | packet_counter += item.tx_packets |
| 805 | byte_counter += item.tx_bytes |
| 806 | |
| 807 | logging.info("Transmitted" + str(packet_counter) + " packets") |
| 808 | logging.info("Transmitted" + str(byte_counter) + "bytes") |
| 809 | |
Rich Lane | 90b3d73 | 2012-12-31 10:03:50 -0800 | [diff] [blame] | 810 | if (expect_packet == None or packet_counter == expect_packet) and \ |
| 811 | (expect_byte == None or byte_counter == expect_byte): |
| 812 | break |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 813 | |
Rich Lane | 90b3d73 | 2012-12-31 10:03:50 -0800 | [diff] [blame] | 814 | sleep(0.1) |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 815 | |
| 816 | if expect_packet != None : |
| 817 | self.assertEqual(packet_counter,expect_packet,"tx_packets counter is not incremented correctly") |
| 818 | |
| 819 | if expect_byte != None : |
| 820 | self.assertEqual(byte_counter,expect_byte,"tx_bytes counter is not incremented correctly") |
| 821 | |
| 822 | |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 823 | ############################## Various delete commands ############################################################################################# |
| 824 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 825 | def strict_delete(self,match,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 826 | # Issue Strict Delete |
| 827 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 828 | #Create flow_mod message, command DELETE_STRICT |
| 829 | msg4 = message.flow_mod() |
| 830 | msg4.out_port = ofp.OFPP_NONE |
| 831 | msg4.command = ofp.OFPFC_DELETE_STRICT |
| 832 | msg4.buffer_id = 0xffffffff |
| 833 | msg4.match = match |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 834 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 835 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 836 | msg4.priority = priority |
| 837 | rv = self.controller.message_send(msg4) |
| 838 | self.assertTrue(rv!= -1, "Error installing flow mod") |
| 839 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 840 | |
| 841 | |
| 842 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 843 | def nonstrict_delete(self,match,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 844 | # Issue Non_Strict Delete |
| 845 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 846 | #Create flow_mod message, command DELETE |
| 847 | msg6 = message.flow_mod() |
| 848 | msg6.out_port = ofp.OFPP_NONE |
| 849 | msg6.command = ofp.OFPFC_DELETE |
| 850 | msg6.buffer_id = 0xffffffff |
| 851 | msg6.match = match |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 852 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 853 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 854 | msg6.priority = priority |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 855 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 856 | rv = self.controller.message_send(msg6) |
| 857 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 858 | self.assertEqual(do_barrier(self.controller),0, "Barrier failed") |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 859 | |
| 860 | |
| 861 | ########################################################################################################################################################### |
| 862 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 863 | def send_packet(obj, pkt, ingress_port, egress_port): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 864 | #Send Packets on a specified ingress_port and verify if its recieved on correct egress_port. |
| 865 | |
| 866 | obj.dataplane.send(ingress_port, str(pkt)) |
| 867 | exp_pkt_arg = pkt |
| 868 | exp_port = egress_port |
| 869 | |
| 870 | (rcv_port, rcv_pkt, pkt_time) = obj.dataplane.poll(timeout=2, |
| 871 | port_number=exp_port, |
| 872 | exp_pkt=exp_pkt_arg) |
| 873 | obj.assertTrue(rcv_pkt is not None, |
| 874 | "Packet not received on port " + str(egress_port)) |
| 875 | obj.assertEqual(rcv_port, egress_port, |
| 876 | "Packet received on port " + str(rcv_port) + |
| 877 | ", expected port " + str(egress_port)) |
| 878 | obj.assertEqual(str(pkt), str(rcv_pkt), |
| 879 | 'Response packet does not match send packet') |
| 880 | |
| 881 | |
ShreyaPandita | 572e64b | 2012-09-28 14:41:06 -0400 | [diff] [blame] | 882 | def sw_supported_actions(parent,use_cache=False): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 883 | #Returns the switch's supported actions |
| 884 | |
| 885 | cache_supported_actions = None |
| 886 | if cache_supported_actions is None or not use_cache: |
| 887 | request = message.features_request() |
| 888 | (reply, pkt) = parent.controller.transact(request) |
| 889 | parent.assertTrue(reply is not None, "Did not get response to ftr req") |
| 890 | cache_supported_actions = reply.actions |
| 891 | return cache_supported_actions |
| 892 | |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 893 | ############################################################################################################################################################## |
| 894 | |