blob: 7defeb943f7c83c562f272f617582478e3aad0ac [file] [log] [blame]
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001/*
2 * Copyright 2016-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 */
16package org.opencord.olt.impl;
17
Saurav Dasf62cea82020-08-26 17:43:04 -070018import java.util.ArrayList;
19import java.util.Collection;
20import java.util.List;
21import java.util.Map;
22import java.util.Optional;
23import java.util.Set;
24import java.util.concurrent.CompletableFuture;
25
Ilayda Ozdemir90a93622021-02-25 09:40:58 +000026import com.google.common.collect.Maps;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000027import org.apache.commons.lang3.tuple.Pair;
28import org.junit.Before;
29import org.junit.Test;
30import org.onlab.packet.EthType;
31import org.onlab.packet.VlanId;
32import org.onosproject.cluster.NodeId;
33import org.onosproject.cluster.RoleInfo;
34import org.onosproject.mastership.MastershipInfo;
35import org.onosproject.mastership.MastershipListener;
36import org.onosproject.net.DeviceId;
37import org.onosproject.net.MastershipRole;
38import org.onosproject.net.PortNumber;
39import org.onosproject.net.flow.TrafficSelector;
40import org.onosproject.net.flow.TrafficTreatment;
41import org.onosproject.net.flow.criteria.Criterion;
42import org.onosproject.net.flow.criteria.EthTypeCriterion;
43import org.onosproject.net.flow.criteria.PortCriterion;
44import org.onosproject.net.flow.criteria.VlanIdCriterion;
45import org.onosproject.net.flow.instructions.Instruction;
46import org.onosproject.net.flow.instructions.Instructions;
47import org.onosproject.net.flow.instructions.L2ModificationInstruction;
48import org.onosproject.net.flowobjective.FilteringObjQueueKey;
49import org.onosproject.net.flowobjective.FilteringObjective;
50import org.onosproject.net.flowobjective.ForwardingObjQueueKey;
51import org.onosproject.net.flowobjective.ForwardingObjective;
52import org.onosproject.net.flowobjective.NextObjQueueKey;
53import org.onosproject.net.flowobjective.NextObjective;
54import org.onosproject.net.flowobjective.Objective;
55import org.onosproject.net.meter.MeterId;
56import org.onosproject.net.meter.MeterKey;
57import org.opencord.sadis.BandwidthProfileInformation;
58import org.opencord.sadis.UniTagInformation;
59
Saurav Dasf62cea82020-08-26 17:43:04 -070060import com.google.common.collect.ImmutableList;
61import com.google.common.collect.ImmutableMap;
62import com.google.common.collect.ImmutableSet;
63import com.google.common.collect.ListMultimap;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000064
65public class OltFlowTest extends TestBase {
66 private OltFlowService oltFlowService;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000067 PortNumber uniPortNumber = PortNumber.portNumber(1);
Andrea Campanella3a96ce82021-02-09 12:32:42 +010068 PortNumber uniPortNumber2 = PortNumber.portNumber(2);
Andrea Campanellacbbb7952019-11-25 06:38:41 +000069 PortNumber nniPortNumber = PortNumber.portNumber(65535);
70
71 UniTagInformation.Builder tagInfoBuilder = new UniTagInformation.Builder();
72 UniTagInformation uniTagInfo = tagInfoBuilder.setUniTagMatch(VlanId.vlanId((short) 35))
73 .setPonCTag(VlanId.vlanId((short) 33))
74 .setPonSTag(VlanId.vlanId((short) 7))
75 .setDsPonCTagPriority(0)
76 .setUsPonSTagPriority(0)
77 .setTechnologyProfileId(64)
78 .setDownstreamBandwidthProfile(dsBpId)
79 .setUpstreamBandwidthProfile(usBpId)
Saurav Dasf62cea82020-08-26 17:43:04 -070080 .setIsDhcpRequired(true)
81 .setIsIgmpRequired(true)
82 .build();
83
Andrea Campanella3a96ce82021-02-09 12:32:42 +010084 UniTagInformation.Builder tagInfoBuilderNoPcp = new UniTagInformation.Builder();
85 UniTagInformation uniTagInfoNoPcp = tagInfoBuilderNoPcp.setUniTagMatch(VlanId.vlanId((short) 35))
86 .setPonCTag(VlanId.vlanId((short) 34))
87 .setPonSTag(VlanId.vlanId((short) 7))
88 .setDsPonCTagPriority(-1)
89 .setUsPonSTagPriority(-1)
90 .setUsPonCTagPriority(-1)
91 .setDsPonSTagPriority(-1)
92 .setTechnologyProfileId(64)
93 .setDownstreamBandwidthProfile(dsBpId)
94 .setUpstreamBandwidthProfile(usBpId)
95 .setIsDhcpRequired(true)
96 .setIsIgmpRequired(true)
97 .build();
98
Saurav Dasf62cea82020-08-26 17:43:04 -070099 UniTagInformation.Builder tagInfoBuilder2 = new UniTagInformation.Builder();
100 UniTagInformation uniTagInfoNoDhcpNoIgmp = tagInfoBuilder2
101 .setUniTagMatch(VlanId.vlanId((short) 35))
102 .setPonCTag(VlanId.vlanId((short) 33))
103 .setPonSTag(VlanId.vlanId((short) 7))
104 .setDsPonCTagPriority(0)
105 .setUsPonSTagPriority(0)
106 .setTechnologyProfileId(64)
107 .setDownstreamBandwidthProfile(dsBpId)
108 .setUpstreamBandwidthProfile(usBpId)
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000109 .build();
110
111 @Before
112 public void setUp() {
113 oltFlowService = new OltFlowService();
114 oltFlowService.oltMeterService = new MockOltMeterService();
115 oltFlowService.flowObjectiveService = new MockOltFlowObjectiveService();
116 oltFlowService.mastershipService = new MockMastershipService();
117 oltFlowService.sadisService = new MockSadisService();
118 oltFlowService.bpService = oltFlowService.sadisService.getBandwidthProfileService();
119 oltFlowService.appId = appId;
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000120 oltFlowService.pendingEapolForDevice = Maps.newConcurrentMap();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000121 }
122
123 @Test
124 public void testDhcpFiltering() {
Saurav Dasf62cea82020-08-26 17:43:04 -0700125 oltFlowService.flowObjectiveService.clearQueue();
126 // ensure upstream dhcp traps can be added and removed
127 oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000128 usMeterId, uniTagInfo,
129 true, true);
Saurav Dasf62cea82020-08-26 17:43:04 -0700130 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 1;
131 oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000132 usMeterId, uniTagInfo,
133 false, true);
Saurav Dasf62cea82020-08-26 17:43:04 -0700134 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 2;
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100135
136 // Ensure upstream flow has no pcp unless properly specified.
137 oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber2,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000138 usMeterId, uniTagInfoNoPcp,
139 true, true);
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100140 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3;
141
Saurav Dasf62cea82020-08-26 17:43:04 -0700142 // ensure upstream flows are not added if uniTagInfo is missing dhcp requirement
143 oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000144 usMeterId, uniTagInfoNoDhcpNoIgmp,
145 true, true);
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100146 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3;
Saurav Dasf62cea82020-08-26 17:43:04 -0700147
148 // ensure downstream traps don't succeed without global config for nni ports
149 oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, nniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000150 null, null,
151 true, false);
Saurav Dasf62cea82020-08-26 17:43:04 -0700152 oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, nniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000153 null, null,
154 false, false);
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100155 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3;
Saurav Dasf62cea82020-08-26 17:43:04 -0700156 // do global config for nni ports and now it should succeed
157 oltFlowService.enableDhcpOnNni = true;
158 oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, nniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000159 null, null,
160 true, false);
Saurav Dasf62cea82020-08-26 17:43:04 -0700161 oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, nniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000162 null, null,
163 false, false);
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100164 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 5;
Saurav Dasf62cea82020-08-26 17:43:04 -0700165
166 // turn on DHCPv6 and we should get 2 flows
167 oltFlowService.enableDhcpV6 = true;
168 oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000169 usMeterId, uniTagInfo,
170 true, true);
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100171 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 7;
Saurav Dasf62cea82020-08-26 17:43:04 -0700172
173 // turn off DHCPv4 and it's only v6
174 oltFlowService.enableDhcpV4 = false;
175 oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000176 usMeterId, uniTagInfo,
177 true, true);
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100178 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 8;
Saurav Dasf62cea82020-08-26 17:43:04 -0700179
180 // cleanup
181 oltFlowService.flowObjectiveService.clearQueue();
182 oltFlowService.enableDhcpV4 = true;
183 oltFlowService.enableDhcpV6 = false;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000184 }
185
186 @Test
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300187 public void testPppoedFiltering() {
188 oltFlowService.flowObjectiveService.clearQueue();
189
190 // ensure pppoed traps are not added if global config is off.
191 oltFlowService.enablePppoe = false;
192 oltFlowService.processPPPoEDFilteringObjectives(DEVICE_ID_1, uniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000193 usMeterId, uniTagInfo,
194 true, true);
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300195 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 0;
196
197 // ensure upstream pppoed traps can be added and removed
198 oltFlowService.enablePppoe = true;
199 oltFlowService.processPPPoEDFilteringObjectives(DEVICE_ID_1, uniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000200 usMeterId, uniTagInfo,
201 true, true);
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300202 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 1;
203 oltFlowService.processPPPoEDFilteringObjectives(DEVICE_ID_1, uniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000204 usMeterId, uniTagInfo,
205 false, true);
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300206 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 2;
207
208 // ensure downstream pppoed traps can be added and removed
209 oltFlowService.processPPPoEDFilteringObjectives(DEVICE_ID_1, nniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000210 null, null,
211 true, false);
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300212 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3;
213 oltFlowService.processPPPoEDFilteringObjectives(DEVICE_ID_1, nniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000214 null, null,
215 false, false);
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300216 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 4;
217
218 // cleanup
219 oltFlowService.flowObjectiveService.clearQueue();
220 }
221
222 @Test
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000223 public void testIgmpFiltering() {
Saurav Dasf62cea82020-08-26 17:43:04 -0700224 oltFlowService.flowObjectiveService.clearQueue();
225
226 // ensure igmp flows can be added and removed
227 oltFlowService.processIgmpFilteringObjectives(DEVICE_ID_1, uniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000228 usMeterId, uniTagInfo,
229 true, true);
Saurav Dasf62cea82020-08-26 17:43:04 -0700230 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 1;
231 oltFlowService.processIgmpFilteringObjectives(DEVICE_ID_1, uniPortNumber, usMeterId,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000232 uniTagInfo,
233 false, true);
Saurav Dasf62cea82020-08-26 17:43:04 -0700234 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 2;
235
236 // ensure igmp flow is not added if uniTag has no igmp requirement
237 oltFlowService.processIgmpFilteringObjectives(DEVICE_ID_1, uniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000238 usMeterId, uniTagInfoNoDhcpNoIgmp,
239 true, true);
Saurav Dasf62cea82020-08-26 17:43:04 -0700240 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 2;
241
242 //ensure igmp flow on NNI fails without global setting
243 oltFlowService.processIgmpFilteringObjectives(DEVICE_ID_1, nniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000244 null, null,
245 true, false);
Saurav Dasf62cea82020-08-26 17:43:04 -0700246 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 2;
247
248 // igmp trap on NNI should succeed with global config
249 oltFlowService.enableIgmpOnNni = true;
250 oltFlowService.processIgmpFilteringObjectives(DEVICE_ID_1, nniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000251 null, null,
252 true, false);
Saurav Dasf62cea82020-08-26 17:43:04 -0700253 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3;
254 // cleanup
255 oltFlowService.flowObjectiveService.clearQueue();
256
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000257 }
258
259 @Test
260 public void testEapolFiltering() {
261 addBandwidthProfile(uniTagInfo.getUpstreamBandwidthProfile());
262 oltFlowService.enableEapol = true;
263
264 //will install
265 oltFlowService.processEapolFilteringObjectives(DEVICE_ID_1, uniPortNumber,
266 uniTagInfo.getUpstreamBandwidthProfile(), new CompletableFuture<>(),
267 uniTagInfo.getUniTagMatch(), true);
268
269 //bp profile doesn't exist
270 oltFlowService.processEapolFilteringObjectives(DEVICE_ID_1, uniPortNumber,
271 uniTagInfo.getDownstreamBandwidthProfile(), new CompletableFuture<>(),
272 uniTagInfo.getUniTagMatch(), true);
273 }
274
275 @Test
276 public void testLldpFiltering() {
277 oltFlowService.processLldpFilteringObjective(DEVICE_ID_1, nniPortNumber, true);
278 oltFlowService.processLldpFilteringObjective(DEVICE_ID_1, nniPortNumber, false);
279 }
280
281 @Test
282 public void testNniFiltering() {
Saurav Dasf62cea82020-08-26 17:43:04 -0700283 oltFlowService.flowObjectiveService.clearQueue();
284 oltFlowService.enableDhcpOnNni = true;
285 oltFlowService.enableIgmpOnNni = true;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000286 oltFlowService.processNniFilteringObjectives(DEVICE_ID_1, nniPortNumber, true);
Saurav Dasf62cea82020-08-26 17:43:04 -0700287 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives()
288 .size() == 3;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000289 oltFlowService.processNniFilteringObjectives(DEVICE_ID_1, nniPortNumber, false);
Saurav Dasf62cea82020-08-26 17:43:04 -0700290 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives()
291 .size() == 6;
292 oltFlowService.flowObjectiveService.clearQueue();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000293 }
294
295 @Test
296 public void testUpBuilder() {
297 ForwardingObjective objective =
298 oltFlowService.createUpBuilder(nniPortNumber, uniPortNumber, usMeterId, uniTagInfo).add();
299 checkObjective(objective, true);
300 }
301
302 @Test
303 public void testDownBuilder() {
304 ForwardingObjective objective =
305 oltFlowService.createDownBuilder(nniPortNumber, uniPortNumber, dsMeterId, uniTagInfo).remove();
306 checkObjective(objective, false);
307 }
308
309 private void checkObjective(ForwardingObjective fwd, boolean upstream) {
310 TrafficTreatment treatment = fwd.treatment();
311
312 //check instructions
313 Set<Instructions.MeterInstruction> meters = treatment.meters();
314 assert !meters.isEmpty();
315
316 Instructions.MetadataInstruction writeMetadata = treatment.writeMetadata();
317 assert writeMetadata != null;
318
319 List<Instruction> immediateInstructions = treatment.immediate();
320 Optional<Instruction> vlanInstruction = immediateInstructions.stream()
321 .filter(i -> i.type() == Instruction.Type.L2MODIFICATION)
322 .filter(i -> ((L2ModificationInstruction) i).subtype() ==
323 L2ModificationInstruction.L2SubType.VLAN_PUSH ||
324 ((L2ModificationInstruction) i).subtype() ==
325 L2ModificationInstruction.L2SubType.VLAN_POP)
326 .findAny();
327
328 assert vlanInstruction.isPresent();
329
330 //check match criteria
331 TrafficSelector selector = fwd.selector();
332 assert selector.getCriterion(Criterion.Type.IN_PORT) != null;
333 assert selector.getCriterion(Criterion.Type.VLAN_VID) != null;
334
335 if (!upstream) {
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000336 assert selector.getCriterion(Criterion.Type.METADATA) != null;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000337 }
338 }
339
340 private class MockOltMeterService implements org.opencord.olt.internalapi.AccessDeviceMeterService {
341 @Override
342 public ImmutableMap<String, Collection<MeterKey>> getBpMeterMappings() {
343 return null;
344 }
345
346 @Override
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000347 public MeterId getMeterIdFromBpMapping(DeviceId deviceId, String bandwidthProfile) {
348 return null;
349 }
350
351
352 @Override
353 public ImmutableSet<MeterKey> getProgMeters() {
354 return null;
355 }
356
357 @Override
358 public MeterId createMeter(DeviceId deviceId, BandwidthProfileInformation bpInfo,
359 CompletableFuture<Object> meterFuture) {
360 return usMeterId;
361 }
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800362
363 @Override
Andrea Campanella600d2e22020-06-22 11:00:31 +0200364 public void removeFromPendingMeters(DeviceId deviceId, BandwidthProfileInformation bwpInfo) {
365
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200366 }
367
368 @Override
Andrea Campanellad1e26642020-10-23 12:08:32 +0200369 public boolean checkAndAddPendingMeter(DeviceId deviceId, BandwidthProfileInformation bwpInfo) {
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200370 return false;
371 }
372
Andrea Campanella600d2e22020-06-22 11:00:31 +0200373
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200374 @Override
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800375 public void clearMeters(DeviceId deviceId) {
376 }
Andrea Campanella600d2e22020-06-22 11:00:31 +0200377
378 @Override
379 public void clearDeviceState(DeviceId deviceId) {
380
381 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000382 }
383
384 private class MockOltFlowObjectiveService implements org.onosproject.net.flowobjective.FlowObjectiveService {
Saurav Dasf62cea82020-08-26 17:43:04 -0700385 List<String> flowObjectives = new ArrayList<>();
386
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000387 @Override
388 public void filter(DeviceId deviceId, FilteringObjective filteringObjective) {
Saurav Dasf62cea82020-08-26 17:43:04 -0700389 flowObjectives.add(filteringObjective.toString());
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000390 EthTypeCriterion ethType = (EthTypeCriterion)
391 filterForCriterion(filteringObjective.conditions(), Criterion.Type.ETH_TYPE);
392
393 Instructions.MeterInstruction meter = filteringObjective.meta().metered();
394 Instruction writeMetadata = filteringObjective.meta().writeMetadata();
395 VlanIdCriterion vlanIdCriterion = (VlanIdCriterion)
396 filterForCriterion(filteringObjective.conditions(), Criterion.Type.VLAN_VID);
397 PortCriterion portCriterion = (PortCriterion) filteringObjective.key();
398
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100399 filteringObjective.meta().allInstructions().forEach(instruction -> {
400 if (instruction.type().equals(Instruction.Type.L2MODIFICATION)) {
401 L2ModificationInstruction l2Instruction = (L2ModificationInstruction) instruction;
402 if (l2Instruction.subtype().equals(L2ModificationInstruction.L2SubType.VLAN_PCP)) {
403 //this, given the uniTagInfo we provide, should not be present
404 assert false;
405 }
406 }
407 });
408
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000409
410 if (ethType.ethType().equals(EthType.EtherType.LLDP.ethType()) ||
411 portCriterion.port().equals(nniPortNumber)) {
412 assert meter == null;
413 assert writeMetadata == null;
414 assert vlanIdCriterion == null;
415 } else {
416 assert meter.meterId().equals(usMeterId) || meter.meterId().equals(dsMeterId);
417 assert writeMetadata != null;
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100418 assert vlanIdCriterion == null || vlanIdCriterion.vlanId() == uniTagInfo.getUniTagMatch()
419 || vlanIdCriterion.vlanId() == uniTagInfoNoPcp.getUniTagMatch();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000420 }
421
422 }
423
424 @Override
425 public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) {
426
427 }
428
429 @Override
430 public void next(DeviceId deviceId, NextObjective nextObjective) {
431
432 }
433
434 @Override
435 public int allocateNextId() {
436 return 0;
437 }
438
439 @Override
440 public void initPolicy(String s) {
441
442 }
443
444 @Override
445 public void apply(DeviceId deviceId, Objective objective) {
446
447 }
448
449 @Override
450 public Map<Pair<Integer, DeviceId>, List<String>> getNextMappingsChain() {
451 return null;
452 }
453
454 @Override
455 public List<String> getNextMappings() {
456 return null;
457 }
458
459 @Override
460 public List<String> getPendingFlowObjectives() {
Saurav Dasf62cea82020-08-26 17:43:04 -0700461 return ImmutableList.copyOf(flowObjectives);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000462 }
463
464 @Override
465 public ListMultimap<FilteringObjQueueKey, Objective> getFilteringObjQueue() {
466 return null;
467 }
468
469 @Override
470 public ListMultimap<ForwardingObjQueueKey, Objective> getForwardingObjQueue() {
471 return null;
472 }
473
474 @Override
475 public ListMultimap<NextObjQueueKey, Objective> getNextObjQueue() {
476 return null;
477 }
478
479 @Override
480 public Map<FilteringObjQueueKey, Objective> getFilteringObjQueueHead() {
481 return null;
482 }
483
484 @Override
485 public Map<ForwardingObjQueueKey, Objective> getForwardingObjQueueHead() {
486 return null;
487 }
488
489 @Override
490 public Map<NextObjQueueKey, Objective> getNextObjQueueHead() {
491 return null;
492 }
493
494 @Override
495 public void clearQueue() {
Saurav Dasf62cea82020-08-26 17:43:04 -0700496 flowObjectives.clear();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000497 }
498
499 private Criterion filterForCriterion(Collection<Criterion> criteria, Criterion.Type type) {
500 return criteria.stream()
501 .filter(c -> c.type().equals(type))
502 .limit(1)
503 .findFirst().orElse(null);
504 }
505 }
506
507 private class MockMastershipService implements org.onosproject.mastership.MastershipService {
508 @Override
509 public MastershipRole getLocalRole(DeviceId deviceId) {
510 return null;
511 }
512
513 @Override
514 public boolean isLocalMaster(DeviceId deviceId) {
515 return true;
516 }
517
518 @Override
519 public CompletableFuture<MastershipRole> requestRoleFor(DeviceId deviceId) {
520 return null;
521 }
522
523 @Override
524 public CompletableFuture<Void> relinquishMastership(DeviceId deviceId) {
525 return null;
526 }
527
528 @Override
529 public NodeId getMasterFor(DeviceId deviceId) {
530 return null;
531 }
532
533 @Override
534 public RoleInfo getNodesFor(DeviceId deviceId) {
535 return null;
536 }
537
538 @Override
539 public MastershipInfo getMastershipFor(DeviceId deviceId) {
540 return null;
541 }
542
543 @Override
544 public Set<DeviceId> getDevicesOf(NodeId nodeId) {
545 return null;
546 }
547
548 @Override
549 public void addListener(MastershipListener mastershipListener) {
550
551 }
552
553 @Override
554 public void removeListener(MastershipListener mastershipListener) {
555
556 }
557 }
558}