blob: 1768deaee1b999e4ae5bad0a753392bf708ae92d [file] [log] [blame]
sdna6a1a532018-05-23 20:13:16 +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;
sdnca3e4f32018-08-08 13:54:08 +090019import org.onlab.packet.EthType;
sdna6a1a532018-05-23 20:13:16 +090020import org.onosproject.net.Device;
21import org.onosproject.net.DeviceId;
22import org.onosproject.net.behaviour.PipelinerContext;
23import org.onosproject.net.device.DeviceService;
24import org.onosproject.net.flow.DefaultTrafficTreatment;
25import org.onosproject.net.flow.TrafficTreatment;
sdnca3e4f32018-08-08 13:54:08 +090026import org.onosproject.net.flow.criteria.Criterion;
27import org.onosproject.net.flow.criteria.EthTypeCriterion;
sdna6a1a532018-05-23 20:13:16 +090028import org.onosproject.net.flowobjective.DefaultForwardingObjective;
29import org.onosproject.net.flowobjective.ForwardingObjective;
30import org.slf4j.Logger;
31
32import java.util.Optional;
33
34import static org.slf4j.LoggerFactory.getLogger;
35
36/**
37 * Cisco N9K Switch single table pipeline abstraction.
38 */
39public class CiscoN9kPipeliner extends DefaultSingleTablePipeline {
40
41 private final Logger log = getLogger(getClass());
42 private ServiceDirectory serviceDirectory;
43 private DeviceId deviceId;
sdna6a1a532018-05-23 20:13:16 +090044 protected DeviceService deviceService;
sdn35cc3e62018-06-01 18:08:41 +090045
sdna6a1a532018-05-23 20:13:16 +090046 @Override
47 public void init(DeviceId deviceId, PipelinerContext context) {
sdn35cc3e62018-06-01 18:08:41 +090048 super.init(deviceId, context);
sdna6a1a532018-05-23 20:13:16 +090049 this.deviceId = deviceId;
50 this.serviceDirectory = context.directory();
sdn35cc3e62018-06-01 18:08:41 +090051 deviceService = serviceDirectory.get(DeviceService.class);
sdna6a1a532018-05-23 20:13:16 +090052 }
53
sdna6a1a532018-05-23 20:13:16 +090054 @Override
55 public void forward(ForwardingObjective forwardObjective) {
56 ForwardingObjective newFwd = forwardObjective;
57 Device device = deviceService.getDevice(deviceId);
58
59 if (forwardObjective.treatment() != null && forwardObjective.treatment().clearedDeferred()) {
60 log.warn("Using 'clear actions' instruction which is not supported by {} {} {} Switch"
61 + " removing the clear deferred from the forwarding objective",
62 device.id(), device.manufacturer(), device.hwVersion());
63 newFwd = forwardingObjectiveWithoutCleardDef(forwardObjective).orElse(forwardObjective);
64 }
65
sdnca3e4f32018-08-08 13:54:08 +090066 EthTypeCriterion ethType =
67 (EthTypeCriterion) newFwd.selector().getCriterion(Criterion.Type.ETH_TYPE);
68 if (ethType != null && ethType.ethType() == EthType.EtherType.IPV6.ethType()) {
69 log.error("IPv6 type not supported for {} {} {} Switch, " +
70 "The FlowRule associated with IPv6 is dropped.",
71 device.id(), device.manufacturer(), device.hwVersion());
72 return;
73 }
74
sdna6a1a532018-05-23 20:13:16 +090075 super.forward(newFwd);
76 }
77
78
79 private Optional<ForwardingObjective> forwardingObjectiveWithoutCleardDef(ForwardingObjective forwardingObjective) {
80 TrafficTreatment treatment = trafficTreatmentWithoutClearedDeffered(forwardingObjective.treatment());
81
82 DefaultForwardingObjective.Builder foBuilder = (DefaultForwardingObjective.Builder) forwardingObjective.copy();
83 foBuilder.withTreatment(treatment);
84
85 switch (forwardingObjective.op()) {
86 case ADD:
87 return Optional.of(foBuilder.add(forwardingObjective.context().orElse(null)));
88 case REMOVE:
89 return Optional.of(foBuilder.remove(forwardingObjective.context().orElse(null)));
90 default:
91 log.warn("Driver does not support other operations for forwarding objective");
92 return Optional.empty();
93 }
94
95 }
96
97
98 private TrafficTreatment trafficTreatmentWithoutClearedDeffered(TrafficTreatment treatment) {
99 return DefaultTrafficTreatment.builder(treatment)
100 .notWipeDeferred()
101 .build();
102 }
103
104}