Matteo Scandolo | a229eca | 2017-08-08 13:05:28 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
ShreyaPandita | 055102a | 2012-11-28 11:43:45 -0500 | [diff] [blame] | 17 | """ 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] | 18 | |
| 19 | import sys |
| 20 | import copy |
| 21 | import random |
| 22 | |
| 23 | import oftest.controller as controller |
Rich Lane | d7b0ffa | 2013-03-08 15:53:42 -0800 | [diff] [blame] | 24 | import ofp |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 25 | import oftest.dataplane as dataplane |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 26 | import oftest.parse as parse |
| 27 | import logging |
| 28 | import types |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 29 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 30 | import oftest.base_tests as base_tests |
Rich Lane | da3b5ad | 2012-10-03 09:05:32 -0700 | [diff] [blame] | 31 | from oftest.testutils import * |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 32 | from time import sleep |
| 33 | |
| 34 | #################### Functions for various types of flow_mod ########################################################################################## |
| 35 | |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 36 | def match_send_flowadd(self, match, priority, port): |
Rich Lane | ba3f0e2 | 2013-03-11 16:43:57 -0700 | [diff] [blame] | 37 | msg = ofp.message.flow_add() |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 38 | msg.out_port = ofp.OFPP_NONE |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 39 | # msg.cookie = random.randint(0,9007199254740992) |
| 40 | msg.buffer_id = 0xffffffff |
| 41 | msg.match = match |
| 42 | if priority != None : |
| 43 | msg.priority = priority |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 44 | act = ofp.action.output() |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 45 | act.port = port |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame] | 46 | msg.actions.append(act) |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 47 | self.controller.message_send(msg) |
| 48 | do_barrier(self.controller) |
| 49 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 50 | def exact_match(self,of_ports,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 51 | # Generate ExactMatch flow . |
| 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] |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 58 | #match.ipv4_src = 1 |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 59 | match.wildcards=0 |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 60 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 61 | return (pkt_exactflow,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 62 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 63 | def exact_match_with_prio(self,of_ports,priority=None): |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 64 | # Generate ExactMatch with action output to port 2 |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 65 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 66 | #Create a simple tcp packet and generate exact flow match from it. |
| 67 | pkt_exactflow = simple_tcp_packet() |
| 68 | match = parse.packet_to_flow_match(pkt_exactflow) |
| 69 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 70 | match.in_port = of_ports[0] |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 71 | #match.ipv4_src = 1 |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 72 | match.wildcards=0 |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 73 | match_send_flowadd(self, match, priority, of_ports[2]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 74 | return (pkt_exactflow,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 75 | |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 76 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 77 | def match_all_except_source_address(self,of_ports,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 78 | # Generate Match_All_Except_Source_Address flow |
| 79 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 80 | #Create a simple tcp packet and generate match all except src address flow. |
| 81 | pkt_wildcardsrc= simple_tcp_packet() |
| 82 | match1 = parse.packet_to_flow_match(pkt_wildcardsrc) |
| 83 | self.assertTrue(match1 is not None, "Could not generate flow match from pkt") |
| 84 | match1.in_port = of_ports[0] |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 85 | #match1.ipv4_src = 1 |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 86 | match1.wildcards = ofp.OFPFW_DL_SRC |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 87 | match_send_flowadd(self, match1, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 88 | return (pkt_wildcardsrc,match1) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 89 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 90 | def match_ethernet_src_address(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 91 | #Generate Match_Ethernet_SrC_Address flow |
| 92 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 93 | #Create a simple tcp packet and generate match on ethernet src address flow |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 94 | pkt_MatchSrc = simple_eth_packet(eth_src='00:01:01:01:01:01') |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 95 | match = parse.packet_to_flow_match(pkt_MatchSrc) |
| 96 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 97 | match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_SRC |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 98 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 99 | return (pkt_MatchSrc,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 100 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 101 | def match_ethernet_dst_address(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 102 | #Generate Match_Ethernet_Dst_Address flow |
| 103 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 104 | #Create a simple tcp packet and generate match on ethernet dst address flow |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 105 | pkt_matchdst = simple_eth_packet(eth_dst='00:01:01:01:01:01') |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 106 | match = parse.packet_to_flow_match(pkt_matchdst) |
| 107 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 108 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 109 | match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_DST |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 110 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 111 | return (pkt_matchdst,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 112 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 113 | def wildcard_all(self,of_ports,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 114 | # Generate a Wildcard_All Flow |
| 115 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 116 | #Create a simple tcp packet and generate wildcard all flow match from it. |
| 117 | pkt_wildcard = simple_tcp_packet() |
| 118 | match2 = parse.packet_to_flow_match(pkt_wildcard) |
| 119 | self.assertTrue(match2 is not None, "Could not generate flow match from pkt") |
| 120 | match2.wildcards=ofp.OFPFW_ALL |
| 121 | match2.in_port = of_ports[0] |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 122 | match_send_flowadd(self, match2, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 123 | return (pkt_wildcard,match2) |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 124 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 125 | def wildcard_all_except_ingress(self,of_ports,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 126 | # Generate Wildcard_All_Except_Ingress_port flow |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 127 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 128 | #Create a simple tcp packet and generate wildcard all except ingress_port flow. |
| 129 | pkt_matchingress = simple_tcp_packet() |
| 130 | match3 = parse.packet_to_flow_match(pkt_matchingress) |
| 131 | self.assertTrue(match3 is not None, "Could not generate flow match from pkt") |
| 132 | match3.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT |
| 133 | match3.in_port = of_ports[0] |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 134 | match_send_flowadd(self, match3, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 135 | return (pkt_matchingress,match3) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 136 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 137 | def wildcard_all_except_ingress1(self,of_ports,priority=None): |
ShreyaPandita | da75f75 | 2012-10-26 16:26:35 -0400 | [diff] [blame] | 138 | # Generate Wildcard_All_Except_Ingress_port flow with action output to port egress_port 2 |
ShreyaPandita | da75f75 | 2012-10-26 16:26:35 -0400 | [diff] [blame] | 139 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 140 | #Create a simple tcp packet and generate wildcard all except ingress_port flow. |
| 141 | pkt_matchingress = simple_tcp_packet() |
| 142 | match3 = parse.packet_to_flow_match(pkt_matchingress) |
| 143 | self.assertTrue(match3 is not None, "Could not generate flow match from pkt") |
| 144 | match3.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT |
| 145 | match3.in_port = of_ports[0] |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 146 | match_send_flowadd(self, match3, priority, of_ports[2]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 147 | return (pkt_matchingress,match3) |
ShreyaPandita | da75f75 | 2012-10-26 16:26:35 -0400 | [diff] [blame] | 148 | |
| 149 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 150 | def match_vlan_id(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 151 | #Generate Match_Vlan_Id |
| 152 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 153 | #Create a simple tcp packet and generate match on ethernet dst address flow |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 154 | pkt_matchvlanid = simple_tcp_packet(dl_vlan_enable=True,vlan_vid=1) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 155 | match = parse.packet_to_flow_match(pkt_matchvlanid) |
| 156 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 157 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 158 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_DL_VLAN |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 159 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 160 | return (pkt_matchvlanid,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 match_vlan_pcp(self,of_ports,priority=None): |
ShreyaPandita | 055102a | 2012-11-28 11:43:45 -0500 | [diff] [blame] | 163 | #Generate Match_Vlan_Priority |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 164 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 165 | #Create a simple tcp packet and generate match on ethernet dst address flow |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 166 | pkt_matchvlanpcp = simple_tcp_packet(dl_vlan_enable=True,vlan_vid=1,vlan_pcp=5) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 167 | match = parse.packet_to_flow_match(pkt_matchvlanpcp) |
| 168 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 169 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 170 | match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE^ofp.OFPFW_DL_VLAN^ofp.OFPFW_DL_VLAN_PCP |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 171 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 172 | return (pkt_matchvlanpcp,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 173 | |
| 174 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 175 | def match_mul_l2(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 176 | #Generate Match_Mul_L2 flow |
| 177 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 178 | #Create a simple eth packet and generate match on ethernet protocol flow |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 179 | pkt_mulL2 = simple_eth_packet(eth_type=0x88cc,eth_src='00:01:01:01:01:01',eth_dst='00:01:01:01:01:02') |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 180 | match = parse.packet_to_flow_match(pkt_mulL2) |
| 181 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 182 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 183 | match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_DL_DST ^ofp.OFPFW_DL_SRC |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 184 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 185 | return (pkt_mulL2,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 186 | |
| 187 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 188 | def match_mul_l4(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 189 | #Generate Match_Mul_L4 flow |
| 190 | |
| 191 | #Create a simple tcp packet and generate match on tcp protocol flow |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 192 | pkt_mulL4 = simple_tcp_packet(tcp_sport=111,tcp_dport=112) |
| 193 | match = parse.packet_to_flow_match(pkt_mulL4) |
| 194 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 195 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_NW_PROTO^ofp.OFPFW_TP_SRC ^ofp.OFPFW_TP_DST |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 196 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 197 | return (pkt_mulL4,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 198 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 199 | def match_ip_tos(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 200 | #Generate a Match on IP Type of service flow |
| 201 | |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 202 | #Create a simple tcp packet and generate match on Type of service |
Rich Lane | b5c7379 | 2012-12-03 17:12:32 -0800 | [diff] [blame] | 203 | pkt_iptos = simple_tcp_packet(ip_tos=28) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 204 | match = parse.packet_to_flow_match(pkt_iptos) |
| 205 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 206 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 207 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE^ofp.OFPFW_NW_PROTO ^ofp.OFPFW_NW_TOS |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 208 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 209 | return (pkt_iptos,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 210 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 211 | def match_ip_protocol(self,of_ports,priority=None): |
| 212 | #Generate a Match on IP Protocol |
| 213 | |
| 214 | #Create a simple tcp packet and generate match on Type of service |
| 215 | pkt_iptos = simple_tcp_packet() |
| 216 | match = parse.packet_to_flow_match(pkt_iptos) |
| 217 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 218 | |
| 219 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE^ofp.OFPFW_NW_PROTO |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 220 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 221 | return (pkt_iptos,match) |
| 222 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 223 | def match_tcp_src(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 224 | #Generate Match_Tcp_Src |
| 225 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 226 | #Create a simple tcp packet and generate match on tcp source port flow |
| 227 | pkt_matchtSrc = simple_tcp_packet(tcp_sport=111) |
| 228 | match = parse.packet_to_flow_match(pkt_matchtSrc) |
| 229 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 230 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 231 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_NW_PROTO ^ofp.OFPFW_TP_SRC |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 232 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 233 | return (pkt_matchtSrc,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 234 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 235 | def match_tcp_dst(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 236 | #Generate Match_Tcp_Dst |
| 237 | |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 238 | #Create a simple tcp packet and generate match on tcp destination port flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 239 | pkt_matchdst = simple_tcp_packet(tcp_dport=112) |
| 240 | match = parse.packet_to_flow_match(pkt_matchdst) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 241 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 242 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 243 | match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE^ofp.OFPFW_NW_PROTO^ofp.OFPFW_TP_DST |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 244 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 245 | return (pkt_matchdst,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 246 | |
ShreyaPandita | 055102a | 2012-11-28 11:43:45 -0500 | [diff] [blame] | 247 | |
Shudong Zhou | c2f1876 | 2013-01-11 00:12:44 -0800 | [diff] [blame] | 248 | def match_udp_src(self,of_ports,priority=None): |
| 249 | #Generate Match_Udp_Src |
| 250 | |
| 251 | #Create a simple udp packet and generate match on udp source port flow |
| 252 | pkt_matchtSrc = simple_udp_packet(udp_sport=111) |
| 253 | match = parse.packet_to_flow_match(pkt_matchtSrc) |
| 254 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 255 | |
| 256 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_NW_PROTO ^ofp.OFPFW_TP_SRC |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 257 | match_send_flowadd(self, match, priority, of_ports[1]) |
Shudong Zhou | c2f1876 | 2013-01-11 00:12:44 -0800 | [diff] [blame] | 258 | return (pkt_matchtSrc,match) |
| 259 | |
| 260 | def match_udp_dst(self,of_ports,priority=None): |
| 261 | #Generate Match_Udp_Dst |
| 262 | |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 263 | #Create a simple udp packet and generate match on udp destination port flow |
Shudong Zhou | c2f1876 | 2013-01-11 00:12:44 -0800 | [diff] [blame] | 264 | pkt_matchdst = simple_udp_packet(udp_dport=112) |
| 265 | match = parse.packet_to_flow_match(pkt_matchdst) |
| 266 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 267 | |
| 268 | match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE^ofp.OFPFW_NW_PROTO^ofp.OFPFW_TP_DST |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 269 | match_send_flowadd(self, match, priority, of_ports[1]) |
Shudong Zhou | c2f1876 | 2013-01-11 00:12:44 -0800 | [diff] [blame] | 270 | return (pkt_matchdst,match) |
| 271 | |
| 272 | |
| 273 | def match_icmp_type(self,of_ports,priority=None): |
| 274 | #Generate Match_Icmp_Type |
| 275 | |
| 276 | #Create a simple icmp packet and generate match on icmp type flow |
| 277 | pkt_match = simple_icmp_packet(icmp_type=1) |
| 278 | match = parse.packet_to_flow_match(pkt_match) |
| 279 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 280 | |
| 281 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_NW_PROTO ^ofp.OFPFW_TP_SRC |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 282 | match_send_flowadd(self, match, priority, of_ports[1]) |
Shudong Zhou | c2f1876 | 2013-01-11 00:12:44 -0800 | [diff] [blame] | 283 | return (pkt_match, match) |
| 284 | |
| 285 | def match_icmp_code(self,of_ports,priority=None): |
| 286 | #Generate Match_Icmp_Code |
| 287 | |
| 288 | #Create a simple icmp packet and generate match on icmp code flow |
| 289 | pkt_match = simple_icmp_packet(icmp_code=3) |
| 290 | match = parse.packet_to_flow_match(pkt_match) |
| 291 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 292 | |
| 293 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_NW_PROTO ^ofp.OFPFW_TP_DST |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 294 | match_send_flowadd(self, match, priority, of_ports[1]) |
Shudong Zhou | c2f1876 | 2013-01-11 00:12:44 -0800 | [diff] [blame] | 295 | return (pkt_match, match) |
| 296 | |
Kiran Poola | ff12e48 | 2013-07-02 14:19:52 -0700 | [diff] [blame] | 297 | def match_arp_opcode(self,of_ports,priority=None): |
| 298 | #Generate Match_Arp_Opcode |
| 299 | |
| 300 | #Create a simple arp packet and generate match on arp opcode |
| 301 | pkt_match = simple_arp_packet(arp_op=1) |
| 302 | match = parse.packet_to_flow_match(pkt_match) |
| 303 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 304 | |
Kiran Poola | ceee1c6 | 2013-07-02 14:57:42 -0700 | [diff] [blame] | 305 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE^ofp.OFPFW_NW_PROTO |
Kiran Poola | ff12e48 | 2013-07-02 14:19:52 -0700 | [diff] [blame] | 306 | match_send_flowadd(self, match, priority, of_ports[1]) |
| 307 | return (pkt_match, match) |
| 308 | |
Shudong Zhou | dceec93 | 2013-02-06 01:12:54 -0800 | [diff] [blame] | 309 | def match_arp_sender(self,of_ports,priority=None): |
| 310 | #Generate Match_Arp_Sender |
| 311 | |
| 312 | #Create a simple icmp packet and generate match on arp sender flow |
| 313 | pkt_match = simple_arp_packet() |
| 314 | match = parse.packet_to_flow_match(pkt_match) |
| 315 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 316 | |
| 317 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_NW_PROTO ^ofp.OFPFW_NW_SRC_MASK |
| 318 | match_send_flowadd(self, match, priority, of_ports[1]) |
| 319 | return (pkt_match, match) |
| 320 | |
| 321 | def match_arp_target(self,of_ports,priority=None): |
| 322 | #Generate Match_Arp_Target |
| 323 | |
| 324 | #Create a simple icmp packet and generate match on arp target flow |
| 325 | pkt_match = simple_arp_packet() |
| 326 | match = parse.packet_to_flow_match(pkt_match) |
| 327 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 328 | |
| 329 | match.wildcards = ofp.OFPFW_ALL^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_NW_PROTO ^ofp.OFPFW_NW_DST_MASK |
| 330 | match_send_flowadd(self, match, priority, of_ports[1]) |
| 331 | return (pkt_match, match) |
| 332 | |
Shudong Zhou | c2f1876 | 2013-01-11 00:12:44 -0800 | [diff] [blame] | 333 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 334 | def match_ethernet_type(self,of_ports,priority=None): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 335 | #Generate a Match_Ethernet_Type flow |
| 336 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 337 | #Create a simple tcp packet and generate match on ethernet type flow |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 338 | pkt_matchtype = simple_eth_packet(eth_type=0x88cc) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 339 | match = parse.packet_to_flow_match(pkt_matchtype) |
| 340 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 341 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 342 | match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE |
Shudong Zhou | 857fb60 | 2013-02-06 00:11:38 -0800 | [diff] [blame] | 343 | match_send_flowadd(self, match, priority, of_ports[1]) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 344 | return (pkt_matchtype,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 345 | |
| 346 | |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 347 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 348 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 349 | def strict_modify_flow_action(self,egress_port,match,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 350 | # Strict Modify the flow Action |
| 351 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 352 | #Create a flow_mod message , command MODIFY_STRICT |
Rich Lane | ba3f0e2 | 2013-03-11 16:43:57 -0700 | [diff] [blame] | 353 | msg5 = ofp.message.flow_modify_strict() |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 354 | msg5.match = match |
| 355 | msg5.cookie = random.randint(0,9007199254740992) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 356 | msg5.buffer_id = 0xffffffff |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 357 | act5 = ofp.action.output() |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 358 | act5.port = egress_port |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame] | 359 | msg5.actions.append(act5) |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 360 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 361 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 362 | msg5.priority = priority |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 363 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 364 | # Send the flow with action A' |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 365 | self.controller.message_send (msg5) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 366 | do_barrier(self.controller) |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 367 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 368 | def modify_flow_action(self,of_ports,match,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 369 | # Modify the flow action |
| 370 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 371 | #Create a flow_mod message , command MODIFY |
Rich Lane | ba3f0e2 | 2013-03-11 16:43:57 -0700 | [diff] [blame] | 372 | msg8 = ofp.message.flow_modify() |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 373 | msg8.match = match |
| 374 | msg8.cookie = random.randint(0,9007199254740992) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 375 | #out_port will be ignored for flow adds and flow modify (here for test-case Add_Modify_With_Outport) |
| 376 | msg8.out_port = of_ports[3] |
| 377 | msg8.buffer_id = 0xffffffff |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 378 | act8 = ofp.action.output() |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 379 | act8.port = of_ports[2] |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame] | 380 | msg8.actions.append(act8) |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 381 | |
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 | msg8.priority = priority |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 384 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 385 | # Send the flow with action A' |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 386 | self.controller.message_send (msg8) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 387 | do_barrier(self.controller) |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 388 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 389 | def enqueue(self,ingress_port,egress_port,egress_queue_id): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 390 | #Generate a flow with enqueue action i.e output to a queue configured on a egress_port |
| 391 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 392 | pkt = simple_tcp_packet() |
| 393 | match = packet_to_flow_match(self, pkt) |
| 394 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 395 | self.assertTrue(match is not None, |
| 396 | "Could not generate flow match from pkt") |
| 397 | |
| 398 | match.in_port = ingress_port |
Rich Lane | ba3f0e2 | 2013-03-11 16:43:57 -0700 | [diff] [blame] | 399 | request = ofp.message.flow_add() |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 400 | request.match = match |
| 401 | request.buffer_id = 0xffffffff |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 402 | act = ofp.action.enqueue() |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 403 | act.port = egress_port |
| 404 | act.queue_id = egress_queue_id |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame] | 405 | request.actions.append(act) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 406 | |
| 407 | logging.info("Inserting flow") |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 408 | self.controller.message_send(request) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 409 | do_barrier(self.controller) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 410 | return (pkt,match) |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 411 | |
| 412 | |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 413 | ########################### Verify Stats Functions ########################################################################################### |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 414 | def get_flowstats(self,match): |
| 415 | # Generate flow_stats request |
| 416 | |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 417 | stat_req = ofp.message.flow_stats_request() |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 418 | stat_req.match = match |
| 419 | stat_req.table_id = 0xff |
| 420 | stat_req.out_port = ofp.OFPP_NONE |
| 421 | |
| 422 | logging.info("Sending stats request") |
| 423 | response, pkt = self.controller.transact(stat_req, |
| 424 | timeout=5) |
| 425 | self.assertTrue(response is not None,"No response to stats request") |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 426 | |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 427 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 428 | def get_portstats(self,port_num): |
| 429 | |
| 430 | # Return all the port counters in the form a tuple |
Rich Lane | 0d4a558 | 2015-04-10 12:25:39 -0700 | [diff] [blame] | 431 | entries = get_port_stats(self, port_num) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 432 | rx_pkts=0 |
| 433 | tx_pkts=0 |
| 434 | rx_byts=0 |
| 435 | tx_byts=0 |
| 436 | rx_drp =0 |
| 437 | tx_drp = 0 |
| 438 | rx_err=0 |
| 439 | tx_err =0 |
| 440 | rx_fr_err=0 |
| 441 | rx_ovr_err=0 |
| 442 | rx_crc_err=0 |
| 443 | collisions = 0 |
| 444 | tx_err=0 |
| 445 | |
| 446 | |
Rich Lane | 0d4a558 | 2015-04-10 12:25:39 -0700 | [diff] [blame] | 447 | for obj in entries: |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 448 | rx_pkts += obj.rx_packets |
| 449 | tx_pkts += obj.tx_packets |
| 450 | rx_byts += obj.rx_bytes |
| 451 | tx_byts += obj.tx_bytes |
| 452 | rx_drp += obj.rx_dropped |
| 453 | tx_drp += obj.tx_dropped |
| 454 | rx_err += obj.rx_errors |
| 455 | rx_fr_err += obj.rx_frame_err |
| 456 | rx_ovr_err += obj.rx_over_err |
| 457 | rx_crc_err += obj.rx_crc_err |
| 458 | collisions+= obj.collisions |
| 459 | tx_err += obj.tx_errors |
| 460 | |
| 461 | 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) |
| 462 | |
| 463 | def get_queuestats(self,port_num,queue_id): |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 464 | #Generate Queue Stats request |
| 465 | |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 466 | request = ofp.message.queue_stats_request() |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 467 | request.port_no = port_num |
| 468 | request.queue_id = queue_id |
| 469 | (queue_stats, p) = self.controller.transact(request) |
| 470 | self.assertNotEqual(queue_stats, None, "Queue stats request failed") |
| 471 | |
| 472 | return (queue_stats,p) |
| 473 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 474 | def get_tablestats(self): |
| 475 | # Send Table_Stats request (retrieve current table counters ) |
| 476 | |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 477 | stat_req = ofp.message.table_stats_request() |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 478 | response, pkt = self.controller.transact(stat_req, |
| 479 | timeout=5) |
| 480 | self.assertTrue(response is not None, |
| 481 | "No response to stats request") |
| 482 | current_lookedup = 0 |
| 483 | current_matched = 0 |
| 484 | current_active = 0 |
| 485 | |
Rich Lane | 5fd6faf | 2013-03-11 13:30:20 -0700 | [diff] [blame] | 486 | for obj in response.entries: |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 487 | current_lookedup += obj.lookup_count |
| 488 | current_matched += obj.matched_count |
| 489 | current_active += obj.active_count |
| 490 | |
| 491 | return (current_lookedup,current_matched,current_active) |
| 492 | |
| 493 | |
| 494 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 495 | def verify_tablestats(self,expect_lookup=None,expect_match=None,expect_active=None): |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 496 | |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 497 | stat_req = ofp.message.table_stats_request() |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 498 | |
Rich Lane | 90b3d73 | 2012-12-31 10:03:50 -0800 | [diff] [blame] | 499 | for i in range(0,100): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 500 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 501 | logging.info("Sending stats request") |
| 502 | # TODO: move REPLY_MORE handling to controller.transact? |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 503 | response, pkt = self.controller.transact(stat_req, |
| 504 | timeout=5) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 505 | self.assertTrue(response is not None,"No response to stats request") |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 506 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 507 | lookedup = 0 |
| 508 | matched = 0 |
| 509 | active = 0 |
| 510 | |
Rich Lane | 5fd6faf | 2013-03-11 13:30:20 -0700 | [diff] [blame] | 511 | for item in response.entries: |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 512 | lookedup += item.lookup_count |
| 513 | matched += item.matched_count |
| 514 | active += item.active_count |
| 515 | |
Rich Lane | afcd0dd | 2013-01-03 20:54:56 -0800 | [diff] [blame] | 516 | logging.info("Packets Looked up: %d", lookedup) |
| 517 | logging.info("Packets matched: %d", matched) |
| 518 | logging.info("Active flow entries: %d", active) |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 519 | |
Rich Lane | 175f956 | 2013-01-03 20:58:40 -0800 | [diff] [blame] | 520 | if (expect_lookup == None or lookedup >= expect_lookup) and \ |
| 521 | (expect_match == None or matched >= expect_match) and \ |
| 522 | (expect_active == None or active >= expect_active): |
Rich Lane | 90b3d73 | 2012-12-31 10:03:50 -0800 | [diff] [blame] | 523 | break |
| 524 | |
| 525 | sleep(0.1) |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 526 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 527 | if expect_lookup != None : |
Rich Lane | ecb5dfd | 2015-04-23 13:36:41 -0700 | [diff] [blame] | 528 | self.assertLessEqual(expect_lookup, lookedup, "lookup counter is not incremented properly") |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 529 | if expect_match != None : |
Rich Lane | ecb5dfd | 2015-04-23 13:36:41 -0700 | [diff] [blame] | 530 | self.assertLessEqual(expect_match, matched, "matched counter is not incremented properly") |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 531 | if expect_active != None : |
Rich Lane | ecb5dfd | 2015-04-23 13:36:41 -0700 | [diff] [blame] | 532 | self.assertLessEqual(expect_active, active ,"active counter is not incremented properly") |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 533 | |
| 534 | |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 535 | ############################## Various delete commands ############################################################################################# |
| 536 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 537 | def strict_delete(self,match,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 538 | # Issue Strict Delete |
| 539 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 540 | #Create flow_mod message, command DELETE_STRICT |
Rich Lane | ba3f0e2 | 2013-03-11 16:43:57 -0700 | [diff] [blame] | 541 | msg4 = ofp.message.flow_delete_strict() |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 542 | msg4.out_port = ofp.OFPP_NONE |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 543 | msg4.buffer_id = 0xffffffff |
| 544 | msg4.match = match |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 545 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 546 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 547 | msg4.priority = priority |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 548 | self.controller.message_send(msg4) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 549 | do_barrier(self.controller) |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 550 | |
| 551 | |
| 552 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 553 | def nonstrict_delete(self,match,priority=None): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 554 | # Issue Non_Strict Delete |
| 555 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 556 | #Create flow_mod message, command DELETE |
Rich Lane | ba3f0e2 | 2013-03-11 16:43:57 -0700 | [diff] [blame] | 557 | msg6 = ofp.message.flow_delete() |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 558 | msg6.out_port = ofp.OFPP_NONE |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 559 | msg6.buffer_id = 0xffffffff |
| 560 | msg6.match = match |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 561 | |
ShreyaPandita | ed20996 | 2012-11-04 02:16:48 -0500 | [diff] [blame] | 562 | if priority != None : |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 563 | msg6.priority = priority |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 564 | |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 565 | self.controller.message_send(msg6) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 566 | do_barrier(self.controller) |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 567 | |
| 568 | |
| 569 | ########################################################################################################################################################### |
| 570 | |
ShreyaPandita | 4ebbac3 | 2012-11-02 13:40:44 -0400 | [diff] [blame] | 571 | def send_packet(obj, pkt, ingress_port, egress_port): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 572 | #Send Packets on a specified ingress_port and verify if its recieved on correct egress_port. |
| 573 | |
| 574 | obj.dataplane.send(ingress_port, str(pkt)) |
| 575 | exp_pkt_arg = pkt |
| 576 | exp_port = egress_port |
| 577 | |
| 578 | (rcv_port, rcv_pkt, pkt_time) = obj.dataplane.poll(timeout=2, |
| 579 | port_number=exp_port, |
| 580 | exp_pkt=exp_pkt_arg) |
| 581 | obj.assertTrue(rcv_pkt is not None, |
| 582 | "Packet not received on port " + str(egress_port)) |
| 583 | obj.assertEqual(rcv_port, egress_port, |
| 584 | "Packet received on port " + str(rcv_port) + |
| 585 | ", expected port " + str(egress_port)) |
| 586 | obj.assertEqual(str(pkt), str(rcv_pkt), |
| 587 | 'Response packet does not match send packet') |
| 588 | |
| 589 | |
ShreyaPandita | 572e64b | 2012-09-28 14:41:06 -0400 | [diff] [blame] | 590 | def sw_supported_actions(parent,use_cache=False): |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 591 | #Returns the switch's supported actions |
| 592 | |
| 593 | cache_supported_actions = None |
| 594 | if cache_supported_actions is None or not use_cache: |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 595 | request = ofp.message.features_request() |
ShreyaPandita | 60e4554 | 2012-09-27 15:11:16 -0400 | [diff] [blame] | 596 | (reply, pkt) = parent.controller.transact(request) |
| 597 | parent.assertTrue(reply is not None, "Did not get response to ftr req") |
| 598 | cache_supported_actions = reply.actions |
| 599 | return cache_supported_actions |
| 600 | |
ShreyaPandita | 66de26f | 2012-10-26 14:44:24 -0400 | [diff] [blame] | 601 | ############################################################################################################################################################## |
| 602 | |