blob: 8f976da3aba94861a043e5dd15feb81d07154edd [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;
21import java.util.List;
22
23import org.onlab.packet.VlanId;
24import org.onosproject.core.ApplicationId;
25import org.onosproject.net.Port;
26import org.onosproject.net.PortNumber;
Saurav Das558afec2015-05-31 17:12:48 -070027import org.onosproject.net.flow.DefaultFlowRule;
28import org.onosproject.net.flow.DefaultTrafficSelector;
29import org.onosproject.net.flow.DefaultTrafficTreatment;
30import org.onosproject.net.flow.FlowRule;
31import org.onosproject.net.flow.FlowRuleOperations;
32import org.onosproject.net.flow.FlowRuleOperationsContext;
33import org.onosproject.net.flow.TrafficSelector;
34import org.onosproject.net.flow.TrafficTreatment;
Saurav Das2857f382015-11-03 14:39:27 -080035import org.onosproject.net.flow.criteria.PortCriterion;
36import org.onosproject.net.flow.criteria.VlanIdCriterion;
Saurav Das558afec2015-05-31 17:12:48 -070037import org.slf4j.Logger;
38
39
40/**
Saurav Das822c4e22015-10-23 10:51:11 -070041 * Driver for software switch emulation of the OFDPA 2.0 pipeline.
Saurav Das558afec2015-05-31 17:12:48 -070042 * The software switch is the CPqD OF 1.3 switch.
43 */
Saurav Das822c4e22015-10-23 10:51:11 -070044public class CpqdOFDPA2Pipeline extends OFDPA2Pipeline {
Saurav Das558afec2015-05-31 17:12:48 -070045
46 private final Logger log = getLogger(getClass());
47
48 @Override
Saurav Das2857f382015-11-03 14:39:27 -080049 protected List<FlowRule> processVlanIdFilter(PortCriterion portCriterion,
50 VlanIdCriterion vidCriterion,
51 VlanId assignedVlan,
52 ApplicationId applicationId) {
53 List<FlowRule> rules = new ArrayList<FlowRule>();
54 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
55 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
56 selector.matchVlanId(vidCriterion.vlanId());
57 if (vidCriterion.vlanId() == VlanId.NONE) {
58 // untagged packets are assigned vlans
59 treatment.pushVlan().setVlanId(assignedVlan);
60 }
61 treatment.transition(TMAC_TABLE);
62
63 // ofdpa cannot match on ALL portnumber, so we need to use separate
64 // rules for each port.
65 List<PortNumber> portnums = new ArrayList<PortNumber>();
66 if (portCriterion.port() == PortNumber.ALL) {
67 for (Port port : deviceService.getPorts(deviceId)) {
68 if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) {
69 portnums.add(port.number());
70 }
71 }
72 } else {
73 portnums.add(portCriterion.port());
74 }
75 for (PortNumber pnum : portnums) {
76 selector.matchInPort(pnum);
77 FlowRule rule = DefaultFlowRule.builder()
78 .forDevice(deviceId)
79 .withSelector(selector.build())
80 .withTreatment(treatment.build())
81 .withPriority(DEFAULT_PRIORITY)
82 .fromApp(applicationId)
83 .makePermanent()
84 .forTable(VLAN_TABLE).build();
85 rules.add(rule);
86 }
87 return rules;
88 }
89
90
91 @Override
Saurav Das558afec2015-05-31 17:12:48 -070092 protected void initializePipeline() {
93 processPortTable();
Saurav Das2857f382015-11-03 14:39:27 -080094 // vlan table processing not required, as default is to drop packets
95 // which can be accomplished without a table-miss-entry.
Saurav Das558afec2015-05-31 17:12:48 -070096 processTmacTable();
97 processIpTable();
Saurav Das2857f382015-11-03 14:39:27 -080098 processMplsTable();
Saurav Das558afec2015-05-31 17:12:48 -070099 processBridgingTable();
Saurav Das337c7a42015-06-02 15:12:06 -0700100 processAclTable();
Saurav Das558afec2015-05-31 17:12:48 -0700101 }
102
103 @Override
104 protected void processPortTable() {
105 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
106 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
107 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
108 treatment.transition(VLAN_TABLE);
109 FlowRule tmisse = DefaultFlowRule.builder()
110 .forDevice(deviceId)
111 .withSelector(selector.build())
112 .withTreatment(treatment.build())
113 .withPriority(LOWEST_PRIORITY)
114 .fromApp(driverId)
115 .makePermanent()
116 .forTable(PORT_TABLE).build();
117 ops = ops.add(tmisse);
118
119 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
120 @Override
121 public void onSuccess(FlowRuleOperations ops) {
122 log.info("Initialized port table");
123 }
124
125 @Override
126 public void onError(FlowRuleOperations ops) {
127 log.info("Failed to initialize port table");
128 }
129 }));
130 }
131
132 @Override
133 protected void processTmacTable() {
134 //table miss entry
135 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
136 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
137 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
138 selector = DefaultTrafficSelector.builder();
139 treatment = DefaultTrafficTreatment.builder();
140 treatment.transition(BRIDGING_TABLE);
141 FlowRule rule = DefaultFlowRule.builder()
142 .forDevice(deviceId)
143 .withSelector(selector.build())
144 .withTreatment(treatment.build())
145 .withPriority(LOWEST_PRIORITY)
146 .fromApp(driverId)
147 .makePermanent()
148 .forTable(TMAC_TABLE).build();
149 ops = ops.add(rule);
150 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
151 @Override
152 public void onSuccess(FlowRuleOperations ops) {
153 log.info("Initialized tmac table");
154 }
155
156 @Override
157 public void onError(FlowRuleOperations ops) {
158 log.info("Failed to initialize tmac table");
159 }
160 }));
161 }
162
163 @Override
164 protected void processIpTable() {
165 //table miss entry
166 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
167 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
168 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
169 selector = DefaultTrafficSelector.builder();
170 treatment = DefaultTrafficTreatment.builder();
171 treatment.transition(ACL_TABLE);
172 FlowRule rule = DefaultFlowRule.builder()
173 .forDevice(deviceId)
174 .withSelector(selector.build())
175 .withTreatment(treatment.build())
176 .withPriority(LOWEST_PRIORITY)
177 .fromApp(driverId)
178 .makePermanent()
179 .forTable(UNICAST_ROUTING_TABLE).build();
180 ops = ops.add(rule);
181 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
182 @Override
183 public void onSuccess(FlowRuleOperations ops) {
184 log.info("Initialized IP table");
185 }
186
187 @Override
188 public void onError(FlowRuleOperations ops) {
189 log.info("Failed to initialize unicast IP table");
190 }
191 }));
192 }
193
Saurav Das2857f382015-11-03 14:39:27 -0800194 @Override
195 protected void processMplsTable() {
196 //table miss entry
197 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
198 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
199 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
200 selector = DefaultTrafficSelector.builder();
201 treatment = DefaultTrafficTreatment.builder();
202 treatment.transition(MPLS_TABLE_1);
203 FlowRule rule = DefaultFlowRule.builder()
204 .forDevice(deviceId)
205 .withSelector(selector.build())
206 .withTreatment(treatment.build())
207 .withPriority(LOWEST_PRIORITY)
208 .fromApp(driverId)
209 .makePermanent()
210 .forTable(MPLS_TABLE_0).build();
211 ops = ops.add(rule);
212
213 treatment.transition(ACL_TABLE);
214 rule = DefaultFlowRule.builder()
215 .forDevice(deviceId)
216 .withSelector(selector.build())
217 .withTreatment(treatment.build())
218 .withPriority(LOWEST_PRIORITY)
219 .fromApp(driverId)
220 .makePermanent()
221 .forTable(MPLS_TABLE_1).build();
222 ops = ops.add(rule);
223
224 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
225 @Override
226 public void onSuccess(FlowRuleOperations ops) {
227 log.info("Initialized MPLS tables");
228 }
229
230 @Override
231 public void onError(FlowRuleOperations ops) {
232 log.info("Failed to initialize MPLS tables");
233 }
234 }));
235 }
236
Saurav Das558afec2015-05-31 17:12:48 -0700237 private void processBridgingTable() {
238 //table miss entry
239 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
240 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
241 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
242 selector = DefaultTrafficSelector.builder();
243 treatment = DefaultTrafficTreatment.builder();
244 treatment.transition(ACL_TABLE);
245 FlowRule rule = DefaultFlowRule.builder()
246 .forDevice(deviceId)
247 .withSelector(selector.build())
248 .withTreatment(treatment.build())
249 .withPriority(LOWEST_PRIORITY)
250 .fromApp(driverId)
251 .makePermanent()
252 .forTable(BRIDGING_TABLE).build();
253 ops = ops.add(rule);
254 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
255 @Override
256 public void onSuccess(FlowRuleOperations ops) {
257 log.info("Initialized Bridging table");
258 }
259
260 @Override
261 public void onError(FlowRuleOperations ops) {
262 log.info("Failed to initialize Bridging table");
263 }
264 }));
Saurav Das337c7a42015-06-02 15:12:06 -0700265 }
Saurav Das558afec2015-05-31 17:12:48 -0700266
Saurav Das822c4e22015-10-23 10:51:11 -0700267 @Override
Saurav Dasa07f2032015-10-19 14:37:36 -0700268 protected void processAclTable() {
Saurav Das337c7a42015-06-02 15:12:06 -0700269 //table miss entry - catch all to executed action-set
270 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
271 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
272 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
273 selector = DefaultTrafficSelector.builder();
274 treatment = DefaultTrafficTreatment.builder();
275 FlowRule rule = DefaultFlowRule.builder()
276 .forDevice(deviceId)
277 .withSelector(selector.build())
278 .withTreatment(treatment.build())
279 .withPriority(LOWEST_PRIORITY)
280 .fromApp(driverId)
281 .makePermanent()
282 .forTable(ACL_TABLE).build();
283 ops = ops.add(rule);
284 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
285 @Override
286 public void onSuccess(FlowRuleOperations ops) {
287 log.info("Initialized Acl table");
288 }
289
290 @Override
291 public void onError(FlowRuleOperations ops) {
292 log.info("Failed to initialize Acl table");
293 }
294 }));
Saurav Das558afec2015-05-31 17:12:48 -0700295 }
296
297}