blob: 0cb30d28cad40bd5de7f21ba9f49ecaac44adad9 [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
Saurav Das558afec2015-05-31 17:12:48 -070016package org.onosproject.driver.pipeline;
17
18import static org.slf4j.LoggerFactory.getLogger;
19
Saurav Das2857f382015-11-03 14:39:27 -080020import java.util.ArrayList;
Saurav Das4f980082015-11-05 13:39:15 -080021import java.util.Collections;
Saurav Das2857f382015-11-03 14:39:27 -080022import java.util.List;
Saurav Das4f980082015-11-05 13:39:15 -080023import java.util.Set;
24import java.util.concurrent.ConcurrentHashMap;
Saurav Das2857f382015-11-03 14:39:27 -080025
26import org.onlab.packet.VlanId;
27import org.onosproject.core.ApplicationId;
28import org.onosproject.net.Port;
29import org.onosproject.net.PortNumber;
Saurav Das558afec2015-05-31 17:12:48 -070030import org.onosproject.net.flow.DefaultFlowRule;
31import org.onosproject.net.flow.DefaultTrafficSelector;
32import org.onosproject.net.flow.DefaultTrafficTreatment;
33import org.onosproject.net.flow.FlowRule;
34import org.onosproject.net.flow.FlowRuleOperations;
35import org.onosproject.net.flow.FlowRuleOperationsContext;
36import org.onosproject.net.flow.TrafficSelector;
37import org.onosproject.net.flow.TrafficTreatment;
Saurav Das2857f382015-11-03 14:39:27 -080038import org.onosproject.net.flow.criteria.PortCriterion;
39import org.onosproject.net.flow.criteria.VlanIdCriterion;
Saurav Das558afec2015-05-31 17:12:48 -070040import org.slf4j.Logger;
41
42
43/**
Saurav Das822c4e22015-10-23 10:51:11 -070044 * Driver for software switch emulation of the OFDPA 2.0 pipeline.
Saurav Das558afec2015-05-31 17:12:48 -070045 * The software switch is the CPqD OF 1.3 switch.
46 */
Saurav Das822c4e22015-10-23 10:51:11 -070047public class CpqdOFDPA2Pipeline extends OFDPA2Pipeline {
Saurav Das558afec2015-05-31 17:12:48 -070048
49 private final Logger log = getLogger(getClass());
50
51 @Override
Saurav Das2857f382015-11-03 14:39:27 -080052 protected List<FlowRule> processVlanIdFilter(PortCriterion portCriterion,
53 VlanIdCriterion vidCriterion,
54 VlanId assignedVlan,
55 ApplicationId applicationId) {
56 List<FlowRule> rules = new ArrayList<FlowRule>();
57 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
58 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
59 selector.matchVlanId(vidCriterion.vlanId());
Saurav Das4f980082015-11-05 13:39:15 -080060 treatment.transition(TMAC_TABLE);
61
62 VlanId storeVlan = null;
Saurav Das2857f382015-11-03 14:39:27 -080063 if (vidCriterion.vlanId() == VlanId.NONE) {
64 // untagged packets are assigned vlans
65 treatment.pushVlan().setVlanId(assignedVlan);
Saurav Das4f980082015-11-05 13:39:15 -080066 storeVlan = assignedVlan;
67 } else {
68 storeVlan = vidCriterion.vlanId();
Saurav Das2857f382015-11-03 14:39:27 -080069 }
Saurav Das2857f382015-11-03 14:39:27 -080070
71 // ofdpa cannot match on ALL portnumber, so we need to use separate
72 // rules for each port.
73 List<PortNumber> portnums = new ArrayList<PortNumber>();
74 if (portCriterion.port() == PortNumber.ALL) {
75 for (Port port : deviceService.getPorts(deviceId)) {
76 if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) {
77 portnums.add(port.number());
78 }
79 }
80 } else {
81 portnums.add(portCriterion.port());
82 }
Saurav Das4f980082015-11-05 13:39:15 -080083
Saurav Das2857f382015-11-03 14:39:27 -080084 for (PortNumber pnum : portnums) {
Saurav Das4f980082015-11-05 13:39:15 -080085 // update storage
86 port2Vlan.put(pnum, storeVlan);
87 Set<PortNumber> vlanPorts = vlan2Port.get(storeVlan);
88 if (vlanPorts == null) {
89 vlanPorts = Collections.newSetFromMap(
90 new ConcurrentHashMap<PortNumber, Boolean>());
91 vlanPorts.add(pnum);
92 vlan2Port.put(storeVlan, vlanPorts);
93 } else {
94 vlanPorts.add(pnum);
95 }
96 // create rest of flowrule
Saurav Das2857f382015-11-03 14:39:27 -080097 selector.matchInPort(pnum);
98 FlowRule rule = DefaultFlowRule.builder()
99 .forDevice(deviceId)
100 .withSelector(selector.build())
101 .withTreatment(treatment.build())
102 .withPriority(DEFAULT_PRIORITY)
103 .fromApp(applicationId)
104 .makePermanent()
105 .forTable(VLAN_TABLE).build();
106 rules.add(rule);
107 }
108 return rules;
109 }
110
111
112 @Override
Saurav Das558afec2015-05-31 17:12:48 -0700113 protected void initializePipeline() {
114 processPortTable();
Saurav Das2857f382015-11-03 14:39:27 -0800115 // vlan table processing not required, as default is to drop packets
116 // which can be accomplished without a table-miss-entry.
Saurav Das558afec2015-05-31 17:12:48 -0700117 processTmacTable();
118 processIpTable();
Saurav Das2857f382015-11-03 14:39:27 -0800119 processMplsTable();
Saurav Das558afec2015-05-31 17:12:48 -0700120 processBridgingTable();
Saurav Das337c7a42015-06-02 15:12:06 -0700121 processAclTable();
Saurav Das558afec2015-05-31 17:12:48 -0700122 }
123
124 @Override
125 protected void processPortTable() {
126 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
127 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
128 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
129 treatment.transition(VLAN_TABLE);
130 FlowRule tmisse = DefaultFlowRule.builder()
131 .forDevice(deviceId)
132 .withSelector(selector.build())
133 .withTreatment(treatment.build())
134 .withPriority(LOWEST_PRIORITY)
135 .fromApp(driverId)
136 .makePermanent()
137 .forTable(PORT_TABLE).build();
138 ops = ops.add(tmisse);
139
140 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
141 @Override
142 public void onSuccess(FlowRuleOperations ops) {
143 log.info("Initialized port table");
144 }
145
146 @Override
147 public void onError(FlowRuleOperations ops) {
148 log.info("Failed to initialize port table");
149 }
150 }));
151 }
152
153 @Override
154 protected void processTmacTable() {
155 //table miss entry
156 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
157 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
158 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
159 selector = DefaultTrafficSelector.builder();
160 treatment = DefaultTrafficTreatment.builder();
161 treatment.transition(BRIDGING_TABLE);
162 FlowRule rule = DefaultFlowRule.builder()
163 .forDevice(deviceId)
164 .withSelector(selector.build())
165 .withTreatment(treatment.build())
166 .withPriority(LOWEST_PRIORITY)
167 .fromApp(driverId)
168 .makePermanent()
169 .forTable(TMAC_TABLE).build();
170 ops = ops.add(rule);
171 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
172 @Override
173 public void onSuccess(FlowRuleOperations ops) {
174 log.info("Initialized tmac table");
175 }
176
177 @Override
178 public void onError(FlowRuleOperations ops) {
179 log.info("Failed to initialize tmac table");
180 }
181 }));
182 }
183
184 @Override
185 protected void processIpTable() {
186 //table miss entry
187 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
188 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
189 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
190 selector = DefaultTrafficSelector.builder();
191 treatment = DefaultTrafficTreatment.builder();
192 treatment.transition(ACL_TABLE);
193 FlowRule rule = DefaultFlowRule.builder()
194 .forDevice(deviceId)
195 .withSelector(selector.build())
196 .withTreatment(treatment.build())
197 .withPriority(LOWEST_PRIORITY)
198 .fromApp(driverId)
199 .makePermanent()
200 .forTable(UNICAST_ROUTING_TABLE).build();
201 ops = ops.add(rule);
202 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
203 @Override
204 public void onSuccess(FlowRuleOperations ops) {
205 log.info("Initialized IP table");
206 }
207
208 @Override
209 public void onError(FlowRuleOperations ops) {
210 log.info("Failed to initialize unicast IP table");
211 }
212 }));
213 }
214
Saurav Das2857f382015-11-03 14:39:27 -0800215 @Override
216 protected void processMplsTable() {
217 //table miss entry
218 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
219 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
220 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
221 selector = DefaultTrafficSelector.builder();
222 treatment = DefaultTrafficTreatment.builder();
223 treatment.transition(MPLS_TABLE_1);
224 FlowRule rule = DefaultFlowRule.builder()
225 .forDevice(deviceId)
226 .withSelector(selector.build())
227 .withTreatment(treatment.build())
228 .withPriority(LOWEST_PRIORITY)
229 .fromApp(driverId)
230 .makePermanent()
231 .forTable(MPLS_TABLE_0).build();
232 ops = ops.add(rule);
233
234 treatment.transition(ACL_TABLE);
235 rule = DefaultFlowRule.builder()
236 .forDevice(deviceId)
237 .withSelector(selector.build())
238 .withTreatment(treatment.build())
239 .withPriority(LOWEST_PRIORITY)
240 .fromApp(driverId)
241 .makePermanent()
242 .forTable(MPLS_TABLE_1).build();
243 ops = ops.add(rule);
244
245 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
246 @Override
247 public void onSuccess(FlowRuleOperations ops) {
248 log.info("Initialized MPLS tables");
249 }
250
251 @Override
252 public void onError(FlowRuleOperations ops) {
253 log.info("Failed to initialize MPLS tables");
254 }
255 }));
256 }
257
Saurav Das558afec2015-05-31 17:12:48 -0700258 private void processBridgingTable() {
259 //table miss entry
260 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
261 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
262 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
263 selector = DefaultTrafficSelector.builder();
264 treatment = DefaultTrafficTreatment.builder();
265 treatment.transition(ACL_TABLE);
266 FlowRule rule = DefaultFlowRule.builder()
267 .forDevice(deviceId)
268 .withSelector(selector.build())
269 .withTreatment(treatment.build())
270 .withPriority(LOWEST_PRIORITY)
271 .fromApp(driverId)
272 .makePermanent()
273 .forTable(BRIDGING_TABLE).build();
274 ops = ops.add(rule);
275 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
276 @Override
277 public void onSuccess(FlowRuleOperations ops) {
278 log.info("Initialized Bridging table");
279 }
280
281 @Override
282 public void onError(FlowRuleOperations ops) {
283 log.info("Failed to initialize Bridging table");
284 }
285 }));
Saurav Das337c7a42015-06-02 15:12:06 -0700286 }
Saurav Das558afec2015-05-31 17:12:48 -0700287
Saurav Das822c4e22015-10-23 10:51:11 -0700288 @Override
Saurav Dasa07f2032015-10-19 14:37:36 -0700289 protected void processAclTable() {
Saurav Das337c7a42015-06-02 15:12:06 -0700290 //table miss entry - catch all to executed action-set
291 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
292 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
293 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
294 selector = DefaultTrafficSelector.builder();
295 treatment = DefaultTrafficTreatment.builder();
296 FlowRule rule = DefaultFlowRule.builder()
297 .forDevice(deviceId)
298 .withSelector(selector.build())
299 .withTreatment(treatment.build())
300 .withPriority(LOWEST_PRIORITY)
301 .fromApp(driverId)
302 .makePermanent()
303 .forTable(ACL_TABLE).build();
304 ops = ops.add(rule);
305 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
306 @Override
307 public void onSuccess(FlowRuleOperations ops) {
308 log.info("Initialized Acl table");
309 }
310
311 @Override
312 public void onError(FlowRuleOperations ops) {
313 log.info("Failed to initialize Acl table");
314 }
315 }));
Saurav Das558afec2015-05-31 17:12:48 -0700316 }
317
318}