sdn | a6a1a53 | 2018-05-23 20:13:16 +0900 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.driver.pipeline; |
| 17 | |
| 18 | import org.onlab.osgi.ServiceDirectory; |
sdn | ca3e4f3 | 2018-08-08 13:54:08 +0900 | [diff] [blame] | 19 | import org.onlab.packet.EthType; |
sdn | a6a1a53 | 2018-05-23 20:13:16 +0900 | [diff] [blame] | 20 | import org.onosproject.net.Device; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | import org.onosproject.net.behaviour.PipelinerContext; |
| 23 | import org.onosproject.net.device.DeviceService; |
| 24 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 25 | import org.onosproject.net.flow.TrafficTreatment; |
sdn | ca3e4f3 | 2018-08-08 13:54:08 +0900 | [diff] [blame] | 26 | import org.onosproject.net.flow.criteria.Criterion; |
| 27 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
sdn | a6a1a53 | 2018-05-23 20:13:16 +0900 | [diff] [blame] | 28 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 29 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 30 | import org.slf4j.Logger; |
| 31 | |
| 32 | import java.util.Optional; |
| 33 | |
| 34 | import static org.slf4j.LoggerFactory.getLogger; |
| 35 | |
| 36 | /** |
| 37 | * Cisco N9K Switch single table pipeline abstraction. |
| 38 | */ |
| 39 | public class CiscoN9kPipeliner extends DefaultSingleTablePipeline { |
| 40 | |
| 41 | private final Logger log = getLogger(getClass()); |
| 42 | private ServiceDirectory serviceDirectory; |
| 43 | private DeviceId deviceId; |
sdn | a6a1a53 | 2018-05-23 20:13:16 +0900 | [diff] [blame] | 44 | protected DeviceService deviceService; |
sdn | 35cc3e6 | 2018-06-01 18:08:41 +0900 | [diff] [blame] | 45 | |
sdn | a6a1a53 | 2018-05-23 20:13:16 +0900 | [diff] [blame] | 46 | @Override |
| 47 | public void init(DeviceId deviceId, PipelinerContext context) { |
sdn | 35cc3e6 | 2018-06-01 18:08:41 +0900 | [diff] [blame] | 48 | super.init(deviceId, context); |
sdn | a6a1a53 | 2018-05-23 20:13:16 +0900 | [diff] [blame] | 49 | this.deviceId = deviceId; |
| 50 | this.serviceDirectory = context.directory(); |
sdn | 35cc3e6 | 2018-06-01 18:08:41 +0900 | [diff] [blame] | 51 | deviceService = serviceDirectory.get(DeviceService.class); |
sdn | a6a1a53 | 2018-05-23 20:13:16 +0900 | [diff] [blame] | 52 | } |
| 53 | |
sdn | a6a1a53 | 2018-05-23 20:13:16 +0900 | [diff] [blame] | 54 | @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 | |
sdn | ca3e4f3 | 2018-08-08 13:54:08 +0900 | [diff] [blame] | 66 | 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 | |
sdn | a6a1a53 | 2018-05-23 20:13:16 +0900 | [diff] [blame] | 75 | 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 | } |