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