blob: 8b1a508ff17ab259071adfb8bbc09c2966896320 [file] [log] [blame]
sdn87018982018-05-08 11:46:27 +09001/*
2 * Copyright 2018-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 */
16package org.onosproject.driver.pipeline;
17
18import org.onlab.osgi.ServiceDirectory;
19import org.onosproject.net.DeviceId;
20import org.onosproject.net.Device;
21import org.onosproject.net.behaviour.PipelinerContext;
22import org.onosproject.net.device.DeviceService;
23import org.onosproject.net.flow.DefaultTrafficTreatment;
24import org.onosproject.net.flow.TrafficTreatment;
25import org.onosproject.net.flowobjective.DefaultForwardingObjective;
26import org.onosproject.net.flowobjective.ForwardingObjective;
27import org.slf4j.Logger;
28
29import java.util.Optional;
30
31import static org.slf4j.LoggerFactory.getLogger;
32
33/**
34 * Simple single table pipeline abstraction.
35 */
36public class AristaPipeliner extends DefaultSingleTablePipeline {
37
38 private final Logger log = getLogger(getClass());
39 private ServiceDirectory serviceDirectory;
40 private DeviceId deviceId;
41
42 protected DeviceService deviceSetvice;
43 @Override
44 public void init(DeviceId deviceId, PipelinerContext context) {
45 this.deviceId = deviceId;
46 this.serviceDirectory = context.directory();
47 this.deviceSetvice = serviceDirectory.get(DeviceService.class);
48 }
49
50
51 @Override
52 public void forward(ForwardingObjective forwardObjective) {
53 ForwardingObjective newFwd = forwardObjective;
54
55 Device device = deviceSetvice.getDevice(deviceId);
56 if (forwardObjective.treatment() != null && forwardObjective.treatment().clearedDeferred()) {
57 log.warn("Using 'clear actions' instruction which is not supported by {} {} {} Switch"
58 + " removing the clear deferred from the forwarding objective",
59 device.id(), device.manufacturer(), device.hwVersion());
60 newFwd = forwardingObjectiveWithoutCleardDef(forwardObjective).orElse(forwardObjective);
61 }
62
63 super.forward(newFwd);
64 }
65
66
67 private Optional<ForwardingObjective> forwardingObjectiveWithoutCleardDef(ForwardingObjective forwardingObjective) {
68 TrafficTreatment treatment = trafficTreatmentWithoutClearedDeffered(forwardingObjective.treatment());
69
70 DefaultForwardingObjective.Builder foBuilder = (DefaultForwardingObjective.Builder) forwardingObjective.copy();
71 foBuilder.withTreatment(treatment);
72
73 switch (forwardingObjective.op()) {
74 case ADD:
75 return Optional.of(foBuilder.add(forwardingObjective.context().orElse(null)));
76 case REMOVE:
77 return Optional.of(foBuilder.remove(forwardingObjective.context().orElse(null)));
78 default:
79 log.warn("Driver Not support other operations for forwarding objective");
80 return Optional.empty();
81 }
82
83 }
84
85
86 private TrafficTreatment trafficTreatmentWithoutClearedDeffered(TrafficTreatment treatment) {
87 return DefaultTrafficTreatment.builder(treatment)
88 .notWipeDeferred()
89 .build();
90 }
91
92}