blob: 081f68f63c59263f1e7b4a01b87abe5f0410a4d0 [file] [log] [blame]
Yi Tseng0b809722017-11-03 10:23:26 -07001/*
2 * Copyright 2017-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.pipelines.fabric.pipeliner;
18
Yi Tseng1b154bd2017-11-20 17:48:19 -080019import com.google.common.collect.ImmutableList;
Carmelo Casconeb5324e72018-11-25 02:26:32 -080020import org.junit.Before;
Yi Tseng0b809722017-11-03 10:23:26 -070021import org.junit.Test;
Yi Tseng0b809722017-11-03 10:23:26 -070022import org.onosproject.net.flow.DefaultFlowRule;
23import org.onosproject.net.flow.DefaultTrafficSelector;
24import org.onosproject.net.flow.DefaultTrafficTreatment;
25import org.onosproject.net.flow.FlowRule;
26import org.onosproject.net.flow.TrafficSelector;
27import org.onosproject.net.flow.TrafficTreatment;
28import org.onosproject.net.flow.criteria.PiCriterion;
29import org.onosproject.net.flowobjective.DefaultNextObjective;
30import org.onosproject.net.flowobjective.NextObjective;
Yi Tseng1b154bd2017-11-20 17:48:19 -080031import org.onosproject.net.group.DefaultGroupBucket;
32import org.onosproject.net.group.DefaultGroupDescription;
Esin Karaman24fda8a2018-01-26 11:52:28 +000033import org.onosproject.net.group.DefaultGroupKey;
Yi Tseng1b154bd2017-11-20 17:48:19 -080034import org.onosproject.net.group.GroupBucket;
35import org.onosproject.net.group.GroupBuckets;
Yi Tseng0b809722017-11-03 10:23:26 -070036import org.onosproject.net.group.GroupDescription;
Esin Karaman24fda8a2018-01-26 11:52:28 +000037import org.onosproject.net.group.GroupKey;
38import org.onosproject.net.pi.runtime.PiAction;
Yi Tseng1b154bd2017-11-20 17:48:19 -080039import org.onosproject.net.pi.runtime.PiActionGroupId;
Esin Karaman24fda8a2018-01-26 11:52:28 +000040import org.onosproject.net.pi.runtime.PiActionParam;
Yi Tseng1b154bd2017-11-20 17:48:19 -080041import org.onosproject.net.pi.runtime.PiGroupKey;
Yi Tseng0b809722017-11-03 10:23:26 -070042import org.onosproject.pipelines.fabric.FabricConstants;
43
44import java.util.List;
Yi Tseng1b154bd2017-11-20 17:48:19 -080045import java.util.stream.Collectors;
Yi Tseng0b809722017-11-03 10:23:26 -070046
47import static org.junit.Assert.assertEquals;
Yi Tseng0b809722017-11-03 10:23:26 -070048
49/**
50 * Test cases for fabric.p4 pipeline next control block.
51 */
52public class FabricNextPipelinerTest extends FabricPipelinerTest {
Carmelo Casconeb5324e72018-11-25 02:26:32 -080053
54 private NextObjectiveTranslator translatorHashed;
55 private NextObjectiveTranslator translatorSimple;
56
Yi Tseng20f9e7b2018-05-24 23:27:39 +080057 private FlowRule vlanMetaFlowRule;
58
Carmelo Casconeb5324e72018-11-25 02:26:32 -080059 @Before
60 public void setup() {
61 super.doSetup();
62
63 translatorHashed = new NextObjectiveTranslator(DEVICE_ID, capabilitiesHashed);
64 translatorSimple = new NextObjectiveTranslator(DEVICE_ID, capabilitiesSimple);
65
Yi Tseng20f9e7b2018-05-24 23:27:39 +080066 PiCriterion nextIdCriterion = PiCriterion.builder()
Carmelo Casconeb5324e72018-11-25 02:26:32 -080067 .matchExact(FabricConstants.HDR_NEXT_ID, NEXT_ID_1)
Yi Tseng20f9e7b2018-05-24 23:27:39 +080068 .build();
69 TrafficSelector selector = DefaultTrafficSelector.builder()
70 .matchPi(nextIdCriterion)
71 .build();
Carmelo Casconeb5324e72018-11-25 02:26:32 -080072 PiAction piAction = PiAction.builder()
73 .withId(FabricConstants.FABRIC_INGRESS_NEXT_SET_VLAN)
74 .withParameter(new PiActionParam(FabricConstants.VLAN_ID, VLAN_100.toShort()))
Yi Tseng20f9e7b2018-05-24 23:27:39 +080075 .build();
Carmelo Casconeb5324e72018-11-25 02:26:32 -080076 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
77 .piTableAction(piAction)
78 .build();
Yi Tseng20f9e7b2018-05-24 23:27:39 +080079 vlanMetaFlowRule = DefaultFlowRule.builder()
80 .withSelector(selector)
81 .withTreatment(treatment)
Carmelo Casconeb5324e72018-11-25 02:26:32 -080082 .forTable(FabricConstants.FABRIC_INGRESS_NEXT_NEXT_VLAN)
Yi Tseng20f9e7b2018-05-24 23:27:39 +080083 .makePermanent()
84 // FIXME: currently next objective doesn't support priority, ignore this
85 .withPriority(0)
86 .forDevice(DEVICE_ID)
87 .fromApp(APP_ID)
88 .build();
89 }
Yi Tseng0b809722017-11-03 10:23:26 -070090
91 /**
92 * Test program output rule for Simple table.
93 */
94 @Test
Carmelo Casconeb5324e72018-11-25 02:26:32 -080095 public void testSimpleOutput() throws FabricPipelinerException {
Yi Tseng0b809722017-11-03 10:23:26 -070096 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
97 .setOutput(PORT_1)
98 .build();
Carmelo Casconeb5324e72018-11-25 02:26:32 -080099 PiAction piAction = PiAction.builder()
100 .withId(FabricConstants.FABRIC_INGRESS_NEXT_OUTPUT_SIMPLE)
101 .withParameter(new PiActionParam(
102 FabricConstants.PORT_NUM, PORT_1.toLong()))
103 .build();
104 testSimple(treatment, piAction);
Yi Tseng0b809722017-11-03 10:23:26 -0700105 }
106
107 /**
108 * Test program set vlan and output rule for Simple table.
109 */
110 @Test
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800111 public void testSimpleOutputWithVlanTranslation() throws FabricPipelinerException {
Yi Tseng0b809722017-11-03 10:23:26 -0700112 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
113 .setVlanId(VLAN_100)
114 .setOutput(PORT_1)
115 .build();
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800116 PiAction piAction = PiAction.builder()
117 .withId(FabricConstants.FABRIC_INGRESS_NEXT_OUTPUT_SIMPLE)
118 .withParameter(new PiActionParam(
119 FabricConstants.PORT_NUM, PORT_1.toLong()))
120 .build();
121 testSimple(treatment, piAction);
Yi Tseng0b809722017-11-03 10:23:26 -0700122 }
123
Yi Tsengdbe05602017-11-17 18:02:43 -0800124 /**
125 * Test program set mac and output rule for Simple table.
126 */
127 @Test
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800128 public void testSimpleOutputWithMacTranslation() throws FabricPipelinerException {
Yi Tsengdbe05602017-11-17 18:02:43 -0800129 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
130 .setEthSrc(ROUTER_MAC)
131 .setEthDst(HOST_MAC)
132 .setOutput(PORT_1)
133 .build();
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800134 PiAction piAction = PiAction.builder()
135 .withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_SIMPLE)
136 .withParameter(new PiActionParam(
137 FabricConstants.SMAC, ROUTER_MAC.toBytes()))
138 .withParameter(new PiActionParam(
139 FabricConstants.DMAC, HOST_MAC.toBytes()))
140 .withParameter(new PiActionParam(
141 FabricConstants.PORT_NUM, PORT_1.toLong()))
142 .build();
143 testSimple(treatment, piAction);
Yi Tsengdbe05602017-11-17 18:02:43 -0800144 }
145
Yi Tseng20f9e7b2018-05-24 23:27:39 +0800146 /**
147 * Test program set mac, set vlan, and output rule for Simple table.
148 */
149 @Test
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800150 public void testSimpleOutputWithVlanAndMacTranslation() throws FabricPipelinerException {
Yi Tseng20f9e7b2018-05-24 23:27:39 +0800151 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
152 .setEthSrc(ROUTER_MAC)
153 .setEthDst(HOST_MAC)
154 .setVlanId(VLAN_100)
155 .setOutput(PORT_1)
156 .build();
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800157 PiAction piAction = PiAction.builder()
158 .withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_SIMPLE)
159 .withParameter(new PiActionParam(
160 FabricConstants.SMAC, ROUTER_MAC.toBytes()))
161 .withParameter(new PiActionParam(
162 FabricConstants.DMAC, HOST_MAC.toBytes()))
163 .withParameter(new PiActionParam(
164 FabricConstants.PORT_NUM, PORT_1.toLong()))
165 .build();
166 testSimple(treatment, piAction);
Yi Tseng20f9e7b2018-05-24 23:27:39 +0800167 }
168
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800169 private void testSimple(TrafficTreatment treatment, PiAction piAction) throws FabricPipelinerException {
Yi Tseng0b809722017-11-03 10:23:26 -0700170 NextObjective nextObjective = DefaultNextObjective.builder()
171 .withId(NEXT_ID_1)
172 .withPriority(PRIORITY)
Yi Tseng20f9e7b2018-05-24 23:27:39 +0800173 .withMeta(VLAN_META)
Yi Tseng0b809722017-11-03 10:23:26 -0700174 .addTreatment(treatment)
175 .withType(NextObjective.Type.SIMPLE)
176 .makePermanent()
177 .fromApp(APP_ID)
178 .add();
179
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800180 ObjectiveTranslation actualTranslation = translatorSimple.translate(nextObjective);
Yi Tseng0b809722017-11-03 10:23:26 -0700181
Yi Tseng1b154bd2017-11-20 17:48:19 -0800182 // Simple table
Yi Tseng0b809722017-11-03 10:23:26 -0700183 PiCriterion nextIdCriterion = PiCriterion.builder()
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800184 .matchExact(FabricConstants.HDR_NEXT_ID, NEXT_ID_1)
Yi Tseng1b154bd2017-11-20 17:48:19 -0800185 .build();
186 TrafficSelector nextIdSelector = DefaultTrafficSelector.builder()
187 .matchPi(nextIdCriterion)
188 .build();
Yi Tseng1b154bd2017-11-20 17:48:19 -0800189 FlowRule expectedFlowRule = DefaultFlowRule.builder()
190 .forDevice(DEVICE_ID)
191 .fromApp(APP_ID)
192 .makePermanent()
193 // FIXME: currently next objective doesn't support priority, ignore this
194 .withPriority(0)
Yi Tseng43ee7e82018-04-12 16:37:34 +0800195 .forTable(FabricConstants.FABRIC_INGRESS_NEXT_SIMPLE)
Yi Tseng1b154bd2017-11-20 17:48:19 -0800196 .withSelector(nextIdSelector)
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800197 .withTreatment(DefaultTrafficTreatment.builder()
198 .piTableAction(piAction).build())
Yi Tseng1b154bd2017-11-20 17:48:19 -0800199 .build();
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800200
201 ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder()
202 .addFlowRule(vlanMetaFlowRule)
203 .addFlowRule(expectedFlowRule)
204 .build();
205
206 assertEquals(expectedTranslation, actualTranslation);
Yi Tseng1b154bd2017-11-20 17:48:19 -0800207 }
208
Yi Tseng0b809722017-11-03 10:23:26 -0700209 /**
210 * Test program ecmp output group for Hashed table.
211 */
212 @Test
Yi Tseng1b154bd2017-11-20 17:48:19 -0800213 public void testHashedOutput() throws Exception {
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800214 PiAction piAction1 = PiAction.builder()
215 .withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED)
216 .withParameter(new PiActionParam(
217 FabricConstants.SMAC, ROUTER_MAC.toBytes()))
218 .withParameter(new PiActionParam(
219 FabricConstants.DMAC, HOST_MAC.toBytes()))
220 .withParameter(new PiActionParam(
221 FabricConstants.PORT_NUM, PORT_1.toLong()))
222 .build();
223 PiAction piAction2 = PiAction.builder()
224 .withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED)
225 .withParameter(new PiActionParam(
226 FabricConstants.SMAC, ROUTER_MAC.toBytes()))
227 .withParameter(new PiActionParam(
228 FabricConstants.DMAC, HOST_MAC.toBytes()))
229 .withParameter(new PiActionParam(
230 FabricConstants.PORT_NUM, PORT_1.toLong()))
231 .build();
Yi Tseng1b154bd2017-11-20 17:48:19 -0800232 TrafficTreatment treatment1 = DefaultTrafficTreatment.builder()
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800233 .piTableAction(piAction1)
Yi Tseng1b154bd2017-11-20 17:48:19 -0800234 .build();
235 TrafficTreatment treatment2 = DefaultTrafficTreatment.builder()
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800236 .piTableAction(piAction2)
Yi Tseng1b154bd2017-11-20 17:48:19 -0800237 .build();
238
239 NextObjective nextObjective = DefaultNextObjective.builder()
240 .withId(NEXT_ID_1)
241 .withPriority(PRIORITY)
Yi Tseng20f9e7b2018-05-24 23:27:39 +0800242 .withMeta(VLAN_META)
Yi Tseng1b154bd2017-11-20 17:48:19 -0800243 .addTreatment(treatment1)
244 .addTreatment(treatment2)
245 .withType(NextObjective.Type.HASHED)
246 .makePermanent()
247 .fromApp(APP_ID)
248 .add();
249
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800250 ObjectiveTranslation actualTranslation = translatorHashed.doTranslate(nextObjective);
Yi Tseng1b154bd2017-11-20 17:48:19 -0800251
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800252 // Expected hashed table flow rule.
Yi Tseng1b154bd2017-11-20 17:48:19 -0800253 PiCriterion nextIdCriterion = PiCriterion.builder()
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800254 .matchExact(FabricConstants.HDR_NEXT_ID, NEXT_ID_1)
Yi Tseng1b154bd2017-11-20 17:48:19 -0800255 .build();
256 TrafficSelector nextIdSelector = DefaultTrafficSelector.builder()
257 .matchPi(nextIdCriterion)
258 .build();
259 PiActionGroupId actionGroupId = PiActionGroupId.of(NEXT_ID_1);
260 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
261 .piTableAction(actionGroupId)
262 .build();
Yi Tseng1b154bd2017-11-20 17:48:19 -0800263 FlowRule expectedFlowRule = DefaultFlowRule.builder()
264 .forDevice(DEVICE_ID)
265 .fromApp(APP_ID)
266 .makePermanent()
267 // FIXME: currently next objective doesn't support priority, ignore this
268 .withPriority(0)
Yi Tseng43ee7e82018-04-12 16:37:34 +0800269 .forTable(FabricConstants.FABRIC_INGRESS_NEXT_HASHED)
Yi Tseng1b154bd2017-11-20 17:48:19 -0800270 .withSelector(nextIdSelector)
271 .withTreatment(treatment)
272 .build();
Yi Tseng1b154bd2017-11-20 17:48:19 -0800273
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800274 // Expected group
Yi Tseng1b154bd2017-11-20 17:48:19 -0800275 List<TrafficTreatment> treatments = ImmutableList.of(treatment1, treatment2);
Yi Tseng1b154bd2017-11-20 17:48:19 -0800276 List<GroupBucket> buckets = treatments.stream()
277 .map(DefaultGroupBucket::createSelectGroupBucket)
278 .collect(Collectors.toList());
279 GroupBuckets groupBuckets = new GroupBuckets(buckets);
Yi Tseng43ee7e82018-04-12 16:37:34 +0800280 PiGroupKey groupKey = new PiGroupKey(FabricConstants.FABRIC_INGRESS_NEXT_HASHED,
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800281 FabricConstants.FABRIC_INGRESS_NEXT_HASHED_SELECTOR,
Yi Tseng43ee7e82018-04-12 16:37:34 +0800282 NEXT_ID_1);
Yi Tseng1b154bd2017-11-20 17:48:19 -0800283 GroupDescription expectedGroup = new DefaultGroupDescription(
284 DEVICE_ID,
285 GroupDescription.Type.SELECT,
286 groupBuckets,
287 groupKey,
288 NEXT_ID_1,
289 APP_ID
290 );
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800291
292 ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder()
293 .addFlowRule(expectedFlowRule)
294 .addFlowRule(vlanMetaFlowRule)
295 .addGroup(expectedGroup)
296 .build();
297
298 assertEquals(expectedTranslation, actualTranslation);
Yi Tseng0b809722017-11-03 10:23:26 -0700299
300 }
301
302 /**
303 * Test program output group for Broadcast table.
304 */
305 @Test
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800306 public void testBroadcastOutput() throws FabricPipelinerException {
Esin Karaman24fda8a2018-01-26 11:52:28 +0000307 TrafficTreatment treatment1 = DefaultTrafficTreatment.builder()
308 .setOutput(PORT_1)
309 .build();
310 TrafficTreatment treatment2 = DefaultTrafficTreatment.builder()
311 .popVlan()
312 .setOutput(PORT_2)
313 .build();
314 NextObjective nextObjective = DefaultNextObjective.builder()
315 .withId(NEXT_ID_1)
316 .withPriority(PRIORITY)
317 .addTreatment(treatment1)
318 .addTreatment(treatment2)
319 .withMeta(VLAN_META)
320 .withType(NextObjective.Type.BROADCAST)
321 .makePermanent()
322 .fromApp(APP_ID)
323 .add();
Yi Tseng0b809722017-11-03 10:23:26 -0700324
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800325 ObjectiveTranslation actualTranslation = translatorHashed.doTranslate(nextObjective);
Esin Karaman24fda8a2018-01-26 11:52:28 +0000326
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800327 // Should generate 3 flows:
328 // - Multicast table flow that matches on next-id and set multicast group (1)
329 // - Egress VLAN pop handling for treatment2 (0)
330 // - Next VLAN flow (2)
331 // And 2 groups:
332 // - Multicast group
Esin Karaman24fda8a2018-01-26 11:52:28 +0000333
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800334 // Expected multicast table flow rule.
Esin Karaman24fda8a2018-01-26 11:52:28 +0000335 PiCriterion nextIdCriterion = PiCriterion.builder()
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800336 .matchExact(FabricConstants.HDR_NEXT_ID, NEXT_ID_1)
Esin Karaman24fda8a2018-01-26 11:52:28 +0000337 .build();
338 TrafficSelector nextIdSelector = DefaultTrafficSelector.builder()
339 .matchPi(nextIdCriterion)
340 .build();
Esin Karaman24fda8a2018-01-26 11:52:28 +0000341 PiAction setMcGroupAction = PiAction.builder()
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800342 .withId(FabricConstants.FABRIC_INGRESS_NEXT_SET_MCAST_GROUP_ID)
343 .withParameter(new PiActionParam(
344 FabricConstants.GROUP_ID, NEXT_ID_1))
Esin Karaman24fda8a2018-01-26 11:52:28 +0000345 .build();
346 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
347 .piTableAction(setMcGroupAction)
348 .build();
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800349 FlowRule expectedHashedFlowRule = DefaultFlowRule.builder()
Esin Karaman24fda8a2018-01-26 11:52:28 +0000350 .forDevice(DEVICE_ID)
351 .fromApp(APP_ID)
352 .makePermanent()
353 .withPriority(nextObjective.priority())
354 .forTable(FabricConstants.FABRIC_INGRESS_NEXT_MULTICAST)
355 .withSelector(nextIdSelector)
356 .withTreatment(treatment)
357 .build();
358
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800359 // Expected egress VLAN POP flow rule.
Esin Karaman24fda8a2018-01-26 11:52:28 +0000360 PiCriterion egressVlanTableMatch = PiCriterion.builder()
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800361 .matchExact(FabricConstants.HDR_EG_PORT, PORT_2.toLong())
Esin Karaman24fda8a2018-01-26 11:52:28 +0000362 .build();
363 TrafficSelector selectorForEgressVlan = DefaultTrafficSelector.builder()
364 .matchPi(egressVlanTableMatch)
365 .matchVlanId(VLAN_100)
366 .build();
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800367 PiAction piActionForEgressVlan = PiAction.builder()
368 .withId(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_POP_VLAN)
369 .build();
Esin Karaman24fda8a2018-01-26 11:52:28 +0000370 TrafficTreatment treatmentForEgressVlan = DefaultTrafficTreatment.builder()
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800371 .piTableAction(piActionForEgressVlan)
Esin Karaman24fda8a2018-01-26 11:52:28 +0000372 .build();
373 FlowRule expectedEgressVlanRule = DefaultFlowRule.builder()
374 .withSelector(selectorForEgressVlan)
375 .withTreatment(treatmentForEgressVlan)
376 .forTable(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN)
377 .makePermanent()
378 .withPriority(nextObjective.priority())
379 .forDevice(DEVICE_ID)
380 .fromApp(APP_ID)
381 .build();
Esin Karaman24fda8a2018-01-26 11:52:28 +0000382
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800383 // Expected ALL group.
384 TrafficTreatment allGroupTreatment1 = DefaultTrafficTreatment.builder()
Carmelo Cascone58136812018-07-19 03:40:16 +0200385 .setOutput(PORT_1)
386 .build();
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800387 TrafficTreatment allGroupTreatment2 = DefaultTrafficTreatment.builder()
Carmelo Cascone58136812018-07-19 03:40:16 +0200388 .setOutput(PORT_2)
389 .build();
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800390 List<TrafficTreatment> allTreatments = ImmutableList.of(
391 allGroupTreatment1, allGroupTreatment2);
392 List<GroupBucket> allBuckets = allTreatments.stream()
Esin Karaman24fda8a2018-01-26 11:52:28 +0000393 .map(DefaultGroupBucket::createAllGroupBucket)
394 .collect(Collectors.toList());
Carmelo Cascone1e8843f2018-07-19 19:01:12 +0200395 // FIXME: remove when we implement proper clone to CPU behavior
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800396 allBuckets.add(DefaultGroupBucket.createAllGroupBucket(
Carmelo Cascone1e8843f2018-07-19 19:01:12 +0200397 DefaultTrafficTreatment.builder().punt().build()));
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800398 GroupBuckets allGroupBuckets = new GroupBuckets(allBuckets);
399 GroupKey allGroupKey = new DefaultGroupKey(FabricPipeliner.KRYO.serialize(NEXT_ID_1));
400 GroupDescription expectedAllGroup = new DefaultGroupDescription(
Esin Karaman24fda8a2018-01-26 11:52:28 +0000401 DEVICE_ID,
402 GroupDescription.Type.ALL,
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800403 allGroupBuckets,
404 allGroupKey,
Esin Karaman24fda8a2018-01-26 11:52:28 +0000405 NEXT_ID_1,
406 APP_ID
407 );
Yi Tseng15ab4b02018-09-14 11:14:43 -0700408
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800409 ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder()
410 .addFlowRule(expectedHashedFlowRule)
411 .addFlowRule(vlanMetaFlowRule)
412 .addFlowRule(expectedEgressVlanRule)
413 .addGroup(expectedAllGroup)
414 .build();
Yi Tseng15ab4b02018-09-14 11:14:43 -0700415
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800416 assertEquals(expectedTranslation, actualTranslation);
Yi Tseng15ab4b02018-09-14 11:14:43 -0700417 }
Yi Tseng0b809722017-11-03 10:23:26 -0700418}