blob: 7f44b4802ee4030a0bf11235817152d2b0ab4f70 [file] [log] [blame]
macauley60952512015-07-16 17:40:59 +08001# Distributed under the OpenFlow Software License (see LICENSE)
2# Copyright (c) 2010 The Board of Trustees of The Leland Stanford Junior University
3# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
4# Copyright (c) 2012, 2013 CPqD
5# Copyright (c) 2012, 2013 Ericsson
6# Copyright (c) 2015 Research Education and Advanced Network New Zealand Ltd.
7"""
8Basic test cases
9
10Test cases in other modules depend on this functionality.
11"""
12
13import logging
14
15from oftest import config
16import oftest.base_tests as base_tests
17import ofp
18import time
19from oftest.testutils import *
20
21
22
23class case1(base_tests.SimpleDataPlane):
24
25 def runTest(self):
26 ports = sorted(config["port_map"].keys())
27
28 delete_all_flows(self.controller)
29 delete_all_groups(self.controller)
30
31 #l2-interface-grup_port1_vlann100_untag
32 grouptype = 0
33 vlanid = 100
34 of_port=1
35 group_id = of_port + (vlanid << 16) + (grouptype << 28)
36 actions = [
37 ofp.action.pop_vlan(),
38 ofp.action.output(of_port),
39 ]
40 buckets = [
41 ofp.bucket(actions=actions),
42 ]
43 request = ofp.message.group_add(
44 group_type=ofp.OFPGT_INDIRECT,
45 group_id=group_id,
46 buckets=buckets
47 )
48 self.controller.message_send(request)
49 #l2-interface-grup_port2_vlann100_untag
50 grouptype = 0
51 vlanid = 100
52 of_port=2
53 group_id = of_port + (vlanid << 16) + (grouptype << 28)
54 actions = [
55 ofp.action.pop_vlan(),
56 ofp.action.output(of_port),
57 ]
58 buckets = [
59 ofp.bucket(actions=actions),
60 ]
61 request = ofp.message.group_add(
62 group_type=ofp.OFPGT_INDIRECT,
63 group_id=group_id,
64 buckets=buckets
65 )
66 self.controller.message_send(request)
67
68 #10_add_port1_allow_rx_tag_vid_100
69 match = ofp.match()
70 of_port=1
71 vlanid=100
72 match.oxm_list.append(ofp.oxm.in_port(of_port))
73 match.oxm_list.append(ofp.oxm.vlan_vid(0x1000|vlanid))
74 request = ofp.message.flow_add(
75 table_id=10,
76 cookie=42,
77 match=match,
78 instructions=[
79 ofp.instruction.goto_table(20)
80 ],
81 priority=0)
82 logging.info("Set vlan-1 tagged on port %d, and goto table 20" % of_port)
83 self.controller.message_send(request)
84 """
85 #50_mac_0000000010_vlan_100
86 grouptype = 0
87 vlanid = 100
88 out_port=2
89 group_id = out_port + (vlanid << 16) + (grouptype << 28)
90 match = ofp.match()
91 match.oxm_list.append(ofp.oxm.eth_dst([0x00, 0x00, 0x00, 0x00, 0x00, 0x10]))
92 match.oxm_list.append(ofp.oxm.vlan_vid(vlanid))
93 request = ofp.message.flow_add(
94 table_id=50,
95 cookie=42,
96 match=match,
97 instructions=[
98 ofp.instruction.write_actions(
99 actions=[
100 ofp.action.group(group_id)]),
101 ofp.instruction.goto_table(60)
102 ],
103 buffer_id=ofp.OFP_NO_BUFFER,
104 priority=1000)
105
106 logging.info("Inserting Bridge flow sending matching packets to port %d", out_port)
107 self.controller.message_send(request)
108 do_barrier(self.controller)
109 """
110 #60_acl
111
112 grouptype = 0
113 vlanid = 100
114 out_port=2
115 group_id = out_port + (vlanid << 16) + (grouptype << 28)
116 match = ofp.match()
117 match.oxm_list.append(ofp.oxm.eth_dst([0x00, 0x00, 0x00, 0x00, 0x00, 0x10]))
118 match.oxm_list.append(ofp.oxm.vlan_vid(vlanid))
119 match.oxm_list.append(ofp.oxm.eth_type(0x0800))
120 match.oxm_list.append(ofp.oxm.ipv4_dst_masked(0xc0010164, 32))
121 request = ofp.message.flow_add(
122 table_id=60,
123 cookie=42,
124 match=match,
125 instructions=[
126 ofp.instruction.apply_actions(
127 actions=[
128 ofp.action.group(group_id)])
129 ],
130 buffer_id=ofp.OFP_NO_BUFFER,
131 priority=1000)
132
133 logging.info("Inserting ACL flow sending matching packets to port %d", out_port)
134 self.controller.message_send(request)
135 do_barrier(self.controller)
136
137 #send packet on port 1
138 in_port=1
139 out_port=2
140 parsed_pkt = simple_tcp_packet(pktlen=104,
141 eth_dst='00:00:00:00:00:10',
142 dl_vlan_enable=True,
143 vlan_vid=100,
144 ip_dst='192.168.1.100')
145 pkt = str(parsed_pkt)
146 logging.info("Send packet on port %d, out port %d", in_port, out_port)
147 self.dataplane.send(in_port, pkt)
148 #construct verify packet content
149 parsed_pkt = simple_tcp_packet(pktlen=100,
150 eth_dst='00:00:00:00:00:10',
151 ip_dst='192.168.1.100')
152 verify_packet(self, parsed_pkt, out_port)
153
154 verify_no_other_packets(self)
155
156 #send packet on port 1, again but diff DST IP
157 in_port=1
158 out_port=2
159 parsed_pkt = simple_tcp_packet(pktlen=104,
160 eth_dst='00:00:00:00:00:10',
161 dl_vlan_enable=True,
162 vlan_vid=100,
163 ip_dst='192.168.1.200')
164 pkt = str(parsed_pkt)
165 logging.info("Send packet on port %d, out port %d", in_port, out_port)
166 self.dataplane.send(in_port, pkt)
167 #construct verify packet content
168 parsed_pkt = simple_tcp_packet(pktlen=100,
169 eth_dst='00:00:00:00:00:10',
170 ip_dst='192.168.1.200')
171 verify_no_packet(self, parsed_pkt, out_port)
172
173 verify_no_other_packets(self)
174