Jovana Vuleta | 1de6126 | 2017-06-14 11:10:29 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2017-present 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 | */ |
| 16 | |
| 17 | package org.onosproject.drivers.hp; |
| 18 | |
| 19 | import org.onosproject.net.PortNumber; |
| 20 | import org.onosproject.net.flow.DefaultFlowRule; |
| 21 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 22 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 23 | import org.onosproject.net.flow.FlowRule; |
| 24 | import org.onosproject.net.flow.FlowRuleOperations; |
| 25 | import org.onosproject.net.flow.FlowRuleOperationsContext; |
| 26 | import org.onosproject.net.flow.TrafficSelector; |
| 27 | import org.onosproject.net.flow.TrafficTreatment; |
| 28 | import org.onosproject.net.flow.criteria.EthCriterion; |
| 29 | import org.onosproject.net.flow.criteria.IPCriterion; |
| 30 | import org.onosproject.net.flow.criteria.PortCriterion; |
| 31 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
| 32 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 33 | import org.slf4j.Logger; |
| 34 | |
| 35 | import static org.slf4j.LoggerFactory.getLogger; |
| 36 | |
| 37 | /** |
| 38 | * Driver for HP3800 hybrid switches. |
| 39 | */ |
| 40 | public class HPPipelineV3800 extends AbstractHPPipeline { |
| 41 | |
| 42 | private static final int HP_TABLE_ZERO = 0; |
| 43 | private static final int HP_HARDWARE_TABLE = 100; |
| 44 | private static final int HP_SOFTWARE_TABLE = 200; |
| 45 | |
| 46 | private final Logger log = getLogger(getClass()); |
| 47 | |
| 48 | |
| 49 | @Override |
| 50 | protected FlowRule.Builder setDefaultTableIdForFlowObjective(FlowRule.Builder ruleBuilder) { |
| 51 | log.debug("Setting default table id to hardware table {}", HP_HARDWARE_TABLE); |
| 52 | return ruleBuilder.forTable(HP_HARDWARE_TABLE); |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | protected void initializePipeline() { |
| 57 | log.debug("Installing table zero {}", HP_TABLE_ZERO); |
| 58 | installHPTableZero(); |
| 59 | log.debug("Installing scavenger rule to hardware table {} because it is default objective table", |
| 60 | HP_HARDWARE_TABLE); |
| 61 | installHPHardwareTable(); |
| 62 | log.debug("Installing software table {}", HP_SOFTWARE_TABLE); |
| 63 | installHPSoftwareTable(); |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public void filter(FilteringObjective filter) { |
| 68 | log.error("Unsupported FilteringObjective: : filtering method send"); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | protected FlowRule.Builder processEthFiler(FilteringObjective filt, EthCriterion eth, PortCriterion port) { |
| 73 | log.error("Unsupported FilteringObjective: processEthFilter invoked"); |
| 74 | return null; |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | protected FlowRule.Builder processVlanFiler(FilteringObjective filt, VlanIdCriterion vlan, PortCriterion port) { |
| 79 | log.error("Unsupported FilteringObjective: processVlanFilter invoked"); |
| 80 | return null; |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | protected FlowRule.Builder processIpFilter(FilteringObjective filt, IPCriterion ip, PortCriterion port) { |
| 85 | log.error("Unsupported FilteringObjective: processIpFilter invoked"); |
| 86 | return null; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * HP Table 0 initialization. |
| 91 | * Installs rule goto HP hardware table in HP table zero |
| 92 | */ |
| 93 | private void installHPTableZero() { |
| 94 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 95 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 96 | |
| 97 | treatment.transition(HP_HARDWARE_TABLE); |
| 98 | |
| 99 | FlowRule rule = DefaultFlowRule.builder().forDevice(this.deviceId) |
| 100 | .withSelector(selector.build()) |
| 101 | .withTreatment(treatment.build()) |
| 102 | .withPriority(0) |
| 103 | .fromApp(appId) |
| 104 | .makePermanent() |
| 105 | .forTable(HP_TABLE_ZERO) |
| 106 | .build(); |
| 107 | |
| 108 | this.applyRules(true, rule); |
| 109 | |
| 110 | log.info("Installed table {}", HP_TABLE_ZERO); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * HP hardware table initialization. |
| 115 | * Installs scavenger rule in HP hardware table. |
| 116 | */ |
| 117 | private void installHPHardwareTable() { |
| 118 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 119 | |
| 120 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 121 | treatment.setOutput(PortNumber.NORMAL); |
| 122 | |
| 123 | FlowRule rule = DefaultFlowRule.builder().forDevice(this.deviceId) |
| 124 | .withSelector(selector.build()) |
| 125 | .withTreatment(treatment.build()) |
| 126 | .withPriority(0) |
| 127 | .fromApp(appId) |
| 128 | .makePermanent() |
| 129 | .forTable(HP_HARDWARE_TABLE) |
| 130 | .build(); |
| 131 | |
| 132 | this.applyRules(true, rule); |
| 133 | |
| 134 | log.info("Installed table {}", HP_HARDWARE_TABLE); |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * HP software table initialization. |
| 139 | */ |
| 140 | private void installHPSoftwareTable() { |
| 141 | log.info("No rules installed in table {}", HP_SOFTWARE_TABLE); |
| 142 | } |
| 143 | |
| 144 | |
| 145 | /** |
| 146 | * Applies FlowRule. |
| 147 | * Installs or removes FlowRule. |
| 148 | * |
| 149 | * @param install - whether to install or remove rule |
| 150 | * @param rule - the rule to be installed or removed |
| 151 | */ |
| 152 | private void applyRules(boolean install, FlowRule rule) { |
| 153 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 154 | |
| 155 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 156 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 157 | @Override |
| 158 | public void onSuccess(FlowRuleOperations ops) { |
| 159 | log.trace("Provisioned rule: " + rule.toString()); |
| 160 | log.trace("HP3800 driver: provisioned " + rule.tableId() + " table"); |
| 161 | } |
| 162 | |
| 163 | @Override |
| 164 | public void onError(FlowRuleOperations ops) { |
| 165 | log.info("HP3800 driver: failed to provision " + rule.tableId() + " table"); |
| 166 | } |
| 167 | })); |
| 168 | } |
| 169 | } |