Michele Santuari | 9a8d16d | 2016-03-24 10:37:58 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2014-2016 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.corsa; |
| 18 | |
| 19 | import org.onlab.packet.Ethernet; |
| 20 | import org.onlab.packet.IPv4; |
| 21 | import org.onlab.packet.VlanId; |
| 22 | import org.onosproject.net.flow.DefaultFlowRule; |
| 23 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 24 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 25 | import org.onosproject.net.flow.FlowRule; |
| 26 | import org.onosproject.net.flow.TrafficSelector; |
| 27 | import org.onosproject.net.flow.TrafficTreatment; |
| 28 | import org.onosproject.net.flow.criteria.Criterion; |
| 29 | import org.onosproject.net.flow.criteria.IPCriterion; |
| 30 | import org.onosproject.net.flow.criteria.IPProtocolCriterion; |
| 31 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 32 | import org.onosproject.net.flowobjective.ObjectiveError; |
| 33 | import org.slf4j.Logger; |
| 34 | |
| 35 | import java.util.Collection; |
| 36 | import java.util.Collections; |
| 37 | |
| 38 | import static org.onosproject.net.flow.FlowRule.Builder; |
| 39 | import static org.slf4j.LoggerFactory.getLogger; |
| 40 | |
| 41 | public class CorsaPipelineV39 extends CorsaPipelineV3 { |
| 42 | |
| 43 | private final Logger log = getLogger(getClass()); |
| 44 | |
| 45 | private static final Short NATIVE_VLAN = 4095; |
| 46 | |
| 47 | @Override |
| 48 | public void initializePipeline() { |
| 49 | |
| 50 | processMeterTable(true); //Meter Table |
| 51 | processPortBasedProtoTable(true); |
| 52 | processVlanCheckTable(true); //Table 1 |
| 53 | processVlanMacXlateTable(true); //Table 2 |
| 54 | processVlanCircuitTable(true); //Table 3 |
| 55 | processL3IFMacDATable(true); //Table 5 |
| 56 | processEtherTable(true); //Table 6 |
| 57 | //TODO: to be implemented for intents |
| 58 | //processFibTable(true); //Table 7 |
| 59 | //processLocalTable(true); //Table 9 |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | protected void processVlanCheckTable(boolean install) { |
| 64 | //FIXME: error |
| 65 | processTableMissGoTo(true, VLAN_CHECK_TABLE, VLAN_MAC_XLATE_TABLE, "Provisioned vlan tagged"); |
| 66 | //Tag untagged packets |
| 67 | processUntaggedPackets(install); |
| 68 | |
| 69 | } |
| 70 | |
| 71 | private void processUntaggedPackets(boolean install) { |
| 72 | |
| 73 | deviceService.getPorts(deviceId).forEach(port -> { |
| 74 | if (!port.number().isLogical()) { |
| 75 | |
| 76 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder() |
| 77 | .pushVlan().setVlanId(VlanId.vlanId(NATIVE_VLAN)) |
| 78 | .transition(VLAN_MAC_XLATE_TABLE); |
| 79 | |
| 80 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder() |
| 81 | .matchVlanId(VlanId.NONE) |
| 82 | .matchInPort(port.number()); |
| 83 | |
| 84 | Builder rule = DefaultFlowRule.builder() |
| 85 | .forDevice(deviceId) |
| 86 | .withTreatment(treatment.build()) |
| 87 | .withSelector(selector.build()) |
| 88 | .withPriority(CONTROLLER_PRIORITY) |
| 89 | .fromApp(appId) |
| 90 | .makePermanent() |
| 91 | .forTable(VLAN_CHECK_TABLE); |
| 92 | |
| 93 | processFlowRule(install, rule.build(), "Provisioned vlan untagged packet table"); |
| 94 | } |
| 95 | }); |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | protected void processVlanCircuitTable(boolean install) { |
| 100 | //Default action |
| 101 | processTableMissDrop(install, VLAN_CIRCUIT_TABLE, "Provisioned vlan circuit table drop"); |
| 102 | //FIXME: it should be done only per port based when intent is installed |
| 103 | //Manage untagged packets |
| 104 | processRouterPacket(install); |
| 105 | } |
| 106 | |
| 107 | private void processRouterPacket(boolean install) { |
| 108 | |
| 109 | deviceService.getPorts(deviceId).forEach(port -> { |
| 110 | if (!port.number().isLogical()) { |
| 111 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder() |
| 112 | .matchVlanId(VlanId.vlanId(NATIVE_VLAN)) |
| 113 | .matchInPort(port.number()); |
| 114 | |
| 115 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder() |
| 116 | .setVlanPcp((byte) 0) |
| 117 | .setQueue(0) |
| 118 | .meter(defaultMeterId) |
| 119 | .transition(L3_IF_MAC_DA_TABLE); |
| 120 | |
| 121 | FlowRule rule = DefaultFlowRule.builder() |
| 122 | .forDevice(deviceId) |
| 123 | .withSelector(selector.build()) |
| 124 | .withTreatment(treatment.build()) |
| 125 | .withPriority(CONTROLLER_PRIORITY) |
| 126 | .fromApp(appId) |
| 127 | .makePermanent() |
| 128 | .forTable(VLAN_CIRCUIT_TABLE).build(); |
| 129 | processFlowRule(install, rule, "Provisioned vlan circuit table"); |
| 130 | } |
| 131 | }); |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | protected void processL3IFMacDATable(boolean install) { |
| 136 | int table = L3_IF_MAC_DA_TABLE; |
| 137 | |
| 138 | //Default action |
| 139 | processTableMissDrop(install, table, "Provisioned l3 table drop"); |
| 140 | |
| 141 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 142 | |
| 143 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder() |
| 144 | .transition(ETHER_TABLE); |
| 145 | |
| 146 | FlowRule rule = DefaultFlowRule.builder() |
| 147 | .forDevice(deviceId) |
| 148 | .withSelector(selector.build()) |
| 149 | .withTreatment(treatment.build()) |
| 150 | .withPriority(1) |
| 151 | .fromApp(appId) |
| 152 | .makePermanent() |
| 153 | .forTable(table).build(); |
| 154 | processFlowRule(install, rule, "Provisioned l3 table"); |
| 155 | } |
| 156 | |
| 157 | protected void processEtherTable(boolean install) { |
| 158 | |
| 159 | //Default action |
| 160 | processTableMissDrop(install, ETHER_TABLE, "Provisioned ether type table drop"); |
| 161 | |
| 162 | //IP to FIB_TABLE |
| 163 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder() |
| 164 | .matchEthType(Ethernet.TYPE_IPV4); |
| 165 | |
| 166 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().transition(FIB_TABLE); |
| 167 | |
| 168 | FlowRule rule = DefaultFlowRule.builder() |
| 169 | .forDevice(deviceId) |
| 170 | .withSelector(selector.build()) |
| 171 | .withTreatment(treatment.build()) |
| 172 | .withPriority(CONTROLLER_PRIORITY) |
| 173 | .fromApp(appId) |
| 174 | .makePermanent() |
| 175 | .forTable(ETHER_TABLE).build(); |
| 176 | processFlowRule(install, rule, "Provisioned ether type table ip"); |
| 177 | } |
| 178 | |
| 179 | @Override |
| 180 | protected Collection<FlowRule> processArpTraffic(ForwardingObjective fwd, Builder rule) { |
| 181 | rule.forTable(PORT_BASED_PROTO_TABLE); |
| 182 | rule.withPriority(255); |
| 183 | return Collections.singletonList(rule.build()); |
| 184 | } |
| 185 | |
| 186 | @Override |
| 187 | protected Collection<FlowRule> processLinkDiscovery(ForwardingObjective fwd, Builder rule) { |
| 188 | rule.forTable(PORT_BASED_PROTO_TABLE); |
| 189 | rule.withPriority(255); |
| 190 | return Collections.singletonList(rule.build()); |
| 191 | } |
| 192 | |
| 193 | @Override |
| 194 | protected Collection<FlowRule> processIpTraffic(ForwardingObjective fwd, Builder rule) { |
| 195 | IPCriterion ipSrc = (IPCriterion) fwd.selector() |
| 196 | .getCriterion(Criterion.Type.IPV4_SRC); |
| 197 | if (ipSrc != null) { |
| 198 | log.warn("Driver does not currently handle matching Src IP"); |
| 199 | fail(fwd, ObjectiveError.UNSUPPORTED); |
| 200 | return Collections.emptySet(); |
| 201 | } |
| 202 | IPCriterion ipDst = (IPCriterion) fwd.selector() |
| 203 | .getCriterion(Criterion.Type.IPV4_DST); |
| 204 | if (ipDst != null) { |
| 205 | log.error("Driver handles Dst IP matching as specific forwarding " |
| 206 | + "objective, not versatile"); |
| 207 | fail(fwd, ObjectiveError.UNSUPPORTED); |
| 208 | return Collections.emptySet(); |
| 209 | } |
| 210 | IPProtocolCriterion ipProto = (IPProtocolCriterion) fwd.selector() |
| 211 | .getCriterion(Criterion.Type.IP_PROTO); |
| 212 | if (ipProto != null && ipProto.protocol() == IPv4.PROTOCOL_TCP) { |
| 213 | log.warn("Driver automatically punts all packets reaching the " |
| 214 | + "LOCAL table to the controller"); |
| 215 | pass(fwd); |
| 216 | return Collections.emptySet(); |
| 217 | } |
| 218 | return Collections.emptySet(); |
| 219 | } |
| 220 | } |