blob: 2e714273aa73834c090328e3c3a8ef925adcb072 [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Thomas Vachuska58de4162015-09-10 16:15:33 -07003 *
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 Tsengef19de12017-04-24 11:33:05 -070016package org.onosproject.driver.pipeline.ofdpa;
Saurav Das558afec2015-05-31 17:12:48 -070017
Charles Chan5270ed02016-01-30 23:22:37 -080018import com.google.common.collect.ImmutableList;
Charles Chan5b9df8d2016-03-28 22:21:40 -070019import com.google.common.collect.ImmutableSet;
Saurav Das8a0732e2015-11-20 15:27:53 -080020import org.onlab.packet.Ethernet;
Julia Ferguson65428c32017-08-10 18:15:24 +000021import org.onlab.packet.IpAddress;
Flavio Castroe10fa242016-01-15 12:43:51 -080022import org.onlab.packet.IpPrefix;
Charles Chan45b69ab2018-03-02 15:41:41 -080023import org.onlab.packet.MacAddress;
Saurav Das2857f382015-11-03 14:39:27 -080024import org.onlab.packet.VlanId;
25import org.onosproject.core.ApplicationId;
Yi Tsengfa394de2017-02-01 11:26:40 -080026import org.onosproject.core.GroupId;
Saurav Das2857f382015-11-03 14:39:27 -080027import org.onosproject.net.Port;
28import org.onosproject.net.PortNumber;
Saurav Das8a0732e2015-11-20 15:27:53 -080029import org.onosproject.net.behaviour.NextGroup;
Charles Chan425854b2016-04-11 15:32:12 -070030import org.onosproject.net.behaviour.PipelinerContext;
Saurav Das558afec2015-05-31 17:12:48 -070031import org.onosproject.net.flow.DefaultFlowRule;
32import org.onosproject.net.flow.DefaultTrafficSelector;
33import org.onosproject.net.flow.DefaultTrafficTreatment;
34import org.onosproject.net.flow.FlowRule;
35import org.onosproject.net.flow.FlowRuleOperations;
36import org.onosproject.net.flow.FlowRuleOperationsContext;
37import org.onosproject.net.flow.TrafficSelector;
38import org.onosproject.net.flow.TrafficTreatment;
Saurav Das4ce45962015-11-24 23:21:05 -080039import org.onosproject.net.flow.criteria.Criteria;
Saurav Das8a0732e2015-11-20 15:27:53 -080040import org.onosproject.net.flow.criteria.Criterion;
Saurav Das4ce45962015-11-24 23:21:05 -080041import org.onosproject.net.flow.criteria.EthCriterion;
Saurav Das8a0732e2015-11-20 15:27:53 -080042import org.onosproject.net.flow.criteria.EthTypeCriterion;
43import org.onosproject.net.flow.criteria.IPCriterion;
Pier Ventree0ae7a32016-11-23 09:57:42 -080044import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion;
45import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion;
Saurav Das8a0732e2015-11-20 15:27:53 -080046import org.onosproject.net.flow.criteria.MplsBosCriterion;
47import org.onosproject.net.flow.criteria.MplsCriterion;
Saurav Das2857f382015-11-03 14:39:27 -080048import org.onosproject.net.flow.criteria.PortCriterion;
49import org.onosproject.net.flow.criteria.VlanIdCriterion;
Saurav Das8a0732e2015-11-20 15:27:53 -080050import org.onosproject.net.flow.instructions.Instruction;
Saurav Das52025962016-01-28 22:30:01 -080051import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
Charles Chan40132b32017-01-22 00:19:37 -080052import org.onosproject.net.flow.instructions.L3ModificationInstruction;
Saurav Das8a0732e2015-11-20 15:27:53 -080053import org.onosproject.net.flowobjective.ForwardingObjective;
54import org.onosproject.net.flowobjective.ObjectiveError;
Charles Chan0f43e472017-02-14 14:00:16 -080055import org.onosproject.net.group.DefaultGroupBucket;
56import org.onosproject.net.group.DefaultGroupDescription;
57import org.onosproject.net.group.DefaultGroupKey;
Saurav Das8a0732e2015-11-20 15:27:53 -080058import org.onosproject.net.group.Group;
Charles Chan0f43e472017-02-14 14:00:16 -080059import org.onosproject.net.group.GroupBucket;
60import org.onosproject.net.group.GroupBuckets;
61import org.onosproject.net.group.GroupDescription;
Saurav Das8a0732e2015-11-20 15:27:53 -080062import org.onosproject.net.group.GroupKey;
Charles Chanf57a8252016-06-29 19:12:37 -070063import org.onosproject.net.packet.PacketPriority;
Saurav Das558afec2015-05-31 17:12:48 -070064import org.slf4j.Logger;
65
Jonathan Hart855179c2016-04-26 07:40:04 -070066import java.util.ArrayList;
67import java.util.Collection;
68import java.util.Collections;
69import java.util.Deque;
70import java.util.List;
Charles Chan0f43e472017-02-14 14:00:16 -080071import java.util.Objects;
Jonathan Hart855179c2016-04-26 07:40:04 -070072
Pier Ventree0ae7a32016-11-23 09:57:42 -080073import static org.onlab.packet.IPv6.PROTOCOL_ICMP6;
Charles Chand05f54b2017-02-13 11:56:54 -080074import static org.onlab.packet.MacAddress.BROADCAST;
75import static org.onlab.packet.MacAddress.NONE;
Yi Tsengef19de12017-04-24 11:33:05 -070076import static org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.*;
Jonathan Hart855179c2016-04-26 07:40:04 -070077import static org.slf4j.LoggerFactory.getLogger;
78
Saurav Das558afec2015-05-31 17:12:48 -070079
80/**
Charles Chan40132b32017-01-22 00:19:37 -080081 * Driver for software switch emulation of the OFDPA pipeline.
Saurav Das52025962016-01-28 22:30:01 -080082 * 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 Das558afec2015-05-31 17:12:48 -070087 */
Charles Chan361154b2016-03-24 10:23:39 -070088public class CpqdOfdpa2Pipeline extends Ofdpa2Pipeline {
Saurav Das558afec2015-05-31 17:12:48 -070089
90 private final Logger log = getLogger(getClass());
91
Charles Chan40132b32017-01-22 00:19:37 -080092 /**
Charles Chan0f43e472017-02-14 14:00:16 -080093 * 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 Chan053b1cb2017-03-22 16:56:35 -0700110 @Override
111 protected boolean requireVlanExtensions() {
112 return false;
113 }
114
Charles Chan0f43e472017-02-14 14:00:16 -0800115 /**
Charles Chan40132b32017-01-22 00:19:37 -0800116 * 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 Chan0f43e472017-02-14 14:00:16 -0800124 /**
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 Chan425854b2016-04-11 15:32:12 -0700146 @Override
Charles Chan40132b32017-01-22 00:19:37 -0800147 protected void initDriverId() {
Charles Chan425854b2016-04-11 15:32:12 -0700148 driverId = coreService.registerApplication(
149 "org.onosproject.driver.CpqdOfdpa2Pipeline");
Charles Chan40132b32017-01-22 00:19:37 -0800150 }
Charles Chan425854b2016-04-11 15:32:12 -0700151
Charles Chan40132b32017-01-22 00:19:37 -0800152 @Override
153 protected void initGroupHander(PipelinerContext context) {
154 groupHandler = new CpqdOfdpa2GroupHandler();
155 groupHandler.init(deviceId, context);
Charles Chan425854b2016-04-11 15:32:12 -0700156 }
157
Saurav Das4ce45962015-11-24 23:21:05 -0800158 /*
Saurav Das1ce0a7b2016-10-21 14:06:29 -0700159 * Cpqd emulation does not require the non OF-standard rules for
160 * matching untagged packets that ofdpa uses.
Saurav Das4ce45962015-11-24 23:21:05 -0800161 *
162 * (non-Javadoc)
163 * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#processVlanIdFilter
164 */
Saurav Das558afec2015-05-31 17:12:48 -0700165 @Override
Charles Chan66291502018-03-02 16:43:28 -0800166 protected List<List<FlowRule>> processVlanIdFilter(PortCriterion portCriterion,
Saurav Das2857f382015-11-03 14:39:27 -0800167 VlanIdCriterion vidCriterion,
168 VlanId assignedVlan,
169 ApplicationId applicationId) {
Charles Chan79769232016-07-05 16:34:39 -0700170 List<FlowRule> rules = new ArrayList<>();
Saurav Das2857f382015-11-03 14:39:27 -0800171 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
172 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
173 selector.matchVlanId(vidCriterion.vlanId());
Saurav Das4f980082015-11-05 13:39:15 -0800174 treatment.transition(TMAC_TABLE);
175
Saurav Das2857f382015-11-03 14:39:27 -0800176 if (vidCriterion.vlanId() == VlanId.NONE) {
177 // untagged packets are assigned vlans
178 treatment.pushVlan().setVlanId(assignedVlan);
Piere5bff482018-03-07 11:42:50 +0100179 } else if (!vidCriterion.vlanId().equals(assignedVlan)) {
180 // Rewrite with assigned vlans
181 treatment.setVlanId(assignedVlan);
Saurav Das2857f382015-11-03 14:39:27 -0800182 }
Saurav Das2857f382015-11-03 14:39:27 -0800183
184 // ofdpa cannot match on ALL portnumber, so we need to use separate
185 // rules for each port.
Charles Chan50d900c2018-03-02 13:26:22 -0800186 List<PortNumber> portnums = new ArrayList<>();
Charles Chan70ce68e2018-05-10 11:32:56 -0700187 if (portCriterion != null && portCriterion.port() == PortNumber.ALL) {
Saurav Das2857f382015-11-03 14:39:27 -0800188 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 Das4f980082015-11-05 13:39:15 -0800196
Saurav Das2857f382015-11-03 14:39:27 -0800197 for (PortNumber pnum : portnums) {
Charles Chan0f43e472017-02-14 14:00:16 -0800198 // NOTE: Emulating OFDPA behavior by popping off internal assigned
199 // VLAN before sending to controller
200 if (supportPuntGroup() && vidCriterion.vlanId() == VlanId.NONE) {
Yi Tsengef19de12017-04-24 11:33:05 -0700201 GroupKey groupKey = popVlanPuntGroupKey();
Charles Chan0f43e472017-02-14 14:00:16 -0800202 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 Das4f980082015-11-05 13:39:15 -0800211 // create rest of flowrule
Saurav Das2857f382015-11-03 14:39:27 -0800212 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 Chanf57a8252016-06-29 19:12:37 -0700223
Charles Chan66291502018-03-02 16:43:28 -0800224 return ImmutableList.of(rules);
Saurav Das2857f382015-11-03 14:39:27 -0800225 }
226
Pier Ventree0ae7a32016-11-23 09:57:42 -0800227 /**
Charles Chan0f43e472017-02-14 14:00:16 -0800228 * 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 Tsengfa394de2017-02-01 11:26:40 -0800240 .group(new GroupId(POP_VLAN_PUNT_GROUP_ID));
Charles Chan0f43e472017-02-14 14:00:16 -0800241
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 Ventree0ae7a32016-11-23 09:57:42 -0800253 * Builds a punt to the controller rule for the arp protocol.
Charles Chan0f43e472017-02-14 14:00:16 -0800254 * <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 Ventree0ae7a32016-11-23 09:57:42 -0800259 *
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 Chan0f43e472017-02-14 14:00:16 -0800284 * <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 Ventree0ae7a32016-11-23 09:57:42 -0800289 *
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 Das4ce45962015-11-24 23:21:05 -0800313 /*
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 Das8a0732e2015-11-20 15:27:53 -0800320 @Override
Charles Chan66291502018-03-02 16:43:28 -0800321 protected List<List<FlowRule>> processEthDstFilter(PortCriterion portCriterion,
Saurav Das4ce45962015-11-24 23:21:05 -0800322 EthCriterion ethCriterion,
323 VlanIdCriterion vidCriterion,
324 VlanId assignedVlan,
Charles Chan45b69ab2018-03-02 15:41:41 -0800325 MacAddress unicastMac,
Saurav Das4ce45962015-11-24 23:21:05 -0800326 ApplicationId applicationId) {
Charles Chan5270ed02016-01-30 23:22:37 -0800327 // 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 Chan5b9df8d2016-03-28 22:21:40 -0700332 // Multicast MAC
333 if (ethCriterion.mask() != null) {
Charles Chan45b69ab2018-03-02 15:41:41 -0800334 return processMcastEthDstFilter(ethCriterion, assignedVlan, unicastMac, applicationId);
Charles Chan5b9df8d2016-03-28 22:21:40 -0700335 }
336
Saurav Das4ce45962015-11-24 23:21:05 -0800337 //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 Chan50d900c2018-03-02 13:26:22 -0800343 List<PortNumber> portnums = new ArrayList<>();
Ray Milkey74e59132018-01-17 15:24:52 -0800344 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 Das4ce45962015-11-24 23:21:05 -0800350 }
Ray Milkey74e59132018-01-17 15:24:52 -0800351 } else {
352 portnums.add(portCriterion.port());
Saurav Das4ce45962015-11-24 23:21:05 -0800353 }
Saurav Das4ce45962015-11-24 23:21:05 -0800354 }
355
Charles Chan50d900c2018-03-02 13:26:22 -0800356 List<FlowRule> rules = new ArrayList<>();
Saurav Das4ce45962015-11-24 23:21:05 -0800357 for (PortNumber pnum : portnums) {
Charles Chan0f43e472017-02-14 14:00:16 -0800358 // TMAC rules for unicast IP packets
Saurav Das4ce45962015-11-24 23:21:05 -0800359 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 Chan0f43e472017-02-14 14:00:16 -0800365 if (!supportTaggedMpls()) {
366 treatment.popVlan();
367 }
Saurav Das4ce45962015-11-24 23:21:05 -0800368 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 Chan0f43e472017-02-14 14:00:16 -0800378
379 // TMAC rules for MPLS packets
Saurav Das4ce45962015-11-24 23:21:05 -0800380 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 Chan0f43e472017-02-14 14:00:16 -0800386 if (!supportTaggedMpls()) {
387 treatment.popVlan();
388 }
Saurav Das4ce45962015-11-24 23:21:05 -0800389 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 Chan0f43e472017-02-14 14:00:16 -0800399
400 // TMAC rules for IPv6 packets
Pier Ventree0ae7a32016-11-23 09:57:42 -0800401 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 Chan0f43e472017-02-14 14:00:16 -0800407 if (!supportTaggedMpls()) {
408 treatment.popVlan();
409 }
Pier Ventree0ae7a32016-11-23 09:57:42 -0800410 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 Das4ce45962015-11-24 23:21:05 -0800420 }
Charles Chan66291502018-03-02 16:43:28 -0800421 return ImmutableList.of(rules);
Saurav Das4ce45962015-11-24 23:21:05 -0800422 }
423
Charles Chan5270ed02016-01-30 23:22:37 -0800424 @Override
Charles Chan66291502018-03-02 16:43:28 -0800425 protected List<List<FlowRule>> processEthDstOnlyFilter(EthCriterion ethCriterion,
Yi Tsengef19de12017-04-24 11:33:05 -0700426 ApplicationId applicationId) {
Charles Chan5270ed02016-01-30 23:22:37 -0800427 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
428 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
429 selector.matchEthType(Ethernet.TYPE_IPV4);
430 selector.matchEthDst(ethCriterion.mac());
Charles Chan0f43e472017-02-14 14:00:16 -0800431 if (!supportTaggedMpls()) {
432 treatment.popVlan();
433 }
Charles Chan5270ed02016-01-30 23:22:37 -0800434 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 Chan66291502018-03-02 16:43:28 -0800443 return ImmutableList.of(ImmutableList.of(rule));
Charles Chan5270ed02016-01-30 23:22:37 -0800444 }
445
Saurav Das4ce45962015-11-24 23:21:05 -0800446 /*
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 Das8a0732e2015-11-20 15:27:53 -0800454 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 Ventree0ae7a32016-11-23 09:57:42 -0800459 (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST) &&
460 (ethType.ethType().toShort() != Ethernet.TYPE_IPV6)) {
Saurav Das4ce45962015-11-24 23:21:05 -0800461 log.warn("processSpecific: Unsupported forwarding objective criteria"
462 + "ethType:{} in dev:{}", ethType, deviceId);
Saurav Das8a0732e2015-11-20 15:27:53 -0800463 fail(fwd, ObjectiveError.UNSUPPORTED);
464 return Collections.emptySet();
465 }
Flavio Castroe10fa242016-01-15 12:43:51 -0800466 boolean defaultRule = false;
Charles Chan50d900c2018-03-02 13:26:22 -0800467 int forTableId;
Saurav Das8a0732e2015-11-20 15:27:53 -0800468 TrafficSelector.Builder filteredSelector = DefaultTrafficSelector.builder();
Flavio Castroe10fa242016-01-15 12:43:51 -0800469 TrafficSelector.Builder complementarySelector = DefaultTrafficSelector.builder();
470
Saurav Das8a0732e2015-11-20 15:27:53 -0800471 if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
Flavio Castroe10fa242016-01-15 12:43:51 -0800472 IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip();
Charles Chan5b9df8d2016-03-28 22:21:40 -0700473 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 Castroe10fa242016-01-15 12:43:51 -0800490 } else {
Charles Chanf9e98652016-09-07 16:54:23 -0700491 if (ipv4Dst.prefixLength() == 0) {
492 // The entire IPV4_DST field is wildcarded intentionally
493 filteredSelector.matchEthType(Ethernet.TYPE_IPV4);
Charles Chan5b9df8d2016-03-28 22:21:40 -0700494 } else {
Charles Chanf9e98652016-09-07 16:54:23 -0700495 filteredSelector.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ipv4Dst);
Charles Chan5b9df8d2016-03-28 22:21:40 -0700496 }
497 forTableId = UNICAST_ROUTING_TABLE;
498 log.debug("processing IPv4 unicast specific forwarding objective {} -> next:{}"
499 + " in dev:{}", fwd.id(), fwd.nextId(), deviceId);
Flavio Castroe10fa242016-01-15 12:43:51 -0800500 }
Pier Ventree0ae7a32016-11-23 09:57:42 -0800501 } else if (ethType.ethType().toShort() == Ethernet.TYPE_IPV6) {
Julia Ferguson65428c32017-08-10 18:15:24 +0000502 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 Ventree0ae7a32016-11-23 09:57:42 -0800525 }
Saurav Das8a0732e2015-11-20 15:27:53 -0800526 } 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 Das4ce45962015-11-24 23:21:05 -0800537 log.debug("processing MPLS specific forwarding objective {} -> next:{}"
538 + " in dev {}", fwd.id(), fwd.nextId(), deviceId);
Saurav Das8a0732e2015-11-20 15:27:53 -0800539 }
540
541 TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
542 if (fwd.treatment() != null) {
543 for (Instruction i : fwd.treatment().allInstructions()) {
Charles Chan40132b32017-01-22 00:19:37 -0800544 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 Chan7d10b162015-12-07 18:54:45 -0800551 /*
552 * NOTE: OF-DPA does not support immediate instruction in
553 * L3 unicast and MPLS table.
554 */
555 tb.deferred().add(i);
Saurav Das8a0732e2015-11-20 15:27:53 -0800556 }
557 }
558
559 if (fwd.nextId() != null) {
Saurav Das423fe2b2015-12-04 10:52:59 -0800560 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 Das1ce0a7b2016-10-21 14:06:29 -0700566 log.warn("Group with key:{} for next-id:{} not found in dev:{}",
567 gkeys.get(0).peekFirst(), fwd.nextId(), deviceId);
Saurav Das423fe2b2015-12-04 10:52:59 -0800568 fail(fwd, ObjectiveError.GROUPMISSING);
569 return Collections.emptySet();
570 }
571 tb.deferred().group(group.id());
Saurav Das8a0732e2015-11-20 15:27:53 -0800572 }
Saurav Das8a0732e2015-11-20 15:27:53 -0800573 }
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 Castroe10fa242016-01-15 12:43:51 -0800588 Collection<FlowRule> flowRuleCollection = new ArrayList<>();
589 flowRuleCollection.add(ruleBuilder.build());
590 if (defaultRule) {
Pier Ventree0ae7a32016-11-23 09:57:42 -0800591 flowRuleCollection.add(
592 defaultRoute(fwd, complementarySelector, forTableId, tb)
593 );
Flavio Castroe10fa242016-01-15 12:43:51 -0800594 log.debug("Default rule 0.0.0.0/0 is being installed two rules");
595 }
Flavio Castroe10fa242016-01-15 12:43:51 -0800596 return flowRuleCollection;
Saurav Das8a0732e2015-11-20 15:27:53 -0800597 }
598
Charles Chan1e492d32016-01-30 23:22:37 -0800599 @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 Chand05f54b2017-02-13 11:56:54 -0800620 if (!ethCriterion.mac().equals(NONE) && !ethCriterion.mac().equals(BROADCAST)) {
Charles Chan1e492d32016-01-30 23:22:37 -0800621 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 Das52025962016-01-28 22:30:01 -0800674 /*
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 Ventree0ae7a32016-11-23 09:57:42 -0800701 } 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 Das52025962016-01-28 22:30:01 -0800709 } 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 Chan0f43e472017-02-14 14:00:16 -0800722 ttBuilder.transition(PUNT_TABLE);
Saurav Das52025962016-01-28 22:30:01 -0800723 } 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 Chan2df0e8a2017-01-09 11:45:08 -0800731 if (fwd.treatment().clearedDeferred()) {
732 ttBuilder.wipeDeferred();
733 }
Saurav Das52025962016-01-28 22:30:01 -0800734 }
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 Das2857f382015-11-03 14:39:27 -0800768 @Override
Saurav Das558afec2015-05-31 17:12:48 -0700769 protected void initializePipeline() {
Charles Chanf6ec1532017-02-08 16:10:40 -0800770 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 Chan0f43e472017-02-14 14:00:16 -0800779
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 Das558afec2015-05-31 17:12:48 -0700788 }
789
Charles Chanf6ec1532017-02-08 16:10:40 -0800790 /**
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 Das558afec2015-05-31 17:12:48 -0700802 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
Charles Chanf6ec1532017-02-08 16:10:40 -0800803 TrafficSelector selector = DefaultTrafficSelector.builder().build();
Saurav Das558afec2015-05-31 17:12:48 -0700804
Charles Chanf6ec1532017-02-08 16:10:40 -0800805 if (treatment == null) {
806 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
807 if (nextTable > 0) {
808 tBuilder.transition(nextTable);
Saurav Das558afec2015-05-31 17:12:48 -0700809 }
Charles Chanf6ec1532017-02-08 16:10:40 -0800810 treatment = tBuilder.build();
811 }
Saurav Das558afec2015-05-31 17:12:48 -0700812
Charles Chanb7504392017-02-10 12:51:04 -0800813 FlowRule rule = DefaultFlowRule.builder()
814 .forDevice(deviceId)
Charles Chanf6ec1532017-02-08 16:10:40 -0800815 .withSelector(selector)
816 .withTreatment(treatment)
Charles Chanb7504392017-02-10 12:51:04 -0800817 .withPriority(LOWEST_PRIORITY)
818 .fromApp(driverId)
819 .makePermanent()
Charles Chanf6ec1532017-02-08 16:10:40 -0800820 .forTable(thisTable).build();
Charles Chanb7504392017-02-10 12:51:04 -0800821 ops = ops.add(rule);
Saurav Das2857f382015-11-03 14:39:27 -0800822
823 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
824 @Override
825 public void onSuccess(FlowRuleOperations ops) {
Charles Chanf6ec1532017-02-08 16:10:40 -0800826 log.info("Initialized table {} on {}", thisTable, deviceId);
Saurav Das2857f382015-11-03 14:39:27 -0800827 }
Saurav Das2857f382015-11-03 14:39:27 -0800828 @Override
829 public void onError(FlowRuleOperations ops) {
Charles Chanf6ec1532017-02-08 16:10:40 -0800830 log.warn("Failed to initialize table {} on {}", thisTable, deviceId);
Saurav Das2857f382015-11-03 14:39:27 -0800831 }
832 }));
833 }
Charles Chan0f43e472017-02-14 14:00:16 -0800834
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 Tsengef19de12017-04-24 11:33:05 -0700842 GroupKey groupKey = popVlanPuntGroupKey();
Charles Chan0f43e472017-02-14 14:00:16 -0800843 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 Tsengef19de12017-04-24 11:33:05 -0700859
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 Das558afec2015-05-31 17:12:48 -0700870}