blob: 2947bf3a5b1a074a508d75794df33ca9d31f73c8 [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;
Tunahan Sezena07fe962021-02-24 08:24:24 +000031import org.onlab.packet.MacAddress;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000032import org.onlab.packet.VlanId;
33import org.onosproject.cluster.NodeId;
34import org.onosproject.cluster.RoleInfo;
35import org.onosproject.mastership.MastershipInfo;
36import org.onosproject.mastership.MastershipListener;
37import org.onosproject.net.DeviceId;
38import org.onosproject.net.MastershipRole;
39import org.onosproject.net.PortNumber;
40import org.onosproject.net.flow.TrafficSelector;
41import org.onosproject.net.flow.TrafficTreatment;
42import org.onosproject.net.flow.criteria.Criterion;
43import org.onosproject.net.flow.criteria.EthTypeCriterion;
44import org.onosproject.net.flow.criteria.PortCriterion;
45import org.onosproject.net.flow.criteria.VlanIdCriterion;
46import org.onosproject.net.flow.instructions.Instruction;
47import org.onosproject.net.flow.instructions.Instructions;
48import org.onosproject.net.flow.instructions.L2ModificationInstruction;
49import org.onosproject.net.flowobjective.FilteringObjQueueKey;
50import org.onosproject.net.flowobjective.FilteringObjective;
51import org.onosproject.net.flowobjective.ForwardingObjQueueKey;
52import org.onosproject.net.flowobjective.ForwardingObjective;
53import org.onosproject.net.flowobjective.NextObjQueueKey;
54import org.onosproject.net.flowobjective.NextObjective;
55import org.onosproject.net.flowobjective.Objective;
56import org.onosproject.net.meter.MeterId;
57import org.onosproject.net.meter.MeterKey;
58import org.opencord.sadis.BandwidthProfileInformation;
59import org.opencord.sadis.UniTagInformation;
60
Saurav Dasf62cea82020-08-26 17:43:04 -070061import com.google.common.collect.ImmutableList;
62import com.google.common.collect.ImmutableMap;
63import com.google.common.collect.ImmutableSet;
64import com.google.common.collect.ListMultimap;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000065
66public class OltFlowTest extends TestBase {
67 private OltFlowService oltFlowService;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000068 PortNumber uniPortNumber = PortNumber.portNumber(1);
Andrea Campanella3a96ce82021-02-09 12:32:42 +010069 PortNumber uniPortNumber2 = PortNumber.portNumber(2);
Andrea Campanellacbbb7952019-11-25 06:38:41 +000070 PortNumber nniPortNumber = PortNumber.portNumber(65535);
71
Tunahan Sezena07fe962021-02-24 08:24:24 +000072 MacAddress macAddress = MacAddress.valueOf("00:00:00:00:0a:0b");
73
Andrea Campanellacbbb7952019-11-25 06:38:41 +000074 UniTagInformation.Builder tagInfoBuilder = new UniTagInformation.Builder();
75 UniTagInformation uniTagInfo = tagInfoBuilder.setUniTagMatch(VlanId.vlanId((short) 35))
76 .setPonCTag(VlanId.vlanId((short) 33))
77 .setPonSTag(VlanId.vlanId((short) 7))
78 .setDsPonCTagPriority(0)
79 .setUsPonSTagPriority(0)
80 .setTechnologyProfileId(64)
81 .setDownstreamBandwidthProfile(dsBpId)
82 .setUpstreamBandwidthProfile(usBpId)
Saurav Dasf62cea82020-08-26 17:43:04 -070083 .setIsDhcpRequired(true)
84 .setIsIgmpRequired(true)
85 .build();
86
Andrea Campanella3a96ce82021-02-09 12:32:42 +010087 UniTagInformation.Builder tagInfoBuilderNoPcp = new UniTagInformation.Builder();
88 UniTagInformation uniTagInfoNoPcp = tagInfoBuilderNoPcp.setUniTagMatch(VlanId.vlanId((short) 35))
89 .setPonCTag(VlanId.vlanId((short) 34))
90 .setPonSTag(VlanId.vlanId((short) 7))
91 .setDsPonCTagPriority(-1)
92 .setUsPonSTagPriority(-1)
93 .setUsPonCTagPriority(-1)
94 .setDsPonSTagPriority(-1)
95 .setTechnologyProfileId(64)
96 .setDownstreamBandwidthProfile(dsBpId)
97 .setUpstreamBandwidthProfile(usBpId)
98 .setIsDhcpRequired(true)
99 .setIsIgmpRequired(true)
100 .build();
101
Saurav Dasf62cea82020-08-26 17:43:04 -0700102 UniTagInformation.Builder tagInfoBuilder2 = new UniTagInformation.Builder();
103 UniTagInformation uniTagInfoNoDhcpNoIgmp = tagInfoBuilder2
104 .setUniTagMatch(VlanId.vlanId((short) 35))
105 .setPonCTag(VlanId.vlanId((short) 33))
106 .setPonSTag(VlanId.vlanId((short) 7))
107 .setDsPonCTagPriority(0)
108 .setUsPonSTagPriority(0)
109 .setTechnologyProfileId(64)
110 .setDownstreamBandwidthProfile(dsBpId)
111 .setUpstreamBandwidthProfile(usBpId)
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000112 .build();
113
114 @Before
115 public void setUp() {
116 oltFlowService = new OltFlowService();
117 oltFlowService.oltMeterService = new MockOltMeterService();
118 oltFlowService.flowObjectiveService = new MockOltFlowObjectiveService();
119 oltFlowService.mastershipService = new MockMastershipService();
120 oltFlowService.sadisService = new MockSadisService();
121 oltFlowService.bpService = oltFlowService.sadisService.getBandwidthProfileService();
122 oltFlowService.appId = appId;
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000123 oltFlowService.pendingEapolForDevice = Maps.newConcurrentMap();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000124 }
125
126 @Test
127 public void testDhcpFiltering() {
Saurav Dasf62cea82020-08-26 17:43:04 -0700128 oltFlowService.flowObjectiveService.clearQueue();
129 // ensure upstream dhcp traps can be added and removed
130 oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000131 usMeterId, uniTagInfo,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000132 true, true, Optional.empty());
Saurav Dasf62cea82020-08-26 17:43:04 -0700133 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 1;
134 oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000135 usMeterId, uniTagInfo,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000136 false, true, Optional.empty());
Saurav Dasf62cea82020-08-26 17:43:04 -0700137 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 2;
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100138
139 // Ensure upstream flow has no pcp unless properly specified.
140 oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber2,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000141 usMeterId, uniTagInfoNoPcp,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000142 true, true, Optional.empty());
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100143 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3;
144
Saurav Dasf62cea82020-08-26 17:43:04 -0700145 // ensure upstream flows are not added if uniTagInfo is missing dhcp requirement
146 oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000147 usMeterId, uniTagInfoNoDhcpNoIgmp,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000148 true, true, Optional.empty());
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100149 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3;
Saurav Dasf62cea82020-08-26 17:43:04 -0700150
151 // ensure downstream traps don't succeed without global config for nni ports
152 oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, nniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000153 null, null,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000154 true, false, Optional.empty());
Saurav Dasf62cea82020-08-26 17:43:04 -0700155 oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, nniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000156 null, null,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000157 false, false, Optional.empty());
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100158 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3;
Saurav Dasf62cea82020-08-26 17:43:04 -0700159 // do global config for nni ports and now it should succeed
160 oltFlowService.enableDhcpOnNni = true;
161 oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, nniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000162 null, null,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000163 true, false, Optional.empty());
Saurav Dasf62cea82020-08-26 17:43:04 -0700164 oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, nniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000165 null, null,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000166 false, false, Optional.empty());
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100167 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 5;
Saurav Dasf62cea82020-08-26 17:43:04 -0700168
169 // turn on DHCPv6 and we should get 2 flows
170 oltFlowService.enableDhcpV6 = true;
171 oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000172 usMeterId, uniTagInfo,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000173 true, true, Optional.empty());
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100174 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 7;
Saurav Dasf62cea82020-08-26 17:43:04 -0700175
176 // turn off DHCPv4 and it's only v6
177 oltFlowService.enableDhcpV4 = false;
178 oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000179 usMeterId, uniTagInfo,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000180 true, true, Optional.empty());
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100181 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 8;
Saurav Dasf62cea82020-08-26 17:43:04 -0700182
183 // cleanup
184 oltFlowService.flowObjectiveService.clearQueue();
185 oltFlowService.enableDhcpV4 = true;
186 oltFlowService.enableDhcpV6 = false;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000187 }
188
189 @Test
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300190 public void testPppoedFiltering() {
191 oltFlowService.flowObjectiveService.clearQueue();
192
193 // ensure pppoed traps are not added if global config is off.
194 oltFlowService.enablePppoe = false;
195 oltFlowService.processPPPoEDFilteringObjectives(DEVICE_ID_1, uniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000196 usMeterId, uniTagInfo,
197 true, true);
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300198 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 0;
199
200 // ensure upstream pppoed traps can be added and removed
201 oltFlowService.enablePppoe = true;
202 oltFlowService.processPPPoEDFilteringObjectives(DEVICE_ID_1, uniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000203 usMeterId, uniTagInfo,
204 true, true);
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300205 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 1;
206 oltFlowService.processPPPoEDFilteringObjectives(DEVICE_ID_1, uniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000207 usMeterId, uniTagInfo,
208 false, true);
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300209 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 2;
210
211 // ensure downstream pppoed traps can be added and removed
212 oltFlowService.processPPPoEDFilteringObjectives(DEVICE_ID_1, nniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000213 null, null,
214 true, false);
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300215 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3;
216 oltFlowService.processPPPoEDFilteringObjectives(DEVICE_ID_1, nniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000217 null, null,
218 false, false);
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300219 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 4;
220
221 // cleanup
222 oltFlowService.flowObjectiveService.clearQueue();
223 }
224
225 @Test
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000226 public void testIgmpFiltering() {
Saurav Dasf62cea82020-08-26 17:43:04 -0700227 oltFlowService.flowObjectiveService.clearQueue();
228
229 // ensure igmp flows can be added and removed
230 oltFlowService.processIgmpFilteringObjectives(DEVICE_ID_1, uniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000231 usMeterId, uniTagInfo,
232 true, true);
Saurav Dasf62cea82020-08-26 17:43:04 -0700233 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 1;
234 oltFlowService.processIgmpFilteringObjectives(DEVICE_ID_1, uniPortNumber, usMeterId,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000235 uniTagInfo,
236 false, true);
Saurav Dasf62cea82020-08-26 17:43:04 -0700237 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 2;
238
239 // ensure igmp flow is not added if uniTag has no igmp requirement
240 oltFlowService.processIgmpFilteringObjectives(DEVICE_ID_1, uniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000241 usMeterId, uniTagInfoNoDhcpNoIgmp,
242 true, true);
Saurav Dasf62cea82020-08-26 17:43:04 -0700243 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 2;
244
245 //ensure igmp flow on NNI fails without global setting
246 oltFlowService.processIgmpFilteringObjectives(DEVICE_ID_1, nniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000247 null, null,
248 true, false);
Saurav Dasf62cea82020-08-26 17:43:04 -0700249 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 2;
250
251 // igmp trap on NNI should succeed with global config
252 oltFlowService.enableIgmpOnNni = true;
253 oltFlowService.processIgmpFilteringObjectives(DEVICE_ID_1, nniPortNumber,
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000254 null, null,
255 true, false);
Saurav Dasf62cea82020-08-26 17:43:04 -0700256 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives().size() == 3;
257 // cleanup
258 oltFlowService.flowObjectiveService.clearQueue();
259
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000260 }
261
262 @Test
263 public void testEapolFiltering() {
264 addBandwidthProfile(uniTagInfo.getUpstreamBandwidthProfile());
265 oltFlowService.enableEapol = true;
266
267 //will install
268 oltFlowService.processEapolFilteringObjectives(DEVICE_ID_1, uniPortNumber,
269 uniTagInfo.getUpstreamBandwidthProfile(), new CompletableFuture<>(),
270 uniTagInfo.getUniTagMatch(), true);
271
272 //bp profile doesn't exist
273 oltFlowService.processEapolFilteringObjectives(DEVICE_ID_1, uniPortNumber,
274 uniTagInfo.getDownstreamBandwidthProfile(), new CompletableFuture<>(),
275 uniTagInfo.getUniTagMatch(), true);
276 }
277
278 @Test
279 public void testLldpFiltering() {
280 oltFlowService.processLldpFilteringObjective(DEVICE_ID_1, nniPortNumber, true);
281 oltFlowService.processLldpFilteringObjective(DEVICE_ID_1, nniPortNumber, false);
282 }
283
284 @Test
285 public void testNniFiltering() {
Saurav Dasf62cea82020-08-26 17:43:04 -0700286 oltFlowService.flowObjectiveService.clearQueue();
287 oltFlowService.enableDhcpOnNni = true;
288 oltFlowService.enableIgmpOnNni = true;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000289 oltFlowService.processNniFilteringObjectives(DEVICE_ID_1, nniPortNumber, true);
Saurav Dasf62cea82020-08-26 17:43:04 -0700290 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives()
291 .size() == 3;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000292 oltFlowService.processNniFilteringObjectives(DEVICE_ID_1, nniPortNumber, false);
Saurav Dasf62cea82020-08-26 17:43:04 -0700293 assert oltFlowService.flowObjectiveService.getPendingFlowObjectives()
294 .size() == 6;
295 oltFlowService.flowObjectiveService.clearQueue();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000296 }
297
298 @Test
299 public void testUpBuilder() {
300 ForwardingObjective objective =
301 oltFlowService.createUpBuilder(nniPortNumber, uniPortNumber, usMeterId, uniTagInfo).add();
302 checkObjective(objective, true);
303 }
304
305 @Test
306 public void testDownBuilder() {
307 ForwardingObjective objective =
Tunahan Sezena07fe962021-02-24 08:24:24 +0000308 oltFlowService.createDownBuilder(nniPortNumber, uniPortNumber, dsMeterId, uniTagInfo,
309 Optional.of(macAddress)).remove();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000310 checkObjective(objective, false);
311 }
312
313 private void checkObjective(ForwardingObjective fwd, boolean upstream) {
314 TrafficTreatment treatment = fwd.treatment();
315
316 //check instructions
317 Set<Instructions.MeterInstruction> meters = treatment.meters();
318 assert !meters.isEmpty();
319
320 Instructions.MetadataInstruction writeMetadata = treatment.writeMetadata();
321 assert writeMetadata != null;
322
323 List<Instruction> immediateInstructions = treatment.immediate();
324 Optional<Instruction> vlanInstruction = immediateInstructions.stream()
325 .filter(i -> i.type() == Instruction.Type.L2MODIFICATION)
326 .filter(i -> ((L2ModificationInstruction) i).subtype() ==
327 L2ModificationInstruction.L2SubType.VLAN_PUSH ||
328 ((L2ModificationInstruction) i).subtype() ==
329 L2ModificationInstruction.L2SubType.VLAN_POP)
330 .findAny();
331
332 assert vlanInstruction.isPresent();
333
334 //check match criteria
335 TrafficSelector selector = fwd.selector();
336 assert selector.getCriterion(Criterion.Type.IN_PORT) != null;
337 assert selector.getCriterion(Criterion.Type.VLAN_VID) != null;
338
339 if (!upstream) {
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000340 assert selector.getCriterion(Criterion.Type.METADATA) != null;
Tunahan Sezena07fe962021-02-24 08:24:24 +0000341 assert selector.getCriterion(Criterion.Type.ETH_DST) != null;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000342 }
343 }
344
345 private class MockOltMeterService implements org.opencord.olt.internalapi.AccessDeviceMeterService {
346 @Override
347 public ImmutableMap<String, Collection<MeterKey>> getBpMeterMappings() {
348 return null;
349 }
350
351 @Override
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000352 public MeterId getMeterIdFromBpMapping(DeviceId deviceId, String bandwidthProfile) {
353 return null;
354 }
355
356
357 @Override
358 public ImmutableSet<MeterKey> getProgMeters() {
359 return null;
360 }
361
362 @Override
363 public MeterId createMeter(DeviceId deviceId, BandwidthProfileInformation bpInfo,
364 CompletableFuture<Object> meterFuture) {
365 return usMeterId;
366 }
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800367
368 @Override
Andrea Campanella600d2e22020-06-22 11:00:31 +0200369 public void removeFromPendingMeters(DeviceId deviceId, BandwidthProfileInformation bwpInfo) {
370
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200371 }
372
373 @Override
Andrea Campanellad1e26642020-10-23 12:08:32 +0200374 public boolean checkAndAddPendingMeter(DeviceId deviceId, BandwidthProfileInformation bwpInfo) {
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200375 return false;
376 }
377
Andrea Campanella600d2e22020-06-22 11:00:31 +0200378
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200379 @Override
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800380 public void clearMeters(DeviceId deviceId) {
381 }
Andrea Campanella600d2e22020-06-22 11:00:31 +0200382
383 @Override
384 public void clearDeviceState(DeviceId deviceId) {
385
386 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000387 }
388
389 private class MockOltFlowObjectiveService implements org.onosproject.net.flowobjective.FlowObjectiveService {
Saurav Dasf62cea82020-08-26 17:43:04 -0700390 List<String> flowObjectives = new ArrayList<>();
391
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000392 @Override
393 public void filter(DeviceId deviceId, FilteringObjective filteringObjective) {
Saurav Dasf62cea82020-08-26 17:43:04 -0700394 flowObjectives.add(filteringObjective.toString());
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000395 EthTypeCriterion ethType = (EthTypeCriterion)
396 filterForCriterion(filteringObjective.conditions(), Criterion.Type.ETH_TYPE);
397
398 Instructions.MeterInstruction meter = filteringObjective.meta().metered();
399 Instruction writeMetadata = filteringObjective.meta().writeMetadata();
400 VlanIdCriterion vlanIdCriterion = (VlanIdCriterion)
401 filterForCriterion(filteringObjective.conditions(), Criterion.Type.VLAN_VID);
402 PortCriterion portCriterion = (PortCriterion) filteringObjective.key();
403
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100404 filteringObjective.meta().allInstructions().forEach(instruction -> {
405 if (instruction.type().equals(Instruction.Type.L2MODIFICATION)) {
406 L2ModificationInstruction l2Instruction = (L2ModificationInstruction) instruction;
407 if (l2Instruction.subtype().equals(L2ModificationInstruction.L2SubType.VLAN_PCP)) {
408 //this, given the uniTagInfo we provide, should not be present
409 assert false;
410 }
411 }
412 });
413
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000414
415 if (ethType.ethType().equals(EthType.EtherType.LLDP.ethType()) ||
416 portCriterion.port().equals(nniPortNumber)) {
417 assert meter == null;
418 assert writeMetadata == null;
419 assert vlanIdCriterion == null;
420 } else {
421 assert meter.meterId().equals(usMeterId) || meter.meterId().equals(dsMeterId);
422 assert writeMetadata != null;
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100423 assert vlanIdCriterion == null || vlanIdCriterion.vlanId() == uniTagInfo.getUniTagMatch()
424 || vlanIdCriterion.vlanId() == uniTagInfoNoPcp.getUniTagMatch();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000425 }
426
427 }
428
429 @Override
430 public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) {
431
432 }
433
434 @Override
435 public void next(DeviceId deviceId, NextObjective nextObjective) {
436
437 }
438
439 @Override
440 public int allocateNextId() {
441 return 0;
442 }
443
444 @Override
445 public void initPolicy(String s) {
446
447 }
448
449 @Override
450 public void apply(DeviceId deviceId, Objective objective) {
451
452 }
453
454 @Override
455 public Map<Pair<Integer, DeviceId>, List<String>> getNextMappingsChain() {
456 return null;
457 }
458
459 @Override
460 public List<String> getNextMappings() {
461 return null;
462 }
463
464 @Override
465 public List<String> getPendingFlowObjectives() {
Saurav Dasf62cea82020-08-26 17:43:04 -0700466 return ImmutableList.copyOf(flowObjectives);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000467 }
468
469 @Override
470 public ListMultimap<FilteringObjQueueKey, Objective> getFilteringObjQueue() {
471 return null;
472 }
473
474 @Override
475 public ListMultimap<ForwardingObjQueueKey, Objective> getForwardingObjQueue() {
476 return null;
477 }
478
479 @Override
480 public ListMultimap<NextObjQueueKey, Objective> getNextObjQueue() {
481 return null;
482 }
483
484 @Override
485 public Map<FilteringObjQueueKey, Objective> getFilteringObjQueueHead() {
486 return null;
487 }
488
489 @Override
490 public Map<ForwardingObjQueueKey, Objective> getForwardingObjQueueHead() {
491 return null;
492 }
493
494 @Override
495 public Map<NextObjQueueKey, Objective> getNextObjQueueHead() {
496 return null;
497 }
498
499 @Override
500 public void clearQueue() {
Saurav Dasf62cea82020-08-26 17:43:04 -0700501 flowObjectives.clear();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000502 }
503
504 private Criterion filterForCriterion(Collection<Criterion> criteria, Criterion.Type type) {
505 return criteria.stream()
506 .filter(c -> c.type().equals(type))
507 .limit(1)
508 .findFirst().orElse(null);
509 }
510 }
511
512 private class MockMastershipService implements org.onosproject.mastership.MastershipService {
513 @Override
514 public MastershipRole getLocalRole(DeviceId deviceId) {
515 return null;
516 }
517
518 @Override
519 public boolean isLocalMaster(DeviceId deviceId) {
520 return true;
521 }
522
523 @Override
524 public CompletableFuture<MastershipRole> requestRoleFor(DeviceId deviceId) {
525 return null;
526 }
527
528 @Override
529 public CompletableFuture<Void> relinquishMastership(DeviceId deviceId) {
530 return null;
531 }
532
533 @Override
534 public NodeId getMasterFor(DeviceId deviceId) {
535 return null;
536 }
537
538 @Override
539 public RoleInfo getNodesFor(DeviceId deviceId) {
540 return null;
541 }
542
543 @Override
544 public MastershipInfo getMastershipFor(DeviceId deviceId) {
545 return null;
546 }
547
548 @Override
549 public Set<DeviceId> getDevicesOf(NodeId nodeId) {
550 return null;
551 }
552
553 @Override
554 public void addListener(MastershipListener mastershipListener) {
555
556 }
557
558 @Override
559 public void removeListener(MastershipListener mastershipListener) {
560
561 }
562 }
563}