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