Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 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 | */ |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 16 | package org.onosproject.driver.pipeline.ofdpa; |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 17 | |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableList; |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableSet; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 20 | import org.onlab.packet.Ethernet; |
Julia Ferguson | 65428c3 | 2017-08-10 18:15:24 +0000 | [diff] [blame] | 21 | import org.onlab.packet.IpAddress; |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 22 | import org.onlab.packet.IpPrefix; |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 23 | import org.onlab.packet.VlanId; |
| 24 | import org.onosproject.core.ApplicationId; |
Yi Tseng | fa394de | 2017-02-01 11:26:40 -0800 | [diff] [blame] | 25 | import org.onosproject.core.GroupId; |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 26 | import org.onosproject.net.Port; |
| 27 | import org.onosproject.net.PortNumber; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 28 | import org.onosproject.net.behaviour.NextGroup; |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 29 | import org.onosproject.net.behaviour.PipelinerContext; |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 30 | import org.onosproject.net.flow.DefaultFlowRule; |
| 31 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 32 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 33 | import org.onosproject.net.flow.FlowRule; |
| 34 | import org.onosproject.net.flow.FlowRuleOperations; |
| 35 | import org.onosproject.net.flow.FlowRuleOperationsContext; |
| 36 | import org.onosproject.net.flow.TrafficSelector; |
| 37 | import org.onosproject.net.flow.TrafficTreatment; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 38 | import org.onosproject.net.flow.criteria.Criteria; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 39 | import org.onosproject.net.flow.criteria.Criterion; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 40 | import org.onosproject.net.flow.criteria.EthCriterion; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 41 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
| 42 | import org.onosproject.net.flow.criteria.IPCriterion; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 43 | import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion; |
| 44 | import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 45 | import org.onosproject.net.flow.criteria.MplsBosCriterion; |
| 46 | import org.onosproject.net.flow.criteria.MplsCriterion; |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 47 | import org.onosproject.net.flow.criteria.PortCriterion; |
| 48 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 49 | import org.onosproject.net.flow.instructions.Instruction; |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 50 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 51 | import org.onosproject.net.flow.instructions.L3ModificationInstruction; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 52 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 53 | import org.onosproject.net.flowobjective.ObjectiveError; |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 54 | import org.onosproject.net.group.DefaultGroupBucket; |
| 55 | import org.onosproject.net.group.DefaultGroupDescription; |
| 56 | import org.onosproject.net.group.DefaultGroupKey; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 57 | import org.onosproject.net.group.Group; |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 58 | import org.onosproject.net.group.GroupBucket; |
| 59 | import org.onosproject.net.group.GroupBuckets; |
| 60 | import org.onosproject.net.group.GroupDescription; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 61 | import org.onosproject.net.group.GroupKey; |
Charles Chan | f57a825 | 2016-06-29 19:12:37 -0700 | [diff] [blame] | 62 | import org.onosproject.net.packet.PacketPriority; |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 63 | import org.slf4j.Logger; |
| 64 | |
Jonathan Hart | 855179c | 2016-04-26 07:40:04 -0700 | [diff] [blame] | 65 | import java.util.ArrayList; |
| 66 | import java.util.Collection; |
| 67 | import java.util.Collections; |
| 68 | import java.util.Deque; |
| 69 | import java.util.List; |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 70 | import java.util.Objects; |
Jonathan Hart | 855179c | 2016-04-26 07:40:04 -0700 | [diff] [blame] | 71 | |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 72 | import static org.onlab.packet.IPv6.PROTOCOL_ICMP6; |
Charles Chan | d05f54b | 2017-02-13 11:56:54 -0800 | [diff] [blame] | 73 | import static org.onlab.packet.MacAddress.BROADCAST; |
| 74 | import static org.onlab.packet.MacAddress.NONE; |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 75 | import static org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.*; |
Jonathan Hart | 855179c | 2016-04-26 07:40:04 -0700 | [diff] [blame] | 76 | import static org.slf4j.LoggerFactory.getLogger; |
| 77 | |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 80 | * Driver for software switch emulation of the OFDPA pipeline. |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 81 | * The software switch is the CPqD OF 1.3 switch. Unfortunately the CPqD switch |
| 82 | * does not handle vlan tags and mpls labels simultaneously, which requires us |
| 83 | * to do some workarounds in the driver. This driver is meant for the use of |
| 84 | * the cpqd switch when MPLS is required. As a result this driver works only |
| 85 | * on incoming untagged packets. |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 86 | */ |
Charles Chan | 361154b | 2016-03-24 10:23:39 -0700 | [diff] [blame] | 87 | public class CpqdOfdpa2Pipeline extends Ofdpa2Pipeline { |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 88 | |
| 89 | private final Logger log = getLogger(getClass()); |
| 90 | |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 91 | /** |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 92 | * Table that determines whether VLAN is popped before punting to controller. |
| 93 | * <p> |
| 94 | * This is a non-OFDPA table to emulate OFDPA packet in behavior. |
| 95 | * VLAN will be popped before punting if the VLAN is internally assigned. |
| 96 | * <p> |
| 97 | * Also note that 63 is the max table number in CpqD. |
| 98 | */ |
| 99 | private static final int PUNT_TABLE = 63; |
| 100 | |
| 101 | /** |
| 102 | * A static indirect group that pop vlan and punt to controller. |
| 103 | * <p> |
| 104 | * The purpose of using a group instead of immediate action is that this |
| 105 | * won't affect another copy on the data plane when write action exists. |
| 106 | */ |
| 107 | private static final int POP_VLAN_PUNT_GROUP_ID = 0xc0000000; |
| 108 | |
Charles Chan | 053b1cb | 2017-03-22 16:56:35 -0700 | [diff] [blame] | 109 | @Override |
| 110 | protected boolean requireVlanExtensions() { |
| 111 | return false; |
| 112 | } |
| 113 | |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 114 | /** |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 115 | * Determines whether this pipeline support copy ttl instructions or not. |
| 116 | * |
| 117 | * @return true if copy ttl instructions are supported |
| 118 | */ |
| 119 | protected boolean supportCopyTtl() { |
| 120 | return true; |
| 121 | } |
| 122 | |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 123 | /** |
| 124 | * Determines whether this pipeline support push mpls to vlan-tagged packets or not. |
| 125 | * <p> |
| 126 | * If not support, pop vlan before push entering unicast and mpls table. |
| 127 | * Side effect: HostService learns redundant hosts with same MAC but |
| 128 | * different VLAN. No known side effect on the network reachability. |
| 129 | * |
| 130 | * @return true if push mpls to vlan-tagged packets is supported |
| 131 | */ |
| 132 | protected boolean supportTaggedMpls() { |
| 133 | return false; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Determines whether this pipeline support punt action in group bucket. |
| 138 | * |
| 139 | * @return true if punt action in group bucket is supported |
| 140 | */ |
| 141 | protected boolean supportPuntGroup() { |
| 142 | return false; |
| 143 | } |
| 144 | |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 145 | @Override |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 146 | protected void initDriverId() { |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 147 | driverId = coreService.registerApplication( |
| 148 | "org.onosproject.driver.CpqdOfdpa2Pipeline"); |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 149 | } |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 150 | |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 151 | @Override |
| 152 | protected void initGroupHander(PipelinerContext context) { |
| 153 | groupHandler = new CpqdOfdpa2GroupHandler(); |
| 154 | groupHandler.init(deviceId, context); |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 157 | /* |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 158 | * Cpqd emulation does not require the non OF-standard rules for |
| 159 | * matching untagged packets that ofdpa uses. |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 160 | * |
| 161 | * (non-Javadoc) |
| 162 | * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#processVlanIdFilter |
| 163 | */ |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 164 | @Override |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 165 | protected List<FlowRule> processVlanIdFilter(PortCriterion portCriterion, |
| 166 | VlanIdCriterion vidCriterion, |
| 167 | VlanId assignedVlan, |
| 168 | ApplicationId applicationId) { |
Charles Chan | 7976923 | 2016-07-05 16:34:39 -0700 | [diff] [blame] | 169 | List<FlowRule> rules = new ArrayList<>(); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 170 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 171 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 172 | selector.matchVlanId(vidCriterion.vlanId()); |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 173 | treatment.transition(TMAC_TABLE); |
| 174 | |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 175 | if (vidCriterion.vlanId() == VlanId.NONE) { |
| 176 | // untagged packets are assigned vlans |
| 177 | treatment.pushVlan().setVlanId(assignedVlan); |
| 178 | } |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 179 | |
| 180 | // ofdpa cannot match on ALL portnumber, so we need to use separate |
| 181 | // rules for each port. |
| 182 | List<PortNumber> portnums = new ArrayList<PortNumber>(); |
| 183 | if (portCriterion.port() == PortNumber.ALL) { |
| 184 | for (Port port : deviceService.getPorts(deviceId)) { |
| 185 | if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) { |
| 186 | portnums.add(port.number()); |
| 187 | } |
| 188 | } |
| 189 | } else { |
| 190 | portnums.add(portCriterion.port()); |
| 191 | } |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 192 | |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 193 | for (PortNumber pnum : portnums) { |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 194 | // NOTE: Emulating OFDPA behavior by popping off internal assigned |
| 195 | // VLAN before sending to controller |
| 196 | if (supportPuntGroup() && vidCriterion.vlanId() == VlanId.NONE) { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 197 | GroupKey groupKey = popVlanPuntGroupKey(); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 198 | Group group = groupService.getGroup(deviceId, groupKey); |
| 199 | if (group != null) { |
| 200 | rules.add(buildPuntTableRule(pnum, assignedVlan)); |
| 201 | } else { |
| 202 | log.info("popVlanPuntGroup not found in dev:{}", deviceId); |
| 203 | return Collections.emptyList(); |
| 204 | } |
| 205 | } |
| 206 | |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 207 | // create rest of flowrule |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 208 | selector.matchInPort(pnum); |
| 209 | FlowRule rule = DefaultFlowRule.builder() |
| 210 | .forDevice(deviceId) |
| 211 | .withSelector(selector.build()) |
| 212 | .withTreatment(treatment.build()) |
| 213 | .withPriority(DEFAULT_PRIORITY) |
| 214 | .fromApp(applicationId) |
| 215 | .makePermanent() |
| 216 | .forTable(VLAN_TABLE).build(); |
| 217 | rules.add(rule); |
| 218 | } |
Charles Chan | f57a825 | 2016-06-29 19:12:37 -0700 | [diff] [blame] | 219 | |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 220 | return rules; |
| 221 | } |
| 222 | |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 223 | /** |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 224 | * Creates punt table entry that matches IN_PORT and VLAN_VID and points to |
| 225 | * a group that pop vlan and punt. |
| 226 | * |
| 227 | * @param portNumber port number |
| 228 | * @param assignedVlan internally assigned vlan id |
| 229 | * @return punt table flow rule |
| 230 | */ |
| 231 | private FlowRule buildPuntTableRule(PortNumber portNumber, VlanId assignedVlan) { |
| 232 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder() |
| 233 | .matchInPort(portNumber) |
| 234 | .matchVlanId(assignedVlan); |
| 235 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder() |
Yi Tseng | fa394de | 2017-02-01 11:26:40 -0800 | [diff] [blame] | 236 | .group(new GroupId(POP_VLAN_PUNT_GROUP_ID)); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 237 | |
| 238 | return DefaultFlowRule.builder() |
| 239 | .forDevice(deviceId) |
| 240 | .withSelector(sbuilder.build()) |
| 241 | .withTreatment(tbuilder.build()) |
| 242 | .withPriority(PacketPriority.CONTROL.priorityValue()) |
| 243 | .fromApp(driverId) |
| 244 | .makePermanent() |
| 245 | .forTable(PUNT_TABLE).build(); |
| 246 | } |
| 247 | |
| 248 | /** |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 249 | * Builds a punt to the controller rule for the arp protocol. |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 250 | * <p> |
| 251 | * NOTE: CpqD cannot punt correctly in group bucket. The current impl will |
| 252 | * pop VLAN before sending to controller disregarding whether |
| 253 | * it's an internally assigned VLAN or a natural VLAN. |
| 254 | * Therefore, trunk port is not supported in CpqD. |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 255 | * |
| 256 | * @param assignedVlan the internal assigned vlan id |
| 257 | * @param applicationId the application id |
| 258 | * @return the punt flow rule for the arp |
| 259 | */ |
| 260 | private FlowRule buildArpPunt(VlanId assignedVlan, ApplicationId applicationId) { |
| 261 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder() |
| 262 | .matchEthType(Ethernet.TYPE_ARP) |
| 263 | .matchVlanId(assignedVlan); |
| 264 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder() |
| 265 | .popVlan() |
| 266 | .punt(); |
| 267 | |
| 268 | return DefaultFlowRule.builder() |
| 269 | .forDevice(deviceId) |
| 270 | .withSelector(sbuilder.build()) |
| 271 | .withTreatment(tbuilder.build()) |
| 272 | .withPriority(PacketPriority.CONTROL.priorityValue() + 1) |
| 273 | .fromApp(applicationId) |
| 274 | .makePermanent() |
| 275 | .forTable(ACL_TABLE).build(); |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * Builds a punt to the controller rule for the icmp v6 messages. |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 280 | * <p> |
| 281 | * NOTE: CpqD cannot punt correctly in group bucket. The current impl will |
| 282 | * pop VLAN before sending to controller disregarding whether |
| 283 | * it's an internally assigned VLAN or a natural VLAN. |
| 284 | * Therefore, trunk port is not supported in CpqD. |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 285 | * |
| 286 | * @param assignedVlan the internal assigned vlan id |
| 287 | * @param applicationId the application id |
| 288 | * @return the punt flow rule for the icmp v6 messages |
| 289 | */ |
| 290 | private FlowRule buildIcmpV6Punt(VlanId assignedVlan, ApplicationId applicationId) { |
| 291 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder() |
| 292 | .matchVlanId(assignedVlan) |
| 293 | .matchEthType(Ethernet.TYPE_IPV6) |
| 294 | .matchIPProtocol(PROTOCOL_ICMP6); |
| 295 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder() |
| 296 | .popVlan() |
| 297 | .punt(); |
| 298 | |
| 299 | return DefaultFlowRule.builder() |
| 300 | .forDevice(deviceId) |
| 301 | .withSelector(sbuilder.build()) |
| 302 | .withTreatment(tbuilder.build()) |
| 303 | .withPriority(PacketPriority.CONTROL.priorityValue() + 1) |
| 304 | .fromApp(applicationId) |
| 305 | .makePermanent() |
| 306 | .forTable(ACL_TABLE).build(); |
| 307 | } |
| 308 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 309 | /* |
| 310 | * Cpqd emulation does not handle vlan tags and mpls labels correctly. |
| 311 | * Workaround requires popping off the VLAN tags in the TMAC table. |
| 312 | * |
| 313 | * (non-Javadoc) |
| 314 | * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#processEthDstFilter |
| 315 | */ |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 316 | @Override |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 317 | protected List<FlowRule> processEthDstFilter(PortCriterion portCriterion, |
| 318 | EthCriterion ethCriterion, |
| 319 | VlanIdCriterion vidCriterion, |
| 320 | VlanId assignedVlan, |
| 321 | ApplicationId applicationId) { |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 322 | // Consider PortNumber.ANY as wildcard. Match ETH_DST only |
| 323 | if (portCriterion != null && portCriterion.port() == PortNumber.ANY) { |
| 324 | return processEthDstOnlyFilter(ethCriterion, applicationId); |
| 325 | } |
| 326 | |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 327 | // Multicast MAC |
| 328 | if (ethCriterion.mask() != null) { |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 329 | return processMcastEthDstFilter(ethCriterion, assignedVlan, applicationId); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 332 | //handling untagged packets via assigned VLAN |
| 333 | if (vidCriterion.vlanId() == VlanId.NONE) { |
| 334 | vidCriterion = (VlanIdCriterion) Criteria.matchVlanId(assignedVlan); |
| 335 | } |
| 336 | // ofdpa cannot match on ALL portnumber, so we need to use separate |
| 337 | // rules for each port. |
| 338 | List<PortNumber> portnums = new ArrayList<PortNumber>(); |
| 339 | if (portCriterion.port() == PortNumber.ALL) { |
| 340 | for (Port port : deviceService.getPorts(deviceId)) { |
| 341 | if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) { |
| 342 | portnums.add(port.number()); |
| 343 | } |
| 344 | } |
| 345 | } else { |
| 346 | portnums.add(portCriterion.port()); |
| 347 | } |
| 348 | |
| 349 | List<FlowRule> rules = new ArrayList<FlowRule>(); |
| 350 | for (PortNumber pnum : portnums) { |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 351 | // TMAC rules for unicast IP packets |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 352 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 353 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 354 | selector.matchInPort(pnum); |
| 355 | selector.matchVlanId(vidCriterion.vlanId()); |
| 356 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 357 | selector.matchEthDst(ethCriterion.mac()); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 358 | if (!supportTaggedMpls()) { |
| 359 | treatment.popVlan(); |
| 360 | } |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 361 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 362 | FlowRule rule = DefaultFlowRule.builder() |
| 363 | .forDevice(deviceId) |
| 364 | .withSelector(selector.build()) |
| 365 | .withTreatment(treatment.build()) |
| 366 | .withPriority(DEFAULT_PRIORITY) |
| 367 | .fromApp(applicationId) |
| 368 | .makePermanent() |
| 369 | .forTable(TMAC_TABLE).build(); |
| 370 | rules.add(rule); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 371 | |
| 372 | // TMAC rules for MPLS packets |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 373 | selector = DefaultTrafficSelector.builder(); |
| 374 | treatment = DefaultTrafficTreatment.builder(); |
| 375 | selector.matchInPort(pnum); |
| 376 | selector.matchVlanId(vidCriterion.vlanId()); |
| 377 | selector.matchEthType(Ethernet.MPLS_UNICAST); |
| 378 | selector.matchEthDst(ethCriterion.mac()); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 379 | if (!supportTaggedMpls()) { |
| 380 | treatment.popVlan(); |
| 381 | } |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 382 | treatment.transition(MPLS_TABLE_0); |
| 383 | rule = DefaultFlowRule.builder() |
| 384 | .forDevice(deviceId) |
| 385 | .withSelector(selector.build()) |
| 386 | .withTreatment(treatment.build()) |
| 387 | .withPriority(DEFAULT_PRIORITY) |
| 388 | .fromApp(applicationId) |
| 389 | .makePermanent() |
| 390 | .forTable(TMAC_TABLE).build(); |
| 391 | rules.add(rule); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 392 | |
| 393 | // TMAC rules for IPv6 packets |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 394 | selector = DefaultTrafficSelector.builder(); |
| 395 | treatment = DefaultTrafficTreatment.builder(); |
| 396 | selector.matchInPort(pnum); |
| 397 | selector.matchVlanId(vidCriterion.vlanId()); |
| 398 | selector.matchEthType(Ethernet.TYPE_IPV6); |
| 399 | selector.matchEthDst(ethCriterion.mac()); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 400 | if (!supportTaggedMpls()) { |
| 401 | treatment.popVlan(); |
| 402 | } |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 403 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 404 | rule = DefaultFlowRule.builder() |
| 405 | .forDevice(deviceId) |
| 406 | .withSelector(selector.build()) |
| 407 | .withTreatment(treatment.build()) |
| 408 | .withPriority(DEFAULT_PRIORITY) |
| 409 | .fromApp(applicationId) |
| 410 | .makePermanent() |
| 411 | .forTable(TMAC_TABLE).build(); |
| 412 | rules.add(rule); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 413 | } |
| 414 | return rules; |
| 415 | } |
| 416 | |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 417 | @Override |
| 418 | protected List<FlowRule> processEthDstOnlyFilter(EthCriterion ethCriterion, |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 419 | ApplicationId applicationId) { |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 420 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 421 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 422 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 423 | selector.matchEthDst(ethCriterion.mac()); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 424 | if (!supportTaggedMpls()) { |
| 425 | treatment.popVlan(); |
| 426 | } |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 427 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 428 | FlowRule rule = DefaultFlowRule.builder() |
| 429 | .forDevice(deviceId) |
| 430 | .withSelector(selector.build()) |
| 431 | .withTreatment(treatment.build()) |
| 432 | .withPriority(DEFAULT_PRIORITY) |
| 433 | .fromApp(applicationId) |
| 434 | .makePermanent() |
| 435 | .forTable(TMAC_TABLE).build(); |
| 436 | return ImmutableList.<FlowRule>builder().add(rule).build(); |
| 437 | } |
| 438 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 439 | /* |
| 440 | * Cpqd emulation allows MPLS ecmp. |
| 441 | * |
| 442 | * (non-Javadoc) |
| 443 | * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#processEthTypeSpecific |
| 444 | */ |
| 445 | @Override |
| 446 | protected Collection<FlowRule> processEthTypeSpecific(ForwardingObjective fwd) { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 447 | TrafficSelector selector = fwd.selector(); |
| 448 | EthTypeCriterion ethType = |
| 449 | (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE); |
| 450 | if ((ethType == null) || |
| 451 | (ethType.ethType().toShort() != Ethernet.TYPE_IPV4) && |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 452 | (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST) && |
| 453 | (ethType.ethType().toShort() != Ethernet.TYPE_IPV6)) { |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 454 | log.warn("processSpecific: Unsupported forwarding objective criteria" |
| 455 | + "ethType:{} in dev:{}", ethType, deviceId); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 456 | fail(fwd, ObjectiveError.UNSUPPORTED); |
| 457 | return Collections.emptySet(); |
| 458 | } |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 459 | boolean defaultRule = false; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 460 | int forTableId = -1; |
| 461 | TrafficSelector.Builder filteredSelector = DefaultTrafficSelector.builder(); |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 462 | TrafficSelector.Builder complementarySelector = DefaultTrafficSelector.builder(); |
| 463 | |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 464 | if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) { |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 465 | IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip(); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 466 | if (ipv4Dst.isMulticast()) { |
| 467 | if (ipv4Dst.prefixLength() != 32) { |
| 468 | log.warn("Multicast specific forwarding objective can only be /32"); |
| 469 | fail(fwd, ObjectiveError.BADPARAMS); |
| 470 | return ImmutableSet.of(); |
| 471 | } |
| 472 | VlanId assignedVlan = readVlanFromSelector(fwd.meta()); |
| 473 | if (assignedVlan == null) { |
| 474 | log.warn("VLAN ID required by multicast specific fwd obj is missing. Abort."); |
| 475 | fail(fwd, ObjectiveError.BADPARAMS); |
| 476 | return ImmutableSet.of(); |
| 477 | } |
| 478 | filteredSelector.matchVlanId(assignedVlan); |
| 479 | filteredSelector.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ipv4Dst); |
| 480 | forTableId = MULTICAST_ROUTING_TABLE; |
| 481 | log.debug("processing IPv4 multicast specific forwarding objective {} -> next:{}" |
| 482 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 483 | } else { |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 484 | if (ipv4Dst.prefixLength() == 0) { |
| 485 | // The entire IPV4_DST field is wildcarded intentionally |
| 486 | filteredSelector.matchEthType(Ethernet.TYPE_IPV4); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 487 | } else { |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 488 | filteredSelector.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ipv4Dst); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 489 | } |
| 490 | forTableId = UNICAST_ROUTING_TABLE; |
| 491 | log.debug("processing IPv4 unicast specific forwarding objective {} -> next:{}" |
| 492 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 493 | } |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 494 | } else if (ethType.ethType().toShort() == Ethernet.TYPE_IPV6) { |
Julia Ferguson | 65428c3 | 2017-08-10 18:15:24 +0000 | [diff] [blame] | 495 | IpPrefix ipv6Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV6_DST)).ip(); |
| 496 | if (ipv6Dst.isMulticast()) { |
| 497 | if (ipv6Dst.prefixLength() != IpAddress.INET6_BIT_LENGTH) { |
| 498 | log.debug("Multicast specific IPv6 forwarding objective can only be /128"); |
| 499 | fail(fwd, ObjectiveError.BADPARAMS); |
| 500 | return ImmutableSet.of(); |
| 501 | } |
| 502 | VlanId assignedVlan = readVlanFromSelector(fwd.meta()); |
| 503 | if (assignedVlan == null) { |
| 504 | log.debug("VLAN ID required by multicast specific fwd obj is missing. Abort."); |
| 505 | fail(fwd, ObjectiveError.BADPARAMS); |
| 506 | return ImmutableSet.of(); |
| 507 | } |
| 508 | filteredSelector.matchVlanId(assignedVlan); |
| 509 | filteredSelector.matchEthType(Ethernet.TYPE_IPV6).matchIPv6Dst(ipv6Dst); |
| 510 | forTableId = MULTICAST_ROUTING_TABLE; |
| 511 | log.debug("processing IPv6 multicast specific forwarding objective {} -> next:{}" |
| 512 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
| 513 | } else { |
| 514 | if (buildIpv6Selector(filteredSelector, fwd) < 0) { |
| 515 | return Collections.emptyList(); |
| 516 | } |
| 517 | forTableId = UNICAST_ROUTING_TABLE; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 518 | } |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 519 | } else { |
| 520 | filteredSelector |
| 521 | .matchEthType(Ethernet.MPLS_UNICAST) |
| 522 | .matchMplsLabel(((MplsCriterion) |
| 523 | selector.getCriterion(Criterion.Type.MPLS_LABEL)).label()); |
| 524 | MplsBosCriterion bos = (MplsBosCriterion) selector |
| 525 | .getCriterion(Criterion.Type.MPLS_BOS); |
| 526 | if (bos != null) { |
| 527 | filteredSelector.matchMplsBos(bos.mplsBos()); |
| 528 | } |
| 529 | forTableId = MPLS_TABLE_1; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 530 | log.debug("processing MPLS specific forwarding objective {} -> next:{}" |
| 531 | + " in dev {}", fwd.id(), fwd.nextId(), deviceId); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder(); |
| 535 | if (fwd.treatment() != null) { |
| 536 | for (Instruction i : fwd.treatment().allInstructions()) { |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 537 | if (!supportCopyTtl() && i instanceof L3ModificationInstruction) { |
| 538 | L3ModificationInstruction l3instr = (L3ModificationInstruction) i; |
| 539 | if (l3instr.subtype().equals(L3ModificationInstruction.L3SubType.TTL_IN) || |
| 540 | l3instr.subtype().equals(L3ModificationInstruction.L3SubType.TTL_OUT)) { |
| 541 | continue; |
| 542 | } |
| 543 | } |
Charles Chan | 7d10b16 | 2015-12-07 18:54:45 -0800 | [diff] [blame] | 544 | /* |
| 545 | * NOTE: OF-DPA does not support immediate instruction in |
| 546 | * L3 unicast and MPLS table. |
| 547 | */ |
| 548 | tb.deferred().add(i); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | |
| 552 | if (fwd.nextId() != null) { |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 553 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
| 554 | if (next != null) { |
| 555 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 556 | // we only need the top level group's key to point the flow to it |
| 557 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 558 | if (group == null) { |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 559 | log.warn("Group with key:{} for next-id:{} not found in dev:{}", |
| 560 | gkeys.get(0).peekFirst(), fwd.nextId(), deviceId); |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 561 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 562 | return Collections.emptySet(); |
| 563 | } |
| 564 | tb.deferred().group(group.id()); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 565 | } |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 566 | } |
| 567 | tb.transition(ACL_TABLE); |
| 568 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
| 569 | .fromApp(fwd.appId()) |
| 570 | .withPriority(fwd.priority()) |
| 571 | .forDevice(deviceId) |
| 572 | .withSelector(filteredSelector.build()) |
| 573 | .withTreatment(tb.build()) |
| 574 | .forTable(forTableId); |
| 575 | |
| 576 | if (fwd.permanent()) { |
| 577 | ruleBuilder.makePermanent(); |
| 578 | } else { |
| 579 | ruleBuilder.makeTemporary(fwd.timeout()); |
| 580 | } |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 581 | Collection<FlowRule> flowRuleCollection = new ArrayList<>(); |
| 582 | flowRuleCollection.add(ruleBuilder.build()); |
| 583 | if (defaultRule) { |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 584 | flowRuleCollection.add( |
| 585 | defaultRoute(fwd, complementarySelector, forTableId, tb) |
| 586 | ); |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 587 | log.debug("Default rule 0.0.0.0/0 is being installed two rules"); |
| 588 | } |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 589 | return flowRuleCollection; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 590 | } |
| 591 | |
Charles Chan | 1e492d3 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 592 | @Override |
| 593 | protected Collection<FlowRule> processEthDstSpecific(ForwardingObjective fwd) { |
| 594 | List<FlowRule> rules = new ArrayList<>(); |
| 595 | |
| 596 | // Build filtered selector |
| 597 | TrafficSelector selector = fwd.selector(); |
| 598 | EthCriterion ethCriterion = (EthCriterion) selector |
| 599 | .getCriterion(Criterion.Type.ETH_DST); |
| 600 | VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) selector |
| 601 | .getCriterion(Criterion.Type.VLAN_VID); |
| 602 | |
| 603 | if (vlanIdCriterion == null) { |
| 604 | log.warn("Forwarding objective for bridging requires vlan. Not " |
| 605 | + "installing fwd:{} in dev:{}", fwd.id(), deviceId); |
| 606 | fail(fwd, ObjectiveError.BADPARAMS); |
| 607 | return Collections.emptySet(); |
| 608 | } |
| 609 | |
| 610 | TrafficSelector.Builder filteredSelectorBuilder = |
| 611 | DefaultTrafficSelector.builder(); |
| 612 | // Do not match MacAddress for subnet broadcast entry |
Charles Chan | d05f54b | 2017-02-13 11:56:54 -0800 | [diff] [blame] | 613 | if (!ethCriterion.mac().equals(NONE) && !ethCriterion.mac().equals(BROADCAST)) { |
Charles Chan | 1e492d3 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 614 | filteredSelectorBuilder.matchEthDst(ethCriterion.mac()); |
| 615 | log.debug("processing L2 forwarding objective:{} -> next:{} in dev:{}", |
| 616 | fwd.id(), fwd.nextId(), deviceId); |
| 617 | } else { |
| 618 | log.debug("processing L2 Broadcast forwarding objective:{} -> next:{} " |
| 619 | + "in dev:{} for vlan:{}", |
| 620 | fwd.id(), fwd.nextId(), deviceId, vlanIdCriterion.vlanId()); |
| 621 | } |
| 622 | filteredSelectorBuilder.matchVlanId(vlanIdCriterion.vlanId()); |
| 623 | TrafficSelector filteredSelector = filteredSelectorBuilder.build(); |
| 624 | |
| 625 | if (fwd.treatment() != null) { |
| 626 | log.warn("Ignoring traffic treatment in fwd rule {} meant for L2 table" |
| 627 | + "for dev:{}. Expecting only nextId", fwd.id(), deviceId); |
| 628 | } |
| 629 | |
| 630 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 631 | if (fwd.nextId() != null) { |
| 632 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
| 633 | if (next != null) { |
| 634 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 635 | // we only need the top level group's key to point the flow to it |
| 636 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 637 | if (group != null) { |
| 638 | treatmentBuilder.deferred().group(group.id()); |
| 639 | } else { |
| 640 | log.warn("Group with key:{} for next-id:{} not found in dev:{}", |
| 641 | gkeys.get(0).peekFirst(), fwd.nextId(), deviceId); |
| 642 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 643 | return Collections.emptySet(); |
| 644 | } |
| 645 | } |
| 646 | } |
| 647 | treatmentBuilder.immediate().transition(ACL_TABLE); |
| 648 | TrafficTreatment filteredTreatment = treatmentBuilder.build(); |
| 649 | |
| 650 | // Build bridging table entries |
| 651 | FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder(); |
| 652 | flowRuleBuilder.fromApp(fwd.appId()) |
| 653 | .withPriority(fwd.priority()) |
| 654 | .forDevice(deviceId) |
| 655 | .withSelector(filteredSelector) |
| 656 | .withTreatment(filteredTreatment) |
| 657 | .forTable(BRIDGING_TABLE); |
| 658 | if (fwd.permanent()) { |
| 659 | flowRuleBuilder.makePermanent(); |
| 660 | } else { |
| 661 | flowRuleBuilder.makeTemporary(fwd.timeout()); |
| 662 | } |
| 663 | rules.add(flowRuleBuilder.build()); |
| 664 | return rules; |
| 665 | } |
| 666 | |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 667 | /* |
| 668 | * In the OF-DPA 2.0 pipeline, versatile forwarding objectives go to the |
| 669 | * ACL table. Because we pop off vlan tags in TMAC table, |
| 670 | * we need to avoid matching on vlans in the ACL table. |
| 671 | */ |
| 672 | @Override |
| 673 | protected Collection<FlowRule> processVersatile(ForwardingObjective fwd) { |
| 674 | log.info("Processing versatile forwarding objective"); |
| 675 | |
| 676 | EthTypeCriterion ethType = |
| 677 | (EthTypeCriterion) fwd.selector().getCriterion(Criterion.Type.ETH_TYPE); |
| 678 | if (ethType == null) { |
| 679 | log.error("Versatile forwarding objective must include ethType"); |
| 680 | fail(fwd, ObjectiveError.BADPARAMS); |
| 681 | return Collections.emptySet(); |
| 682 | } |
| 683 | if (fwd.nextId() == null && fwd.treatment() == null) { |
| 684 | log.error("Forwarding objective {} from {} must contain " |
| 685 | + "nextId or Treatment", fwd.selector(), fwd.appId()); |
| 686 | return Collections.emptySet(); |
| 687 | } |
| 688 | |
| 689 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 690 | fwd.selector().criteria().forEach(criterion -> { |
| 691 | if (criterion instanceof VlanIdCriterion) { |
| 692 | // avoid matching on vlans |
| 693 | return; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 694 | } else if (criterion instanceof Icmpv6TypeCriterion || |
| 695 | criterion instanceof Icmpv6CodeCriterion) { |
| 696 | /* |
| 697 | * We silenty discard these criterions, our current |
| 698 | * OFDPA platform does not support these matches on |
| 699 | * the ACL table. |
| 700 | */ |
| 701 | log.warn("ICMPv6 Type and ICMPv6 Code are not supported"); |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 702 | } else { |
| 703 | sbuilder.add(criterion); |
| 704 | } |
| 705 | }); |
| 706 | |
| 707 | // XXX driver does not currently do type checking as per Tables 65-67 in |
| 708 | // OFDPA 2.0 spec. The only allowed treatment is a punt to the controller. |
| 709 | TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder(); |
| 710 | if (fwd.treatment() != null) { |
| 711 | for (Instruction ins : fwd.treatment().allInstructions()) { |
| 712 | if (ins instanceof OutputInstruction) { |
| 713 | OutputInstruction o = (OutputInstruction) ins; |
| 714 | if (o.port() == PortNumber.CONTROLLER) { |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 715 | ttBuilder.transition(PUNT_TABLE); |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 716 | } else { |
| 717 | log.warn("Only allowed treatments in versatile forwarding " |
| 718 | + "objectives are punts to the controller"); |
| 719 | } |
| 720 | } else { |
| 721 | log.warn("Cannot process instruction in versatile fwd {}", ins); |
| 722 | } |
| 723 | } |
Charles Chan | 2df0e8a | 2017-01-09 11:45:08 -0800 | [diff] [blame] | 724 | if (fwd.treatment().clearedDeferred()) { |
| 725 | ttBuilder.wipeDeferred(); |
| 726 | } |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 727 | } |
| 728 | if (fwd.nextId() != null) { |
| 729 | // overide case |
| 730 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
| 731 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 732 | // we only need the top level group's key to point the flow to it |
| 733 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 734 | if (group == null) { |
| 735 | log.warn("Group with key:{} for next-id:{} not found in dev:{}", |
| 736 | gkeys.get(0).peekFirst(), fwd.nextId(), deviceId); |
| 737 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 738 | return Collections.emptySet(); |
| 739 | } |
| 740 | ttBuilder.deferred().group(group.id()); |
| 741 | } |
| 742 | |
| 743 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
| 744 | .fromApp(fwd.appId()) |
| 745 | .withPriority(fwd.priority()) |
| 746 | .forDevice(deviceId) |
| 747 | .withSelector(sbuilder.build()) |
| 748 | .withTreatment(ttBuilder.build()) |
| 749 | .makePermanent() |
| 750 | .forTable(ACL_TABLE); |
| 751 | return Collections.singletonList(ruleBuilder.build()); |
| 752 | } |
| 753 | |
| 754 | /* |
| 755 | * Cpqd emulation requires table-miss-entries in forwarding tables. |
| 756 | * Real OFDPA does not require these rules as they are put in by default. |
| 757 | * |
| 758 | * (non-Javadoc) |
| 759 | * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#initializePipeline() |
| 760 | */ |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 761 | @Override |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 762 | protected void initializePipeline() { |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 763 | initTableMiss(PORT_TABLE, VLAN_TABLE, null); |
| 764 | initTableMiss(VLAN_TABLE, ACL_TABLE, null); |
| 765 | initTableMiss(TMAC_TABLE, BRIDGING_TABLE, null); |
| 766 | initTableMiss(UNICAST_ROUTING_TABLE, ACL_TABLE, null); |
| 767 | initTableMiss(MULTICAST_ROUTING_TABLE, ACL_TABLE, null); |
| 768 | initTableMiss(MPLS_TABLE_0, MPLS_TABLE_1, null); |
| 769 | initTableMiss(MPLS_TABLE_1, ACL_TABLE, null); |
| 770 | initTableMiss(BRIDGING_TABLE, ACL_TABLE, null); |
| 771 | initTableMiss(ACL_TABLE, -1, null); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 772 | |
| 773 | if (supportPuntGroup()) { |
| 774 | initTableMiss(PUNT_TABLE, -1, |
| 775 | DefaultTrafficTreatment.builder().punt().build()); |
| 776 | initPopVlanPuntGroup(); |
| 777 | } else { |
| 778 | initTableMiss(PUNT_TABLE, -1, |
| 779 | DefaultTrafficTreatment.builder().popVlan().punt().build()); |
| 780 | } |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 781 | } |
| 782 | |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 783 | /** |
| 784 | * Install table-miss flow entry. |
| 785 | * |
| 786 | * If treatment exists, use it directly. |
| 787 | * Else if treatment does not exist but nextTable > 0, transit to next table. |
| 788 | * Else apply empty treatment. |
| 789 | * |
| 790 | * @param thisTable this table ID |
| 791 | * @param nextTable next table ID |
| 792 | * @param treatment traffic treatment to apply. |
| 793 | */ |
| 794 | private void initTableMiss(int thisTable, int nextTable, TrafficTreatment treatment) { |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 795 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 796 | TrafficSelector selector = DefaultTrafficSelector.builder().build(); |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 797 | |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 798 | if (treatment == null) { |
| 799 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 800 | if (nextTable > 0) { |
| 801 | tBuilder.transition(nextTable); |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 802 | } |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 803 | treatment = tBuilder.build(); |
| 804 | } |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 805 | |
Charles Chan | b750439 | 2017-02-10 12:51:04 -0800 | [diff] [blame] | 806 | FlowRule rule = DefaultFlowRule.builder() |
| 807 | .forDevice(deviceId) |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 808 | .withSelector(selector) |
| 809 | .withTreatment(treatment) |
Charles Chan | b750439 | 2017-02-10 12:51:04 -0800 | [diff] [blame] | 810 | .withPriority(LOWEST_PRIORITY) |
| 811 | .fromApp(driverId) |
| 812 | .makePermanent() |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 813 | .forTable(thisTable).build(); |
Charles Chan | b750439 | 2017-02-10 12:51:04 -0800 | [diff] [blame] | 814 | ops = ops.add(rule); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 815 | |
| 816 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 817 | @Override |
| 818 | public void onSuccess(FlowRuleOperations ops) { |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 819 | log.info("Initialized table {} on {}", thisTable, deviceId); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 820 | } |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 821 | @Override |
| 822 | public void onError(FlowRuleOperations ops) { |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 823 | log.warn("Failed to initialize table {} on {}", thisTable, deviceId); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 824 | } |
| 825 | })); |
| 826 | } |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 827 | |
| 828 | /** |
| 829 | * Builds a indirect group contains pop_vlan and punt actions. |
| 830 | * <p> |
| 831 | * Using group instead of immediate action to ensure that |
| 832 | * the copy of packet on the data plane is not affected by the pop vlan action. |
| 833 | */ |
| 834 | private void initPopVlanPuntGroup() { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 835 | GroupKey groupKey = popVlanPuntGroupKey(); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 836 | TrafficTreatment bucketTreatment = DefaultTrafficTreatment.builder() |
| 837 | .popVlan().punt().build(); |
| 838 | GroupBucket bucket = |
| 839 | DefaultGroupBucket.createIndirectGroupBucket(bucketTreatment); |
| 840 | GroupDescription groupDesc = |
| 841 | new DefaultGroupDescription( |
| 842 | deviceId, |
| 843 | GroupDescription.Type.INDIRECT, |
| 844 | new GroupBuckets(Collections.singletonList(bucket)), |
| 845 | groupKey, |
| 846 | POP_VLAN_PUNT_GROUP_ID, |
| 847 | driverId); |
| 848 | groupService.addGroup(groupDesc); |
| 849 | |
| 850 | log.info("Initialized pop vlan punt group on {}", deviceId); |
| 851 | } |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 852 | |
| 853 | /** |
| 854 | * Generates group key for a static indirect group that pop vlan and punt to |
| 855 | * controller. |
| 856 | * |
| 857 | * @return the group key of the indirect table |
| 858 | */ |
| 859 | private GroupKey popVlanPuntGroupKey() { |
| 860 | int hash = POP_VLAN_PUNT_GROUP_ID | (Objects.hash(deviceId) & FOUR_BIT_MASK); |
| 861 | return new DefaultGroupKey(Ofdpa2Pipeline.appKryo.serialize(hash)); |
| 862 | } |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 863 | } |