blob: 9c22b372762ea40932b8d5facb61415fbdb82f95 [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 Fergusond8f145e2017-08-10 18:15:24 +000021import org.onlab.packet.IpAddress;
Flavio Castroe10fa242016-01-15 12:43:51 -080022import org.onlab.packet.IpPrefix;
Charles Chan3bb17c62018-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 Chan3aed59a2018-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);
179 }
Saurav Das2857f382015-11-03 14:39:27 -0800180
181 // ofdpa cannot match on ALL portnumber, so we need to use separate
182 // rules for each port.
Charles Chanc6e64bb2018-03-02 13:26:22 -0800183 List<PortNumber> portnums = new ArrayList<>();
Saurav Das2857f382015-11-03 14:39:27 -0800184 if (portCriterion.port() == PortNumber.ALL) {
185 for (Port port : deviceService.getPorts(deviceId)) {
186 if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) {
187 portnums.add(port.number());
188 }
189 }
190 } else {
191 portnums.add(portCriterion.port());
192 }
Saurav Das4f980082015-11-05 13:39:15 -0800193
Saurav Das2857f382015-11-03 14:39:27 -0800194 for (PortNumber pnum : portnums) {
Charles Chan0f43e472017-02-14 14:00:16 -0800195 // NOTE: Emulating OFDPA behavior by popping off internal assigned
196 // VLAN before sending to controller
197 if (supportPuntGroup() && vidCriterion.vlanId() == VlanId.NONE) {
Yi Tsengef19de12017-04-24 11:33:05 -0700198 GroupKey groupKey = popVlanPuntGroupKey();
Charles Chan0f43e472017-02-14 14:00:16 -0800199 Group group = groupService.getGroup(deviceId, groupKey);
200 if (group != null) {
201 rules.add(buildPuntTableRule(pnum, assignedVlan));
202 } else {
203 log.info("popVlanPuntGroup not found in dev:{}", deviceId);
204 return Collections.emptyList();
205 }
206 }
207
Saurav Das4f980082015-11-05 13:39:15 -0800208 // create rest of flowrule
Saurav Das2857f382015-11-03 14:39:27 -0800209 selector.matchInPort(pnum);
210 FlowRule rule = DefaultFlowRule.builder()
211 .forDevice(deviceId)
212 .withSelector(selector.build())
213 .withTreatment(treatment.build())
214 .withPriority(DEFAULT_PRIORITY)
215 .fromApp(applicationId)
216 .makePermanent()
217 .forTable(VLAN_TABLE).build();
218 rules.add(rule);
219 }
Charles Chanf57a8252016-06-29 19:12:37 -0700220
Charles Chan3aed59a2018-03-02 16:43:28 -0800221 return ImmutableList.of(rules);
Saurav Das2857f382015-11-03 14:39:27 -0800222 }
223
Pier Ventree0ae7a32016-11-23 09:57:42 -0800224 /**
Charles Chan0f43e472017-02-14 14:00:16 -0800225 * Creates punt table entry that matches IN_PORT and VLAN_VID and points to
226 * a group that pop vlan and punt.
227 *
228 * @param portNumber port number
229 * @param assignedVlan internally assigned vlan id
230 * @return punt table flow rule
231 */
232 private FlowRule buildPuntTableRule(PortNumber portNumber, VlanId assignedVlan) {
233 TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder()
234 .matchInPort(portNumber)
235 .matchVlanId(assignedVlan);
236 TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder()
Yi Tsengfa394de2017-02-01 11:26:40 -0800237 .group(new GroupId(POP_VLAN_PUNT_GROUP_ID));
Charles Chan0f43e472017-02-14 14:00:16 -0800238
239 return DefaultFlowRule.builder()
240 .forDevice(deviceId)
241 .withSelector(sbuilder.build())
242 .withTreatment(tbuilder.build())
243 .withPriority(PacketPriority.CONTROL.priorityValue())
244 .fromApp(driverId)
245 .makePermanent()
246 .forTable(PUNT_TABLE).build();
247 }
248
249 /**
Pier Ventree0ae7a32016-11-23 09:57:42 -0800250 * Builds a punt to the controller rule for the arp protocol.
Charles Chan0f43e472017-02-14 14:00:16 -0800251 * <p>
252 * NOTE: CpqD cannot punt correctly in group bucket. The current impl will
253 * pop VLAN before sending to controller disregarding whether
254 * it's an internally assigned VLAN or a natural VLAN.
255 * Therefore, trunk port is not supported in CpqD.
Pier Ventree0ae7a32016-11-23 09:57:42 -0800256 *
257 * @param assignedVlan the internal assigned vlan id
258 * @param applicationId the application id
259 * @return the punt flow rule for the arp
260 */
261 private FlowRule buildArpPunt(VlanId assignedVlan, ApplicationId applicationId) {
262 TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder()
263 .matchEthType(Ethernet.TYPE_ARP)
264 .matchVlanId(assignedVlan);
265 TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder()
266 .popVlan()
267 .punt();
268
269 return DefaultFlowRule.builder()
270 .forDevice(deviceId)
271 .withSelector(sbuilder.build())
272 .withTreatment(tbuilder.build())
273 .withPriority(PacketPriority.CONTROL.priorityValue() + 1)
274 .fromApp(applicationId)
275 .makePermanent()
276 .forTable(ACL_TABLE).build();
277 }
278
279 /**
280 * Builds a punt to the controller rule for the icmp v6 messages.
Charles Chan0f43e472017-02-14 14:00:16 -0800281 * <p>
282 * NOTE: CpqD cannot punt correctly in group bucket. The current impl will
283 * pop VLAN before sending to controller disregarding whether
284 * it's an internally assigned VLAN or a natural VLAN.
285 * Therefore, trunk port is not supported in CpqD.
Pier Ventree0ae7a32016-11-23 09:57:42 -0800286 *
287 * @param assignedVlan the internal assigned vlan id
288 * @param applicationId the application id
289 * @return the punt flow rule for the icmp v6 messages
290 */
291 private FlowRule buildIcmpV6Punt(VlanId assignedVlan, ApplicationId applicationId) {
292 TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder()
293 .matchVlanId(assignedVlan)
294 .matchEthType(Ethernet.TYPE_IPV6)
295 .matchIPProtocol(PROTOCOL_ICMP6);
296 TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder()
297 .popVlan()
298 .punt();
299
300 return DefaultFlowRule.builder()
301 .forDevice(deviceId)
302 .withSelector(sbuilder.build())
303 .withTreatment(tbuilder.build())
304 .withPriority(PacketPriority.CONTROL.priorityValue() + 1)
305 .fromApp(applicationId)
306 .makePermanent()
307 .forTable(ACL_TABLE).build();
308 }
309
Saurav Das4ce45962015-11-24 23:21:05 -0800310 /*
311 * Cpqd emulation does not handle vlan tags and mpls labels correctly.
312 * Workaround requires popping off the VLAN tags in the TMAC table.
313 *
314 * (non-Javadoc)
315 * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#processEthDstFilter
316 */
Saurav Das8a0732e2015-11-20 15:27:53 -0800317 @Override
Charles Chan3aed59a2018-03-02 16:43:28 -0800318 protected List<List<FlowRule>> processEthDstFilter(PortCriterion portCriterion,
Saurav Das4ce45962015-11-24 23:21:05 -0800319 EthCriterion ethCriterion,
320 VlanIdCriterion vidCriterion,
321 VlanId assignedVlan,
Charles Chan3bb17c62018-03-02 15:41:41 -0800322 MacAddress unicastMac,
Saurav Das4ce45962015-11-24 23:21:05 -0800323 ApplicationId applicationId) {
Charles Chan5270ed02016-01-30 23:22:37 -0800324 // Consider PortNumber.ANY as wildcard. Match ETH_DST only
325 if (portCriterion != null && portCriterion.port() == PortNumber.ANY) {
326 return processEthDstOnlyFilter(ethCriterion, applicationId);
327 }
328
Charles Chan5b9df8d2016-03-28 22:21:40 -0700329 // Multicast MAC
330 if (ethCriterion.mask() != null) {
Charles Chan3bb17c62018-03-02 15:41:41 -0800331 return processMcastEthDstFilter(ethCriterion, assignedVlan, unicastMac, applicationId);
Charles Chan5b9df8d2016-03-28 22:21:40 -0700332 }
333
Saurav Das4ce45962015-11-24 23:21:05 -0800334 //handling untagged packets via assigned VLAN
335 if (vidCriterion.vlanId() == VlanId.NONE) {
336 vidCriterion = (VlanIdCriterion) Criteria.matchVlanId(assignedVlan);
337 }
338 // ofdpa cannot match on ALL portnumber, so we need to use separate
339 // rules for each port.
Charles Chanc6e64bb2018-03-02 13:26:22 -0800340 List<PortNumber> portnums = new ArrayList<>();
Ray Milkeyfd4f8d32018-01-17 15:24:52 -0800341 if (portCriterion != null) {
342 if (portCriterion.port() == PortNumber.ALL) {
343 for (Port port : deviceService.getPorts(deviceId)) {
344 if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) {
345 portnums.add(port.number());
346 }
Saurav Das4ce45962015-11-24 23:21:05 -0800347 }
Ray Milkeyfd4f8d32018-01-17 15:24:52 -0800348 } else {
349 portnums.add(portCriterion.port());
Saurav Das4ce45962015-11-24 23:21:05 -0800350 }
Saurav Das4ce45962015-11-24 23:21:05 -0800351 }
352
Charles Chanc6e64bb2018-03-02 13:26:22 -0800353 List<FlowRule> rules = new ArrayList<>();
Saurav Das4ce45962015-11-24 23:21:05 -0800354 for (PortNumber pnum : portnums) {
Charles Chan0f43e472017-02-14 14:00:16 -0800355 // TMAC rules for unicast IP packets
Saurav Das4ce45962015-11-24 23:21:05 -0800356 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
357 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
358 selector.matchInPort(pnum);
359 selector.matchVlanId(vidCriterion.vlanId());
360 selector.matchEthType(Ethernet.TYPE_IPV4);
361 selector.matchEthDst(ethCriterion.mac());
Charles Chan0f43e472017-02-14 14:00:16 -0800362 if (!supportTaggedMpls()) {
363 treatment.popVlan();
364 }
Saurav Das4ce45962015-11-24 23:21:05 -0800365 treatment.transition(UNICAST_ROUTING_TABLE);
366 FlowRule rule = DefaultFlowRule.builder()
367 .forDevice(deviceId)
368 .withSelector(selector.build())
369 .withTreatment(treatment.build())
370 .withPriority(DEFAULT_PRIORITY)
371 .fromApp(applicationId)
372 .makePermanent()
373 .forTable(TMAC_TABLE).build();
374 rules.add(rule);
Charles Chan0f43e472017-02-14 14:00:16 -0800375
376 // TMAC rules for MPLS packets
Saurav Das4ce45962015-11-24 23:21:05 -0800377 selector = DefaultTrafficSelector.builder();
378 treatment = DefaultTrafficTreatment.builder();
379 selector.matchInPort(pnum);
380 selector.matchVlanId(vidCriterion.vlanId());
381 selector.matchEthType(Ethernet.MPLS_UNICAST);
382 selector.matchEthDst(ethCriterion.mac());
Charles Chan0f43e472017-02-14 14:00:16 -0800383 if (!supportTaggedMpls()) {
384 treatment.popVlan();
385 }
Saurav Das4ce45962015-11-24 23:21:05 -0800386 treatment.transition(MPLS_TABLE_0);
387 rule = DefaultFlowRule.builder()
388 .forDevice(deviceId)
389 .withSelector(selector.build())
390 .withTreatment(treatment.build())
391 .withPriority(DEFAULT_PRIORITY)
392 .fromApp(applicationId)
393 .makePermanent()
394 .forTable(TMAC_TABLE).build();
395 rules.add(rule);
Charles Chan0f43e472017-02-14 14:00:16 -0800396
397 // TMAC rules for IPv6 packets
Pier Ventree0ae7a32016-11-23 09:57:42 -0800398 selector = DefaultTrafficSelector.builder();
399 treatment = DefaultTrafficTreatment.builder();
400 selector.matchInPort(pnum);
401 selector.matchVlanId(vidCriterion.vlanId());
402 selector.matchEthType(Ethernet.TYPE_IPV6);
403 selector.matchEthDst(ethCriterion.mac());
Charles Chan0f43e472017-02-14 14:00:16 -0800404 if (!supportTaggedMpls()) {
405 treatment.popVlan();
406 }
Pier Ventree0ae7a32016-11-23 09:57:42 -0800407 treatment.transition(UNICAST_ROUTING_TABLE);
408 rule = DefaultFlowRule.builder()
409 .forDevice(deviceId)
410 .withSelector(selector.build())
411 .withTreatment(treatment.build())
412 .withPriority(DEFAULT_PRIORITY)
413 .fromApp(applicationId)
414 .makePermanent()
415 .forTable(TMAC_TABLE).build();
416 rules.add(rule);
Saurav Das4ce45962015-11-24 23:21:05 -0800417 }
Charles Chan3aed59a2018-03-02 16:43:28 -0800418 return ImmutableList.of(rules);
Saurav Das4ce45962015-11-24 23:21:05 -0800419 }
420
Charles Chan5270ed02016-01-30 23:22:37 -0800421 @Override
Charles Chan3aed59a2018-03-02 16:43:28 -0800422 protected List<List<FlowRule>> processEthDstOnlyFilter(EthCriterion ethCriterion,
Yi Tsengef19de12017-04-24 11:33:05 -0700423 ApplicationId applicationId) {
Charles Chan5270ed02016-01-30 23:22:37 -0800424 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
425 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
426 selector.matchEthType(Ethernet.TYPE_IPV4);
427 selector.matchEthDst(ethCriterion.mac());
Charles Chan0f43e472017-02-14 14:00:16 -0800428 if (!supportTaggedMpls()) {
429 treatment.popVlan();
430 }
Charles Chan5270ed02016-01-30 23:22:37 -0800431 treatment.transition(UNICAST_ROUTING_TABLE);
432 FlowRule rule = DefaultFlowRule.builder()
433 .forDevice(deviceId)
434 .withSelector(selector.build())
435 .withTreatment(treatment.build())
436 .withPriority(DEFAULT_PRIORITY)
437 .fromApp(applicationId)
438 .makePermanent()
439 .forTable(TMAC_TABLE).build();
Charles Chan3aed59a2018-03-02 16:43:28 -0800440 return ImmutableList.of(ImmutableList.of(rule));
Charles Chan5270ed02016-01-30 23:22:37 -0800441 }
442
Saurav Das4ce45962015-11-24 23:21:05 -0800443 /*
444 * Cpqd emulation allows MPLS ecmp.
445 *
446 * (non-Javadoc)
447 * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#processEthTypeSpecific
448 */
449 @Override
450 protected Collection<FlowRule> processEthTypeSpecific(ForwardingObjective fwd) {
Saurav Das8a0732e2015-11-20 15:27:53 -0800451 TrafficSelector selector = fwd.selector();
452 EthTypeCriterion ethType =
453 (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
454 if ((ethType == null) ||
455 (ethType.ethType().toShort() != Ethernet.TYPE_IPV4) &&
Pier Ventree0ae7a32016-11-23 09:57:42 -0800456 (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST) &&
457 (ethType.ethType().toShort() != Ethernet.TYPE_IPV6)) {
Saurav Das4ce45962015-11-24 23:21:05 -0800458 log.warn("processSpecific: Unsupported forwarding objective criteria"
459 + "ethType:{} in dev:{}", ethType, deviceId);
Saurav Das8a0732e2015-11-20 15:27:53 -0800460 fail(fwd, ObjectiveError.UNSUPPORTED);
461 return Collections.emptySet();
462 }
Flavio Castroe10fa242016-01-15 12:43:51 -0800463 boolean defaultRule = false;
Charles Chanc6e64bb2018-03-02 13:26:22 -0800464 int forTableId;
Saurav Das8a0732e2015-11-20 15:27:53 -0800465 TrafficSelector.Builder filteredSelector = DefaultTrafficSelector.builder();
Flavio Castroe10fa242016-01-15 12:43:51 -0800466 TrafficSelector.Builder complementarySelector = DefaultTrafficSelector.builder();
467
Saurav Das8a0732e2015-11-20 15:27:53 -0800468 if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
Flavio Castroe10fa242016-01-15 12:43:51 -0800469 IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip();
Charles Chan5b9df8d2016-03-28 22:21:40 -0700470 if (ipv4Dst.isMulticast()) {
471 if (ipv4Dst.prefixLength() != 32) {
472 log.warn("Multicast specific forwarding objective can only be /32");
473 fail(fwd, ObjectiveError.BADPARAMS);
474 return ImmutableSet.of();
475 }
476 VlanId assignedVlan = readVlanFromSelector(fwd.meta());
477 if (assignedVlan == null) {
478 log.warn("VLAN ID required by multicast specific fwd obj is missing. Abort.");
479 fail(fwd, ObjectiveError.BADPARAMS);
480 return ImmutableSet.of();
481 }
482 filteredSelector.matchVlanId(assignedVlan);
483 filteredSelector.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ipv4Dst);
484 forTableId = MULTICAST_ROUTING_TABLE;
485 log.debug("processing IPv4 multicast specific forwarding objective {} -> next:{}"
486 + " in dev:{}", fwd.id(), fwd.nextId(), deviceId);
Flavio Castroe10fa242016-01-15 12:43:51 -0800487 } else {
Charles Chanf9e98652016-09-07 16:54:23 -0700488 if (ipv4Dst.prefixLength() == 0) {
489 // The entire IPV4_DST field is wildcarded intentionally
490 filteredSelector.matchEthType(Ethernet.TYPE_IPV4);
Charles Chan5b9df8d2016-03-28 22:21:40 -0700491 } else {
Charles Chanf9e98652016-09-07 16:54:23 -0700492 filteredSelector.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ipv4Dst);
Charles Chan5b9df8d2016-03-28 22:21:40 -0700493 }
494 forTableId = UNICAST_ROUTING_TABLE;
495 log.debug("processing IPv4 unicast specific forwarding objective {} -> next:{}"
496 + " in dev:{}", fwd.id(), fwd.nextId(), deviceId);
Flavio Castroe10fa242016-01-15 12:43:51 -0800497 }
Pier Ventree0ae7a32016-11-23 09:57:42 -0800498 } else if (ethType.ethType().toShort() == Ethernet.TYPE_IPV6) {
Julia Fergusond8f145e2017-08-10 18:15:24 +0000499 IpPrefix ipv6Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV6_DST)).ip();
500 if (ipv6Dst.isMulticast()) {
501 if (ipv6Dst.prefixLength() != IpAddress.INET6_BIT_LENGTH) {
502 log.debug("Multicast specific IPv6 forwarding objective can only be /128");
503 fail(fwd, ObjectiveError.BADPARAMS);
504 return ImmutableSet.of();
505 }
506 VlanId assignedVlan = readVlanFromSelector(fwd.meta());
507 if (assignedVlan == null) {
508 log.debug("VLAN ID required by multicast specific fwd obj is missing. Abort.");
509 fail(fwd, ObjectiveError.BADPARAMS);
510 return ImmutableSet.of();
511 }
512 filteredSelector.matchVlanId(assignedVlan);
513 filteredSelector.matchEthType(Ethernet.TYPE_IPV6).matchIPv6Dst(ipv6Dst);
514 forTableId = MULTICAST_ROUTING_TABLE;
515 log.debug("processing IPv6 multicast specific forwarding objective {} -> next:{}"
516 + " in dev:{}", fwd.id(), fwd.nextId(), deviceId);
517 } else {
518 if (buildIpv6Selector(filteredSelector, fwd) < 0) {
519 return Collections.emptyList();
520 }
521 forTableId = UNICAST_ROUTING_TABLE;
Pier Ventree0ae7a32016-11-23 09:57:42 -0800522 }
Saurav Das8a0732e2015-11-20 15:27:53 -0800523 } else {
524 filteredSelector
525 .matchEthType(Ethernet.MPLS_UNICAST)
526 .matchMplsLabel(((MplsCriterion)
527 selector.getCriterion(Criterion.Type.MPLS_LABEL)).label());
528 MplsBosCriterion bos = (MplsBosCriterion) selector
529 .getCriterion(Criterion.Type.MPLS_BOS);
530 if (bos != null) {
531 filteredSelector.matchMplsBos(bos.mplsBos());
532 }
533 forTableId = MPLS_TABLE_1;
Saurav Das4ce45962015-11-24 23:21:05 -0800534 log.debug("processing MPLS specific forwarding objective {} -> next:{}"
535 + " in dev {}", fwd.id(), fwd.nextId(), deviceId);
Saurav Das8a0732e2015-11-20 15:27:53 -0800536 }
537
538 TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
539 if (fwd.treatment() != null) {
540 for (Instruction i : fwd.treatment().allInstructions()) {
Charles Chan40132b32017-01-22 00:19:37 -0800541 if (!supportCopyTtl() && i instanceof L3ModificationInstruction) {
542 L3ModificationInstruction l3instr = (L3ModificationInstruction) i;
543 if (l3instr.subtype().equals(L3ModificationInstruction.L3SubType.TTL_IN) ||
544 l3instr.subtype().equals(L3ModificationInstruction.L3SubType.TTL_OUT)) {
545 continue;
546 }
547 }
Charles Chan7d10b162015-12-07 18:54:45 -0800548 /*
549 * NOTE: OF-DPA does not support immediate instruction in
550 * L3 unicast and MPLS table.
551 */
552 tb.deferred().add(i);
Saurav Das8a0732e2015-11-20 15:27:53 -0800553 }
554 }
555
556 if (fwd.nextId() != null) {
Saurav Das423fe2b2015-12-04 10:52:59 -0800557 NextGroup next = getGroupForNextObjective(fwd.nextId());
558 if (next != null) {
559 List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
560 // we only need the top level group's key to point the flow to it
561 Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst());
562 if (group == null) {
Saurav Das1ce0a7b2016-10-21 14:06:29 -0700563 log.warn("Group with key:{} for next-id:{} not found in dev:{}",
564 gkeys.get(0).peekFirst(), fwd.nextId(), deviceId);
Saurav Das423fe2b2015-12-04 10:52:59 -0800565 fail(fwd, ObjectiveError.GROUPMISSING);
566 return Collections.emptySet();
567 }
568 tb.deferred().group(group.id());
Saurav Das8a0732e2015-11-20 15:27:53 -0800569 }
Saurav Das8a0732e2015-11-20 15:27:53 -0800570 }
571 tb.transition(ACL_TABLE);
572 FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
573 .fromApp(fwd.appId())
574 .withPriority(fwd.priority())
575 .forDevice(deviceId)
576 .withSelector(filteredSelector.build())
577 .withTreatment(tb.build())
578 .forTable(forTableId);
579
580 if (fwd.permanent()) {
581 ruleBuilder.makePermanent();
582 } else {
583 ruleBuilder.makeTemporary(fwd.timeout());
584 }
Flavio Castroe10fa242016-01-15 12:43:51 -0800585 Collection<FlowRule> flowRuleCollection = new ArrayList<>();
586 flowRuleCollection.add(ruleBuilder.build());
587 if (defaultRule) {
Pier Ventree0ae7a32016-11-23 09:57:42 -0800588 flowRuleCollection.add(
589 defaultRoute(fwd, complementarySelector, forTableId, tb)
590 );
Flavio Castroe10fa242016-01-15 12:43:51 -0800591 log.debug("Default rule 0.0.0.0/0 is being installed two rules");
592 }
Flavio Castroe10fa242016-01-15 12:43:51 -0800593 return flowRuleCollection;
Saurav Das8a0732e2015-11-20 15:27:53 -0800594 }
595
Charles Chan1e492d32016-01-30 23:22:37 -0800596 @Override
597 protected Collection<FlowRule> processEthDstSpecific(ForwardingObjective fwd) {
598 List<FlowRule> rules = new ArrayList<>();
599
600 // Build filtered selector
601 TrafficSelector selector = fwd.selector();
602 EthCriterion ethCriterion = (EthCriterion) selector
603 .getCriterion(Criterion.Type.ETH_DST);
604 VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) selector
605 .getCriterion(Criterion.Type.VLAN_VID);
606
607 if (vlanIdCriterion == null) {
608 log.warn("Forwarding objective for bridging requires vlan. Not "
609 + "installing fwd:{} in dev:{}", fwd.id(), deviceId);
610 fail(fwd, ObjectiveError.BADPARAMS);
611 return Collections.emptySet();
612 }
613
614 TrafficSelector.Builder filteredSelectorBuilder =
615 DefaultTrafficSelector.builder();
616 // Do not match MacAddress for subnet broadcast entry
Charles Chand05f54b2017-02-13 11:56:54 -0800617 if (!ethCriterion.mac().equals(NONE) && !ethCriterion.mac().equals(BROADCAST)) {
Charles Chan1e492d32016-01-30 23:22:37 -0800618 filteredSelectorBuilder.matchEthDst(ethCriterion.mac());
619 log.debug("processing L2 forwarding objective:{} -> next:{} in dev:{}",
620 fwd.id(), fwd.nextId(), deviceId);
621 } else {
622 log.debug("processing L2 Broadcast forwarding objective:{} -> next:{} "
623 + "in dev:{} for vlan:{}",
624 fwd.id(), fwd.nextId(), deviceId, vlanIdCriterion.vlanId());
625 }
626 filteredSelectorBuilder.matchVlanId(vlanIdCriterion.vlanId());
627 TrafficSelector filteredSelector = filteredSelectorBuilder.build();
628
629 if (fwd.treatment() != null) {
630 log.warn("Ignoring traffic treatment in fwd rule {} meant for L2 table"
631 + "for dev:{}. Expecting only nextId", fwd.id(), deviceId);
632 }
633
634 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
635 if (fwd.nextId() != null) {
636 NextGroup next = getGroupForNextObjective(fwd.nextId());
637 if (next != null) {
638 List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
639 // we only need the top level group's key to point the flow to it
640 Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst());
641 if (group != null) {
642 treatmentBuilder.deferred().group(group.id());
643 } else {
644 log.warn("Group with key:{} for next-id:{} not found in dev:{}",
645 gkeys.get(0).peekFirst(), fwd.nextId(), deviceId);
646 fail(fwd, ObjectiveError.GROUPMISSING);
647 return Collections.emptySet();
648 }
649 }
650 }
651 treatmentBuilder.immediate().transition(ACL_TABLE);
652 TrafficTreatment filteredTreatment = treatmentBuilder.build();
653
654 // Build bridging table entries
655 FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder();
656 flowRuleBuilder.fromApp(fwd.appId())
657 .withPriority(fwd.priority())
658 .forDevice(deviceId)
659 .withSelector(filteredSelector)
660 .withTreatment(filteredTreatment)
661 .forTable(BRIDGING_TABLE);
662 if (fwd.permanent()) {
663 flowRuleBuilder.makePermanent();
664 } else {
665 flowRuleBuilder.makeTemporary(fwd.timeout());
666 }
667 rules.add(flowRuleBuilder.build());
668 return rules;
669 }
670
Saurav Das52025962016-01-28 22:30:01 -0800671 /*
672 * In the OF-DPA 2.0 pipeline, versatile forwarding objectives go to the
673 * ACL table. Because we pop off vlan tags in TMAC table,
674 * we need to avoid matching on vlans in the ACL table.
675 */
676 @Override
677 protected Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
678 log.info("Processing versatile forwarding objective");
679
680 EthTypeCriterion ethType =
681 (EthTypeCriterion) fwd.selector().getCriterion(Criterion.Type.ETH_TYPE);
682 if (ethType == null) {
683 log.error("Versatile forwarding objective must include ethType");
684 fail(fwd, ObjectiveError.BADPARAMS);
685 return Collections.emptySet();
686 }
687 if (fwd.nextId() == null && fwd.treatment() == null) {
688 log.error("Forwarding objective {} from {} must contain "
689 + "nextId or Treatment", fwd.selector(), fwd.appId());
690 return Collections.emptySet();
691 }
692
693 TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
694 fwd.selector().criteria().forEach(criterion -> {
695 if (criterion instanceof VlanIdCriterion) {
696 // avoid matching on vlans
697 return;
Pier Ventree0ae7a32016-11-23 09:57:42 -0800698 } else if (criterion instanceof Icmpv6TypeCriterion ||
699 criterion instanceof Icmpv6CodeCriterion) {
700 /*
701 * We silenty discard these criterions, our current
702 * OFDPA platform does not support these matches on
703 * the ACL table.
704 */
705 log.warn("ICMPv6 Type and ICMPv6 Code are not supported");
Saurav Das52025962016-01-28 22:30:01 -0800706 } else {
707 sbuilder.add(criterion);
708 }
709 });
710
711 // XXX driver does not currently do type checking as per Tables 65-67 in
712 // OFDPA 2.0 spec. The only allowed treatment is a punt to the controller.
713 TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder();
714 if (fwd.treatment() != null) {
715 for (Instruction ins : fwd.treatment().allInstructions()) {
716 if (ins instanceof OutputInstruction) {
717 OutputInstruction o = (OutputInstruction) ins;
718 if (o.port() == PortNumber.CONTROLLER) {
Charles Chan0f43e472017-02-14 14:00:16 -0800719 ttBuilder.transition(PUNT_TABLE);
Saurav Das52025962016-01-28 22:30:01 -0800720 } else {
721 log.warn("Only allowed treatments in versatile forwarding "
722 + "objectives are punts to the controller");
723 }
724 } else {
725 log.warn("Cannot process instruction in versatile fwd {}", ins);
726 }
727 }
Charles Chan2df0e8a2017-01-09 11:45:08 -0800728 if (fwd.treatment().clearedDeferred()) {
729 ttBuilder.wipeDeferred();
730 }
Saurav Das52025962016-01-28 22:30:01 -0800731 }
732 if (fwd.nextId() != null) {
733 // overide case
734 NextGroup next = getGroupForNextObjective(fwd.nextId());
735 List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
736 // we only need the top level group's key to point the flow to it
737 Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst());
738 if (group == null) {
739 log.warn("Group with key:{} for next-id:{} not found in dev:{}",
740 gkeys.get(0).peekFirst(), fwd.nextId(), deviceId);
741 fail(fwd, ObjectiveError.GROUPMISSING);
742 return Collections.emptySet();
743 }
744 ttBuilder.deferred().group(group.id());
745 }
746
747 FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
748 .fromApp(fwd.appId())
749 .withPriority(fwd.priority())
750 .forDevice(deviceId)
751 .withSelector(sbuilder.build())
752 .withTreatment(ttBuilder.build())
753 .makePermanent()
754 .forTable(ACL_TABLE);
755 return Collections.singletonList(ruleBuilder.build());
756 }
757
758 /*
759 * Cpqd emulation requires table-miss-entries in forwarding tables.
760 * Real OFDPA does not require these rules as they are put in by default.
761 *
762 * (non-Javadoc)
763 * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#initializePipeline()
764 */
Saurav Das2857f382015-11-03 14:39:27 -0800765 @Override
Saurav Das558afec2015-05-31 17:12:48 -0700766 protected void initializePipeline() {
Charles Chanf6ec1532017-02-08 16:10:40 -0800767 initTableMiss(PORT_TABLE, VLAN_TABLE, null);
768 initTableMiss(VLAN_TABLE, ACL_TABLE, null);
769 initTableMiss(TMAC_TABLE, BRIDGING_TABLE, null);
770 initTableMiss(UNICAST_ROUTING_TABLE, ACL_TABLE, null);
771 initTableMiss(MULTICAST_ROUTING_TABLE, ACL_TABLE, null);
772 initTableMiss(MPLS_TABLE_0, MPLS_TABLE_1, null);
773 initTableMiss(MPLS_TABLE_1, ACL_TABLE, null);
774 initTableMiss(BRIDGING_TABLE, ACL_TABLE, null);
775 initTableMiss(ACL_TABLE, -1, null);
Charles Chan0f43e472017-02-14 14:00:16 -0800776
777 if (supportPuntGroup()) {
778 initTableMiss(PUNT_TABLE, -1,
779 DefaultTrafficTreatment.builder().punt().build());
780 initPopVlanPuntGroup();
781 } else {
782 initTableMiss(PUNT_TABLE, -1,
783 DefaultTrafficTreatment.builder().popVlan().punt().build());
784 }
Saurav Das558afec2015-05-31 17:12:48 -0700785 }
786
Charles Chanf6ec1532017-02-08 16:10:40 -0800787 /**
788 * Install table-miss flow entry.
789 *
790 * If treatment exists, use it directly.
791 * Else if treatment does not exist but nextTable > 0, transit to next table.
792 * Else apply empty treatment.
793 *
794 * @param thisTable this table ID
795 * @param nextTable next table ID
796 * @param treatment traffic treatment to apply.
797 */
798 private void initTableMiss(int thisTable, int nextTable, TrafficTreatment treatment) {
Saurav Das558afec2015-05-31 17:12:48 -0700799 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
Charles Chanf6ec1532017-02-08 16:10:40 -0800800 TrafficSelector selector = DefaultTrafficSelector.builder().build();
Saurav Das558afec2015-05-31 17:12:48 -0700801
Charles Chanf6ec1532017-02-08 16:10:40 -0800802 if (treatment == null) {
803 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
804 if (nextTable > 0) {
805 tBuilder.transition(nextTable);
Saurav Das558afec2015-05-31 17:12:48 -0700806 }
Charles Chanf6ec1532017-02-08 16:10:40 -0800807 treatment = tBuilder.build();
808 }
Saurav Das558afec2015-05-31 17:12:48 -0700809
Charles Chanb7504392017-02-10 12:51:04 -0800810 FlowRule rule = DefaultFlowRule.builder()
811 .forDevice(deviceId)
Charles Chanf6ec1532017-02-08 16:10:40 -0800812 .withSelector(selector)
813 .withTreatment(treatment)
Charles Chanb7504392017-02-10 12:51:04 -0800814 .withPriority(LOWEST_PRIORITY)
815 .fromApp(driverId)
816 .makePermanent()
Charles Chanf6ec1532017-02-08 16:10:40 -0800817 .forTable(thisTable).build();
Charles Chanb7504392017-02-10 12:51:04 -0800818 ops = ops.add(rule);
Saurav Das2857f382015-11-03 14:39:27 -0800819
820 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
821 @Override
822 public void onSuccess(FlowRuleOperations ops) {
Charles Chanf6ec1532017-02-08 16:10:40 -0800823 log.info("Initialized table {} on {}", thisTable, deviceId);
Saurav Das2857f382015-11-03 14:39:27 -0800824 }
Saurav Das2857f382015-11-03 14:39:27 -0800825 @Override
826 public void onError(FlowRuleOperations ops) {
Charles Chanf6ec1532017-02-08 16:10:40 -0800827 log.warn("Failed to initialize table {} on {}", thisTable, deviceId);
Saurav Das2857f382015-11-03 14:39:27 -0800828 }
829 }));
830 }
Charles Chan0f43e472017-02-14 14:00:16 -0800831
832 /**
833 * Builds a indirect group contains pop_vlan and punt actions.
834 * <p>
835 * Using group instead of immediate action to ensure that
836 * the copy of packet on the data plane is not affected by the pop vlan action.
837 */
838 private void initPopVlanPuntGroup() {
Yi Tsengef19de12017-04-24 11:33:05 -0700839 GroupKey groupKey = popVlanPuntGroupKey();
Charles Chan0f43e472017-02-14 14:00:16 -0800840 TrafficTreatment bucketTreatment = DefaultTrafficTreatment.builder()
841 .popVlan().punt().build();
842 GroupBucket bucket =
843 DefaultGroupBucket.createIndirectGroupBucket(bucketTreatment);
844 GroupDescription groupDesc =
845 new DefaultGroupDescription(
846 deviceId,
847 GroupDescription.Type.INDIRECT,
848 new GroupBuckets(Collections.singletonList(bucket)),
849 groupKey,
850 POP_VLAN_PUNT_GROUP_ID,
851 driverId);
852 groupService.addGroup(groupDesc);
853
854 log.info("Initialized pop vlan punt group on {}", deviceId);
855 }
Yi Tsengef19de12017-04-24 11:33:05 -0700856
857 /**
858 * Generates group key for a static indirect group that pop vlan and punt to
859 * controller.
860 *
861 * @return the group key of the indirect table
862 */
863 private GroupKey popVlanPuntGroupKey() {
864 int hash = POP_VLAN_PUNT_GROUP_ID | (Objects.hash(deviceId) & FOUR_BIT_MASK);
865 return new DefaultGroupKey(Ofdpa2Pipeline.appKryo.serialize(hash));
866 }
Saurav Das558afec2015-05-31 17:12:48 -0700867}